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(Badge): deprecate some props and new UpdateBadge and StatusBadge components #1258

Merged
merged 5 commits into from
Jul 29, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { StoryDescriptor } from '../../stories/components/StoryDescriptor';
import { Badge, BadgeProps } from './Badge';

export default {
title: 'Components/Badge',
title: 'Components/Badge/Badge',
component: Badge,
};

Expand All @@ -28,7 +28,7 @@ export const Sizes = (): React.ReactElement => (
<StoryDescriptor title="Medium">
<Badge size="medium" count={1} />
</StoryDescriptor>
<StoryDescriptor title="Large">
<StoryDescriptor title="Large (deprecated)">
<Badge size="large" count={1} />
</StoryDescriptor>
</>
Expand All @@ -39,7 +39,7 @@ export const Kinds = (): React.ReactElement => (
<StoryDescriptor title="Primary">
<Badge kind="primary" count={1} />
</StoryDescriptor>
<StoryDescriptor title="Secondary">
<StoryDescriptor title="Secondary (Deprecated)">
<Badge kind="secondary" count={1} />
</StoryDescriptor>
<StoryDescriptor title="Tertiary">
Expand All @@ -64,7 +64,7 @@ export const Types = (): React.ReactElement => (
<StoryDescriptor title="Alert">
<Badge type="alert" />
</StoryDescriptor>
<StoryDescriptor title="Dot">
<StoryDescriptor title="Dot (Deprecated)">
<Badge type="dot" />
</StoryDescriptor>
</>
Expand Down
3 changes: 3 additions & 0 deletions packages/react-components/src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
count?: number;
/**
* Specify the badge kind
* @param secondary - is deprecated, use "primary" or "tertiary" instead
*/
kind?: 'primary' | 'secondary' | 'tertiary';
/**
Expand All @@ -23,10 +24,12 @@ export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
max?: number;
/**
* Specify the badge size
* @param large - is deprecated, use "medium" or "compact" instead
*/
size?: 'large' | 'medium' | 'compact';
/**
* Specify the badge type
* @param dot - is deprecated, use "UpdateBadge" component instead
*/
type?: 'counter' | 'alert' | 'dot';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$base-class: 'status-badge';

@mixin size($size, $border-size) {
border-width: $border-size;
border-radius: $size;
width: $size;
height: $size;
}

.#{$base-class} {
box-sizing: content-box;
display: flex;
border-style: solid;
border-color: var(--surface-primary-default);

&--3XS {
@include size(4px, 1px);
}

&--2XS {
@include size(5px, 1px);
}

&--XS {
@include size(6px, 1px);
}

&--SM {
@include size(8px, 1px);
}

&--MD {
@include size(9px, 2px);
}

&--LG {
@include size(10px, 2px);
}

&--XL {
@include size(12px, 2px);
}

&--2XL {
@include size(16px, 2px);
}

&--3XL {
@include size(24px, 3px);
}

&--offline {
background-color: var(--content-basic-disabled);
}

&--accept {
background-color: var(--surface-accent-emphasis-high-positive);
}

&--not-accept {
background-color: var(--surface-accent-emphasis-high-negative);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as React from 'react';

import { StoryDescriptor } from '../../stories/components/StoryDescriptor';

import {
IStatusBadgeProps,
StatusBadge,
StatusBadgeSizes,
} from './StatusBadge';

export default {
title: 'Components/Badge/StatusBadge',
component: StatusBadge,
};

const SIZES: StatusBadgeSizes[] = [
'3XS',
'2XS',
'XS',
'SM',
'MD',
'LG',
'XL',
'2XL',
'3XL',
];

export const Default = (args: IStatusBadgeProps): React.ReactElement => (
<StatusBadge {...args} />
);

export const KindsAndSizes = (): React.ReactElement => (
<>
{SIZES.map((size) => (
<StoryDescriptor title={`${size}`}>
<StatusBadge size={size} kind="accept" />
<StatusBadge size={size} kind="not-accept" />
<StatusBadge size={size} kind="offline" />
</StoryDescriptor>
))}
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as React from 'react';

import cx from 'clsx';

import styles from './StatusBadge.module.scss';

const baseClass = 'status-badge';

export type StatusBadgeSizes =
| '3XS'
| '2XS'
| 'XS'
| 'SM'
| 'MD'
| 'LG'
| 'XL'
| '2XL'
| '3XL';

export interface IStatusBadgeProps
extends React.HTMLAttributes<HTMLSpanElement> {
/**
* Specify the status badge kind
*/
kind?: 'offline' | 'accept' | 'not-accept';
/**
* Specify the status badge size
*/
size?: StatusBadgeSizes;
}

export const StatusBadge: React.FC<IStatusBadgeProps> = ({
className,
kind = 'offline',
size = 'MD',
...spanProps
}) => {
const mergedClassNames = cx(
styles[baseClass],
styles[`${baseClass}--${kind}`],
styles[`${baseClass}--${size}`],
className
);

return <span className={mergedClassNames} {...spanProps} />;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { StatusBadge } from './StatusBadge';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$base-class: 'update-badge';
$size: 9px;

.#{$base-class} {
display: flex;
align-items: center;
justify-content: center;
border-radius: $size;
box-shadow: inset 0 0 0 3.25px var(--surface-accent-emphasis-high-negative);
background-color: var(--content-locked-white);
width: $size;
height: $size;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import * as React from 'react';

import { UpdateBadge } from './UpdateBadge';

export default {
title: 'Components/Badge/UpdateBadge',
component: UpdateBadge,
};

export const Default = (): React.ReactElement => <UpdateBadge />;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from 'react';

import styles from './UpdateBadge.module.scss';

const baseClass = 'update-badge';

export const UpdateBadge: React.FC = () => (
<span className={styles[baseClass]} />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { UpdateBadge } from './UpdateBadge';
2 changes: 2 additions & 0 deletions packages/react-components/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export * from './components/PromoBannerV2';
export * from './components/RadioButton';
export * from './components/Search';
export * from './components/Skeleton';
export * from './components/StatusBadge';
export * from './components/Switch';
export * from './components/Tab';
export * from './components/Tag';
Expand All @@ -46,5 +47,6 @@ export * from './components/Toast';
export * from './components/Tooltip';
export * from './components/Typography';
export * from './components/Textarea';
export * from './components/UpdateBadge';
export * from './components/FileUploadProgress';
export * from './components/UploadBar';
Loading