Skip to content

Commit 493f70c

Browse files
committed
Add badge variants and deprecate status component
1 parent 00e69fd commit 493f70c

File tree

6 files changed

+56
-6
lines changed

6 files changed

+56
-6
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

.changeset/lucky-actors-clean.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@strapi/design-system': major
3+
'@strapi/ui-primitives': major
4+
---
5+
6+
Fix grid item column fallback value

docs/stories/Grid.stories.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,21 @@ export const BaseGrid = {
4747
name: 'base grid',
4848
} satisfies Story;
4949

50+
export const GridItemColSizeFallback = {
51+
render: () => (
52+
<Grid.Root gap={5}>
53+
{Array(12)
54+
.fill(null)
55+
.map((_, i) => (
56+
<Grid.Item key={i} background="success200" col={6}>
57+
<Typography>Column {i + 1}</Typography>
58+
</Grid.Item>
59+
))}
60+
</Grid.Root>
61+
),
62+
name: 'Column size fallback to col',
63+
} satisfies Story;
64+
5065
export const ComplexGrid = {
5166
render: () => (
5267
<Grid.Root

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>

packages/design-system/src/primitives/Grid/Grid.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ type ItemComponent<C extends React.ElementType = 'div'> = <T extends React.Eleme
5757
) => JSX.Element;
5858

5959
const Item = styled(Flex)`
60-
grid-column: span ${({ $xs }) => $xs ?? 12};
60+
grid-column: span ${({ $xs, $col }) => $xs ?? $col ?? 12};
6161
max-width: 100%;
6262
6363
${({ theme }) => theme.breakpoints.small} {
64-
grid-column: span ${({ $s, $xs }) => $s ?? $xs ?? 12};
64+
grid-column: span ${({ $s, $xs, $col }) => $s ?? $xs ?? $col ?? 12};
6565
}
6666
6767
${({ theme }) => theme.breakpoints.medium} {
68-
grid-column: span ${({ $m, $s, $xs }) => $m ?? $s ?? $xs ?? 12};
68+
grid-column: span ${({ $m, $s, $xs, $col }) => $m ?? $s ?? $xs ?? $col ?? 12};
6969
}
7070
7171
${({ theme }) => theme.breakpoints.large} {

0 commit comments

Comments
 (0)