File tree Expand file tree Collapse file tree 7 files changed +120
-0
lines changed
Expand file tree Collapse file tree 7 files changed +120
-0
lines changed Original file line number Diff line number Diff line change 1+ @use ' variables' as * ;
2+ @use ' functions' as * ;
3+
4+ .ids-badge {
5+ display : flex ;
6+ align-items : center ;
7+ justify-content : center ;
8+ min-width : $badge-size-medium ;
9+ height : $badge-size-medium ;
10+ border-radius : $badge-size-medium ;
11+ background : $color-error-80 ;
12+ opacity : 1 ;
13+ cursor : pointer ;
14+ color : $color-neutral-10 ;
15+ font-size : $text-font-size-xs ;
16+ transition : all 0.2s ease-in-out ;
17+
18+ & --small {
19+ min-width : $badge-size-small ;
20+ height : $badge-size-small ;
21+ border-radius : $badge-size-small ;
22+ }
23+
24+ & --expanded {
25+ padding : 0 calculateRem (3px );
26+ }
27+ }
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 1515@use ' input' ;
1616@use ' inputs-list' ;
1717@use ' label' ;
18+ @use ' badge' ;
1819
1920@use ' inputs/checkbox' ;
2021@use ' inputs/input-text' ;
Original file line number Diff line number Diff line change 1+ import type { Meta , StoryObj } from '@storybook/react' ;
2+
3+ import { BADGE_SIZE_VALUES } from './Badge.types' ;
4+ import Badge from './Badge' ;
5+
6+ const meta : Meta < typeof Badge > = {
7+ component : Badge ,
8+ parameters : {
9+ layout : 'centered' ,
10+ } ,
11+ tags : [ 'autodocs' ] ,
12+ argTypes : {
13+ value : {
14+ control : 'number' ,
15+ } ,
16+ className : {
17+ control : 'text' ,
18+ } ,
19+ size : {
20+ control : 'select' ,
21+ options : BADGE_SIZE_VALUES ,
22+ } ,
23+ } ,
24+ } ;
25+
26+ export default meta ;
27+
28+ type Story = StoryObj < typeof Badge > ;
29+
30+ export const Default : Story = {
31+ name : 'Default' ,
32+ args : {
33+ value : 1 ,
34+ size : 'medium' ,
35+ } ,
36+ } ;
37+
38+ export const Small : Story = {
39+ name : 'Small' ,
40+ args : {
41+ value : 1 ,
42+ size : 'small' ,
43+ } ,
44+ } ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames' ;
4+
5+ import type { BadgeProps } from './Badge.types' ;
6+
7+ const MAX_BADGE_VALUE = 99 ;
8+
9+ const formatBadgeValue = ( value : number ) : string => {
10+ return value > MAX_BADGE_VALUE ? '99+' : value . toString ( ) ;
11+ } ;
12+
13+ const Badge = ( { value, size = 'medium' , className = '' } : BadgeProps ) => {
14+ const isExpanded = value > MAX_BADGE_VALUE ;
15+
16+ const componentClassName = createCssClassNames ( {
17+ 'ids-badge' : true ,
18+ [ `ids-badge--${ size } ` ] : true ,
19+ 'ids-badge--expanded' : isExpanded ,
20+ [ className ] : ! ! className ,
21+ } ) ;
22+
23+ return (
24+ < div className = { componentClassName } >
25+ { formatBadgeValue ( value ) }
26+ </ div >
27+ ) ;
28+ } ;
29+
30+ export default Badge ;
Original file line number Diff line number Diff line change 1+ import { BaseComponentAttributes } from '@ids-types/general' ;
2+
3+ export const BADGE_SIZE_VALUES = [ 'medium' , 'small' ] as const ;
4+
5+ export type BadgeSizeType = ( typeof BADGE_SIZE_VALUES ) [ number ] ;
6+
7+ export interface BadgeProps extends BaseComponentAttributes {
8+ value : number ;
9+ size ?: BadgeSizeType ;
10+ }
Original file line number Diff line number Diff line change 1+ import Badge from './Badge' ;
2+ import { BadgeProps } from './Badge.types' ;
3+
4+ export default Badge ;
5+ export type { BadgeProps } ;
You can’t perform that action at this time.
0 commit comments