-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Try] Add support for LitElement #7731
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8215ff6
feat: basic support for lit-element
lonyele c04592d
feat: add TemplateResult to return type and add a comment
lonyele 4211b80
feat: add lit-element-kitchen-sink example
lonyele 7e55e74
Merge branch 'next' of https://github.com/storybookjs/storybook into …
lonyele b390afc
chore: version up to beta.26
lonyele 0f1e07e
Merge branch 'next' into pr/lonyele/7731
ndelangen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
docs | ||
src | ||
.babelrc |
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,31 @@ | ||
# Storybook for Polymer | ||
|
||
Storybook for polymer is a UI development environment for your Polymer components. | ||
With it, you can visualize different states of your UI components and develop them interactively. | ||
|
||
> Storybook for Polymer is at the **EXPERIMENTAL** stage! | ||
|
||
![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-polymer-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. | ||
|
||
## Polymer Notes | ||
|
||
- This is super super experimental, if you want to use this, expect some bugs, and missing features. | ||
- We're looking for help to support this. If you're a member of the Polymer community and like this project, please help us! | ||
If you need any onboarding from us, we're happy to help you in any way! |
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,4 @@ | ||
#!/usr/bin/env node | ||
|
||
process.env.NODE_ENV = process.env.NODE_ENV || 'production'; | ||
require('../dist/server/build'); |
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,3 @@ | ||
#!/usr/bin/env node | ||
|
||
require('../dist/server'); |
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,51 @@ | ||
{ | ||
"name": "@storybook/lit-element", | ||
"version": "5.2.0-beta.26", | ||
"description": "Storybook for LitElement: Develop LitElement components in isolation with Hot Reloading.", | ||
"keywords": [ | ||
"storybook" | ||
], | ||
"homepage": "https://github.com/storybookjs/storybook/tree/master/app/lit-element", | ||
"bugs": { | ||
"url": "https://github.com/storybookjs/storybook/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/storybookjs/storybook.git", | ||
"directory": "app/lit-element" | ||
}, | ||
"license": "MIT", | ||
"main": "dist/client/index.js", | ||
"types": "dist/client/index.d.ts", | ||
"bin": { | ||
"build-storybook": "./bin/build.js", | ||
"start-storybook": "./bin/index.js", | ||
"storybook-server": "./bin/index.js" | ||
}, | ||
"scripts": { | ||
"prepare": "node ../../scripts/prepare.js" | ||
}, | ||
"dependencies": { | ||
"@storybook/addons": "5.2.0-beta.26", | ||
"@storybook/core": "5.2.0-beta.26", | ||
"common-tags": "^1.8.0", | ||
"core-js": "^3.0.1", | ||
"global": "^4.3.2", | ||
"html-loader": "^0.5.5", | ||
"regenerator-runtime": "^0.12.1", | ||
"webpack": "^4.33.0" | ||
}, | ||
"devDependencies": { | ||
"lit-element": "^2.2.1" | ||
}, | ||
"peerDependencies": { | ||
"babel-loader": "^7.0.0 || ^8.0.0", | ||
"lit-element": "^2.2.1" | ||
}, | ||
"engines": { | ||
"node": ">=8.0.0" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,14 @@ | ||
export { | ||
storiesOf, | ||
setAddon, | ||
addDecorator, | ||
addParameters, | ||
configure, | ||
getStorybook, | ||
forceReRender, | ||
raw, | ||
} from './preview'; | ||
|
||
if (module && module.hot && module.hot.decline) { | ||
module.hot.decline(); | ||
} |
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,3 @@ | ||
import { window } from 'global'; | ||
|
||
window.STORYBOOK_ENV = 'lit-element'; |
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,24 @@ | ||
/* eslint-disable prefer-destructuring */ | ||
import { start } from '@storybook/core/client'; | ||
|
||
import './globals'; | ||
import render from './render'; | ||
import { ClientApi } from './types'; | ||
|
||
const framework = 'lit-element'; | ||
const api = start(render); | ||
|
||
export const storiesOf: ClientApi['storiesOf'] = (kind, m) => { | ||
return (api.clientApi.storiesOf(kind, m) as ReturnType<ClientApi['storiesOf']>).addParameters({ | ||
framework, | ||
}); | ||
}; | ||
|
||
export const configure: ClientApi['configure'] = (...args) => api.configure(...args, framework); | ||
export const addDecorator: ClientApi['addDecorator'] = api.clientApi.addDecorator; | ||
export const addParameters: ClientApi['addParameters'] = api.clientApi.addParameters; | ||
export const clearDecorators: ClientApi['clearDecorators'] = api.clientApi.clearDecorators; | ||
export const setAddon: ClientApi['setAddon'] = api.clientApi.setAddon; | ||
export const forceReRender: ClientApi['forceReRender'] = api.forceReRender; | ||
export const getStorybook: ClientApi['getStorybook'] = api.clientApi.getStorybook; | ||
export const raw: ClientApi['raw'] = api.clientApi.raw; |
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,50 @@ | ||
import { document } from 'global'; | ||
import { stripIndents } from 'common-tags'; | ||
import { TemplateResult, LitElement } from 'lit-element'; | ||
import { RenderMainArgs } from './types'; | ||
|
||
const rootElement = document.getElementById('root'); | ||
|
||
export default function renderMain({ | ||
storyFn, | ||
selectedKind, | ||
selectedStory, | ||
showMain, | ||
showError, | ||
forceRender, | ||
}: RenderMainArgs) { | ||
const element = storyFn(); | ||
|
||
if (!element) { | ||
showError({ | ||
title: `Expecting a LitElement component from the story: "${selectedStory}" of "${selectedKind}".`, | ||
description: stripIndents` | ||
Did you forget to return the Polymer component from the story? | ||
Use "() => '<your-component-name></your-component-name\>'" when defining the story. | ||
`, | ||
}); | ||
return; | ||
} | ||
|
||
showMain(); | ||
if (typeof element === 'string') { | ||
rootElement.innerHTML = element; | ||
} else if (element instanceof TemplateResult) { | ||
// `render` stores the TemplateInstance in the Node and tries to update based on that. | ||
// Since we reuse `rootElement` for all stories, remove the stored instance first. | ||
// But forceRender means that it's the same story, so we want too keep the state in that case. | ||
if (!forceRender || !rootElement.querySelector('[id="root-inner"]')) { | ||
rootElement.innerHTML = '<div id="root-inner"></div>'; | ||
} | ||
const renderTo = rootElement.querySelector('[id="root-inner"]'); | ||
|
||
// Use lit-html's render function that is being used at lit-element | ||
// internally to cover the case using only html`...` instead of | ||
// lit-element which makes using lit-html and lit-element at the same | ||
// time. | ||
LitElement.render(element, renderTo, { scopeName: '' }); | ||
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 think this is a hack I've found... |
||
} else { | ||
rootElement.innerHTML = ''; | ||
rootElement.appendChild(element); | ||
} | ||
} |
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,38 @@ | ||
import { StoryFn, ClientStoryApi, Loadable } from '@storybook/addons'; | ||
import { TemplateResult } from 'lit-element'; | ||
|
||
export type StoryFnLitElementReturnType = TemplateResult | string | Node; | ||
|
||
export interface ShowErrorArgs { | ||
title: string; | ||
description: string; | ||
} | ||
|
||
export interface RenderMainArgs { | ||
storyFn: () => StoryFn<StoryFnLitElementReturnType>; | ||
selectedKind: string; | ||
selectedStory: string; | ||
showMain: () => void; | ||
showError: (args: ShowErrorArgs) => void; | ||
forceRender: boolean; | ||
} | ||
|
||
export interface IStorybookStory { | ||
name: string; | ||
render: () => any; | ||
} | ||
|
||
export interface IStorybookSection { | ||
kind: string; | ||
stories: IStorybookStory[]; | ||
} | ||
|
||
export interface ClientApi extends ClientStoryApi<StoryFnLitElementReturnType> { | ||
setAddon(addon: any): void; | ||
configure(loader: Loadable, module: NodeModule): void; | ||
getStorybook(): IStorybookSection[]; | ||
clearDecorators(): void; | ||
forceReRender(): void; | ||
raw: () => any; | ||
load: (...args: any[]) => void; | ||
} |
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,4 @@ | ||
import { buildStatic } from '@storybook/core/server'; | ||
import options from './options'; | ||
|
||
buildStatic(options); |
21 changes: 21 additions & 0 deletions
21
app/lit-element/src/server/framework-preset-lit-element.ts
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 { Configuration } from 'webpack'; | ||
|
||
export function webpack(config: Configuration) { | ||
return { | ||
...config, | ||
module: { | ||
...config.module, | ||
rules: [ | ||
...config.module.rules, | ||
{ | ||
test: /\.html$/, | ||
use: [ | ||
{ | ||
loader: require.resolve('html-loader'), | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
} |
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,4 @@ | ||
import { buildDev } from '@storybook/core/server'; | ||
import options from './options'; | ||
|
||
buildDev(options); |
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,6 @@ | ||
const packageJson = require('../../package.json'); | ||
|
||
export default { | ||
packageJson, | ||
frameworkPresets: [require.resolve('./framework-preset-lit-element.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,2 @@ | ||
declare module '@storybook/core/*'; | ||
declare module 'global'; |
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,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; |
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,14 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"rootDir": "./src", | ||
"types": ["webpack-env"], | ||
"resolveJsonModule": true | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"src/**/*.test.*" | ||
] | ||
} |
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,10 @@ | ||
import '@storybook/addon-a11y/register'; | ||
import '@storybook/addon-actions/register'; | ||
import '@storybook/addon-backgrounds/register'; | ||
import '@storybook/addon-events/register'; | ||
import '@storybook/addon-jest/register'; | ||
import '@storybook/addon-knobs/register'; | ||
import '@storybook/addon-notes/register'; | ||
import '@storybook/addon-options/register'; | ||
import '@storybook/addon-storysource/register'; | ||
import '@storybook/addon-viewport/register'; |
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,22 @@ | ||
import { configure, addParameters, addDecorator } from '@storybook/lit-element'; | ||
import { withA11y } from '@storybook/addon-a11y'; | ||
|
||
addDecorator(withA11y); | ||
|
||
addParameters({ | ||
a11y: { | ||
config: {}, | ||
options: { | ||
checks: { 'color-contrast': { options: { noScroll: true } } }, | ||
restoreScroll: true, | ||
}, | ||
}, | ||
options: { | ||
hierarchyRootSeparator: /\|/, | ||
docs: { | ||
iframeHeight: '200px', | ||
}, | ||
}, | ||
}); | ||
|
||
configure(require.context('../src/stories', true, /\.stories\.(js|mdx)$/), module); |
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 = ['@storybook/addon-docs/html/preset']; |
4 changes: 4 additions & 0 deletions
4
examples/lit-element-kitchen-sink/.storybook/webpack.config.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,4 @@ | ||
module.exports = async ({ config }) => { | ||
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 the place where help is needed. Please see Also some advanced webpack settings. More example from |
||
config.module.rules[0].include.push(/node_modules(?:\/|\\)lit-element|lit-html/); | ||
return config; | ||
}; |
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,11 @@ | ||
const config = require('../../jest.config'); | ||
|
||
module.exports = { | ||
...config, | ||
roots: [__dirname], | ||
transform: { | ||
...config.transform, | ||
'.*\\.(html)$': '<rootDir>/node_modules/jest-raw-loader', | ||
}, | ||
moduleFileExtensions: [...config.moduleFileExtensions, 'html'], | ||
}; |
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,45 @@ | ||
{ | ||
"name": "lit-element-kitchen-sink", | ||
"version": "5.2.0-beta.26", | ||
"private": true, | ||
"description": "", | ||
"keywords": [], | ||
"license": "MIT", | ||
"author": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"build-storybook": "build-storybook", | ||
"generate-addon-jest-testresults": "jest --config=tests/addon-jest.config.json --json --outputFile=stories/addon-jest.testresults.json", | ||
"now-build": "node ../../scripts/bootstrap --core && yarn run build-storybook --quiet", | ||
"storybook": "start-storybook -p 9006" | ||
}, | ||
"devDependencies": { | ||
"@storybook/addon-a11y": "5.2.0-beta.26", | ||
"@storybook/addon-actions": "5.2.0-beta.26", | ||
"@storybook/addon-backgrounds": "5.2.0-beta.26", | ||
"@storybook/addon-centered": "5.2.0-beta.26", | ||
"@storybook/addon-docs": "5.2.0-beta.26", | ||
"@storybook/addon-events": "5.2.0-beta.26", | ||
"@storybook/addon-jest": "5.2.0-beta.26", | ||
"@storybook/addon-knobs": "5.2.0-beta.26", | ||
"@storybook/addon-links": "5.2.0-beta.26", | ||
"@storybook/addon-notes": "5.2.0-beta.26", | ||
"@storybook/addon-options": "5.2.0-beta.26", | ||
"@storybook/addon-storyshots": "5.2.0-beta.26", | ||
"@storybook/addon-storysource": "5.2.0-beta.26", | ||
"@storybook/addon-viewport": "5.2.0-beta.26", | ||
"@storybook/addons": "5.2.0-beta.26", | ||
"@storybook/client-api": "5.2.0-beta.26", | ||
"@storybook/core": "5.2.0-beta.26", | ||
"@storybook/core-events": "5.2.0-beta.26", | ||
"@storybook/html": "5.2.0-beta.26", | ||
"@storybook/source-loader": "5.2.0-beta.26", | ||
"@storybook/lit-element": "5.2.0-beta.26", | ||
"eventemitter3": "^4.0.0", | ||
"format-json": "^1.0.3", | ||
"global": "^4.3.2" | ||
}, | ||
"dependencies": { | ||
"lit-element": "^2.1.1" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
probably this title needs to be adjusted to
Lit-Element
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.
Well, there are other mentions in the readme as well, work in progress I guess
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.
great work btw!