// // Copyright 2023 DXOS.org // import { ark } from '@ark-ui/react/factory'; import { type Meta, type StoryObj } from '@storybook/react-vite'; import React, { PropsWithChildren } from 'react'; import { mx } from '@dxos/ui-theme'; import { ThemedClassName } from '@dxos/ui-types'; import { withTheme } from '../testing/index.ts'; import { composable, composableProps, slottable } from '../util/slots.ts'; /** * `asChild` composition. * Every part that renders a DOM element accepts an `asChild` prop. When it is set, the part renders * no element of its own and instead clones its child, passing it the props and behaviour it needs. * https://ark-ui.com/docs/guides/composition */ const Outer = slottable( ({ children, asChild, priority, ...props }, forwardedRef) => { return ( (props, { classNames: 'p-2 border border-red-500 rounded' })} ref={forwardedRef} > {children} ); }, ); const Middle = slottable(({ children, asChild, ...props }, forwardedRef) => { return ( (props, { classNames: 'p-2 border border-red-500 rounded' })} ref={forwardedRef} > {children} ); }); const Leaf = composable(({ children, ...props }, forwardedRef) => { return ( ); }); /** This isn't a valid child for a `slottable` component. */ const Simple = ({ children, classNames }: ThemedClassName) => (
{children}
); const meta = { title: 'ui/react-ui-core/exemplars/slot', decorators: [withTheme()], parameters: { layout: 'centered', }, } satisfies Meta; export default meta; type Story = StoryObj; export const Single: Story = { render: () => ( Single asChild (non-compliant — see console) ), }; export const Nested: Story = { render: () => ( Nested asChild ), }; export const Inner: Story = { render: () => (
Leaf
), }; export const Error: Story = { render: () => ( Simple ), };