Skip to content

The open alternative to Salesforce, designed for AI.

Add shared Card actions and controls (#28528)

Raphaël Bosi1ccc4e7fc191
diff --git a/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx b/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx
index 0f7f5697b05..f4b0a6e993a 100644
--- a/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/surfaces/card.mdx
@@ -41,6 +41,54 @@
Native styles applied to the rendered part.
</ParamField>
+### Card.Action
+
+<ParamField body="Action.children" type="ReactNode">
+ Optional content inside the stretched action. Supply an accessible name for empty actions.
+</ParamField>
+
+<ParamField body="Action.className" type="string">
+ CSS class merged with the action class.
+</ParamField>
+
+<ParamField body="Action.disabled" type="boolean" default="false">
+ Disables native button owners and suppresses the action hover treatment. Links and associated controls remain responsible for their own disabled behavior.
+</ParamField>
+
+<ParamField body="Action.ref" type="Ref&lt;HTMLButtonElement&gt;">
+ Ref to the default button, or the element supplied through render.
+</ParamField>
+
+<ParamField body="Action.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, {}&gt;">
+ Native element or render callback composed through Base UI useRender. Links retain native navigation and labels activate their associated controls without an additional keyboard target.
+</ParamField>
+
+<ParamField body="Action.style" type="CSSProperties">
+ Native styles applied to the rendered action.
+</ParamField>
+
+### Card.Control
+
+<ParamField body="Control.children" type="ReactNode">
+ Independent controls or tooltip targets lifted above a sibling Card.Action.
+</ParamField>
+
+<ParamField body="Control.className" type="string">
+ CSS class merged with the control class.
+</ParamField>
+
+<ParamField body="Control.ref" type="Ref&lt;HTMLSpanElement&gt;">
+ Ref to the default span, or the element supplied through render.
+</ParamField>
+
+<ParamField body="Control.render" type="ReactElement&lt;unknown, string | JSXElementConstructor&lt;any&gt;&gt; | ComponentRenderFn&lt;HTMLProps, {}&gt;">
+ Element or render callback composed through Base UI useRender. The supplied control retains its native attributes, events and semantics.
+</ParamField>
+
+<ParamField body="Control.style" type="CSSProperties">
+ Native styles applied to the rendered control wrapper.
+</ParamField>
+
### Card.Header
<ParamField body="Header.children" type="ReactNode">
diff --git a/packages/twenty-docs/ui/primitives/surfaces/card.mdx b/packages/twenty-docs/ui/primitives/surfaces/card.mdx
index 3ef96d57619..d39c113ca1e 100644
--- a/packages/twenty-docs/ui/primitives/surfaces/card.mdx
+++ b/packages/twenty-docs/ui/primitives/surfaces/card.mdx
@@ -6,7 +6,7 @@ description: Group related information inside a bordered surface.
import { StoryEmbed } from '/snippets/ui/StoryEmbed.mdx';
import CardReference from '/snippets/ui/generated/surfaces/card.mdx';
-`Card` groups four presentational parts under one named export. Compose `Card.Root`, `Card.Header`, `Card.Content`, and `Card.Footer` to separate a title, body, and supporting actions. The parts do not manage selection, focus, or application state. The application owns the behavior of any controls placed inside them.
+`Card` groups related information and actions under one named export. Compose `Card.Root`, `Card.Header`, `Card.Content`, and `Card.Footer` to separate a title, body, and supporting actions. The parts do not manage selection, focus, or application state. The application owns the behavior of any controls placed inside them.
<StoryEmbed
storyId="ui-surfaces-card--display"
@@ -51,14 +51,16 @@ Use [Heading](/ui/primitives/typography/heading) at the level required by the su
Card.Root (outer surface)
├── Card.Header (optional)
├── Card.Content (optional, repeatable)
-└── Card.Footer (optional)
+├── Card.Footer (optional)
+├── Card.Action (optional, inside an action area)
+└── Card.Control (optional, independent control or tooltip target)
```
Import `Card` from `twenty-ui/primitives/surfaces`. `Card.Root` supplies the outer border and clipping, but creates no sections internally. No part requires another part or a particular section order. The sections also work independently, without `Card.Root` or context.
-Each part renders a `div` by default and accepts native div attributes, event handlers, `className`, `style`, and a DOM `ref`. Use `render` with an element or callback to choose a semantic target. No part infers an element or role from `onClick`.
+Root, Header, Content and Footer render a `div` by default and accept native div attributes, event handlers, `className`, `style`, and a DOM `ref`. Action renders a native button with `type="button"`, and Control renders a span. Use `render` with an element or callback to choose a semantic target. No part infers an element or role from `onClick`.
-`CardRootProps`, `CardHeaderProps`, `CardContentProps`, and `CardFooterProps` are exported from `twenty-ui/primitives/surfaces`, `twenty-ui/primitives`, and the root package.
+`CardRootProps`, `CardHeaderProps`, `CardContentProps`, `CardFooterProps`, `CardActionProps`, and `CardControlProps` are exported from `twenty-ui/primitives/surfaces`, `twenty-ui/primitives`, and the root package.
## Appearance and dividers
@@ -136,6 +138,50 @@ export const ImportLinkCard = () => (
Native button and link owners retain the card layout and get a visible focus outline. Explicit button and link owners highlight on hover. Disabled owners keep their disabled appearance. Custom owners must supply their interaction behavior, including keyboard activation and disabled handling when applicable.
+## Stretched actions and independent controls
+
+Use `Card.Action` when one primary action covers a card section that also contains independent controls. Place the action directly inside Card.Root, Card.Header, Card.Content or Card.Footer. That immediate part defines the stretched area. Keep one primary action per area, and keep expanded forms or other independent sections outside it.
+
+`Card.Action` is a native button by default. Give an empty action an accessible name with `aria-label` or `aria-labelledby`, and use `aria-describedby` for supporting text. A native anchor or router link supplied through `render` keeps its own navigation, target, modifier-click and context-menu behavior. Custom owners receive no synthetic button role, keyboard handler or tab stop. Put target-specific native attributes on the rendered element.
+
+`Card.Control` lifts an independent control or tooltip target above the stretched action. Compose its existing element through `render` to keep its layout and attributes. Controls stay siblings of the primary action, rather than children of a button or link. Card does not infer which descendants are interactive and does not forward their clicks to the primary action. Applications own any additional handling needed for raised plain text.
+
+```tsx
+import { useId } from 'react';
+import { Button } from 'twenty-ui/primitives/input';
+import { Card } from 'twenty-ui/primitives/surfaces';
+import { Text } from 'twenty-ui/primitives/typography';
+
+export const CustomerImportActions = () => {
+ const titleId = useId();
+
+ return (
+ <Card.Root>
+ <Card.Content>
+ <Card.Action
+ aria-labelledby={titleId}
+ render={<a href="/imports/review" />}
+ />
+ <Text id={titleId}>Review customer import</Text>
+ <Card.Control render={<Button variant="ghost" />}>
+ Import options
+ </Card.Control>
+ </Card.Content>
+ </Card.Root>
+ );
+};
+```
+
+Enabled action areas use the shared Card hover color, including when an independent control is hovered. A nested action area owns its highlight and does not highlight its ancestors. Native button and link actions show a 2px inset focus outline around the stretched area. A disabled native button is removed from keyboard navigation and its area does not highlight, including a button supplied through `render`. Links and controls associated through labels remain responsible for their own disabled behavior; the Action `disabled` prop also suppresses the shared action-area treatment.
+
+For a Switch or Radio row, render Action as `<label htmlFor={controlId} />` and give the actual control that ID. Keep its visible label and accessible description associated with the control. The label creates no additional keyboard target or focus ring. Switch and Radio retain their own focus and keyboard behavior. Put a radio option's expanded form in a separate Card.Content so the label covers only its selection header.
+
+<StoryEmbed
+ storyId="ui-surfaces-card-interactions--stretched-actions"
+ title="Stretched actions with independent controls"
+ height={360}
+/>
+
## Independent parts and custom wrappers
A section can be used without the outer surface. Wrappers can use its exported props type and spread it to preserve native attributes, event handlers, refs, render composition, classes, and styles. With a custom target, put its target-specific ref on the supplied element. Base UI merges that ref with the part ref and composed props.
diff --git a/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx b/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx
index 8a5bff08b18..18f6b0580a5 100644
--- a/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx
+++ b/packages/twenty-front/src/modules/activities/components/ActivityRow.tsx
@@ -1,31 +1,15 @@
-import { CARD_ACTION_CLASS_NAME } from '@/ui/layout/card/styles/CardActionClassName';
import { styled } from '@linaria/react';
import { type MouseEvent, type PropsWithChildren } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { Card } from 'twenty-ui/primitives/surfaces';
import { themeCssVariables } from 'twenty-ui/theme';
-const StyledRowContentContainer = styled.div`
- > div:has(> .${CARD_ACTION_CLASS_NAME}:not(:disabled)):hover {
- background: ${themeCssVariables.background.transparent.lighter};
- cursor: pointer;
- }
-`;
-
const StyledRowContent = styled(Card.Content)`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing[2]};
height: ${themeCssVariables.spacing[12]};
padding: ${themeCssVariables.spacing[0]} ${themeCssVariables.spacing[4]};
- position: relative;
-`;
-
-const StyledRowAction = styled.button`
- &:disabled {
- cursor: default;
- pointer-events: none;
- }
`;
const INDEPENDENT_ROW_ACTION_SELECTOR = [
@@ -71,19 +55,11 @@ export const ActivityRow = ({
};
return (
- <StyledRowContentContainer>
- <StyledRowContent divider={divider} onClick={handleContentClick}>
- {isDefined(onClick) && (
- <StyledRowAction
- className={CARD_ACTION_CLASS_NAME}
- type="button"
- aria-label={label}
- onClick={onClick}
- disabled={disabled}
- />
- )}
- {children}
- </StyledRowContent>
- </StyledRowContentContainer>
+ <StyledRowContent divider={divider} onClick={handleContentClick}>
+ {isDefined(onClick) && (
+ <Card.Action aria-label={label} onClick={onClick} disabled={disabled} />
+ )}
+ {children}
+ </StyledRowContent>
);
};
diff --git a/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx b/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx
index e9df3773b67..cc1c2b45a72 100644
--- a/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx
+++ b/packages/twenty-front/src/modules/activities/components/__stories__/ActivityRow.stories.tsx
@@ -3,6 +3,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
import { expect, fn, userEvent, within } from 'storybook/test';
import { isDefined } from 'twenty-shared/utils';
import { Checkbox } from 'twenty-ui/primitives/input';
+import { Card } from 'twenty-ui/primitives/surfaces';
import {
OverflowingTextWithTooltip,
Text,
@@ -50,12 +51,12 @@ export const Disabled: Story = {
export const IndependentCheckbox: Story = {
render: (args) => (
<ActivityRow {...args}>
- <span style={{ position: 'relative', zIndex: 1 }}>
+ <Card.Control>
<Checkbox aria-label="Complete activity" />
- </span>
- <Text style={{ position: 'relative', zIndex: 1 }}>
+ </Card.Control>
+ <Card.Control render={<Text />}>
Activity with independent completion
- </Text>
+ </Card.Control>
</ActivityRow>
),
play: async ({ canvasElement, args }) => {
@@ -82,21 +83,24 @@ export const IndependentCheckbox: Story = {
export const BodyTooltipAndLink: Story = {
render: (args) => (
<ActivityRow {...args}>
- <OverflowingTextWithTooltip
- text={
- <Text render={<span />}>
- Activity body{' '}
- <a
- href="#activity-reference"
- onClick={(event) => event.preventDefault()}
- >
- Reference
- </a>
- </Text>
+ <Card.Control
+ render={
+ <OverflowingTextWithTooltip
+ text={
+ <Text render={<span />}>
+ Activity body{' '}
+ <a
+ href="#activity-reference"
+ onClick={(event) => event.preventDefault()}
+ >
+ Reference
+ </a>
+ </Text>
+ }
+ tooltipContent="Activity details"
+ alwaysShowTooltip
+ />
}
- tooltipContent="Activity details"
- alwaysShowTooltip
- style={{ position: 'relative', zIndex: 1 }}
/>
</ActivityRow>
),
@@ -123,24 +127,25 @@ export const HoverSurface: Story = {
<>
<Text>Outside activity</Text>
<ActivityRow {...args}>
- <Text style={{ position: 'relative', zIndex: 1 }}>
- Raised activity summary
- </Text>
- <span style={{ position: 'relative', zIndex: 1 }}>
+ <Card.Control render={<Text />}>Raised activity summary</Card.Control>
+ <Card.Control>
<Checkbox aria-label="Complete hovered activity" />
- </span>
- <a
- href="#hovered-activity-reference"
- onClick={(event) => event.preventDefault()}
- style={{ position: 'relative', zIndex: 1 }}
+ </Card.Control>
+ <Card.Control
+ render={
+ <a
+ href="#hovered-activity-reference"
+ onClick={(event) => event.preventDefault()}
+ />
+ }
>
Activity reference
- </a>
+ </Card.Control>
</ActivityRow>
<ActivityRow {...args} disabled label="Unavailable activity">
- <Text style={{ position: 'relative', zIndex: 1 }}>
+ <Card.Control render={<Text />}>
Unavailable activity summary
- </Text>
+ </Card.Control>
</ActivityRow>
</>
),
diff --git a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
index f18f2e0a6be..32cf973ba95 100644
--- a/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
+++ b/packages/twenty-front/src/modules/activities/files/components/AttachmentRow.tsx
@@ -19,6 +19,7 @@ import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFla
import { isNavigationModifierPressed } from '@/ui/navigation/utils/isNavigationModifierPressed';
import { CoreObjectNameSingular } from 'twenty-shared/types';
import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
+import { Card } from 'twenty-ui/primitives/surfaces';
import { IconCalendar } from 'twenty-ui/icon';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
import { PermissionFlagType } from '~/generated-metadata/graphql';
@@ -40,8 +41,6 @@ const StyledRightContent = styled.div`
align-items: center;
display: flex;
gap: ${themeCssVariables.spacing['0.5']};
- position: relative;
- z-index: 1;
`;
const StyledCalendarIconContainer = styled.div`
@@ -52,20 +51,11 @@ const StyledCalendarIconContainer = styled.div`
const StyledLink = styled.a`
align-items: center;
- appearance: none;
- background: none;
- border: none;
color: ${themeCssVariables.font.color.primary};
cursor: pointer;
display: flex;
- font-family: inherit;
- font-size: inherit;
- padding: 0;
- position: relative;
- text-align: left;
text-decoration: none;
width: 100%;
- z-index: 1;
:hover {
color: ${themeCssVariables.font.color.secondary};
@@ -78,9 +68,7 @@ const StyledLinkContainer = styled.div`
`;
const StyledTextInputContainer = styled.div`
- position: relative;
width: 100%;
- z-index: 1;
`;
type AttachmentRowProps = {
@@ -211,8 +199,12 @@ export const AttachmentRow = ({
<StyledLeftContent>
<FileIcon fileCategory={fileCategory} thumbnailUrl={fileUrl} />
{isEditing ? (
- <StyledTextInputContainer
- onClick={(event) => event.stopPropagation()}
+ <Card.Control
+ render={
+ <StyledTextInputContainer
+ onClick={(event) => event.stopPropagation()}
+ />
+ }
>
<SettingsTextInput
instanceId={`attachment-${attachment.id}-name`}
@@ -222,23 +214,27 @@ export const AttachmentRow = ({
autoFocus
onKeyDown={handleOnKeyDown}
/>
- </StyledTextInputContainer>
+ </Card.Control>
) : (
<StyledLinkContainer>
- <StyledLink
- onClick={handleFileLinkClick}
- href={safeFileUrl}
- target="_blank"
- rel="noopener noreferrer"
+ <Card.Control
+ render={
+ <StyledLink
+ onClick={handleFileLinkClick}
+ href={safeFileUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ />
+ }
>
<OverflowingTextWithTooltip
text={`${attachmentFileName}${attachmentFileExtension}`}
/>
- </StyledLink>
+ </Card.Control>
</StyledLinkContainer>
)}
</StyledLeftContent>
- <StyledRightContent>
+ <Card.Control render={<StyledRightContent />}>
<StyledCalendarIconContainer>
<IconCalendar size={theme.icon.size.md} />
</StyledCalendarIconContainer>
@@ -250,7 +246,7 @@ export const AttachmentRow = ({
onRename={handleRename}
hasDownloadPermission={hasDownloadPermission}
/>
- </StyledRightContent>
+ </Card.Control>
</ActivityRow>
</FieldContext.Provider>
);
diff --git a/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx b/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx
index 2048705eaeb..d0d2a45a084 100644
--- a/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx
+++ b/packages/twenty-front/src/modules/activities/tasks/components/TaskRow.tsx
@@ -21,6 +21,7 @@ import { CoreObjectNameSingular } from 'twenty-shared/types';
import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
import { IconCalendar } from 'twenty-ui/icon';
import { Checkbox } from 'twenty-ui/primitives/input';
+import { Card } from 'twenty-ui/primitives/surfaces';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
const StyledTaskBody = styled.div`
@@ -29,9 +30,7 @@ const StyledTaskBody = styled.div`
max-width: calc(80% - ${themeCssVariables.spacing[2]});
overflow: hidden;
padding-bottom: 1px;
- position: relative;
text-overflow: ellipsis;
- z-index: 1;
`;
const StyledTaskTitle = styled.div<{
@@ -71,9 +70,7 @@ const StyledRightSideContainer = styled.div`
const StyledActivityTargetsContainer = styled.div`
overflow: clip;
- position: relative;
width: 100%;
- z-index: 1;
`;
const StyledPlaceholder = styled.div`
@@ -90,8 +87,6 @@ const StyledLeftSideContainer = styled.div`
const StyledCheckboxContainer = styled.div`
display: flex;
- position: relative;
- z-index: 1;
`;
export const TaskRow = ({
@@ -132,26 +127,25 @@ export const TaskRow = ({
}}
>
<StyledLeftSideContainer>
- <StyledCheckboxContainer
- onClick={(e) => {
- e.stopPropagation();
- }}
+ <Card.Control
+ render={<StyledCheckboxContainer />}
+ onClick={(event) => event.stopPropagation()}
>
<Checkbox
checked={task.status === 'DONE'}
shape={'round'}
onCheckedChange={completeTask}
/>
- </StyledCheckboxContainer>
+ </Card.Control>
<StyledTaskTitle completed={task.status === 'DONE'}>
{task.title || <StyledPlaceholder>{t`Task title`}</StyledPlaceholder>}
</StyledTaskTitle>
- <StyledTaskBody>
+ <Card.Control render={<StyledTaskBody />}>
<OverflowingTextWithTooltip
text={<LinkifiedText text={body} />}
tooltipContent={body}
/>
- </StyledTaskBody>
+ </Card.Control>
</StyledLeftSideContainer>
<StyledRightSideContainer>
{task.dueAt && (
@@ -163,7 +157,7 @@ export const TaskRow = ({
</StyledDueDate>
)}
{
- <StyledActivityTargetsContainer>
+ <Card.Control render={<StyledActivityTargetsContainer />}>
<FieldContextProvider
objectNameSingular={CoreObjectNameSingular.Task}
objectRecordId={task.id}
@@ -181,7 +175,7 @@ export const TaskRow = ({
</RecordFieldComponentInstanceContext.Provider>
</StopPropagationContainer>
</FieldContextProvider>
- </StyledActivityTargetsContainer>
+ </Card.Control>
}
</StyledRightSideContainer>
</ActivityRow>
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx b/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx
index 148273abb02..5cfeea7afb8 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsListItemCardContent.tsx
@@ -1,5 +1,4 @@
-import { CARD_ACTION_CLASS_NAME } from '@/ui/layout/card/styles/CardActionClassName';
-import { css, cx } from '@linaria/core';
+import { css } from '@linaria/core';
import { styled } from '@linaria/react';
import { isNonEmptyString } from '@sniptt/guards';
import { type ReactNode, useId } from 'react';
@@ -9,19 +8,15 @@ import { IconChevronRight, type IconComponent } from 'twenty-ui/icon';
import { Card } from 'twenty-ui/primitives/surfaces';
import { useTheme, themeCssVariables } from 'twenty-ui/theme';
-const StyledRowContainer = styled.div`
- > div {
- align-items: center;
- box-sizing: border-box;
- display: flex;
- font-size: ${themeCssVariables.font.size.md};
- font-weight: ${themeCssVariables.font.weight.medium};
- gap: ${themeCssVariables.spacing[2]};
- height: ${themeCssVariables.spacing[10]};
- padding: ${themeCssVariables.spacing[2]};
- padding-left: ${themeCssVariables.spacing[3]};
- position: relative;
- }
+const ROW_CONTENT_CLASS_NAME = css`
+ align-items: center;
+ display: flex;
+ font-size: ${themeCssVariables.font.size.md};
+ font-weight: ${themeCssVariables.font.weight.medium};
+ gap: ${themeCssVariables.spacing[2]};
+ height: ${themeCssVariables.spacing[10]};
+ padding: ${themeCssVariables.spacing[2]};
+ padding-left: ${themeCssVariables.spacing[3]};
`;
const StyledRightContainer = styled.div`
@@ -30,8 +25,6 @@ const StyledRightContainer = styled.div`
flex-shrink: 0;
gap: ${themeCssVariables.spacing[1]};
pointer-events: none;
- position: relative;
- z-index: 1;
:is(
a,
@@ -77,12 +70,6 @@ const StyledDescription = styled.span`
white-space: nowrap;
`;
-const rowActionClassName = css`
- &:hover {
- background: ${themeCssVariables.background.transparent.lighter};
- }
-`;
-
type SettingsListItemCardContentProps = {
label: string;
description?: string;
@@ -110,51 +97,46 @@ export const SettingsListItemCardContent = ({
const hasDescription = isNonEmptyString(description);
return (
- <StyledRowContainer>
- <Card.Content divider={divider}>
- {isDefined(to) ? (
- <Link
- className={cx(CARD_ACTION_CLASS_NAME, rowActionClassName)}
+ <Card.Content divider={divider} className={ROW_CONTENT_CLASS_NAME}>
+ {isDefined(to) ? (
+ <Card.Action
+ render={<Link to={to} />}
+ aria-labelledby={labelId}
+ aria-describedby={hasDescription ? descriptionId : undefined}
+ onClick={onClick}
+ />
+ ) : (
+ isDefined(onClick) && (
+ <Card.Action
aria-labelledby={labelId}
aria-describedby={hasDescription ? descriptionId : undefined}
onClick={onClick}
- to={to}
/>
- ) : (
- isDefined(onClick) && (
- <button
- className={cx(CARD_ACTION_CLASS_NAME, rowActionClassName)}
- aria-labelledby={labelId}
- aria-describedby={hasDescription ? descriptionId : undefined}
- onClick={onClick}
- type="button"
- />
- )
+ )
+ )}
+ {isDefined(LeftIcon) && (
+ <LeftIcon
+ size={theme.icon.size.md}
+ color={LeftIconColor ?? 'currentColor'}
+ />
+ )}
+ <StyledContent>
+ <StyledLabel id={labelId}>{label}</StyledLabel>
+ {hasDescription && (
+ <StyledDescription id={descriptionId}>
+ {description}
+ </StyledDescription>
)}
- {isDefined(LeftIcon) && (
- <LeftIcon
+ </StyledContent>
+ <Card.Control render={<StyledRightContainer />}>
+ {rightComponent}
+ {isDefined(to) && (
+ <IconChevronRight
size={theme.icon.size.md}
- color={LeftIconColor ?? 'currentColor'}
+ color={theme.font.color.tertiary}
/>
)}
- <StyledContent>
- <StyledLabel id={labelId}>{label}</StyledLabel>
- {hasDescription && (
- <StyledDescription id={descriptionId}>
- {description}
- </StyledDescription>
- )}
- </StyledContent>
- <StyledRightContainer>
- {rightComponent}
- {isDefined(to) && (
- <IconChevronRight
- size={theme.icon.size.md}
- color={theme.font.color.tertiary}
- />
- )}
- </StyledRightContainer>
- </Card.Content>
- </StyledRowContainer>
+ </Card.Control>
+ </Card.Content>
);
};
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsOptions/SettingsOptionCardContentSwitch.tsx b/packages/twenty-front/src/modules/settings/components/SettingsOptions/SettingsOptionCardContentSwitch.tsx
index 34b7b0fdb7d..4edc1de2484 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsOptions/SettingsOptionCardContentSwitch.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsOptions/SettingsOptionCardContentSwitch.tsx
@@ -7,25 +7,23 @@ import {
} from '@/settings/components/SettingsOptions/SettingsCardContentBase';
import { SettingsOptionIconCustomizer } from '@/settings/components/SettingsOptions/SettingsOptionIconCustomizer';
import { styled } from '@linaria/react';
+import { isNonEmptyString } from '@sniptt/guards';
+import { isDefined } from 'twenty-shared/utils';
+import { Card } from 'twenty-ui/primitives/surfaces';
import { useId } from 'react';
import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
import { type IconComponent } from 'twenty-ui/icon';
import { Switch } from 'twenty-ui/primitives/input';
import { themeCssVariables } from 'twenty-ui/theme';
-const StyledSettingsCardSwitchContent = styled.div<{ disabled?: boolean }>`
+const StyledSettingsCardSwitchContent = styled.div`
align-items: center;
- background-color: ${themeCssVariables.background.secondary};
- cursor: ${({ disabled }) => (disabled ? 'default' : 'pointer')};
display: flex;
gap: ${themeCssVariables.spacing[3]};
- padding: ${themeCssVariables.spacing[4]};
- pointer-events: ${({ disabled }) => (disabled ? 'none' : 'auto')};
- position: relative;
+`;
- &:hover {
- background: ${themeCssVariables.background.transparent.lighter};
- }
+const StyledSettingsCardDescriptionText = styled.span`
+ display: block;
`;
const StyledSettingsCardSwitchButtonContainer = styled.span`
@@ -35,12 +33,6 @@ const StyledSettingsCardSwitchButtonContainer = styled.span`
margin-left: auto;
`;
-const StyledSettingsCardSwitchCover = styled.span`
- cursor: pointer;
- inset: 0;
- position: absolute;
-`;
-
type SettingsOptionCardContentSwitchProps = {
Icon?: IconComponent;
title: React.ReactNode;
@@ -61,38 +53,55 @@ export const SettingsOptionCardContentSwitch = ({
onChange,
}: SettingsOptionCardContentSwitchProps) => {
const switchId = useId();
+ const titleId = `${switchId}-title`;
+ const descriptionId = `${switchId}-description`;
+ const hasDescription = isNonEmptyString(description);
return (
<>
- <StyledSettingsCardSwitchContent disabled={disabled}>
- {Icon && (
- <StyledSettingsCardIcon>
- <SettingsOptionIconCustomizer Icon={Icon} />
- </StyledSettingsCardIcon>
- )}
- <StyledSettingsCardTextContainer>
- <StyledSettingsCardTitle>
- <label htmlFor={switchId}>
- {title}
- <StyledSettingsCardSwitchCover />
- </label>
- </StyledSettingsCardTitle>
- {description && (
- <StyledSettingsCardDescription>
- <OverflowingTextWithTooltip text={description} />
- </StyledSettingsCardDescription>
+ <Card.Content>
+ <Card.Action
+ disabled={disabled}
+ render={<label htmlFor={switchId} aria-labelledby={titleId} />}
+ />
+ <StyledSettingsCardSwitchContent>
+ {isDefined(Icon) && (
+ <StyledSettingsCardIcon>
+ <SettingsOptionIconCustomizer Icon={Icon} />
+ </StyledSettingsCardIcon>
)}
- </StyledSettingsCardTextContainer>
- <StyledSettingsCardSwitchButtonContainer>
- <Switch
- id={switchId}
- checked={checked}
- onCheckedChange={onChange}
- disabled={disabled}
- size="sm"
- />
- </StyledSettingsCardSwitchButtonContainer>
- </StyledSettingsCardSwitchContent>
+ <StyledSettingsCardTextContainer>
+ <StyledSettingsCardTitle id={titleId}>
+ <label htmlFor={switchId}>{title}</label>
+ </StyledSettingsCardTitle>
+ {hasDescription && (
+ <StyledSettingsCardDescription id={descriptionId}>
+ <Card.Control
+ render={
+ <label htmlFor={switchId} aria-labelledby={descriptionId} />
+ }
+ >
+ <OverflowingTextWithTooltip
+ text={description}
+ render={<StyledSettingsCardDescriptionText />}
+ />
+ </Card.Control>
+ </StyledSettingsCardDescription>
+ )}
+ </StyledSettingsCardTextContainer>
+ <Card.Control render={<StyledSettingsCardSwitchButtonContainer />}>
+ <Switch
+ id={switchId}
+ aria-labelledby={titleId}
+ aria-describedby={hasDescription ? descriptionId : undefined}
+ checked={checked}
+ onCheckedChange={onChange}
+ disabled={disabled}
+ size="sm"
+ />
+ </Card.Control>
+ </StyledSettingsCardSwitchContent>
+ </Card.Content>
{divider && <SettingsCardSeparator />}
</>
);
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsOptions/__stories__/SettingsOptionCardContentSwitch.stories.tsx b/packages/twenty-front/src/modules/settings/components/SettingsOptions/__stories__/SettingsOptionCardContentSwitch.stories.tsx
index 9d84cd10598..01b2a4ff77b 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsOptions/__stories__/SettingsOptionCardContentSwitch.stories.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsOptions/__stories__/SettingsOptionCardContentSwitch.stories.tsx
@@ -2,6 +2,8 @@ import { SettingsOptionCardContentSwitch } from '@/settings/components/SettingsO
import { styled } from '@linaria/react';
import { type Meta, type StoryObj } from '@storybook/react-vite';
import { useState } from 'react';
+import { expect, fn, userEvent, within } from 'storybook/test';
+import { Button } from 'twenty-ui/primitives/input';
import { IconBell, IconLock, IconUsers } from 'twenty-ui/icon';
import { ComponentDecorator } from 'twenty-ui/testing';
@@ -18,7 +20,10 @@ const SettingsOptionCardContentSwitchWrapper = (
<StyledContainer>
<SettingsOptionCardContentSwitch
checked={checked}
- onChange={setChecked}
+ onChange={(nextChecked) => {
+ setChecked(nextChecked);
+ args.onChange?.(nextChecked);
+ }}
Icon={args.Icon}
title={args.title}
description={args.description}
@@ -41,26 +46,105 @@ const meta: Meta<typeof SettingsOptionCardContentSwitchWrapper> = {
export default meta;
type Story = StoryObj<typeof SettingsOptionCardContentSwitchWrapper>;
+const LONG_DESCRIPTION =
+ 'Receive notifications about important updates, upcoming workspace changes and activity from every team you follow, including updates that require your attention.';
+
export const Default: Story = {
args: {
Icon: IconBell,
title: 'Notifications',
- description: 'Receive notifications about important updates',
+ description: LONG_DESCRIPTION,
checked: true,
},
argTypes: {
Icon: { control: false },
onChange: { control: false },
},
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const control = canvas.getByRole('switch', { name: 'Notifications' });
+ const description = canvas.getByText(LONG_DESCRIPTION);
+
+ await expect(control).toBeChecked();
+ await expect(control).toHaveAccessibleDescription(LONG_DESCRIPTION);
+ await expect(description.clientWidth).toBeGreaterThan(0);
+ await expect(description.scrollWidth).toBeGreaterThan(
+ description.clientWidth,
+ );
+ await expect(description).toHaveStyle({
+ display: 'block',
+ overflow: 'hidden',
+ textOverflow: 'ellipsis',
+ whiteSpace: 'nowrap',
+ });
+ await userEvent.click(canvas.getByText('Notifications'));
+ await expect(control).not.toBeChecked();
+ control.focus();
+ await userEvent.keyboard(' ');
+ await expect(control).toBeChecked();
+ await expect(control).toHaveFocus();
+
+ await userEvent.hover(description);
+ await expect(
+ await within(canvasElement.ownerDocument.body).findByRole('tooltip'),
+ ).toHaveTextContent(LONG_DESCRIPTION);
+ await userEvent.click(description);
+ await expect(control).not.toBeChecked();
+ await expect(canvas.queryByRole('button')).not.toBeInTheDocument();
+ },
};
export const Disabled: Story = {
+ tags: ['!dev'],
args: {
Icon: IconLock,
title: 'Locked Setting',
description: 'This setting is currently unavailable',
checked: false,
disabled: true,
+ onChange: fn(),
+ },
+ render: (args) => (
+ <StyledContainer>
+ <Button>Before disabled setting</Button>
+ <SettingsOptionCardContentSwitchWrapper
+ checked={args.checked}
+ onChange={args.onChange}
+ Icon={args.Icon}
+ title={args.title}
+ description={args.description}
+ divider={args.divider}
+ disabled={args.disabled}
+ />
+ <Button>After disabled setting</Button>
+ </StyledContainer>
+ ),
+ play: async ({ canvasElement, args }) => {
+ const { userEvent: trustedUserEvent } = await import('vitest/browser');
+ const canvas = within(canvasElement);
+ const control = canvas.getByRole('switch', { name: 'Locked Setting' });
+
+ for (const target of [
+ canvas.getByText('Locked Setting'),
+ canvas.getByText('This setting is currently unavailable'),
+ control,
+ ]) {
+ await userEvent.click(target);
+ await expect(control).not.toBeChecked();
+ }
+
+ await expect(args.onChange).not.toHaveBeenCalled();
+ await expect(control).toHaveAttribute('aria-disabled', 'true');
+ await expect(control).toHaveAttribute('tabindex', '-1');
+ await trustedUserEvent.click(
+ canvas.getByRole('button', { name: 'Before disabled setting' }),
+ );
+ await trustedUserEvent.tab();
+ await expect(
+ canvas.getByRole('button', { name: 'After disabled setting' }),
+ ).toHaveFocus();
+ await expect(control).not.toHaveFocus();
+ await expect(args.onChange).not.toHaveBeenCalled();
},
};
diff --git a/packages/twenty-front/src/modules/settings/components/SettingsRadioSettingsCard.tsx b/packages/twenty-front/src/modules/settings/components/SettingsRadioSettingsCard.tsx
index 5562e7cd6d5..1097ed557ad 100644
--- a/packages/twenty-front/src/modules/settings/components/SettingsRadioSettingsCard.tsx
+++ b/packages/twenty-front/src/modules/settings/components/SettingsRadioSettingsCard.tsx
@@ -1,7 +1,8 @@
+import { css } from '@linaria/core';
import { styled } from '@linaria/react';
import { type MessageDescriptor } from '@lingui/core';
import { useLingui } from '@lingui/react/macro';
-import { type ReactNode, useId } from 'react';
+import { Fragment, type ReactNode, useId } from 'react';
import { isDefined } from 'twenty-shared/utils';
import { Radio, RadioGroup } from 'twenty-ui/primitives/input';
import { Card } from 'twenty-ui/primitives/surfaces';
@@ -15,16 +16,6 @@ type SettingsRadioSettingsCardProps<Option extends { value: string }> = {
disabled?: boolean;
};
-const StyledCardContentContainer = styled.div`
- > div {
- cursor: pointer;
-
- &:hover {
- background: ${themeCssVariables.background.transparent.lighter};
- }
- }
-`;
-
const StyledOptionHeader = styled.label`
align-items: center;
display: flex;
@@ -53,8 +44,8 @@ const StyledRadioContainer = styled.span`
margin-left: auto;
`;
-const StyledExpandedContent = styled.div`
- margin-top: ${themeCssVariables.spacing[4]};
+const EXPANDED_CONTENT_CLASS_NAME = css`
+ padding-top: ${themeCssVariables.spacing[0]};
`;
export const SettingsRadioSettingsCard = <
@@ -93,10 +84,23 @@ export const SettingsRadioSettingsCard = <
<Card.Root fullWidth>
{options.map((option, index) => {
const isSelected = value === option.value;
+ const hasExpandedContent =
+ isDefined(option.cardContentExpanded) && isSelected;
+ const hasDivider = index < options.length - 1;
+ const radioId = `${groupId}-${index}`;
return (
- <StyledCardContentContainer key={option.value}>
- <Card.Content divider={index < options.length - 1}>
+ <Fragment key={option.value}>
+ <Card.Content divider={hasDivider && !hasExpandedContent}>
+ <Card.Action
+ disabled={disabled}
+ render={
+ <label
+ htmlFor={radioId}
+ aria-labelledby={`${groupId}-${index}-title`}
+ />
+ }
+ />
<StyledOptionHeader>
{option.cardMedia}
<StyledTextContainer>
@@ -107,21 +111,25 @@ export const SettingsRadioSettingsCard = <
{i18n._(option.description)}
</StyledDescription>
</StyledTextContainer>
- <StyledRadioContainer>
+ <Card.Control render={<StyledRadioContainer />}>
<Radio
+ id={radioId}
aria-labelledby={`${groupId}-${index}-title`}
aria-describedby={`${groupId}-${index}-description`}
value={option.value}
/>
- </StyledRadioContainer>
+ </Card.Control>
</StyledOptionHeader>
- {isDefined(option.cardContentExpanded) && isSelected && (
- <StyledExpandedContent>
- {option.cardContentExpanded}
- </StyledExpandedContent>
- )}
</Card.Content>
- </StyledCardContentContainer>
+ {hasExpandedContent && (
+ <Card.Content
+ className={EXPANDED_CONTENT_CLASS_NAME}
+ divider={hasDivider}
+ >
+ {option.cardContentExpanded}
+ </Card.Content>
+ )}
+ </Fragment>
);
})}
</Card.Root>
diff --git a/packages/twenty-front/src/modules/ui/layout/card/styles/CardActionClassName.ts b/packages/twenty-front/src/modules/ui/layout/card/styles/CardActionClassName.ts
deleted file mode 100644
index 5bdc4667181..00000000000
--- a/packages/twenty-front/src/modules/ui/layout/card/styles/CardActionClassName.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { css } from '@linaria/core';
-import { themeCssVariables } from 'twenty-ui/theme';
-
-export const CARD_ACTION_CLASS_NAME = css`
- background: transparent;
- border: none;
- cursor: pointer;
- inset: 0;
- padding: 0;
- position: absolute;
-
- &:focus-visible {
- outline: 2px solid ${themeCssVariables.color.blue};
- outline-offset: -2px;
- }
-`;
diff --git a/packages/twenty-ui/docs/cardActionPropDescriptions.ts b/packages/twenty-ui/docs/cardActionPropDescriptions.ts
new file mode 100644
index 00000000000..2657ee91219
--- /dev/null
+++ b/packages/twenty-ui/docs/cardActionPropDescriptions.ts
@@ -0,0 +1,13 @@
+import { type CardActionProps } from '../src/primitives/surfaces/Card/types/CardActionProps';
+
+export const CARD_ACTION_PROP_DESCRIPTIONS = {
+ children:
+ 'Optional content inside the stretched action. Supply an accessible name for empty actions.',
+ disabled:
+ 'Disables native button owners and suppresses the action hover treatment. Links and associated controls remain responsible for their own disabled behavior.',
+ className: 'CSS class merged with the action class.',
+ style: 'Native styles applied to the rendered action.',
+ ref: 'Ref to the default button, or the element supplied through render.',
+ render:
+ 'Native element or render callback composed through Base UI useRender. Links retain native navigation and labels activate their associated controls without an additional keyboard target.',
+} satisfies Partial<Record<keyof CardActionProps, string>>;
diff --git a/packages/twenty-ui/docs/cardControlPropDescriptions.ts b/packages/twenty-ui/docs/cardControlPropDescriptions.ts
new file mode 100644
index 00000000000..191272560e4
--- /dev/null
+++ b/packages/twenty-ui/docs/cardControlPropDescriptions.ts
@@ -0,0 +1,11 @@
+import { type CardControlProps } from '../src/primitives/surfaces/Card/types/CardControlProps';
+
+export const CARD_CONTROL_PROP_DESCRIPTIONS = {
+ children:
+ 'Independent controls or tooltip targets lifted above a sibling Card.Action.',
+ className: 'CSS class merged with the control class.',
+ style: 'Native styles applied to the rendered control wrapper.',
+ ref: 'Ref to the default span, or the element supplied through render.',
+ render:
+ 'Element or render callback composed through Base UI useRender. The supplied control retains its native attributes, events and semantics.',
+} satisfies Partial<Record<keyof CardControlProps, string>>;
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index 3776342fa35..c93fd442914 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -45,6 +45,8 @@ import { BANNER_PROP_DESCRIPTIONS } from './bannerPropDescriptions';
import { BREADCRUMB_PROP_DESCRIPTIONS } from './breadcrumbPropDescriptions';
import { BUTTON_GROUP_PROP_DESCRIPTIONS } from './buttonGroupPropDescriptions';
import { BUTTON_PROP_DESCRIPTIONS } from './buttonPropDescriptions';
+import { CARD_ACTION_PROP_DESCRIPTIONS } from './cardActionPropDescriptions';
+import { CARD_CONTROL_PROP_DESCRIPTIONS } from './cardControlPropDescriptions';
import { CARD_CONTENT_PROP_DESCRIPTIONS } from './cardContentPropDescriptions';
import { CARD_FOOTER_PROP_DESCRIPTIONS } from './cardFooterPropDescriptions';
import { CARD_HEADER_PROP_DESCRIPTIONS } from './cardHeaderPropDescriptions';
@@ -591,11 +593,16 @@ export const DOCUMENTED_COMPONENTS = [
slug: 'surfaces/card',
partPropDescriptions: {
Root: CARD_PROP_DESCRIPTIONS,
+ Action: CARD_ACTION_PROP_DESCRIPTIONS,
+ Control: CARD_CONTROL_PROP_DESCRIPTIONS,
Header: CARD_HEADER_PROP_DESCRIPTIONS,
Content: CARD_CONTENT_PROP_DESCRIPTIONS,
Footer: CARD_FOOTER_PROP_DESCRIPTIONS,
},
- partPropDefaults: { Footer: { divider: 'true' } },
+ partPropDefaults: {
+ Action: { disabled: 'false' },
+ Footer: { divider: 'true' },
+ },
},
{
name: 'Dialog',
diff --git a/packages/twenty-ui/docs/public-exports.json b/packages/twenty-ui/docs/public-exports.json
index 2353390f824..2b08b8bdf6b 100644
--- a/packages/twenty-ui/docs/public-exports.json
+++ b/packages/twenty-ui/docs/public-exports.json
@@ -1076,7 +1076,9 @@
"AlertDialogTriggerState": "primitives/surfaces/AlertDialog/types/AlertDialogTriggerState",
"AlertDialogViewportProps": "primitives/surfaces/AlertDialog/types/AlertDialogViewportProps",
"AlertDialogViewportState": "primitives/surfaces/AlertDialog/types/AlertDialogViewportState",
+ "CardActionProps": "primitives/surfaces/Card/types/CardActionProps",
"CardContentProps": "primitives/surfaces/Card/types/CardContentProps",
+ "CardControlProps": "primitives/surfaces/Card/types/CardControlProps",
"CardFooterProps": "primitives/surfaces/Card/types/CardFooterProps",
"CardHeaderProps": "primitives/surfaces/Card/types/CardHeaderProps",
"CardRootProps": "primitives/surfaces/Card/types/CardRootProps",
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index b5d3d2f7736..f36776fc171 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -8137,6 +8137,93 @@
}
]
},
+ {
+ "name": "Action",
+ "props": [
+ {
+ "name": "children",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Optional content inside the stretched action. Supply an accessible name for empty actions."
+ },
+ {
+ "name": "className",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "CSS class merged with the action class."
+ },
+ {
+ "name": "disabled",
+ "type": "boolean",
+ "required": false,
+ "defaultValue": "false",
+ "description": "Disables native button owners and suppresses the action hover treatment. Links and associated controls remain responsible for their own disabled behavior."
+ },
+ {
+ "name": "ref",
+ "type": "Ref<HTMLButtonElement>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Ref to the default button, or the element supplied through render."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native element or render callback composed through Base UI useRender. Links retain native navigation and labels activate their associated controls without an additional keyboard target."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native styles applied to the rendered action."
+ }
+ ]
+ },
+ {
+ "name": "Control",
+ "props": [
+ {
+ "name": "children",
+ "type": "ReactNode",
+ "required": false,
+ "defaultValue": null,
+ "description": "Independent controls or tooltip targets lifted above a sibling Card.Action."
+ },
+ {
+ "name": "className",
+ "type": "string",
+ "required": false,
+ "defaultValue": null,
+ "description": "CSS class merged with the control class."
+ },
+ {
+ "name": "ref",
+ "type": "Ref<HTMLSpanElement>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Ref to the default span, or the element supplied through render."
+ },
+ {
+ "name": "render",
+ "type": "ReactElement<unknown, string | JSXElementConstructor<any>> | ComponentRenderFn<HTMLProps, {}>",
+ "required": false,
+ "defaultValue": null,
+ "description": "Element or render callback composed through Base UI useRender. The supplied control retains its native attributes, events and semantics."
+ },
+ {
+ "name": "style",
+ "type": "CSSProperties",
+ "required": false,
+ "defaultValue": null,
+ "description": "Native styles applied to the rendered control wrapper."
+ }
+ ]
+ },
{
"name": "Header",
"props": [
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/Card.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/Card.tsx
index c9b5a225fc4..716060cd81d 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/Card.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/Card.tsx
@@ -1,3 +1,5 @@
+import { CardAction } from './internal/CardAction';
+import { CardControl } from './internal/CardControl';
import { CardContent } from './internal/CardContent';
import { CardFooter } from './internal/CardFooter';
import { CardHeader } from './internal/CardHeader';
@@ -5,6 +7,8 @@ import { CardRoot } from './internal/CardRoot';
export const Card = {
Root: CardRoot,
+ Action: CardAction,
+ Control: CardControl,
Header: CardHeader,
Content: CardContent,
Footer: CardFooter,
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardAction.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardAction.module.scss
new file mode 100644
index 00000000000..d603d4248f2
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardAction.module.scss
@@ -0,0 +1,28 @@
+@use '../../../styles/abstracts/mixins' as *;
+
+.action {
+ appearance: none;
+ background: transparent;
+ border: 0;
+ border-radius: inherit;
+ color: inherit;
+ cursor: pointer;
+ font: inherit;
+ inset: 0;
+ padding: 0;
+ position: absolute;
+ z-index: 0;
+
+ &:is(button, a[href], [role='button'], [role='link']) {
+ @include focus-ring;
+
+ &:focus-visible {
+ outline-offset: -2px;
+ }
+ }
+
+ &:is(:disabled, [aria-disabled='true'], [data-disabled]) {
+ cursor: default;
+ pointer-events: none;
+ }
+}
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardAction.module.scss.d.ts b/packages/twenty-ui/src/primitives/surfaces/Card/CardAction.module.scss.d.ts
new file mode 100644
index 00000000000..d6444d25cb7
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardAction.module.scss.d.ts
@@ -0,0 +1,4 @@
+declare const classNames: {
+ readonly action: 'action';
+};
+export default classNames;
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardControl.module.scss b/packages/twenty-ui/src/primitives/surfaces/Card/CardControl.module.scss
new file mode 100644
index 00000000000..909aff81dcb
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardControl.module.scss
@@ -0,0 +1,4 @@
+.control {
+ position: relative;
+ z-index: 1;
+}
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/CardControl.module.scss.d.ts b/packages/twenty-ui/src/primitives/surfaces/Card/CardControl.module.scss.d.ts
new file mode 100644
index 00000000000..8e8be371913
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/CardControl.module.scss.d.ts
@@ -0,0 +1,4 @@
+declare const classNames: {
+ readonly control: 'control';
+};
+export default classNames;
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scss b/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scss
index 92d905abff6..bd259d731a7 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scss
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/_CardOwner.scss
@@ -35,4 +35,24 @@
opacity: 0.5;
}
}
+
+ &:has(> [data-card-action]) {
+ cursor: default;
+ isolation: isolate;
+ position: relative;
+ }
+
+ &:has(
+ > [data-card-action]:not(:disabled, [aria-disabled='true'], [data-disabled])
+ ) {
+ cursor: pointer;
+
+ @include hover-capable {
+ &:hover:not(:has(:hover > [data-card-action])) {
+ --card-section-background-color: transparent;
+
+ background-color: var(--t-background-transparent-light);
+ }
+ }
+ }
}
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsx
index 6a82f05793f..9b421020f79 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/__stories__/CardInteractions.stories.tsx
@@ -1,17 +1,24 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
-import { createRef, useState } from 'react';
+import { type ComponentProps, createRef, useId, useState } from 'react';
import { expect, fn, userEvent, waitFor, within } from 'storybook/test';
import { Button } from '@ui/primitives/input/Button/Button';
+import { Switch } from '@ui/primitives/input/Switch/Switch';
+import { Text } from '@ui/primitives/typography/Text/Text';
import { ComponentDecorator } from '@ui/testing';
import { Card } from '../Card';
-const SeparateCardControls = () => {
+const SeparateCardControls = ({
+ onClick,
+}: Pick<ComponentProps<typeof Card.Root>, 'onClick'>) => {
const [imported, setImported] = useState(false);
return (
- <Card.Root render={<article aria-label="Customer import" />}>
+ <Card.Root
+ onClick={onClick}
+ render={<article aria-label="Customer import" />}
+ >
<Card.Header>Customer import</Card.Header>
<Card.Content
render={<a href="#card-report" aria-label="Open the report" />}
@@ -37,31 +44,71 @@ const meta: Meta<typeof Card.Root> = {
export default meta;
type Story = StoryObj<typeof Card.Root>;
+type ActionStory = StoryObj<typeof Card.Action>;
+
+const nativePartClick = fn();
export const ButtonOwner: Story = {
render: (args) => (
- <Card.Root {...args} render={<button type="button" />}>
- <Card.Content render={<span />}>Review import</Card.Content>
- </Card.Root>
+ <div style={{ width: '100%' }}>
+ <Card.Root
+ {...args}
+ render={<button type="button" onClick={nativePartClick} />}
+ >
+ <Card.Content render={<span />}>Review import</Card.Content>
+ </Card.Root>
+ <Card.Header
+ onClick={args.onClick}
+ render={<button type="button" onClick={nativePartClick} />}
+ >
+ Review header
+ </Card.Header>
+ <Card.Content
+ onClick={args.onClick}
+ render={<button type="button" onClick={nativePartClick} />}
+ >
+ Review content
+ </Card.Content>
+ <Card.Footer
+ onClick={args.onClick}
+ render={<button type="button" onClick={nativePartClick} />}
+ >
+ Review footer
+ </Card.Footer>
+ </div>
),
play: async ({ canvasElement, args }) => {
- const button = within(canvasElement).getByRole('button', {
- name: 'Review import',
- });
+ const canvas = within(canvasElement);
+ let expectedActivations = 0;
- button.focus();
- await userEvent.keyboard('{Enter}');
- await userEvent.keyboard(' ');
+ nativePartClick.mockClear();
- await expect(args.onClick).toHaveBeenCalledTimes(2);
- await expect(button).toHaveFocus();
- await expect(button).toHaveAttribute('type', 'button');
- await expect(button).toHaveStyle({
- cursor: 'pointer',
- display: 'block',
- outlineWidth: '2px',
- outlineStyle: 'solid',
- });
+ for (const name of [
+ 'Review import',
+ 'Review header',
+ 'Review content',
+ 'Review footer',
+ ]) {
+ const button = canvas.getByRole('button', { name });
+
+ await userEvent.click(button);
+ button.focus();
+ await userEvent.keyboard('{Enter}');
+ await userEvent.keyboard(' ');
+
+ expectedActivations += 3;
+
+ await expect(args.onClick).toHaveBeenCalledTimes(expectedActivations);
+ await expect(nativePartClick).toHaveBeenCalledTimes(expectedActivations);
+ await expect(button).toHaveFocus();
+ await expect(button).toHaveAttribute('type', 'button');
+ await expect(button).toHaveStyle({
+ cursor: 'pointer',
+ display: 'block',
+ outlineWidth: '2px',
+ outlineStyle: 'solid',
+ });
+ }
},
};
@@ -145,19 +192,23 @@ export const DisabledOwner: Story = {
};
export const SeparateControls: Story = {
- render: () => <SeparateCardControls />,
- play: async ({ canvasElement }) => {
+ render: (args) => <SeparateCardControls onClick={args.onClick} />,
+ play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
const article = canvas.getByRole('article', { name: 'Customer import' });
const link = canvas.getByRole('link', { name: 'Open the report' });
const action = canvas.getByRole('button', { name: 'Import customers' });
+ await userEvent.click(canvas.getByText('Customer import'));
+ await expect(args.onClick).toHaveBeenCalledTimes(1);
+
link.focus();
await userEvent.tab();
await userEvent.keyboard(' ');
await expect(action).toHaveFocus();
await expect(action).toHaveAccessibleName('Customers imported');
+ await expect(args.onClick).toHaveBeenCalledTimes(2);
await expect(article).not.toHaveAttribute('tabindex');
await expect(article).not.toHaveAttribute('role');
await expect(link).not.toContainElement(action);
@@ -298,3 +349,224 @@ export const HoverOwners: Story = {
}
},
};
+
+const independentControlClick = fn();
+
+export const StretchedActions: ActionStory = {
+ render: (args) => (
+ <div style={{ width: '100%' }}>
+ <Text>Outside stretched cards</Text>
+ <Card.Root render={<article aria-label="Import cards" />}>
+ <Card.Content render={<section aria-label="Import action area" />}>
+ <Card.Action aria-label="Review customers" onClick={args.onClick} />
+ <Text>24 customers are ready.</Text>
+ <Card.Control render={<Button onClick={independentControlClick} />}>
+ More options
+ </Card.Control>
+ </Card.Content>
+ <Card.Content render={<section aria-label="Unavailable action area" />}>
+ <Card.Action
+ disabled
+ render={<button aria-label="Unavailable review" />}
+ onClick={args.onClick}
+ />
+ <Text>Review is unavailable.</Text>
+ </Card.Content>
+ <Card.Content render={<section aria-label="Static parent area" />}>
+ <Card.Action aria-label="Parent review" onClick={args.onClick} />
+ <Card.Control render={<Card.Root />}>
+ <Card.Content render={<section aria-label="Nested action area" />}>
+ <Card.Action aria-label="Nested review" onClick={args.onClick} />
+ <Text>Nested customer import</Text>
+ </Card.Content>
+ </Card.Control>
+ </Card.Content>
+ </Card.Root>
+ </div>
+ ),
+};
+
+export const StretchedActionsInteractions: ActionStory = {
+ ...StretchedActions,
+ tags: ['!dev'],
+ play: async ({ canvasElement, args }) => {
+ const { userEvent: trustedUserEvent } = await import('vitest/browser');
+ const canvas = within(canvasElement);
+ const action = canvas.getByRole('button', { name: 'Review customers' });
+ const control = canvas.getByRole('button', { name: 'More options' });
+ const actionArea = canvas.getByRole('region', {
+ name: 'Import action area',
+ });
+ const disabledArea = canvas.getByRole('region', {
+ name: 'Unavailable action area',
+ });
+ const staticArea = canvas.getByRole('region', {
+ name: 'Static parent area',
+ });
+ const nestedArea = canvas.getByRole('region', {
+ name: 'Nested action area',
+ });
+ const article = canvas.getByRole('article', { name: 'Import cards' });
+
+ independentControlClick.mockClear();
+ await trustedUserEvent.hover(canvas.getByText('Outside stretched cards'));
+
+ const restingBackground = getComputedStyle(actionArea).backgroundColor;
+ const disabledBackground = getComputedStyle(disabledArea).backgroundColor;
+ const staticBackground = getComputedStyle(staticArea).backgroundColor;
+ const articleBackground = getComputedStyle(article).backgroundColor;
+ const nestedBackground = getComputedStyle(nestedArea).backgroundColor;
+
+ await trustedUserEvent.hover(control);
+ await expect(actionArea).not.toHaveStyle({
+ backgroundColor: restingBackground,
+ });
+ await trustedUserEvent.click(control);
+ await expect(independentControlClick).toHaveBeenCalledTimes(1);
+ await expect(args.onClick).not.toHaveBeenCalled();
+ await expect(action).not.toContainElement(control);
+
+ await trustedUserEvent.tab({ shift: true });
+ await expect(action).toHaveFocus();
+ await trustedUserEvent.keyboard('{Enter} ');
+ await expect(args.onClick).toHaveBeenCalledTimes(2);
+ await expect(action).toHaveStyle({
+ outlineWidth: '2px',
+ outlineStyle: 'solid',
+ outlineOffset: '-2px',
+ });
+
+ const disabledAction = canvas.getByRole('button', {
+ name: 'Unavailable review',
+ });
+ await expect(disabledAction).toBeDisabled();
+ disabledAction.focus();
+ await expect(disabledAction).not.toHaveFocus();
+ await expect(args.onClick).toHaveBeenCalledTimes(2);
+ await trustedUserEvent.hover(canvas.getByText('Review is unavailable.'));
+ await expect(disabledArea).toHaveStyle({
+ backgroundColor: disabledBackground,
+ });
+
+ await trustedUserEvent.hover(
+ canvas.getByRole('button', { name: 'Nested review' }),
+ );
+ await expect(nestedArea).not.toHaveStyle({
+ backgroundColor: nestedBackground,
+ });
+ await expect(staticArea).toHaveStyle({ backgroundColor: staticBackground });
+ await expect(article).toHaveStyle({ backgroundColor: articleBackground });
+ },
+};
+
+export const StretchedLink: ActionStory = {
+ render: (args) => (
+ <div style={{ width: '100%' }}>
+ <Card.Root>
+ <Card.Content>
+ <Card.Action
+ aria-label="Open customer report"
+ onClick={args.onClick}
+ render={
+ <a
+ href="about:blank#stretched-report"
+ aria-label="Open customer report"
+ target="stretched-report-target"
+ />
+ }
+ />
+ <Text>Customer report</Text>
+ </Card.Content>
+ </Card.Root>
+ <iframe
+ hidden
+ name="stretched-report-target"
+ title="Stretched report destination"
+ />
+ </div>
+ ),
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const link = canvas.getByRole('link', { name: 'Open customer report' });
+ const destination = canvas.getByTitle<HTMLIFrameElement>(
+ 'Stretched report destination',
+ );
+
+ link.focus();
+ await userEvent.keyboard('{Enter}');
+ await waitFor(() =>
+ expect(destination.contentWindow?.location.hash).toBe(
+ '#stretched-report',
+ ),
+ );
+ await expect(args.onClick).toHaveBeenCalledTimes(1);
+ await expect(args.onClick).toHaveBeenCalledWith(
+ expect.objectContaining({ defaultPrevented: false }),
+ );
+ await expect(link).not.toHaveAttribute('role');
+ await expect(link).not.toHaveAttribute('type');
+ await expect(link).toHaveAttribute('target', 'stretched-report-target');
+ },
+};
+
+const StretchedSwitchLabelExample = () => {
+ const switchId = useId();
+ const [isChecked, setIsChecked] = useState(false);
+
+ return (
+ <div style={{ width: '100%' }}>
+ <Button>Before setting</Button>
+ <Card.Root>
+ <Card.Content render={<section aria-label="Recording preference" />}>
+ <Card.Action
+ render={<label htmlFor={switchId} aria-label="Record meetings" />}
+ />
+ <Text
+ render={<label htmlFor={switchId} aria-label="Record meetings" />}
+ >
+ Record meetings
+ </Text>
+ <Card.Control>
+ <Switch
+ id={switchId}
+ checked={isChecked}
+ onCheckedChange={setIsChecked}
+ />
+ </Card.Control>
+ </Card.Content>
+ </Card.Root>
+ <Button>After setting</Button>
+ </div>
+ );
+};
+
+export const StretchedControlLabel: Story = {
+ tags: ['!dev'],
+ render: () => <StretchedSwitchLabelExample />,
+ play: async ({ canvasElement }) => {
+ const { userEvent: trustedUserEvent } = await import('vitest/browser');
+ const canvas = within(canvasElement);
+ const control = canvas.getByRole('switch', { name: 'Record meetings' });
+
+ await trustedUserEvent.click(
+ canvas.getByRole('region', { name: 'Recording preference' }),
+ );
+ await expect(control).toBeChecked();
+ await trustedUserEvent.click(
+ canvas.getByRole('button', { name: 'Before setting' }),
+ );
+ await trustedUserEvent.tab();
+ await expect(control).toHaveFocus();
+ await expect(control).toHaveStyle({
+ outlineWidth: '2px',
+ outlineStyle: 'solid',
+ });
+ await trustedUserEvent.keyboard(' ');
+ await expect(control).not.toBeChecked();
+ await trustedUserEvent.tab();
+ await expect(
+ canvas.getByRole('button', { name: 'After setting' }),
+ ).toHaveFocus();
+ await expect(canvas.getAllByRole('button')).toHaveLength(2);
+ },
+};
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx
index 5f150614d08..d9f2372afe0 100644
--- a/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/__tests__/Card.test.tsx
@@ -1,13 +1,14 @@
import { render, screen } from '@testing-library/react';
-import userEvent from '@testing-library/user-event';
import { createRef } from 'react';
-import { describe, expect, it, vi } from 'vitest';
+import { describe, expect, it } from 'vitest';
import { runComponentConformance } from '@test-utilities/conformance/runComponentConformance';
import { Card } from '../Card';
import rootStyles from '../Card.module.scss';
+import actionStyles from '../CardAction.module.scss';
+import controlStyles from '../CardControl.module.scss';
import contentStyles from '../CardContent.module.scss';
import footerStyles from '../CardFooter.module.scss';
import headerStyles from '../CardHeader.module.scss';
@@ -37,24 +38,14 @@ for (const { name, Component, ownClassName } of [
refInstanceOf: HTMLDivElement,
});
- it(`composes Card.${name} with a native button's attributes, handlers and ref`, async () => {
- const user = userEvent.setup();
+ it(`composes Card.${name} with a native button's attributes and ref`, () => {
const nativeRef = createRef<HTMLButtonElement>();
- const onCardClick = vi.fn();
- const onButtonClick = vi.fn();
render(
<Component
aria-describedby="import-description"
- onClick={onCardClick}
render={
- <button
- type="button"
- name="import"
- value="ready"
- ref={nativeRef}
- onClick={onButtonClick}
- />
+ <button type="button" name="import" value="ready" ref={nativeRef} />
}
>
Import records
@@ -68,15 +59,68 @@ for (const { name, Component, ownClassName } of [
expect(button).toHaveAttribute('name', 'import');
expect(button).toHaveAttribute('value', 'ready');
expect(button).toHaveAttribute('aria-describedby', 'import-description');
-
- await user.click(button);
-
- expect(onCardClick).toHaveBeenCalledTimes(1);
- expect(onButtonClick).toHaveBeenCalledTimes(1);
});
}
+runComponentConformance({
+ name: 'Card.Action',
+ element: <Card.Action>Review import</Card.Action>,
+ ownClassName: actionStyles.action,
+ refInstanceOf: HTMLButtonElement,
+});
+
+runComponentConformance({
+ name: 'Card.Control',
+ element: <Card.Control>Independent control</Card.Control>,
+ ownClassName: controlStyles.control,
+ refInstanceOf: HTMLSpanElement,
+});
+
describe('Card rendering', () => {
+ it('keeps native action and label contracts separate', () => {
+ const buttonRef = createRef<HTMLButtonElement>();
+ const composedButtonRef = createRef<HTMLButtonElement>();
+ const labelRef = createRef<HTMLLabelElement>();
+
+ render(
+ <Card.Root>
+ <Card.Content>
+ <Card.Action aria-label="Review import" disabled ref={buttonRef} />
+ </Card.Content>
+ <Card.Content>
+ <Card.Action
+ disabled
+ aria-label="Composed review"
+ render={<button ref={composedButtonRef} />}
+ />
+ </Card.Content>
+ <Card.Content>
+ <Card.Action
+ disabled
+ render={
+ <label
+ htmlFor="record-meetings"
+ aria-label="Record meetings"
+ ref={labelRef}
+ />
+ }
+ />
+ </Card.Content>
+ </Card.Root>,
+ );
+
+ expect(buttonRef.current).toHaveAttribute('type', 'button');
+ expect(buttonRef.current).toBeDisabled();
+ expect(composedButtonRef.current).toHaveAttribute('type', 'button');
+ expect(composedButtonRef.current).toBeDisabled();
+ expect(labelRef.current).toHaveAttribute('for', 'record-meetings');
+ expect(labelRef.current).toHaveAttribute('data-disabled');
+ expect(labelRef.current).not.toHaveAttribute('role');
+ expect(labelRef.current).not.toHaveAttribute('tabindex');
+ expect(labelRef.current).not.toHaveAttribute('type');
+ expect(labelRef.current).not.toBeDisabled();
+ });
+
it('preserves the root appearance flags and merges a custom background with native styles', () => {
render(
<Card.Root
@@ -134,12 +178,9 @@ describe('Card rendering', () => {
);
});
- it('keeps display cards presentational when they observe click events', async () => {
- const user = userEvent.setup();
- const onClick = vi.fn();
-
+ it('keeps display cards presentational with an onClick prop', () => {
render(
- <Card.Root onClick={onClick}>
+ <Card.Root onClick={() => undefined}>
<Card.Content>Import summary</Card.Content>
</Card.Root>,
);
@@ -152,9 +193,5 @@ describe('Card rendering', () => {
expect(root).not.toHaveAttribute('tabindex');
expect(screen.queryByRole('button')).not.toBeInTheDocument();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
-
- await user.click(content);
-
- expect(onClick).toHaveBeenCalledTimes(1);
});
});
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardAction.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardAction.tsx
new file mode 100644
index 00000000000..4802ef06252
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardAction.tsx
@@ -0,0 +1,34 @@
+import { useRender } from '@base-ui/react/use-render';
+import { clsx } from 'clsx';
+import { isValidElement } from 'react';
+
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
+import { type CardActionProps } from '../types/CardActionProps';
+
+import styles from '../CardAction.module.scss';
+
+export const CardAction = ({
+ className,
+ disabled = false,
+ render,
+ ref,
+ ...props
+}: CardActionProps) => {
+ const isNativeButton =
+ !isDefined(render) || (isValidElement(render) && render.type === 'button');
+
+ return useRender({
+ defaultTagName: 'button',
+ render,
+ ref,
+ props: {
+ ...(isNativeButton ? { type: 'button' } : undefined),
+ disabled: disabled || undefined,
+ ...props,
+ className: clsx(styles.action, className),
+ 'data-card-action': '',
+ 'data-disabled': disabled || undefined,
+ },
+ });
+};
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardControl.tsx b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardControl.tsx
new file mode 100644
index 00000000000..f1f021078c2
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/internal/CardControl.tsx
@@ -0,0 +1,22 @@
+import { useRender } from '@base-ui/react/use-render';
+import { clsx } from 'clsx';
+
+import { type CardControlProps } from '../types/CardControlProps';
+
+import styles from '../CardControl.module.scss';
+
+export const CardControl = ({
+ className,
+ render,
+ ref,
+ ...props
+}: CardControlProps) =>
+ useRender({
+ defaultTagName: 'span',
+ render,
+ ref,
+ props: {
+ ...props,
+ className: clsx(styles.control, className),
+ },
+ });
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardActionProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardActionProps.ts
new file mode 100644
index 00000000000..7a55574bf5e
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardActionProps.ts
@@ -0,0 +1,3 @@
+import { type useRender } from '@base-ui/react/use-render';
+
+export type CardActionProps = useRender.ComponentProps<'button'>;
diff --git a/packages/twenty-ui/src/primitives/surfaces/Card/types/CardControlProps.ts b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardControlProps.ts
new file mode 100644
index 00000000000..c36d6ae9531
--- /dev/null
+++ b/packages/twenty-ui/src/primitives/surfaces/Card/types/CardControlProps.ts
@@ -0,0 +1,3 @@
+import { type useRender } from '@base-ui/react/use-render';
+
+export type CardControlProps = useRender.ComponentProps<'span'>;
diff --git a/packages/twenty-ui/src/primitives/surfaces/index.ts b/packages/twenty-ui/src/primitives/surfaces/index.ts
index 1bfa8e9c99f..f2cfafd997b 100644
--- a/packages/twenty-ui/src/primitives/surfaces/index.ts
+++ b/packages/twenty-ui/src/primitives/surfaces/index.ts
@@ -35,7 +35,9 @@ export type { AlertDialogTriggerState } from './AlertDialog/types/AlertDialogTri
export type { AlertDialogViewportProps } from './AlertDialog/types/AlertDialogViewportProps';
export type { AlertDialogViewportState } from './AlertDialog/types/AlertDialogViewportState';
export { Card } from './Card/Card';
+export type { CardActionProps } from './Card/types/CardActionProps';
export type { CardContentProps } from './Card/types/CardContentProps';
+export type { CardControlProps } from './Card/types/CardControlProps';
export type { CardFooterProps } from './Card/types/CardFooterProps';
export type { CardHeaderProps } from './Card/types/CardHeaderProps';
export type { CardRootProps } from './Card/types/CardRootProps';