Skip to content
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

feat: add new Badge sizes #210

Merged
merged 1 commit into from
Oct 12, 2023
Merged
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
34 changes: 27 additions & 7 deletions system/core/src/components/Badge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@ export const baseStyles = css`
font: var(--label);
display: grid;
grid-auto-flow: column;
grid-gap: var(--spacing-l1);
gap: var(--spacing-l1);
align-items: center;
padding: 6px var(--spacing-l2);
border-radius: var(--border-radius-small);
color: var(--neutral-text);
background-color: var(--neutral-surface);

&[data-size='x-small'] {
padding: 2px 6px;
font-size: 12px;
line-height: 16px;
}
&[data-size='small'] {
padding: 4px 6px;
font-size: 12px;
line-height: 16px;
}
&[data-size='large'] {
padding: 10px 10px;
gap: 6px;
}
&[data-size='x-large'] {
padding: 14px 10px;
gap: 6px;
}
`;

export interface Props {
'data-variant'?: BadgeVariant;
'data-size'?: 'small';
'data-size'?: 'x-small' | 'small' | 'medium' | 'large' | 'x-large';
}

const variants = [
Expand All @@ -34,18 +47,25 @@ const variants = [
'error',
'neutral',
'purple',
'orange'
'orange',
'disabled'
] as const;

export type BadgeVariant = (typeof variants)[number];

export const variantStyles = variants.reduce(
(result, key) => ({
...result,
[key]: css`
color: var(--${key}-text);
background-color: var(--${key}-surface);
`
[key]:
key === 'disabled'
? css`
color: var(--text-disabled);
background-color: var(--surface-disabled);
`
: css`
color: var(--${key}-text);
background-color: var(--${key}-surface);
`
}),
{} as Record<BadgeVariant, SerializedStyles>
);
6 changes: 3 additions & 3 deletions system/stories/src/Badge.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ export default {

const Template: Story = ({ Badge }) => (
<>
{[undefined, 'small'].map((size) =>
{(['x-large', 'large', 'medium', 'small', 'x-small'] as const).map((size) =>
['left', 'right', false].map((hasIcon) =>
variants.map((variant) => (
<Badge key={variant} data-variant={variant} data-size={size as any}>
<Badge key={variant} data-variant={variant} data-size={size}>
{hasIcon === 'left' ? (
<FavoriteFilled size={size ? 16 : 20} />
) : null}
Text
{size}
{hasIcon === 'right' ? (
<FavoriteFilled size={size ? 16 : 20} />
) : null}
Expand Down