-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3770 from plumpNation/svelte-support
Svelte support
- Loading branch information
Showing
74 changed files
with
1,672 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
addon | ||
1 | ||
vue | ||
svelte | ||
webcomponents | ||
aurelia | ||
iframe | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |+|+|+|+| | |+| |+| | ||
|[storysource](addons/storysource)|+| |+|+|+|+|+|+|+| | ||
|[viewport](addons/viewport) |+| |+|+|+|+|+|+|+| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div class="svelte-centered-wrapper" style="{style}"> | ||
<div class="svelte-centered-container" style="{innerStyle}"> | ||
<slot></slot> | ||
</div> | ||
</div> | ||
|
||
<script> | ||
export default { | ||
data() { | ||
return { | ||
style: '', | ||
innerStyle: '' | ||
}; | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
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, on } = storyFn(); | ||
|
||
return { Component: OriginalComponent, data, on, Wrapper: Centered, WrapperData: centeredStyles }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./dist/svelte'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
addons/storyshots/storyshots-core/src/frameworks/svelte/loader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import global from 'global'; | ||
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, | ||
}; |
29 changes: 29 additions & 0 deletions
29
addons/storyshots/storyshots-core/src/frameworks/svelte/renderTree.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
docs | ||
.babelrc |
Oops, something went wrong.