-
Notifications
You must be signed in to change notification settings - Fork 129
feat(circuit-ui): Callout component #3733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
matoous
wants to merge
2
commits into
main
Choose a base branch
from
md/callout-component
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sumup-oss/circuit-ui': minor | ||
| --- | ||
|
|
||
| Added the experimental Callout component for static inline guidance or emphasis. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { Meta, Status, Props, Story } from '../../../../.storybook/components'; | ||
| import * as Stories from './Callout.stories'; | ||
|
|
||
| <Meta of={Stories} /> | ||
|
|
||
| # Callout | ||
|
|
||
| <Status variant="experimental" /> | ||
|
|
||
| The `Callout` component renders static guidance or emphasis content within the content flow. | ||
|
|
||
| <Story of={Stories.Base} /> | ||
| <Props /> | ||
|
|
||
| ## When to use it | ||
|
|
||
| Use callouts to highlight persistent guidance, contextual tips, or extra information that belongs next to related content. | ||
|
|
||
| Keep callout copy concise and static. For semantic feedback to user actions, use [`NotificationInline`](Notifications/NotificationInline). For dismissible content or content with a call to action, use [`NotificationBanner`](Notifications/NotificationBanner). | ||
|
|
||
| ## How to use it | ||
|
|
||
| ### Variants | ||
|
|
||
| <Story of={Stories.Variants} /> | ||
|
|
||
| - Use the 'info' variant for informational, neutral messages. | ||
| - Use the 'success' variant for successful messages. | ||
| - Use the 'warning' variant for warning messages, and other information a user should be aware of. | ||
| - Use the 'danger' variant for error messages. Be descriptive and give users clear next steps. | ||
| - Use the 'promo' variant for promotional or upgrade-related messages. | ||
|
|
||
| ### Links | ||
|
|
||
| The callout body supports links to related content. Avoid placing other interactive content inside a callout. | ||
|
|
||
| <Story of={Stories.WithRichContent} /> | ||
|
|
||
| ## Accessibility | ||
|
|
||
| ### Best practices | ||
|
|
||
| #### Place callouts close to their related content | ||
|
|
||
| Callouts are part of the content flow, and should be placed near their related content. Make use of headings and semantic markup to programmatically group content into meaningful sections. | ||
|
|
||
| #### Avoid dynamically rendering a callout | ||
|
|
||
| The `Callout` component is meant for static content. If you need to render a message dynamically, you most likely want to use the [`NotificationInline`](Notifications/NotificationInline) component instead. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: mostly adopted for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| .base { | ||
| display: flex; | ||
| flex-direction: row; | ||
| align-items: center; | ||
| padding: var(--cui-spacings-kilo) var(--cui-spacings-mega); | ||
| border-radius: var(--cui-border-radius-kilo); | ||
| } | ||
|
|
||
| .icon { | ||
| position: relative; | ||
| flex-grow: 0; | ||
| flex-shrink: 0; | ||
| align-self: flex-start; | ||
| line-height: 0; | ||
| } | ||
|
|
||
| .content { | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: flex-start; | ||
| padding-left: var(--cui-spacings-mega); | ||
| font-size: var(--cui-body-m-font-size); | ||
| font-weight: var(--cui-font-weight-regular); | ||
| line-height: var(--cui-body-m-line-height); | ||
| letter-spacing: var(--cui-letter-spacing); | ||
| } | ||
|
|
||
| /* Variants */ | ||
|
|
||
| .info { | ||
| background-color: var(--cui-bg-subtle); | ||
| } | ||
|
|
||
| .info .icon { | ||
| color: var(--cui-fg-accent); | ||
| } | ||
|
|
||
| .success { | ||
| background-color: var(--cui-bg-success); | ||
| } | ||
|
|
||
| .success .icon { | ||
| color: var(--cui-fg-success); | ||
| } | ||
|
|
||
| .warning { | ||
| background-color: var(--cui-bg-warning); | ||
| } | ||
|
|
||
| .warning .icon { | ||
| color: var(--cui-fg-warning); | ||
| } | ||
|
|
||
| .danger { | ||
| background-color: var(--cui-bg-danger); | ||
| } | ||
|
|
||
| .danger .icon { | ||
| color: var(--cui-fg-danger); | ||
| } | ||
|
|
||
| .promo { | ||
| background-color: var(--cui-bg-promo); | ||
| } | ||
|
|
||
| .promo .icon { | ||
| color: var(--cui-fg-promo); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * Copyright 2026, SumUp Ltd. | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { createRef } from 'react'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| import type { IconProps } from '@sumup-oss/icons'; | ||
|
|
||
| import { axe, render, screen } from '../../util/test-utils.js'; | ||
|
|
||
| import { Callout, type CalloutProps } from './Callout.js'; | ||
|
|
||
| describe('Callout', () => { | ||
| const renderCallout = (props: CalloutProps) => render(<Callout {...props} />); | ||
|
|
||
| const baseProps: CalloutProps = { | ||
| body: 'This is a callout', | ||
| }; | ||
|
|
||
| it('should render the callout', () => { | ||
| renderCallout(baseProps); | ||
|
|
||
| expect(screen.getByText('This is a callout')).toBeVisible(); | ||
| }); | ||
|
|
||
| it.each([ | ||
| 'info', | ||
| 'success', | ||
| 'warning', | ||
| 'danger', | ||
| 'promo', | ||
| ] as const)('should render the %s variant', (variant) => { | ||
| const { container } = renderCallout({ ...baseProps, variant }); | ||
|
|
||
| expect(container.firstElementChild?.className).toContain(`_${variant}_`); | ||
| }); | ||
|
|
||
| it('should render a custom icon', () => { | ||
| const CustomIcon = (props: IconProps) => ( | ||
| <svg {...props} data-testid="custom-icon" /> | ||
| ); | ||
|
|
||
| renderCallout({ ...baseProps, icon: CustomIcon }); | ||
|
|
||
| const icon = screen.getByTestId('custom-icon'); | ||
|
|
||
| expect(icon).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render the icon label visually hidden', () => { | ||
| renderCallout({ ...baseProps, iconLabel: 'Information' }); | ||
|
|
||
| expect(screen.getByText('Information')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should forward a ref', () => { | ||
| const ref = createRef<HTMLDivElement>(); | ||
| const { container } = render(<Callout ref={ref} {...baseProps} />); | ||
|
|
||
| expect(ref.current).toBe(container.firstChild); | ||
| }); | ||
|
|
||
| it('should have no accessibility violations', async () => { | ||
| const { container } = renderCallout(baseProps); | ||
| const actual = await axe(container); | ||
|
|
||
| expect(actual).toHaveNoViolations(); | ||
| }); | ||
| }); |
65 changes: 65 additions & 0 deletions
65
packages/circuit-ui/components/Callout/Callout.stories.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /** | ||
| * Copyright 2026, SumUp Ltd. | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { Stack } from '../../../../.storybook/components/index.js'; | ||
| import { Anchor } from '../Anchor/Anchor.js'; | ||
|
|
||
| import { Callout, type CalloutProps } from './Callout.js'; | ||
|
|
||
| export default { | ||
| title: 'Notifications/Callout', | ||
| component: Callout, | ||
| tags: ['status:experimental'], | ||
| }; | ||
|
|
||
| const variants = ['info', 'success', 'warning', 'danger', 'promo'] as const; | ||
|
|
||
| export const Base = (args: CalloutProps) => <Callout {...args} />; | ||
|
|
||
| Base.args = { | ||
| body: 'Callout is a newly available component for static inline guidance or emphasis.', | ||
| variant: 'promo', | ||
| } as CalloutProps; | ||
|
|
||
| Base.parameters = { | ||
| chromatic: { | ||
| // covered in the Variants story | ||
| disableSnapshot: true, | ||
| }, | ||
| }; | ||
|
|
||
| export const Variants = (args: CalloutProps) => ( | ||
| <Stack vertical> | ||
| {variants.map((variant) => ( | ||
| <Callout key={variant} {...args} variant={variant} /> | ||
| ))} | ||
| </Stack> | ||
| ); | ||
|
|
||
| Variants.args = { | ||
| body: 'This is a callout message', | ||
| } as CalloutProps; | ||
|
|
||
| export const WithRichContent = (args: CalloutProps) => <Callout {...args} />; | ||
|
|
||
| WithRichContent.args = { | ||
| body: ( | ||
| <div id="callout-rich-content"> | ||
| Callouts can include{' '} | ||
| <Anchor href="#callout-rich-content">links to related content</Anchor>. | ||
| </div> | ||
| ), | ||
| variant: 'promo', | ||
| } as CalloutProps; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /** | ||
| * Copyright 2026, SumUp Ltd. | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { forwardRef, type HTMLAttributes, type ReactNode } from 'react'; | ||
|
|
||
| import { | ||
| Alert, | ||
| Confirm, | ||
| Info, | ||
| Notify, | ||
| Sparkles, | ||
| type IconComponentType, | ||
| } from '@sumup-oss/icons'; | ||
|
|
||
| import { clsx } from '../../styles/clsx.js'; | ||
| import { utilClasses } from '../../styles/utility.js'; | ||
|
|
||
| import classes from './Callout.module.css'; | ||
|
|
||
| export type CalloutVariant = | ||
| | 'info' | ||
| | 'success' | ||
| | 'warning' | ||
| | 'danger' | ||
| | 'promo'; | ||
|
|
||
| const CALLOUT_ICONS: Record<CalloutVariant, IconComponentType<'24'>> = { | ||
| info: Info, | ||
| success: Confirm, | ||
| warning: Notify, | ||
| danger: Alert, | ||
| promo: Sparkles, | ||
| }; | ||
|
|
||
| export interface CalloutProps extends HTMLAttributes<HTMLDivElement> { | ||
| /** | ||
| * The callout's variant. | ||
| * @default 'info' | ||
| */ | ||
| variant?: CalloutVariant; | ||
| /** | ||
| * The callout's body content. | ||
| */ | ||
| body: ReactNode; | ||
| /** | ||
| * The icon displayed next to the body. | ||
| */ | ||
| icon?: IconComponentType<'24'>; | ||
| /** | ||
| * A text replacement for the icon in the context of the callout, if its body | ||
| * copy isn't self-explanatory. Defaults to an empty string. | ||
| */ | ||
| iconLabel?: string; | ||
| } | ||
|
|
||
| /** | ||
| * The `Callout` component renders static inline guidance or emphasis within | ||
| * the content flow. | ||
| */ | ||
| export const Callout = forwardRef<HTMLDivElement, CalloutProps>( | ||
| ( | ||
| { variant = 'info', body, icon, iconLabel = '', className, ...props }, | ||
| ref, | ||
| ) => { | ||
| const Icon = icon || CALLOUT_ICONS[variant]; | ||
|
|
||
| return ( | ||
| <div | ||
| ref={ref} | ||
| className={clsx(classes.base, classes[variant], className)} | ||
| {...props} | ||
| > | ||
| <div className={classes.icon}> | ||
| <Icon aria-hidden="true" size="24" /> | ||
| </div> | ||
| <span className={utilClasses.hideVisually}>{iconLabel}</span> | ||
| <div className={classes.content}>{body}</div> | ||
| </div> | ||
| ); | ||
| }, | ||
| ); | ||
|
|
||
| Callout.displayName = 'Callout'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| /** | ||
| * Copyright 2026, SumUp Ltd. | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| export { Callout } from './Callout.js'; | ||
| export type { CalloutProps, CalloutVariant } from './Callout.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We usually structure this page in two main sections (When to use, How to use) and them some optional ones (Related components, Accessibility, or any component specific guidelines)
When to use ideally lists one or two valid use cases, gives some tips about copy and content, and can suggest more suitable components for similar but not so accurate usages. In the example of the Callout, we can suggest using the NotificationInline for semantic feedback to user actions (danger, success and warning), and the NotificationBanner for dismissible content or content with a CTA.
How to use details things like variants, different states and possible customisation of the component.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks! Can you please check if my changes match the desired structure?