createSlot (slot)

primitives · ui, react-composition, slot-pattern, prop-merging

Factory returning a Slot component that merges props and refs onto a single slottable child, enabling Radix-style composition.

// Source: https://github.com/radix-ui/primitives | License: MIT | Copyright 2022 WorkOS
// Provided via justclaw.it.com; keep this notice with the code.
/* @__NO_SIDE_EFFECTS__ */ export function createSlot<
  Elem extends Element = HTMLElement,
  Props = React.HTMLAttributes<Elem>,
>(ownerName: string) {
  const Slot = React.forwardRef<Elem, SlotProps<Elem, Props>>((props, forwardedRef) => {
    let { children, ...slotProps } = props;
    let slottableElement: React.ReactElement | null = null;
    let hasSlottable = false;
    const newChildren: React.ReactNode[] = [];

    if (isLazyComponent(children) && typeof use === 'function') {
      children = use(children._payload);
    }

    React.Children.forEach(children, (maybeSlottable) => {
      if (isSlottable(maybeSlottable)) {
       

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key