Skip to content

Commit 20e16a1

Browse files
committed
IBX-7880: Badge
1 parent 8a8a172 commit 20e16a1

File tree

7 files changed

+124
-0
lines changed

7 files changed

+124
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@use 'variables' as *;
2+
@use 'functions' as *;
3+
4+
.ids-badge {
5+
position: absolute;
6+
display: flex;
7+
align-items: center;
8+
justify-content: center;
9+
min-width: $badge-size-medium;
10+
height: $badge-size-medium;
11+
border-radius: $badge-size-medium;
12+
background: $color-error-80;
13+
opacity: 1;
14+
cursor: pointer;
15+
color: $color-neutral-10;
16+
font-size: $text-font-size-xs;
17+
transition: all 0.2s ease-in-out;
18+
font-size: $text-font-size-xs;
19+
20+
&--small {
21+
min-width: $badge-size-small;
22+
height: $badge-size-small;
23+
border-radius: $badge-size-small;
24+
}
25+
26+
&--expanded {
27+
padding: 0 calculateRem(3px);
28+
}
29+
}

packages/assets/src/scss/_variables.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,7 @@ $base-line-height: 1.5 !default;
1515
$border-radius-medium: calculateRem(8px) !default;
1616
$border-radius-large: calculateRem(12px) !default;
1717

18+
$badge-size-small: calculateRem(12px) !default;
19+
$badge-size-medium: calculateRem(18px) !default;
20+
1821
$assets-base-path: '/' !default;

packages/assets/src/scss/styles.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
@use 'input';
1111
@use 'label';
1212
@use 'helper-text';
13+
@use 'badge';
1314

1415
@use 'inputs/input-text';
1516

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
3+
import Badge from './Badge';
4+
5+
const meta: Meta<typeof Badge> = {
6+
component: Badge,
7+
parameters: {
8+
layout: 'centered',
9+
},
10+
tags: ['autodocs'],
11+
argTypes: {
12+
className: {
13+
control: 'text',
14+
},
15+
title: {
16+
control: 'text',
17+
},
18+
},
19+
};
20+
21+
export default meta;
22+
23+
type Story = StoryObj<typeof Badge>;
24+
25+
export const Default: Story = {
26+
name: 'Default',
27+
args: {
28+
children: '1',
29+
size: 'medium',
30+
},
31+
};
32+
33+
export const Small: Story = {
34+
name: 'Small',
35+
args: {
36+
children: '1',
37+
size: 'small',
38+
},
39+
};
40+
41+
export const LongContent: Story = {
42+
name: 'LongContent',
43+
args: {
44+
children: '99+',
45+
size: 'medium',
46+
},
47+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react';
2+
3+
import { createCssClassNames } from '@ids-internal/shared/css.class.names';
4+
5+
import { BadgeProps } from './Badge.types';
6+
7+
const MAX_CIRCULAR_LENGTH = 2;
8+
9+
const Badge = ({ children, size = 'medium', className = '', title = '' }: BadgeProps) => {
10+
const content = typeof children === 'string' ? children : '';
11+
const isExpanded = content.length > MAX_CIRCULAR_LENGTH;
12+
13+
const componentClassName = createCssClassNames({
14+
'ids-badge': true,
15+
[`ids-badge--${size}`]: !!size,
16+
'ids-badge--expanded': isExpanded,
17+
[className]: !!className,
18+
});
19+
20+
return (
21+
<div className={componentClassName} title={title}>
22+
{children}
23+
</div>
24+
);
25+
};
26+
27+
export default Badge;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ReactNode } from 'react';
2+
3+
import { BaseComponentAttributes } from '@ids-types/general';
4+
5+
export const BADGE_SIZE_VALUES = ['medium', 'small'] as const;
6+
7+
export type BadgeSizeType = (typeof BADGE_SIZE_VALUES)[number];
8+
9+
export interface BadgeProps extends BaseComponentAttributes {
10+
children: ReactNode;
11+
size?: BadgeSizeType;
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Badge from './Badge';
2+
import { BadgeProps } from './Badge.types';
3+
4+
export default Badge;
5+
export type { BadgeProps };

0 commit comments

Comments
 (0)