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

Extract & expose Dialog utility components #1466

Open
brandongregoryscott opened this issue May 3, 2022 · 2 comments · May be fixed by #1470
Open

Extract & expose Dialog utility components #1466

brandongregoryscott opened this issue May 3, 2022 · 2 comments · May be fixed by #1470

Comments

@brandongregoryscott
Copy link
Contributor

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

@shreedharbhat98
Copy link
Contributor

Hey @brandongregoryscott I would like to contribute to this issue. Can you please assign this issue to me?

@brandongregoryscott
Copy link
Contributor Author

Sure thing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants