diff --git a/src/TextInput/TextInput.stories.js b/src/TextInput/TextInput.stories.js index c57e47a3..306b497c 100644 --- a/src/TextInput/TextInput.stories.js +++ b/src/TextInput/TextInput.stories.js @@ -23,6 +23,11 @@ export const Default = () => ({ "Content of form validation UI (invalidText)", "A valid value is required" ), + warn: boolean('Show warning state (warn)', false), + warnText: text( + 'Warning state text (warnText)', + 'This will overwrite your current settings' + ), placeholder: text("Placeholder text (placeholder)", "Placeholder text."), id: text("TextInput id", "text-input-id"), name: text("TextInput name", "text-input-name"), diff --git a/src/TextInput/TextInput.svelte b/src/TextInput/TextInput.svelte index 9fa4d76b..11c89a39 100644 --- a/src/TextInput/TextInput.svelte +++ b/src/TextInput/TextInput.svelte @@ -77,6 +77,18 @@ */ export let invalidText = ""; + /** + * Set to `true` to indicate an warning state + * @type {boolean} [warn=false] + */ + export let warn = false; + + /** + * Specify the warning state text + * @type {string} [invalidText=""] + */ + export let warnText = ""; + /** * Obtain a reference to the input HTML element * @type {null | HTMLInputElement} [ref=null] @@ -90,8 +102,10 @@ export let required = false; import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16"; + import WarningAltFilled16 from "carbon-icons-svelte/lib/WarningAltFilled16"; $: errorId = `error-${id}`; + $: warnId = `warn-${id}`;
{#if invalid} {/if} + {#if !invalid && warn} + + {/if} {invalidText}
{/if} + {#if !invalid && warn} +
{warnText}
+ {/if}