1.0.0 • Published 11 months ago

@element-public/react-dialog v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Dialog

Description

Dialogs inform users about a task and can contain critical information, require decisions, or involve multiple tasks. A dialog is a type of modal window that appears in front of app content to provide critical information or ask for a decision. Dialogs disable all app functionality when they appear, and remain on screen until confirmed, dismissed, or a required action has been taken.

See live demos on storybook

Storybook Dialog Demos

Install bundle from npm-e

npm i @element-public/react-components @element-public/themes

Optional: install the component individually

npm i @element-public/react-dialog @element-public/themes

Open ~/.npmrc in an editor and add the following line to enable the @element-public scope:

@element-public:registry=https://npm.platforms.engineering

Troubleshooting

See below if you have never installed a package from Bayer's npm-enterprise or run into the following error:

npm ERR! code E401
npm ERR! Unable to authenticate, your authentication token seems to be invalid.
npm ERR! To correct this please trying logging in again with:
npm ERR!     npm login

Setup an access token

See the devtools npm-e guide to learn how to create an access token if this is the first time you are using a npm-e package at Bayer or you do not have a line that starts with the following in your ~/.npmrc file:

//npm.platforms.engineering/:_authToken=

Notes

A notable prop for Dialog is preventClose which prevents the user from closing the dialog by hitting escape or clicking the scrim. This limits the use of Dialog to forcing the user to click a button to close the window, instead of navigating the window with keyboard input.

Usage

Dialogs are often used with other components, like a Button to open or close the Dialog window or a selection input, like Radio or Checkbox, to gather data within the Dialog window.

Dialog Props

NameTypeDefaultRequiredDescription
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
contentIdstringempty stringfalseCustom id for the content container. If one is not specified a random id will be generated.
headerIdstringempty stringfalseCustom id for the header container. If one is not specified a random id will be generated.
openbooleanfalsefalseIf true, the dialog will be visible on screen.
preventClosebooleanfalsefalsePrevents the user from closing the dialog by hitting escape or clicking the scrim.
returnFocusSelectorstringnullfalseDOM selector to provide a target to return focus. Accepts any valid query (see mdn docs for Element.querySelector). If omitted focus will return to the last focused element upon closing.
stackedButtonsbooleanfalsefalseIf true, the cancel button will be rendered beneath the accept button instead of side-by-side. Stacking of buttons happens automatically in cases where the button text is too long for all buttons to fit on a single line. Setting this prop to true is only required if you want to override this behavior.

Dialog Render Props

NameTypeDefaultRequiredDescription
acceptButtonReact.ReactNodenullfalseButton for the approving action of the dialog. When pressed, the dialog will close.
actionsReact.ReactNodenullfalseslot/element for adding action buttons
cancelButtonReact.ReactNodenullfalseButton for the cancel/close action of the dialog. When pressed, the dialog will close.
contentReact.ReactNodenullfalsePrimary content of the dialog. Optional, children may be used instead.
headerReact.ReactNodenullfalseTitle information displayed at the top of the dialog.

Dialog Events

NameDefaultRequiredParamsDescription
onActionnullfalseFired only when the closing action was triggered via dialog interaction.
onClosednullfalseFired when the Dialog finishes its closing animation. Where action is the action which closed the dialog.
onClosingnullfalseFired when the dialog begins its closing animation. action represents the action which closed the dialog.
onOpenednullfalseFired when the dialog finishes its opening animation.
onOpeningnullfalseFired when the dialog begins its opening animation.

Dialog Breaking Changes

Description
dialogButton (removed): Use actions instead.
onClose (removed): Renamed to onClosing.

Dialog Action Props

NameTypeDefaultRequiredDescription
actionstringempty stringfalseDialog action
focusedbooleannullfalseFocus element on dialog upon open
tagstring|React.ElementType|React.Component'div'trueBase component that will be rendered

Dialog Action Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalsechildren

