Skip to content

Commit b99d984

Browse files
HoldenFolkHichamELBSI
authored andcommitted
Add badge variants and deprecate status component
1 parent ace623b commit b99d984

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

.changeset/blue-spoons-argue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@strapi/design-system': minor
3+
---
4+
5+
Add variants to Badge component

docs/stories/Status.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import { Meta, Canvas, ArgTypes } from '@storybook/addon-docs/blocks';
22
import { Status } from '@strapi/design-system';
33

4+
import { DeprecationNotice } from '../components/DeprecationNotice';
5+
46
import * as StatusStories from './Status.stories';
57

68
<Meta of={StatusStories} />
79

810
# Status
911

12+
<DeprecationNotice href="/?path=/docs/stories/Badge">Badge</DeprecationNotice>
13+
1014
Status are used to give an important visual indication to the users on a page level.
1115

1216
**Best practices**

packages/design-system/src/components/Badge/Badge.tsx

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,55 @@
1-
import { css, styled } from 'styled-components';
1+
import { css, styled, DefaultTheme } from 'styled-components';
22

33
import { Flex, FlexComponent, FlexProps } from '../../primitives/Flex';
44
import { Typography } from '../../primitives/Typography';
55
import { DefaultThemeOrCSSProp } from '../../types';
66

77
type BadgeSize = 'S' | 'M';
88

9+
type BadgeVariant = 'success' | 'primary' | 'danger' | 'warning' | 'neutral' | 'secondary' | 'alternative';
10+
911
interface BadgeProps extends FlexProps {
1012
/**
1113
* If `true`, it changes the `backgroundColor` to `primary200` and the `textColor` to `primary600`
1214
*/
1315
active?: boolean;
16+
1417
backgroundColor?: DefaultThemeOrCSSProp<'colors', 'background'>;
1518
/**
1619
* @default 'M'
1720
*/
1821
size?: BadgeSize;
22+
1923
textColor?: DefaultThemeOrCSSProp<'colors', 'color'>;
24+
25+
/**
26+
* @default 'neutral'
27+
*/
28+
variant?: BadgeVariant;
2029
}
2130

2231
const Badge = ({
2332
active = false,
2433
size = 'M',
2534
textColor = 'neutral600',
2635
backgroundColor = 'neutral150',
36+
variant,
2737
children,
2838
minWidth = 5,
2939
...props
3040
}: BadgeProps) => {
3141
const paddingX = size === 'S' ? 1 : 2;
3242

43+
const overridedColors = variant
44+
? {
45+
backgroundColor: `${variant}200` satisfies keyof DefaultTheme['colors'],
46+
textColor: `${variant}700` satisfies keyof DefaultTheme['colors'],
47+
}
48+
: {
49+
backgroundColor,
50+
textColor,
51+
};
52+
3353
return (
3454
<Base
3555
inline
@@ -38,11 +58,11 @@ const Badge = ({
3858
minWidth={minWidth}
3959
paddingLeft={paddingX}
4060
paddingRight={paddingX}
41-
background={active ? 'primary200' : backgroundColor}
61+
background={active ? 'primary200' : overridedColors.backgroundColor}
4262
$size={size}
4363
{...props}
4464
>
45-
<Typography variant="sigma" textColor={active ? 'primary600' : textColor} lineHeight="1rem">
65+
<Typography variant="sigma" textColor={active ? 'primary600' : overridedColors.textColor} lineHeight="1rem">
4666
{children}
4767
</Typography>
4868
</Base>

0 commit comments

Comments
 (0)