-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add new rarity badge * fix: Wrap the badge with a background
- Loading branch information
1 parent
edbae59
commit e7808e1
Showing
15 changed files
with
255 additions
and
62 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
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
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,27 @@ | ||
.dui-rarity-badge { | ||
display: inline-flex; | ||
align-items: center; | ||
text-transform: uppercase; | ||
border-radius: 5px; | ||
width: fit-content; | ||
background-color: var(--background); | ||
} | ||
|
||
.dui-rarity-badge .wrapper { | ||
border-radius: 5px; | ||
} | ||
|
||
.dui-rarity-badge .wrapper.medium { | ||
padding: 4px 12px; | ||
} | ||
.dui-rarity-badge .wrapper.medium .text { | ||
font-size: 15px; | ||
} | ||
|
||
.dui-rarity-badge .wrapper.small { | ||
padding: 3px 6px; | ||
height: 24px; | ||
} | ||
.dui-rarity-badge .wrapper.small .text { | ||
font-size: 13px; | ||
} |
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,5 @@ | ||
.dui-rarity-badge-story-wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
} |
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,47 @@ | ||
import React from 'react' | ||
import { Rarity } from '@dcl/schemas' | ||
import { storiesOf } from '@storybook/react' | ||
import RarityBadge from './RarityBadge' | ||
import './RarityBadge.stories.css' | ||
|
||
const i18n = { | ||
rarities: Rarity.getRarities().reduce((acc, rarity) => { | ||
acc[rarity as string] = rarity | ||
return acc | ||
}, {}) as unknown as Record<Rarity, string>, | ||
rarities_description: Rarity.getRarities().reduce((acc, rarity) => { | ||
acc[rarity as string] = `This is the ${rarity} rarity` | ||
return acc | ||
}, {}) as unknown as Record<Rarity, string> | ||
} | ||
|
||
storiesOf('RarityBadge', module) | ||
.add('Small size badges', () => { | ||
return ( | ||
<div className="dui-rarity-badge-story-wrapper"> | ||
{Rarity.getRarities().map((rarity) => ( | ||
<RarityBadge | ||
key={rarity} | ||
i18n={i18n} | ||
rarity={rarity} | ||
size="small" | ||
onClick={() => alert(`Clicked ${rarity}!`)} | ||
/> | ||
))} | ||
</div> | ||
) | ||
}) | ||
.add('Medium size badges', () => { | ||
return ( | ||
<div className="dui-rarity-badge-story-wrapper"> | ||
{Rarity.getRarities().map((rarity) => ( | ||
<RarityBadge | ||
key={rarity} | ||
i18n={i18n} | ||
rarity={rarity} | ||
onClick={() => alert(`Clicked ${rarity}!`)} | ||
/> | ||
))} | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React from 'react' | ||
import classnames from 'classnames' | ||
import { Rarity } from '@dcl/schemas' | ||
import { hex2rgb } from '../../lib/colors' | ||
import { Popup } from '../Popup/Popup' | ||
import { RarityBadgeProps } from './RarityBadge.types' | ||
import './RarityBadge.css' | ||
|
||
const RarityBadge = ({ | ||
rarity, | ||
className, | ||
size, | ||
withTooltip, | ||
i18n, | ||
onClick | ||
}: RarityBadgeProps) => { | ||
const [lightColor, regularColor] = Rarity.getGradient(rarity) | ||
const hexColor = hex2rgb(regularColor) | ||
|
||
const trigger = ( | ||
<div | ||
className={classnames('dui-rarity-badge', className)} | ||
style={{ | ||
cursor: onClick ? 'pointer' : 'default' | ||
}} | ||
title={!withTooltip ? i18n.rarities_description[rarity] : ''} | ||
onClick={onClick} | ||
> | ||
<div | ||
className={classnames('wrapper', size)} | ||
style={{ | ||
backgroundColor: `rgb(${hexColor.r} ${hexColor.g} ${hexColor.b} / 20%)` | ||
}} | ||
> | ||
<span className="text" style={{ color: lightColor }}> | ||
{i18n.rarities[rarity]} | ||
</span> | ||
</div> | ||
</div> | ||
) | ||
|
||
return withTooltip ? ( | ||
<Popup | ||
position="top center" | ||
content={i18n.rarities_description[rarity]} | ||
trigger={trigger} | ||
/> | ||
) : ( | ||
trigger | ||
) | ||
} | ||
|
||
RarityBadge.defaultProps = { | ||
size: 'medium', | ||
withTooltip: true | ||
} | ||
|
||
export default React.memo(RarityBadge) |
Oops, something went wrong.