From 3a42b4d79bbb15e22bce648c2b664862d8810edf Mon Sep 17 00:00:00 2001 From: Ville Eriksson Date: Thu, 24 Oct 2024 13:40:57 +0300 Subject: [PATCH 1/3] fix(Attributes): Override reserved attributes correctly --- package-lock.json | 9 +- .../components/examples/c-slider/Basic.vue | 1 + .../csc-ui-documentation/layouts/Default.vue | 11 + packages/csc-ui-documentation/package.json | 3 +- .../pages/getting-started/react.vue | 292 ++++++++++++++++++ packages/csc-ui/src/components.d.ts | 36 +-- .../csc-ui/src/components/c-input/c-input.tsx | 10 +- .../csc-ui/src/components/c-input/readme.md | 57 ++-- .../src/components/c-slider/c-slider.tsx | 9 +- .../csc-ui/src/components/c-slider/readme.md | 32 +- .../components/c-text-field/c-text-field.tsx | 11 +- .../src/components/c-text-field/readme.md | 54 ++-- packages/csc-ui/vscode-data.json | 12 +- 13 files changed, 416 insertions(+), 121 deletions(-) create mode 100644 packages/csc-ui-documentation/pages/getting-started/react.vue diff --git a/package-lock.json b/package-lock.json index e0586da4..9b64cf6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4990,6 +4990,12 @@ "@sinonjs/commons": "^1.7.0" } }, + "node_modules/@stackblitz/sdk": { + "version": "1.11.0", + "resolved": "https://registry.npmjs.org/@stackblitz/sdk/-/sdk-1.11.0.tgz", + "integrity": "sha512-DFQGANNkEZRzFk1/rDP6TcFdM82ycHE+zfl9C/M/jXlH68jiqHWHFMQURLELoD8koxvu/eW5uhg94NSAZlYrUQ==", + "license": "MIT" + }, "node_modules/@stencil-community/eslint-plugin": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/@stencil-community/eslint-plugin/-/eslint-plugin-0.8.0.tgz", @@ -27555,7 +27561,7 @@ }, "packages/csc-ui": { "name": "@cscfi/csc-ui", - "version": "2.2.6", + "version": "2.2.8", "license": "MIT", "dependencies": { "@mdi/js": "^7.4.47", @@ -27602,6 +27608,7 @@ "@cscfi/csc-ui-vue": "*", "@mdi/js": "^7.4.47", "@pinia/nuxt": "^0.4.11", + "@stackblitz/sdk": "^1.11.0", "@vueuse/nuxt": "^10.7.2", "nuxt-stencil": "^0.1.1", "pinia": "^2.1.7", diff --git a/packages/csc-ui-documentation/components/examples/c-slider/Basic.vue b/packages/csc-ui-documentation/components/examples/c-slider/Basic.vue index 57733008..52dcef93 100644 --- a/packages/csc-ui-documentation/components/examples/c-slider/Basic.vue +++ b/packages/csc-ui-documentation/components/examples/c-slider/Basic.vue @@ -23,6 +23,7 @@ + + + React + + + + +

+ Usage in React +

+ +

1. Install the required dependencies

+ + + +

+ This command will install the CSC Design system component library + @cscfi/csc-ui + and the wrapper + @cscfi/csc-ui-react + which allows the components to support 2-way model binding. +

+ +

+ + 2. Add the following line to eg. + App.css + +

+ + + +

+ 3. Use in your React components +

+ + + +

+ Working example +

