-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
packages/examples/react/src/components/ForwardRefButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ComponentPropsWithRef, forwardRef } from 'react' | ||
|
||
export interface ButtonProps extends ComponentPropsWithRef<'button'> { | ||
variant?: 'red' | 'green' | ||
} | ||
|
||
const ForwardRefButton = forwardRef<HTMLButtonElement, ButtonProps>(function ForwardRefButton( | ||
{ variant = 'red', children, ...rest }, | ||
ref, | ||
) { | ||
return ( | ||
<button ref={ref} style={{ color: variant }} {...rest}> | ||
{children} | ||
</button> | ||
) | ||
}) | ||
|
||
export { ForwardRefButton } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Story } from '@storylite/storylite' | ||
|
||
import { ForwardRefButton } from '../src/components/ForwardRefButton' | ||
|
||
import '../src/styles/components.css' | ||
|
||
type StoryType = Story<typeof ForwardRefButton> | ||
|
||
// 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 ( | ||
<div style={{ padding: 20, borderRadius: '8px', background: '#ddd' }}> | ||
<Story {...context?.args} /> | ||
</div> | ||
) | ||
}, | ||
], | ||
args: { | ||
// default args | ||
children: 'My Button', | ||
}, | ||
navigation: { | ||
// overriden navigation options | ||
icon: <span>⏩</span>, | ||
hidden: true, // hidden in sub-menu | ||
}, | ||
} satisfies StoryType | ||
|
||
export const DefaultStory: StoryType = { | ||
name: 'Default', | ||
} | ||
|
||
export const WithComponentProps: StoryType = { | ||
args: { | ||
variant: 'green', | ||
children: 'Green Variant', | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters