Skip to content

Extract & expose Dialog utility components  #1466

Open
@brandongregoryscott

Description

@brandongregoryscott

Extract the following JSX/functions from Dialog.js and expose them as standalone components:

DialogHeader

const renderHeader = close => {
if (!header && !hasHeader) {
return undefined
}
return (
<Pane flexShrink={0} display="flex" alignItems="center" {...themedHeaderProps}>
{header ? (
renderNode(header, close)
) : (
<>
<Heading is="h4" size={600} flex="1">
{title}
</Heading>
{hasClose && <IconButton appearance="minimal" icon={CrossIcon} onClick={() => onCancel(close)} />}
</>
)}
</Pane>
)
}

DialogBody

<Pane
data-state={state}
display="flex"
overflow="auto"
flexDirection="column"
minHeight={minHeightContent}
{...themedBodyProps}
{...contentContainerProps}
>
<Pane>{renderChildren(close)}</Pane>
</Pane>

DialogFooter

const renderFooter = close => {
if (!footer && !hasFooter) {
return undefined
}
return (
<Pane display="flex" justifyContent="flex-end" {...themedFooterProps}>
<Pane>
{footer ? (
renderNode(footer, close)
) : (
<>
{/* Cancel should be first to make sure focus gets on it first. */}
{hasCancel && (
<Button tabIndex={0} onClick={() => onCancel(close)}>
{cancelLabel}
</Button>
)}
<Button
tabIndex={0}
marginLeft={8}
appearance="primary"
intent={intent}
isLoading={isConfirmLoading}
disabled={isConfirmDisabled}
onClick={() => onConfirm(close)}
>
{confirmLabel}
</Button>
</>
)}
</Pane>
</Pane>
)
}

These are already mostly "themed" as regular components, but may need some slight tweaks during extraction:

const themedHeaderProps = useStyleConfig('DialogHeader', emptyProps, emptyProps, emptyProps)
const themedBodyProps = useStyleConfig('DialogBody', emptyProps, emptyProps, emptyProps)
const themedFooterProps = useStyleConfig('DialogFooter', emptyProps, emptyProps, emptyProps)

https://github.com/segmentio/evergreen/blob/master/src/themes/default/components/dialog-header.js
https://github.com/segmentio/evergreen/blob/master/src/themes/default/components/dialog-body.js
https://github.com/segmentio/evergreen/blob/master/src/themes/default/components/dialog-footer.js

These components should be attached to the Dialog component so they can be used for composition if needed, similar to the EmptyState component:

EmptyState.PrimaryButton = PrimaryButton
EmptyState.LinkButton = LinkButton

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions