-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add addon background to monorepo #2220
Merged
Merged
Changes from all commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
df0c6ca
setup project
a2ece0c
add some info to the readme
f84c9c6
OPS-2135 Adding react dependency
edolyne 673837d
OPS-2135 Setting a blank background state on unmount
edolyne 9a312de
added tests for swatch component
JakeDawkins fc2a77b
added tests for swatch component
JakeDawkins 25e352a
added skeleton of backgroundPanel tests
JakeDawkins f191fac
filled out tests for the backgroundPanel
JakeDawkins 8c87516
removed ghooks from package
JakeDawkins f13baad
SYS-2135 Adding system font
edolyne 89f0b16
fix code block usage
7c581fb
fixed a few lint errors, commented out failing test for now, setup tr…
9703944
added coverage reports
b43653a
update badges
04a8d2a
added docs
b5bd13d
fix docs build
6e161cb
updated docs
fbabdd9
short docs and add typscript definitions
6a3d41a
minor bump for ts fix
81c3d0e
better registration
3043590
setup url based rendering
6d0e21d
updated readme
af203b3
bump version
0d268bb
update docs
3d28569
SYS-2136 Adding test for setting and unsetting query sting
edolyne a309d38
added test for default background swatch showing
JakeDawkins 7364bbb
added test for default background swatch showing
JakeDawkins 50ef165
added tests for BackgroundPanel
JakeDawkins 20b74fb
fixed failing tests
JakeDawkins 09162b5
Fixes HMR when used as a global decorator
Coobaha 7e84ed9
Tests for prop updates
15f3661
Tests pass
3f4fafe
update changelog and version bump
a71125d
update build
6ac4d3d
Fixed typo ;)
JakeDawkins a227715
added react-dom dependency and updated react dep
JakeDawkins d65656e
add overflow scroll to allow scrolling again (#17)
c8129e1
Support background-images (#15)
97ec219
0.0.5
b0d34a6
update changelog
b987342
allow default background (#21)
bfce94f
set default background color (#23)
802e1d6
Fixed layout when background text is too long.
281b32a
Bump Storybook dependencies to v3
chris-verclytte c713fdc
UPDATE dependencies && RENAME package name
ndelangen 1dbfc36
REMOVE coverage reporting
ndelangen 8c7b889
FIX example && linting
ndelangen cdbcb9d
Update Readme
ndelangen 3b2d1e2
Linting
ndelangen 0d22ce3
convert to js with babel
psimyn 8698781
disable eslint, plan to get everything else working first
psimyn 849b505
fix warnings from React import. remove object-assign
psimyn c1d77a0
Update package name references and repos
chris-verclytte 7a5601c
Update changelog
chris-verclytte a5f4a5c
remove unused eslint packages for now
psimyn 4e92209
REMOVE docs
ndelangen e83e864
WIP
ndelangen ef83a81
Merge branch 'master' into ndelangen/import-addon-background
Hypnosphi 81420d2
FIX unittests
ndelangen 3c6bff8
Merge branch 'master' into ndelangen/import-addon-background
Hypnosphi a119a99
FIX linting
ndelangen 037542d
Merge branch 'ndelangen/import-addon-background' of github.com:storyb…
ndelangen 9285aae
DELETE local licence
ndelangen 30fb685
Fix linting and accessibility
Hypnosphi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,55 @@ | ||
# addon-backgrounds | ||
|
||
[![Build Status](https://travis-ci.org/storybooks/addon-backgrounds.svg?branch=travis)](https://travis-ci.org/storybooks/addon-backgrounds) | ||
|
||
![React Storybook Screenshot](./.storybook/backgrounds.gif) | ||
|
||
### Getting Started | ||
|
||
```sh | ||
npm i --save @storybook/addon-backgrounds | ||
``` | ||
|
||
Then create a file called `addons.js` in your storybook config. | ||
|
||
Add following content to it: | ||
|
||
```js | ||
import '@storybook/addon-backgrounds/register'; | ||
``` | ||
|
||
Then write your stories like this: | ||
|
||
```js | ||
import React from 'react'; | ||
import { storiesOf } from "@storybook/react"; | ||
import backgrounds from "@storybook/addon-backgrounds"; | ||
|
||
storiesOf("Button", module) | ||
.addDecorator(backgrounds([ | ||
{ name: "twitter", value: "#00aced", default: true }, | ||
{ name: "facebook", value: "#3b5998" }, | ||
])) | ||
.add("with text", () => <button>Click me</button>); | ||
``` | ||
|
||
### Development | ||
|
||
This project is built using typescript and is tested with jest. To get started, clone this repo and run the following command: | ||
|
||
```bash | ||
$ npm install # install node deps | ||
``` | ||
|
||
To run the project locally, run: | ||
|
||
```bash | ||
$ npm run storybook # for storybook testing | ||
# (coming soon) $ npm run test-watch # for testing | ||
``` | ||
|
||
To test the project run: | ||
|
||
```bash | ||
$ npm test | ||
``` |
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,32 @@ | ||
{ | ||
"name": "@storybook/addon-backgrounds", | ||
"version": "3.2.14", | ||
"description": "A storybook addon to show different backgrounds for your preview", | ||
"keywords": [ | ||
"addon", | ||
"background", | ||
"react", | ||
"storybook" | ||
], | ||
"homepage": "https://storybook.js.org", | ||
"bugs": { | ||
"url": "https://github.com/storybooks/storybook/issues" | ||
}, | ||
"license": "MIT", | ||
"author": "jbaxleyiii", | ||
"main": "dist/index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybooks/storybook.git" | ||
}, | ||
"scripts": { | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"prop-types": "^15.6.0" | ||
}, | ||
"peerDependencies": { | ||
"@storybook/addons": "^3.2.14", | ||
"react": "*" | ||
} | ||
} |
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 @@ | ||
require('./dist/register'); |
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,125 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import addons from '@storybook/addons'; | ||
import EventEmitter from 'events'; | ||
|
||
import Swatch from './Swatch'; | ||
|
||
const style = { | ||
font: { | ||
fontFamily: | ||
"-apple-system,'.SFNSText-Regular', 'San Francisco', Roboto, 'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif", | ||
fontSize: '14px', | ||
}, | ||
}; | ||
|
||
const defaultBackground = { | ||
name: 'default', | ||
value: 'transparent', | ||
}; | ||
|
||
const instructionsHtml = ` | ||
import { storiesOf } from "@storybook/react"; | ||
import backgrounds from "@storybook/addon-backgrounds"; | ||
|
||
storiesOf("First Component", module) | ||
.addDecorator(backgrounds([ | ||
{ name: "twitter", value: "#00aced" }, | ||
{ name: "facebook", value: "#3b5998" }, | ||
])) | ||
.add("First Button", () => <button>Click me</button>); | ||
`.trim(); | ||
|
||
const Instructions = () => ( | ||
<div style={Object.assign({ padding: '20px' }, style.font)}> | ||
<h5 style={{ fontSize: '16px' }}>Setup Instructions</h5> | ||
<p> | ||
Please add the background decorator definition to your story. The background decorate accepts | ||
an array of items, which should include a name for your color (preferably the css class name) | ||
and the corresponding color / image value. | ||
</p> | ||
<p>Below is an example of how to add the background decorator to your story definition.</p> | ||
<pre | ||
style={{ | ||
padding: '30px', | ||
display: 'block', | ||
background: 'rgba(19,19,19,0.9)', | ||
color: 'rgba(255,255,255,0.95)', | ||
marginTop: '15px', | ||
lineHeight: '1.75em', | ||
}} | ||
> | ||
<code>{instructionsHtml}</code> | ||
</pre> | ||
</div> | ||
); | ||
|
||
export default class BackgroundPanel extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const { channel, api } = props; | ||
|
||
// A channel is explicitly passed in for testing | ||
if (channel) { | ||
this.channel = channel; | ||
} else { | ||
this.channel = addons.getChannel(); | ||
} | ||
|
||
this.state = { backgrounds: [] }; | ||
|
||
this.channel.on('background-set', backgrounds => { | ||
this.setState({ backgrounds }); | ||
const currentBackground = api.getQueryParam('background'); | ||
|
||
if (currentBackground) { | ||
this.setBackgroundInPreview(currentBackground); | ||
} else if (backgrounds.filter(x => x.default).length) { | ||
const defaultBgs = backgrounds.filter(x => x.default); | ||
this.setBackgroundInPreview(defaultBgs[0].value); | ||
} | ||
}); | ||
|
||
this.channel.on('background-unset', () => { | ||
this.setState({ backgrounds: [] }); | ||
api.setQueryParams({ background: null }); | ||
}); | ||
} | ||
|
||
setBackgroundInPreview = background => this.channel.emit('background', background); | ||
|
||
setBackgroundFromSwatch = background => { | ||
this.setBackgroundInPreview(background); | ||
this.props.api.setQueryParams({ background }); | ||
}; | ||
|
||
render() { | ||
const backgrounds = [...this.state.backgrounds]; | ||
|
||
if (!backgrounds.length) return <Instructions />; | ||
|
||
const hasDefault = backgrounds.filter(x => x.default).length; | ||
if (!hasDefault) backgrounds.push(defaultBackground); | ||
|
||
return ( | ||
<div style={{ display: 'inline-block', padding: '15px' }}> | ||
{backgrounds.map(({ value, name }) => ( | ||
<div key={`${name} ${value}`} style={{ display: 'inline-block', padding: '5px' }}> | ||
<Swatch value={value} name={name} setBackground={this.setBackgroundFromSwatch} /> | ||
</div> | ||
))} | ||
</div> | ||
); | ||
} | ||
} | ||
BackgroundPanel.propTypes = { | ||
api: PropTypes.shape({ | ||
getQueryParam: PropTypes.func, | ||
setQueryParams: PropTypes.func, | ||
}).isRequired, | ||
channel: PropTypes.instanceOf(EventEmitter), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails in
Let's use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok sure |
||
}; | ||
BackgroundPanel.defaultProps = { | ||
channel: undefined, | ||
}; |
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,65 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const style = { | ||
swatches: { | ||
backgroundColor: '#fff', | ||
textAlign: 'center', | ||
padding: '0', | ||
border: '1px solid rgba(0,0,0,0.1)', | ||
borderRadius: '4px', | ||
cursor: 'pointer', | ||
display: 'inline-block', | ||
width: '175px', | ||
verticalAlign: 'top', | ||
wordWrap: 'break-word', | ||
}, | ||
swatch: { | ||
height: '80px', | ||
borderRadius: '4px 4px 0 0', | ||
transition: 'opacity 0.25s ease-in-out', | ||
borderBottom: '1px solid rgba(0,0,0,0.1)', | ||
}, | ||
listStyle: { listStyle: 'none' }, | ||
pushBottom: { marginBottom: '10px' }, | ||
pushLeft: { marginLeft: '10px' }, | ||
soft: { paddingLeft: '10px', paddingRight: '10px' }, | ||
hard: { padding: '0' }, | ||
flush: { margin: '0' }, | ||
font: { | ||
fontFamily: | ||
"-apple-system, '.SFNSText-Regular', 'San Francisco', Roboto, 'Segoe UI', 'Helvetica Neue', 'Lucida Grande', sans-serif", | ||
fontSize: '14px', | ||
wordBreak: 'break-word', | ||
}, | ||
}; | ||
|
||
const Swatch = ({ name, value, setBackground }) => ( | ||
<button | ||
style={Object.assign({}, style.swatches, style.listStyle, style.hard)} | ||
onClick={() => setBackground(value)} | ||
// Prevent focusing on mousedown | ||
onMouseDown={event => event.preventDefault()} | ||
> | ||
<div | ||
style={Object.assign({}, style.swatch, { | ||
background: value, | ||
backgroundSize: 'cover', | ||
backgroundPosition: 'center', | ||
})} | ||
/> | ||
<div style={Object.assign({}, style.listStyle, style.soft)}> | ||
<h4 style={Object.assign({ float: 'left', fontWeight: 'bold' }, style.font)}>{name}:</h4> | ||
<h4 style={Object.assign({ float: 'right', fontWeight: 'normal' }, style.font)}> | ||
<em>{value}</em> | ||
</h4> | ||
</div> | ||
</button> | ||
); | ||
Swatch.propTypes = { | ||
name: PropTypes.string.isRequired, | ||
value: PropTypes.string.isRequired, | ||
setBackground: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Swatch; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is it still typescript?
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.
good point, will remove it. No we removed the typescript.