Skip to content

The open alternative to Salesforce, designed for AI.

Add shared Banner dismissal (#28525)

Raphaël Bosi334b97368701
diff --git a/packages/twenty-companion/src/renderer/components/Notice.tsx b/packages/twenty-companion/src/renderer/components/Notice.tsx
index 689a07812f8..e9b83d4f925 100644
--- a/packages/twenty-companion/src/renderer/components/Notice.tsx
+++ b/packages/twenty-companion/src/renderer/components/Notice.tsx
@@ -1,6 +1,5 @@
import { i18n } from '@lingui/core';
import { Banner } from 'twenty-ui/primitives/feedback';
-import { IconX } from 'twenty-ui/icon';
import { isDefined } from 'twenty-ui/utilities';
import { type ActionProps } from '../types/ActionProps';
import { noticeMessage } from '../utils/noticeMessage';
@@ -33,19 +32,14 @@ export const Notice = ({ state, command }: ActionProps) => {
>
<Banner
status={isDefined(state.error) ? 'error' : 'info'}
+ onDismiss={dismiss}
+ closeLabel={i18n._('Dismiss message')}
action={
- <div className="notice-actions">
- {isDefined(recovery) && (
- <Banner.Action onClick={() => void command(recovery)}>
- {i18n._('Install Desktop Recorder')}
- </Banner.Action>
- )}
- <Banner.Action
- aria-label={i18n._('Dismiss message')}
- startIcon={<IconX />}
- onClick={dismiss}
- />
- </div>
+ isDefined(recovery) ? (
+ <Banner.Action onClick={() => void command(recovery)}>
+ {i18n._('Install Desktop Recorder')}
+ </Banner.Action>
+ ) : undefined
}
>
{state.error?.message ??
diff --git a/packages/twenty-companion/src/renderer/style.css b/packages/twenty-companion/src/renderer/style.css
index 6b118dfc770..c8985158cdb 100644
--- a/packages/twenty-companion/src/renderer/style.css
+++ b/packages/twenty-companion/src/renderer/style.css
@@ -125,11 +125,6 @@ select {
.notice {
flex-shrink: 0;
}
-.notice-actions {
- align-items: center;
- display: flex;
- gap: var(--t-spacing-2);
-}
.preview-label {
background: var(--t-background-secondary);
border-bottom: 1px solid var(--t-border-color-medium);
diff --git a/packages/twenty-docs/snippets/ui/generated/feedback/banner.mdx b/packages/twenty-docs/snippets/ui/generated/feedback/banner.mdx
index 4bb44c4488b..65061bc0bba 100644
--- a/packages/twenty-docs/snippets/ui/generated/feedback/banner.mdx
+++ b/packages/twenty-docs/snippets/ui/generated/feedback/banner.mdx
@@ -23,6 +23,10 @@
Class merged onto the root div or composed element.
</ParamField>
+<ParamField body="closeLabel" type="string" default="Close">
+ Accessible label for the close control. Defaults to Close; supply localized text when needed.
+</ParamField>
+
<ParamField body="color" type="&quot;blue&quot; | &quot;gray&quot; | &quot;green&quot; | &quot;orange&quot; | &quot;red&quot;" default="status palette">
Palette override: gray, blue, green, orange or red. When omitted, status selects the corresponding palette.
</ParamField>
@@ -31,6 +35,10 @@
Optional leading ReactNode. The caller supplies decorative or accessible icon semantics.
</ParamField>
+<ParamField body="onDismiss" type="(() =&gt; void)">
+ Renders a 24px ghost close control and calls this callback when activated. The caller owns visibility.
+</ParamField>
+
<ParamField body="ref" type="Ref&lt;HTMLDivElement&gt;">
Ref to the root div, or to the DOM element supplied through render.
</ParamField>
diff --git a/packages/twenty-docs/ui/primitives/feedback/banner.mdx b/packages/twenty-docs/ui/primitives/feedback/banner.mdx
index 6b23b446862..f78ac8b1c2c 100644
--- a/packages/twenty-docs/ui/primitives/feedback/banner.mdx
+++ b/packages/twenty-docs/ui/primitives/feedback/banner.mdx
@@ -76,6 +76,36 @@ export const SyncResult = () => (
Status does not automatically assign `role`, `aria-live` or announcements. Choose them at the caller when updates should be announced. Supply accessible names for controls and mark decorative icon nodes with `aria-hidden`. The caller owns visibility and dismissal.
+## Dismissal
+
+Pass `onDismiss` to show a 24px ghost close control at the logical inline end. The control inherits the banner color and has `type="button"`. `closeLabel` defaults to `Close`; supply localized text in your application. Balanced inline spacing keeps centered content and actions clear of the control.
+
+The caller owns visibility. Activating the close control calls `onDismiss` and leaves the banner mounted until its caller updates state. Other actions remain in the `action` slot.
+
+```tsx
+import { useState } from 'react';
+import { Banner } from 'twenty-ui/primitives/feedback';
+
+export const DismissibleSyncBanner = () => {
+ const [isVisible, setIsVisible] = useState(true);
+
+ return isVisible ? (
+ <Banner
+ onDismiss={() => setIsVisible(false)}
+ closeLabel="Dismiss sync message"
+ >
+ Contacts are syncing in the background.
+ </Banner>
+ ) : null;
+};
+```
+
+<StoryEmbed
+ storyId="ui-feedback-banner--dismissible"
+ title="Dismissible banner"
+ height={160}
+/>
+
## Migration
Replace `variant="primary"` with `variant="solid"` and `variant="secondary"` with `variant="soft"`. Replace `color="danger"` with `status="error"`, or `color="red"` when only the palette should change. Blue information banners can use `status="info"`.
diff --git a/packages/twenty-front/src/modules/information-banner/components/InformationBanner.tsx b/packages/twenty-front/src/modules/information-banner/components/InformationBanner.tsx
index 1c0bf94355f..c1a1a43b7fc 100644
--- a/packages/twenty-front/src/modules/information-banner/components/InformationBanner.tsx
+++ b/packages/twenty-front/src/modules/information-banner/components/InformationBanner.tsx
@@ -1,13 +1,11 @@
import { InformationBannerComponentInstanceContext } from '@/information-banner/states/contexts/InformationBannerComponentInstanceContext';
import { informationBannerIsOpenComponentState } from '@/information-banner/states/informationBannerIsOpenComponentState';
import { useAtomComponentStateValue } from '@/ui/utilities/state/jotai/hooks/useAtomComponentStateValue';
-import { css } from '@linaria/core';
import { styled } from '@linaria/react';
import { t } from '@lingui/core/macro';
import { isDefined } from 'twenty-shared/utils';
-import { IconButton } from 'twenty-ui/components/input';
import { OverflowingTextWithTooltip } from 'twenty-ui/primitives/typography';
-import { type IconComponent, IconX } from 'twenty-ui/icon';
+import { type IconComponent } from 'twenty-ui/icon';
import {
Banner,
type BannerColor,
@@ -20,19 +18,12 @@ const StyledText = styled.div`
min-width: 0;
`;
-const BANNER_ICON_BUTTON_CLASS_NAME = css`
- &[data-variant='ghost'] {
- color: inherit;
- }
-`;
-
-const StyledContent = styled.div<{ hasCloseButton: boolean }>`
+const StyledContent = styled.div`
align-items: center;
display: flex;
flex: 1;
gap: ${themeCssVariables.spacing[3]};
justify-content: center;
- margin-left: ${({ hasCloseButton }) => (hasCloseButton ? '24px' : '0')};
min-width: 0;
`;
@@ -71,8 +62,14 @@ export const InformationBanner = ({
}}
>
{informationBannerIsOpen && (
- <Banner color={color} status={status} variant={variant}>
- <StyledContent hasCloseButton={isDefined(onClose)}>
+ <Banner
+ color={color}
+ status={status}
+ variant={variant}
+ onDismiss={onClose}
+ closeLabel={t`Close banner`}
+ >
+ <StyledContent>
<StyledText>
<OverflowingTextWithTooltip
isFocusable
@@ -90,17 +87,6 @@ export const InformationBanner = ({
</Banner.Action>
)}
</StyledContent>
- {isDefined(onClose) && (
- <IconButton
- className={BANNER_ICON_BUTTON_CLASS_NAME}
- size="sm"
- variant="ghost"
- onClick={onClose}
- aria-label={t`Close banner`}
- >
- <IconX />
- </IconButton>
- )}
</Banner>
)}
</InformationBannerComponentInstanceContext.Provider>
diff --git a/packages/twenty-ui/docs/bannerPropDescriptions.ts b/packages/twenty-ui/docs/bannerPropDescriptions.ts
index 55e0b731836..81ae81be270 100644
--- a/packages/twenty-ui/docs/bannerPropDescriptions.ts
+++ b/packages/twenty-ui/docs/bannerPropDescriptions.ts
@@ -12,6 +12,10 @@ export const BANNER_PROP_DESCRIPTIONS = {
icon: 'Optional leading ReactNode. The caller supplies decorative or accessible icon semantics.',
action:
'Optional trailing ReactNode. Banner.Action supplies a small outline action that inherits the resolved banner color; arbitrary controls are also accepted.',
+ onDismiss:
+ 'Renders a 24px ghost close control and calls this callback when activated. The caller owns visibility.',
+ closeLabel:
+ 'Accessible label for the close control. Defaults to Close; supply localized text when needed.',
className: 'Class merged onto the root div or composed element.',
style: 'Inline styles applied to the root div or composed element.',
ref: 'Ref to the root div, or to the DOM element supplied through render.',
diff --git a/packages/twenty-ui/docs/components.ts b/packages/twenty-ui/docs/components.ts
index 3e37ab60e5b..3776342fa35 100644
--- a/packages/twenty-ui/docs/components.ts
+++ b/packages/twenty-ui/docs/components.ts
@@ -188,7 +188,12 @@ export const DOCUMENTED_COMPONENTS = [
entryPoint: 'twenty-ui/primitives/feedback',
slug: 'feedback/banner',
propDescriptions: BANNER_PROP_DESCRIPTIONS,
- propDefaults: { color: 'status palette', status: 'info', variant: 'solid' },
+ propDefaults: {
+ color: 'status palette',
+ status: 'info',
+ variant: 'solid',
+ closeLabel: 'Close',
+ },
parts: ['Action'],
partPropDescriptions: { Action: BUTTON_PROP_DESCRIPTIONS },
},
diff --git a/packages/twenty-ui/generated/components.docs.json b/packages/twenty-ui/generated/components.docs.json
index 943b4c62900..5bc47d9be67 100644
--- a/packages/twenty-ui/generated/components.docs.json
+++ b/packages/twenty-ui/generated/components.docs.json
@@ -1249,6 +1249,13 @@
"defaultValue": null,
"description": "Class merged onto the root div or composed element."
},
+ {
+ "name": "closeLabel",
+ "type": "string",
+ "required": false,
+ "defaultValue": "Close",
+ "description": "Accessible label for the close control. Defaults to Close; supply localized text when needed."
+ },
{
"name": "color",
"type": "\"blue\" | \"gray\" | \"green\" | \"orange\" | \"red\"",
@@ -1263,6 +1270,13 @@
"defaultValue": null,
"description": "Optional leading ReactNode. The caller supplies decorative or accessible icon semantics."
},
+ {
+ "name": "onDismiss",
+ "type": "(() => void)",
+ "required": false,
+ "defaultValue": null,
+ "description": "Renders a 24px ghost close control and calls this callback when activated. The caller owns visibility."
+ },
{
"name": "ref",
"type": "Ref<HTMLDivElement>",
diff --git a/packages/twenty-ui/src/components/feedback/InlineBanner/types/InlineBannerProps.ts b/packages/twenty-ui/src/components/feedback/InlineBanner/types/InlineBannerProps.ts
index 0cf46aa511d..fb39a515931 100644
--- a/packages/twenty-ui/src/components/feedback/InlineBanner/types/InlineBannerProps.ts
+++ b/packages/twenty-ui/src/components/feedback/InlineBanner/types/InlineBannerProps.ts
@@ -2,7 +2,10 @@ import { type BannerProps } from '@ui/primitives/feedback/Banner/types/BannerPro
import { type InlineBannerLayout } from './InlineBannerLayout';
-export type InlineBannerProps = BannerProps & {
+export type InlineBannerProps = Omit<
+ BannerProps,
+ 'onDismiss' | 'closeLabel'
+> & {
layout?: InlineBannerLayout;
embedded?: boolean;
fullWidth?: boolean;
diff --git a/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss b/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss
index 3ccd05f61fd..8fb3b177bdc 100644
--- a/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss
+++ b/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss
@@ -62,3 +62,19 @@
display: flex;
flex-shrink: 0;
}
+
+.dismissible {
+ padding-inline: calc(
+ var(--t-spacing-2) + var(--t-spacing-6) + var(--t-spacing-3)
+ );
+ position: relative;
+}
+
+.closeButton {
+ @include square-button;
+
+ inset-inline-end: var(--t-spacing-2);
+ position: absolute;
+ top: 50%;
+ transform: translateY(-50%);
+}
diff --git a/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss.d.ts b/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss.d.ts
index cbb44880c98..6be1e623db6 100644
--- a/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss.d.ts
+++ b/packages/twenty-ui/src/primitives/feedback/Banner/Banner.module.scss.d.ts
@@ -2,5 +2,7 @@ declare const classNames: {
readonly banner: 'banner';
readonly icon: 'icon';
readonly action: 'action';
+ readonly dismissible: 'dismissible';
+ readonly closeButton: 'closeButton';
};
export default classNames;
diff --git a/packages/twenty-ui/src/primitives/feedback/Banner/__stories__/Banner.stories.tsx b/packages/twenty-ui/src/primitives/feedback/Banner/__stories__/Banner.stories.tsx
index c1b0ecf0fe8..f9b93636517 100644
--- a/packages/twenty-ui/src/primitives/feedback/Banner/__stories__/Banner.stories.tsx
+++ b/packages/twenty-ui/src/primitives/feedback/Banner/__stories__/Banner.stories.tsx
@@ -1,5 +1,9 @@
import { type Meta, type StoryObj } from '@storybook/react-vite';
-import { expect, within } from 'storybook/test';
+import { expect, fn, userEvent, within } from 'storybook/test';
+import { useState } from 'react';
+
+import { Button } from '@ui/primitives/input/Button/Button';
+import { DirectionProvider } from '@ui/primitives/layout/DirectionProvider/DirectionProvider';
import { IconInfoCircle } from '@ui/icon';
import { Banner } from '@ui/primitives/feedback/Banner/Banner';
@@ -159,3 +163,102 @@ export const IndependentAppearance: Story = {
);
},
};
+
+export const Dismissible: Story = {
+ args: {
+ children: 'Contacts are syncing in the background.',
+ onDismiss: fn(),
+ role: 'status',
+ action: <Banner.Action>View progress</Banner.Action>,
+ },
+ parameters: { container: { width: 400 } },
+ decorators: [ComponentDecorator],
+};
+
+export const DismissalInteractions: Story = {
+ ...Dismissible,
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const banner = canvas.getByRole('status');
+ const close = canvas.getByRole('button', { name: 'Close' });
+ const action = canvas.getByRole('button', { name: 'View progress' });
+
+ await expect(close).toHaveAttribute('type', 'button');
+ await expect(close.getBoundingClientRect().width).toBe(24);
+ await expect(close.getBoundingClientRect().height).toBe(24);
+ await expect(action.getBoundingClientRect().right).toBeLessThan(
+ close.getBoundingClientRect().left,
+ );
+ await expect(getComputedStyle(close).color).toBe(
+ getComputedStyle(banner).color,
+ );
+ close.focus();
+ await userEvent.keyboard('{Enter}');
+ await expect(args.onDismiss).toHaveBeenCalledOnce();
+ await expect(banner).toBeVisible();
+ },
+};
+
+export const DismissibleRtl: Story = {
+ ...Dismissible,
+ args: {
+ ...Dismissible.args,
+ closeLabel: 'Dismiss sync message',
+ dir: 'rtl',
+ onDismiss: fn(),
+ },
+ decorators: [
+ ComponentDecorator,
+ (Story) => (
+ <DirectionProvider direction="rtl">
+ <Story />
+ </DirectionProvider>
+ ),
+ ],
+ play: async ({ canvasElement, args }) => {
+ const canvas = within(canvasElement);
+ const close = canvas.getByRole('button', { name: 'Dismiss sync message' });
+ const action = canvas.getByRole('button', { name: 'View progress' });
+
+ await expect(close.getBoundingClientRect().right).toBeLessThan(
+ action.getBoundingClientRect().left,
+ );
+ await userEvent.click(close);
+ await expect(args.onDismiss).toHaveBeenCalledOnce();
+ },
+};
+
+export const ControlledDismissal: Story = {
+ decorators: [ComponentDecorator],
+ render: function ControlledDismissalExample() {
+ const [isVisible, setIsVisible] = useState(true);
+
+ return (
+ <form onSubmit={(event) => event.preventDefault()}>
+ {isVisible ? (
+ <Banner
+ onDismiss={() => setIsVisible(false)}
+ closeLabel="Dismiss sync message"
+ role="status"
+ >
+ Contacts are syncing in the background.
+ </Banner>
+ ) : (
+ <Button onClick={() => setIsVisible(true)}>Show sync message</Button>
+ )}
+ </form>
+ );
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Dismiss sync message' }),
+ );
+ await expect(canvas.queryByRole('status')).not.toBeInTheDocument();
+ await userEvent.click(
+ canvas.getByRole('button', { name: 'Show sync message' }),
+ );
+ await expect(canvas.getByRole('status')).toBeVisible();
+ },
+};
diff --git a/packages/twenty-ui/src/primitives/feedback/Banner/internal/BannerComponent.tsx b/packages/twenty-ui/src/primitives/feedback/Banner/internal/BannerComponent.tsx
index 01310db8268..1922fa4f869 100644
--- a/packages/twenty-ui/src/primitives/feedback/Banner/internal/BannerComponent.tsx
+++ b/packages/twenty-ui/src/primitives/feedback/Banner/internal/BannerComponent.tsx
@@ -1,6 +1,11 @@
import { useRender } from '@base-ui/react/use-render';
import { clsx } from 'clsx';
+import { Button } from '@ui/primitives/input/Button/Button';
+import { IconX } from '@ui/icon/components/TablerIcons';
+import { doNotTranslate } from '@ui/utilities/internal/doNotTranslate';
+import { isDefined } from '@ui/utilities/utils/isDefined';
+
import { FEEDBACK_STATUS_COLORS } from '@ui/primitives/feedback/internal/constants/FeedbackStatusColors';
import { isRenderableSlot } from '@ui/utilities/internal/isRenderableSlot';
@@ -13,6 +18,8 @@ export const BannerComponent = ({
color = FEEDBACK_STATUS_COLORS[status],
icon,
action,
+ onDismiss,
+ closeLabel = doNotTranslate('Close'),
className,
children,
render,
@@ -25,7 +32,11 @@ export const BannerComponent = ({
state: { status, variant, color },
props: {
...props,
- className: clsx(styles.banner, className),
+ className: clsx(
+ styles.banner,
+ isDefined(onDismiss) && styles.dismissible,
+ className,
+ ),
children: (
<>
{isRenderableSlot(icon) && (
@@ -35,6 +46,18 @@ export const BannerComponent = ({
{isRenderableSlot(action) && (
<div className={styles.action}>{action}</div>
)}
+ {isDefined(onDismiss) && (
+ <Button
+ type="button"
+ size="sm"
+ variant="ghost"
+ color="inherit"
+ className={styles.closeButton}
+ aria-label={closeLabel}
+ onClick={onDismiss}
+ startIcon={<IconX aria-hidden="true" />}
+ />
+ )}
</>
),
},
diff --git a/packages/twenty-ui/src/primitives/feedback/Banner/types/BannerProps.ts b/packages/twenty-ui/src/primitives/feedback/Banner/types/BannerProps.ts
index 072b0c23760..f936bf2d274 100644
--- a/packages/twenty-ui/src/primitives/feedback/Banner/types/BannerProps.ts
+++ b/packages/twenty-ui/src/primitives/feedback/Banner/types/BannerProps.ts
@@ -15,4 +15,6 @@ export type BannerProps = Omit<
color?: BannerColor;
icon?: ReactNode;
action?: ReactNode;
+ onDismiss?: () => void;
+ closeLabel?: string;
};