svelte-select-5 6.0.0
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/.claude/settings.local.json +20 -0
- package/.prettierignore +2 -0
- package/.prettierrc +17 -0
- package/CHANGELOG.md +571 -0
- package/LICENSE +9 -0
- package/MIGRATION_GUIDE.md +98 -0
- package/README.md +316 -0
- package/docs/generate_theming_variables_md.cjs +53 -0
- package/docs/theming_variables.md +113 -0
- package/jsconfig.json +3 -0
- package/package.json +77 -0
- package/rollup.config.js +33 -0
- package/src/app.html +29 -0
- package/src/global.d.ts +1 -0
- package/src/lib/ChevronIcon.svelte +22 -0
- package/src/lib/ClearIcon.svelte +22 -0
- package/src/lib/LoadingIcon.svelte +33 -0
- package/src/lib/Select.svelte +1345 -0
- package/src/lib/filter.js +38 -0
- package/src/lib/get-items.js +25 -0
- package/src/lib/index.js +1 -0
- package/src/lib/tailwind.css +130 -0
- package/src/post-prepare.cjs +6 -0
- package/src/remove-styles.cjs +22 -0
- package/src/routes/+layout.js +1 -0
- package/src/routes/+layout.svelte +263 -0
- package/src/routes/+page.js +5 -0
- package/src/routes/+page.svelte +0 -0
- package/src/routes/examples/+page.svelte +84 -0
- package/src/routes/examples/advanced/create-item/+page.svelte +36 -0
- package/src/routes/examples/advanced/create-item-multiple/+page.svelte +38 -0
- package/src/routes/examples/advanced/floating-ui/+page.svelte +22 -0
- package/src/routes/examples/advanced/form-action/+page.server.js +10 -0
- package/src/routes/examples/advanced/form-action/+page.svelte +20 -0
- package/src/routes/examples/advanced/limit-multi-value/+page.svelte +31 -0
- package/src/routes/examples/advanced/long-item/+page.svelte +38 -0
- package/src/routes/examples/advanced/multi-item-checkboxes/+page.svelte +49 -0
- package/src/routes/examples/advanced/style-props/+page.svelte +14 -0
- package/src/routes/examples/advanced/virtual-list/+page.svelte +95 -0
- package/src/routes/examples/events/blur/+page.svelte +19 -0
- package/src/routes/examples/events/change/+page.svelte +16 -0
- package/src/routes/examples/events/clear/+page.svelte +18 -0
- package/src/routes/examples/events/error/+page.svelte +17 -0
- package/src/routes/examples/events/filter/+page.svelte +16 -0
- package/src/routes/examples/events/focus/+page.svelte +16 -0
- package/src/routes/examples/events/hoverItem/+page.svelte +16 -0
- package/src/routes/examples/events/input/+page.svelte +16 -0
- package/src/routes/examples/events/loaded/+page.svelte +23 -0
- package/src/routes/examples/props/class/+page.svelte +17 -0
- package/src/routes/examples/props/clearFilterTextOnBlur/+page.svelte +13 -0
- package/src/routes/examples/props/clearable/+page.svelte +13 -0
- package/src/routes/examples/props/closeListOnChange/+page.svelte +12 -0
- package/src/routes/examples/props/container-styles/+page.svelte +11 -0
- package/src/routes/examples/props/debounce-wait/+page.svelte +19 -0
- package/src/routes/examples/props/disabled/+page.svelte +15 -0
- package/src/routes/examples/props/filter-text/+page.svelte +14 -0
- package/src/routes/examples/props/floating-config/+page.svelte +42 -0
- package/src/routes/examples/props/focused/+page.svelte +16 -0
- package/src/routes/examples/props/group-header-selectable/+page.svelte +18 -0
- package/src/routes/examples/props/hide-empty-state/+page.svelte +8 -0
- package/src/routes/examples/props/id/+page.svelte +15 -0
- package/src/routes/examples/props/input-attributes/+page.svelte +11 -0
- package/src/routes/examples/props/item-id/+page.svelte +15 -0
- package/src/routes/examples/props/items/+page.svelte +15 -0
- package/src/routes/examples/props/just-value/+page.svelte +16 -0
- package/src/routes/examples/props/label/+page.svelte +15 -0
- package/src/routes/examples/props/list-auto-width/+page.svelte +21 -0
- package/src/routes/examples/props/list-offset/+page.svelte +21 -0
- package/src/routes/examples/props/list-open/+page.svelte +31 -0
- package/src/routes/examples/props/loadOptions/+page.svelte +16 -0
- package/src/routes/examples/props/loading/+page.svelte +15 -0
- package/src/routes/examples/props/multiFullItemClearable/+page.svelte +12 -0
- package/src/routes/examples/props/multiple/+page.svelte +12 -0
- package/src/routes/examples/props/name/+page.svelte +13 -0
- package/src/routes/examples/props/placeholder/+page.svelte +14 -0
- package/src/routes/examples/props/placeholder-always-show/+page.svelte +11 -0
- package/src/routes/examples/props/required/+page.svelte +14 -0
- package/src/routes/examples/props/searchable/+page.svelte +15 -0
- package/src/routes/examples/props/show-chevron/+page.svelte +15 -0
- package/src/routes/examples/props/value/+page.svelte +19 -0
- package/src/routes/examples/slots/chevron-icon/+page.svelte +16 -0
- package/src/routes/examples/slots/clear-icon/+page.svelte +21 -0
- package/src/routes/examples/slots/empty/+page.svelte +18 -0
- package/src/routes/examples/slots/input-hidden/+page.server.js +10 -0
- package/src/routes/examples/slots/input-hidden/+page.svelte +22 -0
- package/src/routes/examples/slots/item/+page.svelte +15 -0
- package/src/routes/examples/slots/list/+page.svelte +49 -0
- package/src/routes/examples/slots/list-append/+page.svelte +16 -0
- package/src/routes/examples/slots/list-prepend/+page.svelte +16 -0
- package/src/routes/examples/slots/loading-icon/+page.svelte +29 -0
- package/src/routes/examples/slots/multi-clear-icon/+page.svelte +16 -0
- package/src/routes/examples/slots/prepend/+page.svelte +22 -0
- package/src/routes/examples/slots/required/+page.svelte +31 -0
- package/src/routes/examples/slots/selection/+page.svelte +25 -0
- package/static/nav-icon.svg +2 -0
- package/static/svelte-select.png +0 -0
- package/svelte-select.png +0 -0
- package/svelte.config.js +10 -0
- package/tailwind.config.cjs +4 -0
- package/test/public/favicon.ico +0 -0
- package/test/public/index.html +15 -0
- package/test/src/ChevronSlotTest.svelte +19 -0
- package/test/src/ClearIconSlotTest.svelte +12 -0
- package/test/src/CustomItem.svelte +78 -0
- package/test/src/GroupHeaderNotSelectable.svelte +17 -0
- package/test/src/HoverItemIndexTest.svelte +21 -0
- package/test/src/InputHiddenSlotTest.svelte +12 -0
- package/test/src/ItemHeightTest.svelte +7 -0
- package/test/src/ItemSlotTest.svelte +11 -0
- package/test/src/ListSlotTest.svelte +14 -0
- package/test/src/LoadOptionsGroup.svelte +21 -0
- package/test/src/MultiItemColor.svelte +7 -0
- package/test/src/OuterListTest.svelte +16 -0
- package/test/src/PrependSlotTest.svelte +12 -0
- package/test/src/Select/ParentContainer.svelte +11 -0
- package/test/src/SelectionSlotMultipleTest.svelte +12 -0
- package/test/src/SelectionSlotTest.svelte +12 -0
- package/test/src/TestClearIcon.svelte +1 -0
- package/test/src/TestIcon.svelte +15 -0
- package/test/src/env.js +1 -0
- package/test/src/test-utils.js +124 -0
- package/test/src/tests.js +3745 -0
- package/vite.config.js +9 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export default function filter({
|
|
2
|
+
loadOptions,
|
|
3
|
+
filterText,
|
|
4
|
+
items,
|
|
5
|
+
multiple,
|
|
6
|
+
value,
|
|
7
|
+
itemId,
|
|
8
|
+
groupBy,
|
|
9
|
+
filterSelectedItems,
|
|
10
|
+
itemFilter,
|
|
11
|
+
convertStringItemsToObjects,
|
|
12
|
+
filterGroupedItems,
|
|
13
|
+
label,
|
|
14
|
+
}) {
|
|
15
|
+
if (items && loadOptions) return items;
|
|
16
|
+
if (!items) return [];
|
|
17
|
+
|
|
18
|
+
if (items && items.length > 0 && typeof items[0] !== 'object') {
|
|
19
|
+
items = convertStringItemsToObjects(items);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let filterResults = items.filter((item) => {
|
|
23
|
+
let matchesFilter = itemFilter(item[label], filterText, item);
|
|
24
|
+
if (matchesFilter && multiple && value?.length) {
|
|
25
|
+
matchesFilter = !value.some((x) => {
|
|
26
|
+
return filterSelectedItems ? x[itemId] === item[itemId] : false;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return matchesFilter;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (groupBy) {
|
|
34
|
+
filterResults = filterGroupedItems(filterResults);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return filterResults;
|
|
38
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export default async function getItems({ dispatch, loadOptions, convertStringItemsToObjects, filterText }) {
|
|
2
|
+
let res = await loadOptions(filterText).catch((err) => {
|
|
3
|
+
console.warn('svelte-select loadOptions error :>> ', err);
|
|
4
|
+
dispatch('error', { type: 'loadOptions', details: err });
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
if (res && !res.cancelled) {
|
|
8
|
+
if (res) {
|
|
9
|
+
if (res && res.length > 0 && typeof res[0] !== 'object') {
|
|
10
|
+
res = convertStringItemsToObjects(res);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
dispatch('loaded', { items: res });
|
|
14
|
+
} else {
|
|
15
|
+
res = [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
filteredItems: res,
|
|
20
|
+
loading: false,
|
|
21
|
+
focused: true,
|
|
22
|
+
listOpen: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/lib/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as default } from './Select.svelte';
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
@import 'tailwindcss/base';
|
|
2
|
+
|
|
3
|
+
.svelte-select {
|
|
4
|
+
@apply border rounded box-border h-10 relative flex items-center px-4 py-0 bg-white m-0 w-full
|
|
5
|
+
hover:border-gray-400;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.svelte-select input {
|
|
9
|
+
@apply cursor-default border-none text-gray-600 h-10 leading-10 px-4 py-0 bg-transparent text-sm absolute left-0 m-0 w-full
|
|
10
|
+
focus:outline-none hover:border-gray-400;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.svelte-select.focused {
|
|
14
|
+
@apply border-blue-600;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.svelte-select.disabled {
|
|
18
|
+
@apply bg-gray-200 border-gray-200 text-gray-600;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.svelte-select.disabled input {
|
|
22
|
+
@apply placeholder:text-gray-400 placeholder:opacity-100;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.svelte-select .selected-item {
|
|
26
|
+
@apply leading-10 h-10 overflow-x-hidden pr-5
|
|
27
|
+
focus:outline-none;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.svelte-select .icons {
|
|
31
|
+
@apply absolute flex items-center right-0 translate-y-0 text-gray-200 pointer-events-none top-0 bottom-0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.svelte-select .icons > * {
|
|
35
|
+
@apply transition-colors ease-in-out duration-200;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.svelte-select .clear-select {
|
|
39
|
+
@apply pointer-events-auto;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.svelte-select.focused .icons,
|
|
43
|
+
.svelte-select .chevron:hover,
|
|
44
|
+
.svelte-select .clear-select:hover {
|
|
45
|
+
@apply text-gray-600;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.svelte-select .clear-select {
|
|
49
|
+
@apply px-2 h-5 text-gray-300 flex-none w-9;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.svelte-select .chevron {
|
|
53
|
+
@apply flex pt-0 pr-2 pl-2 border-l-2 w-9 h-5 text-gray-300;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.svelte-select.multi {
|
|
57
|
+
@apply pr-9 pl-4 h-auto flex-wrap items-stretch;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.svelte-select.multi input {
|
|
61
|
+
@apply p-0 relative m-0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.svelte-select.error {
|
|
65
|
+
@apply border-red-500 bg-white;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.a11y-text {
|
|
69
|
+
@apply sr-only;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.list {
|
|
73
|
+
@apply shadow-md rounded-sm max-h-64 overflow-y-auto bg-white border-none absolute z-10 w-full left-0 right-0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.list .list-group-title {
|
|
77
|
+
@apply text-gray-400 cursor-default text-sm font-medium h-10 leading-10 px-5 overflow-ellipsis whitespace-nowrap uppercase;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.list .empty {
|
|
81
|
+
@apply text-center py-5 text-gray-500;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.item {
|
|
85
|
+
@apply cursor-default h-10 leading-10 px-5 text-gray-800 overflow-ellipsis overflow-hidden whitespace-nowrap;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.item.group-item {
|
|
89
|
+
@apply px-10;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.item:active {
|
|
93
|
+
@apply bg-blue-200;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.item.active {
|
|
97
|
+
@apply bg-blue-600 text-white;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.item.not-selectable {
|
|
101
|
+
@apply text-gray-300;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.item.first {
|
|
105
|
+
@apply rounded-t-sm;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.item.hover:not(.active) {
|
|
109
|
+
@apply bg-blue-100;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.multi input {
|
|
113
|
+
flex: 1 1 40px;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.multi-item {
|
|
117
|
+
@apply bg-gray-100 mt-1 mr-1 border border-gray-200 rounded-sm h-8 leading-8 flex cursor-default pr-1 pl-1 max-w-full items-center mr-1 overflow-hidden overflow-ellipsis whitespace-nowrap;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.multi-item.disabled {
|
|
121
|
+
@apply hover:bg-gray-300 hover:text-gray-500;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.multi-item-clear {
|
|
125
|
+
@apply flex items-center justify-center w-5;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.list-item {
|
|
129
|
+
@apply list-none;
|
|
130
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { writeFile, mkdir } = require('fs/promises');
|
|
2
|
+
const path = require("path");
|
|
3
|
+
const { find } = require("find-in-files");
|
|
4
|
+
|
|
5
|
+
const USAGE_PATTERN = /((.|\n)*)(?=<style)/;
|
|
6
|
+
const SOURCE_FOLDER = path.join(__dirname, 'lib');
|
|
7
|
+
|
|
8
|
+
(async () => {
|
|
9
|
+
const searchResults = await find(USAGE_PATTERN, SOURCE_FOLDER, '.svelte$');
|
|
10
|
+
let promises = [mkdir(path.join(__dirname, '/lib/no-styles'), { recursive: true })];
|
|
11
|
+
|
|
12
|
+
Object.keys(searchResults).forEach((key) => {
|
|
13
|
+
let fileName = key.split('/').pop();
|
|
14
|
+
if (fileName === 'Select.svelte') {
|
|
15
|
+
searchResults[key].matches[0] = searchResults[key].matches[0].replace('./filter', '../filter');
|
|
16
|
+
searchResults[key].matches[0] = searchResults[key].matches[0].replace('./get-items', '../get-items');
|
|
17
|
+
}
|
|
18
|
+
promises.push(writeFile(path.join(__dirname, '/lib/no-styles', fileName), searchResults[key].matches[0]));
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const all = await Promise.all(promises);
|
|
22
|
+
})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const prerender = true;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { page, navigating } from '$app/stores';
|
|
3
|
+
|
|
4
|
+
import { HighlightSvelte } from 'svelte-highlight';
|
|
5
|
+
import highlightStyles from 'svelte-highlight/styles/atom-one-dark';
|
|
6
|
+
|
|
7
|
+
let { children } = $props();
|
|
8
|
+
|
|
9
|
+
const _props = import.meta.glob('./examples/props/*/*.svelte', { as: 'raw' });
|
|
10
|
+
const _slots = import.meta.glob('./examples/slots/*/*.svelte', { as: 'raw' });
|
|
11
|
+
const _events = import.meta.glob('./examples/events/*/*.svelte', { as: 'raw' });
|
|
12
|
+
const _advanced = import.meta.glob('./examples/advanced/*/*.svelte', { as: 'raw' });
|
|
13
|
+
|
|
14
|
+
let source = $state(null);
|
|
15
|
+
let showNav = $state(false);
|
|
16
|
+
|
|
17
|
+
function buildLinks(obj) {
|
|
18
|
+
return Object.keys(obj).map((key) => {
|
|
19
|
+
const sp = key.split('/');
|
|
20
|
+
const name = sp[3].split('.')[0];
|
|
21
|
+
return {
|
|
22
|
+
href: `${sp[1]}/${sp[2]}/` + name,
|
|
23
|
+
name: name.replace(/-./g, (x) => x[1].toUpperCase()),
|
|
24
|
+
source: obj[key],
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const pascalToSpaced = (s) => {
|
|
30
|
+
return s.replace(/([A-Z])/g, ' $1').replace(/^./, (str) => str.toUpperCase());
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
async function handleExampleCode(newPage) {
|
|
34
|
+
source = null;
|
|
35
|
+
|
|
36
|
+
if (!newPage?.route?.id) return;
|
|
37
|
+
|
|
38
|
+
if (newPage?.route?.id?.includes('examples/')) {
|
|
39
|
+
const s = newPage.route.id.split('/');
|
|
40
|
+
const file = setup[s[2]].find((i) => i.href.split('/').pop() === s[3]);
|
|
41
|
+
const raw = await file.source();
|
|
42
|
+
source = raw.replace('$lib/Select.svelte', 'svelte-select');
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function handleNav() {
|
|
47
|
+
showNav = !showNav;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let setup = $derived({
|
|
51
|
+
props: buildLinks(_props),
|
|
52
|
+
slots: buildLinks(_slots),
|
|
53
|
+
events: buildLinks(_events),
|
|
54
|
+
advanced: buildLinks(_advanced),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
let route = $derived($page.route.id.substring(1));
|
|
58
|
+
|
|
59
|
+
$effect(() => {
|
|
60
|
+
if ($navigating) showNav = false;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
$effect(() => {
|
|
64
|
+
handleExampleCode($page);
|
|
65
|
+
});
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<svelte:head>
|
|
69
|
+
{@html highlightStyles}
|
|
70
|
+
</svelte:head>
|
|
71
|
+
|
|
72
|
+
<div class="container">
|
|
73
|
+
<button onclick={handleNav} class="show-nav" aria-label="Toggle navigation">
|
|
74
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#000000"
|
|
75
|
+
><path
|
|
76
|
+
d="M 3 5 A 1.0001 1.0001 0 1 0 3 7 L 21 7 A 1.0001 1.0001 0 1 0 21 5 L 3 5 z M 3 11 A 1.0001 1.0001 0 1 0 3 13 L 21 13 A 1.0001 1.0001 0 1 0 21 11 L 3 11 z M 3 17 A 1.0001 1.0001 0 1 0 3 19 L 21 19 A 1.0001 1.0001 0 1 0 21 17 L 3 17 z"
|
|
77
|
+
fill="currentcolor" /></svg>
|
|
78
|
+
</button>
|
|
79
|
+
|
|
80
|
+
<nav class:show={showNav} class:navigating={$navigating}>
|
|
81
|
+
<ul>
|
|
82
|
+
<li><a class:active={$page.route.id === 'examples'} href="/">Home</a></li>
|
|
83
|
+
</ul>
|
|
84
|
+
|
|
85
|
+
<h2>Props</h2>
|
|
86
|
+
<ul>
|
|
87
|
+
{#each setup.props as { href, name }}
|
|
88
|
+
<li><a class:active={route === href} href={`/${href}`}>{name}</a></li>
|
|
89
|
+
{/each}
|
|
90
|
+
</ul>
|
|
91
|
+
|
|
92
|
+
<h2>Slots</h2>
|
|
93
|
+
<ul>
|
|
94
|
+
{#each setup.slots as { href, name }}
|
|
95
|
+
<li><a class:active={route === href} href={`/${href}`}>{name}</a></li>
|
|
96
|
+
{/each}
|
|
97
|
+
</ul>
|
|
98
|
+
|
|
99
|
+
<h2>Events</h2>
|
|
100
|
+
<ul>
|
|
101
|
+
{#each setup.events as { href, name }}
|
|
102
|
+
<li><a class:active={route === href} href={`/${href}`}>{name}</a></li>
|
|
103
|
+
{/each}
|
|
104
|
+
</ul>
|
|
105
|
+
|
|
106
|
+
<h2>Advanced</h2>
|
|
107
|
+
<ul>
|
|
108
|
+
{#each setup.advanced as { href, name }}
|
|
109
|
+
<li><a class:active={route === href} href={`/${href}`}>{pascalToSpaced(name)}</a></li>
|
|
110
|
+
{/each}
|
|
111
|
+
</ul>
|
|
112
|
+
</nav>
|
|
113
|
+
|
|
114
|
+
<div class="content" class:spinning={$navigating}>
|
|
115
|
+
<img src="/svelte-select.png" alt="Svelte Select Logo" class="spinner" />
|
|
116
|
+
|
|
117
|
+
{#if !$navigating}
|
|
118
|
+
{@render children()}
|
|
119
|
+
|
|
120
|
+
{#if source}
|
|
121
|
+
<HighlightSvelte code={source} />
|
|
122
|
+
{/if}
|
|
123
|
+
{/if}
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<style>
|
|
128
|
+
.show-nav {
|
|
129
|
+
position: fixed;
|
|
130
|
+
bottom: 20px;
|
|
131
|
+
right: 20px;
|
|
132
|
+
width: 40px;
|
|
133
|
+
background: #ff3e00;
|
|
134
|
+
border: none;
|
|
135
|
+
border-radius: 6px;
|
|
136
|
+
padding: 5px 8px;
|
|
137
|
+
color: #fff;
|
|
138
|
+
display: flex;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
nav {
|
|
142
|
+
display: none;
|
|
143
|
+
position: fixed;
|
|
144
|
+
top: 0;
|
|
145
|
+
right: 0;
|
|
146
|
+
left: 0;
|
|
147
|
+
height: 100vh;
|
|
148
|
+
flex-direction: column;
|
|
149
|
+
background: #fff;
|
|
150
|
+
overflow-y: scroll;
|
|
151
|
+
position: fixed;
|
|
152
|
+
z-index: 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
nav.show {
|
|
156
|
+
display: flex;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
nav.show.navigating {
|
|
160
|
+
display: none;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.container {
|
|
164
|
+
display: flex;
|
|
165
|
+
flex-direction: column;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
h2 {
|
|
169
|
+
margin: 0;
|
|
170
|
+
font-size: 16px;
|
|
171
|
+
padding: 10px;
|
|
172
|
+
border-bottom: 1px solid #f3f1fd;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
ul {
|
|
176
|
+
padding: 0;
|
|
177
|
+
margin: 0 0 10px;
|
|
178
|
+
list-style: none;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
li {
|
|
182
|
+
display: flex;
|
|
183
|
+
flex-direction: column;
|
|
184
|
+
border-bottom: 1px solid #f3f1fd;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
a {
|
|
188
|
+
color: #696d75;
|
|
189
|
+
padding: 10px;
|
|
190
|
+
text-decoration: none;
|
|
191
|
+
font-size: 16px;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
a.active {
|
|
195
|
+
background: #f3f1fd;
|
|
196
|
+
color: black;
|
|
197
|
+
font-weight: bold;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
.content {
|
|
201
|
+
padding: 20px;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.content .spinner {
|
|
205
|
+
display: none;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.content.spinning {
|
|
209
|
+
display: flex;
|
|
210
|
+
flex-direction: column;
|
|
211
|
+
align-items: center;
|
|
212
|
+
justify-content: center;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.content.spinning .spinner {
|
|
216
|
+
display: block;
|
|
217
|
+
animation-name: spin;
|
|
218
|
+
animation-duration: 550ms;
|
|
219
|
+
animation-iteration-count: infinite;
|
|
220
|
+
animation-timing-function: linear;
|
|
221
|
+
width: 30px;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
@keyframes spin {
|
|
225
|
+
from {
|
|
226
|
+
transform: rotate(0deg);
|
|
227
|
+
}
|
|
228
|
+
to {
|
|
229
|
+
transform: rotate(360deg);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@media (min-width: 800px) {
|
|
234
|
+
.show-nav {
|
|
235
|
+
display: none;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
nav,
|
|
239
|
+
nav.navigating {
|
|
240
|
+
display: flex;
|
|
241
|
+
flex-direction: column;
|
|
242
|
+
width: 250px;
|
|
243
|
+
border-right: 1px solid #f3f1fd;
|
|
244
|
+
right: unset;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
.container {
|
|
248
|
+
display: flex;
|
|
249
|
+
gap: 30px;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.content {
|
|
253
|
+
position: fixed;
|
|
254
|
+
left: 250px;
|
|
255
|
+
right: 0;
|
|
256
|
+
top: 0;
|
|
257
|
+
bottom: 0;
|
|
258
|
+
overflow-y: auto;
|
|
259
|
+
padding: 30px;
|
|
260
|
+
flex-grow: 1;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
</style>
|
|
File without changes
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
<div class="container">
|
|
2
|
+
<header>
|
|
3
|
+
<img src="/svelte-select.png" alt="Svelte Select" />
|
|
4
|
+
|
|
5
|
+
<aside>
|
|
6
|
+
<h1>Svelte Select /</h1>
|
|
7
|
+
<h2>Examples</h2>
|
|
8
|
+
</aside>
|
|
9
|
+
</header>
|
|
10
|
+
|
|
11
|
+
<div class="badges">
|
|
12
|
+
<a href="https://npmjs.org/package/svelte-select">
|
|
13
|
+
<img src="https://badgen.now.sh/npm/v/svelte-select" alt="version" />
|
|
14
|
+
</a>
|
|
15
|
+
<a href="https://npmjs.org/package/svelte-select">
|
|
16
|
+
<img src="https://badgen.now.sh/npm/dm/svelte-select" alt="downloads" />
|
|
17
|
+
</a>
|
|
18
|
+
<a href="https://github.com/rob-balfre/svelte-select">
|
|
19
|
+
<img src="https://badgen.net/badge/icon/github?icon=github&label" alt="downloads" />
|
|
20
|
+
</a>
|
|
21
|
+
</div>
|
|
22
|
+
</div>
|
|
23
|
+
|
|
24
|
+
<style>
|
|
25
|
+
.container {
|
|
26
|
+
display: flex;
|
|
27
|
+
flex-direction: column;
|
|
28
|
+
align-items: center;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
header {
|
|
32
|
+
display: flex;
|
|
33
|
+
gap: 10px;
|
|
34
|
+
margin-bottom: 20px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
header img {
|
|
38
|
+
width: 50px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
h1 {
|
|
42
|
+
font-size: 16px;
|
|
43
|
+
margin: 0;
|
|
44
|
+
text-transform: uppercase;
|
|
45
|
+
color: #999;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
h2 {
|
|
49
|
+
margin: 0;
|
|
50
|
+
font-size: 36px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.badges {
|
|
54
|
+
display: flex;
|
|
55
|
+
gap: 10px;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.badges a {
|
|
59
|
+
display: flex;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@media (min-width: 800px) {
|
|
63
|
+
|
|
64
|
+
header img {
|
|
65
|
+
width:93px;
|
|
66
|
+
margin: 0;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
aside {
|
|
70
|
+
display: flex;
|
|
71
|
+
flex-direction: column;
|
|
72
|
+
justify-content: flex-end;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
h1 {
|
|
76
|
+
font-size: 24px;
|
|
77
|
+
line-height: 0px;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
h2 {
|
|
81
|
+
font-size: 68px;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
</style>
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Select from '$lib/Select.svelte';
|
|
3
|
+
|
|
4
|
+
let filterText = $state('');
|
|
5
|
+
|
|
6
|
+
let items = $state([
|
|
7
|
+
{ value: 1, label: 'name 1' },
|
|
8
|
+
{ value: 2, label: 'name 2' },
|
|
9
|
+
{ value: 3, label: 'name 3' },
|
|
10
|
+
{ value: 4, label: 'name 4' },
|
|
11
|
+
{ value: 5, label: 'name 5' },
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
function handleFilter(filteredItems) {
|
|
15
|
+
if (filteredItems.length === 0 && filterText.length > 0) {
|
|
16
|
+
const prev = items.filter((i) => !i.created);
|
|
17
|
+
items = [...prev, { value: filterText, label: filterText, created: true }];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function handleChange(value) {
|
|
22
|
+
items = items.map((i) => {
|
|
23
|
+
delete i.created;
|
|
24
|
+
return i;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<Select onchange={handleChange} onfilter={handleFilter} bind:filterText {items}>
|
|
30
|
+
{#snippet item({ item })}
|
|
31
|
+
<div>
|
|
32
|
+
{item.created ? 'Add new: ' : ''}
|
|
33
|
+
{item.label}
|
|
34
|
+
</div>
|
|
35
|
+
{/snippet}
|
|
36
|
+
</Select>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Select from '$lib/Select.svelte';
|
|
3
|
+
|
|
4
|
+
let filterText = $state('');
|
|
5
|
+
let value = $state(null);
|
|
6
|
+
|
|
7
|
+
let items = $state([
|
|
8
|
+
{ value: 1, label: 'name 1' },
|
|
9
|
+
{ value: 2, label: 'name 2' },
|
|
10
|
+
{ value: 3, label: 'name 3' },
|
|
11
|
+
{ value: 4, label: 'name 4' },
|
|
12
|
+
{ value: 5, label: 'name 5' },
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
function handleFilter(filteredItems) {
|
|
16
|
+
if (value?.find(i => i.label === filterText)) return;
|
|
17
|
+
if (filteredItems.length === 0 && filterText.length > 0) {
|
|
18
|
+
const prev = items.filter((i) => !i.created);
|
|
19
|
+
items = [...prev, { value: filterText, label: filterText, created: true }];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function handleChange(newValue) {
|
|
24
|
+
items = items.map((i) => {
|
|
25
|
+
delete i.created;
|
|
26
|
+
return i;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<Select onchange={handleChange} multiple onfilter={handleFilter} bind:filterText bind:value {items}>
|
|
32
|
+
{#snippet item({ item })}
|
|
33
|
+
<div>
|
|
34
|
+
{item.created ? 'Add new: ' : ''}
|
|
35
|
+
{item.label}
|
|
36
|
+
</div>
|
|
37
|
+
{/snippet}
|
|
38
|
+
</Select>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Select from '$lib/Select.svelte';
|
|
3
|
+
|
|
4
|
+
let items = ['One', 'Two', 'Three'];
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class="box"></div>
|
|
8
|
+
|
|
9
|
+
<div style="position:fixed; left: 300px; top: 100px; width: 400px">
|
|
10
|
+
<Select
|
|
11
|
+
{items}
|
|
12
|
+
floatingConfig={{
|
|
13
|
+
strategy: 'fixed',
|
|
14
|
+
}} />
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<style>
|
|
19
|
+
.box {
|
|
20
|
+
height: 300px;
|
|
21
|
+
}
|
|
22
|
+
</style>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const prerender = false;
|
|
2
|
+
|
|
3
|
+
/** @type {import('./$types').Actions} */
|
|
4
|
+
export const actions = {
|
|
5
|
+
someaction: async ({ request }) => {
|
|
6
|
+
const data = await request.formData();
|
|
7
|
+
const foobar = data.get('foobar');
|
|
8
|
+
return { success: true, foobar };
|
|
9
|
+
},
|
|
10
|
+
};
|