mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2026-03-01 12:44:17 +00:00
* Refactor Layer and its subcomponents, replacing cloneElement by context * Add showcase for PopupButton template component * Templateify exported elements (WIP) * Remove unused file * Export templateified PopupStartEndInput * Fix template component type * Change folder structure * Lower test coverage * changed export name * Refactor PopupForm and PopupView * More refactoring * Add provider for PopupFormContext * Fix popupform title * Add comments * Use correct ItemFormPopup for new items * Fix linting * Reduce coverage * Change tailwind prefix * Fix type --------- Co-authored-by: Anton Tranelis <mail@antontranelis.de> Co-authored-by: Anton Tranelis <31516529+antontranelis@users.noreply.github.com>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { createContext, useContext, useState } from 'react'
|
|
|
|
import type { PopupFormState } from '#types/PopupFormState'
|
|
|
|
type UsePopupFormManagerResult = ReturnType<typeof usePopupFormManager>
|
|
|
|
const PoupFormContext = createContext<UsePopupFormManagerResult>({
|
|
popupForm: {} as PopupFormState | null,
|
|
setPopupForm: () => {
|
|
/* empty function */
|
|
},
|
|
})
|
|
|
|
function usePopupFormManager(): {
|
|
popupForm: PopupFormState | null
|
|
setPopupForm: React.Dispatch<React.SetStateAction<PopupFormState | null>>
|
|
} {
|
|
const [popupForm, setPopupForm] = useState<PopupFormState | null>(null)
|
|
|
|
return { popupForm, setPopupForm }
|
|
}
|
|
|
|
interface Props {
|
|
children?: React.ReactNode
|
|
}
|
|
|
|
export const PopupFormProvider: React.FunctionComponent<Props> = ({ children }: Props) => (
|
|
<PoupFormContext.Provider value={usePopupFormManager()}>{children}</PoupFormContext.Provider>
|
|
)
|
|
|
|
export const usePopupForm = (): UsePopupFormManagerResult => {
|
|
const { popupForm, setPopupForm } = useContext(PoupFormContext)
|
|
return { popupForm, setPopupForm }
|
|
}
|