mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-15 02:11:05 +00:00
* feat(toolbar): forward "clear" event in ToolbarSearch
* docs(search): add on:clear example
* fix(ui-shell): set aria-hidden in SideNav
Ref c2b4f1f00
* chore(deps-dev): upgrade carbon-components to v10.30.0
* fix(text-input): use bx--text-input class for TextInputSkeleton
* fix(radio-button): only render span if labelText is truthy
* docs(password-input): add custom tooltip example
* feat(button): add isSelected prop for icon-only, ghost buttons
* feat(radio-button): add legendText prop to RadioButtonGroup
* docs(tag): add filterable (disabled) variant
* feat(tag): add interactive prop
* chore(number-input): deprecate the mobile variant
Mobile variant styles will no longer work.
* feat(button): set aria-pressed attribute if icon-only, ghost button is selected
* fix(multi-select): type dispatched select event
* fix(button): remove redundant "button" role
* feat(icon): deprecate Icon, IconSkeleton
* feat(ui-shell): make SideNavMenuItem text slottable
* fix(list-box): update styles for ListBoxSelection
* fix(list-box): temporarily apply override styles to ListBoxMenuIcon for chevron
* fix(tag): set disabled prop on interactive tag
* docs(button): extract selected, icon-only button example
* feat(tooltip): elevate z-index of tooltip when open
* feat: forward restProps to input element
* fix(types): fix TimePicker test to pass svelte-check
* feat: add ImageLoader component
* test: add ImageLoader
* feat: add LocalStorage component
* test(local-storage): fix invalid file
* chore(docs): use green tag type
156 lines
3.9 KiB
Svelte
156 lines
3.9 KiB
Svelte
<script>
|
|
/**
|
|
* Set the size of the input
|
|
* @type {"sm" | "xl"}
|
|
*/
|
|
export let size = undefined;
|
|
|
|
/** Specify the input type */
|
|
export let type = "text";
|
|
|
|
/** Specify the input placeholder text */
|
|
export let placeholder = "";
|
|
|
|
/** Specify the Regular Expression for the input value */
|
|
export let pattern = "\\d{1,2}\\/\\d{1,2}\\/\\d{4}";
|
|
|
|
/** Set to `true` to disable the input */
|
|
export let disabled = false;
|
|
|
|
/** Specify the ARIA label for the calendar icon */
|
|
export let iconDescription = "";
|
|
|
|
/** Set an id for the input element */
|
|
export let id = "ccs-" + Math.random().toString(36);
|
|
|
|
/** Specify the label text */
|
|
export let labelText = "";
|
|
|
|
/** Set to `true` to visually hide the label text */
|
|
export let hideLabel = false;
|
|
|
|
/** Set to `true` to indicate an invalid state */
|
|
export let invalid = false;
|
|
|
|
/** Specify the invalid state text */
|
|
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
|
|
* @type {string}
|
|
*/
|
|
export let name = undefined;
|
|
|
|
/** Obtain a reference to the input HTML element */
|
|
export let ref = null;
|
|
|
|
import { getContext, onMount } from "svelte";
|
|
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 {
|
|
range,
|
|
add,
|
|
hasCalendar,
|
|
declareRef,
|
|
updateValue,
|
|
blurInput,
|
|
openCalendar,
|
|
focusCalendar,
|
|
inputValue,
|
|
} = getContext("DatePicker");
|
|
|
|
add({ id, labelText });
|
|
|
|
onMount(() => {
|
|
declareRef({ id, ref });
|
|
});
|
|
</script>
|
|
|
|
<div
|
|
class:bx--date-picker-container="{true}"
|
|
class:bx--date-picker--nolabel="{!labelText}"
|
|
>
|
|
{#if labelText}
|
|
<label
|
|
for="{id}"
|
|
class:bx--label="{true}"
|
|
class:bx--visually-hidden="{hideLabel}"
|
|
class:bx--label--disabled="{disabled}"
|
|
>
|
|
{labelText}
|
|
</label>
|
|
{/if}
|
|
<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
|
|
bind:this="{ref}"
|
|
data-invalid="{invalid || undefined}"
|
|
id="{id}"
|
|
name="{name}"
|
|
placeholder="{placeholder}"
|
|
type="{type}"
|
|
pattern="{pattern}"
|
|
disabled="{disabled}"
|
|
{...$$restProps}
|
|
value="{!$range ? $inputValue : undefined}"
|
|
class:bx--date-picker__input="{true}"
|
|
class:bx--date-picker__input--invalid="{invalid}"
|
|
class="{size && `bx--date-picker__input--${size}`}"
|
|
on:input
|
|
on:input="{({ target }) => {
|
|
updateValue({ type: 'input', value: target.value });
|
|
}}"
|
|
on:change="{({ target }) => {
|
|
updateValue({ type: 'change', value: target.value });
|
|
}}"
|
|
on:keydown
|
|
on:keydown="{({ key }) => {
|
|
if (key === 'ArrowDown') {
|
|
focusCalendar();
|
|
}
|
|
}}"
|
|
on:blur
|
|
on:blur="{({ 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}
|
|
<Calendar16
|
|
role="img"
|
|
class="bx--date-picker__icon"
|
|
aria-label="{iconDescription}"
|
|
title="{iconDescription}"
|
|
on:click="{openCalendar}"
|
|
/>
|
|
{/if}
|
|
</div>
|
|
{#if invalid}
|
|
<div class:bx--form-requirement="{true}">{invalidText}</div>
|
|
{/if}
|
|
{#if !invalid && warn}
|
|
<div class:bx--form-requirement="{true}">{warnText}</div>
|
|
{/if}
|
|
</div>
|