Skip to content

Commit

Permalink
feat(dyne-inline): add ability to put el inline (#3)
Browse files Browse the repository at this point in the history
* feat(dyne-inline): add ability to put el inline

* test(dyne-inline): remove old classes
  • Loading branch information
puria authored May 9, 2024
1 parent 3cb15ff commit 3d8973f
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .storybook/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { StorybookConfig } from '@storybook/html-vite';
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials', '@storybook/addon-interactions',
"@saucelabs/storybook-variants"
],
framework: '@storybook/html-vite',
staticDirs: ['../dist'],
async viteFinal(config, options) {
Expand Down
22 changes: 22 additions & 0 deletions .storybook/modes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export const allModes = {
'dark mobile': {
backgrounds: 'dark',
theme: 'dark',
viewport: 'small',
},
'dark desktop': {
backgrounds: 'dark',
theme: 'dark',
viewport: 'large',
},
'light mobile': {
backgrounds: 'light',
theme: 'light',
viewport: 'small',
},
'light desktop': {
backgrounds: 'light',
theme: 'light',
viewport: 'large',
},
};
22 changes: 22 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withThemeByClassName } from '@storybook/addon-themes';
import { Preview } from '@storybook/html';
import { defineCustomElements } from '../loader';
import dyneTheme from './dyne-theme';
Expand All @@ -9,7 +10,28 @@ const preview: Preview = {
actions: { argTypesRegex: '^on[A-Z].*' },
docs: { toc: true, themes: dyneTheme },
layout: 'centered',
viewport: {
viewports: {
iphone: { name: 'Small', styles: { width: '393px', height: '767px' } },
large: { name: 'Large', styles: { width: '1024px', height: '1000px' } },
},
},
backgrounds: {
values: [
{ name: 'light', value: '#fff' },
{ name: 'dark', value: '#1E293B' },
],
},
},
decorators: [
withThemeByClassName({
themes: {
light: 'light',
dark: 'dark',
},
defaultTheme: 'light',
}),
],
};

export default preview;
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@storybook/addon-essentials": "^8.0.8",
"@storybook/addon-interactions": "^8.0.8",
"@storybook/addon-links": "^8.0.8",
"@storybook/addon-themes": "^8.0.10",
"@storybook/blocks": "^8.0.8",
"@storybook/cli": "^8.0.8",
"@storybook/html": "^8.0.8",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export namespace Components {
*/
"size"?: Size;
}
interface DyneInline {
"gap"?: number;
}
}
declare global {
interface HTMLDyneButtonElement extends Components.DyneButton, HTMLStencilElement {
Expand All @@ -30,8 +33,15 @@ declare global {
prototype: HTMLDyneButtonElement;
new (): HTMLDyneButtonElement;
};
interface HTMLDyneInlineElement extends Components.DyneInline, HTMLStencilElement {
}
var HTMLDyneInlineElement: {
prototype: HTMLDyneInlineElement;
new (): HTMLDyneInlineElement;
};
interface HTMLElementTagNameMap {
"dyne-button": HTMLDyneButtonElement;
"dyne-inline": HTMLDyneInlineElement;
}
}
declare namespace LocalJSX {
Expand All @@ -49,15 +59,20 @@ declare namespace LocalJSX {
*/
"size"?: Size;
}
interface DyneInline {
"gap"?: number;
}
interface IntrinsicElements {
"dyne-button": DyneButton;
"dyne-inline": DyneInline;
}
}
export { LocalJSX as JSX };
declare module "@stencil/core" {
export namespace JSX {
interface IntrinsicElements {
"dyne-button": LocalJSX.DyneButton & JSXBase.HTMLAttributes<HTMLDyneButtonElement>;
"dyne-inline": LocalJSX.DyneInline & JSXBase.HTMLAttributes<HTMLDyneInlineElement>;
}
}
}
8 changes: 7 additions & 1 deletion src/components/dyne-button/dyne-button.stories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Components } from '@/src/components.js';
import { Meta, StoryObj } from '@storybook/html';
import type { Components } from '../../components.js';
import { ColorArgTypes, EmphasisArgTypes, SizeArgTypes } from '../types.js';

const meta = {
Expand All @@ -16,6 +16,12 @@ const meta = {
color: 'primary',
size: 'medium',
},
parameters: {
variants: {
enable: true,
include: ['size', 'color'],
},
},
} satisfies Meta<Components.DyneButton>;

export default meta;
Expand Down
11 changes: 11 additions & 0 deletions src/components/dyne-inline/dyne-inline.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
:host {
@apply flex flex-row;
}

$gaps: 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 72, 80, 96;

