Skip to content

feat(badge): add notification variant #3993

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

Merged
merged 9 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/smooth-gorillas-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@twilio-paste/badge": minor
"@twilio-paste/core": minor
---

[Badge] Added a new notification variant
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ module.exports = {
"icon_small",
"error_counter",
"neutral_counter",
"notification_counter",
// unstable props are allowed
"^unstable_",
// this is a temporary prop, if the console patch is removed from components this can be removed too
Expand Down
1 change: 1 addition & 0 deletions packages/paste-core/components/badge/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const BadgeVariants = [
"neutral_counter",
"error_counter",
"default",
"notification_counter",
// the following variants are outdated but still supported to prevent breaking changes
"info",
] as const;
9 changes: 9 additions & 0 deletions packages/paste-core/components/badge/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ export const badgeVariantStyles: {
color: "colorText",
boxShadow: "shadowBorderWeaker",
},
notification_counter: {
borderRadius: "borderRadiusPill",
backgroundColor: "colorBackgroundNotification",
color: "colorTextInverse",
boxShadow: "shadowBorderNotification",
},
/*
* the following variants are outdated but still supported to prevent breaking changes
*/
Expand Down Expand Up @@ -170,6 +176,9 @@ export const badgeButtonStyles: {
error_counter: {
boxShadow: "shadowBorderBottomErrorWeaker",
},
notification_counter: {
boxShadow: "shadowBorderBottomNotificationStronger",
},
// the following variants are outdated but still supported to prevent breaking changes
default: {
boxShadow: "shadowBorderBottomDecorative10Weaker",
Expand Down
55 changes: 55 additions & 0 deletions packages/paste-core/components/badge/stories/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ export const AllBadges = (): JSX.Element => (
<Badge as="span" variant="error_counter">
1
</Badge>
<Badge as="span" variant="notification_counter">
100
</Badge>
</Wrapper>
);
export const SmallBadges = (): JSX.Element => (
Expand Down Expand Up @@ -126,6 +129,9 @@ export const SmallBadges = (): JSX.Element => (
<Badge as="span" size="small" variant="error_counter">
1
</Badge>
<Badge as="span" size="small" variant="notification_counter">
100
</Badge>
</Wrapper>
);

Expand Down Expand Up @@ -1031,3 +1037,52 @@ export const LongTextBadge = (): JSX.Element => (
</Badge>
</Wrapper>
);

export const NotificationCounterBadge = (): JSX.Element => (
<>
<Heading as="h2" variant="heading40">
Span
</Heading>
<Wrapper>
<Badge as="span" variant="notification_counter">
100
</Badge>
<Badge as="span" variant="notification_counter">
100
</Badge>
<Badge as="span" variant="notification_counter">
100
</Badge>
</Wrapper>
<Heading as="h2" variant="heading40">
Anchor
</Heading>
<Wrapper>
<Badge as="a" href="#" variant="notification_counter">
100
</Badge>
<Badge as="a" href="#" variant="notification_counter">
100
</Badge>
<Badge as="a" href="#" variant="notification_counter">
100
</Badge>
</Wrapper>
<Heading as="h2" variant="heading40">
Button
</Heading>
<Wrapper>
<Badge as="button" onClick={() => {}} variant="notification_counter">
100
</Badge>
<Badge as="button" onClick={() => {}} variant="notification_counter">
100
</Badge>
<Badge as="button" onClick={() => {}} variant="notification_counter">
100
</Badge>
</Wrapper>
</>
);

NotificationCounterBadge.storyName = "Notification Counter Badge";
4 changes: 2 additions & 2 deletions packages/paste-core/components/badge/type-docs.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"BadgeBase": {
"variant": {
"type": "| \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"default\"\n | \"info\"",
"type": "| \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"default\"\n | \"notification_counter\"\n | \"info\"",
"defaultValue": "null",
"required": true,
"externalProp": false
Expand Down Expand Up @@ -29,7 +29,7 @@
"description": "Underlying HTML element to render. Can be \"span\", \"button\", or \"a\"."
},
"variant": {
"type": "| \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"default\"\n | \"info\"",
"type": "| \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"default\"\n | \"notification_counter\"\n | \"info\"",
"defaultValue": "null",
"required": true,
"externalProp": false
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/menu/type-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2477,7 +2477,7 @@
"description": "Toggles the `visible` state"
},
"variant": {
"type": "| \"default\"\n | \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"info\"",
"type": "| \"default\"\n | \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"notification_counter\"\n | \"info\"",
"defaultValue": "null",
"required": true,
"externalProp": false
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/popover/type-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3560,7 +3560,7 @@
},
"PopoverBadgeButton": {
"variant": {
"type": "| \"default\"\n | \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"info\"",
"type": "| \"default\"\n | \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"notification_counter\"\n | \"info\"",
"defaultValue": "null",
"required": true,
"externalProp": false
Expand Down
2 changes: 1 addition & 1 deletion packages/paste-core/components/side-panel/type-docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@
},
"SidePanelBadgeButton": {
"variant": {
"type": "| \"default\"\n | \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"info\"",
"type": "| \"default\"\n | \"neutral\"\n | \"warning\"\n | \"error\"\n | \"success\"\n | \"new\"\n | \"subaccount\"\n | \"decorative10\"\n | \"decorative20\"\n | \"decorative30\"\n | \"decorative40\"\n | \"brand10\"\n | \"brand20\"\n | \"brand30\"\n | \"neutral_counter\"\n | \"error_counter\"\n | \"notification_counter\"\n | \"info\"",
"defaultValue": "null",
"required": true,
"externalProp": false
Expand Down
9 changes: 6 additions & 3 deletions packages/paste-website/src/pages/components/badge/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,9 @@ Use the brand Badge for cross-selling opportunities across platforms (e.g., Segm

### Counter

Use the counter Badge should be used to visually highlight a count in a UI.
For example, the number of pending invitations or the number of errors.
Counter Badges are limited to Neutral and Error variants, and the error variant should always include an error icon.
Use the counter Badge to visually highlight a count in a UI, like the number of pending invitations or the number of errors.

Counter Badges have neutral, error, and notification variants. The error variant should always include an error icon. The notification variant informs users of new or unread items, such as messages, notifications, or updates.

<LivePreview scope={{Box, Badge, InformationIcon, ErrorIcon, WarningIcon, SuccessIcon, NewIcon}} language="jsx">
{`<Box display="flex" columnGap="space80">
Expand All @@ -327,6 +327,9 @@ Counter Badges are limited to Neutral and Error variants, and the error variant
<Badge as="span" variant="error_counter">
100
</Badge>
<Badge as="span" variant="notification_counter">
100
</Badge>
</Box>
`.trim()}
</LivePreview>
Expand Down
Loading