@budibase/bbui 1.1.29-alpha.1 → 1.1.29
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/bbui.es.js +35 -35
- package/dist/bbui.es.js.map +1 -1
- package/package.json +3 -3
- package/src/ActionButton/ActionButton.svelte +7 -0
- package/src/Avatar/Avatar.svelte +3 -16
- package/src/Form/Core/Multiselect.svelte +0 -2
- package/src/Form/Core/Picker.svelte +19 -16
- package/src/Form/Core/Select.svelte +1 -0
- package/src/Form/Multiselect.svelte +1 -2
- package/src/List/Items/DetailSummary.svench +53 -0
- package/src/StatusLight/StatusLight.svelte +16 -0
- package/src/Table/Table.svelte +2 -19
- package/src/index.js +0 -6
- package/src/Form/Core/InputDropdown.svelte +0 -218
- package/src/Form/Core/PickerDropdown.svelte +0 -430
- package/src/Form/InputDropdown.svelte +0 -55
- package/src/Form/PickerDropdown.svelte +0 -125
- package/src/IconPicker/IconPicker.svelte +0 -177
- package/src/List/List.svelte +0 -28
- package/src/List/ListItem.svelte +0 -92
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/bbui",
|
|
3
3
|
"description": "A UI solution used in the different Budibase projects.",
|
|
4
|
-
"version": "1.1.29
|
|
4
|
+
"version": "1.1.29",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"svelte": "src/index.js",
|
|
7
7
|
"module": "dist/bbui.es.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@adobe/spectrum-css-workflow-icons": "^1.2.1",
|
|
41
|
-
"@budibase/string-templates": "^1.1.29
|
|
41
|
+
"@budibase/string-templates": "^1.1.29",
|
|
42
42
|
"@spectrum-css/actionbutton": "^1.0.1",
|
|
43
43
|
"@spectrum-css/actiongroup": "^1.0.1",
|
|
44
44
|
"@spectrum-css/avatar": "^3.0.2",
|
|
@@ -85,5 +85,5 @@
|
|
|
85
85
|
"svelte-flatpickr": "^3.2.3",
|
|
86
86
|
"svelte-portal": "^1.0.0"
|
|
87
87
|
},
|
|
88
|
-
"gitHead": "
|
|
88
|
+
"gitHead": "17638b7cf6b850d6cf472537f9334b9721875bc4"
|
|
89
89
|
}
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
}
|
|
85
85
|
:global([dir="ltr"] .spectrum-ActionButton .spectrum-Icon) {
|
|
86
86
|
margin-left: 0;
|
|
87
|
+
transition: color ease-out 130ms;
|
|
87
88
|
}
|
|
88
89
|
.is-selected:not(.spectrum-ActionButton--emphasized) {
|
|
89
90
|
background: var(--spectrum-global-color-gray-300);
|
|
@@ -92,4 +93,10 @@
|
|
|
92
93
|
padding: 0;
|
|
93
94
|
min-width: 0;
|
|
94
95
|
}
|
|
96
|
+
.spectrum-ActionButton--quiet {
|
|
97
|
+
padding: 0 8px;
|
|
98
|
+
}
|
|
99
|
+
.is-selected:not(.emphasized) .spectrum-Icon {
|
|
100
|
+
color: var(--spectrum-global-color-gray-900);
|
|
101
|
+
}
|
|
95
102
|
</style>
|
package/src/Avatar/Avatar.svelte
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
["XXS", "--spectrum-alias-avatar-size-50"],
|
|
5
5
|
["XS", "--spectrum-alias-avatar-size-75"],
|
|
6
6
|
["S", "--spectrum-alias-avatar-size-200"],
|
|
7
|
-
["M", "--spectrum-alias-avatar-size-
|
|
7
|
+
["M", "--spectrum-alias-avatar-size-300"],
|
|
8
8
|
["L", "--spectrum-alias-avatar-size-500"],
|
|
9
9
|
["XL", "--spectrum-alias-avatar-size-600"],
|
|
10
10
|
["XXL", "--spectrum-alias-avatar-size-700"],
|
|
@@ -13,19 +13,6 @@
|
|
|
13
13
|
export let url = ""
|
|
14
14
|
export let disabled = false
|
|
15
15
|
export let initials = "JD"
|
|
16
|
-
|
|
17
|
-
const DefaultColor = "#3aab87"
|
|
18
|
-
|
|
19
|
-
$: color = getColor(initials)
|
|
20
|
-
|
|
21
|
-
const getColor = initials => {
|
|
22
|
-
if (!initials?.length) {
|
|
23
|
-
return DefaultColor
|
|
24
|
-
}
|
|
25
|
-
const code = initials[0].toLowerCase().charCodeAt(0)
|
|
26
|
-
const hue = ((code % 26) / 26) * 360
|
|
27
|
-
return `hsl(${hue}, 50%, 50%)`
|
|
28
|
-
}
|
|
29
16
|
</script>
|
|
30
17
|
|
|
31
18
|
{#if url}
|
|
@@ -38,11 +25,10 @@
|
|
|
38
25
|
/>
|
|
39
26
|
{:else}
|
|
40
27
|
<div
|
|
41
|
-
class="spectrum-Avatar"
|
|
42
28
|
class:is-disabled={disabled}
|
|
43
29
|
style="width: var({sizes.get(size)}); height: var({sizes.get(
|
|
44
30
|
size
|
|
45
|
-
)}); font-size: calc(var({sizes.get(size)}) / 2)
|
|
31
|
+
)}); font-size: calc(var({sizes.get(size)}) / 2)"
|
|
46
32
|
>
|
|
47
33
|
{initials || ""}
|
|
48
34
|
</div>
|
|
@@ -54,6 +40,7 @@
|
|
|
54
40
|
display: grid;
|
|
55
41
|
place-items: center;
|
|
56
42
|
font-weight: 600;
|
|
43
|
+
background: #3aab87;
|
|
57
44
|
border-radius: 50%;
|
|
58
45
|
overflow: hidden;
|
|
59
46
|
user-select: none;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
export let readonly = false
|
|
14
14
|
export let autocomplete = false
|
|
15
15
|
export let sort = false
|
|
16
|
-
export let autoWidth = false
|
|
17
16
|
|
|
18
17
|
const dispatch = createEventDispatcher()
|
|
19
18
|
$: selectedLookupMap = getSelectedLookupMap(value)
|
|
@@ -86,5 +85,4 @@
|
|
|
86
85
|
{getOptionValue}
|
|
87
86
|
onSelectOption={toggleOption}
|
|
88
87
|
{sort}
|
|
89
|
-
{autoWidth}
|
|
90
88
|
/>
|
|
@@ -87,10 +87,15 @@
|
|
|
87
87
|
on:mousedown={onClick}
|
|
88
88
|
>
|
|
89
89
|
{#if fieldIcon}
|
|
90
|
-
<span class="option-
|
|
90
|
+
<span class="option-extra">
|
|
91
91
|
<Icon name={fieldIcon} />
|
|
92
92
|
</span>
|
|
93
93
|
{/if}
|
|
94
|
+
{#if fieldColour}
|
|
95
|
+
<span class="option-extra">
|
|
96
|
+
<StatusLight square color={fieldColour} />
|
|
97
|
+
</span>
|
|
98
|
+
{/if}
|
|
94
99
|
<span
|
|
95
100
|
class="spectrum-Picker-label"
|
|
96
101
|
class:is-placeholder={isPlaceholder}
|
|
@@ -108,11 +113,6 @@
|
|
|
108
113
|
<use xlink:href="#spectrum-icon-18-Alert" />
|
|
109
114
|
</svg>
|
|
110
115
|
{/if}
|
|
111
|
-
{#if fieldColour}
|
|
112
|
-
<span class="option-colour">
|
|
113
|
-
<StatusLight size="L" color={fieldColour} />
|
|
114
|
-
</span>
|
|
115
|
-
{/if}
|
|
116
116
|
<svg
|
|
117
117
|
class="spectrum-Icon spectrum-UIIcon-ChevronDown100 spectrum-Picker-menuIcon"
|
|
118
118
|
focusable="false"
|
|
@@ -166,10 +166,15 @@
|
|
|
166
166
|
on:click={() => onSelectOption(getOptionValue(option, idx))}
|
|
167
167
|
>
|
|
168
168
|
{#if getOptionIcon(option, idx)}
|
|
169
|
-
<span class="option-
|
|
169
|
+
<span class="option-extra">
|
|
170
170
|
<Icon name={getOptionIcon(option, idx)} />
|
|
171
171
|
</span>
|
|
172
172
|
{/if}
|
|
173
|
+
{#if getOptionColour(option, idx)}
|
|
174
|
+
<span class="option-extra">
|
|
175
|
+
<StatusLight square color={getOptionColour(option, idx)} />
|
|
176
|
+
</span>
|
|
177
|
+
{/if}
|
|
173
178
|
<span class="spectrum-Menu-itemLabel">
|
|
174
179
|
{getOptionLabel(option, idx)}
|
|
175
180
|
</span>
|
|
@@ -180,11 +185,6 @@
|
|
|
180
185
|
>
|
|
181
186
|
<use xlink:href="#spectrum-css-icon-Checkmark100" />
|
|
182
187
|
</svg>
|
|
183
|
-
{#if getOptionColour(option, idx)}
|
|
184
|
-
<span class="option-colour">
|
|
185
|
-
<StatusLight size="L" color={getOptionColour(option, idx)} />
|
|
186
|
-
</span>
|
|
187
|
-
{/if}
|
|
188
188
|
</li>
|
|
189
189
|
{/each}
|
|
190
190
|
{/if}
|
|
@@ -209,6 +209,9 @@
|
|
|
209
209
|
width: 100%;
|
|
210
210
|
box-shadow: none;
|
|
211
211
|
}
|
|
212
|
+
.spectrum-Picker-label.auto-width {
|
|
213
|
+
margin-right: var(--spacing-xs);
|
|
214
|
+
}
|
|
212
215
|
.spectrum-Picker-label:not(.auto-width) {
|
|
213
216
|
overflow: hidden;
|
|
214
217
|
text-overflow: ellipsis;
|
|
@@ -221,16 +224,16 @@
|
|
|
221
224
|
.spectrum-Picker-label.auto-width.is-placeholder {
|
|
222
225
|
padding-right: 2px;
|
|
223
226
|
}
|
|
227
|
+
.auto-width .spectrum-Menu-item {
|
|
228
|
+
padding-right: var(--spacing-xl);
|
|
229
|
+
}
|
|
224
230
|
|
|
225
231
|
/* Icon and colour alignment */
|
|
226
232
|
.spectrum-Menu-checkmark {
|
|
227
233
|
align-self: center;
|
|
228
234
|
margin-top: 0;
|
|
229
235
|
}
|
|
230
|
-
.option-
|
|
231
|
-
padding-left: 8px;
|
|
232
|
-
}
|
|
233
|
-
.option-icon {
|
|
236
|
+
.option-extra {
|
|
234
237
|
padding-right: 8px;
|
|
235
238
|
}
|
|
236
239
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
export let getOptionLabel = option => option
|
|
15
15
|
export let getOptionValue = option => option
|
|
16
16
|
export let sort = false
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
const dispatch = createEventDispatcher()
|
|
19
19
|
const onChange = e => {
|
|
20
20
|
value = e.detail
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
{sort}
|
|
34
34
|
{getOptionLabel}
|
|
35
35
|
{getOptionValue}
|
|
36
|
-
{autoWidth}
|
|
37
36
|
on:change={onChange}
|
|
38
37
|
on:click
|
|
39
38
|
/>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { View } from "svench";
|
|
3
|
+
import DetailSummary from "./DetailSummary.svelte";
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<svelte:head>
|
|
7
|
+
<link href="https://cdn.jsdelivr.net/npm/remixicon@2.5.0/fonts/remixicon.css" rel="stylesheet">
|
|
8
|
+
</svelte:head>
|
|
9
|
+
|
|
10
|
+
<style>
|
|
11
|
+
div {
|
|
12
|
+
display: flex;
|
|
13
|
+
flex-direction: column;
|
|
14
|
+
justify-content: flex-start;
|
|
15
|
+
align-items: stretch;
|
|
16
|
+
gap: var(--spacing-m);
|
|
17
|
+
width: 120px;
|
|
18
|
+
}
|
|
19
|
+
</style>
|
|
20
|
+
|
|
21
|
+
<View name="default">
|
|
22
|
+
<div>
|
|
23
|
+
<DetailSummary name="Category 1">
|
|
24
|
+
<span>1</span>
|
|
25
|
+
<span>2</span>
|
|
26
|
+
<span>3</span>
|
|
27
|
+
<span>4</span>
|
|
28
|
+
</DetailSummary>
|
|
29
|
+
<DetailSummary name="Category 2">
|
|
30
|
+
<span>1</span>
|
|
31
|
+
<span>2</span>
|
|
32
|
+
<span>3</span>
|
|
33
|
+
<span>4</span>
|
|
34
|
+
</DetailSummary>
|
|
35
|
+
</div>
|
|
36
|
+
</View>
|
|
37
|
+
|
|
38
|
+
<View name="thin">
|
|
39
|
+
<div>
|
|
40
|
+
<DetailSummary thin name="Category 1">
|
|
41
|
+
<span>1</span>
|
|
42
|
+
<span>2</span>
|
|
43
|
+
<span>3</span>
|
|
44
|
+
<span>4</span>
|
|
45
|
+
</DetailSummary>
|
|
46
|
+
<DetailSummary thin name="Category 2">
|
|
47
|
+
<span>1</span>
|
|
48
|
+
<span>2</span>
|
|
49
|
+
<span>3</span>
|
|
50
|
+
<span>4</span>
|
|
51
|
+
</DetailSummary>
|
|
52
|
+
</div>
|
|
53
|
+
</View>
|
|
@@ -18,11 +18,16 @@
|
|
|
18
18
|
export let disabled = false
|
|
19
19
|
export let active = false
|
|
20
20
|
export let color = null
|
|
21
|
+
export let square = false
|
|
22
|
+
export let hoverable = false
|
|
21
23
|
</script>
|
|
22
24
|
|
|
23
25
|
<div
|
|
26
|
+
on:click
|
|
24
27
|
class="spectrum-StatusLight spectrum-StatusLight--size{size}"
|
|
25
28
|
class:custom={!!color}
|
|
29
|
+
class:square
|
|
30
|
+
class:hoverable
|
|
26
31
|
style={`--color: ${color};`}
|
|
27
32
|
class:spectrum-StatusLight--celery={celery}
|
|
28
33
|
class:spectrum-StatusLight--yellow={yellow}
|
|
@@ -54,6 +59,7 @@
|
|
|
54
59
|
min-height: 0;
|
|
55
60
|
padding-top: 0;
|
|
56
61
|
padding-bottom: 0;
|
|
62
|
+
transition: color ease-out 130ms;
|
|
57
63
|
}
|
|
58
64
|
.spectrum-StatusLight.withText::before {
|
|
59
65
|
margin-right: 10px;
|
|
@@ -61,4 +67,14 @@
|
|
|
61
67
|
.custom::before {
|
|
62
68
|
background: var(--color) !important;
|
|
63
69
|
}
|
|
70
|
+
.square::before {
|
|
71
|
+
width: 14px;
|
|
72
|
+
height: 14px;
|
|
73
|
+
border-radius: 4px;
|
|
74
|
+
margin: 0;
|
|
75
|
+
}
|
|
76
|
+
.hoverable:hover {
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
color: var(--spectrum-global-color-gray-900);
|
|
79
|
+
}
|
|
64
80
|
</style>
|
package/src/Table/Table.svelte
CHANGED
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
export let autoSortColumns = true
|
|
38
38
|
export let compact = false
|
|
39
39
|
export let customPlaceholder = false
|
|
40
|
-
export let showHeaderBorder = true
|
|
41
40
|
export let placeholderText = "No rows found"
|
|
42
41
|
|
|
43
42
|
const dispatch = createEventDispatcher()
|
|
@@ -287,7 +286,6 @@
|
|
|
287
286
|
<div class="spectrum-Table-head">
|
|
288
287
|
{#if showEditColumn}
|
|
289
288
|
<div
|
|
290
|
-
class:noBorderHeader={!showHeaderBorder}
|
|
291
289
|
class="spectrum-Table-headCell spectrum-Table-headCell--divider spectrum-Table-headCell--edit"
|
|
292
290
|
>
|
|
293
291
|
{#if allowSelectRows}
|
|
@@ -303,7 +301,6 @@
|
|
|
303
301
|
{#each fields as field}
|
|
304
302
|
<div
|
|
305
303
|
class="spectrum-Table-headCell"
|
|
306
|
-
class:noBorderHeader={!showHeaderBorder}
|
|
307
304
|
class:spectrum-Table-headCell--alignCenter={schema[field]
|
|
308
305
|
.align === "Center"}
|
|
309
306
|
class:spectrum-Table-headCell--alignRight={schema[field].align ===
|
|
@@ -351,7 +348,6 @@
|
|
|
351
348
|
<div class="spectrum-Table-row">
|
|
352
349
|
{#if showEditColumn}
|
|
353
350
|
<div
|
|
354
|
-
class:noBorderCheckbox={!showHeaderBorder}
|
|
355
351
|
class="spectrum-Table-cell spectrum-Table-cell--divider spectrum-Table-cell--edit"
|
|
356
352
|
on:click={e => {
|
|
357
353
|
toggleSelectRow(row)
|
|
@@ -485,18 +481,6 @@
|
|
|
485
481
|
.spectrum-Table-headCell:last-of-type {
|
|
486
482
|
border-right: var(--table-border);
|
|
487
483
|
}
|
|
488
|
-
|
|
489
|
-
.noBorderHeader {
|
|
490
|
-
border-top: none !important;
|
|
491
|
-
border-right: none !important;
|
|
492
|
-
border-left: none !important;
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
.noBorderCheckbox {
|
|
496
|
-
border-top: none !important;
|
|
497
|
-
border-right: none !important;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
484
|
.spectrum-Table-headCell--alignCenter {
|
|
501
485
|
justify-content: center;
|
|
502
486
|
}
|
|
@@ -515,7 +499,7 @@
|
|
|
515
499
|
z-index: 3;
|
|
516
500
|
}
|
|
517
501
|
.spectrum-Table-headCell .title {
|
|
518
|
-
overflow:
|
|
502
|
+
overflow: hidden;
|
|
519
503
|
text-overflow: ellipsis;
|
|
520
504
|
}
|
|
521
505
|
.spectrum-Table-headCell:hover .spectrum-Table-editIcon {
|
|
@@ -578,7 +562,7 @@
|
|
|
578
562
|
gap: 4px;
|
|
579
563
|
border-bottom: 1px solid var(--spectrum-alias-border-color-mid);
|
|
580
564
|
background-color: var(--table-bg);
|
|
581
|
-
z-index:
|
|
565
|
+
z-index: 1;
|
|
582
566
|
}
|
|
583
567
|
.spectrum-Table-cell--divider {
|
|
584
568
|
padding-right: var(--cell-padding);
|
|
@@ -586,7 +570,6 @@
|
|
|
586
570
|
.spectrum-Table-cell--divider + .spectrum-Table-cell {
|
|
587
571
|
padding-left: var(--cell-padding);
|
|
588
572
|
}
|
|
589
|
-
|
|
590
573
|
.spectrum-Table-cell--edit {
|
|
591
574
|
position: sticky;
|
|
592
575
|
left: 0;
|
package/src/index.js
CHANGED
|
@@ -23,8 +23,6 @@ export { default as Icon, directions } from "./Icon/Icon.svelte"
|
|
|
23
23
|
export { default as Toggle } from "./Form/Toggle.svelte"
|
|
24
24
|
export { default as RadioGroup } from "./Form/RadioGroup.svelte"
|
|
25
25
|
export { default as Checkbox } from "./Form/Checkbox.svelte"
|
|
26
|
-
export { default as InputDropdown } from "./Form/InputDropdown.svelte"
|
|
27
|
-
export { default as PickerDropdown } from "./Form/PickerDropdown.svelte"
|
|
28
26
|
export { default as DetailSummary } from "./DetailSummary/DetailSummary.svelte"
|
|
29
27
|
export { default as Popover } from "./Popover/Popover.svelte"
|
|
30
28
|
export { default as ProgressBar } from "./ProgressBar/ProgressBar.svelte"
|
|
@@ -60,15 +58,12 @@ export { default as Pagination } from "./Pagination/Pagination.svelte"
|
|
|
60
58
|
export { default as Badge } from "./Badge/Badge.svelte"
|
|
61
59
|
export { default as StatusLight } from "./StatusLight/StatusLight.svelte"
|
|
62
60
|
export { default as ColorPicker } from "./ColorPicker/ColorPicker.svelte"
|
|
63
|
-
export { default as IconPicker } from "./IconPicker/IconPicker.svelte"
|
|
64
61
|
export { default as InlineAlert } from "./InlineAlert/InlineAlert.svelte"
|
|
65
62
|
export { default as Banner } from "./Banner/Banner.svelte"
|
|
66
63
|
export { default as BannerDisplay } from "./Banner/BannerDisplay.svelte"
|
|
67
64
|
export { default as MarkdownEditor } from "./Markdown/MarkdownEditor.svelte"
|
|
68
65
|
export { default as MarkdownViewer } from "./Markdown/MarkdownViewer.svelte"
|
|
69
66
|
export { default as RichTextField } from "./Form/RichTextField.svelte"
|
|
70
|
-
export { default as List } from "./List/List.svelte"
|
|
71
|
-
export { default as ListItem } from "./List/ListItem.svelte"
|
|
72
67
|
export { default as IconSideNav } from "./IconSideNav/IconSideNav.svelte"
|
|
73
68
|
export { default as IconSideNavItem } from "./IconSideNav/IconSideNavItem.svelte"
|
|
74
69
|
export { default as Slider } from "./Form/Slider.svelte"
|
|
@@ -76,7 +71,6 @@ export { default as Slider } from "./Form/Slider.svelte"
|
|
|
76
71
|
// Renderers
|
|
77
72
|
export { default as BoldRenderer } from "./Table/BoldRenderer.svelte"
|
|
78
73
|
export { default as CodeRenderer } from "./Table/CodeRenderer.svelte"
|
|
79
|
-
export { default as InternalRenderer } from "./Table/InternalRenderer.svelte"
|
|
80
74
|
|
|
81
75
|
// Typography
|
|
82
76
|
export { default as Body } from "./Typography/Body.svelte"
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
import "@spectrum-css/inputgroup/dist/index-vars.css"
|
|
3
|
-
import "@spectrum-css/popover/dist/index-vars.css"
|
|
4
|
-
import "@spectrum-css/menu/dist/index-vars.css"
|
|
5
|
-
import { fly } from "svelte/transition"
|
|
6
|
-
import { createEventDispatcher } from "svelte"
|
|
7
|
-
import clickOutside from "../../Actions/click_outside"
|
|
8
|
-
|
|
9
|
-
export let inputValue
|
|
10
|
-
export let dropdownValue
|
|
11
|
-
export let id = null
|
|
12
|
-
export let inputType = "text"
|
|
13
|
-
export let placeholder = "Choose an option or type"
|
|
14
|
-
export let disabled = false
|
|
15
|
-
export let readonly = false
|
|
16
|
-
export let updateOnChange = true
|
|
17
|
-
export let error = null
|
|
18
|
-
export let options = []
|
|
19
|
-
export let getOptionLabel = option => extractProperty(option, "label")
|
|
20
|
-
export let getOptionValue = option => extractProperty(option, "value")
|
|
21
|
-
|
|
22
|
-
export let isOptionSelected = () => false
|
|
23
|
-
|
|
24
|
-
const dispatch = createEventDispatcher()
|
|
25
|
-
let open = false
|
|
26
|
-
let focus = false
|
|
27
|
-
|
|
28
|
-
$: fieldText = getFieldText(dropdownValue, options, placeholder)
|
|
29
|
-
|
|
30
|
-
const getFieldText = (dropdownValue, options, placeholder) => {
|
|
31
|
-
// Always use placeholder if no value
|
|
32
|
-
if (dropdownValue == null || dropdownValue === "") {
|
|
33
|
-
return placeholder || "Choose an option or type"
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Wait for options to load if there is a value but no options
|
|
37
|
-
if (!options?.length) {
|
|
38
|
-
return ""
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Render the label if the selected option is found, otherwise raw value
|
|
42
|
-
const selected = options.find(
|
|
43
|
-
option => getOptionValue(option) === dropdownValue
|
|
44
|
-
)
|
|
45
|
-
return selected ? getOptionLabel(selected) : dropdownValue
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const updateValue = newValue => {
|
|
49
|
-
if (readonly) {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
dispatch("change", newValue)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const onFocus = () => {
|
|
56
|
-
if (readonly) {
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
focus = true
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const onBlur = event => {
|
|
63
|
-
if (readonly) {
|
|
64
|
-
return
|
|
65
|
-
}
|
|
66
|
-
focus = false
|
|
67
|
-
updateValue(event.target.value)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const onInput = event => {
|
|
71
|
-
if (readonly || !updateOnChange) {
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
updateValue(event.target.value)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const updateValueOnEnter = event => {
|
|
78
|
-
if (readonly) {
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
if (event.key === "Enter") {
|
|
82
|
-
updateValue(event.target.value)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const onClick = () => {
|
|
87
|
-
dispatch("click")
|
|
88
|
-
if (readonly) {
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
open = true
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const onPick = newValue => {
|
|
95
|
-
dispatch("pick", newValue)
|
|
96
|
-
open = false
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const extractProperty = (value, property) => {
|
|
100
|
-
if (value && typeof value === "object") {
|
|
101
|
-
return value[property]
|
|
102
|
-
}
|
|
103
|
-
return value
|
|
104
|
-
}
|
|
105
|
-
</script>
|
|
106
|
-
|
|
107
|
-
<div
|
|
108
|
-
class="spectrum-InputGroup"
|
|
109
|
-
class:is-invalid={!!error}
|
|
110
|
-
class:is-disabled={disabled}
|
|
111
|
-
>
|
|
112
|
-
<div
|
|
113
|
-
class="spectrum-Textfield spectrum-InputGroup-textfield"
|
|
114
|
-
class:is-invalid={!!error}
|
|
115
|
-
class:is-disabled={disabled}
|
|
116
|
-
class:is-focused={focus}
|
|
117
|
-
>
|
|
118
|
-
<input
|
|
119
|
-
{id}
|
|
120
|
-
on:click
|
|
121
|
-
on:blur
|
|
122
|
-
on:focus
|
|
123
|
-
on:input
|
|
124
|
-
on:keyup
|
|
125
|
-
on:blur={onBlur}
|
|
126
|
-
on:focus={onFocus}
|
|
127
|
-
on:input={onInput}
|
|
128
|
-
on:keyup={updateValueOnEnter}
|
|
129
|
-
value={inputValue || ""}
|
|
130
|
-
placeholder={placeholder || ""}
|
|
131
|
-
{disabled}
|
|
132
|
-
{readonly}
|
|
133
|
-
{inputType}
|
|
134
|
-
class="spectrum-Textfield-input spectrum-InputGroup-input"
|
|
135
|
-
/>
|
|
136
|
-
</div>
|
|
137
|
-
<div style="width: 30%">
|
|
138
|
-
<button
|
|
139
|
-
{id}
|
|
140
|
-
class="spectrum-Picker spectrum-Picker--sizeM override-borders"
|
|
141
|
-
{disabled}
|
|
142
|
-
class:is-open={open}
|
|
143
|
-
aria-haspopup="listbox"
|
|
144
|
-
on:mousedown={onClick}
|
|
145
|
-
>
|
|
146
|
-
<span class="spectrum-Picker-label">
|
|
147
|
-
<div>
|
|
148
|
-
{fieldText}
|
|
149
|
-
</div></span
|
|
150
|
-
>
|
|
151
|
-
<svg
|
|
152
|
-
class="spectrum-Icon spectrum-UIIcon-ChevronDown100 spectrum-Picker-menuIcon"
|
|
153
|
-
focusable="false"
|
|
154
|
-
aria-hidden="true"
|
|
155
|
-
>
|
|
156
|
-
<use xlink:href="#spectrum-css-icon-Chevron100" />
|
|
157
|
-
</svg>
|
|
158
|
-
</button>
|
|
159
|
-
{#if open}
|
|
160
|
-
<div
|
|
161
|
-
use:clickOutside={() => (open = false)}
|
|
162
|
-
transition:fly|local={{ y: -20, duration: 200 }}
|
|
163
|
-
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
|
164
|
-
>
|
|
165
|
-
<ul class="spectrum-Menu" role="listbox">
|
|
166
|
-
{#each options as option, idx}
|
|
167
|
-
<li
|
|
168
|
-
class="spectrum-Menu-item"
|
|
169
|
-
class:is-selected={isOptionSelected(getOptionValue(option, idx))}
|
|
170
|
-
role="option"
|
|
171
|
-
aria-selected="true"
|
|
172
|
-
tabindex="0"
|
|
173
|
-
on:click={() => onPick(getOptionValue(option, idx))}
|
|
174
|
-
>
|
|
175
|
-
<span class="spectrum-Menu-itemLabel">
|
|
176
|
-
{getOptionLabel(option, idx)}
|
|
177
|
-
</span>
|
|
178
|
-
<svg
|
|
179
|
-
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
|
|
180
|
-
focusable="false"
|
|
181
|
-
aria-hidden="true"
|
|
182
|
-
>
|
|
183
|
-
<use xlink:href="#spectrum-css-icon-Checkmark100" />
|
|
184
|
-
</svg>
|
|
185
|
-
</li>
|
|
186
|
-
{/each}
|
|
187
|
-
</ul>
|
|
188
|
-
</div>
|
|
189
|
-
{/if}
|
|
190
|
-
</div>
|
|
191
|
-
</div>
|
|
192
|
-
|
|
193
|
-
<style>
|
|
194
|
-
.spectrum-InputGroup {
|
|
195
|
-
min-width: 0;
|
|
196
|
-
width: 100%;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
.spectrum-InputGroup-input {
|
|
200
|
-
border-right-width: 1px;
|
|
201
|
-
}
|
|
202
|
-
.spectrum-Textfield {
|
|
203
|
-
width: 100%;
|
|
204
|
-
}
|
|
205
|
-
.spectrum-Textfield-input {
|
|
206
|
-
width: 0;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
.override-borders {
|
|
210
|
-
border-top-left-radius: 0px;
|
|
211
|
-
border-bottom-left-radius: 0px;
|
|
212
|
-
}
|
|
213
|
-
.spectrum-Popover {
|
|
214
|
-
max-height: 240px;
|
|
215
|
-
z-index: 999;
|
|
216
|
-
top: 100%;
|
|
217
|
-
}
|
|
218
|
-
</style>
|