Skip to content

Commit

Permalink
feat: storybook props with lit
Browse files Browse the repository at this point in the history
  • Loading branch information
rjborba committed Jul 15, 2024
1 parent 328b8ba commit 003d743
Show file tree
Hide file tree
Showing 26 changed files with 747 additions and 1,821 deletions.
30 changes: 0 additions & 30 deletions apps/storybook/.storybook/main.js

This file was deleted.

9 changes: 9 additions & 0 deletions apps/storybook/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { StorybookConfig } from '@storybook/web-components-vite'

const config: StorybookConfig = {
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: ['@storybook/addon-essentials', '@storybook/addon-a11y'],
framework: '@storybook/web-components-vite',
docs: {},
}
export default config
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { defineCustomElements } from './../../../packages/ui-stencil/loader'
import { defineCustomElements } from 'ui-stencil/loader'
import 'ui-stencil/dist/orama-ui/orama-ui.css'
import './storybook.css'
import { html } from 'lit-html'

defineCustomElements()

const LIGTH_THEME_BG = '#fbfbfb'
const DARK_THEME_BG = '#050505'

/** @type { import('@storybook/html').Preview } */
const preview = {
decorators: [
(story, context) => {
const classTheme = context.globals?.backgrounds?.value === DARK_THEME_BG ? 'theme-dark' : 'theme-light'
return `<div id="orama-ui" class="${classTheme}">${story()}</div>`
return html`<div id="orama-ui" class="${classTheme}">${story()}</div>`
},
],
parameters: {
Expand Down
3 changes: 0 additions & 3 deletions apps/storybook/.storybook/storybook.css

This file was deleted.

37 changes: 17 additions & 20 deletions apps/storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,30 @@
"storybook-test": "storybook build && clear && concurrently -k -s first -n 'Server,Test' -c 'magenta,blue' --hide 'Server' 'http-server ./storybook-static --port 6006 --silent' 'wait-on http-get://127.0.0.1:6006 && test-storybook --no-cache --verbose --'"
},
"dependencies": {
"@storybook/web-components": "^8.1.11",
"@storybook/web-components": "^8.2.3",
"ui-stencil": "workspace:*"
},
"devDependencies": {
"@chromatic-com/storybook": "^1",
"@chromatic-com/storybook": "^1.6.1",
"@open-wc/lit-helpers": "^0.7.0",
"@stencil/core": "^4.19.0",
"@storybook/addon-a11y": "^8.1.11",
"@storybook/addon-designs": "^8.0.2",
"@storybook/addon-essentials": "^8.1.11",
"@storybook/addon-interactions": "^8.1.11",
"@storybook/addon-links": "^8.1.11",
"@storybook/addon-storysource": "^8.1.11",
"@storybook/addon-styling-webpack": "^1.0.0",
"@storybook/addon-themes": "^8.1.11",
"@storybook/blocks": "^8.1.11",
"@storybook/html": "^8.1.11",
"@storybook/html-vite": "^8.1.11",
"@storybook/manager-api": "^8.1.11",
"@storybook/nextjs": "^8.1.11",
"@storybook/react": "^8.1.11",
"@storybook/test": "^8.1.11",
"@storybook/test-runner": "^0.19.0",
"@storybook/theming": "^8.1.11",
"@storybook/addon-a11y": "^8.2.3",
"@storybook/addon-essentials": "^8.2.3",
"@storybook/blocks": "^8.2.3",
"@storybook/html": "^8.2.3",
"@storybook/html-vite": "^8.2.3",
"@storybook/manager-api": "^8.2.3",
"@storybook/nextjs": "^8.2.3",
"@storybook/react": "^8.2.3",
"@storybook/test": "^8.2.3",
"@storybook/test-runner": "^0.19.1",
"@storybook/theming": "^8.2.3",
"@storybook/web-components-vite": "^8.2.3",
"eslint-plugin-storybook": "^0.8.0",
"lit-html": "^3.1.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"storybook": "^8.1.11",
"storybook": "^8.2.3",
"storybook-addon-stencil": "^0.2.1",
"typescript": "^5.0.2",
"vite": "^4.4.5",
Expand Down
27 changes: 16 additions & 11 deletions apps/storybook/stories/orama-button.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
import type { StoryObj, Meta } from '@storybook/html'
import type { StoryObj, Meta } from '@storybook/web-components'
import type { Components } from 'ui-stencil'
import { spread } from '@open-wc/lit-helpers'
import { html } from 'lit-html'

const meta = {
title: 'Internal/Button',
const meta: Meta<Components.OramaButton> = {
title: 'Internal/OramaButton',
component: 'orama-button',
} satisfies Meta
argTypes: {
variant: {
control: { type: 'select' },
options: ['primary', 'secondary'],
},
},
}

export default meta

type Story = StoryObj
type Story = StoryObj<Components.OramaButton>

const Template = (content: string) => (args) =>
`
<orama-button variant=${args.variant} class=${args.class}>${content}</orama-button>
`
const Template = (content: string) => (args) => html`<orama-button ${spread(args)}>${content}</orama-button>`

export const Primary: Story = {
export const OramaButton: Story = {
render: Template('Primary button'),
args: {
variant: 'primary',
class: 'my-optional-class',
type: 'button',
},
}
15 changes: 3 additions & 12 deletions apps/storybook/stories/orama-chat.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
import type { StoryObj, Meta } from '@storybook/web-components'
import type { Components } from 'ui-stencil'

const meta: Meta = {
const meta: Meta<Components.OramaChat> = {
title: 'Internal/OramaChat',
component: 'orama-chat',
}

export default meta
type Story = StoryObj
type Story = StoryObj<Components.OramaChat>

const Template = (args) => {
return `
<div style="height: 800px; width: 360px; border: 1px solid white; display: flex; flex-direction: column;">
<orama-chat ${{ ...args }}></orama-chat>
</div>
`
}

// More on writing stories with args: https://storybook.js.org/docs/html/writing-stories/args
export const OramaChat: Story = {
render: Template,
args: {},
}
30 changes: 13 additions & 17 deletions apps/storybook/stories/orama-facets.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
// Create a story for the OramaFacets web component
import { h } from '@stencil/core'
import type { StoryObj, Meta } from '@storybook/web-components'
import type { Components } from 'ui-stencil'
import { fn } from '@storybook/test'

const meta: Meta = {
title: 'Internal/Facets',
const meta: Meta<Components.OramaFacets> = {
title: 'Internal/OramaFacets',
component: 'orama-facets',
}

export default meta

type Story = StoryObj

const Template = (args) => {
return `
<div>
<p>Something that uses facets</p>
<orama-facets current-facet=${args.currentFacet} facets=${JSON.stringify(args.facets)}></orama-facets>
</div>
`
}
type Story = StoryObj<Components.OramaFacets>

// More on writing stories with args: https://storybook.js.org/docs/html/writing-stories/args
export const Facets: Story = {
render: Template,
export const OramaFacets: Story = {
args: {
facets: ['FacetOne', 'FacetTwo', 'FacetThree'],
currentFacet: 'Facet 2',
facets: [
{ name: 'FacetOne', count: 200 },
{ name: 'FacetTwo', count: 82 },
{ name: 'FacetThree', count: 74 },
],
selectedFacet: 'FacetOne',
onFacetClick: fn(),
},
}
71 changes: 36 additions & 35 deletions apps/storybook/stories/orama-input.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,42 @@
import type { StoryObj, Meta } from "@storybook/html";

const meta = {
title: "Internal/Form",
tags: ["autodocs"],
} satisfies Meta;

export default meta;
type Story = StoryObj;

const TemplateInput = (args) => `
<orama-input name='test1' label='Small size input' size='small' placeholder="Your name" type='text'>
<orama-input name='test2' label='Medium size input' placeholder="Your surname" type='text'>
<orama-input name='test3' label='Large size input' size='large' placeholder="Your address" type='text'>
`;

export const InputSizes: Story = {
render: TemplateInput,
args: {},
};
import type { StoryObj, Meta } from '@storybook/web-components'
import { html } from 'lit-html'

import type { Components } from 'ui-stencil'
const meta: Meta<Components.OramaInput> = {
title: 'Internal/Form',
component: 'orama-input',
tags: ['autodocs'],
argTypes: {
type: {
control: { type: 'select' },
options: ['text', 'password', 'email', 'number', 'tel', 'url', 'search'],
},
size: {
control: { type: 'select' },
options: ['small', 'medium', 'large'],
},
},
}

const TemplateOnlyInput = (args) => `
<orama-input name='test4' size='large' labelforscreenreaders="Label for screen readers only" placeholder='Your name' type="text">
`;
export default meta
type Story = StoryObj<Components.OramaInput>

export const InputWithoutLabel: Story = {
render: TemplateOnlyInput,
export const Input: Story = {
args: {
// TODO: if I try to pass this arg, the string will be split into an array of attributes - not expected
// labelforscreenreaders: "Label for screen readers only"
name: 'Input',
label: 'Small size input',
placeholder: 'Your name',
size: 'small',
type: 'text',
},
};

const TemplateInputSearch = (args) => `
<orama-input name='test4' size='large' placeholder='Search...' type="search" label-for-screen-readers="Search for something..." default-value="test"></orama-input>
`;
}

export const SearchInput: Story = {
render: TemplateInputSearch,
args: {},
};
args: {
name: 'Input',
size: 'large',
placeholder: 'Search...',
type: 'text',
labelForScreenReaders: 'Search for something...',
},
}
39 changes: 21 additions & 18 deletions apps/storybook/stories/orama-search-results.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
import type { StoryObj, Meta } from '@storybook/html'
import type { Components } from 'ui-stencil'

const meta = {
title: 'Internal/Search Results',
const meta: Meta<Components.OramaSearchResults> = {
title: 'Internal/OramaSearchResults',
component: 'orama-search-results',
} satisfies Meta
}

export default meta
type Story = StoryObj

const Template = (args) => `
<orama-search-results items=${args.items} search-term='test'</orama-search-results>
`
type Story = StoryObj<Components.OramaSearchResults>

export const NoResults: Story = {
render: Template,
args: {},
args: {
sections: [{ section: undefined, items: [] }],
},
}

export const WithResults: Story = {
render: Template,
args: {
items: [
sections: [
{
id: '1',
title: 'Title 1',
description: 'Description 1',
section: 'Section 1',
items: [
{ id: 'id 1', score: 1, title: 'Title 1', description: 'Description 1', path: '../somePath' },
{ id: 'id 2', score: 1, title: 'Title 2', description: 'Description 2', path: '../somePath' },
{ id: 'id 3', score: 1, title: 'Title 3', description: 'Description 3', path: '../somePath' },
],
},
{
id: '2',
title: 'Title 2',
description: 'Description 2',
section: 'Section 2',
items: [
{ id: 'id 1', score: 1, title: 'Title 1', description: 'Description 1', path: '../somePath' },
{ id: 'id 2', score: 1, title: 'Title 2', description: 'Description 2', path: '../somePath' },
{ id: 'id 3', score: 1, title: 'Title 3', description: 'Description 3', path: '../somePath' },
],
},
],
},
Expand Down
21 changes: 6 additions & 15 deletions apps/storybook/stories/orama-search.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import type { StoryObj, Meta } from '@storybook/web-components'
import type { Components } from 'ui-stencil'

const meta: Meta = {
const meta: Meta<Components.OramaSearch> = {
title: 'Internal/OramaSearch',
component: 'orama-search'
component: 'orama-search',
}

export default meta
type Story = StoryObj
type Story = StoryObj<Components.OramaSearch>

const Template = (args) => {
return `
<div style="height: 800px; width: 360px; border: 1px solid white; display: flex; flex-direction: column;">
<orama-search ${{ ...args }}></orama-chat>
</div>
`
}

// More on writing stories with args: https://storybook.js.org/docs/html/writing-stories/args
// TODO: Add controls for props
export const OramaSearch: Story = {
render: Template,
args: {}
args: {},
}
Loading

0 comments on commit 003d743

Please sign in to comment.