-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.svelte
130 lines (96 loc) · 2.81 KB
/
main.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<script>
export let OLSKTaxonomyItems;
export let OLSKTaxonomySuggestionItems = [];
export let OLSKTaxonomyDispatchUpdate;
import { OLSKLocalized } from 'OLSKInternational';
import { OLSKFormatted } from 'OLSKString';
import Choices from 'choices.js';
const mod = {
// VALUE
_ValueSuggestions: OLSKTaxonomySuggestionItems,
// CONTROL
ControlTagSuggestion (inputData) {
mod._ValueSuggestions = mod._ValueSuggestions.filter(function (e) {
return e !== inputData;
});
mod._ChoicesInstance.setValue([inputData]);
mod.ReactItems();
},
// REACT
ReactItems () {
OLSKTaxonomyDispatchUpdate(mod._ChoicesInstance.getValue(true));
},
// SETUP
SetupEverything() {
mod._ChoicesInstance = new Choices(mod._ChoicesElement, {
items: OLSKTaxonomyItems,
placeholder: true,
placeholderValue: OLSKLocalized('OLSKTaxonomyFieldText'),
addItemText (inputData) {
return OLSKFormatted(OLSKLocalized('OLSKTaxonomyHintTemplate'), inputData);
},
removeItems: true,
removeItemButton: true,
allowHTML: false,
});
mod._ChoicesInstance.passedElement.element.addEventListener('change', mod.ReactItems, false);
mod._ChoicesInstance.passedElement.element.addEventListener('removeItem', function (event) {
mod._ValueSuggestions = OLSKTaxonomySuggestionItems.filter(function (e) {
return e === event.detail.value || mod._ValueSuggestions.includes(e);
})
}, false);
},
// LIFECYCLE
LifecycleModuleDidLoad() {
mod.SetupEverything();
},
};
import { onMount } from 'svelte';
onMount(mod.LifecycleModuleDidLoad);
</script>
<div class="OLSKTaxonomy">
<input type="text" bind:this={ mod._ChoicesElement } />
{#if mod._ValueSuggestions.length }
<p>
{#each mod._ValueSuggestions as item }
<button class="OLSKTaxonomySuggestion" on:click={ () => mod.ControlTagSuggestion(item) }>{ item }</button>
{/each}
</p>
{/if}
</div>
<style>
.OLSKTaxonomy :global(.choices) {
margin: 0;
}
.OLSKTaxonomy :global(.choices__inner), .OLSKTaxonomy :global(.choices__list--dropdown) {
background: var(--OLSKDecorFormBlendBackground) !important;
border-color: var(--OLSKDecorForegroundLight) !important;
width: 90% !important;
min-height: unset !important;
padding: var(--OLSKCommonInputPadding) !important;
}
.OLSKTaxonomy :global(.choices__input) {
border: none;
padding: var(--OLSKCommonInputPadding);
margin: 0;
}
.OLSKTaxonomy :global(.choices__list--dropdown .choices__item) {
padding: 0 10px;
}
.OLSKTaxonomy :global(.choices__list--multiple .choices__item) {
background: none;
border-color: var(--OLSKCommonForeground);
color: var(--OLSKCommonForeground);
}
.OLSKTaxonomy :global(.choices__button) {
margin: 0 !important;
padding: 0;
background: unset;
background-repeat: no-repeat;
background-position: center;
border: none !important;
}
.OLSKTaxonomySuggestion {
margin-right: 4px;
}
</style>