forked from nervosnetwork/ckb-explorer-frontend
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement stories for EllipsisMiddle and AddressText
- Loading branch information
1 parent
a8458be
commit 531da8f
Showing
8 changed files
with
164 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.border { | ||
border: 1px solid #000; | ||
box-sizing: content-box; | ||
} |
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,63 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import AddressText from '.' | ||
import styles from './index.stories.module.scss' | ||
import { useForkedState } from '../../utils/hook' | ||
|
||
const meta = { | ||
component: AddressText, | ||
argTypes: { | ||
children: { | ||
// In React 17, `FC<P>` is wrapped in `PropsWithChildren<P>`, causing the type of `children` to be unrecognizable by Storybook. | ||
description: 'This item will be used as text when text is empty.', | ||
type: 'string', | ||
}, | ||
}, | ||
} satisfies Meta<typeof AddressText> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
const addressHash = 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqflz4emgssc6nqj4yv3nfv2sca7g9dzhscgmg28x' | ||
|
||
export const Primary: Story = { | ||
parameters: { | ||
viewport: { | ||
defaultViewport: 'mobile2', | ||
}, | ||
}, | ||
args: { | ||
children: addressHash, | ||
}, | ||
} | ||
|
||
export const UseTextWidthForPlaceholderWidth: Story = { | ||
parameters: { | ||
viewport: { | ||
defaultViewport: 'tablet', | ||
}, | ||
}, | ||
args: { | ||
children: addressHash, | ||
useTextWidthForPlaceholderWidth: true, | ||
className: styles.border, | ||
}, | ||
render: function Render(args) { | ||
const [useTextWidthForPlaceholderWidth, setUseTextWidthForPlaceholderWidth] = useForkedState( | ||
args.useTextWidthForPlaceholderWidth, | ||
) | ||
|
||
return ( | ||
<div> | ||
<AddressText {...args} useTextWidthForPlaceholderWidth={useTextWidthForPlaceholderWidth} /> | ||
<button | ||
type="button" | ||
onClick={() => setUseTextWidthForPlaceholderWidth(value => !value)} | ||
style={{ marginTop: 16 }} | ||
> | ||
toggle useTextWidthForPlaceholderWidth | ||
</button> | ||
</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,80 @@ | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
|
||
import EllipsisMiddle from '.' | ||
import { useForkedState } from '../../utils/hook' | ||
|
||
const meta = { | ||
component: EllipsisMiddle, | ||
parameters: { | ||
viewport: { | ||
defaultViewport: 'tablet', | ||
}, | ||
}, | ||
argTypes: { | ||
children: { | ||
// In React 17, `FC<P>` is wrapped in `PropsWithChildren<P>`, causing the type of `children` to be unrecognizable by Storybook. | ||
description: 'This item will be used as text when text is empty.', | ||
type: 'string', | ||
}, | ||
}, | ||
} satisfies Meta<typeof EllipsisMiddle> | ||
|
||
export default meta | ||
type Story = StoryObj<typeof meta> | ||
|
||
function getSentence(count: number) { | ||
return new Array(count) | ||
.fill(null) | ||
.map((_, idx) => `This is a sentence ${idx}.`) | ||
.join(' ') | ||
} | ||
|
||
export const ShortSentence: Story = { | ||
args: { | ||
children: getSentence(1), | ||
}, | ||
} | ||
|
||
export const LongSentence: Story = { | ||
args: { | ||
children: getSentence(10), | ||
}, | ||
} | ||
|
||
export const MinStartLen: Story = { | ||
parameters: { | ||
viewport: { | ||
defaultViewport: 'mobile1', | ||
}, | ||
}, | ||
args: { | ||
minStartLen: 40, | ||
children: getSentence(10), | ||
}, | ||
} | ||
|
||
export const UseTextWidthForPlaceholderWidth: Story = { | ||
args: { | ||
children: getSentence(1), | ||
useTextWidthForPlaceholderWidth: true, | ||
style: { border: '1px solid #000', boxSizing: 'content-box' }, | ||
}, | ||
render: function Render(args) { | ||
const [useTextWidthForPlaceholderWidth, setUseTextWidthForPlaceholderWidth] = useForkedState( | ||
args.useTextWidthForPlaceholderWidth, | ||
) | ||
|
||
return ( | ||
<div> | ||
<EllipsisMiddle {...args} useTextWidthForPlaceholderWidth={useTextWidthForPlaceholderWidth} /> | ||
<button | ||
type="button" | ||
onClick={() => setUseTextWidthForPlaceholderWidth(value => !value)} | ||
style={{ marginTop: 16 }} | ||
> | ||
toggle useTextWidthForPlaceholderWidth | ||
</button> | ||
</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
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