diff --git a/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Grouped_Options.png b/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Grouped_Options.png index 746554432..c13c7d49f 100644 Binary files a/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Grouped_Options.png and b/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Grouped_Options.png differ diff --git a/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Trailing_Note.png b/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Trailing_Note.png new file mode 100644 index 000000000..7c2e96c24 Binary files /dev/null and b/packages/ui/.loki/reference/chrome_minimal_Components_SelectField_With_Trailing_Note.png differ diff --git a/packages/ui/__stories__/SelectField.stories.tsx b/packages/ui/__stories__/SelectField.stories.tsx index 70ae59600..3592794c0 100644 --- a/packages/ui/__stories__/SelectField.stories.tsx +++ b/packages/ui/__stories__/SelectField.stories.tsx @@ -94,6 +94,16 @@ WithHelperText.args = { helperText: 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.', } +export const WithTrailingNote = Template.bind({}) +WithTrailingNote.args = { + options: [ + { value: 'luke_skywalker', label: 'Luke Skywalker', trailingNote: 'Note' }, + { value: 'custom', label: 'Customized Side Note', trailingNote: Custom Note }, + { value: 'one_word', label: LONG_ONE_WORD_TEXT, trailingNote: 'Note' }, + { value: 'multiple_word', label: LONG_MULTIPLE_WORD_TEXT, trailingNote: 'Note' }, + ], +} + export const Clearable = Template.bind({}) Clearable.args = { isClearable: true, diff --git a/packages/ui/src/Select/Common.module.scss b/packages/ui/src/Select/Common.module.scss index 75e094905..524231761 100644 --- a/packages/ui/src/Select/Common.module.scss +++ b/packages/ui/src/Select/Common.module.scss @@ -54,3 +54,16 @@ $selectHorizontalPadding: c.$grid * 3; // color: c.$colorPrimary; } } + +.valueContainer { + display: flex; + justify-content: space-between; + align-items: center; + width: 100%; + + .trailingNote { + flex-shrink: 0; + color: c.$colorTextSecondary; + margin-left: c.$grid * 2; + } +} diff --git a/packages/ui/src/Select/Common.tsx b/packages/ui/src/Select/Common.tsx index c01090bfb..16dd17843 100644 --- a/packages/ui/src/Select/Common.tsx +++ b/packages/ui/src/Select/Common.tsx @@ -5,9 +5,10 @@ import cn from 'classnames' import { Icon } from '../Icon' import { IconButton } from '../IconButton' +import { TruncatedText } from '../TruncatedText' +import { SelectFieldOption } from './helpers' import styles from './Common.module.scss' -import { TruncatedText } from '../TruncatedText' const DropdownIndicator: typeof rsComponents.DropdownIndicator = ({ selectProps }) => ( { const Option: typeof rsComponents.Option = (props) => ( - +
+ + {(props.data as SelectFieldOption)?.trailingNote} +
) // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -64,7 +68,10 @@ const IndicatorSeparator: typeof rsComponents.IndicatorSeparator = () => null const SingleValue: typeof rsComponents.SingleValue = ({ children, ...props }) => ( - +
+ + {(props.data as SelectFieldOption)?.trailingNote} +
) diff --git a/packages/ui/src/Select/helpers.ts b/packages/ui/src/Select/helpers.ts index ec49577a6..4daa08e92 100644 --- a/packages/ui/src/Select/helpers.ts +++ b/packages/ui/src/Select/helpers.ts @@ -1,3 +1,4 @@ +import { ReactNode } from 'react' import { Options, GroupBase } from 'react-select' import { canUseDOM } from '../utils/ssr' @@ -5,6 +6,7 @@ import { canUseDOM } from '../utils/ssr' export type SelectFieldOption = { label: string value: V + trailingNote?: ReactNode } export type SelectFieldOptionsMap = {