@skeletonlabs/skeleton 2.7.1-dev.c283b123 → 2.8.0-dev.3a27212f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Autocomplete/Autocomplete.svelte +1 -1
- package/dist/components/InputChip/InputChip.svelte +54 -31
- package/dist/components/InputChip/InputChip.svelte.d.ts +14 -0
- package/dist/components/ListBox/ListBox.svelte +2 -0
- package/dist/components/ListBox/ListBox.svelte.d.ts +2 -0
- package/dist/components/ListBox/ListBoxItem.svelte +8 -4
- package/dist/components/ListBox/ListBoxItem.svelte.d.ts +1 -0
- package/package.json +1 -1
|
@@ -62,48 +62,73 @@ onMount(() => {
|
|
|
62
62
|
function onInputHandler() {
|
|
63
63
|
inputValid = true;
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
function validateCustom(chip) {
|
|
66
|
+
return validation === void 0 || validation(chip);
|
|
67
|
+
}
|
|
68
|
+
function validateCount() {
|
|
69
|
+
return max === -1 || value.length < max;
|
|
70
|
+
}
|
|
71
|
+
function validateLength(chip) {
|
|
72
|
+
return (minlength === -1 || chip.length >= minlength) && (maxlength === -1 || chip.length <= maxlength);
|
|
73
|
+
}
|
|
74
|
+
function validateWhiteList(chip) {
|
|
75
|
+
return whitelist.length === 0 || whitelist.includes(chip);
|
|
76
|
+
}
|
|
77
|
+
function validateDuplicates(chip) {
|
|
78
|
+
return allowDuplicates || !value.includes(chip);
|
|
79
|
+
}
|
|
80
|
+
function validate(chip = "") {
|
|
81
|
+
if (!chip && !input)
|
|
80
82
|
return false;
|
|
81
|
-
|
|
83
|
+
chip = chip !== "" ? chip.trim() : input.trim();
|
|
84
|
+
return validateCustom(chip) && validateCount() && validateLength(chip) && validateWhiteList(chip) && validateDuplicates(chip);
|
|
85
|
+
}
|
|
86
|
+
function addChipCommon(chip) {
|
|
87
|
+
chip = allowUpperCase ? chip : chip.toLowerCase();
|
|
88
|
+
value.push(chip);
|
|
89
|
+
value = value;
|
|
90
|
+
chipValues.push({ val: chip, id: Math.random() });
|
|
91
|
+
chipValues = chipValues;
|
|
92
|
+
}
|
|
93
|
+
function removeChipCommon(chip) {
|
|
94
|
+
let chipIndex = value.indexOf(chip);
|
|
95
|
+
value.splice(chipIndex, 1);
|
|
96
|
+
value = value;
|
|
97
|
+
chipValues.splice(chipIndex, 1);
|
|
98
|
+
chipValues = chipValues;
|
|
82
99
|
}
|
|
83
|
-
function
|
|
100
|
+
function addChipInternally(event) {
|
|
84
101
|
event.preventDefault();
|
|
85
102
|
inputValid = validate();
|
|
86
103
|
if (inputValid === false) {
|
|
87
104
|
dispatch("invalid", { event, input });
|
|
88
105
|
return;
|
|
89
106
|
}
|
|
90
|
-
input
|
|
91
|
-
value.push(input);
|
|
92
|
-
value = value;
|
|
93
|
-
chipValues.push({ val: input, id: Math.random() });
|
|
94
|
-
chipValues = chipValues;
|
|
107
|
+
addChipCommon(input);
|
|
95
108
|
dispatch("add", { event, chipIndex: value.length - 1, chipValue: input });
|
|
96
109
|
input = "";
|
|
97
110
|
}
|
|
98
|
-
function
|
|
111
|
+
function removeChipInternally(event, chipIndex, chipValue) {
|
|
99
112
|
if ($$restProps.disabled)
|
|
100
113
|
return;
|
|
101
|
-
|
|
102
|
-
value = value;
|
|
103
|
-
chipValues.splice(chipIndex, 1);
|
|
104
|
-
chipValues = chipValues;
|
|
114
|
+
removeChipCommon(chipValue);
|
|
105
115
|
dispatch("remove", { event, chipIndex, chipValue });
|
|
106
116
|
}
|
|
117
|
+
export function addChip(chip) {
|
|
118
|
+
inputValid = validate(chip);
|
|
119
|
+
if (inputValid === false) {
|
|
120
|
+
dispatch("invalidManually", { input: chip });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
addChipCommon(chip);
|
|
124
|
+
dispatch("addManually", { chipIndex: value.length - 1, chipValue: chip });
|
|
125
|
+
}
|
|
126
|
+
export function removeChip(chip) {
|
|
127
|
+
if ($$restProps.disabled)
|
|
128
|
+
return;
|
|
129
|
+
removeChipCommon(chip);
|
|
130
|
+
dispatch("removeManually", { chipValue: chip });
|
|
131
|
+
}
|
|
107
132
|
$:
|
|
108
133
|
classesInvalid = inputValid === false ? invalid : "";
|
|
109
134
|
$:
|
|
@@ -133,7 +158,7 @@ $:
|
|
|
133
158
|
<!-- Chip Wrapper -->
|
|
134
159
|
<div class="input-chip-wrapper {classesChipWrapper}">
|
|
135
160
|
<!-- Input Field -->
|
|
136
|
-
<form on:submit={
|
|
161
|
+
<form on:submit={addChipInternally}>
|
|
137
162
|
<input
|
|
138
163
|
type="text"
|
|
139
164
|
bind:value={input}
|
|
@@ -159,9 +184,7 @@ $:
|
|
|
159
184
|
<button
|
|
160
185
|
type="button"
|
|
161
186
|
class="chip {chips}"
|
|
162
|
-
on:click={(e) =>
|
|
163
|
-
removeChip(e, i, val);
|
|
164
|
-
}}
|
|
187
|
+
on:click={(e) => removeChipInternally(e, i, val)}
|
|
165
188
|
on:click
|
|
166
189
|
on:keypress
|
|
167
190
|
on:keydown
|
|
@@ -64,6 +64,8 @@ declare class __sveltets_Render<ListTransitionIn extends Transition = FlyTransit
|
|
|
64
64
|
chipTransitionOut?: ChipTransitionOut | undefined;
|
|
65
65
|
/** Transition params provided to `ChipTransitionOut`.*/
|
|
66
66
|
chipTransitionOutParams?: TransitionParams<ChipTransitionOut> | undefined;
|
|
67
|
+
addChip?: ((chip: string) => void) | undefined;
|
|
68
|
+
removeChip?: ((chip: string) => void) | undefined;
|
|
67
69
|
};
|
|
68
70
|
events(): {
|
|
69
71
|
input: Event;
|
|
@@ -83,10 +85,20 @@ declare class __sveltets_Render<ListTransitionIn extends Transition = FlyTransit
|
|
|
83
85
|
chipIndex: number;
|
|
84
86
|
chipValue: string;
|
|
85
87
|
}>;
|
|
88
|
+
addManually: CustomEvent<{
|
|
89
|
+
chipIndex: number;
|
|
90
|
+
chipValue: string;
|
|
91
|
+
}>;
|
|
92
|
+
removeManually: CustomEvent<{
|
|
93
|
+
chipValue: string;
|
|
94
|
+
}>;
|
|
86
95
|
invalid: CustomEvent<{
|
|
87
96
|
event: SubmitEvent;
|
|
88
97
|
input: string;
|
|
89
98
|
}>;
|
|
99
|
+
invalidManually: CustomEvent<{
|
|
100
|
+
input: string;
|
|
101
|
+
}>;
|
|
90
102
|
} & {
|
|
91
103
|
[evt: string]: CustomEvent<any>;
|
|
92
104
|
};
|
|
@@ -96,5 +108,7 @@ export type InputChipProps<ListTransitionIn extends Transition = FlyTransition,
|
|
|
96
108
|
export type InputChipEvents<ListTransitionIn extends Transition = FlyTransition, ListTransitionOut extends Transition = FlyTransition, ChipTransitionIn extends Transition = ScaleTransition, ChipTransitionOut extends Transition = ScaleTransition> = ReturnType<__sveltets_Render<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>['events']>;
|
|
97
109
|
export type InputChipSlots<ListTransitionIn extends Transition = FlyTransition, ListTransitionOut extends Transition = FlyTransition, ChipTransitionIn extends Transition = ScaleTransition, ChipTransitionOut extends Transition = ScaleTransition> = ReturnType<__sveltets_Render<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>['slots']>;
|
|
98
110
|
export default class InputChip<ListTransitionIn extends Transition = FlyTransition, ListTransitionOut extends Transition = FlyTransition, ChipTransitionIn extends Transition = ScaleTransition, ChipTransitionOut extends Transition = ScaleTransition> extends SvelteComponentTyped<InputChipProps<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>, InputChipEvents<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>, InputChipSlots<ListTransitionIn, ListTransitionOut, ChipTransitionIn, ChipTransitionOut>> {
|
|
111
|
+
get addChip(): (chip: string) => void;
|
|
112
|
+
get removeChip(): (chip: string) => void;
|
|
99
113
|
}
|
|
100
114
|
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script>import { setContext } from "svelte";
|
|
2
2
|
export let multiple = false;
|
|
3
|
+
export let disabled = false;
|
|
3
4
|
export let spacing = "space-y-1";
|
|
4
5
|
export let rounded = "rounded-token";
|
|
5
6
|
export let active = "variant-filled";
|
|
@@ -9,6 +10,7 @@ export let regionLead = "";
|
|
|
9
10
|
export let regionDefault = "";
|
|
10
11
|
export let regionTrail = "";
|
|
11
12
|
export let labelledby = "";
|
|
13
|
+
setContext("disabled", disabled);
|
|
12
14
|
setContext("multiple", multiple);
|
|
13
15
|
setContext("rounded", rounded);
|
|
14
16
|
setContext("active", active);
|
|
@@ -4,6 +4,8 @@ declare const __propDef: {
|
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
/** Enable selection of multiple items.*/
|
|
6
6
|
multiple?: boolean | undefined;
|
|
7
|
+
/** Disables selection of items.*/
|
|
8
|
+
disabled?: boolean | undefined;
|
|
7
9
|
/** Provide class to set the vertical spacing style.*/
|
|
8
10
|
spacing?: string | undefined;
|
|
9
11
|
/** Provide classes to set the listbox box radius styles.*/
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export let group;
|
|
3
3
|
export let name;
|
|
4
4
|
export let value;
|
|
5
|
+
export let disabled = getContext("disabled");
|
|
5
6
|
export let multiple = getContext("multiple");
|
|
6
7
|
export let rounded = getContext("rounded");
|
|
7
8
|
export let active = getContext("active");
|
|
@@ -11,6 +12,7 @@ export let regionLead = getContext("regionLead");
|
|
|
11
12
|
export let regionDefault = getContext("regionDefault");
|
|
12
13
|
export let regionTrail = getContext("regionTrail");
|
|
13
14
|
const cBase = "cursor-pointer -outline-offset-[3px]";
|
|
15
|
+
const cDisabled = "opacity-50 !cursor-default";
|
|
14
16
|
const cLabel = "flex items-center space-x-4";
|
|
15
17
|
let checked;
|
|
16
18
|
let elemInput;
|
|
@@ -66,9 +68,11 @@ const cRegionTrail = "";
|
|
|
66
68
|
$:
|
|
67
69
|
selected = multiple ? group.some((groupVal) => areDeeplyEqual(value, groupVal)) : areDeeplyEqual(group, value);
|
|
68
70
|
$:
|
|
69
|
-
classesActive = selected ? active : hover;
|
|
71
|
+
classesActive = selected ? active : !disabled ? hover : "";
|
|
70
72
|
$:
|
|
71
|
-
|
|
73
|
+
classesDisabled = disabled ? cDisabled : "";
|
|
74
|
+
$:
|
|
75
|
+
classesBase = `${cBase} ${classesDisabled} ${rounded} ${padding} ${classesActive} ${$$props.class ?? ""}`;
|
|
72
76
|
$:
|
|
73
77
|
classesLabel = `${cLabel}`;
|
|
74
78
|
$:
|
|
@@ -95,9 +99,9 @@ $:
|
|
|
95
99
|
<!-- NOTE: Don't use `hidden` as it prevents `required` from operating -->
|
|
96
100
|
<div class="h-0 w-0 overflow-hidden">
|
|
97
101
|
{#if multiple}
|
|
98
|
-
<input bind:this={elemInput} type="checkbox" {name} {value} bind:checked tabindex="-1" on:click on:change />
|
|
102
|
+
<input {disabled} bind:this={elemInput} type="checkbox" {name} {value} bind:checked tabindex="-1" on:click on:change />
|
|
99
103
|
{:else}
|
|
100
|
-
<input bind:this={elemInput} type="radio" bind:group {name} {value} tabindex="-1" on:click on:change />
|
|
104
|
+
<input {disabled} bind:this={elemInput} type="radio" bind:group {name} {value} tabindex="-1" on:click on:change />
|
|
101
105
|
{/if}
|
|
102
106
|
</div>
|
|
103
107
|
<!-- <slot /> -->
|