Skip to content

Commit

Permalink
feat: add uncontrolled example for tags
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabhdaware committed Apr 10, 2024
1 parent 41abfc4 commit 2bbbd73
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/blade/src/components/Input/TextArea/TextArea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,50 @@ export const TextAreaWithTags: StoryFn<typeof TextAreaComponent> = ({ ...args })
);
};

export const TextAreaWithControlledTags: StoryFn<typeof TextAreaComponent> = ({ ...args }) => {
const [tags, setTags] = React.useState<string[]>([]);

return (
<Box display="flex" flexDirection="column">
<TextAreaComponent
{...args}
tags={tags}
onTagChange={({ tags }) => {
setTags(tags);
}}
/>
</Box>
);
};

TextAreaWithControlledTags.args = {
isTaggedInput: true,
showClearButton: false,
};

export const TextAreaWithUncontrolledTags: StoryFn<typeof TextAreaComponent> = ({ ...args }) => {
const [tagValues, setTagValues] = React.useState<string[]>([]);
return (
<Box display="flex" flexDirection="column">
<TextAreaComponent
{...args}
onTagChange={({ tags }) => {
console.log('new tags', tags);
setTagValues(tags);
}}
/>
<Box>
<Text>{tagValues.join(', ')}</Text>
</Box>
</Box>
);
};

TextAreaWithUncontrolledTags.args = {
isTaggedInput: true,
showClearButton: true,
};

// Don't copy email regex from here. This is just an example regex for basic emails. Make sure to use email validation as per usecase
const isValidEmail = (email: string): boolean => {
const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|.(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
Expand Down

0 comments on commit 2bbbd73

Please sign in to comment.