UNPKG

@re-flex/ui

Version:
31 lines (30 loc) 1.4 kB
import SwitchStyled from "@re-flex/styled/Switch"; import SwitchInputStyled from "@re-flex/styled/SwitchInput"; import SwitchTrackStyled from "@re-flex/styled/SwitchTrack"; import { useTheme } from "@re-flex/styles"; import React from "react"; const Switch = ({ size = "md", color = "primary", width, height, children, onChange, onBlur, inputProps, onFocus, ...rest }) => { const theme = useTheme(); return (React.createElement(SwitchStyled, { className: theme.prefix + "-switch", size: size, width: width, height: height, color: color, ...rest }, React.createElement(SwitchInputStyled, { ...inputProps, type: "checkbox", onChange: (v) => { if (!!onChange) { onChange(v.currentTarget.checked, v); } if (!!inputProps?.onChange) inputProps.onChange(v); }, onBlur: (v) => { if (!!onBlur) { onBlur(v.currentTarget.checked, v); } if (!!inputProps?.onBlur) inputProps.onBlur(v); }, onFocus: (v) => { if (!!onFocus) { onFocus(v.currentTarget.checked, v); } if (!!inputProps?.onFocus) inputProps.onFocus(v); } }), React.createElement(SwitchTrackStyled, null))); }; export default Switch;