diff --git a/.changeset/flush-banner.md b/.changeset/flush-banner.md new file mode 100644 index 00000000000..2b3cd426745 --- /dev/null +++ b/.changeset/flush-banner.md @@ -0,0 +1,5 @@ +--- +"@primer/react": minor +--- + +Banner: Add `flush` prop for use within confined spaces, such as dialogs, tables, cards, or boxes where available space is limited. diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-colorblind-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-colorblind-linux.png new file mode 100644 index 00000000000..e548fc716cf Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-dimmed-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-dimmed-linux.png new file mode 100644 index 00000000000..b895489c7a5 Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-dimmed-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-high-contrast-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-high-contrast-linux.png new file mode 100644 index 00000000000..e184029d841 Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-linux.png new file mode 100644 index 00000000000..37fd2d5ed5c Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-tritanopia-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-tritanopia-linux.png new file mode 100644 index 00000000000..37fd2d5ed5c Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-dark-tritanopia-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-colorblind-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-colorblind-linux.png new file mode 100644 index 00000000000..f43ea7e1f6e Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-colorblind-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-high-contrast-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-high-contrast-linux.png new file mode 100644 index 00000000000..872fd370c35 Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-high-contrast-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-linux.png new file mode 100644 index 00000000000..95179a4e679 Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-linux.png differ diff --git a/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-tritanopia-linux.png b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-tritanopia-linux.png new file mode 100644 index 00000000000..95179a4e679 Binary files /dev/null and b/.playwright/snapshots/components/Banner.test.ts-snapshots/Banner-FlushInsideDialog-light-tritanopia-linux.png differ diff --git a/e2e/components/Banner.test.ts b/e2e/components/Banner.test.ts index c82a2feb2f9..1ce4a1676d0 100644 --- a/e2e/components/Banner.test.ts +++ b/e2e/components/Banner.test.ts @@ -78,6 +78,10 @@ const stories: Array<{title: string; id: string; viewports?: Array { diff --git a/packages/react/src/Banner/Banner.docs.json b/packages/react/src/Banner/Banner.docs.json index 013f4609357..be04df252ca 100644 --- a/packages/react/src/Banner/Banner.docs.json +++ b/packages/react/src/Banner/Banner.docs.json @@ -117,6 +117,12 @@ "name": "actionsLayout", "type": "'default' | 'inline' | 'stacked'", "description": "Override the responsive layout of the action buttons. 'inline' layout will display the buttons inline with the title and description, while 'stacked' layout will always render the buttons in a new row." + }, + { + "name": "flush", + "type": "boolean", + "defaultValue": "false", + "description": "Full width banner specifically for use within confined spaces, such as dialogs, tables, cards, or boxes where available space is limited." } ], "subcomponents": [ @@ -157,4 +163,4 @@ } } ] -} \ No newline at end of file +} diff --git a/packages/react/src/Banner/Banner.features.stories.tsx b/packages/react/src/Banner/Banner.features.stories.tsx index c8006c0e721..089e5c89f19 100644 --- a/packages/react/src/Banner/Banner.features.stories.tsx +++ b/packages/react/src/Banner/Banner.features.stories.tsx @@ -262,19 +262,28 @@ export const CustomIcon = () => { ) } -export const InsideDialog = () => { +export const FlushInsideDialog = () => { const onDialogClose = React.useCallback(() => {}, []) return ( - + { + // custom renderBody to remove default padding from body and move it to the child after banner + return
{children}
+ }} + > Try again} + flush /> +
rest of the dialog content goes here
) } diff --git a/packages/react/src/Banner/Banner.module.css b/packages/react/src/Banner/Banner.module.css index a0e3aac4ed0..07b04346567 100644 --- a/packages/react/src/Banner/Banner.module.css +++ b/packages/react/src/Banner/Banner.module.css @@ -51,6 +51,12 @@ padding: var(--base-size-4); } + &[data-flush] { + border-left: none; + border-right: none; + border-radius: 0; + } + &[data-variant='critical'] { --banner-bgColor: var(--bgColor-danger-muted); --banner-borderColor: var(--borderColor-danger-muted); diff --git a/packages/react/src/Banner/Banner.test.tsx b/packages/react/src/Banner/Banner.test.tsx index cc75f323b2b..bbce0ca0808 100644 --- a/packages/react/src/Banner/Banner.test.tsx +++ b/packages/react/src/Banner/Banner.test.tsx @@ -239,6 +239,16 @@ describe('Banner', () => { expect(container.firstChild).toHaveAttribute('data-actions-layout', 'default') }) + it('should render data-flush attribute when flush is true', () => { + const {container} = render() + expect(container.firstChild).toHaveAttribute('data-flush') + }) + + it('should not render data-flush attribute when flush is false', () => { + const {container} = render() + expect(container.firstChild).not.toHaveAttribute('data-flush') + }) + describe('Banner.Title', () => { it('should render as a h2 element by default', () => { render( diff --git a/packages/react/src/Banner/Banner.tsx b/packages/react/src/Banner/Banner.tsx index c8ac24770d3..95f2f3c1014 100644 --- a/packages/react/src/Banner/Banner.tsx +++ b/packages/react/src/Banner/Banner.tsx @@ -80,6 +80,11 @@ export type BannerProps = React.ComponentPropsWithoutRef<'section'> & { * Override the default actions layout behavior */ actionsLayout?: 'inline' | 'stacked' | 'default' + + /** + * Full width banner specifically for use within confined spaces, such as dialogs, tables, cards, or boxes where available space is limited. + */ + flush?: boolean } const iconForVariant: Record = { @@ -114,6 +119,7 @@ export const Banner = React.forwardRef(function Banner title, variant = 'info', actionsLayout = 'default', + flush = false, ...rest }, forwardRef, @@ -161,6 +167,7 @@ export const Banner = React.forwardRef(function Banner tabIndex={-1} ref={ref} data-layout={rest.layout || 'default'} + data-flush={flush ? '' : undefined} >
{visual && supportsCustomIcon ? visual : iconForVariant[variant]}