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

[UIE-198] NameModal storybook #4925

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
79 changes: 79 additions & 0 deletions src/stories/packages/components/NameModal.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type { Meta, StoryObj } from '@storybook/react';
import React, { useState } from 'react';
import { ButtonPrimary } from 'src/components/common';
import { NameModal } from 'src/components/NameModal';

const meta: Meta<typeof Modal> = {
title: 'Packages/Components/NameModal',
component: NameModal,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {
onSuccess: {
control: 'function',
description: 'callback on submit. Accepts params object { name }',
},
onDismiss: {
control: 'function',
description: 'callback on dismiss',
},
thing: {
control: 'text',
description: 'the kind of entity to be named',
},
value: {
control: 'text',
description: 'the default name',
},
validator: {
control: 'function',
description:
'RegExp OR callback returning boolean false if the new name is valid, string error message otherwise',
},
validationMessage: {
control: 'text',
description: 'error message to show if the validator rejects the new name. Only used when `validator` is a regex',
},
},
};

export default meta;
type Story = StoryObj<typeof NameModal>;

export const Example: Story = {
args: {
onSuccess: () => {},
onDismiss: () => {},
thing: 'Dog',
value: 'Lassie',
validator: (value) => (value === 'Fido' ? false : 'I only like dogs named Fido'),
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest a case-insensitive match. I had trouble figuring out how to get rid of the error message, as I tried "fido" or "FIDO".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks; I'll make it /i

validationMessage: 'ignored',
},

render: (args) => {
const StoryWrapper = (): React.ReactNode => {
const [isModalOpen, modalOpen] = useState(false);
const [value, setValue] = useState({ name: 'Laddie' });
Copy link
Member

Choose a reason for hiding this comment

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

You used "Lassie" as the value for the modal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah this was intended to be a different value but it doesn't really matter

const showModal = () => {
modalOpen(true);
};
const hideModal = () => {
modalOpen(false);
};
const submitModal = (value) => {
modalOpen(false);
setValue(value);
};
return (
<div>
<div>{`My dog's name is ${value.name}.`}</div>
Copy link
Member

Choose a reason for hiding this comment

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

Could you put a little spacing between the div and the button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep!

<ButtonPrimary onClick={showModal}>Click to show modal</ButtonPrimary>
{isModalOpen && <NameModal {...args} onDismiss={hideModal} onSuccess={submitModal} />}
</div>
);
};
return <StoryWrapper />;
},
};
Loading