-
Notifications
You must be signed in to change notification settings - Fork 44
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
👨 CRT header widget #4693
Merged
Merged
👨 CRT header widget #4693
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0af361d
Component
WRadoslaw c34dbf7
Story
WRadoslaw 8746e33
Correct styling
WRadoslaw 0b6301d
CR fixes
WRadoslaw 154b870
Merge branch 'crt' into feature/widget
WRadoslaw cc77db7
Conflict fixes
WRadoslaw 4c4d89c
Replace useRef
WRadoslaw 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
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, useRef } 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 = useRef<HTMLSpanElement | null>(null) | ||
const smMatch = useMediaMatch('sm') | ||
|
||
return ( | ||
<WidgetTile | ||
title={`$${name || 'ABC'}`} | ||
title={<span ref={titleRef}>${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' |
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.
Somehow the tooltip doesn't to show for me. Why not just:
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.
It's just because I used ref and the component does not rerender after it's set. The
title
attribute imo is too slow, especially since all of our tooltips appear almost instantly.Replace useRef for useState