@each $gap in $gaps {
:host([gap='#{$gap}']) {
@apply gap-#{$gap};
}
}
26 changes: 26 additions & 0 deletions src/components/dyne-inline/dyne-inline.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Components } from '@/src/components';
import { Meta, StoryObj } from '@storybook/html';

const meta = {
title: 'Design System/Atoms/Inline',
component: 'dyne-inline',
render: args => `<dyne-inline gap="${args.gap}"><dyne-button>Click me</dyne-button><dyne-button>Trust me</dyne-button></dyne-inline>`,
argTypes: {
gap: {
control: {
type: 'number',
},
defaultValue: 4,
},
},
} satisfies Meta<Components.DyneInline>;

export default meta;

type Story = StoryObj<Components.DyneInline>;

export const Defaults: Story = {
args: {
gap: 4,
},
};
17 changes: 17 additions & 0 deletions src/components/dyne-inline/dyne-inline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Component, Host, Prop, h } from '@stencil/core';

@Component({
tag: 'dyne-inline',
styleUrl: 'dyne-inline.scss',
shadow: true,
})
export class DyneButton {
@Prop({ reflect: true }) gap?: number = 4;
render() {
return (
<Host>
<slot></slot>
</Host>
);
}
}
17 changes: 17 additions & 0 deletions src/components/dyne-inline/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# dyne-inline



<!-- Auto Generated Below -->


## Properties

| Property | Attribute | Description | Type | Default |
| -------- | --------- | ----------- | -------- | ------- |
| `gap` | `gap` | | `number` | `4` |


----------------------------------------------

*Built with [StencilJS](https://stenciljs.com/)*
16 changes: 16 additions & 0 deletions src/components/dyne-inline/test/dyne-inline.e2e.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf8" />

<!-- Replace with the path to your entrypoint -->
<script src="../../../build/dyne-components.esm.js" type="module"></script>
<script src="../../../build/dyne-components.js" nomodule></script>
</head>
<body>
<dyne-inline>
<dyne-button>Click me</dyne-button>
<dyne-button>Trust me</dyne-button>
</dyne-mimmo>
</body>
</html>
47 changes: 47 additions & 0 deletions src/components/dyne-inline/test/dyne-inline.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { expect } from '@playwright/test';
import { test } from '@stencil/playwright';

test.describe('dyne-inline', () => {
test('should render', async ({ page }) => {
// The path here is the path to the www output relative to the dev server root directory
await page.goto('/components/dyne-inline/test/dyne-inline.e2e.html');

// Rest of test
const component = await page.locator('dyne-inline');
await expect(component).toHaveCSS('display', 'flex');
await expect(component).toHaveClass('hydrated');
await expect(component).toHaveText(`
Click me
Trust me
`);
});
});
6 changes: 6 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
</head>
<body class="p-8">
<div class="grid grid-cols-3 gap-4" id="buttons"></div>
<h1>inline</h1>

<dyne-inline>
<dyne-button>Click me</dyne-button>
<dyne-button>Trust me</dyne-button>
</dyne-inline>
<script>
const sizes = ['small', 'medium', 'large'];
const colors = ['primary', 'secondary', 'tertiary'];
Expand Down
4 changes: 2 additions & 2 deletions stencil.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const config: Config = {
{
type: 'www',
serviceWorker: null, // disable service workers
copy: [{ src: '**/*.html' }, { src: '**/*.css' }]
copy: [{ src: '**/*.html' }, { src: '**/*.css' }],
},
{
type: 'docs-vscode',
Expand All @@ -40,7 +40,7 @@ export const config: Config = {
testing: {
browserHeadless: 'new',
// Stencil Test Runner will no longer execute any 'e2e.ts` files
testRegex: '(/__tests__/.*|(\\.|/)(test|spec)|[//](e2e))\\.[jt]sx?$'
testRegex: '(/__tests__/.*|(\\.|/)(test|spec)|[//](e2e))\\.[jt]sx?$',
},
plugins: [sass(), tailwind(), tailwindHMR()],
rollupPlugins: {
Expand Down
2 changes: 1 addition & 1 deletion tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import type { Config } from 'tailwindcss';

export default {
content: ['./src/**/*.{ts,tsx,html}'],
theme: {},
// theme: {},
plugins: [require('@tailwindcss/line-clamp')],
} satisfies Config;
13 changes: 13 additions & 0 deletions vscode-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@
"description": "button sizes could be: 'small', 'medium' or 'large'"
}
]
},
{
"name": "dyne-inline",
"description": {
"kind": "markdown",
"value": ""
},
"attributes": [
{
"name": "gap",
"description": ""
}
]
}
]
}

0 comments on commit 3d8973f

Please sign in to comment.