Skip to content

Commit

Permalink
feat(arch): move && simplify component skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois Eoche authored and dpellier committed Aug 16, 2023
1 parent 028b0ee commit 2003153
Show file tree
Hide file tree
Showing 79 changed files with 412 additions and 543 deletions.
1 change: 1 addition & 0 deletions packages-new/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@ovhcloud/ods-component-pagination": "^15.0.1",
"@ovhcloud/ods-component-password": "^15.0.1",
"@ovhcloud/ods-component-select": "^15.0.1",
"@ovhcloud/ods-component-skeleton": "^15.0.1",
"@ovhcloud/ods-component-spinner": "^15.0.1",
"@ovhcloud/ods-component-text": "^15.0.1",
"@ovhcloud/ods-component-textarea": "^15.0.1",
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
* [**Interfaces**](#interfaces)
* [**Types**](#types)
* [**Classes**](#classes)
* [**Type alias**](#type-alias)
* [**Variables**](#variables)

## Interfaces

### OdsSkeletonAttributes
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`flex`** | _boolean_ | | | Wether or not skeleton size fill its parent|
|**`randomized`** | _boolean_ | | | Wether or not skeleton size is randomized|
|**`size`** | `OdsSkeletonSize` | | | Skeleton size|

### OdsSkeletonBehavior
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`hostElement`** | `Host` | ✴️ | | reference to the host element of the component|
|**`afterInit`** | _void_ | ✴️ | | method executed after initialization of component(`componentDidLoad` with stenciljs for instance).this method has to call OdsSkeletonController.afterInit|

## Types

### OdsSkeletonSize
| |
|:---:|
| `lg` |
| `md` |
| `sm` |
| `xl` |
| `xs` |

## Classes

### OdsSkeletonController
_common controller logic for skeleton component used by the different implementations._
_it contains all the glue between framework implementation and the third party service._

#### Methods
> **afterInit**() => _unknown_


## Type alias

### OdsSkeleton

interface description of all implementations of `ods-skeleton`.
each implementation must have defined events, methods, attributes
and one controller for the common behavior logic

> - `OdsComponentGenericMethods`
> - `OdsComponentGenericEvents`
### OdsSkeletonAttributes

> _Based on `OdsComponentAttributes`_
### OdsSkeletonEvents

> _Based on `OdsComponentEvents`_
### OdsSkeletonMethods

> _Based on `OdsComponentMethods`_
## Variables

### odsSkeletonDefaultAttributes
`OdsSkeletonAttributes`
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {Description} from '@storybook/addon-docs';
import Specs from './spec.md';
import SpecsSkeletonContents from './specifications-skeleton-contents.mdx';
import SpecsSkeletonTests from './specifications-skeleton-tests.mdx';

## Description
The skeleton component can be displayed in different sizes or its width can be randomized.

<Description>{Specs}</Description>

## Contents
<SpecsSkeletonContents />

## Tests
<SpecsSkeletonTests />
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from '@jest/types';
import { OdsGetJestConfig } from '@ovhcloud/ods-testing';
import { OdsGetJestConfig } from '@ovhcloud/ods-common-testing';

const args = process.argv.slice(2);

Expand All @@ -15,8 +15,9 @@ const args = process.argv.slice(2);
* };
* ```
*/
// @ts-ignore until dependencies are fixed to one unique version of @jest/types
const config: Config.InitialOptions = OdsGetJestConfig({
basePath: '<rootDir>/../../../..',
basePath: '<rootDir>/../../..',
args
});
export default config;
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "@ovhcloud/ods-stencil-skeleton",
"name": "@ovhcloud/ods-component-skeleton",
"version": "15.0.1",
"private": true,
"description": "Skeleton component",
"description": "ODS Skeleton component",
"license": "Apache-2.0",
"main": "dist/index.cjs.js",
"module": "dist/index.js",
"es2015": "dist/esm/index.js",
"es2017": "dist/esm/index.js",
"types": "dist/types/components.d.ts",
"types": "dist/types/index.d.ts",
"collection": "dist/collection/collection-manifest.json",
"collection:main": "dist/collection/index.js",
"scripts": {
Expand All @@ -34,9 +33,12 @@
"test:e2e:ci:screenshot:update": "stencil test --config stencil.config.ts --e2e --ci --screenshot --update-screenshot --passWithNoTests"
},
"dependencies": {
"@ovhcloud/ods-stencil-component": "^15.0.1"
"@ovhcloud/ods-common-core": "^15.0.1",
"@ovhcloud/ods-common-stencil": "^15.0.1",
"@ovhcloud/ods-theming": "^15.0.1"
},
"devDependencies": {
"@ovhcloud/ods-stencil-component-dev": "^15.0.1"
"@ovhcloud/ods-common-testing": "^15.0.1",
"@ovhcloud/ods-stencil-dev": "^15.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@ovhcloud/ods-stencil-skeleton-react",
"name": "@ovhcloud/ods-component-skeleton-react",
"version": "15.0.1",
"private": true,
"description": "React specific wrapper for ods",
Expand All @@ -19,19 +19,13 @@
"dist/"
],
"dependencies": {
"@ovhcloud/ods-stencil-cart": "^15.0.1",
"tslib": "*"
"@ovhcloud/ods-component-skeleton": "^15.0.1"
},
"peerDependencies": {
"react": ">=16.8.6",
"react-dom": ">=16.8.6"
},
"devDependencies": {
"@types/react": "17.0.37",
"@types/react-dom": "17.0.11",
"react": "16.14.0",
"react-dom": "16.14.0",
"rimraf": "^3.0.2",
"typescript": "4.7.4"
"@ovhcloud/ods-react-dev": "^15.0.1"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { OdsSkeletonAttribute } from '../interfaces/attributes';
import { ODS_SKELETON_SIZE } from './skeleton-size';

const DEFAULT_ATTRIBUTE: OdsSkeletonAttribute = Object.freeze({
inline: false,
randomized: false,
size: ODS_SKELETON_SIZE.md,
});

export {
DEFAULT_ATTRIBUTE,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
enum ODS_SKELETON_SIZE {
xs = 'xs',
sm = 'sm',
md = 'md',
lg = 'lg',
xl = 'xl',
}

const ODS_SKELETON_SIZES = Object.freeze(Object.values(ODS_SKELETON_SIZE));

export {
ODS_SKELETON_SIZE,
ODS_SKELETON_SIZES,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ODS_SKELETON_SIZE } from '../constants/skeleton-size';

interface OdsSkeletonAttribute {
/** inline or not: see component principles */
inline?: boolean;
/**
* Wether or not skeleton size is randomized
*/
randomized?: boolean
/**
* Skeleton size
*/
size?: ODS_SKELETON_SIZE
}

export {
OdsSkeletonAttribute,
};
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
import { E2EPage, newE2EPage } from '@stencil/core/testing';

import {
OdsComponentAttributes2StringAttributes,
OdsSkeletonAttributes,
OdsSkeletonSize,
odsSkeletonDefaultAttributes,
} from '@ovhcloud/ods-core';
import {
OdsCreateAttributes,
OdsStringAttributes2Str,
odsSkeletonBaseAttributes,
} from '@ovhcloud/ods-testing';
import type { E2EPage } from '@stencil/core/testing';
import type { OdsSkeletonAttribute } from './interfaces/attributes';
import { newE2EPage } from '@stencil/core/testing';
import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str } from '@ovhcloud/ods-common-testing';
import { ODS_SKELETON_SIZE } from './constants/skeleton-size';
import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';

describe('e2e:osds-skeleton', () => {
let page: E2EPage;

async function setup({ attributes = {} }: { attributes?: Partial<OdsSkeletonAttributes>, html?: string }) {
const minimalAttributes: OdsSkeletonAttributes = OdsCreateAttributes(attributes, odsSkeletonBaseAttributes);
const stringAttributes = OdsComponentAttributes2StringAttributes<OdsSkeletonAttributes>(minimalAttributes, odsSkeletonDefaultAttributes);
async function setup({ attributes = {} }: { attributes?: Partial<OdsSkeletonAttribute>, html?: string }) {
const stringAttributes = odsComponentAttributes2StringAttributes<OdsSkeletonAttribute>(attributes, DEFAULT_ATTRIBUTE);

page = await newE2EPage();
await page.setContent(`
<div class="container">
<div style="background: black;height: 10px"></div>
<osds-skeleton ${OdsStringAttributes2Str(stringAttributes)}></osds-skeleton>
<osds-skeleton ${odsStringAttributes2Str(stringAttributes)}></osds-skeleton>
<div style="background: black;height: 10px"></div>
</div>
`);
Expand All @@ -44,7 +36,7 @@ describe('e2e:osds-skeleton', () => {
});

it('check size small', async () => {
await setup({ attributes: { size: OdsSkeletonSize.sm } });
await setup({ attributes: { size: ODS_SKELETON_SIZE.sm } });
await page.waitForChanges();
await page.evaluate(() => {
const element = document.querySelector('.container') as HTMLElement;
Expand All @@ -56,7 +48,7 @@ describe('e2e:osds-skeleton', () => {
});

it('check size medium', async () => {
await setup({ attributes: { size: OdsSkeletonSize.md } });
await setup({ attributes: { size: ODS_SKELETON_SIZE.md } });
await page.waitForChanges();
await page.evaluate(() => {
const element = document.querySelector('.container') as HTMLElement;
Expand All @@ -68,7 +60,7 @@ describe('e2e:osds-skeleton', () => {
});

it('check size large', async () => {
await setup({ attributes: { size: OdsSkeletonSize.lg } });
await setup({ attributes: { size: ODS_SKELETON_SIZE.lg } });
await page.waitForChanges();
await page.evaluate(() => {
const element = document.querySelector('.container') as HTMLElement;
Expand All @@ -80,7 +72,7 @@ describe('e2e:osds-skeleton', () => {
});

it('check size extra large', async () => {
await setup({ attributes: { size: OdsSkeletonSize.xl } });
await setup({ attributes: { size: ODS_SKELETON_SIZE.xl } });
await page.waitForChanges();
await page.evaluate(() => {
const element = document.querySelector('.container') as HTMLElement;
Expand All @@ -92,15 +84,15 @@ describe('e2e:osds-skeleton', () => {
});
})

it('check flex attribute', async () => {
await setup({ attributes: { flex: true } });
it('check inline attribute', async () => {
await setup({ attributes: { inline: true } });
await page.waitForChanges();
await page.evaluate(() => {
const element = document.querySelector('.container') as HTMLElement;
return { width: element.clientWidth, height: element.clientHeight };
});
await page.setViewport({ width: 600, height:600 });
const results = await page.compareScreenshot('flex', { fullPage: false });
const results = await page.compareScreenshot('inline', { fullPage: false });
expect(results).toMatchScreenshot({ allowableMismatchedRatio: 0 })
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { E2EElement, E2EPage } from '@stencil/core/testing';
import type { OdsSkeletonAttribute } from './interfaces/attributes';
import { newE2EPage } from '@stencil/core/testing';
import { odsComponentAttributes2StringAttributes, odsStringAttributes2Str } from '@ovhcloud/ods-common-testing';
import { DEFAULT_ATTRIBUTE } from './constants/default-attributes';

describe('e2e:osds-skeleton', () => {
let page: E2EPage;
let el: E2EElement;
let skeletonElement: E2EElement;

async function setup({ attributes }: { attributes: Partial<OdsSkeletonAttribute> }) {
const stringAttributes = odsComponentAttributes2StringAttributes<OdsSkeletonAttribute>(attributes, DEFAULT_ATTRIBUTE);

page = await newE2EPage();
await page.setContent(`<osds-skeleton ${odsStringAttributes2Str(stringAttributes)}></osds-skeleton>`);
await page.evaluate(() => document.body.style.setProperty('margin', '0px'));

el = await page.find('osds-skeleton');

skeletonElement = await page.find('osds-skeleton >>> div');
}

it('should render', async () => {
await setup({ attributes: {} });
expect(el).not.toBeNull();
expect(skeletonElement).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
@import '~@ovhcloud/ods-theming/ods-theme';

:host {
display: block;
min-height: .5rem;
position: relative;
display: flex;

&::before {
content: "\00a0";
Expand Down Expand Up @@ -38,10 +38,10 @@
}
}

[flex] {
:host([inline]) {
@include osds-skeleton-on-selected-host() {
display: flex;
width: 100%;
display: inline-block;
width: var(--width);
}
}

Expand Down
Loading

0 comments on commit 2003153

Please sign in to comment.