diff --git a/packages/examples/react/src/components/ForwardRefButton.tsx b/packages/examples/react/src/components/ForwardRefButton.tsx new file mode 100644 index 0000000..6da899e --- /dev/null +++ b/packages/examples/react/src/components/ForwardRefButton.tsx @@ -0,0 +1,18 @@ +import { ComponentPropsWithRef, forwardRef } from 'react' + +export interface ButtonProps extends ComponentPropsWithRef<'button'> { + variant?: 'red' | 'green' +} + +const ForwardRefButton = forwardRef(function ForwardRefButton( + { variant = 'red', children, ...rest }, + ref, +) { + return ( + + ) +}) + +export { ForwardRefButton } diff --git a/packages/examples/react/stories/forwardref.stories.tsx b/packages/examples/react/stories/forwardref.stories.tsx new file mode 100644 index 0000000..2b1f5ee --- /dev/null +++ b/packages/examples/react/stories/forwardref.stories.tsx @@ -0,0 +1,43 @@ +import { Story } from '@storylite/storylite' + +import { ForwardRefButton } from '../src/components/ForwardRefButton' + +import '../src/styles/components.css' + +type StoryType = Story + +// all properties (except navigation) defined in the 'default' export are inherited by +// all other stories in this file +export default { + title: 'ForwardRefButton', + component: ForwardRefButton, + decorators: [ + (Story, context) => { + return ( +
+ +
+ ) + }, + ], + args: { + // default args + children: 'My Button', + }, + navigation: { + // overriden navigation options + icon: , + hidden: true, // hidden in sub-menu + }, +} satisfies StoryType + +export const DefaultStory: StoryType = { + name: 'Default', +} + +export const WithComponentProps: StoryType = { + args: { + variant: 'green', + children: 'Green Variant', + }, +} diff --git a/packages/storylite/src/types/components.ts b/packages/storylite/src/types/components.ts index f504b87..355aeb3 100644 --- a/packages/storylite/src/types/components.ts +++ b/packages/storylite/src/types/components.ts @@ -21,6 +21,13 @@ export type SLNode = // | SLFunctionComponent export type SLFunctionComponent

= React.FC

-export type SLComponentProps

> = { - [key in keyof ComponentProps>]: ComponentProps>[key] -} + +export type SLComponentProps = T extends + | React.ComponentType + | React.Component + ? { + [key in keyof ComponentProps>]: ComponentProps< + SLFunctionComponent

+ >[key] + } + : never