Chore: Improve TagList story (#52012)

* Chore: Improve TagList story

* Chore: fix moreTagsLabel in the TagList component
This commit is contained in:
Sonja Feitsch 2022-07-12 08:06:31 +02:00 committed by GitHub
parent 3003a48dc6
commit ef77c93934
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 6 deletions

View File

@ -1,9 +1,10 @@
import { action } from '@storybook/addon-actions';
import { Story } from '@storybook/react';
import React from 'react';
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
import { TagList } from './TagList';
import { TagList, Props as TagListProps } from './TagList';
import mdx from './TagList.mdx';
export default {
@ -14,15 +15,31 @@ export default {
docs: {
page: mdx,
},
controls: {
exclude: ['className', 'onClick', 'getAriaLabel'],
},
},
args: {
displayMax: 3,
tags: ['datasource-test', 'gdev', 'mysql', 'mssql'],
onClick: action('Tag clicked'),
showIcon: false,
},
};
const tags = ['datasource-test', 'gdev', 'mysql', 'mssql'];
interface StoryProps extends TagListProps {
showIcon?: boolean;
}
export const list = () => {
export const List: Story<StoryProps> = (args) => {
return (
<div style={{ width: 300 }}>
<TagList tags={tags} onClick={action('Tag clicked')} />
<TagList
tags={args.tags}
onClick={args.onClick}
displayMax={args.displayMax}
icon={args.showIcon ? args.icon : undefined}
/>
</div>
);
};

View File

@ -9,8 +9,11 @@ import { IconName } from '../../types/icon';
import { OnTagClick, Tag } from './Tag';
export interface Props {
/** Maximum number of the tags to display */
displayMax?: number;
/** Names of the tags to display */
tags: string[];
/** Callback when the tag is clicked */
onClick?: OnTagClick;
/** Custom styles for the wrapper component */
className?: string;
@ -33,8 +36,8 @@ export const TagList = memo(
<Tag name={tag} icon={icon} onClick={onClick} aria-label={getAriaLabel?.(tag, i)} data-tag-id={i} />
</li>
))}
{displayMax && displayMax > 0 && numTags - 1 > 0 && (
<span className={styles.moreTagsLabel}>+ {numTags - 1}</span>
{displayMax && displayMax > 0 && numTags - displayMax > 0 && (
<span className={styles.moreTagsLabel}>+ {numTags - displayMax}</span>
)}
</ul>
);