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

Svelte support #3770

Merged
merged 98 commits into from Aug 9, 2018
Merged

Svelte support #3770

merged 98 commits into from Aug 9, 2018

Conversation

plumpNation
Copy link
Contributor

@plumpNation plumpNation commented Jun 17, 2018

Issue: #2984

What I did

  • Added support for Svelte.
  • I added example kitchen sink for Svelte.
  • Added or tested support for add ons:
    • centered
    • actions
    • background
    • knobs
    • links
    • notes
    • options
    • storyshots
    • storysource
    • viewport

How to test

In root folder yarn test
Select core tests.

Is this testable with Jest or Chromatic screenshots? Yes, both
Does this need a new example in the kitchen sink apps? Yes
Does this need an update to the documentation? Yes

@igor-dv
Copy link
Member

igor-dv commented Jun 17, 2018

Oh, one more framework support, that's awesome!

@codecov
Copy link

codecov bot commented Jun 17, 2018

Codecov Report

Merging #3770 into master will decrease coverage by 0.48%.
The diff coverage is 1.4%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3770      +/-   ##
==========================================
- Coverage   39.36%   38.87%   -0.49%     
==========================================
  Files         430      442      +12     
  Lines        5475     5546      +71     
  Branches      740      744       +4     
==========================================
+ Hits         2155     2156       +1     
- Misses       2935     3001      +66     
- Partials      385      389       +4
Impacted Files Coverage Δ
addons/storyshots/storyshots-core/.eslintrc.js 0% <ø> (ø) ⬆️
...ts/storyshots-core/src/frameworks/svelte/loader.js 0% <0%> (ø)
app/svelte/src/server/wrapInitialConfig.js 0% <0%> (ø)
app/svelte/src/server/build.js 0% <0%> (ø)
app/svelte/src/server/index.js 0% <0%> (ø)
...toryshots-core/src/frameworks/svelte/renderTree.js 0% <0%> (ø)
addons/centered/src/helpers/json2CSS.js 0% <0%> (ø)
app/svelte/src/client/preview/render.js 0% <0%> (ø)
addons/centered/src/svelte.js 0% <0%> (ø)
app/svelte/src/client/preview/globals.js 0% <0%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2b275b...fb28658. Read the comment docs.

@@ -0,0 +1 @@
module.exports = require('./dist/deprecated');
Copy link
Member

@igor-dv igor-dv Jun 17, 2018

Choose a reason for hiding this comment

The 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 @storybook/addon-backgrounds

</div>

<style>
.style {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could styles be imported from the ./styles.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the purpose of this refactoring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -0,0 +1 @@
module.exports = require('./dist/deprecated');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, knobs are framework agnostic.

addDecorator,
addParameters,
configure,
getStorybook,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also export here the forceReRender.

@@ -0,0 +1,12 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the root .babelrc match your needs?

"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"storybook": "start-storybook -p 9009 -s public"
},
"dependencies": {},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should probably add svelte deps here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Svelte components are compiled, so all Svelte components are vanilla js functions. So, no runtime deps.

work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

React ?

|[links](addons/links) |+|+|+|+|+|+|+| | |
|[notes](addons/notes) |+| |+|+|+|+|+| | |
|[options](addons/options) |+|+|+|+|+|+|+| | |
|[storyshots](addons/storyshots) |+|+|+|+| | |+| | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please mark all the supported addons

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -0,0 +1,32 @@
import global from 'global';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any committed snapshots, does this addon really work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 😸

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be generating snapshots.

@Hypnosphi Hypnosphi self-assigned this Jun 17, 2018
"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",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vue?

@@ -1,11 +1,13 @@
import { storiesOf } from '@storybook/vue';
import Centered from '@storybook/addon-centered';

import MyButton from './Button.vue';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant to this review.

@plumpNation
Copy link
Contributor Author

From what I can see with the CodeFactor issues, these exist in all the other framework examples. If this is acceptable, is there anything else I need to do before this is merged into master?

@plumpNation
Copy link
Contributor Author

Ah, the chromatic test.

@tmeasday
Copy link
Member

tmeasday commented Aug 5, 2018

Hey, to fix chromatic, you just need to change the file examples/official-storybook/built-storybooks/svelte-kitchen-sink to be a symlink to ../../svelte-kitchen-sink/storybook-static.

@ndelangen
Copy link
Member

I created the symlink but this did not resolve the chromatic issue.

Also a unittest is failing:

 FAIL  examples/svelte-kitchen-sink/svelteshots.test.js
  ● Test suite failed to run

    storyshots is intended only to be used with storybook

      2 | import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';
      3 |
    > 4 | initStoryshots({
        | ^
      5 |   framework: 'svelte',
      6 |   configPath: path.join(__dirname, '.storybook'),
      7 |   integrityOptions: { cwd: path.join(__dirname, 'src', 'stories') },

      at loadFramework (examples/svelte-kitchen-sink/node_modules/@storybook/addon-storyshots/dist/frameworks/frameworkLoader.js:42:11)
      at testStorySnapshots (examples/svelte-kitchen-sink/node_modules/@storybook/addon-storyshots/dist/api/index.js:54:54)
      at Object.<anonymous> (examples/svelte-kitchen-sink/svelteshots.test.js:4:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        2.13s
Ran all test suites matching /svelteshots.test.js/i.

Watch Usage: Press w to show more.

@igor-dv
Copy link
Member

igor-dv commented Aug 6, 2018

It is because a wrong alpha versions after the merge. Everything should be 16

@ndelangen
Copy link
Member

Thanks for that @igor-dv, I fixed it.

@igor-dv
Copy link
Member

igor-dv commented Aug 6, 2018

Ok, I think we've tried everything to solve chromatic. I've even tried to exorcise my laptop...
Chromatic people, can you please teach me how to do this?

@tmeasday
Copy link
Member

tmeasday commented Aug 6, 2018

Just as a note -- I could get the Acceptance story running properly locally when i removed the file at examples/official-storybook/built-storybooks/svelte-kitchen-sink and recreated the symlink. However git was confused.

I suspect the solution is to remove the file that currently exists, commit, recreate the symlink, then commit again. I can do it if you like -- not sure where to commit to?

@igor-dv
Copy link
Member

igor-dv commented Aug 7, 2018

This file was my attempt to create a symlink on windows 😓
I've deleted it now.

@tmeasday
Copy link
Member

tmeasday commented Aug 9, 2018

Sorry I didn't realise I could push to the fork. Did that, hopefully fixed now.

@tmeasday
Copy link
Member

tmeasday commented Aug 9, 2018

Ugh, Ok hopefully did it properly this time.

@igor-dv
Copy link
Member

igor-dv commented Aug 9, 2018

hellel

@igor-dv igor-dv merged commit 6d7c3c9 into storybookjs:master Aug 9, 2018
@igor-dv igor-dv added the svelte label Aug 9, 2018
@plumpNation
Copy link
Contributor Author

Yes! Thank you so much guys. Really appreciate you not only accepting it, but helping out to push it out too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants