-
Notifications
You must be signed in to change notification settings - Fork 21
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'), | ||
validationMessage: 'ignored', | ||
}, | ||
|
||
render: (args) => { | ||
const StoryWrapper = (): React.ReactNode => { | ||
const [isModalOpen, modalOpen] = useState(false); | ||
const [value, setValue] = useState({ name: 'Laddie' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You used "Lassie" as the value for the modal. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put a little spacing between the div and the button? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 />; | ||
}, | ||
}; |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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