feat(number-input): support warning state

This commit is contained in:
Eric Liu 2021-01-23 06:19:18 -08:00
commit bf176e642d
5 changed files with 63 additions and 4 deletions

View file

@ -2289,6 +2289,8 @@ export type NumberInputTranslationId = "increment" | "decrement";
| iconDescription | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the ARIA label for the increment icons | | iconDescription | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the ARIA label for the increment icons |
| invalid | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to indicate an invalid state | | invalid | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to indicate an invalid state |
| invalidText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the invalid state text | | invalidText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the invalid state text |
| warn | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to indicate an warning state |
| warnText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the warning state text |
| helperText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the helper text | | helperText | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the helper text |
| label | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text | | label | <code>let</code> | No | <code>string</code> | <code>""</code> | Specify the label text |
| hideLabel | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text | | hideLabel | <code>let</code> | No | <code>boolean</code> | <code>false</code> | Set to `true` to visually hide the label text |

View file

@ -6105,6 +6105,26 @@
"constant": false, "constant": false,
"reactive": false "reactive": false
}, },
{
"name": "warn",
"kind": "let",
"description": "Set to `true` to indicate an warning state",
"type": "boolean",
"value": "false",
"isFunction": false,
"constant": false,
"reactive": false
},
{
"name": "warnText",
"kind": "let",
"description": "Specify the warning state text",
"type": "string",
"value": "\"\"",
"isFunction": false,
"constant": false,
"reactive": false
},
{ {
"name": "helperText", "name": "helperText",
"kind": "let", "kind": "let",

View file

@ -41,7 +41,11 @@ components: ["NumberInput", "NumberInputSkeleton"]
### Invalid state ### Invalid state
<NumberInput invalid invalidText="An error occurred" label="Clusters" /> <NumberInput invalid invalidText="Invalid value" label="Clusters" />
### Warning state
<NumberInput warn warnText="A high number may impact initial rollout" label="Clusters" value="25" />
### Disabled state ### Disabled state

View file

@ -55,6 +55,12 @@
/** Specify the invalid state text */ /** Specify the invalid state text */
export let invalidText = ""; export let invalidText = "";
/** Set to `true` to indicate an warning state */
export let warn = false;
/** Specify the warning state text */
export let warnText = "";
/** Specify the helper text */ /** Specify the helper text */
export let helperText = ""; export let helperText = "";
@ -95,6 +101,7 @@
import CaretDownGlyph from "carbon-icons-svelte/lib/CaretDownGlyph/CaretDownGlyph.svelte"; import CaretDownGlyph from "carbon-icons-svelte/lib/CaretDownGlyph/CaretDownGlyph.svelte";
import CaretUpGlyph from "carbon-icons-svelte/lib/CaretUpGlyph/CaretUpGlyph.svelte"; import CaretUpGlyph from "carbon-icons-svelte/lib/CaretUpGlyph/CaretUpGlyph.svelte";
import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16/WarningFilled16.svelte"; import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16/WarningFilled16.svelte";
import WarningAltFilled16 from "carbon-icons-svelte/lib/WarningAltFilled16/WarningAltFilled16.svelte";
const defaultTranslations = { const defaultTranslations = {
[translationIds.increment]: "Increment number", [translationIds.increment]: "Increment number",
@ -161,7 +168,10 @@
<slot name="label">{label}</slot> <slot name="label">{label}</slot>
</label> </label>
{/if} {/if}
<div class:bx--number__input-wrapper="{true}"> <div
class:bx--number__input-wrapper="{true}"
class:bx--number__input-wrapper--warning="{!invalid && warn}"
>
<button <button
type="button" type="button"
aria-live="polite" aria-live="polite"
@ -222,7 +232,10 @@
<slot name="label">{label}</slot> <slot name="label">{label}</slot>
</label> </label>
{/if} {/if}
<div class:bx--number__input-wrapper="{true}"> <div
class:bx--number__input-wrapper="{true}"
class:bx--number__input-wrapper--warning="{!invalid && warn}"
>
<input <input
bind:this="{ref}" bind:this="{ref}"
type="number" type="number"
@ -246,6 +259,11 @@
{#if invalid} {#if invalid}
<WarningFilled16 class="bx--number__invalid" /> <WarningFilled16 class="bx--number__invalid" />
{/if} {/if}
{#if !invalid && warn}
<WarningAltFilled16
class="bx--number__invalid bx--number__invalid--warning"
/>
{/if}
<div class:bx--number__controls="{true}"> <div class:bx--number__controls="{true}">
<button <button
type="button" type="button"
@ -280,7 +298,7 @@
</div> </div>
</div> </div>
{/if} {/if}
{#if !error && helperText} {#if !error && !warn && helperText}
<div <div
class:bx--form__helper-text="{true}" class:bx--form__helper-text="{true}"
class:bx--form__helper-text--disabled="{disabled}" class:bx--form__helper-text--disabled="{disabled}"
@ -293,5 +311,8 @@
{invalidText} {invalidText}
</div> </div>
{/if} {/if}
{#if !error && warn}
<div id="{errorId}" class:bx--form-requirement="{true}">{warnText}</div>
{/if}
</div> </div>
</div> </div>

View file

@ -78,6 +78,18 @@ export interface NumberInputProps extends svelte.JSX.HTMLAttributes<HTMLElementT
*/ */
invalidText?: string; invalidText?: string;
/**
* Set to `true` to indicate an warning state
* @default false
*/
warn?: boolean;
/**
* Specify the warning state text
* @default ""
*/
warnText?: string;
/** /**
* Specify the helper text * Specify the helper text
* @default "" * @default ""