+ +
+ + + + + diff --git a/packages/csc-ui/src/components.d.ts b/packages/csc-ui/src/components.d.ts index ee6c3ff8..f194fda3 100644 --- a/packages/csc-ui/src/components.d.ts +++ b/packages/csc-ui/src/components.d.ts @@ -568,15 +568,11 @@ export namespace Components { /** * Auto focus the input */ - "autofocus": boolean; + "automaticFocus": boolean; /** * Disable the input */ "disabled": boolean; - /** - * Render a hidden input outside the shadow dom - */ - "form": boolean; /** * Hide the hint and error messages */ @@ -1337,7 +1333,7 @@ export namespace Components { /** * Aria label */ - "ariaLabel": string; + "ariaLabelInternal": string; /** * Disable tooltip */ @@ -1728,10 +1724,6 @@ export namespace Components { * @group Form */ interface CTextField { - /** - * HTML input autocapitalize - */ - "autocapitalize": string; /** * HTML input autocomplete */ @@ -1740,10 +1732,14 @@ export namespace Components { * HTML input autocorrect */ "autocorrect": string; + /** + * HTML input autocapitalize + */ + "automaticCapitalize": string; /** * Auto focus the input */ - "autofocus": boolean; + "automaticFocus": boolean; /** * Disable the input */ @@ -3576,15 +3572,11 @@ declare namespace LocalJSX { /** * Auto focus the input */ - "autofocus"?: boolean; + "automaticFocus"?: boolean; /** * Disable the input */ "disabled"?: boolean; - /** - * Render a hidden input outside the shadow dom - */ - "form"?: boolean; /** * Hide the hint and error messages */ @@ -4389,7 +4381,7 @@ declare namespace LocalJSX { /** * Aria label */ - "ariaLabel"?: string; + "ariaLabelInternal"?: string; /** * Disable tooltip */ @@ -4830,10 +4822,6 @@ declare namespace LocalJSX { * @group Form */ interface CTextField { - /** - * HTML input autocapitalize - */ - "autocapitalize"?: string; /** * HTML input autocomplete */ @@ -4842,10 +4830,14 @@ declare namespace LocalJSX { * HTML input autocorrect */ "autocorrect"?: string; + /** + * HTML input autocapitalize + */ + "automaticCapitalize"?: string; /** * Auto focus the input */ - "autofocus"?: boolean; + "automaticFocus"?: boolean; /** * Disable the input */ diff --git a/packages/csc-ui/src/components/c-input/c-input.tsx b/packages/csc-ui/src/components/c-input/c-input.tsx index fa269de1..74d92874 100644 --- a/packages/csc-ui/src/components/c-input/c-input.tsx +++ b/packages/csc-ui/src/components/c-input/c-input.tsx @@ -31,19 +31,13 @@ export class CInput { /** * Auto focus the input */ - // eslint-disable-next-line @stencil-community/reserved-member-names - @Prop() autofocus = false; + @Prop({ attribute: 'autofocus' }) automaticFocus = false; /** * Disable the input */ @Prop() disabled = false; - /** - * Render a hidden input outside the shadow dom - */ - @Prop() form = false; - /** * Hide the hint and error messages */ @@ -228,7 +222,7 @@ export class CInput { } componentDidLoad() { - if (this.autofocus) { + if (this.automaticFocus) { setTimeout(() => { this._onFocus(false); }, 500); diff --git a/packages/csc-ui/src/components/c-input/readme.md b/packages/csc-ui/src/components/c-input/readme.md index b27f1e7e..02aa0cd2 100644 --- a/packages/csc-ui/src/components/c-input/readme.md +++ b/packages/csc-ui/src/components/c-input/readme.md @@ -7,35 +7,34 @@ ## Properties -| Property | Attribute | Description | Type | Default | -| ---------------- | ------------------ | -------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | -| `active` | `active` | Active state | `boolean` | `false` | -| `autofocus` | `autofocus` | Auto focus the input | `boolean` | `false` | -| `disabled` | `disabled` | Disable the input | `boolean` | `false` | -| `form` | `form` | Render a hidden input outside the shadow dom | `boolean` | `false` | -| `hideDetails` | `hide-details` | Hide the hint and error messages | `boolean` | `false` | -| `hint` | `hint` | Hint text for the input | `string` | `''` | -| `hostId` | `id` | Id of the input | `string` | `undefined` | -| `inputId` | `input-id` | Id of the input element | `string` | `undefined` | -| `items` | -- | Items for the dropdown | `CSelectItem[]` | `undefined` | -| `itemsPerPage` | `items-per-page` | Items per page before adding scroll | `number` | `6` | -| `label` | `label` | Label of the input | `string` | `undefined` | -| `max` | `max` | Maximum value on a numeric input | `number` | `null` | -| `min` | `min` | Minimum value on a numeric input | `number` | `null` | -| `name` | `name` | Name of the input | `string` | `undefined` | -| `placeholder` | `placeholder` | Placeholder of the input | `string` | `undefined` | -| `readonly` | `readonly` | Mark as readonly | `boolean` | `false` | -| `required` | `required` | Set the input as required | `boolean` | `false` | -| `rows` | `rows` | Rows on the input | `number` | `1` | -| `shadow` | `shadow` | Shadow variant of the input | `boolean` | `false` | -| `step` | `step` | Step size on a numeric input | `number` | `null` | -| `type` | `type` | Type of the input | `string` | `undefined` | -| `valid` | `valid` | Set the validíty of the input | `boolean` | `true` | -| `validate` | `validate` | Manual validation | `boolean` | `false` | -| `validateOnBlur` | `validate-on-blur` | Validate the input on blur | `boolean` | `false` | -| `validation` | `validation` | Custom validation message | `string` | `'Required field'` | -| `value` | `value` | Value of the input | `CSelectItem & { ref?: HTMLElement; } \| boolean \| number \| string \| { name: string; value: string \| number; disabled?: boolean; }` | `undefined` | -| `variant` | `variant` | Variant | `"select" \| "text"` | `'text'` | +| Property | Attribute | Description | Type | Default | +| ---------------- | ------------------ | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | +| `active` | `active` | Active state | `boolean` | `false` | +| `automaticFocus` | `autofocus` | Auto focus the input | `boolean` | `false` | +| `disabled` | `disabled` | Disable the input | `boolean` | `false` | +| `hideDetails` | `hide-details` | Hide the hint and error messages | `boolean` | `false` | +| `hint` | `hint` | Hint text for the input | `string` | `''` | +| `hostId` | `id` | Id of the input | `string` | `undefined` | +| `inputId` | `input-id` | Id of the input element | `string` | `undefined` | +| `items` | -- | Items for the dropdown | `CSelectItem[]` | `undefined` | +| `itemsPerPage` | `items-per-page` | Items per page before adding scroll | `number` | `6` | +| `label` | `label` | Label of the input | `string` | `undefined` | +| `max` | `max` | Maximum value on a numeric input | `number` | `null` | +| `min` | `min` | Minimum value on a numeric input | `number` | `null` | +| `name` | `name` | Name of the input | `string` | `undefined` | +| `placeholder` | `placeholder` | Placeholder of the input | `string` | `undefined` | +| `readonly` | `readonly` | Mark as readonly | `boolean` | `false` | +| `required` | `required` | Set the input as required | `boolean` | `false` | +| `rows` | `rows` | Rows on the input | `number` | `1` | +| `shadow` | `shadow` | Shadow variant of the input | `boolean` | `false` | +| `step` | `step` | Step size on a numeric input | `number` | `null` | +| `type` | `type` | Type of the input | `string` | `undefined` | +| `valid` | `valid` | Set the validíty of the input | `boolean` | `true` | +| `validate` | `validate` | Manual validation | `boolean` | `false` | +| `validateOnBlur` | `validate-on-blur` | Validate the input on blur | `boolean` | `false` | +| `validation` | `validation` | Custom validation message | `string` | `'Required field'` | +| `value` | `value` | Value of the input | `CSelectItem & { ref?: HTMLElement; } \| boolean \| number \| string \| { name: string; value: string \| number; disabled?: boolean; }` | `undefined` | +| `variant` | `variant` | Variant | `"select" \| "text"` | `'text'` | ## Events diff --git a/packages/csc-ui/src/components/c-slider/c-slider.tsx b/packages/csc-ui/src/components/c-slider/c-slider.tsx index f3efa462..2c8809dc 100644 --- a/packages/csc-ui/src/components/c-slider/c-slider.tsx +++ b/packages/csc-ui/src/components/c-slider/c-slider.tsx @@ -31,8 +31,7 @@ export class CSlider { /** * Aria label */ - // eslint-disable-next-line @stencil-community/reserved-member-names - @Prop({ attribute: 'aria-label' }) ariaLabel: string; + @Prop({ attribute: 'aria-label' }) ariaLabelInternal: string; /** * Max value @@ -176,7 +175,9 @@ export class CSlider { return ( {!!this.label && ( - + )}
@@ -190,7 +191,7 @@ export class CSlider { (this._inputElement = el)} - aria-label={this.ariaLabel || this.label} + aria-label={this.ariaLabelInternal || this.label} aria-valuenow={this.value} aria-valuetext={`${this.value}${this.unit}`} aria-valuemin={this.min} diff --git a/packages/csc-ui/src/components/c-slider/readme.md b/packages/csc-ui/src/components/c-slider/readme.md index 375debf5..9faa6fe8 100644 --- a/packages/csc-ui/src/components/c-slider/readme.md +++ b/packages/csc-ui/src/components/c-slider/readme.md @@ -7,22 +7,22 @@ ## Properties -| Property | Attribute | Description | Type | Default | -| ---------------- | ----------------- | ------------------- | ------------------ | ----------- | -| `ariaLabel` | `aria-label` | Aria label | `string` | `undefined` | -| `disableTooltip` | `disable-tooltip` | Disable tooltip | `boolean` | `false` | -| `disabled` | `disabled` | Disable the slider | `boolean` | `false` | -| `hostId` | `id` | Id of the element | `string` | `undefined` | -| `hostName` | `name` | Id of the element | `string` | `undefined` | -| `label` | `label` | Label of the slider | `string` | `undefined` | -| `labels` | `labels` | Show tick labels | `boolean` | `false` | -| `max` | `max` | Max value | `string` | `'100'` | -| `min` | `min` | Min value | `string` | `'0'` | -| `segments` | `segments` | Segment count | `string` | `'10'` | -| `step` | `step` | Step | `string` | `'1'` | -| `ticks` | `ticks` | Thow ticks | `boolean` | `false` | -| `unit` | `unit` | Unit | `string` | `'%'` | -| `value` | `value` | Value | `number \| string` | `'50'` | +| Property | Attribute | Description | Type | Default | +| ------------------- | ----------------- | ------------------- | ------------------ | ----------- | +| `ariaLabelInternal` | `aria-label` | Aria label | `string` | `undefined` | +| `disableTooltip` | `disable-tooltip` | Disable tooltip | `boolean` | `false` | +| `disabled` | `disabled` | Disable the slider | `boolean` | `false` | +| `hostId` | `id` | Id of the element | `string` | `undefined` | +| `hostName` | `name` | Id of the element | `string` | `undefined` | +| `label` | `label` | Label of the slider | `string` | `undefined` | +| `labels` | `labels` | Show tick labels | `boolean` | `false` | +| `max` | `max` | Max value | `string` | `'100'` | +| `min` | `min` | Min value | `string` | `'0'` | +| `segments` | `segments` | Segment count | `string` | `'10'` | +| `step` | `step` | Step | `string` | `'1'` | +| `ticks` | `ticks` | Thow ticks | `boolean` | `false` | +| `unit` | `unit` | Unit | `string` | `'%'` | +| `value` | `value` | Value | `number \| string` | `'50'` | ## Events diff --git a/packages/csc-ui/src/components/c-text-field/c-text-field.tsx b/packages/csc-ui/src/components/c-text-field/c-text-field.tsx index ea11b5ba..850f0948 100644 --- a/packages/csc-ui/src/components/c-text-field/c-text-field.tsx +++ b/packages/csc-ui/src/components/c-text-field/c-text-field.tsx @@ -1,4 +1,3 @@ -/* eslint-disable @stencil-community/reserved-member-names */ import { AttachInternals, Component, @@ -30,12 +29,12 @@ export class CTextField { /** * Auto focus the input */ - @Prop() autofocus = false; + @Prop({ attribute: 'autofocus' }) automaticFocus = false; /** * HTML input autocapitalize */ - @Prop() autocapitalize = ''; + @Prop({ attribute: 'autocapitalize' }) automaticCapitalize = ''; /** * HTML input autocorrect @@ -240,7 +239,9 @@ export class CTextField { max: this.max, step: this.step, ...(!!this.autocomplete && { autocomplete: this.autocomplete }), - ...(!!this.autocapitalize && { autocapitalize: this.autocapitalize }), + ...(!!this.automaticCapitalize && { + autocapitalize: this.automaticCapitalize, + }), ...(!!this.autocorrect && { autocorrect: this.autocorrect }), }, textArea: { @@ -324,7 +325,7 @@ export class CTextField { return (