-
-
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
Svelte support #3770
Svelte support #3770
Changes from 53 commits
1381b93
40660ea
306b580
5f64ea3
f64ec68
295f4e2
adabc88
9acf5f5
ce09ea7
cf72ffd
ba11d16
cecc676
bab002e
0eed975
a677702
43b3660
1035614
e65573e
3dbe010
43986fb
037187e
09ca251
75e1fd4
0f4f756
0228962
3844c54
27104f8
03c6c0c
63f09e0
0afd157
17cb74f
bad4b31
1a4cc60
15ee3c6
ef2e19c
a7dd460
284a443
2f8a3ad
edd4770
3ca5be1
f5e5c62
02bc696
05f01ad
cf7b724
e33d5f2
a953fce
35b477f
042ca5d
63b568f
e84768b
ef4a5eb
33006b8
28a4bef
73f5951
b2912e7
157a580
bed1a50
b848466
c636cb5
82f8119
ec832b4
fb333e2
2282813
59ce0d9
2bc8353
dd1e609
cabb323
2c8b958
57c24b3
1b46de2
6096035
7fc81d9
b5bd22b
06b0ac7
d842cea
9a4e2db
209ae29
dc2beac
f79c35b
f41eb61
450e4a6
5c3dbf2
57f1b09
b97bb40
13d09e6
c94f632
9464939
c173e40
846ed34
c60fe16
37c1f5f
0b9f38a
70b4dd1
0fffe6e
86afcac
2a5e762
60ff6ab
fb28658
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
## Addon / Framework Support Table | ||
|
||
| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)| [Marko](app/marko)| | ||
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:| | ||
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| | ||
|[actions](addons/actions) |+|+|+|+|+|+|+|+| | ||
|[backgrounds](addons/backgrounds) |+| |+|+|+|+|+|+| | ||
|[centered](addons/centered) |+| |+|+| |+|+| | | ||
|[events](addons/events) |+| |+|+|+|+|+|+| | ||
|[graphql](addons/graphql) |+| | | | | | | | | ||
|[info](addons/info) |+| | | | | | | | | ||
|[jest](addons/jest) |+| | |+| | |+| | | ||
|[knobs](addons/knobs) |+|+|+|+|+|+|+|+| | ||
|[links](addons/links) |+|+|+|+|+|+|+| | | ||
|[notes](addons/notes) |+| |+|+|+|+|+| | | ||
|[options](addons/options) |+|+|+|+|+|+|+| | | ||
|[storyshots](addons/storyshots) |+|+|+|+| | |+| | | ||
|[storysource](addons/storysource)|+| |+|+|+|+|+|+| | ||
|[viewport](addons/viewport) |+| |+|+|+|+|+|+| | ||
| |[React](app/react)|[React Native](app/react-native)|[Vue](app/vue)|[Angular](app/angular)| [Polymer](app/polymer)| [Mithril](app/mithril)| [HTML](app/html)| [Marko](app/marko)| [Svelte](app/svelte)| | ||
| ----------- |:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:|:-------:| | ||
|[a11y](addons/a11y) |+| |+|+|+|+|+|+| | | ||
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.
The error does not seem to affect functionality though 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. Hmm that's unfortunate, I wonder if axe is actively maintained and we could open a ticket with the maintainers.. |
||
|[actions](addons/actions) |+|+|+|+|+|+|+|+|+| | ||
|[backgrounds](addons/backgrounds) |+| |+|+|+|+|+|+|+| | ||
|[centered](addons/centered) |+| |+|+| |+|+| |+| | ||
|[events](addons/events) |+| |+|+|+|+|+|+| | | ||
|[graphql](addons/graphql) |+| | | | | | | | | | ||
|[info](addons/info) |+| | | | | | | | | | ||
|[jest](addons/jest) |+| | |+| | |+| | | | ||
|[knobs](addons/knobs) |+|+|+|+|+|+|+|+|+| | ||
|[links](addons/links) |+|+|+|+|+|+|+| |+| | ||
|[notes](addons/notes) |+| |+|+|+|+|+| |+| | ||
|[options](addons/options) |+|+|+|+|+|+|+| |+| | ||
|[storyshots](addons/storyshots) |+|+|+|+| | |+| |+| | ||
|[storysource](addons/storysource)|+| |+|+|+|+|+|+|+| | ||
|[viewport](addons/viewport) |+| |+|+|+|+|+|+|+| |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div class="svelte-centered-wrapper" style="{centeredStyles.style}"> | ||
<div class="svelte-centered-container" style="{centeredStyles.innerStyle}"> | ||
<svelte:component this="{OriginalComponent}" {...originalData} /> | ||
</div> | ||
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. Does not work in conjunction with 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 will be fixed in plumpNation#1 |
||
</div> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
OriginalComponent: null, | ||
originalData: {}, | ||
centeredStyles: {} | ||
}; | ||
} | ||
}; | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { document } from 'global'; | ||
|
||
/** | ||
* Not all frameworks support an object for the style attribute but we want all to | ||
* consume `styles.json`. Since `styles.json` uses standard style properties for keys, | ||
* we can just set them on an element and then get the string result of that element's | ||
* `style` attribute. This also means that invalid styles are filtered out. | ||
* | ||
* @param {Object} jsonStyles | ||
* @returns {string} | ||
* @see https://stackoverflow.com/questions/38533544/jsx-css-to-inline-styles | ||
*/ | ||
export default function jsonToCss(jsonStyles) { | ||
const frag = document.createElement('div'); | ||
|
||
Object.keys(jsonStyles).forEach(key => { | ||
frag.style[key] = jsonStyles[key]; | ||
}); | ||
|
||
return frag.getAttribute('style'); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Centered from './components/Centered.svelte'; | ||
import styles from './styles'; | ||
import json2CSS from './helpers/json2CSS'; | ||
|
||
const centeredStyles = { | ||
/** @type {string} */ | ||
style: json2CSS(styles.style), | ||
/** @type {string} */ | ||
innerStyle: json2CSS(styles.innerStyle), | ||
}; | ||
|
||
/** | ||
* This functionality works by passing the svelte story component into another | ||
* svelte component that has the single purpose of centering the story component | ||
* using a wrapper and container. | ||
* | ||
* We use the special element <svelte:component /> to achieve this. | ||
* | ||
* @see https://svelte.technology/guide#svelte-component | ||
*/ | ||
export default function(storyFn) { | ||
const { Component: OriginalComponent, data: originalData } = storyFn(); | ||
|
||
const centeredData = { | ||
OriginalComponent, | ||
centeredStyles, | ||
originalData, | ||
}; | ||
|
||
return { Component: Centered, data: centeredData }; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/svelte'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import global from 'global'; | ||
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. I don't see any committed snapshots, does this addon really work? 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. Not yet, I had to stop and sleep yesterday, got a bit late 😸 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 should now be generating snapshots. |
||
import hasDependency from '../hasDependency'; | ||
import configure from '../configure'; | ||
|
||
function test(options) { | ||
return ( | ||
options.framework === 'svelte' || (!options.framework && hasDependency('@storybook/svelte')) | ||
); | ||
} | ||
|
||
function load(options) { | ||
global.STORYBOOK_ENV = 'svelte'; | ||
|
||
const { configPath, config } = options; | ||
const storybook = require.requireActual('@storybook/svelte'); | ||
|
||
configure({ configPath, config, storybook }); | ||
|
||
return { | ||
framework: 'svelte', | ||
renderTree: require.requireActual('./renderTree').default, | ||
renderShallowTree: () => { | ||
throw new Error('Shallow renderer is not supported for svelte'); | ||
}, | ||
storybook, | ||
}; | ||
} | ||
|
||
export default { | ||
load, | ||
test, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { document } from 'global'; | ||
|
||
/** | ||
* Provides functionality to convert your raw story to the resulting markup. | ||
* | ||
* Storybook snapshots need the rendered markup that svelte outputs, | ||
* but since we only have the story config data ({ Component, data }) in | ||
* the Svelte stories, we need to mount the component, and then return the | ||
* resulting HTML. | ||
* | ||
* If we don't render to HTML, we will get a snapshot of the raw story | ||
* i.e. ({ Component, data }). | ||
*/ | ||
function getRenderedTree(story, context) { | ||
const { Component, data } = story.render(context); | ||
|
||
// We need to create a target to mount onto. | ||
const target = document.createElement('section'); | ||
|
||
new Component({ target, data }); // eslint-disable-line | ||
|
||
// Classify the target so that it is clear where the markup | ||
// originates from, and that it is specific for snapshot tests. | ||
target.className = 'storybook-snapshot-container'; | ||
|
||
return target; | ||
} | ||
|
||
export default getRenderedTree; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
docs | ||
.babelrc |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Storybook for Svelte | ||
|
||
[![Build Status on CircleCI](https://circleci.com/gh/storybooks/storybook.svg?style=shield)](https://circleci.com/gh/storybooks/storybook) | ||
[![CodeFactor](https://www.codefactor.io/repository/github/storybooks/storybook/badge)](https://www.codefactor.io/repository/github/storybooks/storybook) | ||
[![Known Vulnerabilities](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847/badge.svg)](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847) | ||
[![BCH compliance](https://bettercodehub.com/edge/badge/storybooks/storybook)](https://bettercodehub.com/results/storybooks/storybook) [![codecov](https://codecov.io/gh/storybooks/storybook/branch/master/graph/badge.svg)](https://codecov.io/gh/storybooks/storybook) | ||
[![Storybook Slack](https://now-examples-slackin-rrirkqohko.now.sh/badge.svg)](https://now-examples-slackin-rrirkqohko.now.sh/) | ||
[![Backers on Open Collective](https://opencollective.com/storybook/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/storybook/sponsors/badge.svg)](#sponsors) | ||
|
||
* * * | ||
|
||
Storybook for Svelte is a UI development environment for your Svelte components. | ||
With it, you can visualize different states of your UI components and develop them interactively. | ||
|
||
![Storybook Screenshot](https://github.com/storybooks/storybook/blob/master/app/svelte/docs/demo.gif) | ||
|
||
Storybook runs outside of your app. | ||
So you can develop UI components in isolation without worrying about app specific dependencies and requirements. | ||
|
||
## Getting Started | ||
|
||
```sh | ||
npm i -g @storybook/cli | ||
cd my-svelte-app | ||
getstorybook | ||
``` | ||
|
||
For more information visit: [storybook.js.org](https://storybook.js.org) | ||
|
||
* * * | ||
|
||
Storybook also comes with a lot of [addons](https://storybook.js.org/addons/introduction) and a great API to customize as you wish. | ||
You can also build a [static version](https://storybook.js.org/basics/exporting-storybook) of your storybook and deploy it anywhere you want. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/server/build'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/server'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "@storybook/svelte", | ||
"version": "4.0.0-alpha.9", | ||
"description": "Storybook for Svelte: Develop Svelte Component in isolation with Hot Reloading.", | ||
"homepage": "https://github.com/storybooks/storybook/tree/master/apps/svelte", | ||
"bugs": { | ||
"url": "https://github.com/storybooks/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybooks/storybook.git" | ||
}, | ||
"license": "MIT", | ||
"main": "dist/client/index.js", | ||
"jsnext:main": "src/client/index.js", | ||
"bin": { | ||
"build-storybook": "./bin/build.js", | ||
"start-storybook": "./bin/index.js", | ||
"storybook-server": "./bin/index.js" | ||
}, | ||
"scripts": { | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"@storybook/core": "4.0.0-alpha.9", | ||
"common-tags": "^1.8.0", | ||
"global": "^4.3.2", | ||
"react": "^16.4.0", | ||
"react-dom": "^16.4.0" | ||
}, | ||
"devDependencies": { | ||
"svelte": "^2.7.2", | ||
"svelte-loader": "^2.9.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export { | ||
storiesOf, | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
configure, | ||
getStorybook, | ||
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. you can also export here the |
||
forceReRender, | ||
} from './preview'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { window } from 'global'; | ||
|
||
window.STORYBOOK_REACT_CLASSES = {}; | ||
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. Shouldn't be needed here |
||
window.STORYBOOK_ENV = 'svelte'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { start } from '@storybook/core/client'; | ||
|
||
import './globals'; | ||
import render from './render'; | ||
|
||
const { clientApi, configApi, forceReRender } = start(render); | ||
|
||
export const { | ||
storiesOf, | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
clearDecorators, | ||
getStorybook, | ||
} = clientApi; | ||
|
||
export const { configure } = configApi; | ||
export { forceReRender }; |
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.
Please mention yourself here and under
/app/svelte/