Files
twenty_crm/packages/twenty-front/src/modules/ui/input/components/SelectControl.tsx
Baptiste Devessier b3f95d6db9 Ensure the text of select control is aligned on the left (#8238)
Fixes:


![image](https://github.com/user-attachments/assets/900596ed-1426-49cd-a2f3-4b81eacbb7d0)

The regression is due a recent change I made to the SelectControl
component: https://github.com/twentyhq/twenty/pull/8125.

The SelectControls get applied `text-align: center` due to the styles
`react-datepicker` applies to the header component. My grid
implementation makes the label take all the available width. I could
have let it take an `auto` width, but I think it's better to set the
`text-align` property and ensure the `SelectControl` component behaves
predictably.
2024-10-31 12:03:45 +01:00

67 lines
2.0 KiB
TypeScript

import { SelectOption } from '@/ui/input/components/Select';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import {
IconChevronDown,
isDefined,
OverflowingTextWithTooltip,
} from 'twenty-ui';
const StyledControlContainer = styled.div<{
disabled?: boolean;
hasIcon: boolean;
}>`
display: grid;
grid-template-columns: ${({ hasIcon }) =>
hasIcon ? 'auto 1fr auto' : '1fr auto'};
align-items: center;
gap: ${({ theme }) => theme.spacing(1)};
box-sizing: border-box;
height: ${({ theme }) => theme.spacing(8)};
max-width: 100%;
padding: 0 ${({ theme }) => theme.spacing(2)};
background-color: ${({ theme }) => theme.background.transparent.lighter};
border: 1px solid ${({ theme }) => theme.border.color.medium};
border-radius: ${({ theme }) => theme.border.radius.sm};
color: ${({ disabled, theme }) =>
disabled ? theme.font.color.tertiary : theme.font.color.primary};
cursor: ${({ disabled }) => (disabled ? 'not-allowed' : 'pointer')};
text-align: left;
`;
const StyledIconChevronDown = styled(IconChevronDown)<{
disabled?: boolean;
}>`
color: ${({ disabled, theme }) =>
disabled ? theme.font.color.extraLight : theme.font.color.tertiary};
`;
type SelectControlProps = {
selectedOption: SelectOption<string | number | null>;
isDisabled?: boolean;
};
export const SelectControl = ({
selectedOption,
isDisabled,
}: SelectControlProps) => {
const theme = useTheme();
return (
<StyledControlContainer
disabled={isDisabled}
hasIcon={isDefined(selectedOption.Icon)}
>
{isDefined(selectedOption.Icon) ? (
<selectedOption.Icon
color={isDisabled ? theme.font.color.light : theme.font.color.primary}
size={theme.icon.size.md}
stroke={theme.icon.stroke.sm}
/>
) : null}
<OverflowingTextWithTooltip text={selectedOption.label} />
<StyledIconChevronDown disabled={isDisabled} size={theme.icon.size.md} />
</StyledControlContainer>
);
};