diff --git a/app/svelte3/.eslintrc.js b/app/svelte3/.eslintrc.js new file mode 100644 index 000000000000..cd50415d1647 --- /dev/null +++ b/app/svelte3/.eslintrc.js @@ -0,0 +1,12 @@ +module.exports = { + extends: '../../.eslintrc.js', + overrides: [ + { + files: ['*.svelte'], + plugins: ['svelte3'], + rules: { + 'import/no-mutable-exports': 'off', + }, + }, + ], +}; diff --git a/app/svelte3/.npmignore b/app/svelte3/.npmignore new file mode 100644 index 000000000000..6d236e2ff68d --- /dev/null +++ b/app/svelte3/.npmignore @@ -0,0 +1,2 @@ +docs +.babelrc diff --git a/app/svelte3/README.md b/app/svelte3/README.md new file mode 100644 index 000000000000..630698b39911 --- /dev/null +++ b/app/svelte3/README.md @@ -0,0 +1,32 @@ +# Storybook for Svelte + +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/storybookjs/storybook/blob/master/media/storybook-intro.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 +cd my-svelte-app +npx -p @storybook/cli sb init +``` + +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. + +## TODOs + +- [ ] Support `addon-info` +- [ ] Support Svelte markup directly in stories +- [ ] Add Svelte storybook generator +- [ ] Provide stories that show advanced Svelte use cases +- [ ] Hydratable +- [ ] Advanced mount options diff --git a/app/svelte3/bin/build.js b/app/svelte3/bin/build.js new file mode 100755 index 000000000000..410ac35d845e --- /dev/null +++ b/app/svelte3/bin/build.js @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +process.env.NODE_ENV = process.env.NODE_ENV || 'production'; + +require('../dist/server/build'); diff --git a/app/svelte3/bin/index.js b/app/svelte3/bin/index.js new file mode 100755 index 000000000000..2e96258ce63d --- /dev/null +++ b/app/svelte3/bin/index.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +require('../dist/server'); diff --git a/app/svelte3/package.json b/app/svelte3/package.json new file mode 100644 index 000000000000..31ce95f561cc --- /dev/null +++ b/app/svelte3/package.json @@ -0,0 +1,54 @@ +{ + "name": "@storybook/svelte3", + "version": "5.1.1", + "description": "Storybook for Svelte3: Develop Svelte Component in isolation with Hot Reloading.", + "keywords": [ + "storybook" + ], + "homepage": "https://github.com/storybookjs/storybook/tree/master/app/svelte3", + "bugs": { + "url": "https://github.com/storybookjs/storybook/issues" + }, + "repository": { + "type": "git", + "url": "https://github.com/storybookjs/storybook.git", + "directory": "app/svelte3" + }, + "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", + "watch": "node ../../scripts/watch-babel.js" + }, + "dependencies": { + "@storybook/core": "5.1.1", + "@storybook/addon-centered": "5.1.1", + "common-tags": "^1.8.0", + "core-js": "^3.0.1", + "eslint-plugin-svelte3": "^1.2.3", + "global": "^4.3.2", + "lodash": "^4.17.11", + "regenerator-runtime": "^0.12.1" + }, + "devDependencies": { + "svelte": "^3.4.1", + "svelte-loader": "^2.13.4" + }, + "peerDependencies": { + "babel-loader": "^7.0.0 || ^8.0.0", + "svelte": "^3.2", + "svelte-loader": "^2.13" + }, + "engines": { + "node": ">=8.0.0" + }, + "publishConfig": { + "access": "public" + } +} diff --git a/app/svelte3/src/addons/centered/Centered.svelte b/app/svelte3/src/addons/centered/Centered.svelte new file mode 100644 index 000000000000..1b351b0d0df6 --- /dev/null +++ b/app/svelte3/src/addons/centered/Centered.svelte @@ -0,0 +1,17 @@ + + +
+
+ +
+
diff --git a/app/svelte3/src/addons/centered/index.js b/app/svelte3/src/addons/centered/index.js new file mode 100644 index 000000000000..acd0046e0f95 --- /dev/null +++ b/app/svelte3/src/addons/centered/index.js @@ -0,0 +1,8 @@ +import Centered from './Centered.svelte'; + +export default storyFn => + class extends Centered { + constructor(opts) { + super({ ...opts, props: { ...opts.props, Story: storyFn() } }); + } + }; diff --git a/app/svelte3/src/client/components/Preview.svelte b/app/svelte3/src/client/components/Preview.svelte new file mode 100644 index 000000000000..beab0d3dfdec --- /dev/null +++ b/app/svelte3/src/client/components/Preview.svelte @@ -0,0 +1,15 @@ + + + diff --git a/app/svelte3/src/client/components/RegisterContext.svelte b/app/svelte3/src/client/components/RegisterContext.svelte new file mode 100644 index 000000000000..b851c280ea3e --- /dev/null +++ b/app/svelte3/src/client/components/RegisterContext.svelte @@ -0,0 +1,11 @@ + + + diff --git a/app/svelte3/src/client/components/StoriesOf.svelte b/app/svelte3/src/client/components/StoriesOf.svelte new file mode 100644 index 000000000000..cbb8115a8b57 --- /dev/null +++ b/app/svelte3/src/client/components/StoriesOf.svelte @@ -0,0 +1,52 @@ + + +{#if register || render && isMyKind(render)} + +{/if} diff --git a/app/svelte3/src/client/components/Story.svelte b/app/svelte3/src/client/components/Story.svelte new file mode 100644 index 000000000000..ee82ea7d799d --- /dev/null +++ b/app/svelte3/src/client/components/Story.svelte @@ -0,0 +1,24 @@ + + +{#if renderThis} + +{/if} diff --git a/app/svelte3/src/client/constants.js b/app/svelte3/src/client/constants.js new file mode 100644 index 000000000000..8bdee59f5f05 --- /dev/null +++ b/app/svelte3/src/client/constants.js @@ -0,0 +1,7 @@ +// TODO use truly unique identifiers to avoid collisions with user's context +export const CTX_STORIES = 'stories'; +export const CTX_DECORATORS = 'decorators'; +export const CTX_PARAMETERS = 'parameters'; +export const CTX_MODULE = 'module'; +export const CTX_REGISTER = 'register'; +export const CTX_RENDER = 'render'; diff --git a/app/svelte3/src/client/index.js b/app/svelte3/src/client/index.js new file mode 100644 index 000000000000..2a8b6a0a4d29 --- /dev/null +++ b/app/svelte3/src/client/index.js @@ -0,0 +1,20 @@ +export { + setAddon, + addDecorator, + addParameters, + configure, + getStorybook, + forceReRender, + raw, +} from './preview'; + +// functions +export { default as loadSvelteStories } from './utils/loadSvelteStories'; +export { default as storiesOf } from './utils/storiesOf'; +// components +export { default as Story } from './components/Story.svelte'; +export { default as StoriesOf } from './components/StoriesOf.svelte'; + +if (module && module.hot && module.hot.decline) { + module.hot.decline(); +} diff --git a/app/svelte3/src/client/preview/globals.js b/app/svelte3/src/client/preview/globals.js new file mode 100644 index 000000000000..cf7a22eb7101 --- /dev/null +++ b/app/svelte3/src/client/preview/globals.js @@ -0,0 +1,3 @@ +import { window } from 'global'; + +window.STORYBOOK_ENV = 'svelte3'; diff --git a/app/svelte3/src/client/preview/index.js b/app/svelte3/src/client/preview/index.js new file mode 100644 index 000000000000..877b04bca126 --- /dev/null +++ b/app/svelte3/src/client/preview/index.js @@ -0,0 +1,19 @@ +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, + raw, +} = clientApi; + +export const { configure } = configApi; +export { forceReRender }; diff --git a/app/svelte3/src/client/preview/render.js b/app/svelte3/src/client/preview/render.js new file mode 100644 index 000000000000..9f5930b3df5a --- /dev/null +++ b/app/svelte3/src/client/preview/render.js @@ -0,0 +1,49 @@ +import { document } from 'global'; + +import Preview from '../components/Preview.svelte'; + +let previousPreview = null; + +export default function render({ + storyFn, + selectedKind, + selectedStory, + showMain, + // showError, + showException, +}) { + const Stories = storyFn(); + + if (previousPreview) { + previousPreview.$destroy(); + previousPreview = null; + } + + const target = document.getElementById('root'); + + target.innerHTML = ''; + + try { + previousPreview = new Preview({ + target, + props: { + Stories, + selectedKind, + selectedStory, + }, + }); + showMain(); + } catch (ex) { + showException(ex); + // cleanup + if (previousPreview && previousPreview.$destroy) { + try { + previousPreview.$destroy(); + } catch (err) { + // eslint-disable-next-line no-console + console.warn('Failed to destroy previous component', err); + } + } + previousPreview = null; + } +} diff --git a/app/svelte3/src/client/utils/loadSvelteStories.js b/app/svelte3/src/client/utils/loadSvelteStories.js new file mode 100644 index 000000000000..bd66eebd7dff --- /dev/null +++ b/app/svelte3/src/client/utils/loadSvelteStories.js @@ -0,0 +1,43 @@ +/* global document */ + +import RegisterContext from '../components/RegisterContext.svelte'; + +const createFragment = document.createDocumentFragment + ? () => document.createDocumentFragment() + : () => document.createElement('div'); + +/** + * This needs to be hooked in user's `loadStories`: + * + * import { configure, loadSvelteStories } from '@storybook/svelte' + * + * function loadStories() { + * const req = require.context('../src', true, /\.(stories|story)\.svelte$/) + * loadSvelteStories(req) + * } + * + * configure(loadStories, module) + */ +const loadSvelteStories = req => { + req.keys().forEach(filename => { + try { + const Stories = req(filename).default; + const storyFn = () => Stories; + const cmp = new RegisterContext({ + target: createFragment(), + props: { + Stories, + register: { storyFn }, + }, + }); + cmp.$destroy(); + } catch (err) { + // now what? + // TODO find how to display this exception (all while we don't have + // the stories' kind/names) -- meanwhile, don't hide it + throw err; + } + }); +}; + +export default loadSvelteStories; diff --git a/app/svelte3/src/client/utils/storiesOf.js b/app/svelte3/src/client/utils/storiesOf.js new file mode 100644 index 000000000000..e4880d48e234 --- /dev/null +++ b/app/svelte3/src/client/utils/storiesOf.js @@ -0,0 +1,139 @@ +import { setContext, getContext } from 'svelte'; +import { get, set } from 'lodash'; + +import { storiesOf as baseStoriesOf } from '../preview'; +import { + CTX_MODULE, + CTX_STORIES, + CTX_DECORATORS, + CTX_PARAMETERS, + CTX_REGISTER, +} from '../constants'; + +// --- Context --- + +// NOTE context functions will crash if called outside of a svelte component +// instance script with "outside of component initialization", but this is +// desirable since it indicates an incorrect usage -- and svelte's error +// message is explicit enough for our situation too + +const isContextRegister = () => { + return getContext(CTX_REGISTER); +}; + +const setContextStories = stories => { + setContext(CTX_STORIES, stories); +}; + +const setContextModule = m => { + setContext(CTX_MODULE, m); +}; + +// --- Proxies --- + +// eslint-disable-next-line no-use-before-define +const noop = () => noopProxy; +const noopProxy = { + add: noop, + addDecorator: noop, + addParameters: noop, +}; + +const contextProxy = { + addDecorator(...args) { + const decorators = getContext(CTX_DECORATORS) || []; + setContext(CTX_DECORATORS, [...decorators, args]); + return contextProxy; + }, + addParameters(...args) { + const parameters = getContext(CTX_PARAMETERS) || []; + setContext(CTX_PARAMETERS, [...parameters, args]); + return contextProxy; + }, +}; + +// --- HMR Disposable --- + +const loadedModules = {}; + +const getDispose = obj => get(obj, ['hot', 'dispose']); + +const rememberModule = ({ id }, kind) => { + set(loadedModules, [id, kind], true); +}; + +const forgetModule = ({ id }, kind) => () => { + delete loadedModules[id][kind]; +}; + +const storiesOfDisposable = (kind, m) => { + // guard: already loaded (and not disposed) => return a deactivated proxy + // to avoid registering again a story that is still in the stories store + const loadedStories = get(loadedModules, [m.id, kind]); + if (loadedStories) { + return noopProxy; + } + // register kind + const stories = baseStoriesOf(kind, m); + // lifecycle + const onDispose = getDispose(m); + rememberModule(m, kind); + onDispose(forgetModule(m, kind)); + return stories; +}; + +// --- custom storiesOf --- + +// We need to do the dispoable dance here because of the strategy used to +// register stories from Svelte components. +// +// Or we'll get "duplicate story" warnings. +// +// In the general (non svelte) case, kinds/stories are created when the module +// is executed, that is when it is required for the first time. Subsequent +// requires (in user's project `loadConfig`) have no effects. Subsequent +// requires of hot replaced modules is handled internally in Storybook, with +// the expectation that unmodified modules won't be executed again. +// +// However, in order to extract stories written as Svelte components (that is +// have the underlying `storiesOf` and `storiesOf#add` calls executed), we need +// to actually instantiate those components (in "register" mode). Blindly doing +// so for already required and registered modules would result in duplicate +// calls of `storiesOf` and `add` for modules that have not been modified (and +// hot reloaded). And so, our solutions is as follow: +// +// - Keep track of already registered kinds & stories by a given module. +// +// - Do not recreate stories components (i.e. register again) for modules +// that have been remembered. +// +// - Forget a module when it is hot disposed, so that hot updates are taken +// into account. This will not result in a warning, because Storybook's +// core also listen on module.hot.dispose to know when to expect an updated +// story to be registered again. +// +// Further, we cannot do all this in our `loadSvelteStories`, where it would +// arguably be better located (closer to the actual "svelte stories" concern +// and code). Indeed we need access to the `module` (and module.hot.dispose) of +// the file where `storiesOf` is called. And this `module` only becomes visible +// to us when `storiesOf` is actually called and, as elaborated above, merely +// requiring the module isn't enough to trigger calls to `storiesOf` and +// `storiesOf#add` for stories as Svelte components. +// +const storiesOf = (kind, m) => { + if (!isContextRegister()) { + return noopProxy; + } + // partial storiesOf(module): store module in context and wait for the + // StoriesOf component + if (typeof kind === 'object' && !m && kind.id != null) { + setContextModule(kind); + return contextProxy; + } + const isHotDisposable = getDispose(m); + const stories = isHotDisposable ? storiesOfDisposable(kind, m) : baseStoriesOf(kind, m); + setContextStories(stories); + return stories; +}; + +export default storiesOf; diff --git a/app/svelte3/src/server/build.js b/app/svelte3/src/server/build.js new file mode 100755 index 000000000000..d8abf06a4396 --- /dev/null +++ b/app/svelte3/src/server/build.js @@ -0,0 +1,4 @@ +import { buildStatic } from '@storybook/core/server'; +import options from './options'; + +buildStatic(options); diff --git a/app/svelte3/src/server/framework-preset-svelte.js b/app/svelte3/src/server/framework-preset-svelte.js new file mode 100644 index 000000000000..6fcbfb1f79c6 --- /dev/null +++ b/app/svelte3/src/server/framework-preset-svelte.js @@ -0,0 +1,21 @@ +export function webpack(config) { + return { + ...config, + module: { + ...config.module, + rules: [ + ...config.module.rules, + { + test: /\.(svelte|html)$/, + loader: require.resolve('svelte-loader'), + options: {}, + }, + ], + }, + resolve: { + ...config.resolve, + extensions: [...config.resolve.extensions, '.svelte'], + alias: config.resolve.alias, + }, + }; +} diff --git a/app/svelte3/src/server/index.js b/app/svelte3/src/server/index.js new file mode 100755 index 000000000000..774d96025a84 --- /dev/null +++ b/app/svelte3/src/server/index.js @@ -0,0 +1,4 @@ +import { buildDev } from '@storybook/core/server'; +import options from './options'; + +buildDev(options); diff --git a/app/svelte3/src/server/options.js b/app/svelte3/src/server/options.js new file mode 100644 index 000000000000..3e4a77d76407 --- /dev/null +++ b/app/svelte3/src/server/options.js @@ -0,0 +1,6 @@ +import packageJson from '../../package.json'; + +export default { + packageJson, + frameworkPresets: [require.resolve('./framework-preset-svelte.js')], +}; diff --git a/app/svelte3/standalone.js b/app/svelte3/standalone.js new file mode 100644 index 000000000000..1b1febe0d3bb --- /dev/null +++ b/app/svelte3/standalone.js @@ -0,0 +1,8 @@ +const build = require('@storybook/core/standalone'); +const frameworkOptions = require('./dist/server/options').default; + +async function buildStandalone(options) { + return build(options, frameworkOptions); +} + +module.exports = buildStandalone; diff --git a/examples/svelte3-kitchen-sink/.gitignore b/examples/svelte3-kitchen-sink/.gitignore new file mode 100644 index 000000000000..f25c23c591ba --- /dev/null +++ b/examples/svelte3-kitchen-sink/.gitignore @@ -0,0 +1,16 @@ +# See http://help.github.com/ignore-files/ for more about ignoring files. + +# dependencies +node_modules + +# testing +coverage + +# production +build + +# misc +.DS_Store +.env +npm-debug.log +yarn-error.log diff --git a/examples/svelte3-kitchen-sink/.storybook/addons.js b/examples/svelte3-kitchen-sink/.storybook/addons.js new file mode 100644 index 000000000000..d948e3fd71be --- /dev/null +++ b/examples/svelte3-kitchen-sink/.storybook/addons.js @@ -0,0 +1,9 @@ +import '@storybook/addon-storysource/register'; +import '@storybook/addon-actions/register'; +import '@storybook/addon-links/register'; +import '@storybook/addon-notes/register'; +import '@storybook/addon-knobs/register'; +import '@storybook/addon-backgrounds/register'; +import '@storybook/addon-viewport/register'; +import '@storybook/addon-options/register'; +import '@storybook/addon-a11y/register'; diff --git a/examples/svelte3-kitchen-sink/.storybook/config.js b/examples/svelte3-kitchen-sink/.storybook/config.js new file mode 100644 index 000000000000..0a5c1063f6ff --- /dev/null +++ b/examples/svelte3-kitchen-sink/.storybook/config.js @@ -0,0 +1,14 @@ +import { configure, addParameters, loadSvelteStories } from '@storybook/svelte3'; + +addParameters({ + options: { + hierarchyRootSeparator: /\|/, + }, +}); + +function loadStories() { + const req = require.context('../src', true, /\.stories\.svelte$/); + loadSvelteStories(req); +} + +configure(loadStories, module); diff --git a/examples/svelte3-kitchen-sink/.storybook/webpack.config.js b/examples/svelte3-kitchen-sink/.storybook/webpack.config.js new file mode 100644 index 000000000000..a0dac33e4c7b --- /dev/null +++ b/examples/svelte3-kitchen-sink/.storybook/webpack.config.js @@ -0,0 +1,12 @@ +const path = require('path'); + +module.exports = async ({ config }) => { + // TODO support source addon + // config.module.rules.push({ + // test: [/\.stories\.svelte$/, /\.stories\.js$/, /index\.js$/], + // loaders: [require.resolve('@storybook/addon-storysource/loader')], + // include: [path.resolve(__dirname, '../src')], + // enforce: 'pre', + // }); + return config; +}; diff --git a/examples/svelte3-kitchen-sink/README.md b/examples/svelte3-kitchen-sink/README.md new file mode 100644 index 000000000000..22b59e456717 --- /dev/null +++ b/examples/svelte3-kitchen-sink/README.md @@ -0,0 +1,5 @@ +# Storybook Svelte Demo + +This example directory represents the application you wish to integrate storybook into. + +Run `yarn install` to sync Storybook module with the source code and run `yarn storybook` to start the Storybook. diff --git a/examples/svelte3-kitchen-sink/jest.config.js b/examples/svelte3-kitchen-sink/jest.config.js new file mode 100644 index 000000000000..aa9901a30936 --- /dev/null +++ b/examples/svelte3-kitchen-sink/jest.config.js @@ -0,0 +1,11 @@ +const config = require('../../jest.config'); + +module.exports = { + ...config, + roots: [__dirname], + transform: { + ...config.transform, + '.*\\.(svelte)$': '/svelte-transform', + }, + moduleFileExtensions: [...config.moduleFileExtensions, 'svelte'], +}; diff --git a/examples/svelte3-kitchen-sink/package.json b/examples/svelte3-kitchen-sink/package.json new file mode 100644 index 000000000000..e7890d23059c --- /dev/null +++ b/examples/svelte3-kitchen-sink/package.json @@ -0,0 +1,29 @@ +{ + "name": "svelte3-example", + "version": "5.1.1", + "private": true, + "scripts": { + "build-storybook": "build-storybook -s public", + "now-build": "node ../../scripts/bootstrap --core && yarn run build-storybook --quiet", + "storybook": "start-storybook -p 9009 -s public" + }, + "dependencies": { + "global": "^4.3.2", + "svelte": "^3.4.1" + }, + "devDependencies": { + "@storybook/addon-a11y": "5.1.1", + "@storybook/addon-actions": "5.1.1", + "@storybook/addon-backgrounds": "5.1.1", + "@storybook/addon-centered": "5.1.1", + "@storybook/addon-knobs": "5.1.1", + "@storybook/addon-links": "5.1.1", + "@storybook/addon-notes": "5.1.1", + "@storybook/addon-options": "5.1.1", + "@storybook/addon-storyshots": "5.1.1", + "@storybook/addon-storysource": "5.1.1", + "@storybook/addon-viewport": "5.1.1", + "@storybook/addons": "5.1.1", + "@storybook/svelte3": "5.1.1" + } +} diff --git a/examples/svelte3-kitchen-sink/public/favicon.ico b/examples/svelte3-kitchen-sink/public/favicon.ico new file mode 100644 index 000000000000..9e9c880c25b3 Binary files /dev/null and b/examples/svelte3-kitchen-sink/public/favicon.ico differ diff --git a/examples/svelte3-kitchen-sink/public/svelte-logo-horizontal.svg b/examples/svelte3-kitchen-sink/public/svelte-logo-horizontal.svg new file mode 100644 index 000000000000..1d602a905142 --- /dev/null +++ b/examples/svelte3-kitchen-sink/public/svelte-logo-horizontal.svg @@ -0,0 +1,3 @@ + + + diff --git a/examples/svelte3-kitchen-sink/src/components/Button.stories.svelte b/examples/svelte3-kitchen-sink/src/components/Button.stories.svelte new file mode 100644 index 000000000000..3846240ba158 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/components/Button.stories.svelte @@ -0,0 +1,17 @@ + + + + diff --git a/examples/svelte3-kitchen-sink/src/components/Button.test.js b/examples/svelte3-kitchen-sink/src/components/Button.test.js new file mode 100644 index 000000000000..e0721ceaaf74 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/components/Button.test.js @@ -0,0 +1,24 @@ +import { document } from 'global'; +import Button from './Button.svelte'; + +let target; +let component; + +describe('Button Component', () => { + beforeEach(() => { + target = document.createElement('div'); + + component = new Button({ target }); + }); + + it('should render `text` property', () => { + const text = 'Hello world'; + const expected = `Round corners\n ${text}`; + + component.$set({ text }); + + const componentText = target.firstChild.textContent.trim(); + + expect(componentText).toEqual(expected); + }); +}); diff --git a/examples/svelte3-kitchen-sink/src/logo.png b/examples/svelte3-kitchen-sink/src/logo.png new file mode 100644 index 000000000000..92b1560c6de1 Binary files /dev/null and b/examples/svelte3-kitchen-sink/src/logo.png differ diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-actions.stories.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-actions.stories.storyshot new file mode 100644 index 000000000000..c3dc6821fc20 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-actions.stories.storyshot @@ -0,0 +1,62 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon|Actions Action on component method 1`] = ` +
+ +
+`; + +exports[`Storyshots Addon|Actions Action on view method 1`] = ` +
+

+ Button view +

+ + + +

+ A little text to show this is a view. +

+ +

+ If we need to test components in a Svelte environment, for instance to test slot behaviour, +

+ +

+ then wrapping the component up in a view +

+ +

+ made just for the story is the simplest way to achieve this. +

+
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-backgrounds.stories.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-backgrounds.stories.storyshot new file mode 100644 index 000000000000..3f40c77cc6d2 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-backgrounds.stories.storyshot @@ -0,0 +1,43 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon|Backgrounds story 1 1`] = ` +
+

+ Button view +

+ + + +

+ A little text to show this is a view. +

+ +

+ If we need to test components in a Svelte environment, for instance to test slot behaviour, +

+ +

+ then wrapping the component up in a view +

+ +

+ made just for the story is the simplest way to achieve this. +

+
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot new file mode 100644 index 000000000000..1232bcea2ae0 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-centered.stories.storyshot @@ -0,0 +1,39 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon|Centered rounded 1`] = ` +
+ +
+`; + +exports[`Storyshots Addon|Centered with action 1`] = ` +
+ +
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-knobs.stories.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-knobs.stories.storyshot new file mode 100644 index 000000000000..9ad2c1cc73db --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-knobs.stories.storyshot @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon|Knobs Simple 1`] = ` +
+
+

+ I am interactive +

+
+
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-links.stories.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-links.stories.storyshot new file mode 100644 index 000000000000..8e8009d5083f --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-links.stories.storyshot @@ -0,0 +1,29 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon|Links Go to welcome view 1`] = ` +
+
+

+ Link Action +

+ + +
+
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-notes.stories.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-notes.stories.storyshot new file mode 100644 index 000000000000..4f71436ef5dd --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/addon-notes.stories.storyshot @@ -0,0 +1,85 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Addon|Notes Note with HTML 1`] = ` +
+

+ Button view +

+ + + +

+ A little text to show this is a view. +

+ +

+ If we need to test components in a Svelte environment, for instance to test slot behaviour, +

+ +

+ then wrapping the component up in a view +

+ +

+ made just for the story is the simplest way to achieve this. +

+
+`; + +exports[`Storyshots Addon|Notes Simple note 1`] = ` +
+

+ Button view +

+ + + +

+ A little text to show this is a view. +

+ +

+ If we need to test components in a Svelte environment, for instance to test slot behaviour, +

+ +

+ then wrapping the component up in a view +

+ +

+ made just for the story is the simplest way to achieve this. +

+
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/__snapshots__/index.storyshot b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/index.storyshot new file mode 100644 index 000000000000..3d58a6b41277 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/__snapshots__/index.storyshot @@ -0,0 +1,204 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Storyshots Button rounded 1`] = ` +
+

+ Button view +

+ + + +

+ A little text to show this is a view. +

+ +

+ If we need to test components in a Svelte environment, for instance to test slot behaviour, +

+ +

+ then wrapping the component up in a view +

+ +

+ made just for the story is the simplest way to achieve this. +

+
+`; + +exports[`Storyshots Button square 1`] = ` +
+

+ Button view +

+ + + +

+ A little text to show this is a view. +

+ +

+ If we need to test components in a Svelte environment, for instance to test slot behaviour, +

+ +

+ then wrapping the component up in a view +

+ +

+ made just for the story is the simplest way to achieve this. +

+
+`; + +exports[`Storyshots Welcome Welcome 1`] = ` +
+
+

+ Welcome to Storybook for Svelte +

+ + +

+ + This is a UI component dev environment for your svelte app. + +

+ + +

+ + We've added some basic stories inside the + + src/stories + + directory. + + + A story is like a visual test case + + + and represents a single state of one or more UI components. + You can have as many stories as you want. + +

+ + + +

+ Svelte +

+ + + +

+ + Just like that, you can add your own components as stories. + You can also edit those components and see changes right away. + +
+ + (Try editing the + + Button + + component + located at + + src/stories/views/Welcome.svelte + + .) + +

+ + +

+ + Usually we create stories with smaller UI components in the app. +
+ + Have a look at the + + + Writing Stories + + + section in our documentation. + +

+ + +

+ + NOTE: + + + +
+ + Have a look at the + + + .storybook/webpack.config.js + + + to add webpack + loaders and plugins you are using in this project. + +

+
+
+`; diff --git a/examples/svelte3-kitchen-sink/src/stories/addon-actions.stories.svelte b/examples/svelte3-kitchen-sink/src/stories/addon-actions.stories.svelte new file mode 100644 index 000000000000..73c80a80f2cf --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/addon-actions.stories.svelte @@ -0,0 +1,16 @@ + + + + + + + + + diff --git a/examples/svelte3-kitchen-sink/src/stories/addon-backgrounds.stories.svelte b/examples/svelte3-kitchen-sink/src/stories/addon-backgrounds.stories.svelte new file mode 100644 index 000000000000..40bb99d2ddf9 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/addon-backgrounds.stories.svelte @@ -0,0 +1,15 @@ + + + + + diff --git a/examples/svelte3-kitchen-sink/src/stories/addon-centered.stories.svelte b/examples/svelte3-kitchen-sink/src/stories/addon-centered.stories.svelte new file mode 100644 index 000000000000..e6f42aaa6674 --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/addon-centered.stories.svelte @@ -0,0 +1,17 @@ + + + + + + diff --git a/examples/svelte3-kitchen-sink/src/stories/addon-notes.stories.svelte b/examples/svelte3-kitchen-sink/src/stories/addon-notes.stories.svelte new file mode 100644 index 000000000000..d9c38476f6eb --- /dev/null +++ b/examples/svelte3-kitchen-sink/src/stories/addon-notes.stories.svelte @@ -0,0 +1,25 @@ + + + + + +

A little text to show this is a view.

+ + diff --git a/examples/svelte3-kitchen-sink/svelteshots.test.js b/examples/svelte3-kitchen-sink/svelteshots.test.js new file mode 100644 index 000000000000..fd14ec12becb --- /dev/null +++ b/examples/svelte3-kitchen-sink/svelteshots.test.js @@ -0,0 +1,9 @@ +import path from 'path'; +import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots'; + +initStoryshots({ + framework: 'svelte', + configPath: path.join(__dirname, '.storybook'), + integrityOptions: { cwd: path.join(__dirname, 'src', 'stories') }, + test: multiSnapshotWithOptions(), +});