@budibase/bbui 2.2.12-alpha.7 → 2.2.12-alpha.70
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 +3 -3
- package/dist/bbui.es.js.map +1 -1
- package/package.json +4 -3
- package/src/Accordion/Accordion.svelte +58 -0
- package/src/ActionButton/ActionButton.svelte +2 -3
- package/src/ActionMenu/ActionMenu.svelte +1 -2
- package/src/Actions/click_outside.js +28 -9
- package/src/Actions/position_dropdown.js +85 -53
- package/src/Avatar/Avatar.svelte +1 -0
- package/src/Button/Button.svelte +8 -4
- package/src/Drawer/DrawerContent.svelte +0 -1
- package/src/FancyForm/FancyButton.svelte +30 -0
- package/src/FancyForm/FancyButtonRadio.svelte +70 -0
- package/src/FancyForm/FancyCheckbox.svelte +53 -0
- package/src/FancyForm/FancyField.svelte +126 -0
- package/src/FancyForm/FancyFieldLabel.svelte +25 -0
- package/src/FancyForm/FancyForm.svelte +40 -0
- package/src/FancyForm/FancyInput.svelte +77 -0
- package/src/FancyForm/FancySelect.svelte +147 -0
- package/src/FancyForm/index.js +6 -0
- package/src/Form/Core/DatePicker.svelte +1 -1
- package/src/Form/Core/EnvDropdown.svelte +276 -0
- package/src/Form/Core/Picker.svelte +141 -124
- package/src/Form/Core/Select.svelte +3 -0
- package/src/Form/Core/Switch.svelte +0 -2
- package/src/Form/Core/TextField.svelte +0 -6
- package/src/Form/EnvDropdown.svelte +50 -0
- package/src/Form/Input.svelte +0 -2
- package/src/Form/InputDropdown.svelte +0 -2
- package/src/Form/PickerDropdown.svelte +0 -2
- package/src/Form/Toggle.svelte +1 -2
- package/src/Icon/IconAvatar.svelte +3 -0
- package/src/InlineAlert/InlineAlert.svelte +1 -0
- package/src/Label/Label.svelte +1 -0
- package/src/Layout/Page.svelte +82 -13
- package/src/Link/Link.svelte +4 -1
- package/src/List/ListItem.svelte +6 -3
- package/src/Menu/Item.svelte +0 -2
- package/src/Modal/CustomContent.svelte +0 -1
- package/src/Modal/Modal.svench +0 -1
- package/src/Modal/ModalContent.svelte +4 -4
- package/src/Modal/QuizModal.svelte +0 -1
- package/src/Popover/Popover.svelte +35 -31
- package/src/Popover/Popover.svench +0 -1
- package/src/SideNavigation/Item.svelte +0 -2
- package/src/Table/StringRenderer.svelte +9 -1
- package/src/Table/Table.svelte +30 -19
- package/src/Tabs/Tab.svelte +5 -5
- package/src/Tags/Tag.svelte +1 -1
- package/src/Tags/Tags.svelte +10 -0
- package/src/Typography/Heading.svelte +6 -0
- package/src/bbui.css +7 -3
- package/src/context.js +1 -0
- package/src/index.js +5 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from "../Icon/Icon.svelte"
|
|
3
|
+
import { getContext, onMount } from "svelte"
|
|
4
|
+
import { slide } from "svelte/transition"
|
|
5
|
+
|
|
6
|
+
export let disabled = false
|
|
7
|
+
export let error = null
|
|
8
|
+
export let focused = false
|
|
9
|
+
export let clickable = false
|
|
10
|
+
export let validate
|
|
11
|
+
export let value
|
|
12
|
+
export let ref
|
|
13
|
+
export let autoHeight
|
|
14
|
+
|
|
15
|
+
const formContext = getContext("fancy-form")
|
|
16
|
+
const id = Math.random()
|
|
17
|
+
const API = {
|
|
18
|
+
validate: () => {
|
|
19
|
+
if (validate) {
|
|
20
|
+
error = validate(value)
|
|
21
|
+
}
|
|
22
|
+
return !error
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onMount(() => {
|
|
27
|
+
if (formContext) {
|
|
28
|
+
formContext.registerField(id, API)
|
|
29
|
+
}
|
|
30
|
+
return () => {
|
|
31
|
+
if (formContext) {
|
|
32
|
+
formContext.unregisterField(id)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
bind:this={ref}
|
|
40
|
+
class="fancy-field"
|
|
41
|
+
class:error
|
|
42
|
+
class:disabled
|
|
43
|
+
class:focused
|
|
44
|
+
class:clickable
|
|
45
|
+
class:auto-height={autoHeight}
|
|
46
|
+
>
|
|
47
|
+
<div class="content" on:click>
|
|
48
|
+
<div class="field">
|
|
49
|
+
<slot />
|
|
50
|
+
</div>
|
|
51
|
+
{#if error}
|
|
52
|
+
<div class="error-icon">
|
|
53
|
+
<Icon name="Alert" />
|
|
54
|
+
</div>
|
|
55
|
+
{/if}
|
|
56
|
+
</div>
|
|
57
|
+
{#if error}
|
|
58
|
+
<div transition:slide|local={{ duration: 130 }} class="error-message">
|
|
59
|
+
{error}
|
|
60
|
+
</div>
|
|
61
|
+
{/if}
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<style>
|
|
65
|
+
.fancy-field {
|
|
66
|
+
max-width: 400px;
|
|
67
|
+
background: var(--spectrum-global-color-gray-75);
|
|
68
|
+
border: 1px solid var(--spectrum-global-color-gray-300);
|
|
69
|
+
border-radius: 4px;
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
transition: border-color 130ms ease-out, background 130ms ease-out,
|
|
72
|
+
background 130ms ease-out;
|
|
73
|
+
color: var(--spectrum-global-color-gray-800);
|
|
74
|
+
}
|
|
75
|
+
.fancy-field:hover {
|
|
76
|
+
border-color: var(--spectrum-global-color-gray-400);
|
|
77
|
+
}
|
|
78
|
+
.fancy-field.clickable:hover {
|
|
79
|
+
background: var(--spectrum-global-color-gray-200);
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
}
|
|
82
|
+
.fancy-field.focused {
|
|
83
|
+
border-color: var(--spectrum-global-color-blue-400);
|
|
84
|
+
}
|
|
85
|
+
.fancy-field.error {
|
|
86
|
+
border-color: var(--spectrum-global-color-red-400);
|
|
87
|
+
}
|
|
88
|
+
.fancy-field.disabled {
|
|
89
|
+
background: var(--spectrum-global-color-gray-200);
|
|
90
|
+
color: var(--spectrum-global-color-gray-400);
|
|
91
|
+
border: 1px solid var(--spectrum-global-color-gray-300);
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
}
|
|
94
|
+
.content {
|
|
95
|
+
position: relative;
|
|
96
|
+
height: 64px;
|
|
97
|
+
padding: 0 16px;
|
|
98
|
+
}
|
|
99
|
+
.fancy-field.auto-height .content {
|
|
100
|
+
height: auto;
|
|
101
|
+
}
|
|
102
|
+
.content,
|
|
103
|
+
.field {
|
|
104
|
+
display: flex;
|
|
105
|
+
flex-direction: row;
|
|
106
|
+
justify-content: flex-start;
|
|
107
|
+
align-items: center;
|
|
108
|
+
gap: 16px;
|
|
109
|
+
}
|
|
110
|
+
.field {
|
|
111
|
+
flex: 1 1 auto;
|
|
112
|
+
}
|
|
113
|
+
.error-message {
|
|
114
|
+
background: var(--spectrum-global-color-red-400);
|
|
115
|
+
color: white;
|
|
116
|
+
font-size: 14px;
|
|
117
|
+
padding: 6px 16px;
|
|
118
|
+
font-weight: 500;
|
|
119
|
+
}
|
|
120
|
+
.error-icon {
|
|
121
|
+
flex: 0 0 auto;
|
|
122
|
+
}
|
|
123
|
+
.error-icon :global(.spectrum-Icon) {
|
|
124
|
+
fill: var(--spectrum-global-color-red-400);
|
|
125
|
+
}
|
|
126
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let placeholder = true
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<div class:placeholder>
|
|
6
|
+
<slot />
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
div {
|
|
11
|
+
font-size: 14px;
|
|
12
|
+
line-height: 15px;
|
|
13
|
+
font-weight: 500;
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 10px;
|
|
16
|
+
color: var(--spectrum-global-color-gray-600);
|
|
17
|
+
transition: font-size 130ms ease-out, top 130ms ease-out,
|
|
18
|
+
transform 130ms ease-out;
|
|
19
|
+
}
|
|
20
|
+
div.placeholder {
|
|
21
|
+
top: 50%;
|
|
22
|
+
font-size: 15px;
|
|
23
|
+
transform: translateY(-50%);
|
|
24
|
+
}
|
|
25
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { setContext } from "svelte"
|
|
3
|
+
|
|
4
|
+
let fields = {}
|
|
5
|
+
|
|
6
|
+
setContext("fancy-form", {
|
|
7
|
+
registerField: (id, api) => {
|
|
8
|
+
fields = { ...fields, [id]: api }
|
|
9
|
+
},
|
|
10
|
+
unregisterField: id => {
|
|
11
|
+
delete fields[id]
|
|
12
|
+
fields = fields
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
export const validate = () => {
|
|
17
|
+
let valid = true
|
|
18
|
+
Object.values(fields).forEach(api => {
|
|
19
|
+
if (!api.validate()) {
|
|
20
|
+
valid = false
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
return valid
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<div class="fancy-form">
|
|
28
|
+
<slot />
|
|
29
|
+
</div>
|
|
30
|
+
|
|
31
|
+
<style>
|
|
32
|
+
.fancy-form :global(.fancy-field:not(:first-of-type)) {
|
|
33
|
+
border-top-left-radius: 0;
|
|
34
|
+
border-top-right-radius: 0;
|
|
35
|
+
}
|
|
36
|
+
.fancy-form :global(.fancy-field:not(:last-of-type)) {
|
|
37
|
+
border-bottom-left-radius: 0;
|
|
38
|
+
border-bottom-right-radius: 0;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher } from "svelte"
|
|
3
|
+
import FancyField from "./FancyField.svelte"
|
|
4
|
+
import FancyFieldLabel from "./FancyFieldLabel.svelte"
|
|
5
|
+
import { fade } from "svelte/transition"
|
|
6
|
+
|
|
7
|
+
export let label
|
|
8
|
+
export let value
|
|
9
|
+
export let type = "text"
|
|
10
|
+
export let disabled = false
|
|
11
|
+
export let error = null
|
|
12
|
+
export let validate = null
|
|
13
|
+
export let suffix = null
|
|
14
|
+
|
|
15
|
+
const dispatch = createEventDispatcher()
|
|
16
|
+
|
|
17
|
+
let focused = false
|
|
18
|
+
$: placeholder = !focused && !value
|
|
19
|
+
|
|
20
|
+
const onChange = e => {
|
|
21
|
+
const newValue = e.target.value
|
|
22
|
+
dispatch("change", newValue)
|
|
23
|
+
value = newValue
|
|
24
|
+
if (validate) {
|
|
25
|
+
error = validate(newValue)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<FancyField {error} {value} {validate} {disabled} {focused}>
|
|
31
|
+
{#if label}
|
|
32
|
+
<FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
|
|
33
|
+
{/if}
|
|
34
|
+
<input
|
|
35
|
+
{disabled}
|
|
36
|
+
value={value || ""}
|
|
37
|
+
type={type || "text"}
|
|
38
|
+
on:input={onChange}
|
|
39
|
+
on:focus={() => (focused = true)}
|
|
40
|
+
on:blur={() => (focused = false)}
|
|
41
|
+
class:placeholder
|
|
42
|
+
/>
|
|
43
|
+
{#if suffix && !placeholder}
|
|
44
|
+
<div in:fade|local={{ duration: 130 }} class="suffix">{suffix}</div>
|
|
45
|
+
{/if}
|
|
46
|
+
</FancyField>
|
|
47
|
+
|
|
48
|
+
<style>
|
|
49
|
+
input {
|
|
50
|
+
width: 100%;
|
|
51
|
+
transition: transform 130ms ease-out;
|
|
52
|
+
transform: translateY(9px);
|
|
53
|
+
background: transparent;
|
|
54
|
+
font-size: 15px;
|
|
55
|
+
line-height: 17px;
|
|
56
|
+
font-family: var(--font-sans);
|
|
57
|
+
color: var(--spectrum-global-color-gray-900);
|
|
58
|
+
outline: none;
|
|
59
|
+
border: none;
|
|
60
|
+
padding: 0;
|
|
61
|
+
margin: 0;
|
|
62
|
+
}
|
|
63
|
+
input.placeholder {
|
|
64
|
+
transform: translateY(0);
|
|
65
|
+
position: absolute;
|
|
66
|
+
top: 0;
|
|
67
|
+
left: 0;
|
|
68
|
+
height: 100%;
|
|
69
|
+
}
|
|
70
|
+
.suffix {
|
|
71
|
+
color: var(--spectrum-global-color-gray-600);
|
|
72
|
+
transform: translateY(9px);
|
|
73
|
+
font-size: 15px;
|
|
74
|
+
line-height: 17px;
|
|
75
|
+
font-family: var(--font-sans);
|
|
76
|
+
}
|
|
77
|
+
</style>
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher } from "svelte"
|
|
3
|
+
import FancyField from "./FancyField.svelte"
|
|
4
|
+
import Icon from "../Icon/Icon.svelte"
|
|
5
|
+
import Popover from "../Popover/Popover.svelte"
|
|
6
|
+
import FancyFieldLabel from "./FancyFieldLabel.svelte"
|
|
7
|
+
|
|
8
|
+
export let label
|
|
9
|
+
export let value
|
|
10
|
+
export let disabled = false
|
|
11
|
+
export let error = null
|
|
12
|
+
export let validate = null
|
|
13
|
+
export let options = []
|
|
14
|
+
export let getOptionLabel = option => extractProperty(option, "label")
|
|
15
|
+
export let getOptionValue = option => extractProperty(option, "value")
|
|
16
|
+
|
|
17
|
+
const dispatch = createEventDispatcher()
|
|
18
|
+
|
|
19
|
+
let open = false
|
|
20
|
+
let popover
|
|
21
|
+
let wrapper
|
|
22
|
+
|
|
23
|
+
$: placeholder = !value
|
|
24
|
+
$: selectedLabel = getSelectedLabel(value)
|
|
25
|
+
|
|
26
|
+
const extractProperty = (value, property) => {
|
|
27
|
+
if (value && typeof value === "object") {
|
|
28
|
+
return value[property]
|
|
29
|
+
}
|
|
30
|
+
return value
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const onChange = newValue => {
|
|
34
|
+
dispatch("change", newValue)
|
|
35
|
+
value = newValue
|
|
36
|
+
if (validate) {
|
|
37
|
+
error = validate(newValue)
|
|
38
|
+
}
|
|
39
|
+
open = false
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const getSelectedLabel = value => {
|
|
43
|
+
if (!value || !options?.length) {
|
|
44
|
+
return ""
|
|
45
|
+
}
|
|
46
|
+
const selectedOption = options.find(x => getOptionValue(x) === value)
|
|
47
|
+
if (!selectedOption) {
|
|
48
|
+
return value
|
|
49
|
+
}
|
|
50
|
+
return getOptionLabel(selectedOption)
|
|
51
|
+
}
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<FancyField
|
|
55
|
+
bind:ref={wrapper}
|
|
56
|
+
{error}
|
|
57
|
+
{value}
|
|
58
|
+
{validate}
|
|
59
|
+
{disabled}
|
|
60
|
+
clickable
|
|
61
|
+
on:click={() => (open = true)}
|
|
62
|
+
>
|
|
63
|
+
{#if label}
|
|
64
|
+
<FancyFieldLabel {placeholder}>{label}</FancyFieldLabel>
|
|
65
|
+
{/if}
|
|
66
|
+
|
|
67
|
+
<div class="value" class:placeholder>
|
|
68
|
+
{selectedLabel || ""}
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<div class="arrow">
|
|
72
|
+
<Icon name="ChevronDown" />
|
|
73
|
+
</div>
|
|
74
|
+
</FancyField>
|
|
75
|
+
|
|
76
|
+
<Popover
|
|
77
|
+
anchor={wrapper}
|
|
78
|
+
align="left"
|
|
79
|
+
portalTarget={document.documentElement}
|
|
80
|
+
bind:this={popover}
|
|
81
|
+
{open}
|
|
82
|
+
on:close={() => (open = false)}
|
|
83
|
+
useAnchorWidth={true}
|
|
84
|
+
maxWidth={null}
|
|
85
|
+
>
|
|
86
|
+
<div class="popover-content">
|
|
87
|
+
{#if options.length}
|
|
88
|
+
{#each options as option, idx}
|
|
89
|
+
<div
|
|
90
|
+
class="popover-option"
|
|
91
|
+
tabindex="0"
|
|
92
|
+
on:click={() => onChange(getOptionValue(option, idx))}
|
|
93
|
+
>
|
|
94
|
+
<span class="option-text">
|
|
95
|
+
{getOptionLabel(option, idx)}
|
|
96
|
+
</span>
|
|
97
|
+
{#if value === getOptionValue(option, idx)}
|
|
98
|
+
<Icon name="Checkmark" />
|
|
99
|
+
{/if}
|
|
100
|
+
</div>
|
|
101
|
+
{/each}
|
|
102
|
+
{/if}
|
|
103
|
+
</div>
|
|
104
|
+
</Popover>
|
|
105
|
+
|
|
106
|
+
<style>
|
|
107
|
+
.value {
|
|
108
|
+
display: block;
|
|
109
|
+
flex: 1 1 auto;
|
|
110
|
+
font-size: 15px;
|
|
111
|
+
line-height: 17px;
|
|
112
|
+
color: var(--spectrum-global-color-gray-900);
|
|
113
|
+
transition: transform 130ms ease-out, opacity 130ms ease-out;
|
|
114
|
+
opacity: 1;
|
|
115
|
+
white-space: nowrap;
|
|
116
|
+
text-overflow: ellipsis;
|
|
117
|
+
overflow: hidden;
|
|
118
|
+
width: 0;
|
|
119
|
+
transform: translateY(9px);
|
|
120
|
+
}
|
|
121
|
+
.value.placeholder {
|
|
122
|
+
transform: translateY(0);
|
|
123
|
+
opacity: 0;
|
|
124
|
+
pointer-events: none;
|
|
125
|
+
margin-top: 0;
|
|
126
|
+
}
|
|
127
|
+
.popover-content {
|
|
128
|
+
display: flex;
|
|
129
|
+
flex-direction: column;
|
|
130
|
+
justify-content: flex-start;
|
|
131
|
+
align-items: stretch;
|
|
132
|
+
padding: 7px 0;
|
|
133
|
+
}
|
|
134
|
+
.popover-option {
|
|
135
|
+
display: flex;
|
|
136
|
+
flex-direction: row;
|
|
137
|
+
justify-content: space-between;
|
|
138
|
+
align-items: center;
|
|
139
|
+
padding: 7px 16px;
|
|
140
|
+
transition: background 130ms ease-out;
|
|
141
|
+
font-size: 15px;
|
|
142
|
+
}
|
|
143
|
+
.popover-option:hover {
|
|
144
|
+
background: var(--spectrum-global-color-gray-200);
|
|
145
|
+
cursor: pointer;
|
|
146
|
+
}
|
|
147
|
+
</style>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as FancyInput } from "./FancyInput.svelte"
|
|
2
|
+
export { default as FancyCheckbox } from "./FancyCheckbox.svelte"
|
|
3
|
+
export { default as FancySelect } from "./FancySelect.svelte"
|
|
4
|
+
export { default as FancyButton } from "./FancyButton.svelte"
|
|
5
|
+
export { default as FancyForm } from "./FancyForm.svelte"
|
|
6
|
+
export { default as FancyButtonRadio } from "./FancyButtonRadio.svelte"
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import "@spectrum-css/textfield/dist/index-vars.css"
|
|
3
|
+
import { createEventDispatcher, onMount } from "svelte"
|
|
4
|
+
import clickOutside from "../../Actions/click_outside"
|
|
5
|
+
import Divider from "../../Divider/Divider.svelte"
|
|
6
|
+
|
|
7
|
+
export let value = null
|
|
8
|
+
export let placeholder = null
|
|
9
|
+
export let type = "text"
|
|
10
|
+
export let disabled = false
|
|
11
|
+
export let id = null
|
|
12
|
+
export let readonly = false
|
|
13
|
+
export let updateOnChange = true
|
|
14
|
+
export let align
|
|
15
|
+
export let autofocus = false
|
|
16
|
+
export let variables
|
|
17
|
+
export let showModal
|
|
18
|
+
export let environmentVariablesEnabled
|
|
19
|
+
export let handleUpgradePanel
|
|
20
|
+
const dispatch = createEventDispatcher()
|
|
21
|
+
|
|
22
|
+
let field
|
|
23
|
+
let focus = false
|
|
24
|
+
let iconFocused = false
|
|
25
|
+
let open = false
|
|
26
|
+
|
|
27
|
+
//eslint-disable-next-line
|
|
28
|
+
const STRIP_NAME_REGEX = /(?<=\.)(.*?)(?=\ })/g
|
|
29
|
+
|
|
30
|
+
// Strips the name out of the value which is {{ env.Variable }} resulting in an array like ["Variable"]
|
|
31
|
+
$: hbsValue = String(value)?.match(STRIP_NAME_REGEX) || []
|
|
32
|
+
|
|
33
|
+
const updateValue = newValue => {
|
|
34
|
+
if (readonly) {
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
if (type === "number") {
|
|
38
|
+
const float = parseFloat(newValue)
|
|
39
|
+
newValue = isNaN(float) ? null : float
|
|
40
|
+
}
|
|
41
|
+
dispatch("change", newValue)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const onFocus = () => {
|
|
45
|
+
if (readonly) {
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
focus = true
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const onBlur = event => {
|
|
52
|
+
if (readonly) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
focus = false
|
|
56
|
+
updateValue(event.target.value)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const onInput = event => {
|
|
60
|
+
if (readonly || !updateOnChange) {
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
updateValue(event.target.value)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const handleOutsideClick = event => {
|
|
67
|
+
if (open) {
|
|
68
|
+
event.stopPropagation()
|
|
69
|
+
open = false
|
|
70
|
+
focus = false
|
|
71
|
+
iconFocused = false
|
|
72
|
+
dispatch("closed")
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const handleVarSelect = variable => {
|
|
77
|
+
open = false
|
|
78
|
+
focus = false
|
|
79
|
+
iconFocused = false
|
|
80
|
+
updateValue(`{{ env.${variable} }}`)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
onMount(() => {
|
|
84
|
+
focus = autofocus
|
|
85
|
+
if (focus) field.focus()
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
function removeVariable() {
|
|
89
|
+
updateValue("")
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function openPopover() {
|
|
93
|
+
open = true
|
|
94
|
+
focus = true
|
|
95
|
+
iconFocused = true
|
|
96
|
+
}
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<div class="spectrum-InputGroup">
|
|
100
|
+
<div
|
|
101
|
+
class:is-disabled={disabled || hbsValue.length}
|
|
102
|
+
class:is-focused={focus}
|
|
103
|
+
class="spectrum-Textfield"
|
|
104
|
+
>
|
|
105
|
+
<svg
|
|
106
|
+
class:close-color={hbsValue.length}
|
|
107
|
+
class:focused={iconFocused}
|
|
108
|
+
class="hoverable icon-position spectrum-Icon spectrum-Icon--sizeS spectrum-Textfield-validationIcon"
|
|
109
|
+
focusable="false"
|
|
110
|
+
aria-hidden="true"
|
|
111
|
+
on:click={() => {
|
|
112
|
+
hbsValue.length ? removeVariable() : openPopover()
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
<use
|
|
116
|
+
xlink:href={`#spectrum-icon-18-${!hbsValue.length ? "Key" : "Close"}`}
|
|
117
|
+
/>
|
|
118
|
+
</svg>
|
|
119
|
+
|
|
120
|
+
<input
|
|
121
|
+
bind:this={field}
|
|
122
|
+
disabled={hbsValue.length || disabled}
|
|
123
|
+
{readonly}
|
|
124
|
+
{id}
|
|
125
|
+
value={hbsValue.length ? `{{ ${hbsValue[0]} }}` : value}
|
|
126
|
+
placeholder={placeholder || ""}
|
|
127
|
+
on:click
|
|
128
|
+
on:blur
|
|
129
|
+
on:focus
|
|
130
|
+
on:input
|
|
131
|
+
on:keyup
|
|
132
|
+
on:blur={onBlur}
|
|
133
|
+
on:focus={onFocus}
|
|
134
|
+
on:input={onInput}
|
|
135
|
+
type={hbsValue.length ? "text" : type}
|
|
136
|
+
style={align ? `text-align: ${align};` : ""}
|
|
137
|
+
class="spectrum-Textfield-input"
|
|
138
|
+
inputmode={type === "number" ? "decimal" : "text"}
|
|
139
|
+
/>
|
|
140
|
+
</div>
|
|
141
|
+
{#if open}
|
|
142
|
+
<div
|
|
143
|
+
use:clickOutside={handleOutsideClick}
|
|
144
|
+
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
|
145
|
+
>
|
|
146
|
+
<ul class="spectrum-Menu" role="listbox">
|
|
147
|
+
{#if !environmentVariablesEnabled}
|
|
148
|
+
<div class="no-variables-text primary-text">
|
|
149
|
+
Upgrade your plan to get environment variables
|
|
150
|
+
</div>
|
|
151
|
+
{:else if variables.length}
|
|
152
|
+
<div style="max-height: 100px">
|
|
153
|
+
{#each variables as variable, idx}
|
|
154
|
+
<li
|
|
155
|
+
class="spectrum-Menu-item"
|
|
156
|
+
role="option"
|
|
157
|
+
aria-selected="true"
|
|
158
|
+
tabindex="0"
|
|
159
|
+
on:click={() => handleVarSelect(variable.name)}
|
|
160
|
+
>
|
|
161
|
+
<span class="spectrum-Menu-itemLabel">
|
|
162
|
+
<div class="primary-text">
|
|
163
|
+
{variable.name}
|
|
164
|
+
<span />
|
|
165
|
+
</div>
|
|
166
|
+
<svg
|
|
167
|
+
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
|
|
168
|
+
focusable="false"
|
|
169
|
+
aria-hidden="true"
|
|
170
|
+
>
|
|
171
|
+
<use xlink:href="#spectrum-css-icon-Checkmark100" />
|
|
172
|
+
</svg>
|
|
173
|
+
</span>
|
|
174
|
+
</li>
|
|
175
|
+
{/each}
|
|
176
|
+
</div>
|
|
177
|
+
{:else}
|
|
178
|
+
<div class="no-variables-text primary-text">
|
|
179
|
+
You don't have any environment variables yet
|
|
180
|
+
</div>
|
|
181
|
+
{/if}
|
|
182
|
+
</ul>
|
|
183
|
+
<Divider noMargin />
|
|
184
|
+
{#if environmentVariablesEnabled}
|
|
185
|
+
<div on:click={() => showModal()} class="add-variable">
|
|
186
|
+
<svg
|
|
187
|
+
class="spectrum-Icon spectrum-Icon--sizeS "
|
|
188
|
+
focusable="false"
|
|
189
|
+
aria-hidden="true"
|
|
190
|
+
>
|
|
191
|
+
<use xlink:href="#spectrum-icon-18-Add" />
|
|
192
|
+
</svg>
|
|
193
|
+
<div class="primary-text">Add Variable</div>
|
|
194
|
+
</div>
|
|
195
|
+
{:else}
|
|
196
|
+
<div on:click={() => handleUpgradePanel()} class="add-variable">
|
|
197
|
+
<svg
|
|
198
|
+
class="spectrum-Icon spectrum-Icon--sizeS "
|
|
199
|
+
focusable="false"
|
|
200
|
+
aria-hidden="true"
|
|
201
|
+
>
|
|
202
|
+
<use xlink:href="#spectrum-icon-18-ArrowUp" />
|
|
203
|
+
</svg>
|
|
204
|
+
<div class="primary-text">Upgrade plan</div>
|
|
205
|
+
</div>
|
|
206
|
+
{/if}
|
|
207
|
+
</div>
|
|
208
|
+
{/if}
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<style>
|
|
212
|
+
.spectrum-Textfield {
|
|
213
|
+
width: 100%;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
.icon-position {
|
|
217
|
+
position: absolute;
|
|
218
|
+
top: 25%;
|
|
219
|
+
right: 2%;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.hoverable:hover {
|
|
223
|
+
cursor: pointer;
|
|
224
|
+
color: var(--spectrum-global-color-blue-400);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
.primary-text {
|
|
228
|
+
white-space: nowrap;
|
|
229
|
+
overflow: hidden;
|
|
230
|
+
text-overflow: ellipsis;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.spectrum-InputGroup {
|
|
234
|
+
min-width: 0;
|
|
235
|
+
width: 100%;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
.spectrum-Popover {
|
|
239
|
+
max-height: 240px;
|
|
240
|
+
z-index: 999;
|
|
241
|
+
top: 100%;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.spectrum-Popover.spectrum-Popover--bottom.spectrum-Picker-popover.is-open {
|
|
245
|
+
width: 100%;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.no-variables-text {
|
|
249
|
+
padding: var(--spacing-m);
|
|
250
|
+
color: var(--spectrum-global-color-gray-600);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
.add-variable {
|
|
254
|
+
display: flex;
|
|
255
|
+
padding: var(--spacing-m) 0 var(--spacing-m) var(--spacing-m);
|
|
256
|
+
align-items: center;
|
|
257
|
+
gap: var(--spacing-s);
|
|
258
|
+
cursor: pointer;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.focused {
|
|
262
|
+
color: var(--spectrum-global-color-blue-400);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
.add-variable:hover {
|
|
266
|
+
background: var(--grey-1);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
.close-color {
|
|
270
|
+
color: var(--spectrum-global-color-gray-900) !important;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.close-color:hover {
|
|
274
|
+
color: var(--spectrum-global-color-blue-400) !important;
|
|
275
|
+
}
|
|
276
|
+
</style>
|