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

feat(component): restrict actions and header from modals #209

Merged
merged 9 commits into from
Oct 8, 2019

Conversation

jorgemoya
Copy link
Contributor

@jorgemoya jorgemoya commented Oct 7, 2019

BREAKING CHANGES

What

Headers and Actions are now a prop of modal component. Visually no change.

Added header & actions props.

actions accepts an array of Objects with Button props and a text prop.

Example:

[
  { text: 'Cancel', onClick: () => setIsOpen(false) },
  { text: 'Apply', onClick: () => setIsOpen(false) },
]

Updated tests and docs.

Screenshot

2

@jorgemoya jorgemoya requested a review from a team October 7, 2019 18:17
variant: 'modal' | 'dialog';
withActionsBorder?: boolean;
Copy link
Member

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@jorgemoya jorgemoya Oct 7, 2019

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.

@deini
Copy link
Member

deini commented Oct 7, 2019

Can you also add the BREAKING CHANGE section to your commit body with examples of how to migrate? 🙏

@jorgemoya
Copy link
Contributor Author

Can you also add the BREAKING CHANGE section to your commit body with examples of how to migrate? 🙏

Is this done when you squash and merge the commit?

packages/big-design/src/components/Modal/Modal.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Modal/spec.tsx Outdated Show resolved Hide resolved
packages/big-design/src/components/Modal/spec.tsx Outdated Show resolved Hide resolved
<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.
Copy link
Contributor

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).

packages/docs/PropTables/ModalPropTable.tsx Outdated Show resolved Hide resolved
@chanceaclark
Copy link
Contributor

Can you also add the BREAKING CHANGE section to your commit body with examples of how to migrate? 🙏

Is this done when you squash and merge the commit?

Yeah, you can write it in full markdown.

Comment on lines 7 to 9
<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>
Copy link
Contributor Author

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;
Copy link
Member

Choose a reason for hiding this comment

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

Should this be required?

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 was thinking we could have only icon buttons

Copy link
Member

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'> {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why export it?

Copy link
Member

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} />

Copy link
Contributor

@icatalina icatalina left a 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
Copy link
Contributor

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);
});
Copy link
Contributor

@chanceaclark chanceaclark Oct 7, 2019

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.
Copy link
Contributor

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.
🤷

@jorgemoya jorgemoya merged commit bc85d25 into bigcommerce:master Oct 8, 2019
@jorgemoya jorgemoya deleted the restrict-modal branch October 8, 2019 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants