From cf9902fa46bf7253153c2a471f51fa05199cd639 Mon Sep 17 00:00:00 2001 From: hirsch Date: Sat, 29 Jan 2022 23:14:51 +0100 Subject: [PATCH] fix(form): improve invalid style --- packages/components/src/components.d.ts | 60 ++++++++++++++++++- .../form/bal-datepicker/bal-datepicker.tsx | 8 ++- .../bal-field-control/bal-field-control.tsx | 5 ++ .../bal-field/bal-field-control/readme.md | 1 + .../bal-field-label/bal-field-label.tsx | 5 ++ .../form/bal-field/bal-field-label/readme.md | 1 + .../bal-field-message/bal-field-message.tsx | 7 ++- .../bal-field/bal-field-message/readme.md | 7 ++- .../components/form/bal-field/bal-field.tsx | 7 ++- .../components/form/bal-input/bal-input.tsx | 6 ++ .../form/bal-select/bal-select.scss | 4 ++ .../components/form/bal-select/bal-select.tsx | 8 +++ .../form/bal-textarea/bal-textarea.tsx | 6 ++ 13 files changed, 117 insertions(+), 8 deletions(-) diff --git a/packages/components/src/components.d.ts b/packages/components/src/components.d.ts index fbf57ebac9..95af9f087a 100644 --- a/packages/components/src/components.d.ts +++ b/packages/components/src/components.d.ts @@ -330,6 +330,10 @@ export namespace Components { * Returns the native `` element used under the hood. */ "getInputElement": () => Promise; + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; /** * Set this to `true` when the component is placed on a dark background. */ @@ -424,7 +428,7 @@ export namespace Components { */ "disabled": boolean; /** - * If `true` the component gets a invalid style. Only use this if there is no live validation. + * If `true` the component gets a invalid style. */ "invalid": boolean; /** @@ -445,6 +449,10 @@ export namespace Components { * Baloise icon for the right side of the input */ "iconRight": string; + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; /** * If `true` the field can be used on blue background. */ @@ -461,6 +469,10 @@ export namespace Components { "subject": string; } interface BalFieldLabel { + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; /** * If `true` a asterix (*) is added to the label text */ @@ -471,6 +483,10 @@ export namespace Components { * Defines the color of the message. */ "color": '' | ColorTypesExtended; + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; } interface BalFileUpload { /** @@ -664,6 +680,10 @@ export namespace Components { * A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`. */ "inputmode"?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'; + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; /** * If `true` this component can be placed on dark background */ @@ -1035,6 +1055,10 @@ export namespace Components { * Enables the slide in animation for the option items. */ "hasMovement": boolean; + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; /** * Set this to `true` when the component is placed on a dark background. */ @@ -1354,6 +1378,10 @@ export namespace Components { * A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`. */ "inputmode"?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'; + /** + * If `true` the component gets a invalid style. + */ + "invalid": boolean; /** * If `true` this component can be placed on dark background */ @@ -2271,6 +2299,10 @@ declare namespace LocalJSX { * If `true` the component is diabled. */ "disabled"?: boolean; + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; /** * Set this to `true` when the component is placed on a dark background. */ @@ -2369,7 +2401,7 @@ declare namespace LocalJSX { */ "disabled"?: boolean; /** - * If `true` the component gets a invalid style. Only use this if there is no live validation. + * If `true` the component gets a invalid style. */ "invalid"?: boolean; /** @@ -2390,6 +2422,10 @@ declare namespace LocalJSX { * Baloise icon for the right side of the input */ "iconRight"?: string; + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; /** * If `true` the field can be used on blue background. */ @@ -2406,6 +2442,10 @@ declare namespace LocalJSX { "subject"?: string; } interface BalFieldLabel { + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; /** * If `true` a asterix (*) is added to the label text */ @@ -2416,6 +2456,10 @@ declare namespace LocalJSX { * Defines the color of the message. */ "color"?: '' | ColorTypesExtended; + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; } interface BalFileUpload { /** @@ -2597,6 +2641,10 @@ declare namespace LocalJSX { * A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`. */ "inputmode"?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'; + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; /** * If `true` this component can be placed on dark background */ @@ -2973,6 +3021,10 @@ declare namespace LocalJSX { * Enables the slide in animation for the option items. */ "hasMovement"?: boolean; + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; /** * Set this to `true` when the component is placed on a dark background. */ @@ -3324,6 +3376,10 @@ declare namespace LocalJSX { * A hint to the browser for which keyboard to display. Possible values: `"none"`, `"text"`, `"tel"`, `"url"`, `"email"`, `"numeric"`, `"decimal"`, and `"search"`. */ "inputmode"?: 'none' | 'text' | 'tel' | 'url' | 'email' | 'numeric' | 'decimal' | 'search'; + /** + * If `true` the component gets a invalid style. + */ + "invalid"?: boolean; /** * If `true` this component can be placed on dark background */ diff --git a/packages/components/src/components/form/bal-datepicker/bal-datepicker.tsx b/packages/components/src/components/form/bal-datepicker/bal-datepicker.tsx index 7b70e518d5..e7ab87e12a 100644 --- a/packages/components/src/components/form/bal-datepicker/bal-datepicker.tsx +++ b/packages/components/src/components/form/bal-datepicker/bal-datepicker.tsx @@ -64,6 +64,11 @@ export class Datepicker implements ComponentInterface, BalConfigObserver { */ @Prop() name: string = this.inputId + /** + * If `true` the component gets a invalid style. + */ + @Prop() invalid = false + /** * @deprecated Define the locale of month and day names. */ @@ -566,6 +571,7 @@ export class Datepicker implements ComponentInterface, BalConfigObserver { 'clickable': !this.disabled && !this.triggerIcon, 'is-inverted': this.inverted, 'is-disabled': this.disabled, + 'is-danger': this.invalid, }} ref={el => (this.inputElement = el as HTMLInputElement)} id={this.inputId} @@ -590,7 +596,7 @@ export class Datepicker implements ComponentInterface, BalConfigObserver { diff --git a/packages/components/src/components/form/bal-field/bal-field-message/readme.md b/packages/components/src/components/form/bal-field/bal-field-message/readme.md index a04990ffd1..7a9b80fd7d 100644 --- a/packages/components/src/components/form/bal-field/bal-field-message/readme.md +++ b/packages/components/src/components/form/bal-field/bal-field-message/readme.md @@ -2,9 +2,10 @@ #### Properties -| Property | Attribute | Description | Type | Default | -| -------- | --------- | --------------------------------- | ------------------------------------------------ | ------- | -| `color` | `color` | Defines the color of the message. | `"" `, ` "danger" `, ` "success" `, ` "warning"` | `''` | +| Property | Attribute | Description | Type | Default | +| --------- | --------- | --------------------------------------------- | ------------------------------------------------ | ------- | +| `color` | `color` | Defines the color of the message. | `"" `, ` "danger" `, ` "success" `, ` "warning"` | `''` | +| `invalid` | `invalid` | If `true` the component gets a invalid style. | `boolean` | `false` | \ No newline at end of file diff --git a/packages/components/src/components/form/bal-field/bal-field.tsx b/packages/components/src/components/form/bal-field/bal-field.tsx index 194bc22c98..41f574dbeb 100644 --- a/packages/components/src/components/form/bal-field/bal-field.tsx +++ b/packages/components/src/components/form/bal-field/bal-field.tsx @@ -7,7 +7,7 @@ export class Field { @Element() element!: HTMLElement /** - * If `true` the component gets a invalid style. Only use this if there is no live validation. + * If `true` the component gets a invalid style. */ @Prop() invalid = false @@ -28,12 +28,14 @@ export class Field { @Watch('inverted') @Watch('disabled') + @Watch('invalid') watchInputHandler() { this.updateChildInput() } @Watch('loading') @Watch('inverted') + @Watch('invalid') watchFieldHandler() { this.updateChildFieldControl() } @@ -50,6 +52,7 @@ export class Field { inputs.forEach(input => { input.disabled = this.disabled input.inverted = this.inverted + input.invalid = this.invalid }) } @@ -58,10 +61,12 @@ export class Field { controls.forEach(control => { control.loading = this.loading control.inverted = this.inverted + control.invalid = this.invalid const selects = this.element.querySelectorAll('bal-select') selects.forEach(select => { select.loading = this.loading + select.invalid = this.invalid }) }) } diff --git a/packages/components/src/components/form/bal-input/bal-input.tsx b/packages/components/src/components/form/bal-input/bal-input.tsx index 5d40308064..f7154766d4 100644 --- a/packages/components/src/components/form/bal-input/bal-input.tsx +++ b/packages/components/src/components/form/bal-input/bal-input.tsx @@ -40,6 +40,11 @@ export class Input implements ComponentInterface, BalConfigObserver { */ @Prop() name: string = this.inputId + /** + * If `true` the component gets a invalid style. + */ + @Prop() invalid = false + /** * Defines the type of the input (text, number, email ...). */ @@ -374,6 +379,7 @@ export class Input implements ComponentInterface, BalConfigObserver { class={{ 'input': true, 'is-disabled': this.disabled, + 'is-danger': this.invalid, 'is-inverted': this.inverted, 'clickable': this.clickable, 'has-icon-right': this.hasIconRight, diff --git a/packages/components/src/components/form/bal-select/bal-select.scss b/packages/components/src/components/form/bal-select/bal-select.scss index 2c93039300..4fd7db550f 100644 --- a/packages/components/src/components/form/bal-select/bal-select.scss +++ b/packages/components/src/components/form/bal-select/bal-select.scss @@ -22,6 +22,10 @@ bal-select { padding-bottom: 1px; margin-top: -1px; + &.is-danger { + border-color: $danger; + } + &:focus-within, &.is-focused { border-width: 2px; diff --git a/packages/components/src/components/form/bal-select/bal-select.tsx b/packages/components/src/components/form/bal-select/bal-select.tsx index 0c94bcf743..50dedc9d98 100644 --- a/packages/components/src/components/form/bal-select/bal-select.tsx +++ b/packages/components/src/components/form/bal-select/bal-select.tsx @@ -59,6 +59,11 @@ export class Select { */ @Prop() name: string = this.inputId + /** + * If `true` the component gets a invalid style. + */ + @Prop() invalid = false + /** * The tabindex of the control. */ @@ -706,6 +711,7 @@ export class Select { bal-popover-trigger class={{ 'bal-select__slot': true, + 'is-danger': this.invalid, 'is-focused': this.isPopoverOpen, 'has-no-border': this.noBorder, }} @@ -721,6 +727,7 @@ export class Select { class={{ 'input': true, 'is-inverted': this.inverted, + 'is-danger': this.invalid, 'is-clickable': !this.isPopoverOpen, 'data-test-select-input': true, }} @@ -742,6 +749,7 @@ export class Select { class={{ 'is-hidden': this.loading }} name="caret-down" size="xsmall" + color={this.invalid ? 'danger' : 'info'} inverted={this.inverted} turn={this.isPopoverOpen} style={{ diff --git a/packages/components/src/components/form/bal-textarea/bal-textarea.tsx b/packages/components/src/components/form/bal-textarea/bal-textarea.tsx index a579205240..a830c3f2de 100644 --- a/packages/components/src/components/form/bal-textarea/bal-textarea.tsx +++ b/packages/components/src/components/form/bal-textarea/bal-textarea.tsx @@ -30,6 +30,11 @@ export class Textarea implements ComponentInterface { */ @Prop() name: string = this.inputId + /** + * If `true` the component gets a invalid style. + */ + @Prop() invalid = false + /** * Indicates whether and how the text value should be automatically capitalized as it is entered/edited by the user. */ @@ -252,6 +257,7 @@ export class Textarea implements ComponentInterface { 'textarea': true, 'is-inverted': this.inverted, 'is-disabled': this.disabled, + 'is-danger': this.invalid, 'clickable': this.clickable, }} ref={inputEl => (this.nativeInput = inputEl)}