mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
feat(text-input): add warn prop
This commit is contained in:
parent
9202a3e0e4
commit
373fbde4e1
2 changed files with 28 additions and 0 deletions
|
@ -23,6 +23,11 @@ export const Default = () => ({
|
||||||
"Content of form validation UI (invalidText)",
|
"Content of form validation UI (invalidText)",
|
||||||
"A valid value is required"
|
"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."),
|
placeholder: text("Placeholder text (placeholder)", "Placeholder text."),
|
||||||
id: text("TextInput id", "text-input-id"),
|
id: text("TextInput id", "text-input-id"),
|
||||||
name: text("TextInput name", "text-input-name"),
|
name: text("TextInput name", "text-input-name"),
|
||||||
|
|
|
@ -77,6 +77,18 @@
|
||||||
*/
|
*/
|
||||||
export let invalidText = "";
|
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
|
* Obtain a reference to the input HTML element
|
||||||
* @type {null | HTMLInputElement} [ref=null]
|
* @type {null | HTMLInputElement} [ref=null]
|
||||||
|
@ -90,8 +102,10 @@
|
||||||
export let required = false;
|
export let required = false;
|
||||||
|
|
||||||
import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16";
|
import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16";
|
||||||
|
import WarningAltFilled16 from "carbon-icons-svelte/lib/WarningAltFilled16";
|
||||||
|
|
||||||
$: errorId = `error-${id}`;
|
$: errorId = `error-${id}`;
|
||||||
|
$: warnId = `warn-${id}`;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -113,10 +127,16 @@
|
||||||
{/if}
|
{/if}
|
||||||
<div
|
<div
|
||||||
data-invalid="{invalid || undefined}"
|
data-invalid="{invalid || undefined}"
|
||||||
|
data-warn="{warn || undefined}"
|
||||||
class:bx--text-input__field-wrapper="{true}">
|
class:bx--text-input__field-wrapper="{true}">
|
||||||
{#if invalid}
|
{#if invalid}
|
||||||
<WarningFilled16 class="bx--text-input__invalid-icon" />
|
<WarningFilled16 class="bx--text-input__invalid-icon" />
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if !invalid && warn}
|
||||||
|
<WarningAltFilled16
|
||||||
|
class="bx--text-input__invalid-icon
|
||||||
|
bx--text-input__invalid-icon--warning" />
|
||||||
|
{/if}
|
||||||
<input
|
<input
|
||||||
bind:this="{ref}"
|
bind:this="{ref}"
|
||||||
data-invalid="{invalid || undefined}"
|
data-invalid="{invalid || undefined}"
|
||||||
|
@ -152,4 +172,7 @@
|
||||||
{#if invalid}
|
{#if invalid}
|
||||||
<div class:bx--form-requirement="{true}" id="{errorId}">{invalidText}</div>
|
<div class:bx--form-requirement="{true}" id="{errorId}">{invalidText}</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if !invalid && warn}
|
||||||
|
<div class:bx--form-requirement="{true}" id="{warnId}">{warnText}</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue