fix(striker-ui): correct label in SwitchWithLabel

main
Tsu-ba-me 2 years ago
parent 515d3b3b9e
commit cd14783c08
  1. 1
      striker-ui/components/ManageFence/CommonFenceInputGroup.tsx
  2. 47
      striker-ui/components/SwitchWithLabel.tsx
  3. 2
      striker-ui/types/SwitchWithLabel.d.ts

@ -24,7 +24,6 @@ const MAP_TO_INPUT_BUILDER: MapToInputBuilder = {
input={
<SwitchWithLabel
checked={isChecked}
flexBoxProps={{ width: '100%' }}
id={id}
label={label}
name={name}

@ -1,47 +1,46 @@
import { Switch, SxProps, Theme } from '@mui/material';
import { FC, useMemo } from 'react';
import {
FormControlLabel as MUIFormControlLabel,
styled,
Switch as MUISwitch,
} from '@mui/material';
import { FC, ReactElement, useMemo } from 'react';
import { GREY } from '../lib/consts/DEFAULT_THEME';
import FlexBox from './FlexBox';
import { BodyText } from './Text';
const SwitchFormControlLabel = styled(MUIFormControlLabel)({
height: '3.5em',
marginLeft: 0,
width: '100%',
});
const SwitchWithLabel: FC<SwitchWithLabelProps> = ({
checked: isChecked,
flexBoxProps: { sx: flexBoxSx, ...restFlexBoxProps } = {},
formControlLabelProps,
id: switchId,
label,
name: switchName,
onChange,
switchProps,
}) => {
const combinedFlexBoxSx = useMemo<SxProps<Theme>>(
() => ({
'& > :first-child': {
flexGrow: 1,
},
...flexBoxSx,
}),
[flexBoxSx],
);
const labelElement = useMemo(
const labelElement = useMemo<ReactElement>(
() =>
typeof label === 'string' ? (
<BodyText inheritColour color={`${GREY}9F`}>
<BodyText inheritColour color={`${GREY}AF`}>
{label}
</BodyText>
) : (
label
<>{label}</>
),
[label],
);
return (
<FlexBox row {...restFlexBoxProps} sx={combinedFlexBoxSx}>
{labelElement}
<Switch
<SwitchFormControlLabel
componentsProps={{ typography: { flexGrow: 1 } }}
control={
<MUISwitch
checked={isChecked}
edge="end"
id={switchId}
@ -49,7 +48,11 @@ const SwitchWithLabel: FC<SwitchWithLabelProps> = ({
onChange={onChange}
{...switchProps}
/>
</FlexBox>
}
label={labelElement}
labelPlacement="start"
{...formControlLabelProps}
/>
);
};

@ -1,5 +1,5 @@
type SwitchWithLabelOptionalProps = {
flexBoxProps?: import('../components/FlexBox').FlexBoxProps;
formControlLabelProps?: import('@mui/material').FormControlLabelProps;
switchProps?: import('@mui/material').SwitchProps;
};

Loading…
Cancel
Save