Skip to content

Commit

Permalink
FormLabelStart: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Feb 25, 2025
1 parent 89549eb commit 511b924
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/common/components/forms/FormLabelStart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,39 @@ import { GoodTooltip } from '~/common/components/GoodTooltip';
import WarningRoundedIcon from '@mui/icons-material/WarningRounded';


const _styles = {
label: {
flexWrap: 'nowrap',
whiteSpace: 'nowrap',
} as const,
labelClickable: {
flexWrap: 'nowrap',
whiteSpace: 'nowrap',
cursor: 'pointer',
textDecoration: 'underline',
} as const,
} as const;


/**
* Shared label part (left side)
*/
const FormLabelStartBase = (props: {
export const FormLabelStart = React.memo(function FormLabelStartBase(props: {
title: React.ReactNode,
description?: React.ReactNode,
tooltip?: React.ReactNode,
tooltipWarning?: boolean,
onClick?: (event: React.MouseEvent) => void,
sx?: SxProps,
}) =>
<div>
}) {
return <div>
{/* Title */}
<FormLabel
onClick={props.onClick}
sx={{
// minWidth: formLabelStartWidth,
flexWrap: 'nowrap',
whiteSpace: 'nowrap',
...(!!props.onClick && { cursor: 'pointer', textDecoration: 'underline' }),
...props.sx,
}}
sx={props.onClick ? _styles.labelClickable
: props.sx ? { ..._styles.label, ...props.sx }
: _styles.label
}
>
{props.title} {!!props.tooltip && (
<GoodTooltip title={props.tooltip} arrow placement='top'>
Expand All @@ -53,6 +64,4 @@ const FormLabelStartBase = (props: {
</FormHelperText>
)}
</div>;
FormLabelStartBase.displayName = 'FormLabelStart';

export const FormLabelStart = React.memo(FormLabelStartBase);
});

0 comments on commit 511b924

Please sign in to comment.