-
Notifications
You must be signed in to change notification settings - Fork 21
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: CU-1n5w3vb add loading and variants to badge #167
Merged
giardiv
merged 2 commits into
logicalclocks:dev
from
snqb:CU-1n5w3vb_Badges-update-and-clean-code_Esen-Dzhailobaev
Dec 7, 2021
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { keyframes } from '@emotion/core'; | ||
|
||
const rotate = keyframes` | ||
to { | ||
transform: rotate(1turn); | ||
} | ||
`; | ||
|
||
const getBorderAnimation = (borderColor: string) => { | ||
return { | ||
border: 'none', | ||
display: 'inline-block', | ||
position: 'relative', | ||
zIndex: '0', | ||
width: 'auto', | ||
height: 'auto', | ||
overflow: 'hidden', | ||
padding: '3px 6px', | ||
fontFamily: 'arial', | ||
fontSize: '12px', | ||
fontWeight: '500', | ||
borderRadius: '1px', | ||
color: '#f2994a', | ||
':before': { | ||
content: "''", | ||
position: 'absolute', | ||
zIndex: '-2', | ||
left: '-150%', | ||
top: '-450%', | ||
width: '400%', | ||
height: '1000%', | ||
backgroundRepeat: 'no-repeat', | ||
backgroundSize: '50% 50%, 50% 50%', | ||
backgroundPosition: '0 0, 100% 0, 100% 100%, 0 100%', | ||
backgroundImage: `linear-gradient(${borderColor}, ${borderColor})`, | ||
animation: `${rotate} 4s linear infinite`, | ||
}, | ||
':after': { | ||
content: "''", | ||
position: 'absolute', | ||
zIndex: '-1', | ||
left: '1px', | ||
top: '1px', | ||
width: 'calc(100% - 2px)', | ||
height: 'calc(100% - 2px)', | ||
background: 'inherit', | ||
borderRadius: '1px', | ||
}, | ||
}; | ||
}; | ||
|
||
export default getBorderAnimation; |
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 |
---|---|---|
@@ -1,41 +1,103 @@ | ||
import React, { FC } from 'react'; | ||
import { useTheme } from 'emotion-theming'; | ||
import { Flex, FlexProps } from 'rebass'; | ||
|
||
// Components | ||
import { getIcon, IconName } from '../icon/list'; | ||
import Value from '../typography/value'; | ||
import getBorderAnimation from './animation'; | ||
import { ITheme } from '../../theme/types'; | ||
|
||
type Mode = 'default' | 'bordered'; | ||
type Variant = | ||
| 'light' | ||
| 'default' | ||
| 'label' | ||
| 'success' | ||
| 'warning' | ||
| 'notice' | ||
| 'fail'; | ||
|
||
export interface BadgeProps extends Omit<FlexProps, 'css'> { | ||
value: string | number; | ||
variant?: 'light' | 'bold' | 'fail' | 'warning' | 'success' | 'label' | 'border'; | ||
variant?: Variant; | ||
mode?: Mode; | ||
loading?: boolean; | ||
icon?: IconName; | ||
} | ||
|
||
// this is a workaround because styled-system does not support theme colors for `linear-gradient` | ||
const getBorderColor = (theme: ITheme, variant: Variant) => { | ||
switch (variant) { | ||
case 'light': | ||
return theme.colors.grayShade1; | ||
case 'default': | ||
return theme.colors.black; | ||
case 'label': | ||
return theme.colors.black; | ||
case 'success': | ||
return theme.colors.labels.green; | ||
case 'warning': | ||
return theme.colors.labels.orange; | ||
case 'notice': | ||
return theme.colors.labels.yellow; | ||
case 'fail': | ||
return theme.colors.labels.red; | ||
default: | ||
return theme.colors.black; | ||
} | ||
}; | ||
|
||
const THEME_PATH: Record<Mode, string> = { | ||
default: 'variants.badges.primary', | ||
bordered: 'variants.badges.bordered', | ||
}; | ||
|
||
const Badge: FC<BadgeProps> = ({ | ||
value, | ||
variant = 'light', | ||
mode = 'default', | ||
loading = false, | ||
icon, | ||
...props | ||
}: BadgeProps) => ( | ||
<Flex | ||
alignItems="center" | ||
justifyContent="center" | ||
px="7px" | ||
py="4px" | ||
{...props} | ||
sx={{ | ||
borderRadius: '2px', | ||
}} | ||
as="span" | ||
tx="variants.badges.primary" | ||
variant={variant} | ||
> | ||
<Value | ||
}: BadgeProps) => { | ||
const theme = useTheme<ITheme>(); | ||
|
||
const borderColor = getBorderColor(theme, variant); | ||
const borderStyle = loading | ||
? getBorderAnimation(borderColor) | ||
: { borderRadius: '1px' }; | ||
|
||
return ( | ||
<Flex | ||
as="span" | ||
lineHeight="13px" | ||
fontFamily="IBM Plex Mono" | ||
fontWeight="normal" | ||
alignItems="center" | ||
justifyContent="center" | ||
px="6px" | ||
height="19px" | ||
sx={borderStyle} | ||
variant={variant} | ||
tx={loading ? THEME_PATH.bordered : THEME_PATH[mode]} | ||
{...props} | ||
> | ||
{value} | ||
</Value> | ||
</Flex> | ||
); | ||
<Value | ||
as="span" | ||
display="flex" | ||
alignItems="center" | ||
lineHeight="13px" | ||
fontFamily="IBM Plex Mono" | ||
fontWeight="normal" | ||
sx={{ | ||
svg: { | ||
height: '13px', | ||
width: 'auto', | ||
marginLeft: '5px', | ||
}, | ||
}} | ||
> | ||
{value} | ||
{icon && getIcon(icon, 'currentColor')} | ||
</Value> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default Badge; |
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,66 @@ | ||
const variants = { | ||
default: { | ||
'> span': { | ||
color: 'black', | ||
}, | ||
|
||
bg: 'grayShade2', | ||
border: '1px solid', | ||
borderColor: 'black', | ||
}, | ||
fail: { | ||
'> span': { | ||
color: 'labels.red', | ||
}, | ||
|
||
bg: 'labels.redShade3', | ||
border: '1px solid', | ||
borderColor: 'labels.red', | ||
}, | ||
label: { | ||
'> span': { | ||
color: 'black', | ||
}, | ||
|
||
bg: 'white', | ||
border: '1px solid', | ||
borderColor: 'black', | ||
}, | ||
light: { | ||
'> span': { | ||
color: 'black', | ||
}, | ||
|
||
bg: 'grayShade3', | ||
border: '1px solid', | ||
borderColor: 'grayShade1', | ||
}, | ||
success: { | ||
'> span': { | ||
color: 'labels.green', | ||
}, | ||
|
||
bg: 'primaryShade2', | ||
border: '1px solid', | ||
borderColor: 'labels.green', | ||
}, | ||
warning: { | ||
'> span': { | ||
color: 'labels.orange', | ||
}, | ||
|
||
bg: 'labels.orangeShade3', | ||
border: '1px solid', | ||
borderColor: 'labels.orange', | ||
}, | ||
notice: { | ||
'> span': { | ||
color: 'black', | ||
}, | ||
bg: 'labels.yellowLight', | ||
border: '1px solid', | ||
borderColor: 'labels.yellow', | ||
}, | ||
}; | ||
|
||
export default variants; |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const variants = { | ||
bold: { | ||
default: { | ||
'> span': { | ||
color: 'white', | ||
color: 'grayShade3', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the base color was changed |
||
}, | ||
bg: 'gray', | ||
}, | ||
|
@@ -35,18 +35,16 @@ const variants = { | |
}, | ||
warning: { | ||
'> span': { | ||
color: 'black', | ||
color: 'grayShade3', | ||
}, | ||
|
||
bg: 'labels.yellow', | ||
bg: 'labels.orange', | ||
}, | ||
border: { | ||
notice: { | ||
'> span': { | ||
color: 'black', | ||
}, | ||
bg: 'grayShade3', | ||
border: '1px solid', | ||
borderColor: 'grayShade1', | ||
bg: 'labels.yellow', | ||
}, | ||
}; | ||
|
||
|
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 |
---|---|---|
|
@@ -69,7 +69,8 @@ const theme: ITheme = { | |
red: '#EB5757', | ||
orange: '#f2994a', | ||
purple: '#9B51E0', | ||
yellow: '#FFF066', | ||
yellow: '#FFE600', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this yellow was just wrong, see Figma |
||
yellowLight: '#FFF8B3', | ||
green: '#21B182', | ||
skyblue: '#56CCF2', | ||
blue: '#41B7DC', | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rebassjs/rebass#1059