counter.js
import React from 'react'; import classes from './Counter.module.css'; // 计数器的组件 const Counter = (props) => { return ( <div className={classes.Counter}> { (props.amount && props.amount !== 0) ? ( <> <button className={classes.Sub}><span>-</span></button> <span className={classes.count}>{props.amount}</span> </> ) : null } <button className={classes.Add}> <span>+</span> </button> </div> ); }; export default Counter;
样式部分
.Counter{ display: flex; align-items: center; } .Sub, .Add{ display: flex; justify-content: center; align-items: center; border: none; background-color: #FCBF49; width: 36rem; height: 36rem; border-radius: 50%; font-size: 24px; padding: 0; } .Sub{ background-color: white; border: 1px solid black; } .count{ font-size: 16px; margin: 0 5px; }