@budibase/bbui 1.1.32 → 1.1.33-alpha.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/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.32",
4
+ "version": "1.1.33-alpha.0",
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.32",
41
+ "@budibase/string-templates": "1.1.33-alpha.0",
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": "900d5de0723c1b7acf218446507d52755fdf7d83"
88
+ "gitHead": "b57c4e5e740dafe0a44c035602d121eff65c70e2"
89
89
  }
@@ -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-300"],
7
+ ["M", "--spectrum-alias-avatar-size-400"],
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,6 +13,19 @@
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
+ }
16
29
  </script>
17
30
 
18
31
  {#if url}
@@ -25,10 +38,11 @@
25
38
  />
26
39
  {:else}
27
40
  <div
41
+ class="spectrum-Avatar"
28
42
  class:is-disabled={disabled}
29
43
  style="width: var({sizes.get(size)}); height: var({sizes.get(
30
44
  size
31
- )}); font-size: calc(var({sizes.get(size)}) / 2)"
45
+ )}); font-size: calc(var({sizes.get(size)}) / 2); background: {color};"
32
46
  >
33
47
  {initials || ""}
34
48
  </div>
@@ -40,7 +54,6 @@
40
54
  display: grid;
41
55
  place-items: center;
42
56
  font-weight: 600;
43
- background: #3aab87;
44
57
  border-radius: 50%;
45
58
  overflow: hidden;
46
59
  user-select: none;
@@ -0,0 +1,228 @@
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
+ {#if error}
119
+ <svg
120
+ class="spectrum-Icon spectrum-Icon--sizeM spectrum-Textfield-validationIcon"
121
+ focusable="false"
122
+ aria-hidden="true"
123
+ >
124
+ <use xlink:href="#spectrum-icon-18-Alert" />
125
+ </svg>
126
+ {/if}
127
+
128
+ <input
129
+ {id}
130
+ on:click
131
+ on:blur
132
+ on:focus
133
+ on:input
134
+ on:keyup
135
+ on:blur={onBlur}
136
+ on:focus={onFocus}
137
+ on:input={onInput}
138
+ on:keyup={updateValueOnEnter}
139
+ value={inputValue || ""}
140
+ placeholder={placeholder || ""}
141
+ {disabled}
142
+ {readonly}
143
+ {inputType}
144
+ class="spectrum-Textfield-input spectrum-InputGroup-input"
145
+ />
146
+ </div>
147
+ <div style="width: 30%">
148
+ <button
149
+ {id}
150
+ class="spectrum-Picker spectrum-Picker--sizeM override-borders"
151
+ {disabled}
152
+ class:is-open={open}
153
+ aria-haspopup="listbox"
154
+ on:mousedown={onClick}
155
+ >
156
+ <span class="spectrum-Picker-label">
157
+ <div>
158
+ {fieldText}
159
+ </div></span
160
+ >
161
+ <svg
162
+ class="spectrum-Icon spectrum-UIIcon-ChevronDown100 spectrum-Picker-menuIcon"
163
+ focusable="false"
164
+ aria-hidden="true"
165
+ >
166
+ <use xlink:href="#spectrum-css-icon-Chevron100" />
167
+ </svg>
168
+ </button>
169
+ {#if open}
170
+ <div
171
+ use:clickOutside={() => (open = false)}
172
+ transition:fly|local={{ y: -20, duration: 200 }}
173
+ class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
174
+ >
175
+ <ul class="spectrum-Menu" role="listbox">
176
+ {#each options as option, idx}
177
+ <li
178
+ class="spectrum-Menu-item"
179
+ class:is-selected={isOptionSelected(getOptionValue(option, idx))}
180
+ role="option"
181
+ aria-selected="true"
182
+ tabindex="0"
183
+ on:click={() => onPick(getOptionValue(option, idx))}
184
+ >
185
+ <span class="spectrum-Menu-itemLabel">
186
+ {getOptionLabel(option, idx)}
187
+ </span>
188
+ <svg
189
+ class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
190
+ focusable="false"
191
+ aria-hidden="true"
192
+ >
193
+ <use xlink:href="#spectrum-css-icon-Checkmark100" />
194
+ </svg>
195
+ </li>
196
+ {/each}
197
+ </ul>
198
+ </div>
199
+ {/if}
200
+ </div>
201
+ </div>
202
+
203
+ <style>
204
+ .spectrum-InputGroup {
205
+ min-width: 0;
206
+ width: 100%;
207
+ }
208
+
209
+ .spectrum-InputGroup-input {
210
+ border-right-width: 1px;
211
+ }
212
+ .spectrum-Textfield {
213
+ width: 100%;
214
+ }
215
+ .spectrum-Textfield-input {
216
+ width: 0;
217
+ }
218
+
219
+ .override-borders {
220
+ border-top-left-radius: 0px;
221
+ border-bottom-left-radius: 0px;
222
+ }
223
+ .spectrum-Popover {
224
+ max-height: 240px;
225
+ z-index: 999;
226
+ top: 100%;
227
+ }
228
+ </style>
@@ -13,6 +13,7 @@
13
13
  export let readonly = false
14
14
  export let autocomplete = false
15
15
  export let sort = false
16
+ export let autoWidth = false
16
17
 
17
18
  const dispatch = createEventDispatcher()
18
19
  $: selectedLookupMap = getSelectedLookupMap(value)
@@ -85,4 +86,5 @@
85
86
  {getOptionValue}
86
87
  onSelectOption={toggleOption}
87
88
  {sort}
89
+ {autoWidth}
88
90
  />