@onsvisual/svelte-components 1.0.54 → 1.0.55
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/inputs/Dropdown/Dropdown.svelte +15 -1
- package/dist/inputs/Dropdown/Dropdown.svelte.d.ts +2 -0
- package/dist/inputs/Input/Input.svelte +12 -4
- package/dist/inputs/Input/Input.svelte.d.ts +4 -4
- package/dist/inputs/Select/Select.svelte +7 -25
- package/dist/inputs/Select/Select.svelte.d.ts +0 -2
- package/package.json +3 -2
|
@@ -38,6 +38,11 @@
|
|
|
38
38
|
* @type {object[]}
|
|
39
39
|
*/
|
|
40
40
|
export let options = [];
|
|
41
|
+
/**
|
|
42
|
+
* The width of the <input> in characters or a valid css width string (eg. "100px")
|
|
43
|
+
* @type {number|string|null}
|
|
44
|
+
*/
|
|
45
|
+
export let width = 20;
|
|
41
46
|
/**
|
|
42
47
|
* Optional: Set an additional CSS class for the component
|
|
43
48
|
* @type {string|null}
|
|
@@ -52,7 +57,10 @@
|
|
|
52
57
|
<select
|
|
53
58
|
{id}
|
|
54
59
|
{name}
|
|
55
|
-
class="ons-input ons-input--select
|
|
60
|
+
class="ons-input ons-input--select {Number.isInteger(width)
|
|
61
|
+
? `ons-input--w-${width}`
|
|
62
|
+
: ''}"
|
|
63
|
+
style:width={typeof width === "string" ? width : null}
|
|
56
64
|
bind:value
|
|
57
65
|
on:change={(e) => dispatch("change", e)}
|
|
58
66
|
>
|
|
@@ -64,3 +72,9 @@
|
|
|
64
72
|
{/each}
|
|
65
73
|
</select>
|
|
66
74
|
</div>
|
|
75
|
+
|
|
76
|
+
<style>
|
|
77
|
+
.ons-input--select {
|
|
78
|
+
width: 100%;
|
|
79
|
+
}
|
|
80
|
+
</style>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
export default class Dropdown extends SvelteComponentTyped<{
|
|
5
5
|
cls?: string | null | undefined;
|
|
6
6
|
id?: string | null | undefined;
|
|
7
|
+
width?: string | number | null | undefined;
|
|
7
8
|
label?: string | null | undefined;
|
|
8
9
|
name?: string | null | undefined;
|
|
9
10
|
value?: object | null | undefined;
|
|
@@ -24,6 +25,7 @@ declare const __propDef: {
|
|
|
24
25
|
props: {
|
|
25
26
|
cls?: string | null | undefined;
|
|
26
27
|
id?: string | null | undefined;
|
|
28
|
+
width?: string | number | null | undefined;
|
|
27
29
|
label?: string | null | undefined;
|
|
28
30
|
name?: string | null | undefined;
|
|
29
31
|
value?: object | null | undefined;
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
export let description = null;
|
|
36
36
|
/**
|
|
37
37
|
* The maximum number of characters that can be entered (optional)
|
|
38
|
-
* @type {number}
|
|
38
|
+
* @type {number|null}
|
|
39
39
|
*/
|
|
40
40
|
export let charLimit = null;
|
|
41
41
|
/**
|
|
42
|
-
* The width of the <input> in characters
|
|
43
|
-
* @type {number}
|
|
42
|
+
* The width of the <input> in characters or a valid css width string (eg. "100px")
|
|
43
|
+
* @type {number|string|null}
|
|
44
44
|
*/
|
|
45
|
-
export let width =
|
|
45
|
+
export let width = 20;
|
|
46
46
|
/**
|
|
47
47
|
* An optional prefix (eg. £) to appear on the left of the input
|
|
48
48
|
* @type {string|null}
|
|
@@ -116,6 +116,7 @@
|
|
|
116
116
|
class="ons-input ons-input--text ons-input-type__input {Number.isInteger(width)
|
|
117
117
|
? `ons-input--w-${width}`
|
|
118
118
|
: ''}"
|
|
119
|
+
style:width={typeof width === "string" ? width : null}
|
|
119
120
|
class:ons-input--error={error}
|
|
120
121
|
aria-labelledby="{id} {id}-unit"
|
|
121
122
|
aria-describedby={description ? `${id}-description-hint` : null}
|
|
@@ -142,6 +143,7 @@
|
|
|
142
143
|
class="ons-input ons-input--text ons-input-type__input {Number.isInteger(width)
|
|
143
144
|
? `ons-input--w-${width}`
|
|
144
145
|
: ''}"
|
|
146
|
+
style:width={typeof width === "string" ? width : null}
|
|
145
147
|
class:ons-input--error={error}
|
|
146
148
|
aria-describedby={description ? `${id}-description-hint` : null}
|
|
147
149
|
{disabled}
|
|
@@ -149,3 +151,9 @@
|
|
|
149
151
|
/>
|
|
150
152
|
{/if}
|
|
151
153
|
</div>
|
|
154
|
+
|
|
155
|
+
<style>
|
|
156
|
+
.ons-input--text {
|
|
157
|
+
width: 100%;
|
|
158
|
+
}
|
|
159
|
+
</style>
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export default class Input extends SvelteComponentTyped<{
|
|
5
5
|
cls?: string | null | undefined;
|
|
6
6
|
id?: string | null | undefined;
|
|
7
|
-
width?: number | undefined;
|
|
7
|
+
width?: string | number | null | undefined;
|
|
8
8
|
label?: string | null | undefined;
|
|
9
9
|
pattern?: string | null | undefined;
|
|
10
10
|
name?: string | null | undefined;
|
|
@@ -14,7 +14,7 @@ export default class Input extends SvelteComponentTyped<{
|
|
|
14
14
|
description?: string | null | undefined;
|
|
15
15
|
disabled?: boolean | undefined;
|
|
16
16
|
hideLabel?: boolean | undefined;
|
|
17
|
-
charLimit?: number | undefined;
|
|
17
|
+
charLimit?: number | null | undefined;
|
|
18
18
|
prefix?: string | null | undefined;
|
|
19
19
|
suffix?: string | null | undefined;
|
|
20
20
|
unitLabel?: string | undefined;
|
|
@@ -32,7 +32,7 @@ declare const __propDef: {
|
|
|
32
32
|
props: {
|
|
33
33
|
cls?: string | null | undefined;
|
|
34
34
|
id?: string | null | undefined;
|
|
35
|
-
width?: number | undefined;
|
|
35
|
+
width?: string | number | null | undefined;
|
|
36
36
|
label?: string | null | undefined;
|
|
37
37
|
pattern?: string | null | undefined;
|
|
38
38
|
name?: string | null | undefined;
|
|
@@ -42,7 +42,7 @@ declare const __propDef: {
|
|
|
42
42
|
description?: string | null | undefined;
|
|
43
43
|
disabled?: boolean | undefined;
|
|
44
44
|
hideLabel?: boolean | undefined;
|
|
45
|
-
charLimit?: number | undefined;
|
|
45
|
+
charLimit?: number | null | undefined;
|
|
46
46
|
prefix?: string | null | undefined;
|
|
47
47
|
suffix?: string | null | undefined;
|
|
48
48
|
unitLabel?: string | undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
// @ts-nocheck
|
|
3
|
-
|
|
4
3
|
import { onMount, createEventDispatcher } from "svelte";
|
|
4
|
+
import accessibleAutocomplete from "accessible-autocomplete";
|
|
5
5
|
import Dropdown from "../Dropdown/Dropdown.svelte";
|
|
6
6
|
import Input from "../Input/Input.svelte";
|
|
7
7
|
|
|
@@ -10,9 +10,8 @@
|
|
|
10
10
|
const chevron = (opts) =>
|
|
11
11
|
`<svg class="${opts?.className}" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 11.75 7.7" width="18" style="z-index:1"><path fill="currentColor" d="m1.37.15 4.5 5.1 4.5-5.1a.37.37 0 0 1 .6 0l.7.7a.45.45 0 0 1 0 .5l-5.5 6.2a.37.37 0 0 1-.6 0l-5.5-6.1a.64.64 0 0 1 0-.6l.7-.7a.64.64 0 0 1 .6 0Z"></path></svg>`;
|
|
12
12
|
|
|
13
|
+
let mounted = false;
|
|
13
14
|
let inputElement;
|
|
14
|
-
let scriptLoaded;
|
|
15
|
-
let accessibleAutocomplete;
|
|
16
15
|
let hideMenu = false;
|
|
17
16
|
|
|
18
17
|
/**
|
|
@@ -98,12 +97,6 @@
|
|
|
98
97
|
);
|
|
99
98
|
populateResults(filteredResults);
|
|
100
99
|
};
|
|
101
|
-
/**
|
|
102
|
-
* Optional: Override the default CDN URL for the accessible-autocomplete script
|
|
103
|
-
* @type {string}
|
|
104
|
-
*/
|
|
105
|
-
export let scriptUrl =
|
|
106
|
-
"https://cdn.ons.gov.uk/vendor/accessible-autocomplete/3.0.1/accessible-autocomplete.min.js";
|
|
107
100
|
/**
|
|
108
101
|
* Call this function externally to clear the input
|
|
109
102
|
* @type {function}
|
|
@@ -167,13 +160,6 @@
|
|
|
167
160
|
if (!e.target.value) select(null);
|
|
168
161
|
}
|
|
169
162
|
|
|
170
|
-
function handleScriptLoad() {
|
|
171
|
-
if (!scriptLoaded && window?.accessibleAutocomplete) {
|
|
172
|
-
accessibleAutocomplete = window.accessibleAutocomplete;
|
|
173
|
-
scriptLoaded = true;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
163
|
function initAutocomplete(element) {
|
|
178
164
|
accessibleAutocomplete({
|
|
179
165
|
element,
|
|
@@ -209,24 +195,20 @@
|
|
|
209
195
|
}
|
|
210
196
|
$: bindInputValue(value);
|
|
211
197
|
|
|
212
|
-
onMount(
|
|
198
|
+
onMount(() => mounted = true);
|
|
213
199
|
</script>
|
|
214
200
|
|
|
215
|
-
|
|
216
|
-
<script src={scriptUrl} on:load={handleScriptLoad}></script>
|
|
217
|
-
</svelte:head>
|
|
218
|
-
|
|
219
|
-
{#if renderFallback && !scriptLoaded}
|
|
201
|
+
{#if renderFallback && !mounted}
|
|
220
202
|
{#if mode === "search"}
|
|
221
|
-
<Input {id} {name} {label} {hideLabel} value={value?.[labelKey]} />
|
|
203
|
+
<Input {id} {name} {label} {hideLabel} value={value?.[labelKey]} width={null}/>
|
|
222
204
|
{:else}
|
|
223
|
-
<Dropdown {id} {name} {options} {label} {hideLabel} {placeholder} {value} />
|
|
205
|
+
<Dropdown {id} {name} {options} {label} {hideLabel} {placeholder} {value} width={null} />
|
|
224
206
|
{/if}
|
|
225
207
|
{:else}
|
|
226
208
|
<div class="ons-field {cls}">
|
|
227
209
|
{#if label}<label for={id} class="ons-label" class:ons-u-vh={hideLabel}>{label}</label>{/if}
|
|
228
210
|
<div class="ons-autocomplete-wrapper">
|
|
229
|
-
{#if
|
|
211
|
+
{#if mounted}
|
|
230
212
|
<div
|
|
231
213
|
id="{id}-container"
|
|
232
214
|
class="ons-autocomplete"
|
|
@@ -18,7 +18,6 @@ export default class Select extends SvelteComponentTyped<{
|
|
|
18
18
|
renderFallback?: boolean | undefined;
|
|
19
19
|
minLength?: number | undefined;
|
|
20
20
|
loadOptions?: Function | undefined;
|
|
21
|
-
scriptUrl?: string | undefined;
|
|
22
21
|
clearInput?: Function | undefined;
|
|
23
22
|
}, {
|
|
24
23
|
clear: CustomEvent<any>;
|
|
@@ -49,7 +48,6 @@ declare const __propDef: {
|
|
|
49
48
|
renderFallback?: boolean | undefined;
|
|
50
49
|
minLength?: number | undefined;
|
|
51
50
|
loadOptions?: Function | undefined;
|
|
52
|
-
scriptUrl?: string | undefined;
|
|
53
51
|
clearInput?: Function | undefined;
|
|
54
52
|
};
|
|
55
53
|
events: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onsvisual/svelte-components",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "npm run build:package && npm run build:docs",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"@types/node": "^20",
|
|
63
63
|
"@vitest/browser": "3.2.3",
|
|
64
64
|
"@vitest/coverage-v8": "3.2.3",
|
|
65
|
+
"accessible-autocomplete": "^3.0.1",
|
|
65
66
|
"csso": "^5.0.5",
|
|
66
67
|
"eslint": "^9.18.0",
|
|
67
68
|
"eslint-config-prettier": "^10.0.1",
|
|
@@ -86,4 +87,4 @@
|
|
|
86
87
|
"keywords": [
|
|
87
88
|
"svelte"
|
|
88
89
|
]
|
|
89
|
-
}
|
|
90
|
+
}
|