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

✨ Lit, Next のデモ作成 #14

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions asg.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@
"folders": [
{
"name": "root",
"path": "."
"path": ".",
},
{
"name": "📦 asg",
"path": "packages/auto-story-generator"
"path": "packages/auto-story-generator",
},
{
"name": "📄 docs",
"path": "docs"
"path": "docs",
},
{
"name": "🧪 demo react",
"path": "demo/react"
"name": "🧪 react",
"path": "demo/react",
},
{
"name": "🧪 demo vue",
"path": "demo/vue"
"name": "🧪 next",
"path": "demo/next",
},
{
"name": "🧪 demo lit",
"path": "demo/lit"
"name": "🧪 vue",
"path": "demo/vue",
},
{
"name": "🧪 demo svelte",
"path": "demo/svelte"
}
"name": "🧪 lit",
"path": "demo/lit",
},
{
"name": "🧪 svelte",
"path": "demo/svelte",
},
],
"settings": {
"cSpell.words": [
Expand All @@ -36,8 +40,8 @@
"satoshi",
"scule",
"vitepress",
"vumdoc"
]
"vumdoc",
],
},
"extensions": {}
"extensions": {},
}
24 changes: 24 additions & 0 deletions demo/lit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
27 changes: 27 additions & 0 deletions demo/lit/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { StorybookConfig } from "@storybook/web-components-vite";
import { mergeConfig } from "vite";

import autoStoryGenerator from "@takuma-ru/auto-story-generator";

const config: StorybookConfig = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
framework: {
name: "@storybook/web-components-vite",
options: {},
},
docs: {
autodocs: "tag",
},
viteFinal: (config) => {
return mergeConfig(config, {
plugins: [
autoStoryGenerator.vite({
preset: "lit",
imports: ["**/src/components/**/*.ce.ts"],
}),
],
});
},
};
export default config;
15 changes: 15 additions & 0 deletions demo/lit/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from "@storybook/web-components";

const preview: Preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
};

export default preview;
16 changes: 16 additions & 0 deletions demo/lit/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + Lit + TS</title>
<link rel="stylesheet" href="./src/index.css" />
<script type="module" src="/src/my-element.ts"></script>
</head>
<body>
<my-element>
<h1>Vite + Lit</h1>
</my-element>
</body>
</html>
29 changes: 29 additions & 0 deletions demo/lit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "lit",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview",
"sb:dev": "storybook dev -p 6006 --no-open",
"sb:build": "storybook build"
},
"dependencies": {
"@takuma-ru/auto-story-generator": "workspace:^",
"lit": "^3.1.0"
},
"devDependencies": {
"@storybook/addon-essentials": "^7.6.12",
"@storybook/addon-links": "^7.6.12",
"@storybook/blocks": "^7.6.12",
"@storybook/web-components": "^7.6.12",
"@storybook/web-components-vite": "^7.6.12",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^7.6.12",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
1 change: 1 addition & 0 deletions demo/lit/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions demo/lit/src/assets/lit.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions demo/lit/src/components/ce-test-a/ce-test-a.ce.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { LitElement, html } from "lit";
import { customElement, property } from "lit/decorators.js";

export type CeTestAProps = {
propA: string;
};

@customElement("vum-button")
export class CeTestA extends LitElement {
@property({ attribute: "prop-a", type: String })
propA: CeTestAProps["propA"] = "default value";

render() {
return html`<div>${this.propA}</div>`;
}
}
23 changes: 23 additions & 0 deletions demo/lit/src/components/ce-test-a/ce-test-a.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { html } from "lit";

import type { Meta, StoryObj } from "@storybook/web-components";

import { CeTestA, CeTestAProps } from "../ce-test-a/ce-test-a.ce";

const meta: Meta<CeTestAProps> = {
title: "components/ce-test-a",
tags: ["autodocs"],
render: (args) => {
new CeTestA();

return html`<ce-test-a prop-a="${args.propA}">ce-test-a</ce-test-a>`;
},
args: { propA: undefined },
argTypes: { propA: { control: "text" } },
};

export default meta;

export type CeTestAStory = StoryObj<CeTestAProps>;

export const Primary: CeTestAStory = {};
Empty file.
38 changes: 38 additions & 0 deletions demo/lit/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
:root {
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;

color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;

font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
}
127 changes: 127 additions & 0 deletions demo/lit/src/my-element.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
import { LitElement, css, html } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import litLogo from './assets/lit.svg'
import viteLogo from '/vite.svg'

/**
* An example element.
*
* @slot - This element has a slot
* @csspart button - The button
*/
@customElement('my-element')
export class MyElement extends LitElement {
/**
* Copy for the read the docs hint.
*/
@property()
docsHint = 'Click on the Vite and Lit logos to learn more'

/**
* The number of times the button has been clicked.
*/
@property({ type: Number })
count = 0

render() {
return html`
<div>
<a href="https://vitejs.dev" target="_blank">
<img src=${viteLogo} class="logo" alt="Vite logo" />
</a>
<a href="https://lit.dev" target="_blank">
<img src=${litLogo} class="logo lit" alt="Lit logo" />
</a>
</div>
<slot></slot>
<div class="card">
<button @click=${this._onClick} part="button">
count is ${this.count}
</button>
</div>
<p class="read-the-docs">${this.docsHint}</p>
`
}

private _onClick() {
this.count++
}

static styles = css`
:host {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.lit:hover {
filter: drop-shadow(0 0 2em #325cffaa);
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

::slotted(h1) {
font-size: 3.2em;
line-height: 1.1;
}

a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
`
}

declare global {
interface HTMLElementTagNameMap {
'my-element': MyElement
}
}
1 change: 1 addition & 0 deletions demo/lit/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
Loading
Loading