Skip to content

Commit

Permalink
feat(arch): move && simplify component input
Browse files Browse the repository at this point in the history
  • Loading branch information
dpellier committed Aug 8, 2023
1 parent b64338e commit aaea32b
Show file tree
Hide file tree
Showing 144 changed files with 901 additions and 1,040 deletions.
5 changes: 5 additions & 0 deletions packages-new/common/core/src/form/ods-input-value.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OdsInputValue = string | number | null;

export type {
OdsInputValue,
};
1 change: 1 addition & 0 deletions packages-new/common/core/src/form/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './control/public-api';
export * from './error/public-api';
export * from './ods-input-value';
export * from './validation/public-api';
File renamed without changes.
File renamed without changes.
File renamed without changes.
221 changes: 221 additions & 0 deletions packages-new/components/input/documentation/specifications/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
* [**Interfaces**](#interfaces)
* [**Types**](#types)
* [**Classes**](#classes)
* [**Type alias**](#type-alias)
* [**Variables**](#variables)

## Interfaces

### OdsInputAttributes
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`ariaLabel`** | `null` \| `string` | ✴️ | | |
|**`ariaLabelledby`** | _string_ | | | ID of the element that labels the input|
|**`clearable`** | _boolean_ | | | Ability to clear the input value|
|**`color`** | `OdsThemeColorIntent` | | | Main color of the input: see component principles|
|**`contrasted`** | _boolean_ | | | Indicates if the input is contrasted or not: see component principles|
|**`defaultValue`** | `OdsInputValue` | ✴️ | | Default value of the input|
|**`disabled`** | _boolean_ | | | Indicates if the input is disabled or not: see component principles|
|**`error`** | _boolean_ | | | Indicates if the input shows error or not|
|**`errorStateControl`** | `OdsErrorStateControl` | | | Controls the error state of the input|
|**`flex`** | _boolean_ | | | Indicates if the input is full width or not: see component principles|
|**`forbiddenValues`** | `OdsFormForbiddenValues` | ✴️ | | List of forbidden values for the input|
|**`formControl`** | `OdsFormControl` | | | Control object of the form the input belongs to|
|**`icon`** | `ODS_ICON_NAME` | | | Icon to be used in the input field|
|**`label`** | _string_ | | | Label of the input field|
|**`loading`** | _boolean_ | | | Indicates if the input is in loading state or not|
|**`masked`** | _boolean_ | | | Indicates if the input is masked or not|
|**`max`** | _number_ | | | Maximum value for the input (type number)|
|**`min`** | _number_ | | | Minimum value for the input (type number)|
|**`name`** | _string_ | | | Name of the input field|
|**`placeholder`** | _string_ | | | Placeholder text for the input|
|**`readOnly`** | _boolean_ | | | Indicates if the input is read-only or not|
|**`required`** | _boolean_ | | | Indicates if the input is required or not|
|**`size`** | `md` | | | Size of the input: see component principles|
|**`step`** | _number_ | | | Step value for the input|
|**`type`** | `OdsInputType` | ✴️ | | Type of the input field|
|**`value`** | `OdsInputValue` | ✴️ | | Current value of the input|

### OdsInputBehavior
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`hasFocus`** | _boolean_ | ✴️ | | |
|**`inputEl`** | `HTMLInputElement` | | | reference to the input element.|
|**`inputTabindex`** | _number_ | ✴️ | | |
|**`beforeInit`** | _void_ | ✴️ | | before init component function.should be called before component init.should register form controlshould emit valueshould set value with default if undefined|
|**`emitBlur`** | _void_ | ✴️ | | when a blur is triggered, this method emit the event|
|**`emitChange`** | _void_ | ✴️ | | when a input change is triggered, this method emit the event|
|**`emitFocus`** | _void_ | ✴️ | | when a focus is triggered, this method emit the event|
|**`onBlur`** | _void_ | ✴️ | | |
|**`onChange`** | _void_ | ✴️ | | process the change of the component.|
|**`onFocus`** | _void_ | ✴️ | | |
|**`onInput`** | _void_ | ✴️ | | process the input of the component.this method has to call OdsInputController.onInput|

### OdsInputEvents
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`odsInputBlur`** | _void_ | ✴️ | | |
|**`odsInputFocus`** | _void_ | ✴️ | | Event triggered on input blur|
|**`odsValueChange`** | `OdsInputValueChangeEventDetail` | ✴️ | | the input value changed|

### OdsInputMethods
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`clear`** | _void_ | ✴️ | | empty the value|
|**`getValidity`** | `OdsInputValidityState` | ✴️ | | get the validity state|
|**`hide`** | _void_ | ✴️ | | hide or display the value|
|**`reset`** | _void_ | ✴️ | | restore the value to the initial state|
|**`setFocus`** | _void_ | ✴️ | | active the focus on the input in order to let the user write something|
|**`setInputTabindex`** | _void_ | ✴️ | | set a custom tab index for easier navigation|
|**`stepDown`** | _void_ | ✴️ | | |
|**`stepUp`** | _void_ | ✴️ | | |

### OdsInputValidityState
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`badInput`** | _boolean_ | | | |
|**`customError`** | _boolean_ | ✴️ | | |
|**`forbiddenValue`** | _boolean_ | ✴️ | | is the value is forbidden|
|**`invalid`** | _boolean_ | ✴️ | | |
|**`patternMismatch`** | _boolean_ | | | |
|**`rangeOverflow`** | _boolean_ | | | |
|**`rangeUnderflow`** | _boolean_ | | | |
|**`stepMismatch`** | _boolean_ | ✴️ | | |
|**`tooLong`** | _boolean_ | | | |
|**`tooShort`** | _boolean_ | | | |
|**`typeMismatch`** | _boolean_ | | | |
|**`valid`** | _boolean_ | ✴️ | | |
|**`valueMissing`** | _boolean_ | ✴️ | | |

### OdsInputValueChangeEventDetail
|name | Type | Required | Default | Description|
|---|---|:---:|---|---|
|**`oldValue`** | `null` \| `string` | | | |
|**`validity`** | `OdsValidityState` | ✴️ | | |
|**`value`** | `undefined` \| `null` \| `string` | ✴️ | | |

## Types

### OdsInputSize
| |
|:---:|
| `md` |

### OdsInputType
| |
|:---:|
| `date` |
| `email` |
| `number` |
| `password` |
| `search` |
| `tel` |
| `text` |
| `time` |
| `url` |

## Classes

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

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

> **beforeInit**() => _unknown_

> **clear**() => _unknown_

> **getInputValidity**() => _unknown_

> **hasError**() => _unknown_

> **hide**() => _unknown_

> **onBlur**() => _unknown_

> **onChange**() => _unknown_

> **onDefaultValueChange**() => _unknown_

> **onFocus**() => _unknown_

> **onFormControlChange**() => _unknown_

> **onInput**() => _unknown_

> **onValueChange**() => _unknown_

> **reset**() => _unknown_

> **setInputTabindex**() => _unknown_

> **stepDown**() => _unknown_

> **stepUp**() => _unknown_


## Type alias

### HTMLOdsInputElement

### OdsInput

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

> - `OdsComponentGenericMethods`
> - `OdsComponentGenericEvents`
### OdsInputValue

> - _string_
> - _number_
> - _null_
### OdsInputValueChangeEvent

> - `OdsInputValueChangeEventDetail`
### OdsInputAttributes

> _Based on `OdsComponentAttributes`_
### OdsInputEvents

> _Based on `OdsComponentEvents`_
### OdsInputMethods

> _Based on `OdsFormControlMethods`_
### OdsInputValidityState

> _Based on `OdsValidityState`_
## Variables

### odsInputDefaultAttributes
`OdsInputAttributes`
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Description} from '@storybook/addon-docs';
import Specs from '@ovhcloud/ods-core/src/components/input/docs/spec.md';
import SpecsInputTests from '@ovhcloud/ods-specifications/components/input/specifications-input-tests.mdx';
import Specs from './spec.md';
import SpecsInputTests from './specifications-input-tests.mdx';

## Description
The input is the main item used in forms.
Expand Down
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,15 +1,14 @@
{
"name": "@ovhcloud/ods-stencil-input",
"name": "@ovhcloud/ods-component-input",
"version": "15.0.1",
"private": true,
"description": "Custom input HTML component",
"description": "ODS Input component",
"author": "OVH SAS",
"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 @@ -35,11 +34,14 @@
"test:e2e:ci:screenshot:update": "stencil test --config stencil.config.ts --e2e --ci --screenshot --update-screenshot --passWithNoTests"
},
"dependencies": {
"@ovhcloud/ods-common-core": "^15.0.1",
"@ovhcloud/ods-common-stencil": "^15.0.1",
"@ovhcloud/ods-component-icon": "^15.0.1",
"@ovhcloud/ods-component-spinner": "^15.0.1",
"@ovhcloud/ods-stencil-component": "^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-input-react",
"name": "@ovhcloud/ods-component-input-react",
"version": "15.0.1",
"private": true,
"description": "React specific wrapper for ods",
Expand All @@ -20,19 +20,13 @@
"dist/"
],
"dependencies": {
"@ovhcloud/ods-stencil-cart": "^15.0.1",
"tslib": "*"
"@ovhcloud/ods-component-input": "^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
@@ -1,9 +1,9 @@
import { OdsInputAttributes } from './ods-input-attributes';
import type { OdsInputAttribute } from '../interfaces/attributes';
import { OdsThemeColorIntent } from '@ovhcloud/ods-theming';
import { OdsInputSize } from './ods-input-size';
import { OdsInputType } from './ods-input-type';
import { ODS_INPUT_SIZE } from './input-size';
import { ODS_INPUT_TYPE } from './input-type';

export const odsInputDefaultAttributesDoc = {
const DEFAULT_ATTRIBUTE: OdsInputAttribute = Object.freeze({
ariaLabel: null,
ariaLabelledby: undefined,
clearable: false,
Expand All @@ -12,9 +12,9 @@ export const odsInputDefaultAttributesDoc = {
defaultValue: '',
disabled: false,
error: false,
flex: false,
forbiddenValues: [],
icon: undefined,
inline: false,
label: undefined,
loading: false,
masked: true,
Expand All @@ -24,10 +24,12 @@ export const odsInputDefaultAttributesDoc = {
placeholder: undefined,
readOnly: false,
required: false,
size: OdsInputSize.md,
size: ODS_INPUT_SIZE.md,
step: undefined,
type: OdsInputType.number,
type: ODS_INPUT_TYPE.number,
value: '',
} as const;
});

export const odsInputDefaultAttributes = odsInputDefaultAttributesDoc as unknown as OdsInputAttributes;
export {
DEFAULT_ATTRIBUTE,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum ODS_INPUT_SIZE {
md = 'md'
}

const ODS_INPUT_SIZES = Object.freeze(Object.values(ODS_INPUT_SIZE));

export {
ODS_INPUT_SIZE,
ODS_INPUT_SIZES,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
enum ODS_INPUT_TYPE {
date = 'date',
email = 'email',
number = 'number',
password = 'password',
search = 'search',
tel = 'tel',
text = 'text',
time = 'time',
url = 'url',
}

const ODS_INPUT_TYPES = Object.freeze(Object.values(ODS_INPUT_TYPE));

export {
ODS_INPUT_TYPE,
ODS_INPUT_TYPES,
};
Loading

0 comments on commit aaea32b

Please sign in to comment.