// // Copyright 2026 DXOS.org // import { ark } from '@ark-ui/react/factory'; import { type Meta, type StoryObj } from '@storybook/react-vite'; import React, { type ReactNode, forwardRef } from 'react'; import { withLayout, withTheme } from '../testing/index.ts'; import { composable, composableProps, slottable } from './slots.ts'; // // A slottable host and two candidate children: one built with `composable()`, one a plain // `forwardRef`. The `asChild` factory merges its props into whichever child it is given, but a child that // does not spread them drops the injected `className` and `ref` — silently, with no error and no // type complaint. `slottable()` detects that in dev builds and marks the rendered element with // `dx-slot-warning` (a dashed rose outline). // const Host = slottable(({ children, asChild, ...props }, forwardedRef) => { return ( {children} ); }); /** Correct: built with `composable()`, so it carries the COMPOSABLE marker and spreads props. */ const GoodChild = composable(({ children, ...props }, forwardedRef) => (
{children}
)); /** Incorrect: a plain `forwardRef`. It renders fine on its own, but as an `asChild` target the * host's className never reaches the DOM — the failure this diagnostic exists to surface. */ const BadChild = forwardRef(({ children }, forwardedRef) => (
{children}
)); const Row = ({ label, children }: { label: string; children: ReactNode }) => (
{label} {children}
); const DefaultStory = () => (
Plain host Composable child Non-composable child
); const meta = { title: 'ui/react-ui-core/util/slots', render: DefaultStory, decorators: [withTheme(), withLayout()], parameters: { layout: 'fullscreen' }, } satisfies Meta; export default meta; type Story = StoryObj; export const Default: Story = {};