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

refactor: [M3-7542] - TagsInput & TagsPanel Storybook v7 Stories #9963

Merged
merged 8 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

TagsInput & TagsPanel Storybook v7 Stories ([#9963](https://github.com/linode/manager/pull/9963))
1 change: 0 additions & 1 deletion packages/manager/.storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const preview: Preview = {
<Description />
<Primary />
<Controls />
<Stories />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Listing all stories in documentation often leads to state issues and it will make things a bit easier to test visual regression by focusing on individual stories.

Documentation is meant to be a playground on the default rendering of the component.

We can always put it back in if people feel it's necessary.

Copy link
Contributor

@coliu-akamai coliu-akamai Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually a bit confused where this is referring to πŸ˜… - is this regarding the Documentation section of each story, like here:
image

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 to show the list of stories in the Documentation page under the args table

</>
),
},
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/components/Tag/Tag.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ const meta: Meta<TagProps> = {
label: 'Tag',
},
component: Tag,
title: 'Components/Chip/Tag',
title: 'Components/Tags/Tag',
};
export default meta;
81 changes: 0 additions & 81 deletions packages/manager/src/components/TagsInput/TagsInput.stories.mdx

This file was deleted.

50 changes: 50 additions & 0 deletions packages/manager/src/components/TagsInput/TagsInput.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useArgs } from '@storybook/client-api';
import { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import { Box } from 'src/components/Box';

import { TagsInput } from './TagsInput';

import type { TagsInputProps } from './TagsInput';
import type { Item } from 'src/components/EnhancedSelect/Select';

export const Default: StoryObj<TagsInputProps> = {
args: {
disabled: false,
hideLabel: false,
label: '',
menuPlacement: 'bottom',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have better support for menuPlacement? Toggling between "top" and "bottom" has no effect (it's broken in prod Storybook also)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wasn't able to reproduce this - menu placement gets toggled as expected. I did improve the styling of the story so the select sits in the middle of the canvas to help viewing it better tho.

name: '',
tagError: '',
value: [
{ label: 'tag-1', value: 'tag-1' },
{ label: 'tag-2', value: 'tag-2' },
],
},
render: (args) => {
const TagsInputWrapper = () => {
const [, setTags] = useArgs();
const handleUpdateTags = (selected: Item[]) => {
return setTags({ value: selected });
};

return (
<Box sx={{ alignItems: 'center', display: 'flex', height: 300 }}>
<TagsInput
{...args}
onChange={(selected) => handleUpdateTags(selected)}
/>
</Box>
);
};

return TagsInputWrapper();
},
};

const meta: Meta<TagsInputProps> = {
component: TagsInput,
title: 'Components/Tags/Tags Input',
};
export default meta;
30 changes: 27 additions & 3 deletions packages/manager/src/components/TagsInput/TagsInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,43 @@ export interface Tag {
}

export interface TagsInputProps {
/**
* If true, the component is disabled.
*
* @default false
*/
disabled?: boolean;
/**
* If true, the label is hidden, yet still accessible to screen readers.
*/
hideLabel?: boolean;
/**
* The label for the input.
*/
label?: string;
/**
* The placement of the menu, relative to the select input.
*/
menuPlacement?: 'auto' | 'bottom' | 'top';
/**
* The name of the input.
*/
name?: string;
/**
* Callback fired when the value changes.
*/
onChange: (selected: Item[]) => void;
/**
* An error to display beneath the input.
*/
tagError?: string;
/**
* The value of the input.
*/
value: Item[];
}

const TagsInput = (props: TagsInputProps) => {
export const TagsInput = (props: TagsInputProps) => {
const {
disabled,
hideLabel,
Expand Down Expand Up @@ -115,5 +141,3 @@ const TagsInput = (props: TagsInputProps) => {
/>
);
};

export { TagsInput };
66 changes: 0 additions & 66 deletions packages/manager/src/components/TagsPanel/TagsPanel.stories.mdx

This file was deleted.

40 changes: 40 additions & 0 deletions packages/manager/src/components/TagsPanel/TagsPanel.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { useArgs } from '@storybook/client-api';
import { Meta, StoryObj } from '@storybook/react';
import React from 'react';

import { Box } from 'src/components/Box';

import { TagsPanel } from './TagsPanel';

import type { TagsPanelProps } from './TagsPanel';

const _tags: string[] = ['tag1', 'tag2', 'tag3', 'tag4', 'tag5'];

export const Default: StoryObj<TagsPanelProps> = {
render: (args) => {
const TagsInputWrapper = () => {
const [{ tags }, updateArgs] = useArgs();
const handleUpdateTags = (selected: string[]) => {
return Promise.resolve(updateArgs({ tags: selected }));
};

return (
<Box sx={{ height: 300 }}>
<TagsPanel {...args} tags={tags} updateTags={handleUpdateTags} />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have better support for disabled and align?

Currently when it's disabled, we lose the click-X-to-remove functionality for tags, but new tags can still be added (this isn't possible in prod Storybook).

Changing the selection for align doesn't seem to have any effect at all (this is true in prod Storybook also).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently when it's disabled, we lose the click-X-to-remove functionality for tags, but new tags can still be added (this isn't possible in prod Storybook).

I wasn't able to reproduce this but I remove align cause it's used nowhere and not even forwarded

</Box>
);
};

return TagsInputWrapper();
},
};

const meta: Meta<TagsPanelProps> = {
args: {
disabled: false,
tags: _tags,
},
component: TagsPanel,
title: 'Components/Tags/Tags Panel',
};
export default meta;
Loading