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

Function withProvider

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

Source from the content-addressed store, hash-verified

35 }
36
37 const withProvider = <T, P extends { className?: string | undefined }>(
38 Component: ElementType,
39 slot: Slot<R>,
40 ): ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<T>> => {
41 const StyledComponent = styled(Component)
42 const StyledSlotProvider = forwardRef<T, P>((props, ref) => {
43 const [variantProps, otherProps] = recipe.splitVariantProps(props)
44 const slotStyles = recipe(variantProps) as Record<Slot<R>, string>
45
46 return (
47 <StyleContext.Provider value={slotStyles}>
48 <StyledComponent {...otherProps} ref={ref} className={cx(slotStyles?.[slot], props.className)} />
49 </StyleContext.Provider>
50 )
51 })
52 // @ts-expect-error
53 StyledSlotProvider.displayName = Component.displayName || Component.name
54
55 return StyledSlotProvider
56 }
57
58 const withContext = <T, P extends { className?: string | undefined }>(
59 Component: ElementType,

Callers 15

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
editable.tsxFile · 0.85
combobox.tsxFile · 0.85
rating-group.tsxFile · 0.85
checkbox.tsxFile · 0.85

Calls 1

forwardRefFunction · 0.85

Tested by

no test coverage detected