-
Notifications
You must be signed in to change notification settings - Fork 8
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
1 parent
1513ddd
commit 4eebe4f
Showing
6 changed files
with
94 additions
and
6 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
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
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,49 @@ | ||
import React from 'react'; | ||
import { lighten } from 'polished'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** Button with react PropTypes */ | ||
export const Button = ({ disabled, label, onClick, style, backgroundColor, color, type, padding }) => ( | ||
<button | ||
type={type} | ||
disabled={disabled} | ||
onClick={onClick} | ||
style={{ ...style, backgroundColor, color: lighten(disabled ? 0.4 : 0, color), padding }} | ||
> | ||
{label} | ||
</button> | ||
); | ||
|
||
Button.defaultProps = { | ||
disabled: false, | ||
label: 'default', | ||
onClick: () => {}, | ||
style: {}, | ||
backgroundColor: '#fefefe', | ||
color: 'black', | ||
type: 'button', | ||
padding: 5, | ||
}; | ||
|
||
Button.propTypes = { | ||
/** Boolean indicating whether the button should render as disabled */ | ||
disabled: PropTypes.bool, | ||
/** button label. */ | ||
label: PropTypes.string, | ||
/** onClick handler */ | ||
onClick: PropTypes.func, | ||
/** Custom styles */ | ||
style: PropTypes.shape({}), | ||
|
||
/** Background color */ | ||
backgroundColor: PropTypes.string, | ||
|
||
/** Text color, default black */ | ||
color: PropTypes.string, | ||
|
||
/** Button type */ | ||
type: PropTypes.oneOf(['button', 'reset', 'submit']), | ||
|
||
/** Numeric field type */ | ||
padding: PropTypes.number, | ||
}; |
38 changes: 38 additions & 0 deletions
38
examples/storybook-5/src/stories/smart-prop-type.stories.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,38 @@ | ||
import React from 'react'; | ||
import { Button } from '../components/PropTypesButton'; | ||
|
||
export default { | ||
title: 'Storybook/Smart PropTypes', | ||
parameters: { | ||
component: Button, | ||
}, | ||
}; | ||
|
||
export const allProps = props => <Button {...props} />; | ||
|
||
export const onlyColors = props => <Button label="Choose colors" {...props} />; | ||
|
||
onlyColors.story = { | ||
parameters: { | ||
addonControls: { | ||
smart: { | ||
include: ['color', 'backgroundColor'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const noColors = () => <Button label="Choose colors" />; | ||
|
||
noColors.story = { | ||
parameters: { | ||
addonControls: { | ||
smart: { | ||
exclude: ['color', 'backgroundColor'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
// this story does not have parameters, and smart controls will be disabled for it | ||
export const noProps = () => <Button label="No properties" />; |
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
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