mirror of
https://github.com/utopia-os/utopia-ui.git
synced 2025-12-13 07:46:10 +00:00
Add showcase for PopupButton template component
This commit is contained in:
parent
d739977ca1
commit
e5c6cef751
@ -0,0 +1,24 @@
|
||||
import { useContext } from 'react'
|
||||
|
||||
import { PopupButton } from '#components/Map'
|
||||
|
||||
import { Templateify } from './Templateify'
|
||||
import ItemContext from './TemplateItemContext'
|
||||
|
||||
import type { JSXElementConstructor } from 'react'
|
||||
|
||||
type OmitItem<T extends keyof React.JSX.IntrinsicElements | JSXElementConstructor<unknown>> = Omit<
|
||||
React.ComponentProps<T>,
|
||||
'item'
|
||||
>
|
||||
|
||||
/**
|
||||
* @category Map
|
||||
*/
|
||||
export const TemplatePopupButton = (props: OmitItem<typeof PopupButton>) => {
|
||||
const item = useContext(ItemContext)
|
||||
|
||||
return <PopupButton {...props} item={item} />
|
||||
}
|
||||
|
||||
export const TemplatePopupButton2 = Templateify(PopupButton)
|
||||
23
src/Components/Profile/templateComponents/Templateify.tsx
Normal file
23
src/Components/Profile/templateComponents/Templateify.tsx
Normal file
@ -0,0 +1,23 @@
|
||||
import { useContext } from 'react'
|
||||
|
||||
import ItemContext from './TemplateItemContext'
|
||||
|
||||
import type { Item } from '#types/Item'
|
||||
import type { JSXElementConstructor } from 'react'
|
||||
|
||||
type OmitItem<T extends keyof React.JSX.IntrinsicElements | JSXElementConstructor<unknown>> = Omit<
|
||||
React.ComponentProps<T>,
|
||||
'item'
|
||||
>
|
||||
|
||||
export function Templateify<
|
||||
T extends keyof React.JSX.IntrinsicElements | JSXElementConstructor<unknown>,
|
||||
>(Component: React.JSXElementConstructor<React.PropsWithChildren<{ item?: Item }>>) {
|
||||
const TemplateComponent = (props: OmitItem<T>) => {
|
||||
const item = useContext(ItemContext)
|
||||
|
||||
return <Component {...props} item={item} />
|
||||
}
|
||||
|
||||
return TemplateComponent
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user