Polymorphic Slot primitive that merges props, refs, and event handlers for flexible component composition.
// Source: https://github.com/equinor/design-system | License: MIT | Copyright 2020 Equinor ASA
// Provided via justclaw.it.com; keep this notice with the code.
import {
forwardRef,
isValidElement,
cloneElement,
useMemo,
Fragment,
type ReactElement,
type ReactNode,
type Ref,
} from 'react'
import { getElementRef } from '@equinor/eds-utils'
import type { SlotProps } from './Slot.types'
function mergeClassNames(...classNames: (string | undefined)[]) {
return classNames.filter(Boolean).join(' ')
}
function isPrevented(event: unknown) {
return (
typeof event === 'object' &&
event !== null &&
(event as { defaultPrevented?: boolean }).defaultPrevented === true
)
}
function mergeProps(
slotProps: Record<string, unknown>,
childProps: Record<string, unknown>
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key