Skip to content

Conversation

@jeroenransijn
Copy link
Contributor

@jeroenransijn jeroenransijn commented Feb 15, 2018

This PR is based on top of #127, #128. The other PR was still based on the old mono-repo, so I redid most what was in that PR and made some additional changes and tweaks.

This is a breaking change

This PR contains

  • Dialog API improvements
  • More Dialog stories
  • Dialog documentation
  • Button now has a isLoading prop
  • Minor changes in content for Table and Buttons docs.

Props and default props

static propTypes = {
  /**
   * Children can be a node or a function accepting `({ close })`.
   * See an example to understand how this works.
   */
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]).isRequired,

  /**
   * When true, the dialog is shown.
   */
  isShown: PropTypes.bool,

  /**
   * Title of the Dialog. Titles should use Title Case.
   */
  title: PropTypes.node,

  /**
   * When true, the header with the title and close icon button is shown.
   */
  hasHeader: PropTypes.bool,

  /**
   * When true, the footer with the cancel and confirm button is shown.
   */
  hasFooter: PropTypes.bool,

  /**
   * When true, the cancel button is shown.
   */
  hasCancel: PropTypes.bool,

  /**
   * Function that will be called when the exit transition is complete.
   */
  onCloseComplete: PropTypes.func,

  /**
   * Function that will be called when the enter transition is complete.
   */
  onOpenComplete: PropTypes.func,

  /**
   * Function that will be called when the confirm button is clicked.
   * This does not close the Dialog. A close function will be passed
   * as a paramater you can use to close the dialog.
   *
   * `onConfirm={(close) => close()}`
   */
  onConfirm: PropTypes.func,

  /**
   * Label of the confirm button.
   */
  confirmLabel: PropTypes.string,

  /**
   * The type of the message.
   */
  type: PropTypes.oneOf(['default', 'danger']),

  /**
   * When true, the confirm button is set to loading.
   */
  isConfirmLoading: PropTypes.bool,

  /**
   * When true, the confirm button is set to disabled.
   */
  isConfirmDisabled: PropTypes.bool,

  /**
   * Function that will be called when the cancel button is clicked.
   * This closes the Dialog by default.
   *
   * `onCancel={(close) => close()}`
   */
  onCancel: PropTypes.func,

  /**
   * Label of the cancel button.
   */
  cancelLabel: PropTypes.string,

  /**
   * Width of the Dialog.
   */
  width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

  /**
   * The space above the dialog.
   * This offset is also used at the bottom when there is not enough space
   * available on screen — and the dialog scrolls internally.
   */
  topOffset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

  /**
   * The min height of the body content.
   * Makes it less weird when only showing little content.
   */
  minHeightContent: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

  /**
   * Props that are passed to the dialog container.
   */
  containerProps: PropTypes.object
}

static defaultProps = {
  isShown: false,
  hasHeader: true,
  hasFooter: true,
  hasCancel: true,
  type: 'default',
  width: 560,
  topOffset: '12vh',
  minHeightContent: 80,
  confirmLabel: 'Confirm',
  isConfirmLoading: false,
  isConfirmDisabled: false,
  cancelLabel: 'Cancel',
  onCancel: close => close(),
  onConfirm: close => close()
}

Design Examples

These examples don‘t reflect the latest state of the component.

dialog
confirm loading
button isloading
dialog docs

@@ -1,3 +1,4 @@
/* eslint-disable react/no-danger */
Copy link
Contributor

Choose a reason for hiding this comment

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

Why add this? I don't see dangerouslySetInnerHTML anywhere?
https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-danger.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah removed that later.

}
}
&:hover {
text-decoration: underline;
Copy link
Contributor

Choose a reason for hiding this comment

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

Might want a focus style too? 😉

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 too lazy.

flex: 1;
display: flex;
background-color: var(--neutral-3);
/* background-color: var(--neutral-3); */
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably should just delete 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.

Yes

render() {
return this.props.children({
isLoading: this.state.isLoading,
setLoading: () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should really make this a method on the class and keep the JSX clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

render() {
return this.props.children({
isLoading: this.state.isLoading,
setLoading: () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes

BlueprintJS
</a>{' '}
pointed out in their documentation that &ldquo;modal&rdquo; is a misnomer
for &ldquo;dialog&rdquo;.
Copy link
Contributor

Choose a reason for hiding this comment

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

Use “ and ” instead. Unicode is your friend. 😉

* Children can be a node or a function accepting `({ close })`.
* See an example to understand how this works.
*/
children: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth making children required because a dialog without children is pretty useless. 😛

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True

* Passing this object will show the button and cancel button.
* You should pass `children` and `onClick`.
*/
primaryButton: PropTypes.object,
Copy link
Contributor

Choose a reason for hiding this comment

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

So it can't be boolean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope.

Copy link
Contributor

Choose a reason for hiding this comment

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

Most of the time you wouldn't really want to pass props to the primary button though?

Then you'll end up with lots of code like primaryButton={{}}.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You have to pass the onClick handler

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And you need to pass in children to give it a label. You always have to define something right?

* This offset is also used at the bottom when there is not enough space
* available on screen — and the Dialog scrolls internally.
*/
topOffset: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't be a number because I don't think unitless values will work in the CSS calc below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, we need to do add px then.

: close()
}
/>
{hideCancelButton ? null : (
Copy link
Contributor

Choose a reason for hiding this comment

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

Just do {!hideCancelButton && (.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

@jeroenransijn jeroenransijn merged commit 2919112 into master Feb 15, 2018
@jeroenransijn jeroenransijn deleted the improve-dialog-2 branch February 15, 2018 21:39
prateekgoel pushed a commit to prateekgoel/evergreen that referenced this pull request Oct 26, 2018
* improved dialog and docs + button loading

* fixes

* fix build

* more explicit API

* intent => type keep consistent with Alert

* update story and docs

* removed old showCancel

* docs fixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants