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

react组件之间如何使用接收到的className(封装一个按钮案例)

带有hover渐变效果 

一、父组件

import LineGradientBox from '../line-gradient-box';
import styles from './index.module.scss';<LineGradientBoxfontSize={20}className={styles.btn_height}text='Sign up'width="100%"onClick={() => {navigate('/sign-up');}}
/>

 需要传递样式在父组件中先定义好(sitepx函数用法):

.btn_height {height: sitepx(50);
}

二、子组件

import clsx from 'clsx';
import styles from './index.module.scss';
const LineGradientBox: React.FC<{text: string;width: string | number;height?: number;fontSize?: number;className?: string;onClick?: () => void;beforeTextIcon?: React.ReactNode;
}> = ({ text, width, height, fontSize, className, beforeTextIcon, onClick }) => {return (<divonClick={onClick}className={clsx(styles.box, className || '')}style={{ minWidth: width, height, lineHeight: height + 'px' }}><div className={styles.bgfff} /><divclassName={styles.box_content}style={{ ...(fontSize ? { fontSize: fontSize + 'px' } : {}) }}>{beforeTextIcon}{text}</div></div>);
};export default LineGradientBox;

子组件样式:

.box {text-align: center;border-radius: 6px;overflow: hidden;background: $line-gradient-init-color;padding: 1px;position: relative;cursor: pointer;padding: 0 10px;&_content {position: relative;z-index: 2;width: 100%;height: 100%;background: $line-gradient-init-color;background-clip: text;-webkit-background-clip: text;-webkit-text-fill-color: transparent;display: flex;justify-content: center;align-items: center;& path {stroke: linear-gradient(90deg, #8057ff 0%, #936bff 50%, #b892ff 100%) !important;}}&:hover {color: var(--color-primary);background: $line-gradient-hover-color;.box_content {background: $line-gradient-hover-color;background-clip: text;-webkit-background-clip: text;-webkit-text-fill-color: transparent;}}.bgfff {position: absolute;z-index: 1;border-radius: 5px;top: 1px;left: 1px;width: calc(100% - 2px);height: calc(100% - 2px);background-color: #fff;}
}

http://www.xdnf.cn/news/1267.html

相关文章:

  • Python 之 pyecharts 使用
  • 数字化赋能医药未来:柏强制药的战略布局与成果汇报
  • Linux系统编程 day9 SIGCHLD and 线程
  • L1-7、Prompt 的“调试技巧”
  • FPGA设计 时空变换
  • 【springsecurity oauth2授权中心】jwt令牌更换成自省令牌 OpaqueToken P4
  • 西门子PLC S7-1200按钮控制灯实例
  • day4-小白学习JAVA---开发软件_Scanner键盘录入_Random随机数_流程控制语句
  • 基于龙芯 2K1000处理器和复旦微 FPGA K7 的全国产RapidIO 解决方案研究
  • 【Pytorch 中的扩散模型】去噪扩散概率模型(DDPM)的实现
  • ProxySQL性能调优案例
  • 星光璀璨,跨界共鸣——李炳辰亮相 第十五届北影节嘉年华“音乐之旅”
  • [Java · 铢积寸累] 可变参数
  • Win10 关闭自动更新、关闭自动更新并重启
  • 实践项目开发-hbmV4V20250407-跨平台开发框架深度解析与VSCode一站式开发实践
  • 重装系统后的自用包
  • MulanPSL-1.0开源协议
  • PaddlePaddle线性回归详解:从模型定义到加载,掌握深度学习基础
  • 状态空间模型(State‐Space Model)、传递函数和极点
  • React项目添加react-quill富文本编辑器,遇到的问题,比如hr标签丢失
  • 文件操作和IO(上)
  • Towards Multi-Domain Learning for Generalizable Video Anomaly Detection
  • 一页概览:EMC Avamar备份方案
  • C++初阶——string的使用(上)
  • Tomcat启动闪退是为什么?
  • 第6次课 贪心算法 A
  • Electron使用WebAssembly实现CRC-32 原理校验
  • 前端路由 ( 1 ) | history 原理
  • Hyper-V 管理工具
  • Java队列(Queue)核心操作与最佳实践:深入解析与面试指南