-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add minimal typescript example to official-storybook (#9308)
Add minimal typescript example to official-storybook
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
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,26 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
|
||
export type Type = 'default' | 'action'; | ||
|
||
interface Props { | ||
/** | ||
* Click event handler | ||
* @default null | ||
*/ | ||
onClick?: () => void; | ||
|
||
/** | ||
* Button type yo | ||
*/ | ||
type?: Type; | ||
} | ||
|
||
const Button: FunctionComponent<Props> = ({ children, type = 'default', onClick }) => { | ||
return ( | ||
<button type="button" onClick={onClick}> | ||
{type}: {children} | ||
</button> | ||
); | ||
}; | ||
|
||
export default Button; |
25 changes: 25 additions & 0 deletions
25
examples/official-storybook/stories/addon-docs/ts-button.stories.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,25 @@ | ||
import * as React from 'react'; | ||
import { action } from '@storybook/addon-actions'; | ||
import { radios } from '@storybook/addon-knobs'; | ||
import Button, { Type } from '../../components/TsButton'; | ||
|
||
export default { | ||
title: 'Addons/Docs/TsButton', | ||
component: Button, | ||
}; | ||
|
||
type Story = () => any; | ||
|
||
export const SimpleButton: Story = () => { | ||
const x = 0; | ||
return <Button onClick={action('button clicked')}>OK {x}</Button>; | ||
}; | ||
|
||
const typeOptions = { | ||
Default: 'default', | ||
Action: 'action', | ||
}; | ||
|
||
export const WithType = () => ( | ||
<Button type={radios('Type', typeOptions, typeOptions.Default) as Type}>Label</Button> | ||
); |
53bd464
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to following URLs: