Skip to content

The open alternative to Salesforce, designed for AI.

Give percentages and booleans their own inputs in record forms (#28510)

Charles Bochetd4cadf3633bc
diff --git a/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx b/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx
index 417f3edc914..a40a6305f3e 100644
--- a/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/components/input/segmented-control.mdx
@@ -88,3 +88,7 @@
To render an uncontrolled radio group, use the `defaultValue` prop instead.
</ParamField>
+
+<ParamField body="variant" type="&quot;rectangle&quot; | &quot;round&quot;" default="round">
+ Shape: `round` is a pill, `rectangle` fills its container with form-field corners.
+</ParamField>
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/constants/PercentageValuePrecision.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/constants/PercentageValuePrecision.ts
new file mode 100644
index 00000000000..fc7b0946adb
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/constants/PercentageValuePrecision.ts
@@ -0,0 +1 @@
+export const PERCENTAGE_VALUE_PRECISION = 15;
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/NumberFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/NumberFieldInput.tsx
index b2ce4acc808..0db9c692d7d 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/NumberFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/NumberFieldInput.tsx
@@ -1,15 +1,18 @@
-import { useContext } from 'react';
+import { type ClipboardEvent, type KeyboardEvent, useContext } from 'react';
+import { doNotTranslate } from 'twenty-shared/i18n';
import { FieldInputEventContext } from '@/object-record/record-field/ui/contexts/FieldInputEventContext';
import { useNumberField } from '@/object-record/record-field/ui/meta-types/hooks/useNumberField';
import { getNumberValueToPersist } from '@/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist';
import { RecordFieldComponentInstanceContext } from '@/object-record/record-field/ui/states/contexts/RecordFieldComponentInstanceContext';
import { FieldInputContainer } from '@/ui/field/input/components/FieldInputContainer';
+import { StyledFieldInputSuffix } from '@/ui/field/input/components/StyledFieldInputSuffix';
import { TextInput } from '@/ui/field/input/components/TextInput';
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
export const NumberFieldInput = () => {
const { fieldDefinition, draftValue, setDraftValue } = useNumberField();
+ const isPercentage = fieldDefinition.metadata.settings?.type === 'percentage';
const { onEnter, onEscape, onClickOutside, onTab, onShiftTab } = useContext(
FieldInputEventContext,
@@ -60,8 +63,38 @@ export const NumberFieldInput = () => {
setDraftValue(newText);
};
+ const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
+ if (isPercentage && event.key === '%') {
+ event.preventDefault();
+ }
+ };
+
+ const handlePaste = (event: ClipboardEvent<HTMLDivElement>) => {
+ const input = event.target;
+ const pastedText = event.clipboardData.getData('text').trim();
+
+ if (
+ !isPercentage ||
+ !(input instanceof HTMLInputElement) ||
+ !pastedText.endsWith('%')
+ ) {
+ return;
+ }
+
+ event.preventDefault();
+
+ const selectionStart = input.selectionStart ?? input.value.length;
+ const selectionEnd = input.selectionEnd ?? input.value.length;
+
+ setDraftValue(
+ input.value.slice(0, selectionStart) +
+ pastedText.slice(0, -1).trim() +
+ input.value.slice(selectionEnd),
+ );
+ };
+
return (
- <FieldInputContainer>
+ <FieldInputContainer onKeyDown={handleKeyDown} onPaste={handlePaste}>
<TextInput
instanceId={instanceId}
placeholder={fieldDefinition.metadata.placeHolder}
@@ -73,7 +106,16 @@ export const NumberFieldInput = () => {
onShiftTab={handleShiftTab}
onTab={handleTab}
onChange={handleChange}
+ copyButton={!isPercentage}
/>
+ {isPercentage && (
+ <StyledFieldInputSuffix
+ data-globally-prevent-click-outside="true"
+ onMouseDown={(event) => event.preventDefault()}
+ >
+ {doNotTranslate('%')}
+ </StyledFieldInputSuffix>
+ )}
</FieldInputContainer>
);
};
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx
index 5e658da9766..5e402bb1f2e 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/components/__stories__/NumberFieldInput.stories.tsx
@@ -15,6 +15,7 @@ import { useNumberField } from '@/object-record/record-field/ui/meta-types/hooks
import { NumberFieldInput } from '@/object-record/record-field/ui/meta-types/input/components/NumberFieldInput';
import { getFieldInputEventContextProviderWithJestMocks } from '@/object-record/record-field/ui/meta-types/input/components/__stories__/utils/getFieldInputEventContextProviderWithJestMocks';
import { RecordFieldComponentInstanceContext } from '@/object-record/record-field/ui/states/contexts/RecordFieldComponentInstanceContext';
+import { type FieldNumberMetadata } from '@/object-record/record-field/ui/types/FieldMetadata';
import { RECORD_TABLE_CELL_INPUT_ID_PREFIX } from '@/object-record/record-table/constants/RecordTableCellInputIdPrefix';
import { getRecordFieldInputInstanceId } from '@/object-record/utils/getRecordFieldInputId';
import { FocusComponentType } from '@/ui/utilities/focus/types/FocusComponentType';
@@ -41,11 +42,13 @@ const NumberFieldValueSetterEffect = ({ value }: { value: number }) => {
type NumberFieldInputWithContextProps = {
value: number;
recordId: string;
+ settings?: FieldNumberMetadata['settings'];
};
const NumberFieldInputWithContext = ({
recordId,
value,
+ settings,
}: NumberFieldInputWithContextProps) => {
const { pushFocusItemToFocusStack } = usePushFocusItemToFocusStack();
@@ -91,6 +94,7 @@ const NumberFieldInputWithContext = ({
fieldName: 'number',
placeHolder: 'Enter number',
objectMetadataNameSingular: 'person',
+ settings,
},
},
recordId: '123',
@@ -151,6 +155,32 @@ type Story = StoryObj<typeof NumberFieldInputWithContext>;
export const Default: Story = {};
+export const Percentage: Story = {
+ args: {
+ settings: { type: 'percentage' },
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ const suffix = await canvas.findByText('%');
+ expect(suffix).toBeVisible();
+
+ const input = canvas.getByRole('textbox');
+ await userEvent.type(input, '45%');
+
+ expect(input).toHaveValue('45');
+
+ await userEvent.click(suffix);
+
+ expect(handleClickoutsideMocked).not.toHaveBeenCalled();
+
+ await userEvent.clear(input);
+ await userEvent.paste('25.5%');
+
+ expect(input).toHaveValue('25.5');
+ },
+};
+
export const Enter: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getNumberValueToPersist.test.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getNumberValueToPersist.test.ts
index 16251347928..a98ac4ca883 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getNumberValueToPersist.test.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/__tests__/getNumberValueToPersist.test.ts
@@ -19,6 +19,15 @@ describe('getNumberValueToPersist', () => {
).toEqual({ success: true, value: 0.5 });
});
+ it('should persist a decimal percentage without float noise', () => {
+ expect(
+ getNumberValueToPersist({
+ newValue: '33.3',
+ numberType: 'percentage',
+ }),
+ ).toEqual({ success: true, value: 0.333 });
+ });
+
it('should persist an empty percentage as null', () => {
expect(
getNumberValueToPersist({
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist.ts
index 970c80ba632..f8e971e6cd3 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist.ts
@@ -1,5 +1,6 @@
import { isNull } from '@sniptt/guards';
+import { PERCENTAGE_VALUE_PRECISION } from '@/object-record/record-field/ui/constants/PercentageValuePrecision';
import { type FieldNumberVariant } from '@/object-record/record-field/ui/types/FieldMetadata';
import {
canBeCastAsNumberOrNull,
@@ -29,7 +30,12 @@ export const getNumberValueToPersist = ({
const castedValue = castAsNumberOrNull(valueToCast);
if (numberType === 'percentage' && !isNull(castedValue)) {
- return { success: true, value: castedValue / 100 };
+ return {
+ success: true,
+ value: parseFloat(
+ (castedValue / 100).toPrecision(PERCENTAGE_VALUE_PRECISION),
+ ),
+ };
}
return { success: true, value: castedValue };
diff --git a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/computeDraftValueFromFieldValue.ts b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/computeDraftValueFromFieldValue.ts
index 395bd058d18..52c8b34a4f6 100644
--- a/packages/twenty-front/src/modules/object-record/record-field/ui/utils/computeDraftValueFromFieldValue.ts
+++ b/packages/twenty-front/src/modules/object-record/record-field/ui/utils/computeDraftValueFromFieldValue.ts
@@ -1,3 +1,4 @@
+import { PERCENTAGE_VALUE_PRECISION } from '@/object-record/record-field/ui/constants/PercentageValuePrecision';
import { type FieldDefinition } from '@/object-record/record-field/ui/types/FieldDefinition';
import { type FieldInputDraftValue } from '@/object-record/record-field/ui/types/FieldInputDraftValue';
import { type FieldMetadata } from '@/object-record/record-field/ui/types/FieldMetadata';
@@ -15,8 +16,6 @@ import { isFieldValueEmpty } from '@/object-record/record-field/ui/utils/isField
import { isDefined } from 'twenty-shared/utils';
import { stripSimpleQuotesFromString } from '~/utils/string/stripSimpleQuotesFromString';
-const PERCENTAGE_DRAFT_VALUE_PRECISION = 15;
-
type computeDraftValueFromFieldValueParams<FieldValue> = {
fieldDefinition: Pick<FieldDefinition<FieldMetadata>, 'type' | 'metadata'>;
fieldValue: FieldValue;
@@ -89,7 +88,7 @@ export const computeDraftValueFromFieldValue = <FieldValue>({
return (!isDefined(fieldValue)
? ''
: parseFloat(
- (fieldValue * 100).toPrecision(PERCENTAGE_DRAFT_VALUE_PRECISION),
+ (fieldValue * 100).toPrecision(PERCENTAGE_VALUE_PRECISION),
).toString()) as unknown as FieldInputDraftValue<FieldValue>;
}
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx
new file mode 100644
index 00000000000..5cf162c60ac
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormBooleanFieldInput.tsx
@@ -0,0 +1,59 @@
+import { FormFieldInputInnerContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputInnerContainer';
+import { FormFieldInputRowContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputRowContainer';
+import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';
+import { useLingui } from '@lingui/react/macro';
+import { isNonEmptyString } from '@sniptt/guards';
+import { useId, useState } from 'react';
+import { isDefined } from 'twenty-shared/utils';
+import { SegmentedControl } from 'twenty-ui/components/input';
+import { IconCheck, IconX } from 'twenty-ui/icon';
+import { Field } from 'twenty-ui/primitives/input';
+
+type RecordFormBooleanFieldInputProps = {
+ label?: string;
+ defaultValue?: boolean;
+ onChange: (value: boolean) => void;
+ readonly?: boolean;
+};
+
+export const RecordFormBooleanFieldInput = ({
+ label,
+ defaultValue,
+ onChange,
+ readonly,
+}: RecordFormBooleanFieldInputProps) => {
+ const { t } = useLingui();
+
+ // SegmentedControl is uncontrolled, so a default settling later would switch the selection.
+ const [initialValue] = useState(defaultValue);
+
+ const instanceId = useId();
+
+ return (
+ <FormFieldInputContainer>
+ {isNonEmptyString(label) ? <Field.Label>{label}</Field.Label> : null}
+
+ <FormFieldInputRowContainer>
+ <FormFieldInputInnerContainer
+ formFieldInputInstanceId={instanceId}
+ hasRightElement={false}
+ variant="transparent"
+ >
+ <SegmentedControl
+ variant="rectangle"
+ aria-label={isNonEmptyString(label) ? label : t`True or false`}
+ options={[
+ { value: 'true', label: t`True`, startIcon: <IconCheck /> },
+ { value: 'false', label: t`False`, startIcon: <IconX /> },
+ ]}
+ defaultValue={
+ isDefined(initialValue) ? String(initialValue) : undefined
+ }
+ onValueChange={(value) => onChange(value === 'true')}
+ disabled={readonly}
+ />
+ </FormFieldInputInnerContainer>
+ </FormFieldInputRowContainer>
+ </FormFieldInputContainer>
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx
index 11d61308e08..3e231ab0db6 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormCurrencyFieldInput.tsx
@@ -2,7 +2,7 @@ import {
type FieldCurrencyValue,
type FormFieldCurrencyValue,
} from '@/object-record/record-field/ui/types/FieldMetadata';
-import { RecordFormPickerFieldInput } from '@/object-record/record-form/components/RecordFormPickerFieldInput';
+import { RecordFormTextInput } from '@/object-record/record-form/components/RecordFormTextInput';
import { CurrencyPickerDropdownButton } from '@/ui/input/components/internal/currency/components/CurrencyPickerDropdownButton';
import { t } from '@lingui/core/macro';
import { isNonEmptyString } from '@sniptt/guards';
@@ -87,7 +87,7 @@ export const RecordFormCurrencyFieldInput = ({
};
return (
- <RecordFormPickerFieldInput
+ <RecordFormTextInput
label={label}
value={amountText}
onChange={handleAmountTextChange}
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx
index df8155653c1..63436cc86bc 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInput.tsx
@@ -4,15 +4,21 @@ import { FormLinksFieldInput } from '@/object-record/record-field/ui/form-types/
import { type FormFieldInputSubFieldPlaceholders } from '@/object-record/record-field/ui/form-types/types/FormFieldInputSubFieldPlaceholders';
import { type FieldDefinition } from '@/object-record/record-field/ui/types/FieldDefinition';
import { type FieldMetadata } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { isFieldBoolean } from '@/object-record/record-field/ui/types/guards/isFieldBoolean';
+import { isFieldBooleanValue } from '@/object-record/record-field/ui/types/guards/isFieldBooleanValue';
import { isFieldCurrency } from '@/object-record/record-field/ui/types/guards/isFieldCurrency';
import { isFieldCurrencyValue } from '@/object-record/record-field/ui/types/guards/isFieldCurrencyValue';
import { isFieldEmails } from '@/object-record/record-field/ui/types/guards/isFieldEmails';
import { isFieldEmailsValue } from '@/object-record/record-field/ui/types/guards/isFieldEmailsValue';
import { isFieldLinks } from '@/object-record/record-field/ui/types/guards/isFieldLinks';
import { isFieldLinksValue } from '@/object-record/record-field/ui/types/guards/isFieldLinksValue';
+import { isFieldNumber } from '@/object-record/record-field/ui/types/guards/isFieldNumber';
+import { isFieldNumberValue } from '@/object-record/record-field/ui/types/guards/isFieldNumberValue';
import { isFieldPhones } from '@/object-record/record-field/ui/types/guards/isFieldPhones';
import { isFieldPhonesValue } from '@/object-record/record-field/ui/types/guards/isFieldPhonesValue';
+import { RecordFormBooleanFieldInput } from '@/object-record/record-form/components/RecordFormBooleanFieldInput';
import { RecordFormCurrencyFieldInput } from '@/object-record/record-form/components/RecordFormCurrencyFieldInput';
+import { RecordFormPercentageFieldInput } from '@/object-record/record-form/components/RecordFormPercentageFieldInput';
import { RecordFormPhoneFieldInput } from '@/object-record/record-form/components/RecordFormPhoneFieldInput';
import { getRecordFormCurrencyFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormCurrencyFieldDefaultValue';
import { isNonEmptyString } from '@sniptt/guards';
@@ -88,6 +94,32 @@ export const RecordFormFieldInput = ({
);
}
+ if (isFieldNumber(field) && field.metadata.settings?.type === 'percentage') {
+ return (
+ <RecordFormPercentageFieldInput
+ field={field}
+ defaultValue={
+ isFieldNumberValue(defaultValue) ? defaultValue : undefined
+ }
+ onChange={onChange}
+ readonly={readonly}
+ />
+ );
+ }
+
+ if (isFieldBoolean(field)) {
+ return (
+ <RecordFormBooleanFieldInput
+ label={field.label}
+ defaultValue={
+ isFieldBooleanValue(defaultValue) ? defaultValue : undefined
+ }
+ onChange={onChange}
+ readonly={readonly}
+ />
+ );
+ }
+
if (isFieldPhones(field)) {
const defaultCountryCode = field.defaultValue?.primaryPhoneCountryCode;
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx
index 9fc950b3d16..511eb6bfd7e 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormFieldInputs.tsx
@@ -4,6 +4,7 @@ import { formatFieldMetadataItemAsFieldDefinition } from '@/object-metadata/util
import { getFieldMetadataItemGqlFieldName } from '@/object-metadata/utils/getFieldMetadataItemGqlFieldName';
import { RecordFormFieldInput } from '@/object-record/record-form/components/RecordFormFieldInput';
import { RecordFormFieldInputsEffect } from '@/object-record/record-form/components/RecordFormFieldInputsEffect';
+import { getRecordFormBooleanFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormBooleanFieldDefaultValue';
import { getRecordFormCurrencyFieldDefaultValue } from '@/object-record/record-form/utils/getRecordFormCurrencyFieldDefaultValue';
import { getRecordFormFieldPlaceholders } from '@/object-record/record-form/utils/getRecordFormFieldPlaceholders';
import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
@@ -64,7 +65,10 @@ export const RecordFormFieldInputs = ({
defaultValue={
Object.hasOwn(draftRecord, gqlFieldName)
? draftRecord[gqlFieldName]
- : getRecordFormCurrencyFieldDefaultValue(fieldMetadataItem)
+ : (getRecordFormCurrencyFieldDefaultValue(
+ fieldMetadataItem,
+ ) ??
+ getRecordFormBooleanFieldDefaultValue(fieldMetadataItem))
}
onChange={(value) => onFieldValueChange(gqlFieldName, value)}
onClear={() => onFieldValueClear(gqlFieldName)}
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsx
new file mode 100644
index 00000000000..ef4a106aeb1
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPercentageFieldInput.tsx
@@ -0,0 +1,68 @@
+import { getNumberValueToPersist } from '@/object-record/record-field/ui/meta-types/input/utils/getNumberValueToPersist';
+import { type FieldDefinition } from '@/object-record/record-field/ui/types/FieldDefinition';
+import { type FieldNumberMetadata } from '@/object-record/record-field/ui/types/FieldMetadata';
+import { computeDraftValueFromFieldValue } from '@/object-record/record-field/ui/utils/computeDraftValueFromFieldValue';
+import { RecordFormTextInput } from '@/object-record/record-form/components/RecordFormTextInput';
+import { t } from '@lingui/core/macro';
+import { useState } from 'react';
+import { doNotTranslate } from 'twenty-shared/i18n';
+
+type RecordFormPercentageFieldInputProps = {
+ field: Pick<
+ FieldDefinition<FieldNumberMetadata>,
+ 'type' | 'label' | 'metadata'
+ >;
+ defaultValue?: number | null;
+ onChange: (value: number | null) => void;
+ readonly?: boolean;
+};
+
+export const RecordFormPercentageFieldInput = ({
+ field,
+ defaultValue,
+ onChange,
+ readonly,
+}: RecordFormPercentageFieldInputProps) => {
+ const [inputText, setInputText] = useState(
+ String(
+ computeDraftValueFromFieldValue({
+ fieldDefinition: field,
+ fieldValue: defaultValue ?? null,
+ }),
+ ),
+ );
+ const [errorMessage, setErrorMessage] = useState<string | undefined>(
+ undefined,
+ );
+
+ const handleChange = (newText: string) => {
+ const percentageText = newText.replace(/%\s*$/, '');
+
+ setInputText(percentageText);
+
+ const percentageValueResult = getNumberValueToPersist({
+ newValue: percentageText.trim(),
+ numberType: 'percentage',
+ });
+
+ if (!percentageValueResult.success) {
+ setErrorMessage(t`Invalid number`);
+ return;
+ }
+
+ setErrorMessage(undefined);
+ onChange(percentageValueResult.value);
+ };
+
+ return (
+ <RecordFormTextInput
+ label={field.label}
+ value={inputText}
+ onChange={handleChange}
+ readonly={readonly}
+ placeholder={t`Enter a number`}
+ suffix={doNotTranslate('%')}
+ error={errorMessage}
+ />
+ );
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx
index ba07bf4b0e3..64876a25862 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPhoneFieldInput.tsx
@@ -1,5 +1,5 @@
import { type FieldPhonesValue } from '@/object-record/record-field/ui/types/FieldMetadata';
-import { RecordFormPickerFieldInput } from '@/object-record/record-form/components/RecordFormPickerFieldInput';
+import { RecordFormTextInput } from '@/object-record/record-form/components/RecordFormTextInput';
import { useCountries } from '@/ui/input/components/internal/hooks/useCountries';
import { PhoneCountryPickerDropdownButton } from '@/ui/input/components/internal/phone/components/PhoneCountryPickerDropdownButton';
import { t } from '@lingui/core/macro';
@@ -58,7 +58,7 @@ export const RecordFormPhoneFieldInput = ({
};
return (
- <RecordFormPickerFieldInput
+ <RecordFormTextInput
label={label}
value={phoneNumber}
onChange={(newNumber) => emitPhoneValue(countryCode, newNumber)}
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPickerFieldInput.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormTextInput.tsx
similarity index 77%
rename from packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPickerFieldInput.tsx
rename to packages/twenty-front/src/modules/object-record/record-form/components/RecordFormTextInput.tsx
index ab3dad1c017..67c7e828239 100644
--- a/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormPickerFieldInput.tsx
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/RecordFormTextInput.tsx
@@ -1,14 +1,16 @@
import { FormFieldInputInnerContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputInnerContainer';
import { FormFieldInputRowContainer } from '@/object-record/record-field/ui/form-types/components/FormFieldInputRowContainer';
+import { StyledFieldInputSuffix } from '@/ui/field/input/components/StyledFieldInputSuffix';
import { StyledTextInput } from '@/ui/field/input/components/TextInput';
import { FormFieldInputContainer } from '@/ui/input/components/FormFieldInputContainer';
import { isNonEmptyString } from '@sniptt/guards';
import { type ReactNode, useId } from 'react';
import { Field } from 'twenty-ui/primitives/input';
-type RecordFormPickerFieldInputProps = {
+type RecordFormTextInputProps = {
label?: string;
- picker: ReactNode;
+ picker?: ReactNode;
+ suffix?: string;
value: string;
onChange: (value: string) => void;
placeholder: string;
@@ -16,15 +18,16 @@ type RecordFormPickerFieldInputProps = {
error?: string;
};
-export const RecordFormPickerFieldInput = ({
+export const RecordFormTextInput = ({
label,
picker,
+ suffix,
value,
onChange,
placeholder,
readonly,
error,
-}: RecordFormPickerFieldInputProps) => {
+}: RecordFormTextInputProps) => {
const instanceId = useId();
return (
@@ -47,11 +50,16 @@ export const RecordFormPickerFieldInput = ({
onChange={(event) => onChange(event.target.value)}
disabled={readonly}
/>
+ {isNonEmptyString(suffix) && (
+ <StyledFieldInputSuffix>{suffix}</StyledFieldInputSuffix>
+ )}
</FormFieldInputInnerContainer>
</FormFieldInputRowContainer>
{isNonEmptyString(error) ? (
- <Field.Error match>{error}</Field.Error>
+ <Field.Error match role="alert">
+ {error}
+ </Field.Error>
) : null}
</FormFieldInputContainer>
);
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx
new file mode 100644
index 00000000000..4c14d64c923
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/components/__stories__/RecordFormFieldInputs.stories.tsx
@@ -0,0 +1,229 @@
+import { type Meta, type StoryObj } from '@storybook/react-vite';
+import { useState } from 'react';
+import { expect, fn, userEvent, within } from 'storybook/test';
+
+import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
+import { RecordFormFieldInputs } from '@/object-record/record-form/components/RecordFormFieldInputs';
+import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
+import { CurrencyCode } from 'twenty-shared/constants';
+import { type JsonValue } from 'type-fest';
+import { ComponentDecorator } from 'twenty-ui/testing';
+import { getMockFieldMetadataItemOrThrow } from '~/testing/utils/getMockFieldMetadataItemOrThrow';
+import { getMockObjectMetadataItemOrThrow } from '~/testing/utils/getMockObjectMetadataItemOrThrow';
+
+const companyObjectMetadataItem = getMockObjectMetadataItemOrThrow('company');
+const opportunityObjectMetadataItem =
+ getMockObjectMetadataItemOrThrow('opportunity');
+
+const percentageFieldMetadataItem: FieldMetadataItem = {
+ ...getMockFieldMetadataItemOrThrow({
+ objectMetadataItem: companyObjectMetadataItem,
+ fieldName: 'employees',
+ }),
+ name: 'conversionRate',
+ label: 'Conversion rate',
+ settings: { type: 'percentage' },
+};
+
+const booleanFieldMetadataItem: FieldMetadataItem = {
+ ...getMockFieldMetadataItemOrThrow({
+ objectMetadataItem: companyObjectMetadataItem,
+ fieldName: 'idealCustomerProfile',
+ }),
+ name: 'active',
+ label: 'Active',
+ defaultValue: null,
+};
+
+const currencyFieldMetadataItem: FieldMetadataItem = {
+ ...getMockFieldMetadataItemOrThrow({
+ objectMetadataItem: opportunityObjectMetadataItem,
+ fieldName: 'amount',
+ }),
+ defaultValue: { amountMicros: null, currencyCode: "'USD'" },
+};
+
+type RecordFormFieldInputsWithDraftProps = {
+ fieldMetadataItems: FieldMetadataItem[];
+ initialDraftRecord?: Partial<ObjectRecord>;
+ onFieldValueChange: (gqlFieldName: string, value: JsonValue) => void;
+};
+
+const RecordFormFieldInputsWithDraft = ({
+ fieldMetadataItems,
+ initialDraftRecord = {},
+ onFieldValueChange,
+}: RecordFormFieldInputsWithDraftProps) => {
+ const [draftRecord, setDraftRecord] =
+ useState<Partial<ObjectRecord>>(initialDraftRecord);
+
+ const writeDraft = ({
+ gqlFieldName,
+ value,
+ }: {
+ gqlFieldName: string;
+ value: JsonValue;
+ }) => {
+ onFieldValueChange(gqlFieldName, value);
+ setDraftRecord((previousDraftRecord) => ({
+ ...previousDraftRecord,
+ [gqlFieldName]: value,
+ }));
+ };
+
+ return (
+ <RecordFormFieldInputs
+ objectMetadataItem={companyObjectMetadataItem}
+ fieldMetadataItems={fieldMetadataItems}
+ draftRecord={draftRecord}
+ onFieldValueChange={(gqlFieldName, value) =>
+ writeDraft({ gqlFieldName, value })
+ }
+ onFieldValueClear={(gqlFieldName) =>
+ writeDraft({ gqlFieldName, value: null })
+ }
+ />
+ );
+};
+
+const meta: Meta<typeof RecordFormFieldInputsWithDraft> = {
+ title: 'Modules/ObjectRecord/RecordForm/RecordFormFieldInputs',
+ component: RecordFormFieldInputsWithDraft,
+ decorators: [ComponentDecorator],
+ args: {
+ fieldMetadataItems: [percentageFieldMetadataItem, booleanFieldMetadataItem],
+ onFieldValueChange: fn(),
+ },
+};
+
+export default meta;
+type Story = StoryObj<typeof RecordFormFieldInputsWithDraft>;
+
+export const Percentage: Story = {
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const input = canvas.getByRole('textbox', { name: 'Conversion rate' });
+
+ await expect(canvas.getByText('%')).toBeVisible();
+
+ await userEvent.type(input, '25.5');
+
+ await expect(input).toHaveValue('25.5');
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'conversionRate',
+ 0.255,
+ );
+
+ await userEvent.clear(input);
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'conversionRate',
+ null,
+ );
+
+ await userEvent.paste('25%');
+
+ await expect(input).toHaveValue('25');
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'conversionRate',
+ 0.25,
+ );
+ },
+};
+
+export const InvalidPercentage: Story = {
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const input = canvas.getByRole('textbox', { name: 'Conversion rate' });
+
+ await userEvent.type(input, 'abc');
+
+ await expect(canvas.getByRole('alert')).toHaveTextContent('Invalid number');
+ await expect(args.onFieldValueChange).not.toHaveBeenCalled();
+
+ await userEvent.clear(input);
+ await userEvent.type(input, '12');
+
+ await expect(canvas.queryByRole('alert')).not.toBeInTheDocument();
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'conversionRate',
+ 0.12,
+ );
+ },
+};
+
+export const TrueFalse: Story = {
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const trueOption = canvas.getByRole('radio', { name: 'True' });
+ const falseOption = canvas.getByRole('radio', { name: 'False' });
+
+ await expect(
+ canvas.getByRole('radiogroup', { name: 'Active' }),
+ ).toBeVisible();
+ await expect(trueOption).not.toBeChecked();
+ await expect(falseOption).not.toBeChecked();
+ await expect(args.onFieldValueChange).not.toHaveBeenCalled();
+
+ await userEvent.click(falseOption);
+
+ await expect(falseOption).toBeChecked();
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'active',
+ false,
+ );
+
+ await userEvent.keyboard('{ArrowLeft}');
+
+ await expect(trueOption).toBeChecked();
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith(
+ 'active',
+ true,
+ );
+ },
+};
+
+export const StoredValues: Story = {
+ args: {
+ fieldMetadataItems: [
+ percentageFieldMetadataItem,
+ { ...booleanFieldMetadataItem, defaultValue: false },
+ ],
+ initialDraftRecord: { conversionRate: 0.25 },
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+
+ await expect(
+ canvas.getByRole('textbox', { name: 'Conversion rate' }),
+ ).toHaveValue('25');
+ await expect(canvas.getByRole('radio', { name: 'False' })).toBeChecked();
+ await expect(args.onFieldValueChange).not.toHaveBeenCalled();
+ },
+};
+
+export const Currency: Story = {
+ args: {
+ fieldMetadataItems: [currencyFieldMetadataItem],
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const input = canvas.getByRole('textbox', { name: 'Amount' });
+
+ await expect(
+ canvas.getByRole('button', { name: 'Currency: USD' }),
+ ).toBeVisible();
+
+ await userEvent.type(input, '3.21');
+
+ await expect(args.onFieldValueChange).toHaveBeenLastCalledWith('amount', {
+ currencyCode: CurrencyCode.USD,
+ amountMicros: 3_210_000,
+ });
+
+ await userEvent.clear(input);
+ await userEvent.type(input, 'abc');
+
+ await expect(canvas.getByRole('alert')).toHaveTextContent('Invalid number');
+ },
+};
diff --git a/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.clearing.test.tsx b/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.clearing.test.tsx
deleted file mode 100644
index af16ce096f5..00000000000
--- a/packages/twenty-front/src/modules/object-record/record-form/components/__tests__/RecordFormFieldInputs.clearing.test.tsx
+++ /dev/null
@@ -1,119 +0,0 @@
-import { type EnrichedObjectMetadataItem } from '@/object-metadata/types/EnrichedObjectMetadataItem';
-import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
-import { RecordFormFieldInputs } from '@/object-record/record-form/components/RecordFormFieldInputs';
-import { type ObjectRecord } from '@/object-record/types/ObjectRecord';
-import { i18n } from '@lingui/core';
-import { I18nProvider } from '@lingui/react';
-import { render, screen } from '@testing-library/react';
-import userEvent from '@testing-library/user-event';
-import { createStore, Provider } from 'jotai';
-import { useState } from 'react';
-import { CurrencyCode } from 'twenty-shared/constants';
-import { type JsonValue } from 'type-fest';
-import { FieldMetadataType } from '~/generated-metadata/graphql';
-
-jest.mock(
- '@/object-record/record-field/ui/form-types/components/VariableChipStandalone',
- () => ({
- VariableChipStandalone: ({
- rawVariableName,
- }: {
- rawVariableName: string;
- }) => <span>{rawVariableName}</span>,
- }),
-);
-
-// The rich text inputs pull in BlockNote, which jest cannot load; they are
-// never rendered for a currency field.
-jest.mock(
- '@/object-record/record-field/ui/form-types/components/FormRecordRichTextFieldInput',
- () => ({
- FormRecordRichTextFieldInput: () => null,
- }),
-);
-
-jest.mock(
- '@/object-record/record-field/ui/form-types/components/FormRichTextFieldInput',
- () => ({
- FormRichTextFieldInput: () => null,
- }),
-);
-
-const currencyFieldMetadataItem = {
- id: 'amount-field-id',
- name: 'amount',
- label: 'Amount',
- type: FieldMetadataType.CURRENCY,
- defaultValue: { amountMicros: null, currencyCode: "'USD'" },
-} as unknown as FieldMetadataItem;
-
-const objectMetadataItem = {
- id: 'opportunity-object-id',
- nameSingular: 'opportunity',
-} as unknown as EnrichedObjectMetadataItem;
-
-const renderInputs = () => {
- const onFieldValueChange = jest.fn();
- const onFieldValueClear = jest.fn();
- const store = createStore();
-
- // Mirrors how the record creation form keeps the draft: a change writes the
- // value under the field name, a clear writes null.
- const Form = () => {
- const [draftRecord, setDraftRecord] = useState<Partial<ObjectRecord>>({});
-
- return (
- <RecordFormFieldInputs
- objectMetadataItem={objectMetadataItem}
- fieldMetadataItems={[currencyFieldMetadataItem]}
- draftRecord={draftRecord}
- onFieldValueChange={(gqlFieldName: string, value: JsonValue) => {
- onFieldValueChange(gqlFieldName, value);
- setDraftRecord((previousDraftRecord) => ({
- ...previousDraftRecord,
- [gqlFieldName]: value,
- }));
- }}
- onFieldValueClear={(gqlFieldName: string) => {
- onFieldValueClear(gqlFieldName);
- setDraftRecord((previousDraftRecord) => ({
- ...previousDraftRecord,
- [gqlFieldName]: null,
- }));
- }}
- />
- );
- };
-
- render(
- <I18nProvider i18n={i18n}>
- <Provider store={store}>
- <Form />
- </Provider>
- </I18nProvider>,
- );
-
- return { onFieldValueChange, onFieldValueClear };
-};
-
-describe('RecordFormFieldInputs with the real currency input', () => {
- it('pre-fills the metadata default currency', () => {
- renderInputs();
-
- expect(
- screen.getByRole('button', { name: 'Currency: USD' }),
- ).toBeInTheDocument();
- });
-
- it('keeps the default when an amount is typed without touching the currency', async () => {
- const user = userEvent.setup();
- const { onFieldValueChange } = renderInputs();
-
- await user.type(screen.getByRole('textbox'), '3.21');
-
- expect(onFieldValueChange).toHaveBeenLastCalledWith('amount', {
- currencyCode: CurrencyCode.USD,
- amountMicros: 3_210_000,
- });
- });
-});
diff --git a/packages/twenty-front/src/modules/object-record/record-form/utils/getRecordFormBooleanFieldDefaultValue.ts b/packages/twenty-front/src/modules/object-record/record-form/utils/getRecordFormBooleanFieldDefaultValue.ts
new file mode 100644
index 00000000000..913a6a011fb
--- /dev/null
+++ b/packages/twenty-front/src/modules/object-record/record-form/utils/getRecordFormBooleanFieldDefaultValue.ts
@@ -0,0 +1,11 @@
+import { type FieldMetadataItem } from '@/object-metadata/types/FieldMetadataItem';
+import { isBoolean } from '@sniptt/guards';
+import { FieldMetadataType } from '~/generated-metadata/graphql';
+
+export const getRecordFormBooleanFieldDefaultValue = (
+ fieldMetadataItem: Pick<FieldMetadataItem, 'type' | 'defaultValue'>,
+): boolean | undefined =>
+ fieldMetadataItem.type === FieldMetadataType.BOOLEAN &&
+ isBoolean(fieldMetadataItem.defaultValue)
+ ? fieldMetadataItem.defaultValue
+ : undefined;
diff --git a/packages/twenty-front/src/modules/ui/field/input/components/StyledFieldInputSuffix.tsx b/packages/twenty-front/src/modules/ui/field/input/components/StyledFieldInputSuffix.tsx
new file mode 100644
index 00000000000..b1d7be1021e
--- /dev/null
+++ b/packages/twenty-front/src/modules/ui/field/input/components/StyledFieldInputSuffix.tsx
@@ -0,0 +1,16 @@
+import { styled } from '@linaria/react';
+import { themeCssVariables } from 'twenty-ui/theme';
+
+export const StyledFieldInputSuffix = styled.span`
+ align-items: center;
+ align-self: stretch;
+ border-left: 1px solid ${themeCssVariables.border.color.medium};
+ box-sizing: border-box;
+ color: ${themeCssVariables.font.color.tertiary};
+ display: flex;
+ flex-shrink: 0;
+ font-size: ${themeCssVariables.font.size.md};
+ font-weight: ${themeCssVariables.font.weight.medium};
+ justify-content: center;
+ width: ${themeCssVariables.spacing[8]};
+`;
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 72ba77c48e1..2353390f824 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -128,7 +128,8 @@
"SearchInputProps": "components/input/SearchInput/types/SearchInputProps",
"SegmentedControlOption": "components/input/SegmentedControl/types/SegmentedControlOption",
"SegmentedControlProps": "components/input/SegmentedControl/types/SegmentedControlProps",
- "SegmentedControlSize": "components/input/SegmentedControl/types/SegmentedControlSize"
+ "SegmentedControlSize": "components/input/SegmentedControl/types/SegmentedControlSize",
+ "SegmentedControlVariant": "components/input/SegmentedControl/types/SegmentedControlVariant"
}
},
"components/layout": {
diff --git a/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts b/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts
index 5863e6d0838..4551e2ceec7 100644
--- a/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts
+++ b/packages/twenty-ui/docs/segmentedControlPropDescriptions.ts
@@ -8,6 +8,8 @@ export const SEGMENTED_CONTROL_PROP_DESCRIPTIONS = {
options:
'Options with a unique string `value`, a `label` or `startIcon`, and optional `disabled`. Icon-only options require an `aria-label`.',
size: 'Control height: `sm` (24px) or `md` (32px).',
+ variant:
+ 'Shape: `round` is a pill, `rectangle` fills its container with form-field corners.',
'aria-label': 'Accessible group name. Supply this or `aria-labelledby`.',
'aria-labelledby':
'ID of an element that labels the group. Supply this or `aria-label`.',
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 31b774a68ee..943b4c62900 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -2100,6 +2100,13 @@
"required": false,
"defaultValue": null,
"description": "The controlled value of the radio item that should be currently selected.\n\nTo render an uncontrolled radio group, use the `defaultValue` prop instead."
+ },
+ {
+ "name": "variant",
+ "type": "\"rectangle\" | \"round\"",
+ "required": false,
+ "defaultValue": "round",
+ "description": "Shape: `round` is a pill, `rectangle` fills its container with form-field corners."
}
]
},
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss
index fe569f20f0b..452be7c2a12 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.module.scss
@@ -16,6 +16,31 @@
&[data-item-width='content'] {
grid-auto-columns: max-content;
}
+
+ &[data-variant='rectangle'] {
+ border-radius: var(--t-border-radius-md);
+ corner-shape: var(--t-corner-shape, superellipse(2.2));
+ display: grid;
+
+ &:has(.item:focus-visible) {
+ border-color: var(--t-color-blue);
+ }
+
+ .item {
+ border-radius: calc(
+ var(--t-border-radius-md) - var(--tw-segmented-control-padding) - 1px
+ );
+ corner-shape: var(--t-corner-shape, superellipse(2.2));
+
+ &:focus-visible {
+ outline: none;
+ }
+
+ &:focus-visible:not([data-checked]) {
+ background: var(--t-background-transparent-lighter);
+ }
+ }
+ }
}
.sm {
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx
index e1cbf7bc6ec..7bbd83bcf9c 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/SegmentedControl.tsx
@@ -16,6 +16,7 @@ export const SegmentedControl = <TValue extends string>({
itemWidth = 'equal',
options,
size = 'md',
+ variant = 'round',
...props
}: SegmentedControlProps<TValue>) => {
const optionNameIdPrefix = useId();
@@ -28,6 +29,7 @@ export const SegmentedControl = <TValue extends string>({
className,
)}
data-item-width={itemWidth}
+ data-variant={variant}
>
{options.map(
(
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx b/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx
index dd920e6a751..3d548fdcb1c 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/__stories__/SegmentedControl.stories.tsx
@@ -101,6 +101,11 @@ export const Small: Story = {
args: { size: 'sm' },
};
+export const Rectangle: Story = {
+ args: { variant: 'rectangle', style: { width: 280 } },
+ play: Default.play,
+};
+
export const ContentWidth: Story = {
args: { itemWidth: 'content' },
play: async ({ canvasElement }) => {
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
index 1a8503b649b..81d10b9711d 100644
--- a/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlProps.ts
@@ -2,6 +2,7 @@ import { type RadioGroupProps } from '@ui/primitives/input/RadioGroup/types/Radi
import { type SegmentedControlOption } from './SegmentedControlOption';
import { type SegmentedControlSize } from './SegmentedControlSize';
+import { type SegmentedControlVariant } from './SegmentedControlVariant';
export type SegmentedControlProps<TValue extends string = string> = Omit<
RadioGroupProps<TValue>,
@@ -10,4 +11,5 @@ export type SegmentedControlProps<TValue extends string = string> = Omit<
itemWidth?: 'content' | 'equal';
options: readonly SegmentedControlOption<TValue>[];
size?: SegmentedControlSize;
+ variant?: SegmentedControlVariant;
} & ({ 'aria-label': string } | { 'aria-labelledby': string });
diff --git a/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlVariant.ts b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlVariant.ts
new file mode 100644
index 00000000000..398d36c1976
--- /dev/null
+++ b/packages/twenty-ui/src/components/input/SegmentedControl/types/SegmentedControlVariant.ts
@@ -0,0 +1 @@
+export type SegmentedControlVariant = 'round' | 'rectangle';
diff --git a/packages/twenty-ui/src/components/input/index.ts b/packages/twenty-ui/src/components/input/index.ts
index cbd6be94c88..c8b188c7d6d 100644
--- a/packages/twenty-ui/src/components/input/index.ts
+++ b/packages/twenty-ui/src/components/input/index.ts
@@ -46,3 +46,4 @@ export { SegmentedControl } from './SegmentedControl/SegmentedControl';
export type { SegmentedControlOption } from './SegmentedControl/types/SegmentedControlOption';
export type { SegmentedControlProps } from './SegmentedControl/types/SegmentedControlProps';
export type { SegmentedControlSize } from './SegmentedControl/types/SegmentedControlSize';
+export type { SegmentedControlVariant } from './SegmentedControl/types/SegmentedControlVariant';