-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Button example * Add semicolon behind import * Add Image example * Add Form examples * Add Typography examples
- Loading branch information
1 parent
fae8834
commit 0266c97
Showing
17 changed files
with
352 additions
and
25 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,46 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
const styles = { | ||
button: { | ||
padding: '12px 6px', | ||
fontSize: '12px', | ||
lineHeight: '16px', | ||
borderRadius: '5px', | ||
}, | ||
ok: { | ||
backgroundColor: '#028402', | ||
color: '#ffffff', | ||
}, | ||
wrong: { | ||
color: '#ffffff', | ||
backgroundColor: '#4caf50', | ||
} | ||
} | ||
|
||
function Button({ label, content, disabled, contrast }) { | ||
return ( | ||
<button | ||
style={{ | ||
...styles.button, | ||
...styles[contrast], | ||
}} | ||
disabled={disabled} | ||
> | ||
{ content } | ||
</button> | ||
) | ||
} | ||
|
||
Button.propTypes = { | ||
label: PropTypes.string, | ||
content: PropTypes.string, | ||
disabled: PropTypes.bool, | ||
contrast: PropTypes.oneOf(['ok', 'wrong']) | ||
}; | ||
|
||
Button.defaultProps = { | ||
disabled: false, | ||
contrast: 'ok', | ||
}; | ||
|
||
export default Button; |
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,34 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
|
||
import { checkA11y } from './../../../src'; | ||
|
||
import Button from './component'; | ||
|
||
import Faker from 'faker'; | ||
|
||
const text = Faker.lorem.words(); | ||
|
||
storiesOf('<Button />', module) | ||
.addDecorator(checkA11y) | ||
.add('Default', () => ( | ||
<Button /> | ||
)) | ||
.add('Content', () => ( | ||
<Button content={text} /> | ||
)) | ||
.add('Label', () => ( | ||
<Button label={text} /> | ||
)) | ||
.add('Disabled', () => ( | ||
<Button | ||
disabled | ||
content={text} | ||
/> | ||
)) | ||
.add('Invalid contrast', () => ( | ||
<Button | ||
contrast="wrong" | ||
content={Faker.lorem.words()} | ||
/> | ||
)); |
21 changes: 21 additions & 0 deletions
21
addons/a11y/.storybook/components/Form/components/Input.js
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,21 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
function Input({ id, value, type, placeholder }) { | ||
return ( | ||
<input | ||
id={id} | ||
value={value} | ||
placeholder={placeholder} | ||
type={type} | ||
/> | ||
); | ||
} | ||
|
||
Input.propTypes = { | ||
type: PropTypes.oneOf(['text', 'password']), | ||
id: PropTypes.string, | ||
value: PropTypes.string, | ||
placeholder: PropTypes.string, | ||
} | ||
|
||
export default Input; |
25 changes: 25 additions & 0 deletions
25
addons/a11y/.storybook/components/Form/components/Label.js
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 React, { PropTypes } from 'react'; | ||
|
||
const styles = { | ||
label: { | ||
padding: '0 6px', | ||
}, | ||
} | ||
|
||
function Label({ id, content }) { | ||
return ( | ||
<label | ||
style={styles.label} | ||
htmlFor={id} | ||
> | ||
{ content } | ||
</label> | ||
) | ||
} | ||
|
||
Label.propTypes = { | ||
content: PropTypes.string, | ||
id: PropTypes.string, | ||
}; | ||
|
||
export default Label; |
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,20 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
import Label from './Label'; | ||
import Input from './Input'; | ||
|
||
function Row({ label, input }) { | ||
return ( | ||
<div> | ||
{label} | ||
{input} | ||
</div> | ||
); | ||
} | ||
|
||
Row.propTypes = { | ||
label: PropTypes.instanceOf(Label), | ||
input: PropTypes.instanceOf(Input), | ||
} | ||
|
||
export default Row; |
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,9 @@ | ||
import Input from './Input'; | ||
import Label from './Label'; | ||
import Row from './Row'; | ||
|
||
export { | ||
Input, | ||
Label, | ||
Row, | ||
}; |
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,36 @@ | ||
import React from 'react'; | ||
|
||
import * as Form from './components'; | ||
|
||
import { storiesOf } from '@kadira/storybook'; | ||
import { checkA11y } from './../../../src'; | ||
|
||
import Faker from 'faker'; | ||
|
||
const label = Faker.lorem.word(); | ||
const placeholder = Faker.lorem.word(); | ||
|
||
storiesOf('<Form />', module) | ||
.addDecorator(checkA11y) | ||
.add('Without Label', () => ( | ||
<Form.Row | ||
input={<Form.Input />} | ||
/> | ||
)) | ||
.add ('With label', () => ( | ||
<Form.Row | ||
label={<Form.Label | ||
content={label} | ||
id="1" | ||
/>} | ||
input={<Form.Input id="1" />} | ||
/> | ||
)) | ||
.add ('With placeholder', () => ( | ||
<Form.Row | ||
input={<Form.Input | ||
id="1" | ||
placeholder={placeholder} | ||
/>} | ||
/> | ||
)) |
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,19 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
function Image({ src, alt, presentation }) { | ||
return ( | ||
<img | ||
src={src} | ||
alt={alt} | ||
role={presentation && 'presentation'} | ||
/> | ||
); | ||
} | ||
|
||
Image.propTypes = { | ||
src: PropTypes.string.isRequired, | ||
alt: PropTypes.string, | ||
presentation: PropTypes.bool, | ||
}; | ||
|
||
export default Image; |
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,29 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
|
||
import { checkA11y } from './../../../src'; | ||
|
||
import Image from './component'; | ||
|
||
import Faker from 'faker'; | ||
|
||
const image = Faker.image.animals(); | ||
const alt = Faker.lorem.words(); | ||
|
||
storiesOf('<Image />', module) | ||
.addDecorator(checkA11y) | ||
.add('Without alt', () => ( | ||
<Image src={image} /> | ||
)) | ||
.add('With alt', () => ( | ||
<Image | ||
src={image} | ||
alt={alt} | ||
/> | ||
)) | ||
.add('Presentation', () => ( | ||
<Image | ||
presentation | ||
src={image} | ||
/> | ||
)); |
23 changes: 23 additions & 0 deletions
23
addons/a11y/.storybook/components/Typography/components/Heading.js
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,23 @@ | ||
import React, { PropTypes, cloneElement } from 'react'; | ||
|
||
const headings = { | ||
1: (<h1 />), | ||
2: (<h2 />), | ||
3: (<h3 />), | ||
4: (<h4 />), | ||
}; | ||
|
||
function Heading({ level, children }) { | ||
return cloneElement(headings[level], {}, children) | ||
} | ||
|
||
Heading.propTypes = { | ||
level: PropTypes.oneOf([1, 2, 3, 4]), | ||
children: PropTypes.any, | ||
}; | ||
|
||
Heading.defaultProps = { | ||
level: 1, | ||
}; | ||
|
||
export default Heading; |
16 changes: 16 additions & 0 deletions
16
addons/a11y/.storybook/components/Typography/components/Link.js
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,16 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
function Link({ href, content }) { | ||
return ( | ||
<a href={href}> | ||
{ content } | ||
</a> | ||
); | ||
} | ||
|
||
Link.propTypes = { | ||
href: PropTypes.string, | ||
content: PropTypes.string, | ||
}; | ||
|
||
export default Link; |
15 changes: 15 additions & 0 deletions
15
addons/a11y/.storybook/components/Typography/components/Text.js
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,15 @@ | ||
import React, { PropTypes } from 'react'; | ||
|
||
function Text({ children }) { | ||
return ( | ||
<p> | ||
{children} | ||
</p> | ||
); | ||
} | ||
|
||
Text.propTypes = { | ||
children: PropTypes.any, | ||
}; | ||
|
||
export default Text; |
9 changes: 9 additions & 0 deletions
9
addons/a11y/.storybook/components/Typography/components/index.js
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,9 @@ | ||
import Heading from './Heading'; | ||
import Link from './Link'; | ||
import Text from './Text'; | ||
|
||
export { | ||
Heading, | ||
Link, | ||
Text, | ||
}; |
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,41 @@ | ||
import React from 'react'; | ||
import { storiesOf } from '@kadira/storybook'; | ||
|
||
import { checkA11y } from './../../../src'; | ||
|
||
import * as Typography from './components'; | ||
|
||
import Faker from 'faker'; | ||
|
||
const href = "javascript:void 0"; | ||
|
||
storiesOf('<Typography />', module) | ||
.addDecorator(checkA11y) | ||
.add('Correct', () => ( | ||
<div> | ||
<Typography.Heading level={1}> | ||
{Faker.lorem.sentence()} | ||
</Typography.Heading> | ||
|
||
<Typography.Text> | ||
{Faker.lorem.paragraph()} | ||
</Typography.Text> | ||
|
||
<Typography.Link | ||
content={`${Faker.lorem.words(4)}...`} | ||
href={href} | ||
/> | ||
</div> | ||
)) | ||
.add('Empty Heading', () => ( | ||
<Typography.Heading level={2} /> | ||
)) | ||
.add('Empty Paragraph', () => ( | ||
<Typography.Text /> | ||
)) | ||
.add('Empty Link', () => ( | ||
<Typography.Link href={href} /> | ||
)) | ||
.add('Link without href', () => ( | ||
<Typography.Link content={`${Faker.lorem.words(4)}...`} /> | ||
)); |
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 |
---|---|---|
@@ -1,2 +1,9 @@ | ||
import * as storybook from '@kadira/storybook'; | ||
storybook.configure(() => require('./stories'), module); | ||
|
||
const req = require.context('./components/', true, /stories\.js$/) | ||
|
||
const loadStories = () => | ||
req.keys().forEach(req); | ||
|
||
|
||
storybook.configure(loadStories, module) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.