Skip to content
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 7 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/atlas/src/components/WidgetTile/WidgetTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Information } from '../Information'

export type WidgetTileProps = {
loading?: boolean
title: string | number
title: string | number | JSX.Element
button?: { text: string } & Omit<ButtonProps, 'children'>
text?: string | number
customNode?: ReactNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
LeftPlaceholder,
WidgetPreviewContainer,
} from '@/components/_crt/CreateTokenDrawer/steps/styles'
import { CrtBasicInfoWidget } from '@/components/_crt/CrtBasicInfoWidget'
import { CrtFormWrapper } from '@/components/_crt/CrtFormWrapper'
import { FormField } from '@/components/_inputs/FormField'
import { Input } from '@/components/_inputs/Input'
Expand All @@ -18,8 +19,6 @@ import { useMountEffect } from '@/hooks/useMountEffect'

import { CommonStepProps } from './types'

import { CrtBasicInfoWidget } from '../../CrtBasicInfoWidget/CrtBasicInfoWidget'

const accessOptions = [
{
label: 'Anyone',
Expand Down Expand Up @@ -65,8 +64,19 @@ export const SetupTokenStep = ({ setPrimaryButtonProps, onSubmit, form, setPrevi
<LeftPlaceholder />
<CrtBasicInfoWidget
name={watchedForm.name}
creatorReward={watchedForm.creatorReward}
revenueShare={watchedForm.revenueShare}
titleColor="colorText"
details={[
{
caption: 'REVENUE SHARE',
content: `${watchedForm.revenueShare}%`,
tooltipText: 'Lorem ipsum',
},
{
caption: 'CREATOR REWARD',
content: `${watchedForm.creatorReward}%`,
tooltipText: 'Lorem ipsum',
},
]}
/>
<BottomPlaceholder>
<svg xmlns="http://www.w3.org/2000/svg" width="371" height="163" viewBox="0 0 371 163" fill="none">
Expand Down
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',
},
],
}
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"
Copy link
Member

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:

Suggested change
title={<span ref={titleRef}>${name ?? 'ABC'}</span>}
title={<span title="Token name">${name ?? 'ABC'}</span>}

Copy link
Contributor Author

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

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)};
`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './CrtBasicInfoWidget'
Loading