Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/blue-spoons-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@strapi/design-system': minor
---

Add variants to Badge component
3 changes: 3 additions & 0 deletions docs/stories/Status.mdx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { Meta, Canvas, ArgTypes } from '@storybook/addon-docs/blocks';
import { Status } from '@strapi/design-system';

import * as StatusStories from './Status.stories';

Check failure on line 4 in docs/stories/Status.mdx

View workflow job for this annotation

GitHub Actions / lint

There should be at least one empty line between import groups
import { DeprecationNotice } from '../components/DeprecationNotice';

Check failure on line 5 in docs/stories/Status.mdx

View workflow job for this annotation

GitHub Actions / lint

`../components/DeprecationNotice` import should occur before import of `./Status.stories`

<Meta of={StatusStories} />

# Status

<DeprecationNotice href="/?path=/docs/stories/Badge">Badge</DeprecationNotice>

Status are used to give an important visual indication to the users on a page level.

**Best practices**
Expand Down
26 changes: 23 additions & 3 deletions packages/design-system/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,55 @@
import { css, styled } from 'styled-components';
import { css, styled, DefaultTheme } from 'styled-components';

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

type BadgeSize = 'S' | 'M';

type BadgeVariant = 'success' | 'primary' | 'danger' | 'warning' | 'neutral' | 'secondary' | 'alternative';

interface BadgeProps extends FlexProps {
/**
* If `true`, it changes the `backgroundColor` to `primary200` and the `textColor` to `primary600`
*/
active?: boolean;

backgroundColor?: DefaultThemeOrCSSProp<'colors', 'background'>;
/**
* @default 'M'
*/
size?: BadgeSize;

textColor?: DefaultThemeOrCSSProp<'colors', 'color'>;

/**
* @default 'neutral'
*/
variant?: BadgeVariant;
}

const Badge = ({
active = false,
size = 'M',
textColor = 'neutral600',
backgroundColor = 'neutral150',
variant,
children,
minWidth = 5,
...props
}: BadgeProps) => {
const paddingX = size === 'S' ? 1 : 2;

const overridedColors = variant
? {
backgroundColor: `${variant}200` satisfies keyof DefaultTheme['colors'],
textColor: `${variant}700` satisfies keyof DefaultTheme['colors'],
}
: {
backgroundColor,
textColor,
};

return (
<Base
inline
Expand All @@ -38,11 +58,11 @@ const Badge = ({
minWidth={minWidth}
paddingLeft={paddingX}
paddingRight={paddingX}
background={active ? 'primary200' : backgroundColor}
background={active ? 'primary200' : overridedColors.backgroundColor}
$size={size}
{...props}
>
<Typography variant="sigma" textColor={active ? 'primary600' : textColor} lineHeight="1rem">
<Typography variant="sigma" textColor={active ? 'primary600' : overridedColors.textColor} lineHeight="1rem">
{children}
</Typography>
</Base>
Expand Down
Loading