当前位置: 首页 > news >正文

表单自定义组件 - 可选择卡片SelectCard

在这里插入图片描述

import React from 'react';
import styles from './index.module.less';type OptionsType = {/*** 每个item渲染一行,第0项为标题*/labels?: any[];/*** 自定义渲染内容*/label?: string | React.ReactNode;value: any;
};
interface IProps {value?: any;onChange?: Function;options: OptionsType[];layout?: 'horizontal' | 'vertical';disabled?: boolean;
}export default function Index(props: IProps) {const { value, onChange = () => {}, options, layout = 'horizontal', disabled = false } = props;const clickHandler = (row) => {if (disabled) return;if (value === row.value) {onChange(undefined);} else {onChange(row.value);}};return (<div className={`${styles.container} ${styles[layout]}`}>{options?.map((item, index) => {const activeStyles = item.value === value ? styles['select-card-checked'] : styles['select-card'];const disabledStyles = disabled ? styles['select-card-disabled'] : '';return (<div key={index} className={`${activeStyles} ${disabledStyles}`.trim()} onClick={() => clickHandler(item)}><div className={styles.corner}></div><div className={styles.content}>{item?.label? item?.label: item?.labels?.map((v, idx) => {return (<React.Fragment key={idx}>{idx === 0 && v ? (<div className={styles.title}>{v}</div>) : (<div className={styles.text}>{v}</div>)}</React.Fragment>);})}</div></div>);})}</div>);
}
@primaric-color: #5050e6;
@primary-color-opacity: #5050e680;.container {.select-card {position: relative;width: 300px;padding: 14px;border-radius: 5px;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);border: 1px solid #f9f9f9;background-color: #fff;cursor: pointer;margin: 0 14px 14px 0;.corner {position: absolute;top: 2px;right: 2px;width: 0;height: 0;border-top: 12px solid #5050e6;border-left: 12px solid transparent;border-radius: 0 3px 0 0;opacity: 0;}.content {.title {margin: 0;font-size: 15px;font-weight: bold;color: #333;margin-bottom: 10px;}.title:nth-last-of-type(1) {margin-bottom: 0;}.text {margin-bottom: 10px;font-size: 14px;color: #666;}.text:nth-last-of-type(1) {margin-bottom: 0;}}}.select-card:hover {border-color: @primary-color-opacity;box-shadow: 0 0 3px 0 @primaric-color;}.select-card:nth-last-of-type(1) {margin: 0;}.select-card-checked {position: relative;width: 300px;padding: 14px;border-radius: 5px;box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);border: 1px solid @primary-color-opacity;background-color: #f0f2ff;cursor: pointer;margin: 0 14px 14px 0;box-shadow: 0 0 3px 0 @primaric-color;.corner {position: absolute;top: 2px;right: 2px;width: 0;height: 0;border-top: 12px solid @primaric-color;border-left: 12px solid transparent;border-radius: 0 3px 0 0;opacity: 1;}.content {.title {margin: 0;font-size: 15px;font-weight: bold;margin-bottom: 10px;}.title:nth-last-of-type(1) {margin-bottom: 0;}.text {margin-bottom: 10px;font-size: 14px;color: #666;}.text:nth-last-of-type(1) {margin-bottom: 0;}}}.select-card-checked:nth-last-of-type(1) {margin: 0;}.select-card-disabled {background-color: #e0e0e0;border-color: #a0a0a0;color: #666;box-shadow: none;cursor: not-allowed;.corner {border-top-color: #a0a0a0;}}
}.horizontal {
}.vertical {display: flex;flex-wrap: wrap;
}
http://www.lryc.cn/news/392469.html

相关文章:

  • Ubuntu / Debian安装FTP服务
  • 若依 Vue 前端分离 3.8.8 版中生成的前端代码中关于下拉框只有下拉箭头的问题
  • C++把一个类封装成动态链接库
  • 每天一个项目管理概念之项目章程
  • c++11新特性-4-返回类型后置
  • Linux-C语言实现一个进度条小项目
  • vue使用glide.js实现轮播图(可直接复制使用)
  • TK养号工具开发会用上的源代码科普!
  • 信创-办公软件应用工程师认证
  • 数组操作forEach和map
  • 流式处理应用场景与流式计算处理框架选择建议
  • 2024年软件测试岗必问的100+个面试题【含答案】
  • A4-C四驱高防轮式巡检机器人
  • Https网站如何申请免费的SSL证书及操作使用指南
  • 实现资产优化管理:智慧校园资产分类功能解析
  • 大厂开发必知必会:Devops、CI/CD、流水线和Paas的关系解析说明
  • Qt学习:Qt窗口组件以及窗口类型
  • 基于AGX ORIN与FPGA K7实现PCIE高速数据通信/Orin与FPGA高速数据传输/XDMA在linux系统使用教程
  • Vue3:全局播放背景音乐
  • 2024年07月03日 Redis部署方式和持久化
  • 成都仅需浏览器即可快速查看的数据采集监控平台!
  • LLM - 神经网络的训练过程
  • 【全网最全ABC三题完整版】2024年APMCM第十四届亚太地区大学生数学建模竞赛(中文赛项)完整思路解析+代码+论文
  • Python | Leetcode Python题解之第213题打家劫舍II
  • 揭秘数据之美:【Seaborn】在现代【数学建模】中的革命性应用
  • 【宠粉赠书】UML 2.5基础、建模与设计实践
  • Python中几个重要的集合
  • 【JS】纯web端使用ffmpeg实现的视频编辑器-视频合并
  • 解决Python用xpath爬取不到数据的一个思路
  • C#面:如何把一个array复制到arrayist里