Skip to content

The open alternative to Salesforce, designed for AI.

Add plain Chips with exact width limits (#28301)

Raphaël Bosi61eeb86bda5a
diff --git a/packages/twenty-docs/snippets/ui/generated/data-display/chip.mdx b/packages/twenty-docs/snippets/ui/generated/data-display/chip.mdx
index 333dff93bfd..0de84f53e35 100644
--- a/packages/twenty-docs/snippets/ui/generated/data-display/chip.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/data-display/chip.mdx
@@ -40,7 +40,7 @@
</ParamField>
<ParamField body="maxWidth" type="number">
- Maximum chip width in pixels, used to constrain the content.
+ Maximum rendered chip width in pixels, including its leading and trailing padding.
</ParamField>
<ParamField body="render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, {}&gt;">
@@ -75,8 +75,8 @@
Truncates overflowing content with an ellipsis. Defaults to true.
</ParamField>
-<ParamField body="variant" type="&quot;ghost&quot; | &quot;soft&quot; | &quot;solid&quot;" default="ghost">
- Background treatment of the chip.
+<ParamField body="variant" type="&quot;ghost&quot; | &quot;plain&quot; | &quot;soft&quot; | &quot;solid&quot;" default="ghost">
+ Background treatment. Plain has no resting fill or leading padding, with ghost hover and pressed feedback when clickable.
</ParamField>
<ParamField body="weight" type="&quot;medium&quot; | &quot;regular&quot;" default="regular">
diff --git a/packages/twenty-docs/ui/primitives/data-display/chip.mdx b/packages/twenty-docs/ui/primitives/data-display/chip.mdx
index e1f494e12e1..e8c922a6d91 100644
--- a/packages/twenty-docs/ui/primitives/data-display/chip.mdx
+++ b/packages/twenty-docs/ui/primitives/data-display/chip.mdx
@@ -44,7 +44,7 @@ Chip never inserts a label. Supply a translated fallback from your application w
height={200}
/>
-`size` accepts `sm` or `md`. `variant` accepts `ghost`, `soft`, or `solid`; `ghost` is the default. Use `shape="round"` for a pill, `weight="medium"` for emphasis, and `color="secondary"` for secondary text.
+`size` accepts `sm` or `md`. `variant` accepts `ghost`, `soft`, `solid`, or `plain`; `ghost` is the default. Plain chips have no resting fill or leading padding. Clickable plain chips retain the ghost hover and pressed backgrounds, pointer cursor, and focus ring. Use `shape="round"` for a pill, `weight="medium"` for emphasis, and `color="secondary"` for secondary text.
## Buttons and links
@@ -101,12 +101,14 @@ export const FileChip = () => (
);
```
-`maxWidth` constrains the chip in pixels. Content truncates with an ellipsis by default; `truncate={false}` leaves it unconstrained by truncation. String children supply their own tooltip text. Set `tooltipContent` for custom text or node content, `tooltipDelay` for the opening delay, and `isTooltipMultiline` to preserve line breaks. `alwaysShowTooltip` also enables the tooltip when content fits. These options follow [OverflowingTextWithTooltip](/ui/primitives/typography/overflowing-text-with-tooltip). Keep essential information available without relying on hover.
+`maxWidth` constrains the rendered chip width in pixels, including padding. The same limit applies to plain chips with asymmetric padding. Content truncates with an ellipsis by default; `truncate={false}` leaves it unconstrained by truncation. String children supply their own tooltip text. Set `tooltipContent` for custom text or node content, `tooltipDelay` for the opening delay, and `isTooltipMultiline` to preserve line breaks. `alwaysShowTooltip` also enables the tooltip when content fits. These options follow [OverflowingTextWithTooltip](/ui/primitives/typography/overflowing-text-with-tooltip). Keep essential information available without relying on hover.
## Migration
Replace `emptyLabel` with caller-provided fallback children, and replace `forceEmptyText` or `isLabelHidden` with omitted children. Keep translated product fallbacks in the application. Replace `tooltipLabel` with `tooltipContent`. Move `disabled` to the explicit interactive owner and remove `nativeButton`. Add a native button or link through `render` wherever the chip previously relied on `onClick` to choose its element.
+Replace leading-padding overrides with `variant="plain"`. Keep `clickable` enabled for native links and buttons that need hover and pressed feedback.
+
## Props
Types and defaults are generated from the public component types. Native attributes and event handlers are also accepted.
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-chip-controls.front-component.tsx b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-chip-controls.front-component.tsx
index 8dca696ac92..c2350313f13 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-chip-controls.front-component.tsx
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/twenty-ui-chip-controls.front-component.tsx
@@ -1,4 +1,4 @@
-import { createElement, useState } from 'react';
+import { useState } from 'react';
import { defineFrontComponent } from 'twenty-sdk/define';
import { Chip } from 'twenty-ui/primitives/data-display';
import { IconStar } from 'twenty-ui/icon';
@@ -27,7 +27,7 @@ const ChipControls = () => {
render={<button type="button" />}
onClick={handleClick}
onKeyDown={(event) => setLastKey(event.key)}
- variant="soft"
+ variant="plain"
startElement={<IconStar size={14} aria-hidden />}
ref={(element) => {
element?.setAttribute('data-ref-target', 'chip-button');
@@ -81,12 +81,8 @@ const ChipControls = () => {
node: (
<>
<Chip
- render={(renderProps) =>
- createElement('a', {
- ...renderProps,
- href: '#chip-documentation',
- 'data-composed': 'chip-link',
- })
+ render={
+ <a href="#chip-documentation" data-composed="chip-link" />
}
aria-label="Chip documentation"
ref={(element) => {
@@ -108,6 +104,7 @@ const ChipControls = () => {
node: (
<>
<Chip
+ variant="plain"
maxWidth={140}
tooltipContent={'Caller supplied details\nFull account name'}
tooltipDelay={0}
diff --git a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/chipControlsTest.ts b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/chipControlsTest.ts
index ac04d489365..62010f054e2 100644
--- a/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/chipControlsTest.ts
+++ b/packages/twenty-front-component-renderer/src/__stories__/twenty-ui-gallery/utils/chipControlsTest.ts
@@ -35,6 +35,8 @@ export const chipControlsTest: TwentyUiGalleryPlayFunction = async (
const button = canvas.getByRole('button', { name: 'Open chip' });
expect(button.tagName).toBe('BUTTON');
+ expect(getComputedStyle(button).paddingInlineStart).toBe('0px');
+ expect(getComputedStyle(button).paddingInlineEnd).toBe('4px');
expect(button).toHaveAttribute('type', 'button');
expect(button).toHaveAttribute('data-ref-target', 'chip-button');
await user.click(button);
@@ -79,6 +81,9 @@ export const chipControlsTest: TwentyUiGalleryPlayFunction = async (
).not.toBe('ellipsis');
const overflowingLabel = canvas.getByText(OVERFLOW_LABEL);
+ expect(overflowingLabel.parentElement?.getBoundingClientRect().width).toBe(
+ 140,
+ );
await waitFor(
() => {
expect(getComputedStyle(overflowingLabel).textOverflow).toBe('ellipsis');
diff --git a/packages/twenty-front/src/modules/applications/components/AppChip.tsx b/packages/twenty-front/src/modules/applications/components/AppChip.tsx
index c75bbac727e..5dffd3e7a2e 100644
--- a/packages/twenty-front/src/modules/applications/components/AppChip.tsx
+++ b/packages/twenty-front/src/modules/applications/components/AppChip.tsx
@@ -1,7 +1,10 @@
import { useApplicationChipData } from '@/applications/hooks/useApplicationChipData';
import { styled } from '@linaria/react';
-import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
-import { Avatar, type AvatarSize } from 'twenty-ui/primitives/data-display';
+import {
+ Avatar,
+ type AvatarSize,
+ Chip,
+} from 'twenty-ui/primitives/data-display';
import { themeCssVariables } from 'twenty-ui/theme';
import { getAbsoluteImageUrl } from '~/utils/image/getAbsoluteImageUrl';
@@ -26,7 +29,6 @@ const StyledContainer = styled.div`
color: ${themeCssVariables.font.color.secondary};
display: inline-flex;
font-size: ${themeCssVariables.font.size.sm};
- font-weight: ${themeCssVariables.font.weight.regular};
gap: ${themeCssVariables.spacing[1]};
max-width: 100%;
min-width: 0;
@@ -48,22 +50,43 @@ export const AppChip = ({
fallbackApplicationData,
});
+ const avatar = (
+ <Avatar
+ shape={rounded ? 'circle' : 'square'}
+ variant={rounded ? 'soft' : 'outline'}
+ size={size}
+ src={getAbsoluteImageUrl(logoUrl ?? applicationChipData.logo)}
+ name={applicationChipData.name}
+ colorSeed={applicationChipData.seed}
+ color={applicationChipData.colors?.color}
+ backgroundColor={applicationChipData.colors?.backgroundColor}
+ borderColor={applicationChipData.colors?.borderColor}
+ pulsing={pulsing}
+ />
+ );
+
return (
<StyledContainer className={className}>
- <Avatar
- shape={rounded ? 'circle' : 'square'}
- variant={rounded ? 'soft' : 'outline'}
- size={size}
- src={getAbsoluteImageUrl(logoUrl ?? applicationChipData.logo)}
- name={applicationChipData.name}
- colorSeed={applicationChipData.seed}
- color={applicationChipData.colors?.color}
- backgroundColor={applicationChipData.colors?.backgroundColor}
- borderColor={applicationChipData.colors?.borderColor}
- pulsing={pulsing}
- />
- {!chipOnly && (
- <OverflowingTextWithTooltip text={applicationChipData.name} />
+ {chipOnly ? (
+ avatar
+ ) : (
+ <Chip
+ variant="plain"
+ color="secondary"
+ weight="regular"
+ startElement={avatar}
+ style={{
+ blockSize: 'auto',
+ color: 'inherit',
+ fontSize: 'inherit',
+ fontWeight: themeCssVariables.font.weight.regular,
+ gap: 'inherit',
+ minWidth: 0,
+ paddingBlock: 0,
+ }}
+ >
+ {applicationChipData.name}
+ </Chip>
)}
</StyledContainer>
);
diff --git a/packages/twenty-front/src/modules/blocknote-editor/blocks/MentionInlineContent.tsx b/packages/twenty-front/src/modules/blocknote-editor/blocks/MentionInlineContent.tsx
index ff5a15fd829..e7712ccebcc 100644
--- a/packages/twenty-front/src/modules/blocknote-editor/blocks/MentionInlineContent.tsx
+++ b/packages/twenty-front/src/modules/blocknote-editor/blocks/MentionInlineContent.tsx
@@ -51,23 +51,11 @@ const LegacyMentionRenderer = ({
}
if (!isDefined(objectMetadataItem)) {
- return (
- <Chip
- variant="ghost"
- aria-disabled
- style={{ paddingInlineStart: 0 }}
- >{t`Unknown object`}</Chip>
- );
+ return <Chip variant="plain" aria-disabled>{t`Unknown object`}</Chip>;
}
if (!isDefined(record)) {
- return (
- <Chip
- variant="ghost"
- aria-disabled
- style={{ paddingInlineStart: 0 }}
- >{t`Deleted record`}</Chip>
- );
+ return <Chip variant="plain" aria-disabled>{t`Deleted record`}</Chip>;
}
return (
diff --git a/packages/twenty-front/src/modules/log-console/components/LogConsoleMemberChip.tsx b/packages/twenty-front/src/modules/log-console/components/LogConsoleMemberChip.tsx
index cc70c7f4feb..c0e6048eff2 100644
--- a/packages/twenty-front/src/modules/log-console/components/LogConsoleMemberChip.tsx
+++ b/packages/twenty-front/src/modules/log-console/components/LogConsoleMemberChip.tsx
@@ -22,9 +22,8 @@ export const LogConsoleMemberChip = (props: LogConsoleMemberChipProps) => {
return (
<Chip
- variant="ghost"
+ variant="plain"
startElement={<LogConsoleMemberAvatar member={member} />}
- style={{ paddingInlineStart: 0 }}
>
{getChipLabel(member.name).content}
</Chip>
diff --git a/packages/twenty-front/src/modules/mention/components/MentionRecordChip.tsx b/packages/twenty-front/src/modules/mention/components/MentionRecordChip.tsx
index feb2120970e..98c2a2127b9 100644
--- a/packages/twenty-front/src/modules/mention/components/MentionRecordChip.tsx
+++ b/packages/twenty-front/src/modules/mention/components/MentionRecordChip.tsx
@@ -21,23 +21,11 @@ export const MentionRecordChip = ({
imageUrl,
}: MentionRecordChipProps) => {
if (!isNonEmptyString(objectNameSingular)) {
- return (
- <Chip
- variant="ghost"
- aria-disabled
- style={{ paddingInlineStart: 0 }}
- >{t`Unknown object`}</Chip>
- );
+ return <Chip variant="plain" aria-disabled>{t`Unknown object`}</Chip>;
}
if (!isNonEmptyString(recordId)) {
- return (
- <Chip
- variant="ghost"
- aria-disabled
- style={{ paddingInlineStart: 0 }}
- >{t`Deleted record`}</Chip>
- );
+ return <Chip variant="plain" aria-disabled>{t`Deleted record`}</Chip>;
}
const linkToShowPage = getLinkToShowPage(objectNameSingular, {
diff --git a/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowChip.tsx b/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowChip.tsx
index 43ae196bebb..89746d920f8 100644
--- a/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowChip.tsx
+++ b/packages/twenty-front/src/modules/object-core/workflows/components/CoreWorkflowChip.tsx
@@ -44,11 +44,7 @@ export const CoreWorkflowChip = ({ coreRecordId }: CoreWorkflowChipProps) => {
if (disableChipClick) {
return (
- <Chip
- variant="ghost"
- startElement={avatar}
- style={{ paddingInlineStart: 0 }}
- >
+ <Chip variant="plain" startElement={avatar}>
{content}
</Chip>
);
diff --git a/packages/twenty-front/src/modules/object-record/components/RecordChip.tsx b/packages/twenty-front/src/modules/object-record/components/RecordChip.tsx
index c9e28be4fbc..8e5cc887833 100644
--- a/packages/twenty-front/src/modules/object-record/components/RecordChip.tsx
+++ b/packages/twenty-front/src/modules/object-record/components/RecordChip.tsx
@@ -75,7 +75,7 @@ export const RecordChip = ({
weight={isBold ? 'medium' : 'regular'}
size={size}
maxWidth={maxWidth}
- variant="ghost"
+ variant="plain"
startElement={
isIconHidden ? null : (
<AvatarOrIcon
@@ -86,7 +86,6 @@ export const RecordChip = ({
/>
)
}
- style={{ paddingInlineStart: 0 }}
>
{isLabelHidden ? undefined : content}
</Chip>
@@ -109,9 +108,8 @@ export const RecordChip = ({
/>
)
}
- variant={variant ?? 'soft'}
+ variant={variant === 'ghost' ? 'plain' : (variant ?? 'soft')}
clickable={variant !== 'ghost'}
- style={variant === 'ghost' ? { paddingInlineStart: 0 } : undefined}
to={to ?? getLinkToShowPage(objectNameSingular, record)}
onClick={handleCustomClick}
triggerEvent={triggerEvent}
diff --git a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx
index 711fcd927c4..707da5602f1 100644
--- a/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx
+++ b/packages/twenty-front/src/modules/page-layout/widgets/call-recording-transcript/components/CallRecordingTranscriptEntryListItem.tsx
@@ -126,7 +126,7 @@ export const CallRecordingTranscriptEntryListItem = ({
>
<StyledEntryHeader>
<Chip
- variant="ghost"
+ variant="plain"
startElement={
<Avatar
name={speakerName}
@@ -135,7 +135,6 @@ export const CallRecordingTranscriptEntryListItem = ({
shape="circle"
/>
}
- style={{ paddingInlineStart: 0 }}
>
{getChipLabel(speakerName).content}
</Chip>
diff --git a/packages/twenty-front/src/modules/settings/admin-panel/apps/components/__stories__/SettingsAdminApps.stories.tsx b/packages/twenty-front/src/modules/settings/admin-panel/apps/components/__stories__/SettingsAdminApps.stories.tsx
index 9ff95012f4e..0b68b1a502d 100644
--- a/packages/twenty-front/src/modules/settings/admin-panel/apps/components/__stories__/SettingsAdminApps.stories.tsx
+++ b/packages/twenty-front/src/modules/settings/admin-panel/apps/components/__stories__/SettingsAdminApps.stories.tsx
@@ -140,7 +140,24 @@ export const DisplaysAuthorAndInstallCount: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
- expect(await canvas.findByText('Acme app')).toBeVisible();
+ const applicationName = await canvas.findByText('Acme app');
+ const applicationNameStyle = getComputedStyle(applicationName);
+ const rootFontSizeInPixels = Number.parseFloat(
+ getComputedStyle(applicationName.ownerDocument.documentElement).fontSize,
+ );
+ const mediumFontSizeInPixels =
+ Number.parseFloat(
+ applicationNameStyle.getPropertyValue('--t-font-size-md'),
+ ) * rootFontSizeInPixels;
+
+ expect(applicationName).toBeVisible();
+ expect(applicationName).toHaveStyle({
+ color: applicationNameStyle.getPropertyValue('--t-font-color-primary'),
+ fontSize: `${mediumFontSizeInPixels}px`,
+ });
+ expect(applicationName.parentElement).toHaveStyle({
+ gap: applicationNameStyle.getPropertyValue('--t-spacing-2'),
+ });
expect(canvas.getByText('Acme Corp')).toBeVisible();
expect(canvas.getByText('3')).toBeVisible();
},
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsItemTypeTag.tsx b/packages/twenty-front/src/modules/settings/components/SettingsItemTypeTag.tsx
index 5dc81a76309..3a325f14585 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsItemTypeTag.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsItemTypeTag.tsx
@@ -16,24 +16,25 @@ export const SettingsItemTypeTag = ({
}: SettingsItemTypeTagProps) => {
if (isDefined(applicationId)) {
return <AppChip applicationId={applicationId} />;
- } else if (isRemote === true) {
- return (
- <Chip
- variant="ghost"
- color="primary"
- startElement={
- <Avatar
- shape="square"
- variant="outline"
- size="sm"
- name={t`Remote`}
- colorSeed="Remote"
- />
- }
- style={{ paddingInlineStart: 0 }}
- >{t`Remote`}</Chip>
- );
- } else {
+ }
+
+ if (!isRemote) {
return null;
}
+
+ return (
+ <Chip
+ variant="plain"
+ color="primary"
+ startElement={
+ <Avatar
+ shape="square"
+ variant="outline"
+ size="sm"
+ name={t`Remote`}
+ colorSeed="Remote"
+ />
+ }
+ >{t`Remote`}</Chip>
+ );
};
diff --git a/packages/twenty-front/src/modules/sign-in-background-mock/components/BackgroundMockTableRow.tsx b/packages/twenty-front/src/modules/sign-in-background-mock/components/BackgroundMockTableRow.tsx
index 0097b5c3d54..08073ece365 100644
--- a/packages/twenty-front/src/modules/sign-in-background-mock/components/BackgroundMockTableRow.tsx
+++ b/packages/twenty-front/src/modules/sign-in-background-mock/components/BackgroundMockTableRow.tsx
@@ -82,12 +82,11 @@ const PersonChip = ({ fullName }: { fullName: string | null }) => {
return (
<Chip
size="sm"
- variant="ghost"
+ variant="plain"
color="primary"
startElement={
<Avatar shape="circle" name={fullName} colorSeed={fullName} size="md" />
}
- style={{ paddingInlineStart: 0 }}
>
{fullName}
</Chip>
@@ -110,7 +109,7 @@ export const BackgroundMockTableRow = ({
<StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS.Name}>
<Chip
size="sm"
- variant="ghost"
+ variant="plain"
color="primary"
startElement={
<Avatar
@@ -121,7 +120,6 @@ export const BackgroundMockTableRow = ({
size="md"
/>
}
- style={{ paddingInlineStart: 0 }}
>
{company.name}
</Chip>
@@ -129,7 +127,7 @@ export const BackgroundMockTableRow = ({
<StyledCell width={BACKGROUND_MOCK_COLUMN_WIDTHS.Domain}>
<Chip
size="sm"
- variant="ghost"
+ variant="plain"
color="secondary"
weight="medium"
startElement={
@@ -139,7 +137,6 @@ export const BackgroundMockTableRow = ({
color={theme.font.color.tertiary}
/>
}
- style={{ paddingInlineStart: 0 }}
>
{company.domainName}
</Chip>
diff --git a/packages/twenty-front/src/modules/ui/field/display/components/ActorDisplay.tsx b/packages/twenty-front/src/modules/ui/field/display/components/ActorDisplay.tsx
index dea968ad24e..213d02a6b1b 100644
--- a/packages/twenty-front/src/modules/ui/field/display/components/ActorDisplay.tsx
+++ b/packages/twenty-front/src/modules/ui/field/display/components/ActorDisplay.tsx
@@ -23,7 +23,7 @@ export const ActorDisplay = ({
return (
<Chip
- variant="ghost"
+ variant="plain"
startElement={
source === 'APPLICATION' && isDefined(context?.applicationId) ? (
<AppChip
@@ -42,7 +42,6 @@ export const ActorDisplay = ({
/>
)
}
- style={{ paddingInlineStart: 0 }}
>
{getChipLabel(name).content}
</Chip>
diff --git a/packages/twenty-ui/docs/chipPropDescriptions.ts b/packages/twenty-ui/docs/chipPropDescriptions.ts
index 9b285590f92..15f437285ab 100644
--- a/packages/twenty-ui/docs/chipPropDescriptions.ts
+++ b/packages/twenty-ui/docs/chipPropDescriptions.ts
@@ -4,7 +4,8 @@ export const CHIP_PROP_DESCRIPTIONS = {
children:
'Caller-owned content. Missing or empty children add no fallback label.',
size: 'Visual size of the chip.',
- variant: 'Background treatment of the chip.',
+ variant:
+ 'Background treatment. Plain has no resting fill or leading padding, with ghost hover and pressed feedback when clickable.',
color: 'Primary or secondary text color.',
shape: 'Square or round corners.',
weight: 'Font weight of the content.',
@@ -15,7 +16,8 @@ export const CHIP_PROP_DESCRIPTIONS = {
'Content after the label. Avoid interactive content when the chip itself is a button or link.',
endElementDivider:
'Adds a divider before `endElement` when that slot has content.',
- maxWidth: 'Maximum chip width in pixels, used to constrain the content.',
+ maxWidth:
+ 'Maximum rendered chip width in pixels, including its leading and trailing padding.',
truncate: 'Truncates overflowing content with an ellipsis. Defaults to true.',
tooltipContent:
'Tooltip text. Defaults to string children. Supply text explicitly for node content.',
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index ab9970bc2a7..d8288e04fe6 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -11040,7 +11040,7 @@
"type": "number",
"required": false,
"defaultValue": null,
- "description": "Maximum chip width in pixels, used to constrain the content."
+ "description": "Maximum rendered chip width in pixels, including its leading and trailing padding."
},
{
"name": "render",
@@ -11100,10 +11100,10 @@
},
{
"name": "variant",
- "type": "\"ghost\" | \"soft\" | \"solid\"",
+ "type": "\"ghost\" | \"plain\" | \"soft\" | \"solid\"",
"required": false,
"defaultValue": "ghost",
- "description": "Background treatment of the chip."
+ "description": "Background treatment. Plain has no resting fill or leading padding, with ghost hover and pressed feedback when clickable."
},
{
"name": "weight",
diff --git a/packages/twenty-ui/src/primitives/data-display/Chip/Chip.module.scss b/packages/twenty-ui/src/primitives/data-display/Chip/Chip.module.scss
index cea711681b9..86f900518c6 100644
--- a/packages/twenty-ui/src/primitives/data-display/Chip/Chip.module.scss
+++ b/packages/twenty-ui/src/primitives/data-display/Chip/Chip.module.scss
@@ -1,14 +1,22 @@
.chip {
@include focus-ring;
- --tw-chip-padding: var(--t-spacing-1);
+ --tw-chip-padding-start: var(--t-spacing-1);
+ --tw-chip-padding-end: var(--t-spacing-1);
box-sizing: content-box;
align-items: center;
display: inline-flex;
gap: var(--t-spacing-1);
block-size: var(--t-spacing-3);
- max-inline-size: var(--tw-chip-max-width, 100%);
- padding: var(--t-spacing-1) var(--tw-chip-padding);
+ max-inline-size: calc(
+ var(
+ --tw-chip-max-width,
+ calc(100% + var(--tw-chip-padding-start) + var(--tw-chip-padding-end))
+ ) -
+ var(--tw-chip-padding-start) - var(--tw-chip-padding-end)
+ );
+ padding-block: var(--t-spacing-1);
+ padding-inline: var(--tw-chip-padding-start) var(--tw-chip-padding-end);
user-select: none;
font: inherit;
color: var(--t-font-color-primary);
@@ -36,6 +44,10 @@
&[data-weight='medium'] {
font-weight: var(--t-font-weight-medium);
}
+ &[data-variant='plain'] {
+ --tw-chip-padding-start: 0px;
+ background: transparent;
+ }
&[data-variant='soft'] {
background: var(--t-background-transparent-light);
}
diff --git a/packages/twenty-ui/src/primitives/data-display/Chip/Chip.tsx b/packages/twenty-ui/src/primitives/data-display/Chip/Chip.tsx
index cefeaaf440f..8e9bb814797 100644
--- a/packages/twenty-ui/src/primitives/data-display/Chip/Chip.tsx
+++ b/packages/twenty-ui/src/primitives/data-display/Chip/Chip.tsx
@@ -54,9 +54,7 @@ export const Chip = ({
style: {
...(isDefined(maxWidth)
? {
- '--tw-chip-max-width': doNotTranslate(
- `calc(${maxWidth}px - 2 * var(--tw-chip-padding))`,
- ),
+ '--tw-chip-max-width': doNotTranslate(`${maxWidth}px`),
}
: {}),
...style,
diff --git a/packages/twenty-ui/src/primitives/data-display/Chip/__stories__/Chip.stories.tsx b/packages/twenty-ui/src/primitives/data-display/Chip/__stories__/Chip.stories.tsx
index 7de137b992e..75d6f08d322 100644
--- a/packages/twenty-ui/src/primitives/data-display/Chip/__stories__/Chip.stories.tsx
+++ b/packages/twenty-ui/src/primitives/data-display/Chip/__stories__/Chip.stories.tsx
@@ -89,7 +89,7 @@ export const Catalog: CatalogStory<Story, typeof Chip> = {
dimensions: [
{
name: 'variants',
- values: ['ghost', 'soft', 'solid'],
+ values: ['ghost', 'soft', 'solid', 'plain'],
props: (variant: ChipVariant) => ({ variant }),
},
{
@@ -127,7 +127,7 @@ export const WithAvatarCatalog: CatalogStory<Story, typeof Chip> = {
dimensions: [
{
name: 'variants',
- values: ['ghost', 'soft', 'solid'],
+ values: ['ghost', 'soft', 'solid', 'plain'],
props: (variant: ChipVariant) => ({ variant }),
},
{
@@ -341,3 +341,57 @@ export const WithoutTruncation: Story = {
await expect(getComputedStyle(chip).overflow).not.toBe('hidden');
},
};
+
+export const Plain: Story = {
+ decorators: [ComponentDecorator],
+ args: {
+ children: 'Open Jane',
+ variant: 'plain',
+ clickable: true,
+ onClick: fn(),
+ render: <button type="button" />,
+ startElement: <Avatar name="Jane" size="sm" />,
+ },
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const chip = canvas.getByRole('button', { name: 'Open Jane' });
+
+ await expect(getComputedStyle(chip).paddingInlineStart).toBe('0px');
+ await expect(getComputedStyle(chip).paddingInlineEnd).toBe('4px');
+ await userEvent.tab();
+ await expect(chip).toHaveFocus();
+ await expect(getComputedStyle(chip).outlineStyle).toBe('solid');
+ await expect(getComputedStyle(chip).cursor).toBe('pointer');
+ await userEvent.click(chip);
+ await expect(args.onClick).toHaveBeenCalledTimes(1);
+ },
+};
+
+export const ExactMaximumWidth: Story = {
+ decorators: [ComponentDecorator],
+ render: () => (
+ <Text style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
+ {(['ghost', 'soft', 'solid', 'plain'] as const).map((variant) => (
+ <Chip
+ key={variant}
+ variant={variant}
+ maxWidth={120}
+ aria-label={variant}
+ startElement={<Avatar name="Jane" size="sm" />}
+ >
+ A long label that needs to be truncated
+ </Chip>
+ ))}
+ </Text>
+ ),
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ for (const variant of ['ghost', 'soft', 'solid', 'plain']) {
+ const chip = canvas.getByLabelText(variant);
+
+ await expect(chip.getBoundingClientRect().width).toBe(120);
+ await expect(chip.getBoundingClientRect().height).toBe(20);
+ }
+ },
+};
diff --git a/packages/twenty-ui/src/primitives/data-display/Chip/types/ChipVariant.ts b/packages/twenty-ui/src/primitives/data-display/Chip/types/ChipVariant.ts
index 3ff90b789c4..1e68903ccdd 100644
--- a/packages/twenty-ui/src/primitives/data-display/Chip/types/ChipVariant.ts
+++ b/packages/twenty-ui/src/primitives/data-display/Chip/types/ChipVariant.ts
@@ -1 +1 @@
-export type ChipVariant = 'solid' | 'soft' | 'ghost';
+export type ChipVariant = 'solid' | 'soft' | 'ghost' | 'plain';