Skip to content

Commit d34ddb3

Browse files
committed
Example Button component
1 parent 71d011d commit d34ddb3

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

Diff for: client/components/Button/Button.stories.jsx

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import React from 'react';
2+
import { action } from '@storybook/addon-actions';
3+
import { boolean, text } from '@storybook/addon-knobs';
4+
5+
import Button from '.';
6+
7+
export default {
8+
title: 'Common/Button (JS)',
9+
component: Button
10+
};
11+
12+
export const AllFeatures = () => (
13+
<Button
14+
disabled={boolean('disabled', false)}
15+
type="submit"
16+
label={text('label', 'submit')}
17+
>
18+
{text('children', 'this is the button')}
19+
</Button>
20+
);
21+
22+
export const SubmitButton = () => (
23+
<Button type="submit" label="submit">This is a submit button</Button>
24+
);
25+
26+
export const PrimaryButton = () => <Button label="login" onClick={action('onClick')}>Log In</Button>;
27+
28+
export const DisabledButton = () => <Button disabled label="login" onClick={action('onClick')}>Log In</Button>;

Diff for: client/components/Button/Button.stories.mdx

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { Meta, Story, Preview } from '@storybook/addon-docs/blocks';
2+
import { action } from '@storybook/addon-actions';
3+
import { boolean, text } from '@storybook/addon-knobs';
4+
5+
import Button from './';
6+
7+
<Meta title="Common/Button (MDX)" component={Button} />
8+
9+
# Button
10+
11+
A button is used to perform an action.
12+
13+
<Preview>
14+
<Story name="All features">
15+
<Button
16+
disabled={boolean('disabled', false)}
17+
type="submit"
18+
label={text('label', 'submit')}
19+
>
20+
{text('children', 'this is the button')}
21+
</Button>
22+
</Story>
23+
<Story name="Submit button">
24+
<Button type="submit" label="submit" onClick={action('onClick')}>This is a submit button</Button>
25+
</Story>
26+
<Story name="Primary button">
27+
<Button label="Log In" onClick={action('onClick')}>Log In</Button>
28+
</Story>
29+
<Story name="Disabled">
30+
<Button disabled label="Log In" onClick={action('onClick')}>Log In</Button>
31+
</Story>
32+
</Preview>

Diff for: client/components/Button/index.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
import PropTypes from "prop-types";
3+
import styled from 'styled-components';
4+
5+
const StyledButton = styled.button`
6+
margin: 0;
7+
padding: 0;
8+
border: none;
9+
background: none;
10+
`;
11+
12+
/**
13+
* This text will be used for the description in the story
14+
*/
15+
const Button = ({ children, label, ...props }) => {
16+
return <StyledButton aria-label={label} {...props}>{children}</StyledButton>;
17+
}
18+
19+
Button.propTypes = {
20+
/**
21+
* The visible part of the button
22+
*/
23+
children: PropTypes.element.isRequired,
24+
/**
25+
If the button can be clicked or not
26+
*/
27+
disabled: PropTypes.boolean,
28+
/*
29+
* An ARIA Label used for accessibility
30+
*/
31+
label: PropTypes.string.isRequired,
32+
};
33+
34+
export default Button;

Diff for: client/index.stories.mdx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Meta } from '@storybook/addon-docs/blocks';
2+
3+
<Meta title=" |Intro" />
4+
5+
# Welcome to the P5.js Web Editor Style Guide
6+
7+
This guide will contain all the components in the project, with examples of how they can be reused.

0 commit comments

Comments
 (0)