Skip to content

Commit

Permalink
feat(scripts): update component generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Jul 29, 2024
1 parent e3054e8 commit 5d8caec
Show file tree
Hide file tree
Showing 49 changed files with 722 additions and 127 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"build:storybook": "lerna run --stream build:storybook",
"clean": "lerna run clean",
"doc": "lerna run doc",
"generate:component": "plop --plopfile scripts/component-generator/plopfile.js component",
"lint": "yarn lint:ts && yarn lint:scss",
"lint:ts": "lerna run lint:ts",
"lint:scss": "lerna run lint:scss",
"new:component": "plop --plopfile scripts/component-generator/plopfile.js component",
"ods:graduate": "yarn ods:release:prepare && yarn version:graduate",
"ods:major": "yarn ods:release:prepare && yarn version:major",
"ods:minor": "yarn ods:release:prepare && yarn version:minor",
Expand Down
15 changes: 15 additions & 0 deletions packages/ods/react/tests/_app/src/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* File generated and updated using the component generator.
*
* You should not update this file manually!
*
* If you want to create a new component,
* please use the generator command `yarn new:component` at the root of the project
*/
const componentNames = [
'spinner',
'text',
//--generator-anchor--
];

export { componentNames };
35 changes: 24 additions & 11 deletions packages/ods/react/tests/_app/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { createRoot } from 'react-dom/client';
import { StrictMode, Suspense, lazy } from 'react';
import { BrowserRouter, Link, Route, Routes } from 'react-router-dom';
// TODO automate
const Spinner = lazy(() => import('./ods-spinner'));
const Text = lazy(() => import('./ods-text'));
import { componentNames } from './components';

const root = createRoot(document.getElementById('root')!);

Expand All @@ -13,16 +11,31 @@ function renderApp() {
<BrowserRouter>
<Suspense>
<Routes>
<Route path="/ods-spinner" element={ <Spinner /> } />
<Route path="/ods-text" element={ <Text /> } />
{
componentNames.map((componentName, idx) => {
const Component = lazy(() =>
import(/* @vite-ignore */
`./components/ods-${componentName}`).then(comp => comp)
);

return (
<Route key={ idx }
path={ `/ods-${componentName}` }
element={ <Component /> } />
)
})
}

<Route path="*" element={
<ul>
<li>
<Link id="ods-spinner" to="/ods-spinner">ods-spinner</Link>
</li>
<li>
<Link id="ods-text" to="/ods-text">ods-text</Link>
</li>
{
componentNames.map((componentName, idx) => (
<li key={ idx }>
<Link id={ `ods-${componentName}` }
to={ `/ods-${componentName}` }>ods-{ componentName }</Link>
</li>
))
}
</ul>
} />
</Routes>
Expand Down
8 changes: 8 additions & 0 deletions packages/ods/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
/**
* File generated and updated using the component generator.
*
* You should not update this file manually!
*
* If you want to create a new component,
* please use the generator command `yarn new:component` at the root of the project
*/
export * from './spinner/src';
export * from './text/src';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
* [**Interfaces**](#interfaces)
* [**Types**](#types)

## Interfaces

### OdsSpinnerAttribute
|Name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`contrasted`** | _boolean_ | | | contrasted or not: see component principles|
|**`inline`** | _boolean_ | | | full width or not: see component principles|
|**`mode`** | `indeterminate` | | | choose between infinite or progress spinner (infinite only for now)|
|**`size`** | `ODS_SPINNER_SIZE` | | | size: see component principles|

## Types

### ODS_SPINNER_MODE
| |
|:---:|
| `indeterminate` |

### ODS_SPINNER_SIZE
| |
|:---:|
| `lg` |
| `md` |
| `sm` |
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Markdown } from '@storybook/addon-docs';
import Specs from './spec.md';

<Markdown>{ Specs }</Markdown>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Canvas } from '@storybook/addon-docs';

<Canvas sourceState="none">
<ods-spinner color="primary"></ods-spinner>
</Canvas>

```html
<ods-spinner color="primary"></ods-spinner>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Canvas } from '@storybook/addon-docs';

<Canvas sourceState="none">
<ods-spinner size='sm'></ods-spinner>
<ods-spinner size='md'></ods-spinner>
<ods-spinner size='lg'></ods-spinner>
</Canvas>

```html
<ods-spinner size='sm'></ods-spinner>
<ods-spinner size='md'></ods-spinner>
<ods-spinner size='lg'></ods-spinner>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Canvas } from '@storybook/addon-docs';
import ColorProperty from './properties/usage.color.mdx';
import SizeProperty from './properties/usage.size.mdx';

## Usage

### Default

<Canvas sourceState="none">
<div style={{ height: '300px', display: 'inline-flex'}}>
<ods-spinner></ods-spinner>
</div>
</Canvas>

```html
<div style='height: 300px; display: inline-flex'>
<ods-spinner></ods-spinner>
</div>
```

### Color

<ColorProperty />

### Size

