-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBadge.tsx
More file actions
27 lines (22 loc) · 878 Bytes
/
Badge.tsx
File metadata and controls
27 lines (22 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import React from 'react';
import { createCssClassNames } from '@ibexa/ids-core/helpers/cssClassNames';
import { BadgeProps, BadgeSize } from './Badge.types';
const MAX_BADGE_VALUE = 99;
const THRESHOLD = {
[BadgeSize.Medium]: 100,
[BadgeSize.Small]: 10,
};
const Badge = ({ className = '', size = BadgeSize.Medium, value }: BadgeProps) => {
const isStretched = value >= THRESHOLD[size];
const componentClassName = createCssClassNames({
'ids-badge': true,
[`ids-badge--${size}`]: true,
'ids-badge--stretched': isStretched,
[className]: !!className,
});
const formatBadgeValue = (badgeValue: number): string => {
return badgeValue > MAX_BADGE_VALUE ? `${MAX_BADGE_VALUE}+` : badgeValue.toString();
};
return <div className={componentClassName}>{formatBadgeValue(value)}</div>;
};
export default Badge;