-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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 5 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) |+| |+|+|+|+|+|+| | | ||
|[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) |+|+|+|+| | |+| | | | ||
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. please mark all the supported addons 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'm working my way through them, marking them off and committing as I go. I think I've marked off everything I've tested so far. |
||
|[storysource](addons/storysource)|+| |+|+|+|+|+|+| | | ||
|[viewport](addons/viewport) |+| |+|+|+|+|+|+| | |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/deprecated'); | ||
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 is deprecated, so you don't need to add a new one. You should just import from the |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div class="style"> | ||
<div class="inner-style"> | ||
<svelte:component this="{Story}" {...data} /> | ||
</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> | ||
|
||
<style> | ||
.style { | ||
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. Could styles be imported from the 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 can, but it will make the svelte template "worse". The style attribute doesn't work the same way as in react or vue, so I can't just pass the object in there. I'll have a go, and see what you think. 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'm adding a small helper function to convert it to plain CSS strings before applying it inline in the component. Not very pretty but solves the problem. It doesn't make the component 'worse', so I guess there's that. |
||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
bottom: 0; | ||
right: 0; | ||
display: flex; | ||
align-items: center; | ||
overflow: auto; | ||
} | ||
|
||
.inner-style { | ||
margin: auto; | ||
max-height: 100%; /* Hack for centering correctly in IE11 */ | ||
} | ||
</style> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
Story: null, | ||
style: {} | ||
} | ||
} | ||
}; | ||
</script> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,15 @@ import { window } from 'global'; | |
import ReactCentered from './react'; | ||
import VueCentered from './vue'; | ||
|
||
const Centered = window.STORYBOOK_ENV === 'vue' ? VueCentered : ReactCentered; | ||
function getCentered(env) { | ||
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. what is the purpose of this refactoring? 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. Sorry, this is from when I didn't understand that the other frameworks are importing the centered addon directly. I have used Vue as the main starting point since it works in the closest way. So I had svelte in here too, but didn't like it. I'll checkout this file again from master. |
||
switch (env) { | ||
case 'vue': | ||
return VueCentered; | ||
default: | ||
return ReactCentered; | ||
} | ||
} | ||
|
||
const Centered = getCentered(window.STORYBOOK_ENV); | ||
|
||
export default Centered; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Centered from './components/Centered.svelte'; | ||
|
||
export default function(storyFn) { | ||
const { Component, data } = storyFn(); | ||
|
||
data.Story = Component; | ||
|
||
return { Component: Centered, data }; | ||
} |
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 @@ | ||
module.exports = require('./dist/deprecated'); | ||
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. Same here, knobs are framework agnostic. |
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,7 @@ | ||
function getRenderedTree(story, context) { | ||
const storyElement = story.render(context); | ||
|
||
return storyElement; | ||
} | ||
|
||
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 | ||
|
||
[](https://circleci.com/gh/storybooks/storybook) | ||
[](https://www.codefactor.io/repository/github/storybooks/storybook) | ||
[](https://snyk.io/test/github/storybooks/storybook/8f36abfd6697e58cd76df3526b52e4b9dc894847) | ||
[](https://bettercodehub.com/results/storybooks/storybook) [](https://codecov.io/gh/storybooks/storybook) | ||
[](https://now-examples-slackin-rrirkqohko.now.sh/) | ||
[](#backers) [](#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 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,39 @@ | ||
{ | ||
"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/vue", | ||
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. vue? |
||
"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" | ||
}, | ||
"peerDependencies": { | ||
"svelte": "2.7.2", | ||
"svelte-loader": "2.9.1" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 |
||
} 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,26 @@ | ||
import { start } from '@storybook/core/client'; | ||
|
||
import './globals'; | ||
import render from './render'; | ||
|
||
// const createWrapperComponent = Target => ({ | ||
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. redundant? |
||
// functional: true, | ||
// render(h, c) { | ||
// return h(Target, c.data, c.children); | ||
// }, | ||
// }); | ||
|
||
const { clientApi, configApi, forceReRender } = start(render); | ||
// const { clientApi, configApi, forceReRender } = start(render, { decorateStory }); | ||
|
||
export const { | ||
storiesOf, | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
clearDecorators, | ||
getStorybook, | ||
} = clientApi; | ||
|
||
export const { configure } = configApi; | ||
export { forceReRender }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { stripIndents } from 'common-tags'; | ||
|
||
const target = document.getElementById('root'); // eslint-disable-line | ||
|
||
export default function render({ | ||
story, | ||
selectedKind, | ||
selectedStory, | ||
showMain, | ||
showError, | ||
// showException, | ||
}) { | ||
const { Component, data, methods } = story(); | ||
|
||
target.innerHTML = ''; | ||
|
||
if (!Component) { | ||
showError({ | ||
title: `Expecting a Svelte component from the story: "${selectedStory}" of "${selectedKind}".`, | ||
description: stripIndents` | ||
Did you forget to return the Svelte component from the story? | ||
Use "() => ({ Component: YourComponent, data: {} })" | ||
when defining the story. | ||
`, | ||
}); | ||
|
||
return; | ||
} | ||
|
||
const component = new Component({target, data}); // eslint-disable-line | ||
|
||
if (methods) { | ||
Object.keys(methods).forEach(methodName => { | ||
component[methodName] = methods[methodName]; | ||
}); | ||
} | ||
|
||
showMain(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { buildStatic } from '@storybook/core/server'; | ||
|
||
import options from './options'; | ||
|
||
buildStatic(options); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { buildDev } from '@storybook/core/server'; | ||
|
||
import options from './options'; | ||
|
||
buildDev(options); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import packageJson from '../../package.json'; | ||
|
||
import wrapInitialConfig from './wrapInitialConfig'; | ||
|
||
export default { | ||
packageJson, | ||
wrapInitialConfig, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export default config => ({ | ||
...config, | ||
module: { | ||
...config.module, | ||
rules: [ | ||
...config.module.rules, | ||
{ | ||
test: /\.svelte$/, | ||
loader: require.resolve('svelte-loader'), | ||
options: {}, | ||
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. can we also support 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. We can. I'm wondering if they will match other loaders elsewhere in the webpack config, haven't looked into these overrides enough yet. 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 just tested.. and putting this: test: /\.(svelte|html)$/, works without causing any issues with other loaders. Maybe check it out from your side. 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. Thanks for checking that out. Will do. |
||
}, | ||
], | ||
}, | ||
resolve: { | ||
...config.resolve, | ||
extensions: [...config.resolve.extensions, '.svelte'], | ||
alias: config.resolve.alias, | ||
}, | ||
}); |
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.
addon-a11y
works, but it shows an ugly error in the console.The error does not seem to affect functionality though
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.
Hmm that's unfortunate, I wonder if axe is actively maintained and we could open a ticket with the maintainers..