<SizeProperty />
1 change: 0 additions & 1 deletion packages/ods/src/components/spinner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"collection": "dist/collection/collection-manifest.json",
"scripts": {
"clean": "rimraf .stencil coverage dist docs-api www",
"__doc": "typedoc --pretty && node ../../../scripts/generate-typedoc-md.js",
"doc": "typedoc --pretty --plugin typedoc-plugin-markdown --hideBreadcrumbs true --hideInPageTOC true",
"lint:scss": "stylelint 'src/components/**/*.scss'",
"lint:ts": "eslint 'src/**/*.{js,ts,tsx}'",
Expand Down
2 changes: 1 addition & 1 deletion packages/ods/src/components/spinner/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset='utf-8' />
<meta name='viewport' content='width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=5.0' />
<title>Dev ods-text</title>
<title>Dev ods-spinner</title>

<script type='module' src='/build/ods-spinner.esm.js'></script>
<script nomodule src='/build/ods-spinner.js'></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('ods-spinner accessibility', () => {
el = await page.find('ods-spinner');
}

it('should render the web component with the correct role', async() => {
it('should render the web component with the right role', async() => {
await setup('<ods-spinner></ods-spinner>');

expect(el.shadowRoot).not.toBeNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe('ods-spinner rendering', () => {
let page: SpecPage;
let root: HTMLElement | undefined;

async function setup(html: string) {
async function setup(html: string): Promise<void> {
page = await newSpecPage({
components: [OdsSpinner],
html,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ODS_TEXT_PRESET } from '../../constants/text-preset';
export class OdsText {
@Element() el!: HTMLElement;

@Prop({ reflect: true }) neededFlag!: boolean;
// @Prop({ reflect: true }) neededFlag!: boolean;
@Prop({ reflect: true }) preset? = ODS_TEXT_PRESET.text;

@State() hasFocus = false;
Expand Down
15 changes: 15 additions & 0 deletions packages/ods/vue/tests/_app/src/components.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* File generated and updated using the component generator.
*
* You should not update this file manually!
*
* If you want to create a new component,
* please use the generator command `yarn new:component` at the root of the project
*/
const componentNames = [
'spinner',
'text',
//--generator-anchor--
];

export { componentNames };
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { defineComponent } from 'vue';
import { OdsSpinner } from '@ovhcloud/ods-components/vue';
export default defineComponent({
name: 'App',
name: 'Spinner',
components: {
OdsSpinner,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { defineComponent } from 'vue';
import { OdsText } from '@ovhcloud/ods-components/vue';
export default defineComponent({
name: 'App',
name: 'Text',
components: {
OdsText,
},
Expand Down
21 changes: 6 additions & 15 deletions packages/ods/vue/tests/_app/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import SpinnerView from '../views/Spinner.vue';
import TextView from '../views/Text.vue';
import { componentNames } from '../components';

// TODO generate
const routes: Array<RouteRecordRaw> = [
{
path: '/ods-spinner',
name: 'ods-spinner',
component: SpinnerView,
},
{
path: '/ods-text',
name: 'ods-text',
component: TextView,
},
];
const routes: Array<RouteRecordRaw> = componentNames.map((componentName) => ({
component: () => import(`../components/ods-${componentName}.vue`),
path: `/ods-${componentName}`,
name: `ods-${componentName}`,
}))

const router = createRouter({
history: createWebHashHistory(),
Expand Down
1 change: 1 addition & 0 deletions packages/storybook/.storybook/preview.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// import { DocsPage, DocsContainer } from '@storybook/addon-docs'; // TODO check what is it for?
import '@ovhcloud/ods-themes';

/** @type { import('@storybook/web-components').Preview } */
const preview = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Meta } from '@storybook/addon-docs';
import SpecificationsSpinner from '@ovhcloud/ods-components/src/components/spinner/documentation/specifications/specifications-spinner.mdx';

<Meta title="ODS Components/User feedback/Spinner [atom]/Specifications" />

# Spinner - Design Specifications
----

A visual indicator that a process is happening in the background but the interface is not yet ready for interaction:
<div>
<osds-button color="primary" variant="ghost" href="https://zeroheight.com/6fc8a63f7/p/9017bb-spinner/b/40a887" target="_blank">
ZEROHEIGHT - SPINNER DESIGN GUIDELINES &nbsp;
<osds-icon name="external-link" color="primary" size="xs"></osds-icon>
</osds-button>
</div>

# Spinner - Technical Specification
----

<SpecificationsSpinner />
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Meta } from '@storybook/addon-docs';
import Usage from '@ovhcloud/ods-components/src/components/spinner/documentation/usage-guidelines/usage.mdx';

<Meta title="ODS Components/User feedback/Spinner [atom]/Usage Guidelines" />

# Spinner - Usage Guidelines
----

<Usage />
34 changes: 34 additions & 0 deletions packages/storybook/stories/components/spinner/3_demo.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ODS_SPINNER_COLOR, ODS_SPINNER_COLORS, ODS_SPINNER_SIZE, ODS_SPINNER_SIZES } from '@ovhcloud/ods-components';
import { defineCustomElement } from '@ovhcloud/ods-components/dist/components/ods-spinner';
import { html } from 'lit-html';

defineCustomElement();

export default {
title: 'ODS Components/User feedback/Spinner [atom]/Demo',
render: (args) => html`
<ods-spinner color="${args.color}"
size="${args.size}">
</ods-spinner>
`,
argTypes: {
color: {
// category: 'General', // TODO not native storybook, need a table
control: { type: 'select' },
options: ODS_SPINNER_COLORS,
},
size: {
// category: 'General', // TODO not native storybook, need a table
control: { type: 'select' },
options: ODS_SPINNER_SIZES,
},
},
args: {
color: ODS_SPINNER_COLOR.primary,
size: ODS_SPINNER_SIZE.md,
},
};

export const Default = {
args: {},
};
32 changes: 0 additions & 32 deletions packages/storybook/stories/components/text/3_demo.stories.ts

This file was deleted.

Loading

0 comments on commit 5d8caec

Please sign in to comment.