-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7146b40
commit ceda6e0
Showing
6 changed files
with
173 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
@layer components { | ||
.mui-badge { | ||
@apply relative inline-flex align-middle flex-shrink-0; | ||
} | ||
|
||
.mui-badge-content { | ||
@apply absolute z-10 pointer-events-none select-none flex flex-row flex-wrap items-center justify-center text-center text-white bg-mui-placeholder-color; | ||
|
||
transform-origin: 100% 0%; | ||
|
||
&.mui-badge-placement-top-right { | ||
@apply top-0 right-0; | ||
transform: translate(50%, -50%); | ||
} | ||
|
||
&.mui-badge-placement-bottom-right { | ||
@apply bottom-0 right-0; | ||
transform: translate(50%, 50%); | ||
} | ||
|
||
&.mui-badge-placement-bottom-left { | ||
@apply bottom-0 left-0; | ||
transform: translate(-50%, 50%); | ||
} | ||
|
||
&.mui-badge-placement-top-left { | ||
@apply top-0 left-0; | ||
transform: translate(-50%, -50%); | ||
} | ||
|
||
&.pulse { | ||
&::before { | ||
@apply animate-ping opacity-75 bg-mui-placeholder-color absolute inset-0 rounded-full; | ||
z-index: -1; | ||
|
||
/* Displays the before pseudoelement */ | ||
content: ''; | ||
} | ||
} | ||
} | ||
|
||
.mui-badge-default { | ||
@apply mui-badge-content h-5 min-w-5 text-xs; | ||
|
||
padding: 0 6px; | ||
border-radius: 10px; | ||
} | ||
|
||
.mui-badge-mini { | ||
@apply mui-badge-content; | ||
height: 14px; | ||
min-width: 14px; | ||
|
||
/* Styles the text */ | ||
font-size: 0.65rem; | ||
line-height: 0.8rem; | ||
|
||
padding: 0 3px; | ||
border-radius: 10px; | ||
} | ||
|
||
.mui-badge-dot { | ||
@apply mui-badge-content h-2 min-w-2 p-0; | ||
|
||
border-radius: 4px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import React, { useMemo } from 'react'; | ||
import classnames from 'classnames'; | ||
|
||
const variantClassnameMap = { | ||
default: 'mui-badge-default', | ||
mini: 'mui-badge-mini', | ||
dot: 'mui-badge-dot' | ||
}; | ||
|
||
const placementClassnameMap = { | ||
['top-right']: 'mui-badge-placement-top-right', | ||
['bottom-right']: 'mui-badge-placement-bottom-right', | ||
['top-left']: 'mui-badge-placement-top-left', | ||
['bottom-left']: 'mui-badge-placement-bottom-left' | ||
}; | ||
|
||
export type BadgeProps = { | ||
/** | ||
* The badge display number or text | ||
*/ | ||
content?: number | string; | ||
/** | ||
* The maximum number until the badge will add a "+" sign, only taken into consideration if `content` is of type number | ||
* | ||
* @default 9 | ||
*/ | ||
maxValue?: number; | ||
/** | ||
* Whether or not the badge should have a pulsing effect | ||
*/ | ||
pulse?: boolean; | ||
/** | ||
* The badge variant | ||
* | ||
* @default default | ||
*/ | ||
variant?: keyof typeof variantClassnameMap; | ||
/** | ||
* The badge placement | ||
* | ||
* @default top-right | ||
*/ | ||
placement?: keyof typeof placementClassnameMap; | ||
}; | ||
|
||
/** | ||
* A badge | ||
* | ||
* @param props the component props | ||
* @param props.content The badge display number or text | ||
* @param props.maxValue The maximum number until the badge will add a "+" sign, only taken into consideration if `content` is of type number | ||
* @param props.pulse Whether or not the badge should have a pulsing effect | ||
* @param props.variant The badge variant | ||
* @param props.placement The bagge placement | ||
* @param props.children the provided children | ||
*/ | ||
export const Badge: React.FC<BadgeProps> = ({ | ||
content: propsContent, | ||
maxValue = 9, | ||
pulse, | ||
variant = 'default', | ||
placement = 'top-right', | ||
children | ||
}) => { | ||
const content = useMemo( | ||
() => | ||
typeof propsContent === 'number' ? (propsContent > maxValue ? `${maxValue}+` : `${propsContent}`) : propsContent, | ||
[propsContent, maxValue] | ||
); | ||
|
||
return ( | ||
<div className="mui-badge"> | ||
{children} | ||
{content && ( | ||
<span className={classnames(variantClassnameMap[variant], placementClassnameMap[placement], { pulse })}> | ||
{variant !== 'dot' && content} | ||
</span> | ||
)} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
@import './Modal'; | ||
@import './Tooltip'; | ||
@import './Dropdown'; | ||
@import './Badge'; |