MCPcopy
hub / github.com/chakra-ui/ark / withContext

Function withContext

website/src/lib/create-style-context.tsx:58–71  ·  view source on GitHub ↗
(
    Component: ElementType,
    slot: Slot<R>,
  )

Source from the content-addressed store, hash-verified

56 }
57
58 const withContext = <T, P extends { className?: string | undefined }>(
59 Component: ElementType,
60 slot: Slot<R>,
61 ): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>> => {
62 const StyledComponent = styled(Component)
63 const StyledSlotComponent = forwardRef<T, P>((props, ref) => {
64 const slotStyles = useContext(StyleContext)
65 return <StyledComponent {...props} ref={ref} className={cx(slotStyles?.[slot], props.className)} />
66 })
67 // @ts-expect-error
68 StyledSlotComponent.displayName = Component.displayName || Component.name
69
70 return StyledSlotComponent
71 }
72
73 return {
74 withRootProvider,

Callers 15

dialog.tsxFile · 0.85
drawer.tsxFile · 0.85
color-picker.tsxFile · 0.85
switch.tsxFile · 0.85
carousel.tsxFile · 0.85
date-picker.tsxFile · 0.85
card.tsxFile · 0.85
signature-pad.tsxFile · 0.85
tabs.tsxFile · 0.85
tooltip.tsxFile · 0.85
editable.tsxFile · 0.85
combobox.tsxFile · 0.85

Calls 2

useContextFunction · 0.90
forwardRefFunction · 0.85

Tested by

no test coverage detected