Skip to content
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

Better addon apis & devkits for addons #6759

Merged
merged 45 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5ef2ab8
ADD api for setting the state of an addon
ndelangen Apr 10, 2019
bbc75ea
MIGRATE addon-background to use new api
ndelangen Apr 10, 2019
6d97924
ADD api for reading queryParams in client-api
ndelangen Apr 10, 2019
c236cb4
CHANGE addon-knobs so it can read value of knob from url
ndelangen Apr 10, 2019
00fce40
CHANGE addon-knob so it sets queryParams to actual values instead of …
ndelangen Apr 10, 2019
1b56857
ADD custom queryParameters to the generation of the new window URL
ndelangen Apr 10, 2019
5c550c5
CHANGE addon-knob to allow for setting of knob after loading from URL
ndelangen Apr 10, 2019
477836d
ADD customQueryParams to initial src of iframe
ndelangen Apr 10, 2019
a9e034f
IMPROVE setting of knob value in manager
ndelangen Apr 10, 2019
db71b8a
FIX queryParams not being serialized
ndelangen Apr 10, 2019
6eb7037
CHANGE the detection of existingKnob so it just checks the type & nam…
ndelangen Apr 10, 2019
7eb119b
FIX a double slash appearing in the URL after removing customParameters
ndelangen Apr 10, 2019
07d7891
Merge branch 'next' into core/managed-addon-state
ndelangen Apr 25, 2019
dc6eff8
FIX merge conflict
ndelangen Apr 25, 2019
7fddc11
Merge branch 'next' into core/managed-addon-state
ndelangen Apr 26, 2019
82b1e51
Merge branch 'next' into core/managed-addon-state
ndelangen Apr 26, 2019
37c41c3
WIP
ndelangen Apr 26, 2019
fdfa273
Merge branch 'next' into core/managed-addon-state
ndelangen May 8, 2019
9905178
WIP
ndelangen May 8, 2019
1b11536
ADD hooks api && CHANGE roundtrip devkit to use it
ndelangen May 9, 2019
89273a8
CHANGE to an actual tuple as return value for hook
ndelangen May 9, 2019
ce1f749
tweak the example a bit
ndelangen May 9, 2019
65f45cd
ADD async ready method to channel && complete the roundtrip addon
ndelangen May 9, 2019
e56fa60
ADD useParameter hook & apis && ADD a parameter addon devkit
ndelangen May 10, 2019
f6216ee
Merge branch 'next' into core/managed-addon-state
ndelangen May 10, 2019
7cb7d19
FIX CI cachingaddons
ndelangen May 10, 2019
5cdf31b
ADD a design-assets addon
ndelangen May 10, 2019
f4b31a3
FIX snapshots
ndelangen May 10, 2019
f432657
expand docs for design assets
ndelangen May 10, 2019
f1a46b6
ADD design assets addon to the readme
ndelangen May 10, 2019
276c246
DELETE the placeholder addon panel
ndelangen May 14, 2019
280e5b5
Merge branch 'next' into core/managed-addon-state
ndelangen May 14, 2019
b6b3f31
Merge branch 'next' into core/managed-addon-state
ndelangen May 15, 2019
eae8b1d
IMPROVE the apis
ndelangen May 15, 2019
3f4e864
IMPROVE addon-design-assets
ndelangen May 15, 2019
987cbe6
UPGRADE react requirement for lib/api
ndelangen May 15, 2019
8d1e304
CHANGE description of design asset addon && FIX indentation && CLEAMUP
ndelangen May 16, 2019
1e850c9
Merge branch 'next' into core/managed-addon-state
ndelangen May 16, 2019
a3e3149
IMPROVE explanation of devkits
ndelangen May 16, 2019
1d1e4b9
IMPROVE docs code blocks & h2
ndelangen May 16, 2019
8d39bea
IMPROVE documentation for apis
ndelangen May 16, 2019
20b440c
IMPROVE the writing addons documentation
ndelangen May 16, 2019
3e80cf3
Merge branch 'next' into core/managed-addon-state
ndelangen May 20, 2019
7d0da21
FIX snapshots
ndelangen May 20, 2019
88ec8de
Merge branch 'next' into core/managed-addon-state
ndelangen Jun 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
- node_modules
- examples
- addons
- dev-kits
- app
- lib
chromatic:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package OpenSourceProjects_Storybook.buildTypes

import jetbrains.buildServer.configs.kotlin.v2017_2.*
import jetbrains.buildServer.configs.kotlin.v2017_2.buildFeatures.commitStatusPublisher
import jetbrains.buildServer.configs.kotlin.v2017_2.buildSteps.script
import jetbrains.buildServer.configs.kotlin.v2017_2.triggers.vcs
import jetbrains.buildServer.configs.kotlin.v2017_2.triggers.retryBuild
import jetbrains.buildServer.configs.kotlin.v2017_2.triggers.VcsTrigger

