Skip to content

Commit

Permalink
pref: change thing
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <tukon479@gmail.com>
  • Loading branch information
Innei committed Feb 14, 2023
1 parent 16bf795 commit 09c1e09
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
14 changes: 7 additions & 7 deletions packages/kami-design/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ export const Input = memo(
}
}, [inputWrapRef])

const inputContextProviderValue = useRef({
setFocus: (state: boolean) => {
setFocus(state)
},
})

return (
<span
{...merge(props.wrapperProps, {
Expand Down Expand Up @@ -123,13 +129,7 @@ export const Input = memo(
</div>
)}
{props.children ? (
<InputContext.Provider
value={{
setFocus: (state: boolean) => {
setFocus(state)
},
}}
>
<InputContext.Provider value={inputContextProviderValue.current}>
{props.children}
</InputContext.Provider>
) : multi ? (
Expand Down
39 changes: 25 additions & 14 deletions packages/kami-design/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { clsx } from 'clsx'
import type { FC } from 'react'
import React, {
forwardRef,
useCallback,
Expand Down Expand Up @@ -32,6 +33,26 @@ export type ModalRefObject = {
getElement: () => HTMLElement
forceUpdate: () => void
}

const ModalContent: FC<{
title?: string
contentClassName?: string
children: React.ReactNode
}> = (props) => {
const { children, contentClassName, title } = props
return (
<div
className={clsx(
styles['content'],
title && styles['has-title'],
contentClassName,
)}
>
{children}
</div>
)
}

export const Modal = forwardRef<
ModalRefObject,
ModalProps & {
Expand Down Expand Up @@ -72,17 +93,7 @@ export const Modal = forwardRef<

const isMounted = useIsMountedState()

const Content = (
<div
className={clsx(
styles['content'],
title && styles['has-title'],
props.contentClassName,
)}
>
{props.children}
</div>
)
const portalProviderValue = useRef({ to: $wrapper.current as HTMLElement })

const Children = (
<div
Expand All @@ -108,12 +119,12 @@ export const Modal = forwardRef<
)}
{useRootPortal ? (
isMounted ? (
<RootPortalProvider value={{ to: $wrapper.current as HTMLElement }}>
{Content}
<RootPortalProvider value={portalProviderValue.current}>
<ModalContent {...props}>{props.children}</ModalContent>
</RootPortalProvider>
) : null
) : (
Content
<ModalContent {...props}>{props.children}</ModalContent>
)}
</div>
)
Expand Down
12 changes: 7 additions & 5 deletions packages/kami-design/components/Modal/stack-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,15 @@ export const ModalStackProvider: FC<{
}).current

const isClient = useIsClient()
const modalStackProvideValue = useRef({
present,
findCurrentByName,
getStack,
disposeAll,
}).current

return (
<ModalStackContext.Provider
value={
useRef({ present, findCurrentByName, getStack, disposeAll }).current
}
>
<ModalStackContext.Provider value={modalStackProvideValue}>
{children}

{isClient &&
Expand Down

0 comments on commit 09c1e09

Please sign in to comment.