The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Migrate currency picker to Twenty UI (#27127)
Raphaël Bosif05c0cdf754b
diff --git a/packages/twenty-docs/docs.json b/packages/twenty-docs/docs.jsonindex 3a414c81004..1f5edde3212 100644--- a/packages/twenty-docs/docs.json+++ b/packages/twenty-docs/docs.json@@ -637,6 +637,7 @@"ui/components/avatar-group","ui/components/callout","ui/components/command-block",+ "ui/components/currency-picker","ui/components/image-input","ui/components/inline-banner","ui/components/json-tree",diff --git a/packages/twenty-docs/navigation/base-structure.json b/packages/twenty-docs/navigation/base-structure.jsonindex f4a1f0580d9..e72080e219a 100644--- a/packages/twenty-docs/navigation/base-structure.json+++ b/packages/twenty-docs/navigation/base-structure.json@@ -655,6 +655,7 @@"ui/components/avatar-group","ui/components/callout","ui/components/command-block",+ "ui/components/currency-picker","ui/components/image-input","ui/components/inline-banner","ui/components/json-tree",diff --git a/packages/twenty-docs/snippets/ui/generated/components/currency-picker.mdx b/packages/twenty-docs/snippets/ui/generated/components/currency-picker.mdxnew file mode 100644index 00000000000..4b9b2929f8f--- /dev/null+++ b/packages/twenty-docs/snippets/ui/generated/components/currency-picker.mdx@@ -0,0 +1,76 @@+{/*+ * _____ _+ *|_ _|_ _____ _ __ | |_ _ _+ * | | \ \ /\ / / _ \ '_ \| __| | | | Auto-generated file+ * | | \ V V / __/ | | | |_| |_| | DO NOT EDIT - changes will be overwritten+ * |_| \_/\_/ \___|_| |_|\__|\__, | Generated by: npx nx generate:ui twenty-docs+ * |___/+ *+ * This file is generated from the documentation data in packages/twenty-ui/generated.+ * To update it, edit the component prop types or design tokens in twenty-ui and run:+ * npx nx generate:ui twenty-docs+ */}++### CurrencyPicker.Trigger++<ParamField body="Trigger.className" type="string | ((state: PopoverTriggerState) => string | undefined)">+ CSS class applied to the element, or a function that+ returns a class based on the component's state.+</ParamField>++<ParamField body="Trigger.disabled" type="boolean">+ Disables opening the picker.+</ParamField>++<ParamField body="Trigger.id" type="string">+ ID forwarded to the trigger button.+</ParamField>++<ParamField body="Trigger.nativeButton" type="boolean" default="true">+ Whether the component renders a native `<button>` element when replacing it+ via the `render` prop.+ Set to `false` if the rendered element is not a button (e.g. `<div>`).+</ParamField>++<ParamField body="Trigger.render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>">+ Replaces the native trigger button. Forward the supplied props and ref when rendering a custom component.+</ParamField>++<ParamField body="Trigger.style" type="CSSProperties | ((state: PopoverTriggerState) => CSSProperties | undefined)">+ Style applied to the element, or a function that+ returns a style object based on the component's state.+</ParamField>++<ParamField body="Trigger.value" type="string" required>+ Required currency code displayed beside the chevron. The application chooses its initial value and any fallback.+</ParamField>++### CurrencyPicker.Options++<ParamField body="Options.currencies" type="readonly CurrencyPickerOption[]" required>+ Available currency codes and names, in catalogue order. Each code must be unique. An option can be disabled.+</ParamField>++<ParamField body="Options.disabled" type="boolean" default="false">+ Disables search and every currency option.+</ParamField>++<ParamField body="Options.emptyLabel" type="string" default="No results">+ Text announced when no currencies match. Defaults to No results.+</ParamField>++<ParamField body="Options.onValueChange" type="(code: string) => void" required>+ Called with the code chosen by pointer or keyboard. The application updates the selected value.+</ParamField>++<ParamField body="Options.render" type="ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>">+ Replaces the non-interactive root div. Forward the supplied props and ref when rendering a custom component.+</ParamField>++<ParamField body="Options.searchLabel" type="string" default="Search">+ Search placeholder and accessible name. Defaults to Search.+</ParamField>++<ParamField body="Options.value" type="string">+ Selected currency code. Its matching row appears first and is marked pressed.+</ParamField>diff --git a/packages/twenty-docs/ui/components/currency-picker.mdx b/packages/twenty-docs/ui/components/currency-picker.mdxnew file mode 100644index 00000000000..e5ed7b14d82--- /dev/null+++ b/packages/twenty-docs/ui/components/currency-picker.mdx@@ -0,0 +1,77 @@+---+title: CurrencyPicker+description: A compact currency trigger and searchable currency options for picker dropdowns.+---++import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';+import CurrencyPickerReference from '/snippets/ui/generated/components/currency-picker.mdx';++`CurrencyPicker` provides a compact selected currency code and searchable currency options. Import it from `twenty-ui/components` and compose it inside a [Dropdown](/ui/components/dropdown) with `type="picker"`.++<StoryEmbed+ storyId="ui-input-currencypicker--documentation"+ title="Currency picker"+ height={380}+/>++## Usage++Supply the available currencies and the selected code. `Options` calls `onValueChange` with the chosen code. The trigger requires a currency code through `value`; your application chooses its initial value and any fallback.++```tsx+import { useState } from 'react';+import { CurrencyPicker, Dropdown } from 'twenty-ui/components';++const CURRENCIES = [+ { code: 'EUR', name: 'Euro' },+ { code: 'USD', name: 'US Dollar' },+];++export const InvoiceCurrency = () => {+ const [currencyCode, setCurrencyCode] = useState('USD');++ return (+ <Dropdown.Root type="picker">+ <CurrencyPicker.Trigger+ value={currencyCode}+ aria-label={`Invoice currency: ${currencyCode}`}+ />+ <Dropdown.Content aria-label="Invoice currency" width={280}>+ <CurrencyPicker.Options+ currencies={CURRENCIES}+ value={currencyCode}+ onValueChange={setCurrencyCode}+ searchLabel="Search currencies"+ emptyLabel="No currencies found"+ />+ </Dropdown.Content>+ </Dropdown.Root>+ );+};+```++`Trigger` and `Options` can be used separately. Use `Options` with a `Dropdown.Trigger` rendering a Twenty UI `Button` when the host needs a full button instead of the compact code control.++## Search and selection++Search ignores surrounding whitespace and matches currency codes, names, and the displayed `Name (CODE)` label without case sensitivity, using the same matching rules in every browser locale. Results keep the supplied order, with the selected currency first when it matches the search. Each row shows `Name (CODE)` and exposes its selected state through `aria-pressed`.++Search receives focus when the picker opens. With a nonempty search, Enter selects the first enabled match. With an empty search, Enter does nothing until ArrowDown moves focus to an option. Empty results keep the picker open and show the empty label in a status region that stays in place while the picker is open, so screen readers announce it. Selection closes a single-selection dropdown; Escape and outside interaction use the dropdown's existing dismissal and focus behavior.++Set `disabled` on a currency to keep its row visible while preventing selection. `Trigger.disabled` prevents opening; `Options.disabled` disables search and all options in an already open host.++## Ownership and labels++The picker owns searching, selected-first ordering, and currency selection. The application owns the currency catalogue, amount editing, formatting, default currency, persistence, and dropdown lifecycle. Currency names are data supplied by the caller.++`searchLabel` defaults to `Search` and provides both the search placeholder and accessible name. `emptyLabel` defaults to `No results`. Supply translated labels and accessible names from your application. Give the trigger an accessible name that includes its visible currency code, such as `Invoice currency: USD`, and give the dropdown content a name that describes the currency being selected.++Native attributes, `className`, `style`, `ref`, and `render` apply to each part's root element. The trigger forwards the shared dropdown trigger interface, except `children`, hover opening (`openOnHover`, `delay`, `closeDelay`), and the popover `handle` and `payload` props; the options root is a div by default.++## Front-component renderer++React and Preact sandbox fixtures verify code presentation and the disabled trigger. Opening the popup currently fails in the shared Dropdown foundation because the worker cannot read viewport width. Search, currency selection, popup focus, and closing are not supported in that sandbox until this limitation is resolved. Ordinary React hosts exercise the complete interaction.++## Props++<CurrencyPickerReference />diff --git a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsxindex 9f40f80d4c9..08d43e21189 100644--- a/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx+++ b/packages/twenty-front-component-renderer/src/__stories__/TwentyUiGallery.stories.tsx@@ -1,3 +1,4 @@+import { currencyPickerSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/currencyPickerSandboxFailureTest';import { breadcrumbTest } from '@/__stories__/twenty-ui-gallery/utils/breadcrumbTest';import { imageInputTest } from '@/__stories__/twenty-ui-gallery/utils/imageInputTest';import { overflowingListEventIsolationFailureTest } from '@/__stories__/twenty-ui-gallery/utils/overflowingListEventIsolationFailureTest';@@ -643,3 +644,15 @@ export const ImageInputPreact: Story = createGalleryStory({runtime: 'preact',play: imageInputTest,});++export const CurrencyPickerReactPopupFailure: Story = createGalleryStory({+ frontComponentBundleName: 'twenty-ui-currency-picker',+ runtime: 'react',+ play: currencyPickerSandboxFailureTest,+});++export const CurrencyPickerPreactPopupFailure: Story = createGalleryStory({+ frontComponentBundleName: 'twenty-ui-currency-picker',+ runtime: 'preact',+ play: currencyPickerSandboxFailureTest,+});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-currency-picker.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-currency-picker.front-component.tsxnew file mode 100644index 00000000000..7cfba72463d--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-currency-picker.front-component.tsx@@ -0,0 +1,77 @@+import { useState } from 'react';+import { defineFrontComponent } from 'twenty-sdk/define';+import { CurrencyPicker, Dropdown } from 'twenty-ui/components';+import { Text } from 'twenty-ui/primitives/typography';++import { TwentyUiGalleryCard } from '@/__stories__/shared/front-components/twenty-ui-gallery-card';++const CURRENCIES = [+ { code: 'CAD', name: 'Canadian Dollar' },+ { code: 'EUR', name: 'Euro' },+ { code: 'JPY', name: 'Japanese Yen', disabled: true },+ { code: 'USD', name: 'US Dollar' },+];++const CurrencyPickerExample = () => {+ const [primaryCurrency, setPrimaryCurrency] = useState('EUR');+ const [secondaryCurrency, setSecondaryCurrency] = useState('USD');++ return (+ <TwentyUiGalleryCard title="Currency picker">+ <Dropdown.Root type="picker">+ <CurrencyPicker.Trigger+ aria-label="Primary currency"+ value={primaryCurrency}+ />+ <Dropdown.Content aria-label="Primary currencies">+ <CurrencyPicker.Options+ currencies={CURRENCIES}+ value={primaryCurrency}+ searchLabel="Search primary currencies"+ emptyLabel="No matching currencies"+ onValueChange={setPrimaryCurrency}+ />+ </Dropdown.Content>+ </Dropdown.Root>+ <Dropdown.Root type="picker">+ <CurrencyPicker.Trigger+ aria-label="Secondary currency"+ value={secondaryCurrency}+ />+ <Dropdown.Content aria-label="Secondary currencies">+ <CurrencyPicker.Options+ currencies={CURRENCIES}+ value={secondaryCurrency}+ searchLabel="Search secondary currencies"+ onValueChange={setSecondaryCurrency}+ />+ </Dropdown.Content>+ </Dropdown.Root>+ <Dropdown.Root type="picker">+ <CurrencyPicker.Trigger+ aria-label="Disabled currency"+ value="EUR"+ disabled+ />+ <Dropdown.Content aria-label="Disabled currencies">+ <CurrencyPicker.Options+ currencies={CURRENCIES}+ value="EUR"+ disabled+ onValueChange={() => undefined}+ />+ </Dropdown.Content>+ </Dropdown.Root>+ <Text role="status">+ Primary: {primaryCurrency}; Secondary: {secondaryCurrency}+ </Text>+ </TwentyUiGalleryCard>+ );+};++export default defineFrontComponent({+ universalIdentifier: 'b613ee94-d9d9-477a-b76a-606637c81c11',+ name: 'twenty-ui-currency-picker',+ description: 'Currency search and independent selections in the sandbox',+ component: CurrencyPickerExample,+});diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/currencyPickerSandboxFailureTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/currencyPickerSandboxFailureTest.tsnew file mode 100644index 00000000000..bede9c8c1a8--- /dev/null+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/currencyPickerSandboxFailureTest.ts@@ -0,0 +1,40 @@+import { expect, userEvent, within } from 'storybook/test';++import { expectFrontComponentMounted } from '@/__stories__/shared/test-utils/matchers/expectFrontComponentMounted';+import { SANDBOX_ERROR_PATTERNS } from '@/__stories__/twenty-ui-gallery/constants/SANDBOX_ERROR_PATTERNS';+import { type TwentyUiGalleryPlayFunction } from '@/__stories__/twenty-ui-gallery/types/TwentyUiGalleryPlayFunction';+import { createSandboxFailureTest } from '@/__stories__/twenty-ui-gallery/utils/createSandboxFailureTest';++const primaryCurrencyPickerOpenFailureTest = createSandboxFailureTest({+ trigger: { role: 'button', name: 'Primary currency' },+ requiredErrors: [SANDBOX_ERROR_PATTERNS.VIEWPORT_WIDTH],+});++export const currencyPickerSandboxFailureTest: TwentyUiGalleryPlayFunction =+ async (context) => {+ const canvas = within(context.canvasElement);+ const page = within(context.canvasElement.ownerDocument.body);+ await expectFrontComponentMounted(canvas);++ const primaryTrigger = canvas.getByRole('button', {+ name: 'Primary currency',+ });+ const secondaryTrigger = canvas.getByRole('button', {+ name: 'Secondary currency',+ });+ const disabledTrigger = canvas.getByRole('button', {+ name: 'Disabled currency',+ });++ expect(primaryTrigger).toHaveTextContent('EUR');+ expect(secondaryTrigger).toHaveTextContent('USD');+ expect(disabledTrigger).toBeDisabled();+ await userEvent.click(disabledTrigger);++ await primaryCurrencyPickerOpenFailureTest(context);++ expect(disabledTrigger).toHaveAttribute('aria-expanded', 'false');+ expect(+ page.queryByRole('dialog', { name: 'Disabled currencies' }),+ ).toBeNull();+ };diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/CurrencyFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/CurrencyFieldInput.stories.tsxindex 8cad82925ec..5c684e7c5fc 100644--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/CurrencyFieldInput.stories.tsx+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/CurrencyFieldInput.stories.tsx@@ -218,6 +218,29 @@ export const ClickOutsideKeepsCentsWithCommasAndDot: Story = {},};+export const CurrencyPickerReopensOnEnter: Story = {+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);++ await canvas.findByTestId('is-ready-marker');+ const trigger = canvas.getByRole('button', { name: 'Currency: USD' });++ await userEvent.click(trigger);+ await body.findByRole('dialog', { name: 'Currency' });+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(body.queryByRole('dialog')).toBeNull());+ await waitFor(() => expect(trigger).toHaveFocus());++ await userEvent.keyboard('{Enter}');++ const reopenedPopup = await body.findByRole('dialog', { name: 'Currency' });+ await waitFor(() => expect(reopenedPopup).toBeVisible());+ expect(handleEnterMocked).not.toHaveBeenCalled();+ await userEvent.keyboard('{Escape}');+ },+};+export const EscapeKeepsCents: Story = {play: async ({ canvasElement }) => {const canvas = within(canvasElement);diff --git a/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx b/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsxindex 7ee745a662e..6cc892f0008 100644--- a/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx+++ b/packages/twenty-front/src/modules/page-layout/widgets/field/components/__stories__/FieldWidget.stories.tsx@@ -1032,7 +1032,9 @@ export const NestedCurrencyPickerKeepsFieldOpen: Story = {const amountInput = await body.findByPlaceholderText('Currency');await userEvent.clear(amountInput);await userEvent.type(amountInput, '6000000');- await userEvent.click(await body.findByRole('button', { name: 'USD' }));+ await userEvent.click(+ await body.findByRole('button', { name: 'Currency: USD' }),+ );await body.findByRole('dialog', { name: 'Currency' });await userEvent.click(outsideButton);@@ -1042,7 +1044,9 @@ export const NestedCurrencyPickerKeepsFieldOpen: Story = {body.queryByRole('dialog', { name: 'Currency' }),).not.toBeInTheDocument();});- await expect(body.getByRole('button', { name: 'USD' })).toBeVisible();+ await expect(+ body.getByRole('button', { name: 'Currency: USD' }),+ ).toBeVisible();await expect(amountInput).toHaveValue('6,000,000');await userEvent.clear(amountInput);@@ -1051,7 +1055,7 @@ export const NestedCurrencyPickerKeepsFieldOpen: Story = {await waitFor(() => {expect(- body.queryByRole('button', { name: 'USD' }),+ body.queryByRole('button', { name: 'Currency: USD' }),).not.toBeInTheDocument();});await expect(canvas.getByText('5m')).toBeVisible();diff --git a/packages/twenty-front/src/modules/ui/field/input/components/CurrencyInput.tsx b/packages/twenty-front/src/modules/ui/field/input/components/CurrencyInput.tsxindex bd144155247..ff04293c868 100644--- a/packages/twenty-front/src/modules/ui/field/input/components/CurrencyInput.tsx+++ b/packages/twenty-front/src/modules/ui/field/input/components/CurrencyInput.tsx@@ -7,9 +7,7 @@ import { useNumberFormat } from '@/localization/hooks/useNumberFormat';import { CURRENCIES } from '@/settings/data-model/constants/Currencies';import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';import { CURRENCY_MICROS_DECIMAL_PLACES } from '@/ui/field/input/constants/CurrencyMicrosDecimalPlaces';-import { type Currency } from '@/ui/input/components/internal/types/Currency';import { IMaskInput } from 'react-imask';-import { type IconComponent } from 'twenty-ui/icon';import { useTheme, themeCssVariables } from 'twenty-ui/theme';import { getSeparatorsForNumberFormat } from '~/utils/format/getSeparatorsForNumberFormat';@@ -106,8 +104,8 @@ export const CurrencyInput = ({onChange?.(value);};- const handleCurrencyChange = (currency: Currency) => {- onSelect?.(currency.value);+ const handleCurrencyChange = (newCurrencyCode: string) => {+ onSelect?.(newCurrencyCode);};useRegisterInputEvents({@@ -127,12 +125,12 @@ export const CurrencyInput = ({setInternalText(value);}, [value]);- const Icon: IconComponent = currency?.Icon;+ const Icon = currency?.Icon;return (<StyledContainer ref={wrapperRef}><CurrencyPickerDropdownButton- selectedCurrencyCode={currency?.value ?? ''}+ selectedCurrencyCode={currencyCode}onChange={handleCurrencyChange}/><StyledIcon>diff --git a/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx b/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsxindex 84b6e8d0498..e4ba6ffede4 100644--- a/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx+++ b/packages/twenty-front/src/modules/ui/input/components/__stories__/OptionPickers.stories.tsx@@ -1,5 +1,4 @@import { ConfigVariableDatabaseInput } from '@/settings/admin-panel/config-variables/components/ConfigVariableDatabaseInput';-import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';import { DropdownMenuInnerSelect } from '@/ui/layout/dropdown/components/DropdownMenuInnerSelect';import { type Meta, type StoryObj } from '@storybook/react-vite';@@ -8,16 +7,6 @@ import { expect, userEvent, waitFor, within } from 'storybook/test';import { ComponentDecorator } from 'twenty-ui/testing';import { ConfigVariableType } from '~/generated-admin/graphql';-const CurrencyExample = () => {- const [currency, setCurrency] = useState('USD');- return (- <CurrencyPickerDropdownButton- selectedCurrencyCode={currency}- onChange={(option) => setCurrency(option.value)}- />- );-};-const PhoneExample = () => {const [country, setCountry] = useState('US');return (@@ -64,38 +53,6 @@ const meta: Meta = {export default meta;type Story = StoryObj;-export const CurrencySearchAndKeyboard: Story = {- render: () => <CurrencyExample />,- play: async ({ canvasElement }) => {- const canvas = within(canvasElement);- const body = within(canvasElement.ownerDocument.body);- const trigger = canvas.getByRole('button');- await userEvent.click(trigger);- expect(await body.findByRole('dialog', { name: 'Currency' })).toBeVisible();- const search = await body.findByRole('searchbox', { name: 'Search' });- await userEvent.type(search, 'zzzzzz');- expect(await body.findByText('No results')).toBeVisible();- await userEvent.clear(search);- await userEvent.type(search, 'euro');- const euro = await body.findByRole('button', { name: /Euro \(EUR\)/ });- expect(- body.queryByRole('button', { pressed: true }),- ).not.toBeInTheDocument();- await waitFor(() => expect(euro).toHaveAttribute('data-highlighted'));- await userEvent.keyboard('{Enter}');- await waitFor(() =>- expect(body.queryByRole('dialog')).not.toBeInTheDocument(),- );- expect(trigger).toHaveTextContent('EUR');- await waitFor(() => expect(trigger).toHaveFocus());- await userEvent.click(trigger);- expect(await body.findByRole('searchbox', { name: 'Search' })).toHaveValue(- '',- );- await userEvent.keyboard('{Escape}');- },-};-export const PhoneSearchAndSelection: Story = {render: () => <PhoneExample />,play: async ({ canvasElement }) => {diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton.tsx b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton.tsxindex 4469a7cdd65..aa12f5f8174 100644--- a/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton.tsx+++ b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton.tsx@@ -1,73 +1,44 @@-import { styled } from '@linaria/react';import { t } from '@lingui/core/macro';--import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';-import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';+import { type KeyboardEvent, useId } from 'react';import { CurrencyCode } from 'twenty-shared/constants';-import { Dropdown } from 'twenty-ui/components';+import { CurrencyPicker } from 'twenty-ui/components';-import { CURRENCIES } from '@/settings/data-model/constants/Currencies';-import { type Currency } from '@/ui/input/components/internal/types/Currency';-import { IconChevronDown } from 'twenty-ui/icon';-import { useTheme, themeCssVariables } from 'twenty-ui/theme';-import { CurrencyPickerDropdownSelect } from './CurrencyPickerDropdownSelect';-const StyledDropdownButtonContainer = styled.div`- align-items: center;- border-right: 1px solid ${themeCssVariables.border.color.medium};- color: ${({ color }) => color ?? 'none'};- cursor: pointer;- display: flex;- height: 32px;- padding-left: ${themeCssVariables.spacing[2]};- padding-right: ${themeCssVariables.spacing[2]};- user-select: none;- &:hover {- background-color: ${themeCssVariables.background.transparent.light};- }-`;+import { CURRENCY_PICKER_CURRENCIES } from '@/ui/input/components/internal/currency/constants/CurrencyPickerCurrencies';+import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent';+import { DropdownRoot } from '@/ui/layout/dropdown/components/DropdownRoot';-const StyledIconContainer = styled.div`- align-items: center;- color: ${themeCssVariables.font.color.tertiary};- display: flex;- font-weight: ${themeCssVariables.font.weight.medium};- gap: ${themeCssVariables.spacing[1]};- justify-content: center;+type CurrencyPickerDropdownButtonProps = {+ selectedCurrencyCode: string;+ onChange: (currencyCode: string) => void;+};- svg {- align-items: center;- display: flex;- height: 16px;- justify-content: center;+const keepEnterAwayFromFieldHotkeys = (+ event: KeyboardEvent<HTMLButtonElement>,+) => {+ if (event.key !== 'Enter') {+ return;}-`;++ event.stopPropagation();+};export const CurrencyPickerDropdownButton = ({selectedCurrencyCode,onChange,-}: {- selectedCurrencyCode: string;- onChange: (currency: Currency) => void;-}) => {- const theme = useTheme();- const dropdownId = 'currency-picker-dropdown-id';-- const currency = CURRENCIES.find(- ({ value }) => value === selectedCurrencyCode,+}: CurrencyPickerDropdownButtonProps) => {+ const dropdownId = useId();+ const selectedCurrency = CURRENCY_PICKER_CURRENCIES.find(+ ({ code }) => code === selectedCurrencyCode,);-- const currencyCode = currency?.value ?? CurrencyCode.USD;+ const currencyCode = selectedCurrency?.code ?? CurrencyCode.USD;return (<DropdownRoot dropdownId={dropdownId} type="picker">- <Dropdown.Trigger render={<div />} nativeButton={false}>- <StyledDropdownButtonContainer>- <StyledIconContainer>- {currencyCode}- <IconChevronDown size={theme.icon.size.sm} />- </StyledIconContainer>- </StyledDropdownButtonContainer>- </Dropdown.Trigger>+ <CurrencyPicker.Trigger+ value={currencyCode}+ aria-label={t`Currency: ${currencyCode}`}+ onKeyDown={keepEnterAwayFromFieldHotkeys}+ /><DropdownContentside="bottom"align="start"@@ -75,9 +46,12 @@ export const CurrencyPickerDropdownButton = ({alignOffset={0}aria-label={t`Currency`}>- <CurrencyPickerDropdownSelect- selectedCurrency={currency}- onChange={onChange}+ <CurrencyPicker.Options+ currencies={CURRENCY_PICKER_CURRENCIES}+ value={selectedCurrency?.code}+ onValueChange={onChange}+ searchLabel={t`Search`}+ emptyLabel={t`No results`}/></DropdownContent></DropdownRoot>diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownSelect.tsx b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownSelect.tsxdeleted file mode 100644index 4fcf25e0cc7..00000000000--- a/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/CurrencyPickerDropdownSelect.tsx+++ /dev/null@@ -1,75 +0,0 @@-import { CURRENCIES } from '@/settings/data-model/constants/Currencies';-import { type Currency } from '@/ui/input/components/internal/types/Currency';-import { t } from '@lingui/core/macro';-import { useMemo, useState } from 'react';-import { isDefined, isNonEmptyArray } from 'twenty-shared/utils';-import { Dropdown } from 'twenty-ui/components';-import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';--export const CurrencyPickerDropdownSelect = ({- selectedCurrency,- onChange,-}: {- selectedCurrency?: Currency;- onChange: (currency: Currency) => void;-}) => {- const [searchFilter, setSearchFilter] = useState<string>('');-- const filteredCurrencies = useMemo(- () =>- CURRENCIES.filter(- ({ value, label }) =>- value- .toLocaleLowerCase()- .includes(searchFilter.toLocaleLowerCase()) ||- label.toLocaleLowerCase().includes(searchFilter.toLocaleLowerCase()),- ),- [searchFilter],- );-- const isSelectedCurrencyMatchingSearch =- isDefined(selectedCurrency) &&- filteredCurrencies.some(({ value }) => value === selectedCurrency.value);-- return (- <>- <Dropdown.Search- value={searchFilter}- placeholder={t`Search`}- aria-label={t`Search`}- onValueChange={setSearchFilter}- />- <Dropdown.Separator />- <Dropdown.Section scrollable>- {!isNonEmptyArray(filteredCurrencies) ? (- <Dropdown.Empty>{t`No results`}</Dropdown.Empty>- ) : (- <>- {isSelectedCurrencyMatchingSearch && (- <Dropdown.OptionItem- key={selectedCurrency.value}- onSelect={() => onChange(selectedCurrency)}- selected={true}- >- {selectedCurrency.label}- </Dropdown.OptionItem>- )}- {filteredCurrencies.map((item) =>- selectedCurrency?.value === item.value ? null : (- <Dropdown.OptionItem- key={item.value}- onSelect={() => onChange(item)}- selected={selectedCurrency?.value === item.value}- >- <OverflowingTextWithTooltip- text={`${item.label} (${item.value})`}- />- </Dropdown.OptionItem>- ),- )}- </>- )}- </Dropdown.Section>- </>- );-};diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/__stories__/CurrencyPickerDropdownButton.stories.tsx b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/__stories__/CurrencyPickerDropdownButton.stories.tsxnew file mode 100644index 00000000000..a487ca39bb8--- /dev/null+++ b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/__stories__/CurrencyPickerDropdownButton.stories.tsx@@ -0,0 +1,177 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';+import { ComponentDecorator } from 'twenty-ui/testing';++import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';++import { CurrencyPickerDropdownButtonExample } from './CurrencyPickerDropdownButtonExample';++const onCurrencyChange = fn<(currencyCode: string) => void>();++const meta: Meta<typeof CurrencyPickerDropdownButton> = {+ title: 'UI/Input/CurrencyPickerDropdownButton',+ component: CurrencyPickerDropdownButton,+ decorators: [ComponentDecorator],+ args: {+ selectedCurrencyCode: 'USD',+ onChange: onCurrencyChange,+ },+ render: ({ selectedCurrencyCode, onChange }) => (+ <CurrencyPickerDropdownButtonExample+ key={selectedCurrencyCode}+ selectedCurrencyCode={selectedCurrencyCode}+ onChange={onChange}+ />+ ),+};++export default meta;+type Story = StoryObj<typeof CurrencyPickerDropdownButton>;++export const SearchPreservesCurrencyCallback: Story = {+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const trigger = canvas.getByRole('button', { name: 'Currency: USD' });++ await userEvent.click(trigger);+ const dialog = await body.findByRole('dialog', { name: 'Currency' });+ await waitFor(() => expect(dialog).toBeVisible());+ const search = await body.findByRole('searchbox', { name: 'Search' });+ await waitFor(() => expect(search).toHaveFocus());+ await userEvent.type(search, 'zzzzzz');+ expect(await body.findByText('No results')).toBeVisible();+ await userEvent.clear(search);+ await userEvent.type(search, 'euro');+ const euro = await body.findByRole('button', { name: 'Euro (EUR)' });+ expect(+ body.queryByRole('button', { pressed: true }),+ ).not.toBeInTheDocument();+ await waitFor(() => expect(euro).toHaveAttribute('data-highlighted'));+ await userEvent.keyboard('{Enter}');++ await waitFor(() =>+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),+ );+ expect(onCurrencyChange).toHaveBeenCalledTimes(1);+ expect(onCurrencyChange).toHaveBeenCalledWith('EUR');+ expect(trigger).toHaveTextContent('EUR');+ expect(trigger).toHaveAccessibleName('Currency: EUR');+ await waitFor(() => expect(trigger).toHaveFocus());++ await userEvent.click(trigger);+ expect(await body.findByRole('searchbox', { name: 'Search' })).toHaveValue(+ '',+ );+ expect(+ await body.findByRole('button', { name: 'Euro (EUR)' }),+ ).toHaveAttribute('aria-pressed', 'true');+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(trigger).toHaveFocus());+ },+};++export const IndependentInstances: Story = {+ render: ({ onChange }) => (+ <>+ <CurrencyPickerDropdownButtonExample+ selectedCurrencyCode="USD"+ onChange={onChange}+ />+ <CurrencyPickerDropdownButtonExample+ selectedCurrencyCode="EUR"+ onChange={onChange}+ />+ </>+ ),+ play: async ({ canvasElement }) => {+ const canvas = within(canvasElement);+ const body = within(canvasElement.ownerDocument.body);+ const firstTrigger = canvas.getByRole('button', { name: 'Currency: USD' });+ const secondTrigger = canvas.getByRole('button', {+ name: 'Currency: EUR',+ });++ await userEvent.click(firstTrigger);+ expect(+ await body.findAllByRole('dialog', { name: 'Currency' }),+ ).toHaveLength(1);+ expect(secondTrigger).toHaveAttribute('aria-expanded', 'false');+ await userEvent.type(+ await body.findByRole('searchbox', { name: 'Search' }),+ 'jpy',+ );+ await userEvent.keyboard('{Enter}');+ await waitFor(() =>+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),+ );+ expect(firstTrigger).toHaveTextContent('JPY');+ expect(secondTrigger).toHaveTextContent('EUR');+ await waitFor(() => expect(firstTrigger).toHaveFocus());++ await userEvent.click(secondTrigger);+ expect(+ await body.findAllByRole('dialog', { name: 'Currency' }),+ ).toHaveLength(1);+ expect(firstTrigger).toHaveAttribute('aria-expanded', 'false');+ expect(await body.findByRole('searchbox', { name: 'Search' })).toHaveValue(+ '',+ );+ expect(+ await body.findByRole('button', { name: 'Euro (EUR)' }),+ ).toHaveAttribute('aria-pressed', 'true');+ await userEvent.type(+ body.getByRole('searchbox', { name: 'Search' }),+ 'gbp',+ );+ await userEvent.click(+ await body.findByRole('button', { name: /\(GBP\)$/ }),+ );+ await waitFor(() =>+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),+ );+ expect(firstTrigger).toHaveTextContent('JPY');+ expect(secondTrigger).toHaveTextContent('GBP');+ await waitFor(() => expect(secondTrigger).toHaveFocus());+ },+};++export const UnknownCurrencyUsesDisplayFallback: Story = {+ args: { selectedCurrencyCode: 'UNKNOWN' },+ play: async ({ canvasElement }) => {+ const body = within(canvasElement.ownerDocument.body);+ const trigger = within(canvasElement).getByRole('button', {+ name: 'Currency: USD',+ });++ await userEvent.click(trigger);+ const dialog = await body.findByRole('dialog', { name: 'Currency' });+ await waitFor(() => expect(dialog).toBeVisible());+ expect(+ body.queryByRole('button', { pressed: true }),+ ).not.toBeInTheDocument();+ const search = await body.findByRole('searchbox', { name: 'Search' });++ await waitFor(() => expect(search).toHaveFocus());+ await userEvent.keyboard('{Enter}');+ expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await waitFor(() => expect(dialog).toBeVisible());+ expect(onCurrencyChange).not.toHaveBeenCalled();++ await userEvent.type(search, 'usd');+ await userEvent.click(+ await body.findByRole('button', { name: /\(USD\)$/ }),+ );+ await waitFor(() =>+ expect(body.queryByRole('dialog')).not.toBeInTheDocument(),+ );+ expect(onCurrencyChange).toHaveBeenCalledTimes(1);+ expect(onCurrencyChange).toHaveBeenCalledWith('USD');+ await userEvent.click(trigger);+ expect(+ await body.findByRole('button', { name: /\(USD\)$/ }),+ ).toHaveAttribute('aria-pressed', 'true');+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(trigger).toHaveFocus());+ },+};diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/__stories__/CurrencyPickerDropdownButtonExample.tsx b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/__stories__/CurrencyPickerDropdownButtonExample.tsxnew file mode 100644index 00000000000..bbf5ac7411a--- /dev/null+++ b/packages/twenty-front/src/modules/ui/input/components/internal/currency/components/__stories__/CurrencyPickerDropdownButtonExample.tsx@@ -0,0 +1,24 @@+import { useState, type ComponentProps } from 'react';++import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';++type CurrencyPickerDropdownButtonExampleProps = ComponentProps<+ typeof CurrencyPickerDropdownButton+>;++export const CurrencyPickerDropdownButtonExample = ({+ selectedCurrencyCode,+ onChange,+}: CurrencyPickerDropdownButtonExampleProps) => {+ const [currencyCode, setCurrencyCode] = useState(selectedCurrencyCode);++ return (+ <CurrencyPickerDropdownButton+ selectedCurrencyCode={currencyCode}+ onChange={(newCurrencyCode) => {+ setCurrencyCode(newCurrencyCode);+ onChange(newCurrencyCode);+ }}+ />+ );+};diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/currency/constants/CurrencyPickerCurrencies.ts b/packages/twenty-front/src/modules/ui/input/components/internal/currency/constants/CurrencyPickerCurrencies.tsnew file mode 100644index 00000000000..dec66430046--- /dev/null+++ b/packages/twenty-front/src/modules/ui/input/components/internal/currency/constants/CurrencyPickerCurrencies.ts@@ -0,0 +1,8 @@+import { SETTINGS_FIELD_CURRENCY_CODES } from '@/settings/data-model/constants/SettingsFieldCurrencyCodes';+import { type CurrencyPickerOption } from 'twenty-ui/components';++export const CURRENCY_PICKER_CURRENCIES: readonly CurrencyPickerOption[] =+ Object.entries(SETTINGS_FIELD_CURRENCY_CODES).map(([code, { label }]) => ({+ code,+ name: label,+ }));diff --git a/packages/twenty-front/src/modules/ui/input/components/internal/types/Currency.ts b/packages/twenty-front/src/modules/ui/input/components/internal/types/Currency.tsindex 791c1a8e428..3f8b3b73c33 100644--- a/packages/twenty-front/src/modules/ui/input/components/internal/types/Currency.ts+++ b/packages/twenty-front/src/modules/ui/input/components/internal/types/Currency.ts@@ -1,5 +1,7 @@+import { type IconComponent } from 'twenty-ui/icon';+export type Currency = {label: string;value: string;- Icon: any;+ Icon: IconComponent;};diff --git a/packages/twenty-shared/src/constants/DocumentationPaths.ts b/packages/twenty-shared/src/constants/DocumentationPaths.tsindex d270ea15519..ce97e0ab5e2 100644--- a/packages/twenty-shared/src/constants/DocumentationPaths.ts+++ b/packages/twenty-shared/src/constants/DocumentationPaths.ts@@ -134,6 +134,7 @@ export const DOCUMENTATION_PATHS = {UI_COMPONENTS_CALLOUT: '/ui/components/callout',UI_COMPONENTS_CODE_EDITOR: '/ui/components/code-editor',UI_COMPONENTS_COMMAND_BLOCK: '/ui/components/command-block',+ UI_COMPONENTS_CURRENCY_PICKER: '/ui/components/currency-picker',UI_COMPONENTS_DROPDOWN: '/ui/components/dropdown',UI_COMPONENTS_IMAGE_INPUT: '/ui/components/image-input',UI_COMPONENTS_INLINE_BANNER: '/ui/components/inline-banner',diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.tsindex 7ca612a44c1..79f83214069 100644--- a/packages/twenty-ui/docs/components.ts+++ b/packages/twenty-ui/docs/components.ts@@ -1,3 +1,4 @@+import { CURRENCY_PICKER_PART_PROP_DESCRIPTIONS } from './currencyPickerPartPropDescriptions';import { OVERFLOWING_LIST_PROP_DESCRIPTIONS } from './overflowingListPropDescriptions';import { METRIC_ROW_PROP_DESCRIPTIONS } from './metricRowPropDescriptions';import { PROGRESS_RING_PROP_DESCRIPTIONS } from './progressRingPropDescriptions';@@ -65,6 +66,14 @@ import { TOOLTIP_PROP_DESCRIPTIONS } from './tooltipPropDescriptions';import { VISIBILITY_HIDDEN_PROP_DESCRIPTIONS } from './visibilityHiddenPropDescriptions';export const DOCUMENTED_COMPONENTS = [+ {+ name: 'CurrencyPicker',+ source: 'components/input/CurrencyPicker/CurrencyPicker.tsx',+ entryPoint: 'twenty-ui/components',+ slug: 'components/currency-picker',+ parts: ['Trigger', 'Options'],+ partPropDescriptions: CURRENCY_PICKER_PART_PROP_DESCRIPTIONS,+ },{name: 'ProgressRing',source: 'primitives/feedback/ProgressRing/ProgressRing.tsx',diff --git a/packages/twenty-ui/docs/currencyPickerPartPropDescriptions.ts b/packages/twenty-ui/docs/currencyPickerPartPropDescriptions.tsnew file mode 100644index 00000000000..0f437f9c20d--- /dev/null+++ b/packages/twenty-ui/docs/currencyPickerPartPropDescriptions.ts@@ -0,0 +1,27 @@+import { type CurrencyPickerOptionsProps } from '../src/components/input/CurrencyPicker/types/CurrencyPickerOptionsProps';+import { type CurrencyPickerTriggerProps } from '../src/components/input/CurrencyPicker/types/CurrencyPickerTriggerProps';++export const CURRENCY_PICKER_PART_PROP_DESCRIPTIONS = {+ Trigger: {+ value:+ 'Required currency code displayed beside the chevron. The application chooses its initial value and any fallback.',+ disabled: 'Disables opening the picker.',+ id: 'ID forwarded to the trigger button.',+ render:+ 'Replaces the native trigger button. Forward the supplied props and ref when rendering a custom component.',+ } satisfies Partial<Record<keyof CurrencyPickerTriggerProps, string>>,+ Options: {+ currencies:+ 'Available currency codes and names, in catalogue order. Each code must be unique. An option can be disabled.',+ value:+ 'Selected currency code. Its matching row appears first and is marked pressed.',+ onValueChange:+ 'Called with the code chosen by pointer or keyboard. The application updates the selected value.',+ searchLabel: 'Search placeholder and accessible name. Defaults to Search.',+ emptyLabel:+ 'Text announced when no currencies match. Defaults to No results.',+ disabled: 'Disables search and every currency option.',+ render:+ 'Replaces the non-interactive root div. Forward the supplied props and ref when rendering a custom component.',+ } satisfies Partial<Record<keyof CurrencyPickerOptionsProps, string>>,+};diff --git a/packages/twenty-ui/docs/label-ownership.md b/packages/twenty-ui/docs/label-ownership.mdindex ef100d0c00c..0f8616d5551 100644--- a/packages/twenty-ui/docs/label-ownership.md+++ b/packages/twenty-ui/docs/label-ownership.md@@ -7,6 +7,7 @@ This covers production exports under components, primitives, and icons, includin| Callout | `title`, `description`, `action.label`, and `closeLabel` (default `Close`). || ListItem and Menu item parts | Children, description, action slots, native accessible attributes, and `shortcutJoinLabel` (default `then`). || Dropdown | Children name actions, options, titles, sections, empty states, and loading states. `Back` children default to `Back`. Search accepts native placeholder and accessible attributes. Close requires a caller-supplied accessible label and accepts native `aria-labelledby`. Item parts pass `shortcutJoinLabel` to ListItem. |+| CurrencyPicker | `searchLabel` defaults to `Search` and supplies the search placeholder and accessible name. `emptyLabel` defaults to `No results`. Currency names and codes are caller data; trigger and dropdown accessible names belong to the host. || Legacy menu compositions | MenuItem exposes `text`, contextual slots, and `shortcutJoinLabel` (default `then`). Avatar, draggable, suggestion, and picker presets receive their text from callers; they add no English fallback. Keep this additive option until their separate migration removes the exports. || Button, MainButton, LightButton | Children and native accessible attributes. Applications compose upcoming-feature labels with Pill. Loading preserves the supplied name and marks the button busy; its spinner is decorative. Button hints use the shared Shortcut presentation and remain decorative. `shortcutJoinLabel` supplies the sequence join label. || IconButton and LightIconButton | Caller-supplied accessible label and optional tooltip. Native `aria-labelledby` remains available and takes precedence. |diff --git a/packages/twenty-ui/docs/module-ownership.json b/packages/twenty-ui/docs/module-ownership.jsonindex 0eece38e239..e515274ae60 100644--- a/packages/twenty-ui/docs/module-ownership.json+++ b/packages/twenty-ui/docs/module-ownership.json@@ -50,6 +50,7 @@"CodeEditor","CodeEditorHeader","CommandBlock",+ "CurrencyPicker","Dropdown","IconButton","ImageInput",diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.jsonindex 0c46095a736..70ec26197b0 100644--- a/packages/twenty-ui/docs/public-exports.json+++ b/packages/twenty-ui/docs/public-exports.json@@ -16,6 +16,7 @@"AvatarGroup": "components/data-display/AvatarGroup/AvatarGroup","Callout": "components/feedback/Callout/Callout","CommandBlock": "components/data-display/CommandBlock/CommandBlock",+ "CurrencyPicker": "components/input/CurrencyPicker/CurrencyPicker","DEFAULT_COLOR_LABELS": "components/navigation/MenuItem/constants/DefaultColorLabels","Dropdown": "components/navigation/Dropdown/Dropdown","getIconTileColorShades": "components/data-display/TintedIconTile/utils/getIconTileColorShades",@@ -50,6 +51,9 @@"CalloutProps": "components/feedback/Callout/types/CalloutProps","CalloutVariant": "components/feedback/Callout/types/CalloutVariant","ColorLabels": "components/navigation/MenuItem/types/ColorLabels",+ "CurrencyPickerOption": "components/input/CurrencyPicker/types/CurrencyPickerOption",+ "CurrencyPickerOptionsProps": "components/input/CurrencyPicker/types/CurrencyPickerOptionsProps",+ "CurrencyPickerTriggerProps": "components/input/CurrencyPicker/types/CurrencyPickerTriggerProps","DropdownActionItemProps": "components/navigation/Dropdown/types/DropdownActionItemProps","DropdownCloseProps": "components/navigation/Dropdown/types/DropdownCloseProps","DropdownContentProps": "components/navigation/Dropdown/types/DropdownContentProps",diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.jsonindex a4d2706ae48..433ee1e0c7a 100644--- a/packages/twenty-ui/generated/components.docs.json+++ b/packages/twenty-ui/generated/components.docs.json@@ -1,4 +1,120 @@[+ {+ "name": "CurrencyPicker",+ "entryPoint": "twenty-ui/components",+ "slug": "components/currency-picker",+ "props": [],+ "parts": [+ {+ "name": "Trigger",+ "props": [+ {+ "name": "className",+ "type": "string | ((state: PopoverTriggerState) => string | undefined)",+ "required": false,+ "defaultValue": null,+ "description": "CSS class applied to the element, or a function that\nreturns a class based on the component's state."+ },+ {+ "name": "disabled",+ "type": "boolean",+ "required": false,+ "defaultValue": null,+ "description": "Disables opening the picker."+ },+ {+ "name": "id",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "ID forwarded to the trigger button."+ },+ {+ "name": "nativeButton",+ "type": "boolean",+ "required": false,+ "defaultValue": "true",+ "description": "Whether the component renders a native `<button>` element when replacing it\nvia the `render` prop.\nSet to `false` if the rendered element is not a button (e.g. `<div>`)."+ },+ {+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, PopoverTriggerState>",+ "required": false,+ "defaultValue": null,+ "description": "Replaces the native trigger button. Forward the supplied props and ref when rendering a custom component."+ },+ {+ "name": "style",+ "type": "CSSProperties | ((state: PopoverTriggerState) => CSSProperties | undefined)",+ "required": false,+ "defaultValue": null,+ "description": "Style applied to the element, or a function that\nreturns a style object based on the component's state."+ },+ {+ "name": "value",+ "type": "string",+ "required": true,+ "defaultValue": null,+ "description": "Required currency code displayed beside the chevron. The application chooses its initial value and any fallback."+ }+ ]+ },+ {+ "name": "Options",+ "props": [+ {+ "name": "currencies",+ "type": "readonly CurrencyPickerOption[]",+ "required": true,+ "defaultValue": null,+ "description": "Available currency codes and names, in catalogue order. Each code must be unique. An option can be disabled."+ },+ {+ "name": "disabled",+ "type": "boolean",+ "required": false,+ "defaultValue": "false",+ "description": "Disables search and every currency option."+ },+ {+ "name": "emptyLabel",+ "type": "string",+ "required": false,+ "defaultValue": "No results",+ "description": "Text announced when no currencies match. Defaults to No results."+ },+ {+ "name": "onValueChange",+ "type": "(code: string) => void",+ "required": true,+ "defaultValue": null,+ "description": "Called with the code chosen by pointer or keyboard. The application updates the selected value."+ },+ {+ "name": "render",+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",+ "required": false,+ "defaultValue": null,+ "description": "Replaces the non-interactive root div. Forward the supplied props and ref when rendering a custom component."+ },+ {+ "name": "searchLabel",+ "type": "string",+ "required": false,+ "defaultValue": "Search",+ "description": "Search placeholder and accessible name. Defaults to Search."+ },+ {+ "name": "value",+ "type": "string",+ "required": false,+ "defaultValue": null,+ "description": "Selected currency code. Its matching row appears first and is marked pressed."+ }+ ]+ }+ ]+ },{"name": "ProgressRing","entryPoint": "twenty-ui/primitives/feedback",diff --git a/packages/twenty-ui/src/components/index.ts b/packages/twenty-ui/src/components/index.tsindex 4a17db7fd98..057d0d2caff 100644--- a/packages/twenty-ui/src/components/index.ts+++ b/packages/twenty-ui/src/components/index.ts@@ -39,6 +39,10 @@ export type { ToastProviderProps } from './feedback/Toast/types/ToastProviderProexport type { ToastVariant } from './feedback/Toast/types/ToastVariant';export { Toaster } from './feedback/Toaster/Toaster';export type { ToasterProps } from './feedback/Toaster/types/ToasterProps';+export { CurrencyPicker } from './input/CurrencyPicker/CurrencyPicker';+export type { CurrencyPickerOption } from './input/CurrencyPicker/types/CurrencyPickerOption';+export type { CurrencyPickerOptionsProps } from './input/CurrencyPicker/types/CurrencyPickerOptionsProps';+export type { CurrencyPickerTriggerProps } from './input/CurrencyPicker/types/CurrencyPickerTriggerProps';export { IconButton } from './input/IconButton/IconButton';export type { IconButtonProps } from './input/IconButton/types/IconButtonProps';export type { IconButtonSize } from './input/IconButton/types/IconButtonSize';diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.module.scss b/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.module.scssnew file mode 100644index 00000000000..0fba7c1c7e1--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.module.scss@@ -0,0 +1,55 @@+.trigger {+ align-items: center;+ appearance: none;+ background: transparent;+ border: 0;+ border-inline-end: 1px solid var(--t-border-color-medium);+ border-radius: 0;+ box-sizing: border-box;+ color: var(--t-font-color-tertiary);+ cursor: pointer;+ display: inline-flex;+ flex-shrink: 0;+ font-family: inherit;+ font-size: inherit;+ font-weight: var(--t-font-weight-medium);+ gap: var(--t-spacing-1);+ block-size: 32px;+ justify-content: center;+ padding-block: 0;+ padding-inline: var(--t-spacing-2);+ user-select: none;++ &:hover:not([data-disabled]) {+ background: var(--t-background-transparent-light);+ }++ &:focus-visible {+ outline: 2px solid var(--t-color-blue);+ outline-offset: -2px;+ }++ &[data-disabled] {+ cursor: not-allowed;+ opacity: 0.5;+ }+}++.chevron {+ block-size: calc(var(--t-icon-size-sm) * 1px);+ inline-size: calc(var(--t-icon-size-sm) * 1px);+}++.options {+ display: flex;+ flex-direction: column;+ min-inline-size: 0;+}++.emptyStatus:empty {+ padding: 0;+}++.emptyStatus:not(:empty) {+ margin: var(--t-spacing-1);+}diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.module.scss.d.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.module.scss.d.tsnew file mode 100644index 00000000000..10087f8bc98--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.module.scss.d.ts@@ -0,0 +1,7 @@+declare const classNames: {+ readonly trigger: 'trigger';+ readonly chevron: 'chevron';+ readonly options: 'options';+ readonly emptyStatus: 'emptyStatus';+};+export default classNames;diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.tsxnew file mode 100644index 00000000000..c43d1b1a36c--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/CurrencyPicker.tsx@@ -0,0 +1,7 @@+import { CurrencyPickerOptions } from './internal/CurrencyPickerOptions';+import { CurrencyPickerTrigger } from './internal/CurrencyPickerTrigger';++export const CurrencyPicker = {+ Trigger: CurrencyPickerTrigger,+ Options: CurrencyPickerOptions,+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.interactions.stories.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.interactions.stories.tsxnew file mode 100644index 00000000000..02332694472--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.interactions.stories.tsx@@ -0,0 +1,293 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, userEvent, waitFor, within } from 'storybook/test';++import { Button } from '@ui/primitives/input/Button/Button';+import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';++import { CurrencyPickerExample } from './CurrencyPickerExample';+import { openCurrencyPicker } from './openCurrencyPicker';++const meta: Meta<typeof CurrencyPickerExample> = {+ title: 'UI/Input/CurrencyPicker/Interactions',+ component: CurrencyPickerExample,+ render: (args) => <CurrencyPickerExample key={args.defaultValue} {...args} />,+ decorators: [ComponentDecorator],+ args: { onValueChange: fn() },+ parameters: {+ container: { width: 320, height: 340 },+ a11y: A11Y_DEFER_COLOR_CONTRAST,+ },+};++export default meta;+type Story = StoryObj<typeof CurrencyPickerExample>;++export const SearchAndPointerSelection: Story = {+ play: async ({ canvasElement, args }) => {+ const { trigger, dialog, search } = await openCurrencyPicker({+ canvasElement,+ });+ const options = within(dialog);++ await expect(options.getAllByRole('button')[0]).toHaveTextContent(+ 'US Dollar (USD)',+ );+ await expect(+ options.getByRole('button', { name: 'US Dollar (USD)' }),+ ).toHaveAttribute('aria-pressed', 'true');+ await userEvent.type(search, 'dOlLaR');+ await expect(options.getAllByRole('button')).toHaveLength(2);+ await expect(options.getAllByRole('button')[0]).toHaveTextContent(+ 'US Dollar (USD)',+ );+ await userEvent.clear(search);+ await userEvent.type(search, 'eUr');+ await expect(options.getAllByRole('button')).toHaveLength(1);+ await expect(+ options.queryByRole('button', { name: 'US Dollar (USD)' }),+ ).not.toBeInTheDocument();+ await userEvent.clear(search);+ await userEvent.type(search, ' eUr ');+ await expect(options.getAllByRole('button')).toHaveLength(1);+ await expect(options.getByRole('button')).toHaveAccessibleName(+ 'Euro (EUR)',+ );+ await userEvent.clear(search);+ await userEvent.type(search, 'Euro (EUR)');+ await expect(options.getAllByRole('button')).toHaveLength(1);+ await userEvent.click(options.getByRole('button', { name: 'Euro (EUR)' }));+ await expect(args.onValueChange).toHaveBeenCalledOnce();+ await expect(args.onValueChange).toHaveBeenCalledWith('EUR');+ await waitFor(() => expect(dialog).not.toBeInTheDocument());+ await expect(trigger).toHaveTextContent('EUR');+ await waitFor(() => expect(trigger).toHaveFocus());+ },+};++export const KeyboardNavigation: Story = {+ play: async ({ canvasElement, args }) => {+ const trigger = within(canvasElement).getByRole('button', {+ name: 'Currency',+ });++ await userEvent.tab();+ await expect(trigger).toHaveFocus();+ await userEvent.keyboard('{Enter}');++ const dialog = await within(canvasElement.ownerDocument.body).findByRole(+ 'dialog',+ { name: 'Currency' },+ );+ const search = within(dialog).getByRole('searchbox');++ await waitFor(() => expect(dialog).toBeVisible());+ await waitFor(() => expect(search).toHaveFocus());+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await userEvent.keyboard('{ArrowDown}');+ await expect(+ within(dialog).getByRole('button', { name: 'US Dollar (USD)' }),+ ).toHaveFocus();+ await userEvent.keyboard('{ArrowDown}');+ await expect(+ within(dialog).getByRole('button', { name: 'Australian Dollar (AUD)' }),+ ).toHaveFocus();+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).toHaveBeenCalledOnce();+ await expect(args.onValueChange).toHaveBeenCalledWith('AUD');+ await waitFor(() => expect(dialog).not.toBeInTheDocument());+ await waitFor(() => expect(trigger).toHaveFocus());+ },+};++export const MatchingSearchEnter: Story = {+ play: async ({ canvasElement, args }) => {+ const { trigger, dialog, search } = await openCurrencyPicker({+ canvasElement,+ });++ await userEvent.type(search, 'jApAn');+ const japaneseYen = within(dialog).getByRole('button', {+ name: 'Japanese Yen (JPY)',+ });++ await waitFor(() =>+ expect(japaneseYen).toHaveAttribute('data-highlighted'),+ );+ await expect(search).toHaveAttribute(+ 'aria-activedescendant',+ japaneseYen.id,+ );+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).toHaveBeenCalledOnce();+ await expect(args.onValueChange).toHaveBeenCalledWith('JPY');+ await waitFor(() => expect(dialog).not.toBeInTheDocument());+ await expect(trigger).toHaveTextContent('JPY');+ },+};++export const EmptyResultsAndLabelOverrides: Story = {+ args: {+ searchLabel: 'Find a currency',+ emptyLabel: 'No matching currencies',+ },+ play: async ({ canvasElement, args }) => {+ const { trigger, dialog, search } = await openCurrencyPicker({+ canvasElement,+ });++ await expect(search).toHaveAccessibleName('Find a currency');+ await expect(search).toHaveAttribute('placeholder', 'Find a currency');+ const emptyStatus = within(dialog).getByRole('status');++ await expect(emptyStatus).toBeEmptyDOMElement();+ await userEvent.type(search, 'unknown');+ await expect(within(dialog).queryAllByRole('button')).toHaveLength(0);+ await expect(emptyStatus).toHaveTextContent('No matching currencies');+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await expect(search).toHaveFocus();+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(dialog).not.toBeInTheDocument());+ await waitFor(() => expect(trigger).toHaveFocus());+ },+};++export const DisabledCurrency: Story = {+ play: async ({ canvasElement, args }) => {+ const { trigger, dialog, search } = await openCurrencyPicker({+ canvasElement,+ });+ const disabledCurrency = within(dialog).getByRole('button', {+ name: 'British Pound (GBP)',+ });++ await expect(disabledCurrency).toHaveAttribute('aria-disabled', 'true');+ await userEvent.click(disabledCurrency);+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await userEvent.type(search, 'pound');+ await expect(search).not.toHaveAttribute('aria-activedescendant');+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');+ await userEvent.clear(search);+ await userEvent.type(search, 'jpy');+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).toHaveBeenCalledOnce();+ await expect(args.onValueChange).toHaveBeenCalledWith('JPY');+ },+};++export const DisabledTrigger: Story = {+ args: { disabled: true },+ play: async ({ canvasElement, args }) => {+ const trigger = within(canvasElement).getByRole('button', {+ name: 'Currency',+ });++ await expect(trigger).toBeDisabled();+ await userEvent.click(trigger);+ await userEvent.tab();+ await expect(trigger).not.toHaveFocus();+ await expect(+ within(canvasElement.ownerDocument.body).queryByRole('dialog'),+ ).not.toBeInTheDocument();+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};++export const DisabledOptions: Story = {+ args: { optionsDisabled: true },+ play: async ({ canvasElement, args }) => {+ const trigger = within(canvasElement).getByRole('button', {+ name: 'Currency',+ });++ await userEvent.click(trigger);+ const dialog = await within(canvasElement.ownerDocument.body).findByRole(+ 'dialog',+ { name: 'Currency' },+ );++ await waitFor(() => expect(dialog).toBeVisible());+ await expect(within(dialog).getByRole('searchbox')).toBeDisabled();+ for (const option of within(dialog).getAllByRole('button')) {+ await expect(option).toHaveAttribute('aria-disabled', 'true');+ }+ await userEvent.click(+ within(dialog).getByRole('button', { name: 'Euro (EUR)' }),+ );+ await userEvent.keyboard('{Enter}');+ await expect(args.onValueChange).not.toHaveBeenCalled();+ await expect(trigger).toHaveAttribute('aria-expanded', 'true');+ },+};++export const IndependentInstances: Story = {+ render: () => (+ <>+ <CurrencyPickerExample+ triggerLabel="Invoice currency"+ defaultValue="USD"+ />+ <CurrencyPickerExample+ triggerLabel="Budget currency"+ defaultValue="EUR"+ />+ </>+ ),+ play: async ({ canvasElement }) => {+ const invoice = await openCurrencyPicker({+ canvasElement,+ triggerLabel: 'Invoice currency',+ });++ await userEvent.type(invoice.search, 'jpy');+ await userEvent.keyboard('{Enter}');+ await waitFor(() => expect(invoice.dialog).not.toBeInTheDocument());++ const budget = await openCurrencyPicker({+ canvasElement,+ triggerLabel: 'Budget currency',+ });++ await expect(budget.search).toHaveValue('');+ await expect(budget.trigger).toHaveTextContent('EUR');+ await expect(+ within(budget.dialog).getAllByRole('button')[0],+ ).toHaveTextContent('Euro (EUR)');+ await userEvent.keyboard('{Escape}');+ await waitFor(() => expect(budget.dialog).not.toBeInTheDocument());++ const reopenedInvoice = await openCurrencyPicker({+ canvasElement,+ triggerLabel: 'Invoice currency',+ });++ await expect(reopenedInvoice.search).toHaveValue('');+ await expect(reopenedInvoice.trigger).toHaveTextContent('JPY');+ await expect(+ within(reopenedInvoice.dialog).getAllByRole('button')[0],+ ).toHaveTextContent('Japanese Yen (JPY)');+ },+};++export const OutsideDismissal: Story = {+ render: (args) => (+ <>+ <CurrencyPickerExample key={args.defaultValue} {...args} />+ <Button>Continue</Button>+ </>+ ),+ play: async ({ canvasElement, args }) => {+ const { dialog } = await openCurrencyPicker({ canvasElement });++ await userEvent.click(+ within(canvasElement).getByRole('button', { name: 'Continue' }),+ );+ await waitFor(() => expect(dialog).not.toBeInTheDocument());+ await expect(args.onValueChange).not.toHaveBeenCalled();+ },+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.locale.stories.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.locale.stories.tsxnew file mode 100644index 00000000000..16a4bdfa409--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.locale.stories.tsx@@ -0,0 +1,79 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, fn, spyOn, userEvent, waitFor, within } from 'storybook/test';++import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';++import { CurrencyPickerExample } from './CurrencyPickerExample';+import { openCurrencyPicker } from './openCurrencyPicker';++const meta: Meta<typeof CurrencyPickerExample> = {+ title: 'UI/Input/CurrencyPicker/Locale',+ component: CurrencyPickerExample,+ render: (args) => <CurrencyPickerExample key={args.defaultValue} {...args} />,+ decorators: [ComponentDecorator],+ args: { onValueChange: fn() },+ parameters: {+ container: { width: 320, height: 340 },+ a11y: A11Y_DEFER_COLOR_CONTRAST,+ },+};++export default meta;+type Story = StoryObj<typeof CurrencyPickerExample>;++export const TurkishLocaleSearch: Story = {+ args: {+ currencies: [+ { code: 'INR', name: 'Indian Rupee' },+ { code: 'IDR', name: 'Indonesian Rupiah' },+ { code: 'USD', name: 'US Dollar' },+ ],+ },+ beforeEach: () => {+ const originalToLocaleLowerCase = String.prototype.toLocaleLowerCase;+ const toLocaleLowerCaseSpy = spyOn(+ String.prototype,+ 'toLocaleLowerCase',+ ).mockImplementation(function (+ this: string,+ locales?: Intl.LocalesArgument,+ ) {+ return originalToLocaleLowerCase.call(this, locales ?? 'tr-TR');+ });++ return () => toLocaleLowerCaseSpy.mockRestore();+ },+ play: async ({ canvasElement, args }) => {+ const firstPicker = await openCurrencyPicker({ canvasElement });++ await userEvent.type(firstPicker.search, 'indian');+ await expect(+ within(firstPicker.dialog).getByRole('button', {+ name: 'Indian Rupee (INR)',+ }),+ ).toBeVisible();+ await userEvent.keyboard('{Enter}');+ await waitFor(() => expect(firstPicker.dialog).not.toBeInTheDocument());+ await expect(args.onValueChange).toHaveBeenLastCalledWith('INR');++ const secondPicker = await openCurrencyPicker({ canvasElement });++ await userEvent.type(secondPicker.search, 'idr');+ await expect(+ within(secondPicker.dialog).getByRole('button', {+ name: 'Indonesian Rupiah (IDR)',+ }),+ ).toBeVisible();+ await userEvent.clear(secondPicker.search);+ await userEvent.type(secondPicker.search, 'IDR');+ await expect(+ within(secondPicker.dialog).getByRole('button', {+ name: 'Indonesian Rupiah (IDR)',+ }),+ ).toBeVisible();+ await userEvent.keyboard('{Enter}');+ await waitFor(() => expect(secondPicker.dialog).not.toBeInTheDocument());+ await expect(args.onValueChange).toHaveBeenLastCalledWith('IDR');+ await expect(args.onValueChange).toHaveBeenCalledTimes(2);+ },+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.stories.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.stories.tsxnew file mode 100644index 00000000000..49a73997e69--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPicker.stories.tsx@@ -0,0 +1,51 @@+import { type Meta, type StoryObj } from '@storybook/react-vite';+import { expect, within } from 'storybook/test';++import { TextDirectionProvider } from '@ui/primitives/layout/TextDirectionProvider/TextDirectionProvider';+import { A11Y_DEFER_COLOR_CONTRAST, ComponentDecorator } from '@ui/testing';++import { CurrencyPickerExample } from './CurrencyPickerExample';+import { openCurrencyPicker } from './openCurrencyPicker';++const meta: Meta<typeof CurrencyPickerExample> = {+ title: 'UI/Input/CurrencyPicker',+ component: CurrencyPickerExample,+ render: (args) => <CurrencyPickerExample key={args.defaultValue} {...args} />,+ decorators: [ComponentDecorator],+ parameters: {+ container: { width: 320, height: 340 },+ a11y: A11Y_DEFER_COLOR_CONTRAST,+ },+};++export default meta;+type Story = StoryObj<typeof CurrencyPickerExample>;++export const Documentation: Story = {};++export const Default: Story = {+ play: async ({ canvasElement }) => {+ const { dialog } = await openCurrencyPicker({ canvasElement });++ await expect(+ within(dialog).getByRole('button', { name: 'US Dollar (USD)' }),+ ).toHaveAttribute('aria-pressed', 'true');+ },+};++export const Dark: Story = {+ ...Default,+ globals: { colorScheme: 'dark' },+};++export const RightToLeft: Story = {+ ...Default,+ args: { dir: 'rtl' },+ decorators: [+ (Story) => (+ <TextDirectionProvider direction="rtl">+ <Story />+ </TextDirectionProvider>+ ),+ ],+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPickerExample.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPickerExample.tsxnew file mode 100644index 00000000000..44988ab78df--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/CurrencyPickerExample.tsx@@ -0,0 +1,57 @@+import { type ComponentProps, useState } from 'react';++import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';++import { CurrencyPicker } from '../CurrencyPicker';+import { CURRENCY_PICKER_STORY_OPTIONS } from './currencyPickerStoryOptions';++type CurrencyPickerExampleProps = Pick<+ ComponentProps<typeof CurrencyPicker.Options>,+ 'currencies' | 'searchLabel' | 'emptyLabel' | 'onValueChange' | 'dir'+> & {+ defaultValue?: string;+ disabled?: boolean;+ optionsDisabled?: boolean;+ defaultOpen?: boolean;+ triggerLabel?: string;+};++export const CurrencyPickerExample = ({+ currencies = CURRENCY_PICKER_STORY_OPTIONS,+ defaultValue = 'USD',+ disabled = false,+ optionsDisabled = false,+ defaultOpen = false,+ triggerLabel = 'Currency',+ searchLabel,+ emptyLabel,+ onValueChange,+ dir,+}: Partial<CurrencyPickerExampleProps>) => {+ const [value, setValue] = useState(defaultValue);++ return (+ <Dropdown.Root type="picker" defaultOpen={defaultOpen}>+ <CurrencyPicker.Trigger+ aria-label={triggerLabel}+ value={value}+ disabled={disabled}+ dir={dir}+ />+ <Dropdown.Content aria-label={triggerLabel} width={280} dir={dir}>+ <CurrencyPicker.Options+ currencies={currencies}+ value={value}+ onValueChange={(currencyCode) => {+ setValue(currencyCode);+ onValueChange?.(currencyCode);+ }}+ searchLabel={searchLabel}+ emptyLabel={emptyLabel}+ disabled={optionsDisabled}+ dir={dir}+ />+ </Dropdown.Content>+ </Dropdown.Root>+ );+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/currencyPickerStoryOptions.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/currencyPickerStoryOptions.tsnew file mode 100644index 00000000000..f6d53b10657--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/currencyPickerStoryOptions.ts@@ -0,0 +1,9 @@+import { type CurrencyPickerOption } from '../types/CurrencyPickerOption';++export const CURRENCY_PICKER_STORY_OPTIONS = [+ { code: 'AUD', name: 'Australian Dollar' },+ { code: 'EUR', name: 'Euro' },+ { code: 'GBP', name: 'British Pound', disabled: true },+ { code: 'JPY', name: 'Japanese Yen' },+ { code: 'USD', name: 'US Dollar' },+] satisfies CurrencyPickerOption[];diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/openCurrencyPicker.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/openCurrencyPicker.tsnew file mode 100644index 00000000000..758d5c70b83--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__stories__/openCurrencyPicker.ts@@ -0,0 +1,26 @@+import { expect, userEvent, waitFor, within } from 'storybook/test';++export const openCurrencyPicker = async ({+ canvasElement,+ triggerLabel = 'Currency',+}: {+ canvasElement: HTMLElement;+ triggerLabel?: string;+}) => {+ const trigger = within(canvasElement).getByRole('button', {+ name: triggerLabel,+ });++ await userEvent.click(trigger);++ const dialog = await within(canvasElement.ownerDocument.body).findByRole(+ 'dialog',+ { name: triggerLabel },+ );+ const search = within(dialog).getByRole('searchbox');++ await waitFor(() => expect(dialog).toBeVisible());+ await waitFor(() => expect(search).toHaveFocus());++ return { trigger, dialog, search };+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/__tests__/CurrencyPicker.test.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/__tests__/CurrencyPicker.test.tsxnew file mode 100644index 00000000000..7b50f1edb68--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/__tests__/CurrencyPicker.test.tsx@@ -0,0 +1,48 @@+import { type ReactNode } from 'react';++import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';++import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';++import { CurrencyPicker } from '../CurrencyPicker';+import styles from '../CurrencyPicker.module.scss';++const CurrencyPickerTriggerWrapper = ({+ children,+}: {+ children: ReactNode;+}) => <Dropdown.Root type="picker">{children}</Dropdown.Root>;++const CurrencyPickerOptionsWrapper = ({+ children,+}: {+ children: ReactNode;+}) => (+ <Dropdown.Root type="picker" open>+ <Dropdown.Content aria-label="Currency">{children}</Dropdown.Content>+ </Dropdown.Root>+);++runComponentConformance({+ name: 'CurrencyPicker.Trigger',+ element: <CurrencyPicker.Trigger value="USD" aria-label="Currency" />,+ refInstanceOf: HTMLButtonElement,+ wrapper: CurrencyPickerTriggerWrapper,+ ownClassName: styles.trigger,+ renderPropTagName: 'button',+});++runComponentConformance({+ name: 'CurrencyPicker.Options',+ element: (+ <CurrencyPicker.Options+ currencies={[{ code: 'USD', name: 'US Dollar' }]}+ value="USD"+ onValueChange={() => undefined}+ />+ ),+ refInstanceOf: HTMLDivElement,+ wrapper: CurrencyPickerOptionsWrapper,+ ownClassName: styles.options,+ renderPropTagName: 'div',+});diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/internal/CurrencyPickerOptions.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/internal/CurrencyPickerOptions.tsxnew file mode 100644index 00000000000..b47ada697d2--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/internal/CurrencyPickerOptions.tsx@@ -0,0 +1,81 @@+import { useRender } from '@base-ui/react/use-render';+import { isNonEmptyArray } from '@sniptt/guards';+import { clsx } from 'clsx';+import { useState } from 'react';++import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';+import { OverflowingTextWithTooltip } from '@ui/primitives/typography/OverflowingTextWithTooltip/OverflowingTextWithTooltip';+import { isDefined } from '@ui/utilities/utils/isDefined';++import styles from '../CurrencyPicker.module.scss';+import { getCurrencyPickerLabel } from './getCurrencyPickerLabel';+import { type CurrencyPickerOptionsProps } from '../types/CurrencyPickerOptionsProps';++export const CurrencyPickerOptions = ({+ currencies,+ value,+ onValueChange,+ disabled = false,+ searchLabel = 'Search',+ emptyLabel = 'No results',+ className,+ render,+ ref,+ ...props+}: CurrencyPickerOptionsProps) => {+ const [search, setSearch] = useState('');+ const normalizedSearch = search.trim().toLowerCase();+ const matchingCurrencies = currencies.filter((currency) =>+ getCurrencyPickerLabel(currency).toLowerCase().includes(normalizedSearch),+ );+ const hasMatchingCurrencies = isNonEmptyArray(matchingCurrencies);+ const selectedCurrency = matchingCurrencies.find(+ ({ code }) => code === value,+ );+ const orderedCurrencies = isDefined(selectedCurrency)+ ? [+ selectedCurrency,+ ...matchingCurrencies.filter(({ code }) => code !== value),+ ]+ : matchingCurrencies;++ return useRender({+ render,+ ref,+ props: {+ ...props,+ className: clsx(styles.options, className),+ children: (+ <>+ <Dropdown.Search+ value={search}+ placeholder={searchLabel}+ aria-label={searchLabel}+ onValueChange={setSearch}+ disabled={disabled}+ />+ <Dropdown.Separator />+ {hasMatchingCurrencies && (+ <Dropdown.Section scrollable>+ {orderedCurrencies.map((currency) => (+ <Dropdown.OptionItem+ key={currency.code}+ selected={currency.code === value}+ disabled={disabled || currency.disabled}+ onSelect={() => onValueChange(currency.code)}+ >+ <OverflowingTextWithTooltip+ text={getCurrencyPickerLabel(currency)}+ />+ </Dropdown.OptionItem>+ ))}+ </Dropdown.Section>+ )}+ <Dropdown.Empty className={styles.emptyStatus}>+ {hasMatchingCurrencies ? null : emptyLabel}+ </Dropdown.Empty>+ </>+ ),+ },+ });+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/internal/CurrencyPickerTrigger.tsx b/packages/twenty-ui/src/components/input/CurrencyPicker/internal/CurrencyPickerTrigger.tsxnew file mode 100644index 00000000000..59f2da6c9e3--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/internal/CurrencyPickerTrigger.tsx@@ -0,0 +1,20 @@+import { Dropdown } from '@ui/components/navigation/Dropdown/Dropdown';+import { IconChevronDown } from '@ui/icon';+import { mergeClassNames } from '@ui/utilities/internal/mergeClassNames';++import styles from '../CurrencyPicker.module.scss';+import { type CurrencyPickerTriggerProps } from '../types/CurrencyPickerTriggerProps';++export const CurrencyPickerTrigger = ({+ value,+ className,+ ...props+}: CurrencyPickerTriggerProps) => (+ <Dropdown.Trigger+ {...props}+ className={mergeClassNames(styles.trigger, className)}+ >+ {value}+ <IconChevronDown aria-hidden="true" className={styles.chevron} />+ </Dropdown.Trigger>+);diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/internal/getCurrencyPickerLabel.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/internal/getCurrencyPickerLabel.tsnew file mode 100644index 00000000000..1df9c7ca72e--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/internal/getCurrencyPickerLabel.ts@@ -0,0 +1,4 @@+import { type CurrencyPickerOption } from '../types/CurrencyPickerOption';++export const getCurrencyPickerLabel = ({ code, name }: CurrencyPickerOption) =>+ `${name} (${code})`;diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerOption.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerOption.tsnew file mode 100644index 00000000000..a4f8b0571d0--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerOption.ts@@ -0,0 +1,5 @@+export type CurrencyPickerOption = {+ code: string;+ name: string;+ disabled?: boolean;+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerOptionsProps.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerOptionsProps.tsnew file mode 100644index 00000000000..1e473e8f477--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerOptionsProps.ts@@ -0,0 +1,15 @@+import { type useRender } from '@base-ui/react/use-render';++import { type CurrencyPickerOption } from './CurrencyPickerOption';++export type CurrencyPickerOptionsProps = Omit<+ useRender.ComponentProps<'div'>,+ 'children'+> & {+ currencies: readonly CurrencyPickerOption[];+ value?: string;+ onValueChange: (code: string) => void;+ disabled?: boolean;+ searchLabel?: string;+ emptyLabel?: string;+};diff --git a/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerTriggerProps.ts b/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerTriggerProps.tsnew file mode 100644index 00000000000..12078f01978--- /dev/null+++ b/packages/twenty-ui/src/components/input/CurrencyPicker/types/CurrencyPickerTriggerProps.ts@@ -0,0 +1,14 @@+import { type DropdownTriggerProps } from '@ui/components/navigation/Dropdown/types/DropdownTriggerProps';++export type CurrencyPickerTriggerProps = Omit<+ DropdownTriggerProps,+ | 'children'+ | 'value'+ | 'openOnHover'+ | 'delay'+ | 'closeDelay'+ | 'handle'+ | 'payload'+> & {+ value: string;+};