Skip to content

Commit

Permalink
Add minimal typescript example to official-storybook (#9308)
Browse files Browse the repository at this point in the history
Add minimal typescript example to official-storybook
  • Loading branch information
shilman authored Jan 3, 2020
2 parents 052ae2e + 307145a commit 53bd464
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/official-storybook/components/TsButton.tsx
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;
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>
);

1 comment on commit 53bd464

@vercel
Copy link

@vercel vercel bot commented on 53bd464 Jan 3, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.