-
Notifications
You must be signed in to change notification settings - Fork 8
New documentation website #3217
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
base: main
Are you sure you want to change the base?
Changes from 66 commits
0cb9a54
eb5e335
68dc7b1
ff50a1a
0a81c3c
acb3645
c1bd9b5
43b3719
ae6e6cf
3d55251
9eca31b
eb42f4b
dcf96af
8f21736
4279d1e
b03858a
624d730
222b1a6
acf5db0
51c536b
c375aa7
f378ddc
1ffe76c
3d7a001
a87a3ea
4bc88ab
888a99c
165c9a3
5b538a1
37d6b67
26f0856
53e91a3
d73c5c3
3fc12a6
7b2a9f2
0f98d6d
c3ef871
e627fc0
cab4d8b
dedf662
3c38abf
ba53164
5186700
7a1a36c
346f2c4
fe8f89b
39cf4e0
3fffc5e
ec18529
1cbf739
0bf49cc
8d000b8
9e2869d
7e5daaf
c905ac0
d964ec7
06502c0
37ead40
8945fce
134e06d
638f729
2088061
794838f
55a20b8
2b60679
4444d3f
a8ad91c
891b741
1b72686
d202095
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| sourceControlRootUrl: 'https://github.com/sl-design-system/components/tree/main' | ||
|
|
||
| generate: | ||
| files: | ||
| - 'packages/components/*/src/**/*.ts' | ||
| exclude: | ||
| - 'packages/components/*/src/**/*.spec.ts' | ||
| - 'packages/components/*/src/**/*.stories.ts' | ||
| output: 'custom-elements.json' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,3 +108,5 @@ __snapshots__ | |
|
|
||
| # Intellij | ||
| .idea/ | ||
|
|
||
| *storybook.log | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { importCSSSheet } from '@roenlie/vite-plugin-import-css-sheet' | ||
| import { type StorybookConfig } from '@storybook/web-components-vite'; | ||
| import { dirname } from 'path'; | ||
| import { fileURLToPath } from 'url'; | ||
|
|
||
| /** | ||
| * This function is used to resolve the absolute path of a package. | ||
| * It is needed in projects that use Yarn PnP or are set up within a monorepo. | ||
| */ | ||
| function getAbsolutePath(value: string) { | ||
| return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`))) | ||
| } | ||
|
|
||
| const config: StorybookConfig = { | ||
| stories: [ | ||
| '../src/**/*.stories.ts' | ||
| ], | ||
| addons: [ | ||
| getAbsolutePath('@storybook/addon-vitest'), | ||
| getAbsolutePath('@storybook/addon-a11y'), | ||
| getAbsolutePath('@storybook/addon-docs') | ||
| ], | ||
| core: { | ||
| disableTelemetry: true | ||
| }, | ||
| framework: getAbsolutePath('@storybook/web-components-vite'), | ||
| staticDirs: [ | ||
| { from: '../../../packages/themes', to: '/themes' }, | ||
| ], | ||
| async viteFinal(config) { | ||
| const { mergeConfig } = await import('vite'); | ||
|
|
||
| return mergeConfig(config, { | ||
| plugins: [importCSSSheet()] | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| export default config; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <link rel="stylesheet" href="https://use.typekit.net/kes1hoh.css" /> | ||
| <link rel="stylesheet" href="/themes/sanoma-learning/global.css" /> | ||
| <link rel="stylesheet" href="/themes/sanoma-learning/light.css" /> | ||
| <style> | ||
| body { | ||
| background: var(--sl-elevation-surface-base-default); | ||
| color: var(--sl-color-foreground-plain); | ||
| font: var(--sl-text-new-body-md); | ||
| } | ||
| </style> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import '@webcomponents/scoped-custom-element-registry/scoped-custom-element-registry.min.js'; | ||
| import { setup } from '@sl-design-system/sanoma-learning'; | ||
| import { type Preview } from '@storybook/web-components-vite'; | ||
|
|
||
| setup(); | ||
|
|
||
| const preview: Preview = { | ||
| parameters: { | ||
| controls: { | ||
| matchers: { | ||
| color: /(background|color)$/i, | ||
| date: /Date$/i | ||
| } | ||
| }, | ||
|
|
||
| a11y: { | ||
| // 'todo' - show a11y violations in the test UI only | ||
| // 'error' - fail CI on a11y violations | ||
| // 'off' - skip a11y checks entirely | ||
| test: 'todo' | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| export default preview; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import * as a11yAddonAnnotations from "@storybook/addon-a11y/preview"; | ||
| import { setProjectAnnotations } from '@storybook/web-components-vite'; | ||
| import * as projectAnnotations from './preview'; | ||
|
|
||
| // This is an important step to apply the right configuration when testing your stories. | ||
| // More info at: https://storybook.js.org/docs/api/portable-stories/portable-stories-vitest#setprojectannotations | ||
| setProjectAnnotations([a11yAddonAnnotations, projectAnnotations]); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| declare module '*.css' { | ||
| const css: CSSStyleSheet; | ||
| export default css; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,88 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "@sl-design-system/doc-components", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "private": true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type": "module", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "version": "0.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "description": "Web components used in the documentation of the SL Design System", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "license": "ISC", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "repository": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type": "git", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "url": "https://github.com/sl-design-system/components.git" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "exports": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./code-block/code-block.js": "./dist/code-block/code-block.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./code-example/code-example.js": "./dist/code-example/code-example.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./code/code.js": "./dist/code/code.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./copy-button/copy-button.js": "./dist/copy-button/copy-button.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./heading/heading.js": "./dist/heading/heading.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./install-info/install-info.js": "./dist/install-info/install-info.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./open-issue-count/open-issue-count.js": "./dist/open-issue-count/open-issue-count.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./page-toc/page-toc.js": "./dist/page-toc/page-toc.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./search/search.js": "./dist/search/search.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./sidebar/sidebar.js": "./dist/sidebar/sidebar.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./site-nav/nav-group.js": "./dist/site-nav/nav-group.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./site-nav/nav-item.js": "./dist/site-nav/nav-item.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "./site-nav/site-nav.js": "./dist/site-nav/site-nav.js", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+25
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "exports": { | |
| "./code-example/code-example.js": "./dist/code-example/code-example.js", | |
| "./code/code.js": "./dist/code/code.js", | |
| "./copy-button/copy-button.js": "./dist/copy-button/copy-button.js", | |
| "./heading/heading.js": "./dist/heading/heading.js", | |
| "./install-info/install-info.js": "./dist/install-info/install-info.js", | |
| "./page-toc/page-toc.js": "./dist/page-toc/page-toc.js", | |
| "./search/search.js": "./dist/search/search.js", | |
| "./sidebar/sidebar.js": "./dist/sidebar/sidebar.js", | |
| "./site-nav/nav-group.js": "./dist/site-nav/nav-group.js", | |
| "./site-nav/nav-item.js": "./dist/site-nav/nav-item.js", | |
| "./site-nav/site-nav.js": "./dist/site-nav/site-nav.js", | |
| "exports": { | |
| "./code-example/code-example": "./dist/code-example/code-example.js", | |
| "./code-example/code-example.js": "./dist/code-example/code-example.js", | |
| "./code/code": "./dist/code/code.js", | |
| "./code/code.js": "./dist/code/code.js", | |
| "./copy-button/copy-button": "./dist/copy-button/copy-button.js", | |
| "./copy-button/copy-button.js": "./dist/copy-button/copy-button.js", | |
| "./heading/heading": "./dist/heading/heading.js", | |
| "./heading/heading.js": "./dist/heading/heading.js", | |
| "./install-info/install-info": "./dist/install-info/install-info.js", | |
| "./install-info/install-info.js": "./dist/install-info/install-info.js", | |
| "./page-toc/page-toc": "./dist/page-toc/page-toc.js", | |
| "./page-toc/page-toc.js": "./dist/page-toc/page-toc.js", | |
| "./search/search": "./dist/search/search.js", | |
| "./search/search.js": "./dist/search/search.js", | |
| "./sidebar/sidebar": "./dist/sidebar/sidebar.js", | |
| "./sidebar/sidebar.js": "./dist/sidebar/sidebar.js", | |
| "./site-nav/nav-group": "./dist/site-nav/nav-group.js", | |
| "./site-nav/nav-group.js": "./dist/site-nav/nav-group.js", | |
| "./site-nav/nav-item": "./dist/site-nav/nav-item.js", | |
| "./site-nav/nav-item.js": "./dist/site-nav/nav-item.js", | |
| "./site-nav/site-nav": "./dist/site-nav/site-nav.js", | |
| "./site-nav/site-nav.js": "./dist/site-nav/site-nav.js", | |
| "./theme-switch/theme-switch": "./dist/theme-switch/theme-switch.js", |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| :host { | ||
| background: var(--sl-color-background-accent-grey-subtlest); | ||
| border-radius: var(--sl-size-borderRadius-default); | ||
| display: block; | ||
| overflow-x: auto; | ||
| padding: var(--sl-size-200); | ||
| position: relative; | ||
| } | ||
|
|
||
| :host(:hover) doc-copy-button, | ||
| doc-copy-button:focus-within { | ||
| opacity: 1; | ||
| } | ||
|
|
||
| ::slotted(pre) { | ||
| background: transparent !important; | ||
| margin: 0 !important; | ||
| padding: 0 !important; | ||
| } | ||
|
|
||
| doc-copy-button { | ||
| inset-block-start: var(--sl-size-100); | ||
| inset-inline-end: var(--sl-size-100); | ||
| opacity: 0; | ||
| position: absolute; | ||
| transition: opacity 0.15s; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { fixture } from '@sl-design-system/vitest-browser-lit'; | ||
| import { html } from 'lit'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { Code } from './code-block.js'; | ||
|
|
||
| try { | ||
| customElements.define('doc-code-block', Code); | ||
| } catch { | ||
| /* empty */ | ||
| } | ||
|
|
||
| describe('doc-code-block', () => { | ||
| let el: Code; | ||
|
|
||
| describe('defaults', () => { | ||
| beforeEach(async () => { | ||
| el = await fixture(html` | ||
| <doc-code-block> | ||
| <pre><code>const foo = 'bar';</code></pre> | ||
| </doc-code-block> | ||
| `); | ||
| }); | ||
|
|
||
| it('should render', () => { | ||
| expect(el).to.exist; | ||
| expect(el).to.be.instanceOf(Code); | ||
| }); | ||
|
|
||
| it('should render a default slot', () => { | ||
| const slot = el.renderRoot.querySelector<HTMLSlotElement>('slot:not([name])'); | ||
|
|
||
| expect(slot).to.exist; | ||
| expect(slot?.assignedElements()).to.have.length.greaterThan(0); | ||
| }); | ||
|
|
||
| it('should render a copy button', () => { | ||
| expect(el.renderRoot.querySelector('doc-copy-button')).to.exist; | ||
| }); | ||
|
|
||
| it('should set the copy button content from the slotted pre element', () => { | ||
| const copyButton = el.renderRoot.querySelector<HTMLElement & { content?: string }>('doc-copy-button'); | ||
|
|
||
| expect(copyButton?.content).to.equal("const foo = 'bar';"); | ||
| }); | ||
|
|
||
| it('should copy the source to the clipboard on click', async () => { | ||
| const writeText = vi.spyOn(navigator.clipboard, 'writeText').mockResolvedValue(undefined); | ||
|
|
||
| const copyButtonHost = el.renderRoot.querySelector('doc-copy-button')! as Element & { renderRoot: ShadowRoot }; | ||
| copyButtonHost.renderRoot.querySelector<HTMLElement>('sl-button')!.click(); | ||
| await el.updateComplete; | ||
|
|
||
| expect(writeText).toHaveBeenCalledWith("const foo = 'bar';"); | ||
|
|
||
| writeText.mockRestore(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('without pre element', () => { | ||
| beforeEach(async () => { | ||
| el = await fixture(html`<doc-code-block><span>some text</span></doc-code-block>`); | ||
| }); | ||
|
|
||
| it('should render a copy button with no content', () => { | ||
| const copyButton = el.renderRoot.querySelector<HTMLElement & { content?: string }>('doc-copy-button'); | ||
|
|
||
| expect(copyButton?.content).to.equal(''); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { type Meta, type StoryObj } from '@storybook/web-components-vite'; | ||
| import { html } from 'lit'; | ||
| import { Code } from './code-block.js'; | ||
|
|
||
| type Story = StoryObj; | ||
|
|
||
| try { | ||
| customElements.define('doc-code-block', Code); | ||
| } catch { | ||
| /* empty */ | ||
| } | ||
|
|
||
| export default { | ||
| title: 'Code', | ||
| render: () => html` | ||
| <doc-code-block> | ||
| <pre><code class="language-typescript">import { LitElement, html } from 'lit'; | ||
|
|
||
| export class MyElement extends LitElement { | ||
| override render() { | ||
| return html\`<p>Hello world!</p>\`; | ||
| } | ||
| }</code></pre> | ||
| </doc-code-block> | ||
| ` | ||
| } satisfies Meta; | ||
|
|
||
| export const Basic: Story = {}; | ||
|
|
||
| export const MultiLine: Story = { | ||
| render: () => html` | ||
| <doc-code-block> | ||
| <pre><code class="language-html"><sl-button variant="primary">Click me</sl-button> | ||
| <sl-button variant="default">Cancel</sl-button></code></pre> | ||
| </doc-code-block> | ||
| ` | ||
| }; | ||
|
|
||
| export const CSS: Story = { | ||
| render: () => html` | ||
| <doc-code-block> | ||
| <pre><code class="language-css">:host { | ||
| display: block; | ||
| color: red; | ||
| }</code></pre> | ||
| </doc-code-block> | ||
| ` | ||
| }; |
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.
This setup file uses double quotes in the import, which will violate the repo’s enforced single-quote rule (
@stylistic/quotes) and likely fail lint/format checks. Update to single quotes (and run formatting).