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

fix: store to modal children #2176

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/components/ThemeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ThemeHelper = ({ modalStore }) => {
return (
<>
<Modal ariaLabel="theme configuration" store={modalStore} title={title}>
<Modal.Content store={modalStore}>
<Modal.Content>
<Modal.Header subtitle="Documentation for the core theme entries" title={title} />
<Modal.Body mt="xl">
<Box display="flex">
Expand Down
10 changes: 5 additions & 5 deletions docs/pages/components/modal.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function() {
Open modal
</Modal.Trigger>
<Modal store={modal} ariaLabel="example">
<Modal.Content store={modal}>
<Modal.Content>
<Modal.Body>
Praesent sit amet quam ac velit faucibus dapibus. Quisque sapien ligula, rutrum quis
aliquam nec, convallis sit amet erat. Mauris auctor blandit porta. In imperdiet rutrum
Expand Down Expand Up @@ -79,7 +79,7 @@ function() {
auto
</Modal.Trigger>
<Modal store={modal} size={size} ariaLabel="size example">
<Modal.Content store={modal}>
<Modal.Content>
<Modal.Body>
Praesent sit amet quam ac velit faucibus dapibus. Quisque sapien ligula, rutrum quis
aliquam nec, convallis sit amet erat. Mauris auctor blandit porta. In imperdiet rutrum
Expand Down Expand Up @@ -122,7 +122,7 @@ function() {
Example modal
</Modal.Trigger>
<Modal store={modal} ariaLabel="example">
<Modal.Content store={modal}>
<Modal.Content>
<Modal.Header title={title} subtitle={subtitle} icon={icon}/>
<Modal.Body>
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam pretium leo orci, sed
Expand Down Expand Up @@ -273,7 +273,7 @@ function() {
Example modal 2
</Modal.Trigger>
<Modal store={modal2} ariaLabel="example-2">
<Modal.Content store={modal}>
<Modal.Content>
<Modal.Header title={title} subtitle={subtitle} />
<Modal.Body>
Praesent sit amet quam ac velit faucibus dapibus. Quisque sapien ligula, rutrum quis
Expand Down Expand Up @@ -309,7 +309,7 @@ function() {
Example modal 3
</Modal.Trigger>
<Modal store={modal3} ariaLabel="example-3">
<Modal.Content store={modal}>
<Modal.Content>
<Modal.Header title={title} icon={icon} />
<Modal.Body>
Praesent sit amet quam ac velit faucibus dapibus. Quisque sapien ligula, rutrum quis
Expand Down
6 changes: 3 additions & 3 deletions packages/Modal/src/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface ContentOptions {
}

export type ContentProps = ContentOptions & {
store: UseModal
store?: UseModal
}

/**
Expand All @@ -21,8 +21,8 @@ export type ContentProps = ContentOptions & {
export const Content = forwardRef<'div', ContentProps>(({ children, store, ...rest }, ref) => {
const { borderWidths, space } = useTheme()
const [borderOnFooter, setBorderOnFooter] = useState(false)
const contentElement = store.useState('contentElement')
const open = store.useState('open')
const contentElement = store?.useState('contentElement')
const open = store?.useState('open')

const components = useMemo(
() =>
Expand Down
12 changes: 10 additions & 2 deletions packages/Modal/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react'
import React, { Children, cloneElement } from 'react'
import * as Ariakit from '@ariakit/react'
import { BoxProps } from '@welcome-ui/box'
import { As, CreateWuiProps, forwardRef } from '@welcome-ui/system'
Expand Down Expand Up @@ -57,7 +57,15 @@ const ModalComponent = forwardRef<'div', ModalProps>(
size={size}
store={store}
>
{children}
{/* we need to pass store on child */}
{Children.map(children, (child: JSX.Element) => {
if (!child) return null

return cloneElement(child, {
...child.props,
store,
})
})}
</S.Dialog>
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/Modal/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('<Modal>', () => {
open
</Modal.Trigger>
<Modal ariaLabel="modal" store={modal}>
<Modal.Content store={modal}>
<Modal.Content>
{shouldRender && <Modal.Body>Modal.Body exist?</Modal.Body>}
</Modal.Content>
</Modal>
Expand Down