Dialog Action Breaking Changes

Description
component (removed): Renamed to tag.

Dialog Button Props

NameTypeDefaultRequiredDescription
buttonSizestring'themeDefault'falseOne of 'xsmall', 'small', 'medium', 'large' and 'xlarge' will change the size of the button. Defaults according to your theme.Accepted Values: xsmall, small, medium, large, xlarge, themeDefault
classNamestringundefinedfalseThe css class name to be passed through to the component markup.
disabledbooleanfalsefalsePrevent the user from interacting with the component.
elevationstring'default'falseSets elevation of the button. Default will be the theme default.Accepted Values: default, elevated, flat
fullWidthbooleanfalsefalseApplies a full-width style where the textfield will fill it's container.
hrefstringnullfalseThe button will render as an anchor tag. If the tag prop is set, that prop will take precedence.
labelstringnullfalseThe displayed text. Expects a valid string. If label and children are both set, label will take priority.
leadingIconstring|function|React.ReactNodeundefinedfalseAdds the given Icon to the left of the button text. May not be used with trailingIcon - if leadingIcon and trailingIcon are both set, leadingIcon will take priority. Expects the name of a valid Material.io icon, however an icon component may be passed in instead for more control,
tagstring|React.ElementType|React.ComponentnullfalseBy default a button or anchor tag will be rendered, this allows another tag/component to be used instead. A block type element/component is suggested.
themeColorstring'primary'falseSets the theme color for the button. Most commonly used when the control is placed on a darker surface.Accepted Values: primary, secondary, danger, success, on-unknown-black, on-unknown-white, on-primary, on-secondary, on-success, on-dangerDeprecated Values: onUnknownBlack, onUnknownWhite
trailingIconstring|function|React.ReactNodeundefinedfalseAdds the given Icon to the right of the button text. May not be used with leadingIcon - if leadingIcon and trailingIcon are both set, leadingIcon will take priority. Expects the name of a valid Material.io icon, however an icon component may be passed in instead for more control.
typestring'button'falseThis applies the html button type (button, submit, reset) or the anchor media type when used with the href property.Accepted Values: button, submit, reset
variantstring'filled'falseApplies the selected style to the button. rounded-small and rounded-micro are only available on select themes.Accepted Values: filled, outlined, danger, text, success, rounded-small, rounded-micro

Dialog Button Deprecated Props

NameTypeDefaultRequiredDeprecatedDescription
altColorbooleanundefinedfalseUse themeColor='secondary' instead.Preview feature, this may change. Apply alternative button color scheme (defined by the individual theme).
customRefreferenceundefinedfalseforwardRef has been implemented for Button.Reference to the DOM button. This enables a greater level of integration.
dangerbooleanundefinedfalseUse variant='danger' instead.Apply danger style to the button.
filledbooleanundefinedfalseUse variant='filled' instead.Apply a filled-in style. Previously called primary.
outlinedbooleanundefinedfalseUse variant='outlined'.Apply outlined style to the button. Previously called secondary.
primarybooleanundefinedfalseUse variant='filled' instead.Apply primary style to the Button.
secondarybooleanundefinedfalseUse 'variant=outlined' instead.Apply secondary style to the Button.
tertiarybooleanundefinedfalseUse variant='embedded' instead.Apply tertiary style to the Button.
textbooleanundefinedfalseUse variant='text' instead.Apply unfilled, un-outlined style to the Button. Previously called tertiary.
unelevatedbooleanundefinedfalseUse `elevation='flat' instead. | Remove elevation.

Dialog Button Render Props

NameTypeDefaultRequiredDescription
childrenReact.ReactNodenullfalseContent to be rendered inside the button. Can be used instead label of to provide more flexibility. Accepts any valid markup. Warning, if Label is set, it will be used instead of child content.

Dialog Button Events

NameDefaultRequiredParamsDescription
onClickundefinedfalseThe primary interaction event for button.