@lavalogic/scoria 0.34.0 → 0.35.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/README.md +58 -58
- package/dist/Components/AccordionGroup.svelte +42 -42
- package/dist/Components/AccordionGroupButton.svelte +99 -99
- package/dist/Components/Action.svelte +138 -138
- package/dist/Components/AlertModal.svelte +125 -125
- package/dist/Components/Base/ContextWrapper.svelte +50 -50
- package/dist/Components/Base/Pagination.svelte +190 -190
- package/dist/Components/Base/Snippets.svelte +29 -29
- package/dist/Components/BigRadioSet.svelte +29 -29
- package/dist/Components/Bubble.svelte +77 -77
- package/dist/Components/Button.svelte +197 -197
- package/dist/Components/Checkbox.svelte +68 -68
- package/dist/Components/CollapsibleCard.svelte +70 -70
- package/dist/Components/Contexts/ContextMenu.svelte +157 -157
- package/dist/Components/Contexts/ContextMenuDivider.svelte +11 -11
- package/dist/Components/Contexts/ContextMenuOption.svelte +52 -52
- package/dist/Components/Contexts/Toast.svelte +61 -61
- package/dist/Components/Contexts/ToastContainer.svelte +46 -46
- package/dist/Components/Contexts/Tooltip.svelte +26 -26
- package/dist/Components/DataMatrixIcon.svelte +41 -41
- package/dist/Components/DateInput.svelte +109 -109
- package/dist/Components/DatePicker.svelte +312 -312
- package/dist/Components/DesktopModal.svelte +106 -106
- package/dist/Components/Dial.svelte +151 -151
- package/dist/Components/DimensionInput.svelte +184 -184
- package/dist/Components/DragMenu/DragMenuHolder.svelte +106 -106
- package/dist/Components/DragMenu/DraggableCard.svelte +41 -41
- package/dist/Components/FileCard.svelte +20 -20
- package/dist/Components/FileUpload.svelte +196 -196
- package/dist/Components/GridInput.svelte +190 -190
- package/dist/Components/GridInputSet.svelte +22 -22
- package/dist/Components/HorizontalTabGroup.svelte +78 -78
- package/dist/Components/HorizontalTabGroupButton.svelte +96 -96
- package/dist/Components/Icon.svelte +97 -97
- package/dist/Components/Icons.js +357 -357
- package/dist/Components/LoadingAnimation.svelte +32 -32
- package/dist/Components/LoadingModal.svelte +47 -47
- package/dist/Components/LoadingOverlay.svelte +27 -27
- package/dist/Components/Modal.svelte +251 -251
- package/dist/Components/MultiSelect.svelte +197 -197
- package/dist/Components/Nav/Nav.svelte +97 -97
- package/dist/Components/Nav/NavServiceMenuList.svelte +34 -34
- package/dist/Components/Nav/NavTab.svelte +91 -91
- package/dist/Components/Nav/ServiceMenuItem.svelte +91 -91
- package/dist/Components/Nav/ServicesNav.svelte +53 -53
- package/dist/Components/NumberInput.svelte +144 -144
- package/dist/Components/PageHeading.svelte +36 -36
- package/dist/Components/PasswordInput.svelte +73 -73
- package/dist/Components/Portal.svelte +25 -25
- package/dist/Components/ProgressBubble.svelte +80 -80
- package/dist/Components/QuerySelect.svelte +411 -411
- package/dist/Components/SingleSelect.svelte +261 -261
- package/dist/Components/StepButton.svelte +120 -120
- package/dist/Components/StepForm.svelte +108 -108
- package/dist/Components/Switch.svelte +36 -36
- package/dist/Components/Table/Body/QuickSearchCell.svelte +632 -632
- package/dist/Components/Table/Body/Rows/ColumnHighlight.svelte +30 -30
- package/dist/Components/Table/Body/Rows/ColumnList.svelte +56 -56
- package/dist/Components/Table/Body/Rows/ColumnListRow.svelte +179 -179
- package/dist/Components/Table/Body/Rows/Columns/AccessorComponent.svelte +49 -49
- package/dist/Components/Table/Body/Rows/Columns/ActionsCell.svelte +180 -180
- package/dist/Components/Table/Body/Rows/Columns/BubbleCell.svelte +102 -102
- package/dist/Components/Table/Body/Rows/Columns/ExpandCell.svelte +119 -119
- package/dist/Components/Table/Body/Rows/Columns/FocusableImmutableCell.svelte +114 -114
- package/dist/Components/Table/Body/Rows/Columns/ProgressCell.svelte +96 -96
- package/dist/Components/Table/Body/Rows/Columns/TableAction.svelte +72 -72
- package/dist/Components/Table/Body/Rows/Columns/TableCheckbox.svelte +131 -131
- package/dist/Components/Table/Body/Rows/Columns/TableColumn.svelte +144 -144
- package/dist/Components/Table/Body/Rows/Columns/TableDatePicker.svelte +238 -238
- package/dist/Components/Table/Body/Rows/Columns/TableNumberInput.svelte +358 -358
- package/dist/Components/Table/Body/Rows/Columns/TableQuerySelect.svelte +338 -338
- package/dist/Components/Table/Body/Rows/Columns/TableRowSelectionCheckbox.svelte +183 -183
- package/dist/Components/Table/Body/Rows/Columns/TableSelect.svelte +309 -309
- package/dist/Components/Table/Body/Rows/Columns/TableTextInput.svelte +369 -369
- package/dist/Components/Table/Body/Rows/Columns/ValidityCell.svelte +170 -170
- package/dist/Components/Table/Body/Rows/TableRow.svelte +259 -259
- package/dist/Components/Table/Body/TableBody.svelte +67 -67
- package/dist/Components/Table/Headers/HighlightAllHeader.svelte +39 -39
- package/dist/Components/Table/Headers/SelectAllHeader.svelte +28 -28
- package/dist/Components/Table/Headers/TableHead.svelte +260 -260
- package/dist/Components/Table/Misc/ColumnPanel.svelte +78 -78
- package/dist/Components/Table/Misc/ColumnPanelModal.svelte +99 -99
- package/dist/Components/Table/Misc/FilterInput.svelte +556 -556
- package/dist/Components/Table/Misc/FilterPanel.svelte +46 -46
- package/dist/Components/Table/Misc/FilterPanelModal.svelte +67 -67
- package/dist/Components/Table/Misc/SidePanel.svelte +32 -32
- package/dist/Components/Table/Misc/TableFooter.svelte +304 -304
- package/dist/Components/Table/Misc/TableHorizontalBar.svelte +156 -156
- package/dist/Components/Table/Misc/TableSidebar.svelte +176 -176
- package/dist/Components/Table/Misc/ToolboxPanel.svelte +77 -77
- package/dist/Components/Table/Misc/ToolboxPanelModal.svelte +91 -91
- package/dist/Components/Table/NestedTable.svelte +84 -84
- package/dist/Components/Table/Table.svelte +492 -492
- package/dist/Components/Test/TestContextConsumer.svelte +13 -13
- package/dist/Components/TextArea.svelte +108 -108
- package/dist/Components/TextInput.svelte +147 -147
- package/dist/Components/ThreeStateRadio.svelte +124 -124
- package/dist/Components/Touch/BoolCard.svelte +52 -52
- package/dist/Components/Touch/DateModal.svelte +217 -217
- package/dist/Components/Touch/EditCard.svelte +52 -52
- package/dist/Components/Touch/InfoCard.svelte +24 -24
- package/dist/Components/Touch/InfoTextCard.svelte +21 -21
- package/dist/Components/Touch/ModalExplanation.svelte +20 -20
- package/dist/Components/Touch/NumberKeyboard.svelte +268 -268
- package/dist/Components/Touch/NumberModal.svelte +69 -69
- package/dist/Components/Touch/PlusMinusCard.svelte +50 -50
- package/dist/Components/Touch/SelectModal.svelte +105 -105
- package/dist/Components/Touch/SummaryCard.svelte +65 -65
- package/dist/Components/Touch/TextAreaModal.svelte +86 -86
- package/dist/Components/Touch/TextModal.svelte +123 -123
- package/dist/Components/Touch/TouchCard.svelte +28 -28
- package/dist/Components/Touch/TouchModal.svelte +259 -259
- package/dist/Components/Touch/UtilityButton.svelte +91 -91
- package/dist/Components/VerticalTabGroup.svelte +66 -66
- package/dist/Components/VerticalTabGroupButton.svelte +97 -97
- package/dist/Helpers/Datamatrix.d.ts +10 -10
- package/dist/Helpers/Datamatrix.js +1 -1
- package/dist/Helpers/Helpers.svelte.js +6 -4
- package/dist/Types/Examples/ExampleModal.svelte +34 -34
- package/dist/scss/_basics.scss +12 -12
- package/dist/scss/_colours.scss +134 -134
- package/dist/scss/_mixins.scss +3016 -3016
- package/dist/scss/_sizing.scss +69 -69
- package/dist/scss/_transitions.scss +8 -8
- package/package.json +2 -2
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<svelte:options runes />
|
|
2
|
-
|
|
3
|
-
<script lang="ts" module>
|
|
4
|
-
import type { Snippet } from 'svelte';
|
|
5
|
-
|
|
6
|
-
export interface ModalExplanationProps {
|
|
7
|
-
width?: string;
|
|
8
|
-
children: Snippet;
|
|
9
|
-
nowrap?: boolean;
|
|
10
|
-
}
|
|
11
|
-
</script>
|
|
12
|
-
|
|
13
|
-
<script lang="ts">
|
|
14
|
-
let { width, children, nowrap }: ModalExplanationProps = $props();
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<!-- {width ? 0 : "1rem"} -->
|
|
18
|
-
<p class:nowrap style="--width: {width}; --padding: 0;">{@render children()}</p>
|
|
19
|
-
|
|
1
|
+
<svelte:options runes />
|
|
2
|
+
|
|
3
|
+
<script lang="ts" module>
|
|
4
|
+
import type { Snippet } from 'svelte';
|
|
5
|
+
|
|
6
|
+
export interface ModalExplanationProps {
|
|
7
|
+
width?: string;
|
|
8
|
+
children: Snippet;
|
|
9
|
+
nowrap?: boolean;
|
|
10
|
+
}
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
let { width, children, nowrap }: ModalExplanationProps = $props();
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<!-- {width ? 0 : "1rem"} -->
|
|
18
|
+
<p class:nowrap style="--width: {width}; --padding: 0;">{@render children()}</p>
|
|
19
|
+
|
|
20
20
|
<style>p {
|
|
21
21
|
padding: var(--padding);
|
|
22
22
|
color: #3a4952;
|
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
}
|
|
25
25
|
p.nowrap {
|
|
26
26
|
white-space: pre-line;
|
|
27
|
-
}</style>
|
|
27
|
+
}</style>
|
|
@@ -1,270 +1,270 @@
|
|
|
1
|
-
<svelte:options runes />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import { devCatch, passthrough } from '../../Helpers/Helpers.svelte.js';
|
|
5
|
-
import { InputVariant } from '../../Types/Internal/InputVariant.js';
|
|
6
|
-
import { tick, untrack } from 'svelte';
|
|
7
|
-
import Icon from '../Icon.svelte';
|
|
8
|
-
import TextInput from '../TextInput.svelte';
|
|
9
|
-
import type { NumberKeyboardProps } from './NumberKeyboardProps.js';
|
|
10
|
-
|
|
11
|
-
let {
|
|
12
|
-
value = $bindable(null),
|
|
13
|
-
label,
|
|
14
|
-
labelRight,
|
|
15
|
-
placeholder,
|
|
16
|
-
min,
|
|
17
|
-
max,
|
|
18
|
-
decimal = false,
|
|
19
|
-
inputRef = $bindable(),
|
|
20
|
-
coerceValue = false,
|
|
21
|
-
}: NumberKeyboardProps = $props();
|
|
22
|
-
|
|
23
|
-
let _value: string = $derived(
|
|
24
|
-
value != null && value % 1 == 0 ? value.toString() : getDecimalValue()
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
function getDecimalPlaces(value: number): number {
|
|
28
|
-
const str = value.toString();
|
|
29
|
-
if (!str.includes('.')) {
|
|
30
|
-
return decimal ? 2 : 0;
|
|
31
|
-
}
|
|
32
|
-
return str.split('.')[1].length;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const decimalPlaces = $derived(
|
|
36
|
-
min != null ? getDecimalPlaces(min) : max != null ? getDecimalPlaces(max) : decimal ? 2 : 0
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
function getDecimalValue(): string {
|
|
40
|
-
//HACK this absolutely moronic line is intentional. It's the best way to allow arbitrary decimal places without adding leading zeroes
|
|
41
|
-
return value ? parseFloat(value.toFixed(decimalPlaces)).toString() : '';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const newValue = $derived.by(() => {
|
|
45
|
-
const v = decimal ? parseFloat(_value) : parseInt(_value);
|
|
46
|
-
if (isNaN(v)) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
return v;
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
$effect(() => {
|
|
53
|
-
{
|
|
54
|
-
if (coerceValue) {
|
|
55
|
-
const v =
|
|
56
|
-
min != undefined && newValue != null && min > newValue
|
|
57
|
-
? min
|
|
58
|
-
: max != undefined && newValue != null && max < newValue
|
|
59
|
-
? max
|
|
60
|
-
: newValue;
|
|
61
|
-
|
|
62
|
-
value = v;
|
|
63
|
-
} else {
|
|
64
|
-
value = newValue;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
untrack(() => {
|
|
68
|
-
refocus();
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
function refocus() {
|
|
74
|
-
tick()
|
|
75
|
-
.then(() => {
|
|
76
|
-
inputRef?.focus();
|
|
77
|
-
})
|
|
78
|
-
.catch(devCatch);
|
|
79
|
-
}
|
|
80
|
-
function getPrevValue() {
|
|
81
|
-
if (inputRef) {
|
|
82
|
-
if (
|
|
83
|
-
(inputRef.selectionStart === 0 && inputRef.selectionEnd === _value.length) ||
|
|
84
|
-
(inputRef.selectionEnd === 0 && inputRef.selectionStart === _value.length)
|
|
85
|
-
) {
|
|
86
|
-
return '';
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return _value;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function addDecimal() {
|
|
93
|
-
_value = getPrevValue() + '.';
|
|
94
|
-
refocus();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/* due to the fact that number inputs won't allow a leading dot, we have to use a text input
|
|
98
|
-
this doesn't add a number, but concatenated the digit to the end of the string
|
|
99
|
-
*/
|
|
100
|
-
function addDigit(digit: string) {
|
|
101
|
-
const prevValue = getPrevValue();
|
|
102
|
-
_value = prevValue + digit;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function backspace() {
|
|
106
|
-
const preVvalue = getPrevValue();
|
|
107
|
-
const v = preVvalue && _value.slice(0, _value.length - 1);
|
|
108
|
-
_value = v;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function minus() {
|
|
112
|
-
const v = ((decimal ? parseFloat(_value) : parseInt(_value)) || 0) - 1;
|
|
113
|
-
|
|
114
|
-
_value = (min != null ? Math.max(min, v) : v).toString();
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function plus() {
|
|
118
|
-
const v = ((decimal ? parseFloat(_value) : parseInt(_value)) || 0) + 1;
|
|
119
|
-
|
|
120
|
-
_value = (max != null ? Math.min(max, v) : v).toString();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const lessThanMin = $derived(min != null && (value == null || value < min));
|
|
124
|
-
const moreThanMax = $derived(max != null && (value == null || value > max));
|
|
125
|
-
</script>
|
|
126
|
-
|
|
127
|
-
<div class="number-input-wrapper">
|
|
128
|
-
<div class="left-side">
|
|
129
|
-
<div class="value-container">
|
|
130
|
-
<!-- textInput is the only available option when you try to add a decimal point programmatically -->
|
|
131
|
-
<TextInput
|
|
132
|
-
labelTop={label}
|
|
133
|
-
{placeholder}
|
|
134
|
-
{labelRight}
|
|
135
|
-
bind:inputRef
|
|
136
|
-
bind:value={_value}
|
|
137
|
-
variant={InputVariant.Modal}
|
|
138
|
-
required
|
|
139
|
-
invalid={lessThanMin || moreThanMax}
|
|
140
|
-
/>
|
|
141
|
-
{#if max != undefined}
|
|
142
|
-
<TextInput
|
|
143
|
-
value={`${max}`}
|
|
144
|
-
labelTop="Maximum"
|
|
145
|
-
selectNone
|
|
146
|
-
disabled
|
|
147
|
-
variant={InputVariant.Modal}
|
|
148
|
-
/>
|
|
149
|
-
{/if}
|
|
150
|
-
</div>
|
|
151
|
-
<div class="plus-minus">
|
|
152
|
-
<button
|
|
153
|
-
onkeydown={passthrough}
|
|
154
|
-
type="button"
|
|
155
|
-
disabled={value != null && min != null && value <= min}
|
|
156
|
-
onclick={() => {
|
|
157
|
-
minus();
|
|
158
|
-
}}><Icon name="minus" /></button
|
|
159
|
-
>
|
|
160
|
-
<button
|
|
161
|
-
onkeydown={passthrough}
|
|
162
|
-
type="button"
|
|
163
|
-
disabled={value != null && max != null && value >= max}
|
|
164
|
-
onclick={() => {
|
|
165
|
-
plus();
|
|
166
|
-
}}><Icon name="plus" /></button
|
|
167
|
-
>
|
|
168
|
-
</div>
|
|
169
|
-
</div>
|
|
170
|
-
<div class="number-grid">
|
|
171
|
-
<button
|
|
172
|
-
onkeydown={passthrough}
|
|
173
|
-
type="button"
|
|
174
|
-
disabled={(value != null && max && (value * 10 || 0) + 1 > max) || false}
|
|
175
|
-
onclick={() => {
|
|
176
|
-
addDigit('1');
|
|
177
|
-
}}>1</button
|
|
178
|
-
>
|
|
179
|
-
<button
|
|
180
|
-
onkeydown={passthrough}
|
|
181
|
-
type="button"
|
|
182
|
-
disabled={(value != null && max && (value * 10 || 0) + 2 > max) || false}
|
|
183
|
-
onclick={() => {
|
|
184
|
-
addDigit('2');
|
|
185
|
-
}}>2</button
|
|
186
|
-
>
|
|
187
|
-
<button
|
|
188
|
-
onkeydown={passthrough}
|
|
189
|
-
type="button"
|
|
190
|
-
disabled={(value != null && max && (value * 10 || 0) + 3 > max) || false}
|
|
191
|
-
onclick={() => {
|
|
192
|
-
addDigit('3');
|
|
193
|
-
}}>3</button
|
|
194
|
-
>
|
|
195
|
-
<button
|
|
196
|
-
onkeydown={passthrough}
|
|
197
|
-
type="button"
|
|
198
|
-
disabled={(value != null && max && (value * 10 || 0) + 4 > max) || false}
|
|
199
|
-
onclick={() => {
|
|
200
|
-
addDigit('4');
|
|
201
|
-
}}>4</button
|
|
202
|
-
>
|
|
203
|
-
<button
|
|
204
|
-
onkeydown={passthrough}
|
|
205
|
-
type="button"
|
|
206
|
-
disabled={(value != null && max && (value * 10 || 0) + 5 > max) || false}
|
|
207
|
-
onclick={() => {
|
|
208
|
-
addDigit('5');
|
|
209
|
-
}}>5</button
|
|
210
|
-
>
|
|
211
|
-
<button
|
|
212
|
-
onkeydown={passthrough}
|
|
213
|
-
type="button"
|
|
214
|
-
disabled={(value != null && max && (value * 10 || 0) + 6 > max) || false}
|
|
215
|
-
onclick={() => {
|
|
216
|
-
addDigit('6');
|
|
217
|
-
}}>6</button
|
|
218
|
-
>
|
|
219
|
-
<button
|
|
220
|
-
onkeydown={passthrough}
|
|
221
|
-
type="button"
|
|
222
|
-
disabled={(value != null && max && (value * 10 || 0) + 7 > max) || false}
|
|
223
|
-
onclick={() => {
|
|
224
|
-
addDigit('7');
|
|
225
|
-
}}>7</button
|
|
226
|
-
>
|
|
227
|
-
<button
|
|
228
|
-
onkeydown={passthrough}
|
|
229
|
-
type="button"
|
|
230
|
-
disabled={(value != null && max && (value * 10 || 0) + 8 > max) || false}
|
|
231
|
-
onclick={() => {
|
|
232
|
-
addDigit('8');
|
|
233
|
-
}}>8</button
|
|
234
|
-
>
|
|
235
|
-
<button
|
|
236
|
-
onkeydown={passthrough}
|
|
237
|
-
type="button"
|
|
238
|
-
disabled={(value != null && max && (value * 10 || 0) + 9 > max) || false}
|
|
239
|
-
onclick={() => {
|
|
240
|
-
addDigit('9');
|
|
241
|
-
}}>9</button
|
|
242
|
-
>
|
|
243
|
-
<button
|
|
244
|
-
onkeydown={passthrough}
|
|
245
|
-
type="button"
|
|
246
|
-
disabled={!decimal || (value != null && value % 1 !== 0) || _value.endsWith('.')}
|
|
247
|
-
onclick={addDecimal}>.</button
|
|
248
|
-
>
|
|
249
|
-
<button
|
|
250
|
-
onkeydown={passthrough}
|
|
251
|
-
type="button"
|
|
252
|
-
disabled={(value != null && max && (value * 10 || 0) > max) || false}
|
|
253
|
-
onclick={() => {
|
|
254
|
-
addDigit('0');
|
|
255
|
-
}}>0</button
|
|
256
|
-
>
|
|
257
|
-
<button
|
|
258
|
-
onkeydown={passthrough}
|
|
259
|
-
type="button"
|
|
260
|
-
disabled={_value.length === 0}
|
|
261
|
-
onclick={() => {
|
|
262
|
-
backspace();
|
|
263
|
-
}}>⌫</button
|
|
264
|
-
>
|
|
265
|
-
</div>
|
|
266
|
-
</div>
|
|
267
|
-
|
|
1
|
+
<svelte:options runes />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { devCatch, passthrough } from '../../Helpers/Helpers.svelte.js';
|
|
5
|
+
import { InputVariant } from '../../Types/Internal/InputVariant.js';
|
|
6
|
+
import { tick, untrack } from 'svelte';
|
|
7
|
+
import Icon from '../Icon.svelte';
|
|
8
|
+
import TextInput from '../TextInput.svelte';
|
|
9
|
+
import type { NumberKeyboardProps } from './NumberKeyboardProps.js';
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
value = $bindable(null),
|
|
13
|
+
label,
|
|
14
|
+
labelRight,
|
|
15
|
+
placeholder,
|
|
16
|
+
min,
|
|
17
|
+
max,
|
|
18
|
+
decimal = false,
|
|
19
|
+
inputRef = $bindable(),
|
|
20
|
+
coerceValue = false,
|
|
21
|
+
}: NumberKeyboardProps = $props();
|
|
22
|
+
|
|
23
|
+
let _value: string = $derived(
|
|
24
|
+
value != null && value % 1 == 0 ? value.toString() : getDecimalValue()
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
function getDecimalPlaces(value: number): number {
|
|
28
|
+
const str = value.toString();
|
|
29
|
+
if (!str.includes('.')) {
|
|
30
|
+
return decimal ? 2 : 0;
|
|
31
|
+
}
|
|
32
|
+
return str.split('.')[1].length;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const decimalPlaces = $derived(
|
|
36
|
+
min != null ? getDecimalPlaces(min) : max != null ? getDecimalPlaces(max) : decimal ? 2 : 0
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
function getDecimalValue(): string {
|
|
40
|
+
//HACK this absolutely moronic line is intentional. It's the best way to allow arbitrary decimal places without adding leading zeroes
|
|
41
|
+
return value ? parseFloat(value.toFixed(decimalPlaces)).toString() : '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const newValue = $derived.by(() => {
|
|
45
|
+
const v = decimal ? parseFloat(_value) : parseInt(_value);
|
|
46
|
+
if (isNaN(v)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
return v;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
$effect(() => {
|
|
53
|
+
{
|
|
54
|
+
if (coerceValue) {
|
|
55
|
+
const v =
|
|
56
|
+
min != undefined && newValue != null && min > newValue
|
|
57
|
+
? min
|
|
58
|
+
: max != undefined && newValue != null && max < newValue
|
|
59
|
+
? max
|
|
60
|
+
: newValue;
|
|
61
|
+
|
|
62
|
+
value = v;
|
|
63
|
+
} else {
|
|
64
|
+
value = newValue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
untrack(() => {
|
|
68
|
+
refocus();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
function refocus() {
|
|
74
|
+
tick()
|
|
75
|
+
.then(() => {
|
|
76
|
+
inputRef?.focus();
|
|
77
|
+
})
|
|
78
|
+
.catch(devCatch);
|
|
79
|
+
}
|
|
80
|
+
function getPrevValue() {
|
|
81
|
+
if (inputRef) {
|
|
82
|
+
if (
|
|
83
|
+
(inputRef.selectionStart === 0 && inputRef.selectionEnd === _value.length) ||
|
|
84
|
+
(inputRef.selectionEnd === 0 && inputRef.selectionStart === _value.length)
|
|
85
|
+
) {
|
|
86
|
+
return '';
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return _value;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function addDecimal() {
|
|
93
|
+
_value = getPrevValue() + '.';
|
|
94
|
+
refocus();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* due to the fact that number inputs won't allow a leading dot, we have to use a text input
|
|
98
|
+
this doesn't add a number, but concatenated the digit to the end of the string
|
|
99
|
+
*/
|
|
100
|
+
function addDigit(digit: string) {
|
|
101
|
+
const prevValue = getPrevValue();
|
|
102
|
+
_value = prevValue + digit;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function backspace() {
|
|
106
|
+
const preVvalue = getPrevValue();
|
|
107
|
+
const v = preVvalue && _value.slice(0, _value.length - 1);
|
|
108
|
+
_value = v;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function minus() {
|
|
112
|
+
const v = ((decimal ? parseFloat(_value) : parseInt(_value)) || 0) - 1;
|
|
113
|
+
|
|
114
|
+
_value = (min != null ? Math.max(min, v) : v).toString();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function plus() {
|
|
118
|
+
const v = ((decimal ? parseFloat(_value) : parseInt(_value)) || 0) + 1;
|
|
119
|
+
|
|
120
|
+
_value = (max != null ? Math.min(max, v) : v).toString();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const lessThanMin = $derived(min != null && (value == null || value < min));
|
|
124
|
+
const moreThanMax = $derived(max != null && (value == null || value > max));
|
|
125
|
+
</script>
|
|
126
|
+
|
|
127
|
+
<div class="number-input-wrapper">
|
|
128
|
+
<div class="left-side">
|
|
129
|
+
<div class="value-container">
|
|
130
|
+
<!-- textInput is the only available option when you try to add a decimal point programmatically -->
|
|
131
|
+
<TextInput
|
|
132
|
+
labelTop={label}
|
|
133
|
+
{placeholder}
|
|
134
|
+
{labelRight}
|
|
135
|
+
bind:inputRef
|
|
136
|
+
bind:value={_value}
|
|
137
|
+
variant={InputVariant.Modal}
|
|
138
|
+
required
|
|
139
|
+
invalid={lessThanMin || moreThanMax}
|
|
140
|
+
/>
|
|
141
|
+
{#if max != undefined}
|
|
142
|
+
<TextInput
|
|
143
|
+
value={`${max}`}
|
|
144
|
+
labelTop="Maximum"
|
|
145
|
+
selectNone
|
|
146
|
+
disabled
|
|
147
|
+
variant={InputVariant.Modal}
|
|
148
|
+
/>
|
|
149
|
+
{/if}
|
|
150
|
+
</div>
|
|
151
|
+
<div class="plus-minus">
|
|
152
|
+
<button
|
|
153
|
+
onkeydown={passthrough}
|
|
154
|
+
type="button"
|
|
155
|
+
disabled={value != null && min != null && value <= min}
|
|
156
|
+
onclick={() => {
|
|
157
|
+
minus();
|
|
158
|
+
}}><Icon name="minus" /></button
|
|
159
|
+
>
|
|
160
|
+
<button
|
|
161
|
+
onkeydown={passthrough}
|
|
162
|
+
type="button"
|
|
163
|
+
disabled={value != null && max != null && value >= max}
|
|
164
|
+
onclick={() => {
|
|
165
|
+
plus();
|
|
166
|
+
}}><Icon name="plus" /></button
|
|
167
|
+
>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
<div class="number-grid">
|
|
171
|
+
<button
|
|
172
|
+
onkeydown={passthrough}
|
|
173
|
+
type="button"
|
|
174
|
+
disabled={(value != null && max && (value * 10 || 0) + 1 > max) || false}
|
|
175
|
+
onclick={() => {
|
|
176
|
+
addDigit('1');
|
|
177
|
+
}}>1</button
|
|
178
|
+
>
|
|
179
|
+
<button
|
|
180
|
+
onkeydown={passthrough}
|
|
181
|
+
type="button"
|
|
182
|
+
disabled={(value != null && max && (value * 10 || 0) + 2 > max) || false}
|
|
183
|
+
onclick={() => {
|
|
184
|
+
addDigit('2');
|
|
185
|
+
}}>2</button
|
|
186
|
+
>
|
|
187
|
+
<button
|
|
188
|
+
onkeydown={passthrough}
|
|
189
|
+
type="button"
|
|
190
|
+
disabled={(value != null && max && (value * 10 || 0) + 3 > max) || false}
|
|
191
|
+
onclick={() => {
|
|
192
|
+
addDigit('3');
|
|
193
|
+
}}>3</button
|
|
194
|
+
>
|
|
195
|
+
<button
|
|
196
|
+
onkeydown={passthrough}
|
|
197
|
+
type="button"
|
|
198
|
+
disabled={(value != null && max && (value * 10 || 0) + 4 > max) || false}
|
|
199
|
+
onclick={() => {
|
|
200
|
+
addDigit('4');
|
|
201
|
+
}}>4</button
|
|
202
|
+
>
|
|
203
|
+
<button
|
|
204
|
+
onkeydown={passthrough}
|
|
205
|
+
type="button"
|
|
206
|
+
disabled={(value != null && max && (value * 10 || 0) + 5 > max) || false}
|
|
207
|
+
onclick={() => {
|
|
208
|
+
addDigit('5');
|
|
209
|
+
}}>5</button
|
|
210
|
+
>
|
|
211
|
+
<button
|
|
212
|
+
onkeydown={passthrough}
|
|
213
|
+
type="button"
|
|
214
|
+
disabled={(value != null && max && (value * 10 || 0) + 6 > max) || false}
|
|
215
|
+
onclick={() => {
|
|
216
|
+
addDigit('6');
|
|
217
|
+
}}>6</button
|
|
218
|
+
>
|
|
219
|
+
<button
|
|
220
|
+
onkeydown={passthrough}
|
|
221
|
+
type="button"
|
|
222
|
+
disabled={(value != null && max && (value * 10 || 0) + 7 > max) || false}
|
|
223
|
+
onclick={() => {
|
|
224
|
+
addDigit('7');
|
|
225
|
+
}}>7</button
|
|
226
|
+
>
|
|
227
|
+
<button
|
|
228
|
+
onkeydown={passthrough}
|
|
229
|
+
type="button"
|
|
230
|
+
disabled={(value != null && max && (value * 10 || 0) + 8 > max) || false}
|
|
231
|
+
onclick={() => {
|
|
232
|
+
addDigit('8');
|
|
233
|
+
}}>8</button
|
|
234
|
+
>
|
|
235
|
+
<button
|
|
236
|
+
onkeydown={passthrough}
|
|
237
|
+
type="button"
|
|
238
|
+
disabled={(value != null && max && (value * 10 || 0) + 9 > max) || false}
|
|
239
|
+
onclick={() => {
|
|
240
|
+
addDigit('9');
|
|
241
|
+
}}>9</button
|
|
242
|
+
>
|
|
243
|
+
<button
|
|
244
|
+
onkeydown={passthrough}
|
|
245
|
+
type="button"
|
|
246
|
+
disabled={!decimal || (value != null && value % 1 !== 0) || _value.endsWith('.')}
|
|
247
|
+
onclick={addDecimal}>.</button
|
|
248
|
+
>
|
|
249
|
+
<button
|
|
250
|
+
onkeydown={passthrough}
|
|
251
|
+
type="button"
|
|
252
|
+
disabled={(value != null && max && (value * 10 || 0) > max) || false}
|
|
253
|
+
onclick={() => {
|
|
254
|
+
addDigit('0');
|
|
255
|
+
}}>0</button
|
|
256
|
+
>
|
|
257
|
+
<button
|
|
258
|
+
onkeydown={passthrough}
|
|
259
|
+
type="button"
|
|
260
|
+
disabled={_value.length === 0}
|
|
261
|
+
onclick={() => {
|
|
262
|
+
backspace();
|
|
263
|
+
}}>⌫</button
|
|
264
|
+
>
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
|
|
268
268
|
<style>button {
|
|
269
269
|
color: #3a4952;
|
|
270
270
|
fill: #3a4952;
|
|
@@ -352,4 +352,4 @@ button {
|
|
|
352
352
|
}
|
|
353
353
|
.number-input-wrapper .number-grid {
|
|
354
354
|
flex-grow: 2;
|
|
355
|
-
}</style>
|
|
355
|
+
}</style>
|