forked from Joystream/atlas
-
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.
👨 CRT header widget (Joystream#4693)
* Component * Story * Correct styling * CR fixes * Conflict fixes * Replace useRef
- Loading branch information
Showing
5 changed files
with
82 additions
and
47 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
43 changes: 43 additions & 0 deletions
43
packages/atlas/src/components/_crt/CrtBasicInfoWidget/CrtBasicInfoWidget.stories.tsx
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,43 @@ | ||
import { Meta, StoryFn } from '@storybook/react' | ||
|
||
import { JoyTokenIcon } from '@/components/JoyTokenIcon' | ||
import { CrtBasicInfoWidget, CrtBasicInfoWidgetProps } from '@/components/_crt/CrtBasicInfoWidget/CrtBasicInfoWidget' | ||
import { JoystreamProvider } from '@/providers/joystream/joystream.provider' | ||
|
||
export default { | ||
title: 'crt/CrtBasicInfoWidget', | ||
component: CrtBasicInfoWidget, | ||
decorators: [ | ||
(Story) => ( | ||
<JoystreamProvider> | ||
<Story /> | ||
</JoystreamProvider> | ||
), | ||
], | ||
} as Meta<CrtBasicInfoWidgetProps> | ||
|
||
const Template: StoryFn<CrtBasicInfoWidgetProps> = (args) => <CrtBasicInfoWidget {...args} /> | ||
|
||
export const Default = Template.bind({}) | ||
Default.args = { | ||
name: 'CRT', | ||
details: [ | ||
{ | ||
caption: 'TOTAL REV.', | ||
content: 65656, | ||
icon: <JoyTokenIcon size={16} variant="silver" />, | ||
tooltipText: 'Lorem ipsum', | ||
}, | ||
{ | ||
caption: 'REV. SHARE', | ||
content: '80%', | ||
tooltipText: 'Lorem ipsum', | ||
}, | ||
{ | ||
caption: 'AN. REWARD', | ||
content: '20%', | ||
icon: <JoyTokenIcon size={16} variant="silver" />, | ||
tooltipText: 'Lorem ipsum', | ||
}, | ||
], | ||
} |
65 changes: 23 additions & 42 deletions
65
packages/atlas/src/components/_crt/CrtBasicInfoWidget/CrtBasicInfoWidget.tsx
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,64 +1,45 @@ | ||
import styled from '@emotion/styled' | ||
import { ReactElement, ReactNode, useState } from 'react' | ||
|
||
import { JoyTokenIcon } from '@/components/JoyTokenIcon' | ||
import { FlexBox } from '@/components/FlexBox' | ||
import { Color } from '@/components/Text/Text.styles' | ||
import { Tooltip } from '@/components/Tooltip' | ||
import { WidgetTile } from '@/components/WidgetTile' | ||
import { DetailsContent } from '@/components/_nft/NftTile' | ||
import { useMediaMatch } from '@/hooks/useMediaMatch' | ||
import { sizes } from '@/styles' | ||
|
||
type CrtBasicInfoWidgetProps = { | ||
export type CrtBasicInfoWidgetProps = { | ||
name?: string | ||
totalRevenue?: string | ||
revenueShare?: number | ||
creatorReward?: number | ||
titleColor?: Color | ||
details: { | ||
caption: string | ||
content: number | string | ReactElement | ReactElement[] | ||
icon?: ReactNode | ||
tooltipText?: string | ||
}[] | ||
} | ||
|
||
export const CrtBasicInfoWidget = ({ creatorReward, revenueShare, totalRevenue, name }: CrtBasicInfoWidgetProps) => { | ||
export const CrtBasicInfoWidget = ({ name, details, titleColor }: CrtBasicInfoWidgetProps) => { | ||
const [titleRef, setTitleRef] = useState<HTMLSpanElement | null>(null) | ||
const smMatch = useMediaMatch('sm') | ||
|
||
return ( | ||
<WidgetTile | ||
title={`$${name || 'ABC'}`} | ||
title={<span ref={setTitleRef}>${name ?? 'ABC'}</span>} | ||
titleVariant="h700" | ||
titleColor={titleColor ?? 'colorTextStrong'} | ||
customNode={ | ||
<DetailsBox> | ||
{totalRevenue && ( | ||
<DetailsContent | ||
avoidIconStyling | ||
tileSize={smMatch ? 'big' : 'bigSmall'} | ||
caption="TOTAL REVENUE" | ||
content={totalRevenue} | ||
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />} | ||
withDenomination | ||
/> | ||
)} | ||
{revenueShare && ( | ||
<FlexBox gap={5}> | ||
<Tooltip reference={titleRef} text="Token name" placement="top-start" /> | ||
{details.map((detail, idx) => ( | ||
<DetailsContent | ||
{...detail} | ||
key={idx} | ||
avoidIconStyling | ||
tileSize={smMatch ? 'big' : 'bigSmall'} | ||
caption="REVENUE SHARE" | ||
content={`${revenueShare}%`} | ||
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />} | ||
withDenomination | ||
/> | ||
)} | ||
{creatorReward && ( | ||
<DetailsContent | ||
avoidIconStyling | ||
tileSize={smMatch ? 'big' : 'bigSmall'} | ||
caption="CREATOR REWARD" | ||
content={`${creatorReward}%`} | ||
icon={<JoyTokenIcon size={smMatch ? 24 : 16} variant="silver" />} | ||
withDenomination | ||
/> | ||
)} | ||
</DetailsBox> | ||
))} | ||
</FlexBox> | ||
} | ||
/> | ||
) | ||
} | ||
|
||
const DetailsBox = styled.div` | ||
display: flex; | ||
gap: ${sizes(4)}; | ||
` |
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 @@ | ||
export * from './CrtBasicInfoWidget' |