mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-18 03:26:36 +00:00
feat(date-picker): add warn state
This commit is contained in:
parent
6cb4aeb35c
commit
6f7acd224f
5 changed files with 70 additions and 2 deletions
|
@ -916,6 +916,8 @@ None.
|
||||||
| 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 |
|
||||||
| 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 |
|
||||||
| name | <code>let</code> | No | <code>string</code> | -- | Set a name for the input element |
|
| name | <code>let</code> | No | <code>string</code> | -- | Set a name for the input element |
|
||||||
|
|
||||||
### Slots
|
### Slots
|
||||||
|
|
|
@ -3636,6 +3636,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": "name",
|
"name": "name",
|
||||||
"kind": "let",
|
"kind": "let",
|
||||||
|
|
|
@ -43,6 +43,12 @@ components: ["DatePicker", "DatePickerInput", "DatePickerSkeleton"]
|
||||||
<DatePickerInput invalid invalidText="Invalid date" labelText="Date of birth" placeholder="mm/dd/yyyy" />
|
<DatePickerInput invalid invalidText="Invalid date" labelText="Date of birth" placeholder="mm/dd/yyyy" />
|
||||||
</DatePicker>
|
</DatePicker>
|
||||||
|
|
||||||
|
### Warning state
|
||||||
|
|
||||||
|
<DatePicker>
|
||||||
|
<DatePickerInput warn warnText="This info will not be stored" labelText="Date of birth" placeholder="mm/dd/yyyy" />
|
||||||
|
</DatePicker>
|
||||||
|
|
||||||
### Disabled state
|
### Disabled state
|
||||||
|
|
||||||
<DatePicker>
|
<DatePicker>
|
||||||
|
|
|
@ -35,6 +35,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 = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a name for the input element
|
* Set a name for the input element
|
||||||
* @type {string}
|
* @type {string}
|
||||||
|
@ -45,7 +51,9 @@
|
||||||
export let ref = null;
|
export let ref = null;
|
||||||
|
|
||||||
import { getContext, onMount } from "svelte";
|
import { getContext, onMount } from "svelte";
|
||||||
import Calendar16 from "carbon-icons-svelte/lib/Calendar16";
|
import Calendar16 from "carbon-icons-svelte/lib/Calendar16/Calendar16.svelte";
|
||||||
|
import WarningFilled16 from "carbon-icons-svelte/lib/WarningFilled16/WarningFilled16.svelte";
|
||||||
|
import WarningAltFilled16 from "carbon-icons-svelte/lib/WarningAltFilled16/WarningAltFilled16.svelte";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
range,
|
range,
|
||||||
|
@ -81,7 +89,11 @@
|
||||||
{labelText}
|
{labelText}
|
||||||
</label>
|
</label>
|
||||||
{/if}
|
{/if}
|
||||||
<div class:bx--date-picker-input__wrapper="{true}">
|
<div
|
||||||
|
class:bx--date-picker-input__wrapper="{true}"
|
||||||
|
class:bx--date-picker-input__wrapper--invalid="{invalid}"
|
||||||
|
class:bx--date-picker-input__wrapper--warn="{warn}"
|
||||||
|
>
|
||||||
<input
|
<input
|
||||||
bind:this="{ref}"
|
bind:this="{ref}"
|
||||||
data-invalid="{invalid || undefined}"
|
data-invalid="{invalid || undefined}"
|
||||||
|
@ -93,6 +105,7 @@
|
||||||
pattern="{pattern}"
|
pattern="{pattern}"
|
||||||
disabled="{disabled}"
|
disabled="{disabled}"
|
||||||
class:bx--date-picker__input="{true}"
|
class:bx--date-picker__input="{true}"
|
||||||
|
class:bx--date-picker__input--invalid="{invalid}"
|
||||||
class="{size && `bx--date-picker__input--${size}`}"
|
class="{size && `bx--date-picker__input--${size}`}"
|
||||||
on:input
|
on:input
|
||||||
on:input="{({ target }) => {
|
on:input="{({ target }) => {
|
||||||
|
@ -112,6 +125,18 @@
|
||||||
blurInput(relatedTarget);
|
blurInput(relatedTarget);
|
||||||
}}"
|
}}"
|
||||||
/>
|
/>
|
||||||
|
{#if !$hasCalendar}
|
||||||
|
{#if invalid}
|
||||||
|
<WarningFilled16
|
||||||
|
class="bx--date-picker__icon bx--date-picker__icon--invalid"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
{#if !invalid && warn}
|
||||||
|
<WarningAltFilled16
|
||||||
|
class="bx--date-picker__icon bx--date-picker__icon--warn"
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
{#if $hasCalendar}
|
{#if $hasCalendar}
|
||||||
<Calendar16
|
<Calendar16
|
||||||
role="img"
|
role="img"
|
||||||
|
@ -125,4 +150,7 @@
|
||||||
{#if invalid}
|
{#if invalid}
|
||||||
<div class:bx--form-requirement="{true}">{invalidText}</div>
|
<div class:bx--form-requirement="{true}">{invalidText}</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{#if !invalid && warn}
|
||||||
|
<div class:bx--form-requirement="{true}">{warnText}</div>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
12
types/DatePicker/DatePickerInput.d.ts
vendored
12
types/DatePicker/DatePickerInput.d.ts
vendored
|
@ -66,6 +66,18 @@ export interface DatePickerInputProps extends svelte.JSX.HTMLAttributes<HTMLElem
|
||||||
*/
|
*/
|
||||||
invalidText?: string;
|
invalidText?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to `true` to indicate an warning state
|
||||||
|
* @default false
|
||||||
|
*/
|
||||||
|
warn?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the warning state text
|
||||||
|
* @default ""
|
||||||
|
*/
|
||||||
|
warnText?: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a name for the input element
|
* Set a name for the input element
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue