-
Notifications
You must be signed in to change notification settings - Fork 65
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
feat(component): restrict actions and header from modals #209
Conversation
variant: 'modal' | 'dialog'; | ||
withActionsBorder?: boolean; |
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.
Do we have multiple designs? I think this should be consistent in all modals and not configurable.
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.
@deini It seems like you added it in #133 to support @animesh1987 use case. Is this something we need to touch back with design?
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.
Removed borders per offline discussion.
Can you also add the |
Is this done when you squash and merge the commit? |
<PropTable.Prop name="onClose" types="() => void" required> | ||
Function that will be called on close events. | ||
<PropTable.Prop name="actions" types="React.ReactNode"> | ||
Sets the actions of the modal. |
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.
Maybe we should reword this to what should be passed into the actions (i.e. Button
's).
Yeah, you can write it in full markdown. |
Co-Authored-By: Chancellor Clark <chancellorclark@gmail.com>
<PropTable.Prop name="actions" types="object[]"> | ||
Accepts an array of objects with <NextLink href="/button">Button</NextLink> props and a <Code>text</Code> label. | ||
</PropTable.Prop> |
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.
What do you guys think about this prop description?
export interface ModalHeaderProps { | ||
withBorder?: boolean; | ||
interface Action extends Omit<ButtonProps, 'children'> { | ||
text?: string; |
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.
Should this be required?
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 was thinking we could have only icon buttons
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.
Good point, can't think of it being a good use case but let's leave it for now. Good catch.
|
||
export interface ModalHeaderProps { | ||
withBorder?: boolean; | ||
interface Action extends Omit<ButtonProps, 'children'> { |
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.
What do you think about renaming this ModalAction
? We also need to export it.
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.
Why export it?
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.
For example, if you don't want to inline the actions
prop you could do.
const actions: ModalAction[] = [
{ text: 'Cancel', onClick: () => {} }
];
// And use it like
<Modal actions={actions} />
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.
The PR looks awesome, I'll defer to @deini for the final approval.
</Button> | ||
<Button onClick={() => setIsOpen(false)}>Apply</Button> | ||
</Modal.Actions> | ||
<Modal |
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.
This looks great! 👍
const { getAllByRole } = render(<Modal isOpen={true} actions={[{ text: 'Cancel' }, { text: 'Apply' }]} />); | ||
|
||
expect(getAllByRole('button').length).toBe(3); | ||
}); |
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.
🍹Could we add some additional tests? One to make sure the button callbacks fire, another to ensure props like variants
and actionType
have correct stylings, and another to ensure we can't pass a component into the header?
<PropTable.Prop name="onClose" types="() => void" required> | ||
Function that will be called on close events. | ||
<PropTable.Prop name="actions" types="object[]"> | ||
Accepts an array of objects with <NextLink href="/button">Button</NextLink> props and a <Code>text</Code> label. |
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.
Accepts an array of objects with Button props and a
text
label.
Maybe like this:
Accepts an array of objects with Button props with an additional text
prop. See example for usage.
🤷
9abee2f
to
56ef3a7
Compare
BREAKING CHANGES
What
Headers and Actions are now a prop of
modal
component. Visually no change.Added
header
&actions
props.actions
accepts an array ofObjects
withButton
props and atext
prop.Example:
Updated tests and docs.
Screenshot