object OpenSourceProjects_Storybook_Bootstrap : BuildType({
uuid = "9f9177e7-9ec9-4e2e-aabb-d304fd667712"
id = "OpenSourceProjects_Storybook_Bootstrap"
name = "Bootstrap"

artifactRules = """
addons/*/dist/** => dist.zip/addons
addons/storyshots/*/dist/** => dist.zip/addons/storyshots
app/*/dist/** => dist.zip/app
dev-kits/*/dist/** => dist.zip/dev-kits
lib/*/dist/** => dist.zip/lib
lib/core/dll/** => dist.zip/lib/core/dll
""".trimIndent()

vcs {
root(OpenSourceProjects_Storybook.vcsRoots.OpenSourceProjects_Storybook_HttpsGithubComStorybooksStorybookRefsHeadsMaster)
}

steps {
script {
name = "Bootstrap"
scriptContent = """
#!/bin/sh

set -e -x

yarn
yarn bootstrap --core
""".trimIndent()
dockerImage = "node:%docker.node.version%"
}
}

triggers {
vcs {
quietPeriodMode = VcsTrigger.QuietPeriodMode.USE_DEFAULT
triggerRules = "-:comment=^TeamCity change:**"
branchFilter = """
+:pull/*
+:release/*
+:master
+:next
+:snyk-fix-*
""".trimIndent()
enabled = false
}
retryBuild {
delaySeconds = 60
enabled = false
}
}

features {
commitStatusPublisher {
publisher = github {
githubUrl = "https://api.github.com"
authType = personalToken {
token = "credentialsJSON:5ffe2d7e-531e-4f6f-b1fc-a41bfea26eaa"
}
}
param("github_oauth_user", "Hypnosphi")
}
}

requirements {
doesNotContain("env.OS", "Windows")
}

cleanup {
artifacts(days = 1)
}
})
1 change: 1 addition & 0 deletions ADDONS_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
|[centered](addons/centered) |+| |+|+| |+|+| |+| |+|+|
|[contexts](addons/contexts) |+| |+| | | | | | | | |+|
|[events](addons/events) |+| |+|+|+|+|+|+| | |+|+|
|[design assets](addons/design-assets) |+| |+|+|+|+|+|+|+|+|+|+|
|[graphql](addons/graphql) |+| | | | | | | | | | | |
|[google-analytics](addons/google-analytics) |+|+|+|+|+|+|+|+|+|+|+|+|
|[info](addons/info) |+| | | | | | | | | | | |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ For additional help, join us [in our Discord](https://discord.gg/sMFvFsG) or [Sl
| [centered](addons/centered/) | Center the alignment of your components within the Storybook UI |
| [contexts](addons/contexts/) | Interactively inject component contexts for stories in the Storybook UI |
| [cssresources](addons/cssresources/) | Dynamically add/remove css resources to the component iframe |
| [design assets](addons/design-assets/) | View images, videos, weblinks alongside your story |
| [events](addons/events/) | Interactively fire events to components that respond to EventEmitter |
| [graphql](addons/graphql/) | Query a GraphQL server within Storybook stories |
| [google-analytics](addons/google-analytics) | Reports google analytics on stories |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ exports[`A11YPanel should render report 1`] = `
display: -ms-flexbox;
display: flex;
background: #FFFFFF;
z-index: 1;
}

.emotion-3 {
Expand Down Expand Up @@ -215,14 +216,14 @@ exports[`A11YPanel should render report 1`] = `
"inserted": Object {
"0": true,
"110qmus": true,
"11xgcgt": true,
"1551xjo": true,
"15paq49": true,
"1977chw": true,
"19mcg9j": true,
"1ez3l8h": true,
"1kbt4a0": true,
"1l7fvsg": true,
"1myfomu": true,
"1vwgrhn": true,
"4ryd4s": true,
"6hqipu": true,
Expand Down Expand Up @@ -490,7 +491,7 @@ exports[`A11YPanel should render report 1`] = `
data-emotion="css"
>

.emotion-4{position:absolute;bottom:0;right:0;max-width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;background:#FFFFFF;}
.emotion-4{position:absolute;bottom:0;right:0;max-width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;background:#FFFFFF;z-index:1;}
</style>
<style
data-emotion="css"
Expand Down Expand Up @@ -716,7 +717,7 @@ exports[`A11YPanel should render report 1`] = `
data-emotion="css"
>

.emotion-4{position:absolute;bottom:0;right:0;max-width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;background:#FFFFFF;}
.emotion-4{position:absolute;bottom:0;right:0;max-width:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;background:#FFFFFF;z-index:1;}
</style>,
<style
data-emotion="css"
Expand Down
34 changes: 24 additions & 10 deletions addons/backgrounds/src/containers/BackgroundSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ const getSelectedBackgroundColor = (list: Input[], currentSelectedValue: string)
return 'transparent';
};

const mapper = ({ api, state }: Combo): { items: Input[] } => {
const mapper = ({ api, state }: Combo): { items: Input[]; selected: string | null } => {
const story = state.storiesHash[state.storyId];
const list = story ? api.getParameters(story.id, PARAM_KEY) : [];
const selected = state.addons[PARAM_KEY] || null;

return { items: list || [] };
return { items: list || [], selected };
};

const getDisplayedItems = memoize(10)((list: Input[], selected: State['selected'], change) => {
const getDisplayedItems = memoize(10)((list: Input[], selected: string | null, change) => {
let availableBackgroundSelectorItems: Item[] = [];

if (selected !== 'transparent') {
Expand All @@ -91,21 +92,34 @@ const getDisplayedItems = memoize(10)((list: Input[], selected: State['selected'
return availableBackgroundSelectorItems;
});

interface GlobalState {
name: string | undefined;
selected: string | undefined;
}

interface State {
selected: string;
expanded: boolean;
}

export class BackgroundSelector extends Component<{ api: API }, State> {
interface Props {
api: API;
}

export class BackgroundSelector extends Component<Props, State> {
state: State = {
selected: null,
expanded: false,
};

change = ({ selected, name }: { selected: string; name: string }) => {
change = ({ selected, name }: GlobalState) => {
const { api } = this.props;
const { expanded } = this.state;
if (expanded) {
this.setState({ expanded: false });
}
if (typeof selected === 'string') {
api.setAddonState<string>(PARAM_KEY, selected);
}
api.emit(EVENTS.UPDATE, { selected, name });
this.setState({ selected, expanded: false });
};

onVisibilityChange = (s: boolean) => {
Expand All @@ -116,11 +130,11 @@ export class BackgroundSelector extends Component<{ api: API }, State> {
};

render() {
const { expanded, selected } = this.state;
const { expanded } = this.state;

return (
<Consumer filter={mapper}>
{({ items }: { items: Input[] }) => {
{({ items, selected }: ReturnType<typeof mapper>) => {
const selectedBackgroundColor = getSelectedBackgroundColor(items, selected);
const links = getDisplayedItems(items, selectedBackgroundColor, this.change);

Expand Down
55 changes: 55 additions & 0 deletions addons/design-assets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Storybook addon for design assets

This addon for storybook allows you to link to image files, other files, and even url's for embedding in the storybook panel!

You can add as many assets to a single story as you want.

## Install

```sh
npm install @storybook/addon-design-assets
```

## Usage
within `addons.js`:

```js
import '@storybook/addon-design-assets/register';
```

within your stories:
```js
import { storiesOf } from '@storybook/react';

import imageUrl from './images/my-image.jpg';

storiesOf('root|group/component', module)
.addParameters({
assets: [
imageUrl, // link to a file imported
'https://via.placeholder.com/300/09f/fff.png', // link to an external image
'https://www.example.com', // link to a webpage
'https://www.example.com?id={id}', // link to a webpage with the current story's id in the url
],
})
.add('variant', () => <div>your story here</div>);
```

If you have a set of different assets on 1 story, you might want to name then:
```js
import { storiesOf } from '@storybook/react';

import imageUrl from './images/my-image.jpg';

storiesOf('root|group/component', module)
.addParameters({
assets: [{
url: 'https://via.placeholder.com/300/09f/fff.png', // link to an external image
name: 'blue',
}, {
url: 'https://via.placeholder.com/300/f90/fff.png', // link to an external image
name: 'orange',
}],
})
.add('variant', () => <div>your story here</div>);
```
48 changes: 48 additions & 0 deletions addons/design-assets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "@storybook/addon-design-assets",
"version": "5.1.0-rc.5",
"description": "Design asset preview for storybook",
"keywords": [
"addon",
"storybook",
"parameter",
"design",
"assets",
"files",
"viewer"
],
"homepage": "https://github.com/storybooks/storybook#readme",
"bugs": {
"url": "https://github.com/storybooks/storybook/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/storybooks/storybook.git",
"directory": "addons/design-assets"
},
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "5.1.0-rc.5",
"@storybook/api": "5.1.0-rc.5",
"@storybook/client-logger": "5.1.0-rc.5",
"@storybook/components": "5.1.0-rc.5",
"@storybook/core-events": "5.1.0-rc.5",
"@storybook/theming": "5.1.0-rc.5",
"common-tags": "^1.8.0",
"core-js": "^2.6.5",
"global": "^4.3.2",
"react": "^16.8.4",
"use-image": "^1.0.3"
},
"devDependencies": {
"@types/common-tags": "^1.8.0"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions addons/design-assets/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./dist/register');
3 changes: 3 additions & 0 deletions addons/design-assets/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ADDON_ID = 'storybook/design-assets';
export const PANEL_ID = `${ADDON_ID}/panel`;
export const PARAM_KEY = `assets`;
Loading