寻求可调整尺寸的React开关切换组件(iOS风格或其他)
Hey there! I totally get your frustration—hunting for a component that fits your exact needs without having to tweak existing code can be a pain. Let me share some React toggle switch components that natively support sizing props (or equivalent options) since you mentioned you saw one a year back and don't want to modify existing ones:
- react-toggle: This component has been around for years and offers granular sizing control via props like
width,height,thumbWidth, andthumbHeight. You can set these directly when rendering, no need to edit the component's source code. This might very well be the one you remembered from a year ago—it’s widely used and has maintained these features. - react-switch: A lightweight option that includes a built-in
sizeprop with preset values like'sm','md', and'lg'. It’s designed to be customizable out of the box, so you can adjust the size without overriding styles manually. - @mui/material/Switch: If you’re already using Material UI in your project, their Switch component supports a
sizeprop (accepting'small'or'medium'). It integrates smoothly with the rest of the MUI ecosystem and requires zero custom modifications to adjust dimensions.
If none of these jog your memory, it’s worth checking older versions of the components you previously evaluated—sometimes newer releases rename or remove props, but a year-old version might still include the sizing functionality you’re looking for. Niche, lesser-known components could also fit the bill, but the options above are the most reliable with native size support.
内容的提问来源于stack exchange,提问作者Daniel Khoroshko

