Skip to content

Commit

Permalink
feat(button): implement component
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Jul 29, 2024
1 parent fd15623 commit 22b4931
Show file tree
Hide file tree
Showing 44 changed files with 1,274 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"no-nested-ternary": "error",
"no-trailing-spaces": "error",
"object-curly-spacing": ["error", "always"],
"operator-linebreak": ["error", "before"],
"operator-linebreak": ["error", "before", { "overrides": { "&&": "after" }}],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"sort-imports": [
Expand Down
1 change: 1 addition & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"color-named": "never",
"hue-degree-notation": "number",
"scss/at-rule-conditional-no-parentheses": null,
"scss/double-slash-comment-empty-line-before": null,
"scss/no-global-function-names": null,
"selector-class-pattern": [
"^[a-z]([-_]{0,2}?[a-z0-9]+)*(__[a-z0-9]([-]?[a-z0-9]+)*)?(--[a-z0-9]([-]?[a-z0-9]+)*)?$",
Expand Down
1 change: 1 addition & 0 deletions packages/ods/react/tests/_app/src/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const componentNames = [
'link',
'skeleton',
'tooltip',
'button',
//--generator-anchor--
];

Expand Down
21 changes: 21 additions & 0 deletions packages/ods/react/tests/_app/src/components/ods-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react-dom/client';
import { OdsButton } from 'ods-components-react';

const Button = () => {
function onClick() {
console.log('React button click');
}

return (
<>
<OdsButton label="My button"
onClick={ onClick } />

<OdsButton isDisabled={ true }
label="My button"
onClick={ onClick } />
</>
);
};

export default Button;
51 changes: 51 additions & 0 deletions packages/ods/react/tests/e2e/ods-button.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { Page } from 'puppeteer';
import { goToComponentPage, setupBrowser } from '../setup';

describe('ods-button react', () => {
const setup = setupBrowser();
let page: Page;

beforeAll(async () => {
page = setup().page;
});

beforeEach(async () => {
await goToComponentPage(page, 'ods-button');
});

it('render the component correctly', async () => {
const elem = await page.$('ods-button');
const boundingBox = await elem?.boundingBox();

expect(boundingBox?.height).toBeGreaterThan(0);
expect(boundingBox?.width).toBeGreaterThan(0);
});

it('trigger the click handler on click', async () => {
const elem = await page.$('ods-button:not(:disabled)');
let consoleLog = ''
page.on('console', (consoleObj) => {
consoleLog = consoleObj.text()
});

await elem?.click();
// Small delay to ensure page console event has been resolved
await new Promise((resolve) => setTimeout(resolve, 100));

expect(consoleLog).toBe('React button click');
});

it('does not trigger the click handler on click if disabled', async () => {
const elem = await page.$('ods-button:disabled');
let consoleLog = ''
page.on('console', (consoleObj) => {
consoleLog = consoleObj.text()
});

await elem?.click();
// Small delay to ensure page console event has been resolved
await new Promise((resolve) => setTimeout(resolve, 100));

expect(consoleLog).toBe('');
});
});
2 changes: 2 additions & 0 deletions packages/ods/react/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ async function goToComponentPage(page, componentName) {
await page.waitForSelector(`#${componentName}`);
await page.click(`#${componentName}`);
await page.waitForSelector(componentName);
// Small delay to prevent random test errors on slow render
await new Promise((resolve) => setTimeout(resolve, 100));
}

function setupBrowser() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Attributes changes

`dummy` <img src="https://img.shields.io/badge/removed-FF0000" />

Has been removed.

You can use the new `better-dummy` attribute to obtain the same rendering.

## Migration examples

Dummy button:
```html
<ods-button dummy></ods-button>
<!-- is now -->
<ods-button better-dummy></ods-button>
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Content of this file will be auto-generated
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Markdown } from '@storybook/blocks';
import Specs from './spec.md';

## Description
TODO write a description

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

## Usage

### Default

<Canvas sourceState="none">
<ods-button></ods-button>
</Canvas>

```html
<ods-button></ods-button>
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:host(.ods-icon) {
<<<<<<< HEAD
/* use !important to prevent issues with browser extensions that change fonts */
line-height: 1;
font-family: "ODS Icon", serif !important;
Expand Down Expand Up @@ -608,4 +609,14 @@

:host(.ods-icon__warning-triangle)::before {
content: "\e995";
=======
display: inline-block;
-webkit-mask: center/contain no-repeat;
mask: center/contain no-repeat;
-webkit-mask-image: var(--ods-icon-mask-image, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'/%3E"));
mask-image: var(--ods-icon-mask-image, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'/%3E"));
background-color: var(--ods-color-primary-500);
width: 1rem;
height: 1rem;
>>>>>>> ca6158dbb (feat(button): implement component)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { Host, h } from "@stencil/core";
<<<<<<< HEAD
=======
import icons from "../../assets/icons.data.json"; // TODO replace with dedicated icon font when file server get available
>>>>>>> ca6158dbb (feat(button): implement component)
export class OdsIcon {
constructor() {
this.alt = '';
this.name = undefined;
}
render() {
<<<<<<< HEAD
return (h(Host, { key: 'cd390c78bf5d9156308e947e7c45b3b44b0e7686', class: `ods-icon ods-icon__${this.name}`, alt: this.alt }));
=======
const base64Icon = icons[this.name];
return (h(Host, { key: '27d5d10767805aab9a2ac37006374103428f581e', class: "ods-icon", alt: this.alt, style: (base64Icon ? { '--ods-icon-mask-image': `url("${base64Icon}")` } : {}) }));
>>>>>>> ca6158dbb (feat(button): implement component)
}
static get is() { return "ods-icon"; }
static get encapsulation() { return "shadow"; }
Expand Down Expand Up @@ -44,7 +53,11 @@ export class OdsIcon {
"mutable": false,
"complexType": {
"original": "OdsIconName",
<<<<<<< HEAD
"resolved": "\"apps\" | \"arrow-crossed\" | \"arrow-down-left\" | \"arrow-down-right\" | \"arrow-down\" | \"arrow-left-right\" | \"arrow-left\" | \"arrow-right\" | \"arrow-up-down\" | \"arrow-up-left\" | \"arrow-up-right\" | \"arrow-up\" | \"baremetal-rack\" | \"baremetal\" | \"bell\" | \"book\" | \"calendar\" | \"chat\" | \"check-circle\" | \"check-square\" | \"check\" | \"chevron-double-left\" | \"chevron-double-right\" | \"chevron-down\" | \"chevron-left\" | \"chevron-right\" | \"chevron-up\" | \"chrono\" | \"circle\" | \"clock-time-four\" | \"clock-time-nine\" | \"clock-time-six\" | \"clock-time-three\" | \"clock-time-twelve\" | \"cloud-check\" | \"cloud-download\" | \"cloud-lock\" | \"cloud-times\" | \"cloud-upload\" | \"cloud\" | \"cog\" | \"collab\" | \"component\" | \"credit-card\" | \"critical-hexagon-full\" | \"critical-hexagon\" | \"d-pad\" | \"danger-diamond-full\" | \"danger-diamond\" | \"desktop\" | \"diamond\" | \"dot-circle\" | \"download\" | \"ellipsis-horizontal\" | \"ellipsis-vertical\" | \"email\" | \"emoticon-dizzy\" | \"emoticon-neutral\" | \"emoticon-sad\" | \"emoticon-smile\" | \"emoticon-wink\" | \"emoticon\" | \"equal\" | \"error-circle\" | \"external-link\" | \"eye-off\" | \"eye\" | \"file-copy\" | \"file-minus\" | \"file-plus\" | \"file\" | \"filter\" | \"focus\" | \"folder-minus\" | \"folder-plus\" | \"folder\" | \"game-console\" | \"game-controller-alt\" | \"game-controller\" | \"gathering\" | \"globe\" | \"grid\" | \"hamburger-menu\" | \"hexagon\" | \"hierarchy\" | \"home\" | \"info-circle\" | \"key\" | \"labs-empty\" | \"labs-full\" | \"labs-half\" | \"leaf\" | \"lifebuoy\" | \"lightbulb\" | \"list\" | \"location\" | \"lock-close\" | \"lock-open\" | \"minus-square\" | \"minus\" | \"money\" | \"network\" | \"pen\" | \"phone\" | \"plus\" | \"printer\" | \"product-3az\" | \"promotion\" | \"question-circle\" | \"question\" | \"radio\" | \"refresh\" | \"resize\" | \"search\" | \"share\" | \"shield-check\" | \"shield-firewall\" | \"shield-lock\" | \"shield-minus\" | \"shield-off\" | \"shield-plus\" | \"shield-times\" | \"shield-warning\" | \"shield\" | \"shopping-cart-clear\" | \"shopping-cart-error\" | \"shopping-cart-minus\" | \"shopping-cart-plus\" | \"shopping-cart\" | \"shrink\" | \"shutdown\" | \"sort-alpha-down\" | \"sort-alpha-up\" | \"sort-numeric-down\" | \"sort-numeric-up\" | \"square\" | \"star-full\" | \"star\" | \"store\" | \"times\" | \"traffic-cone\" | \"trash\" | \"triangle\" | \"truck\" | \"undo\" | \"upload\" | \"user-circle\" | \"user\" | \"warning-triangle-full\" | \"warning-triangle\"",
=======
"resolved": "\"arrow-left\" | \"warning\"",
>>>>>>> ca6158dbb (feat(button): implement component)
"references": {
"OdsIconName": {
"location": "import",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var ODS_ICON_NAME;
(function (ODS_ICON_NAME) {
<<<<<<< HEAD
ODS_ICON_NAME["apps"] = "apps";
ODS_ICON_NAME["arrowCrossed"] = "arrow-crossed";
ODS_ICON_NAME["arrowDownLeft"] = "arrow-down-left";
Expand Down Expand Up @@ -150,6 +151,11 @@ var ODS_ICON_NAME;
ODS_ICON_NAME["user"] = "user";
ODS_ICON_NAME["warningTriangleFull"] = "warning-triangle-full";
ODS_ICON_NAME["warningTriangle"] = "warning-triangle";
=======
// TODO need actual list from design
ODS_ICON_NAME["arrowLeft"] = "arrow-left";
ODS_ICON_NAME["warning"] = "warning";
>>>>>>> ca6158dbb (feat(button): implement component)
})(ODS_ICON_NAME || (ODS_ICON_NAME = {}));
const ODS_ICON_NAMES = Object.freeze(Object.values(ODS_ICON_NAME));
export { ODS_ICON_NAME, ODS_ICON_NAMES, };
19 changes: 19 additions & 0 deletions packages/ods/src/components/button/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@ovhcloud/ods-component-button",
"version": "17.1.0",
"private": true,
"description": "ODS Button component",
"main": "dist/index.cjs.js",
"collection": "dist/collection/collection-manifest.json",
"scripts": {
"clean": "rimraf .stencil coverage dist docs-api www",
"doc": "typedoc --pretty --plugin ../../../scripts/typedoc-plugin-decorator.js && node ../../../scripts/generate-typedoc-md.js",
"lint:scss": "stylelint 'src/components/**/*.scss'",
"lint:ts": "eslint 'src/**/*.{js,ts,tsx}'",
"start": "stencil build --dev --watch --serve",
"test:e2e": "stencil test --e2e --config stencil.config.ts",
"test:e2e:ci": "tsc --noEmit && stencil test --e2e --ci --config stencil.config.ts",
"test:spec": "stencil test --spec --config stencil.config.ts --coverage",
"test:spec:ci": "tsc --noEmit && stencil test --config stencil.config.ts --spec --ci --coverage"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ export class OdsSpinner {
this.size = ODS_SPINNER_SIZE.md;
}
render() {
<<<<<<< HEAD
return (h(Host, { key: 'e7dabce700e1e689f7e19fbb7e8f0aced2b494dd', class: "ods-spinner", role: "progressbar" }, h("div", { key: 'a880dd34e9c51a4c0741ae28634eeb2dc7323484', class: {
=======
return (h(Host, { key: 'b1b6ba2ed3b5ca4abacc5e5c58079c272484457d', class: "ods-spinner", role: "progressbar" }, h("div", { key: '09f63651555964fcbb178c0a4ecf8c015fd3e9bc', class: {
>>>>>>> ca6158dbb (feat(button): implement component)
'ods-spinner__container': true,
[`ods-spinner__container--${this.color}`]: !!this.color,
[`ods-spinner__container--${this.size}`]: !!this.size,
Expand Down
Loading

0 comments on commit 22b4931

Please sign in to comment.