@geoffcox/sterling-svelte 0.0.16 → 0.0.18
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/{buttons/Button.svelte → Button.svelte} +27 -27
- package/{inputs/Checkbox.svelte → Checkbox.svelte} +26 -21
- package/{inputs/Checkbox.svelte.d.ts → Checkbox.svelte.d.ts} +2 -1
- package/{surfaces/Dialog.svelte → Dialog.svelte} +34 -21
- package/Field.svelte +257 -0
- package/Field.svelte.d.ts +63 -0
- package/Field.types.d.ts +1 -0
- package/Input.svelte +115 -0
- package/{inputs/Input.svelte.d.ts → Input.svelte.d.ts} +8 -3
- package/Label.svelte +51 -0
- package/Label.svelte.d.ts +41 -0
- package/List.constants.d.ts +1 -0
- package/List.constants.js +1 -0
- package/List.svelte +293 -0
- package/List.svelte.d.ts +63 -0
- package/List.types.d.ts +6 -0
- package/ListItem.svelte +89 -0
- package/ListItem.svelte.d.ts +51 -0
- package/{containers/Menu.svelte → Menu.svelte} +42 -27
- package/{containers/MenuBar.svelte → MenuBar.svelte} +13 -13
- package/{buttons/MenuButton.svelte → MenuButton.svelte} +17 -17
- package/{buttons/MenuButton.svelte.d.ts → MenuButton.svelte.d.ts} +1 -1
- package/{containers/MenuItem.svelte → MenuItem.svelte} +42 -54
- package/{containers/MenuItem.svelte.d.ts → MenuItem.svelte.d.ts} +2 -2
- package/{containers/MenuSeparator.svelte → MenuSeparator.svelte} +2 -2
- package/Menus.types.d.ts +22 -0
- package/{containers/Menus.utils.d.ts → Menus.utils.d.ts} +2 -2
- package/{containers/Menus.utils.js → Menus.utils.js} +6 -6
- package/{display/Progress.svelte → Progress.svelte} +28 -52
- package/{display/Progress.svelte.d.ts → Progress.svelte.d.ts} +1 -3
- package/Progress.types.d.ts +1 -0
- package/{inputs/Radio.svelte → Radio.svelte} +34 -29
- package/{inputs/Radio.svelte.d.ts → Radio.svelte.d.ts} +7 -2
- package/{inputs/Select.svelte → Select.svelte} +112 -130
- package/Select.svelte.d.ts +53 -0
- package/{inputs/Slider.svelte → Slider.svelte} +90 -86
- package/Slider.svelte.d.ts +51 -0
- package/{inputs/Switch.svelte → Switch.svelte} +43 -41
- package/Tab.svelte +181 -0
- package/{containers/Tab.svelte.d.ts → Tab.svelte.d.ts} +12 -15
- package/TabList.svelte +247 -0
- package/{containers/TabList.svelte.d.ts → TabList.svelte.d.ts} +21 -21
- package/TabList.types.d.ts +7 -0
- package/TextArea.svelte +113 -0
- package/{inputs/TextArea.svelte.d.ts → TextArea.svelte.d.ts} +3 -6
- package/TextArea.types.js +1 -0
- package/Tooltip.svelte +182 -0
- package/Tooltip.svelte.d.ts +24 -0
- package/Tooltip.types.d.ts +3 -0
- package/Tooltip.types.js +1 -0
- package/Tree.constants.d.ts +2 -0
- package/Tree.constants.js +2 -0
- package/Tree.svelte +114 -0
- package/Tree.svelte.d.ts +24 -0
- package/Tree.types.d.ts +28 -0
- package/Tree.types.js +1 -0
- package/{containers/TreeChevron.svelte → TreeChevron.svelte} +3 -3
- package/TreeItem.svelte +276 -0
- package/TreeItem.svelte.d.ts +65 -0
- package/{containers/TreeItem.svelte → TreeItemDisplay.svelte} +18 -18
- package/{containers/TreeItem.svelte.d.ts → TreeItemDisplay.svelte.d.ts} +11 -14
- package/{forwardEvents.js → actions/forwardEvents.js} +0 -2
- package/index.d.ts +44 -31
- package/index.js +40 -25
- package/package.json +45 -41
- package/theme/darkTheme.js +73 -74
- package/theme/lightTheme.js +76 -77
- package/containers/List.svelte +0 -249
- package/containers/List.svelte.d.ts +0 -68
- package/containers/ListItem.svelte +0 -48
- package/containers/ListItem.svelte.d.ts +0 -26
- package/containers/Menus.types.d.ts +0 -22
- package/containers/Tab.svelte +0 -327
- package/containers/TabList.svelte +0 -126
- package/containers/Tabs.types.d.ts +0 -12
- package/containers/Tree.constants.d.ts +0 -2
- package/containers/Tree.constants.js +0 -2
- package/containers/Tree.svelte +0 -222
- package/containers/Tree.svelte.d.ts +0 -50
- package/containers/Tree.types.d.ts +0 -47
- package/containers/TreeNode.svelte +0 -266
- package/containers/TreeNode.svelte.d.ts +0 -43
- package/display/Label.svelte +0 -27
- package/display/Label.svelte.d.ts +0 -20
- package/display/Progress.types.d.ts +0 -1
- package/inputs/Input.svelte +0 -129
- package/inputs/Select.svelte.d.ts +0 -62
- package/inputs/Slider.svelte.d.ts +0 -28
- package/inputs/TextArea.svelte +0 -154
- package/surfaces/CloseX.svelte +0 -5
- package/surfaces/CloseX.svelte.d.ts +0 -23
- package/surfaces/Portal.svelte +0 -14
- package/surfaces/Portal.svelte.d.ts +0 -21
- /package/{buttons/Button.svelte.d.ts → Button.svelte.d.ts} +0 -0
- /package/{buttons/Button.types.d.ts → Button.types.d.ts} +0 -0
- /package/{buttons/Button.types.js → Button.types.js} +0 -0
- /package/{surfaces/Dialog.svelte.d.ts → Dialog.svelte.d.ts} +0 -0
- /package/{containers/Menus.types.js → Field.types.js} +0 -0
- /package/{containers/Tabs.types.js → List.types.js} +0 -0
- /package/{containers/Menu.svelte.d.ts → Menu.svelte.d.ts} +0 -0
- /package/{containers/MenuBar.svelte.d.ts → MenuBar.svelte.d.ts} +0 -0
- /package/{containers/MenuItemDisplay.svelte → MenuItemDisplay.svelte} +0 -0
- /package/{containers/MenuItemDisplay.svelte.d.ts → MenuItemDisplay.svelte.d.ts} +0 -0
- /package/{containers/MenuSeparator.svelte.d.ts → MenuSeparator.svelte.d.ts} +0 -0
- /package/{containers/Menus.constants.d.ts → Menus.constants.d.ts} +0 -0
- /package/{containers/Menus.constants.js → Menus.constants.js} +0 -0
- /package/{containers/Tree.types.js → Menus.types.js} +0 -0
- /package/{display/Progress.types.js → Progress.types.js} +0 -0
- /package/{inputs/Switch.svelte.d.ts → Switch.svelte.d.ts} +0 -0
- /package/{containers/Tabs.constants.d.ts → TabList.constants.d.ts} +0 -0
- /package/{containers/Tabs.constants.js → TabList.constants.js} +0 -0
- /package/{inputs/TextArea.types.js → TabList.types.js} +0 -0
- /package/{inputs/TextArea.types.d.ts → TextArea.types.d.ts} +0 -0
- /package/{containers/TreeChevron.svelte.d.ts → TreeChevron.svelte.d.ts} +0 -0
- /package/{clickOutside.d.ts → actions/clickOutside.d.ts} +0 -0
- /package/{clickOutside.js → actions/clickOutside.js} +0 -0
- /package/{forwardEvents.d.ts → actions/forwardEvents.d.ts} +0 -0
- /package/{portal.d.ts → actions/portal.d.ts} +0 -0
- /package/{portal.js → actions/portal.js} +0 -0
|
@@ -47,13 +47,13 @@ export let shape = "rounded";
|
|
|
47
47
|
button {
|
|
48
48
|
align-content: center;
|
|
49
49
|
align-items: center;
|
|
50
|
-
background-color: var(--Button__background-color);
|
|
51
|
-
border-color: var(--Button__border-color);
|
|
52
|
-
border-radius: var(--Button__border-radius);
|
|
53
|
-
border-style: var(--Button__border-style);
|
|
54
|
-
border-width: var(--Button__border-width);
|
|
50
|
+
background-color: var(--stsv-Button__background-color);
|
|
51
|
+
border-color: var(--stsv-Button__border-color);
|
|
52
|
+
border-radius: var(--stsv-Button__border-radius);
|
|
53
|
+
border-style: var(--stsv-Button__border-style);
|
|
54
|
+
border-width: var(--stsv-Button__border-width);
|
|
55
55
|
box-sizing: border-box;
|
|
56
|
-
color: var(--Button__color);
|
|
56
|
+
color: var(--stsv-Button__color);
|
|
57
57
|
cursor: pointer;
|
|
58
58
|
display: inline-flex;
|
|
59
59
|
flex-direction: row;
|
|
@@ -85,29 +85,29 @@ export let shape = "rounded";
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
button:hover {
|
|
88
|
-
background-color: var(--Button__background-color--hover);
|
|
89
|
-
border-color: var(--Button__border-color--hover);
|
|
90
|
-
color: var(--Button__color--hover);
|
|
88
|
+
background-color: var(--stsv-Button__background-color--hover);
|
|
89
|
+
border-color: var(--stsv-Button__border-color--hover);
|
|
90
|
+
color: var(--stsv-Button__color--hover);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
button:active {
|
|
94
|
-
background-color: var(--Button__background-color--active);
|
|
95
|
-
border-color: var(--Button__border-color--active);
|
|
96
|
-
color: var(--Button__color--active);
|
|
94
|
+
background-color: var(--stsv-Button__background-color--active);
|
|
95
|
+
border-color: var(--stsv-Button__border-color--active);
|
|
96
|
+
color: var(--stsv-Button__color--active);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
button:focus-visible {
|
|
100
|
-
border-color: var(--Button__border-color--focus);
|
|
101
|
-
outline-color: var(--Common__outline-color);
|
|
102
|
-
outline-offset: var(--Common__outline-offset);
|
|
103
|
-
outline-style: var(--Common__outline-style);
|
|
104
|
-
outline-width: var(--Common__outline-width);
|
|
100
|
+
border-color: var(--stsv-Button__border-color--focus);
|
|
101
|
+
outline-color: var(--stsv-Common__outline-color);
|
|
102
|
+
outline-offset: var(--stsv-Common__outline-offset);
|
|
103
|
+
outline-style: var(--stsv-Common__outline-style);
|
|
104
|
+
outline-width: var(--stsv-Common__outline-width);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
button:disabled {
|
|
108
|
-
background-color: var(--
|
|
109
|
-
border-color: var(--
|
|
110
|
-
color: var(--
|
|
108
|
+
background-color: var(--stsv-Common__background-color--disabled);
|
|
109
|
+
border-color: var(--stsv-Common__border-color--disabled);
|
|
110
|
+
color: var(--stsv-Common__color--disabled);
|
|
111
111
|
cursor: not-allowed;
|
|
112
112
|
}
|
|
113
113
|
|
|
@@ -116,11 +116,11 @@ export let shape = "rounded";
|
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
button.outline:hover {
|
|
119
|
-
background-color: var(--Button__background-color--hover);
|
|
119
|
+
background-color: var(--stsv-Button__background-color--hover);
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
button.outline:active {
|
|
123
|
-
background-color: var(--Button__background-color--active);
|
|
123
|
+
background-color: var(--stsv-Button__background-color--active);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
button.outline:disabled {
|
|
@@ -128,7 +128,7 @@ export let shape = "rounded";
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
button.outline:disabled:hover {
|
|
131
|
-
border-color: var(--
|
|
131
|
+
border-color: var(--stsv-Common__border-color--disabled);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
button.ghost {
|
|
@@ -137,17 +137,17 @@ export let shape = "rounded";
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
button.ghost:hover {
|
|
140
|
-
background-color: var(--Button__background-color--hover);
|
|
140
|
+
background-color: var(--stsv-Button__background-color--hover);
|
|
141
141
|
border-color: transparent;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
button.ghost:active {
|
|
145
|
-
background-color: var(--Button__background-color--active);
|
|
145
|
+
background-color: var(--stsv-Button__background-color--active);
|
|
146
146
|
border-color: transparent;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
button.ghost:focus-visible {
|
|
150
|
-
border-color: var(--Button__border-color--focus);
|
|
150
|
+
border-color: var(--stsv-Button__border-color--focus);
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
button.ghost:disabled {
|
|
@@ -155,7 +155,7 @@ export let shape = "rounded";
|
|
|
155
155
|
}
|
|
156
156
|
|
|
157
157
|
button.ghost:disabled:hover {
|
|
158
|
-
background-color: var(--
|
|
158
|
+
background-color: var(--stsv-Common__background-color--disabled);
|
|
159
159
|
}
|
|
160
160
|
|
|
161
161
|
@media (prefers-reduced-motion) {
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
<script>import { v4 as uuid } from "uuid";
|
|
2
|
-
import Label from "
|
|
2
|
+
import Label from "./Label.svelte";
|
|
3
3
|
export let checked = false;
|
|
4
4
|
export let disabled = false;
|
|
5
|
-
|
|
5
|
+
export let id = void 0;
|
|
6
|
+
$: {
|
|
7
|
+
if ($$slots.default && id === void 0) {
|
|
8
|
+
id = uuid();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
6
11
|
</script>
|
|
7
12
|
|
|
8
13
|
<!--
|
|
@@ -12,6 +17,8 @@ const inputId = uuid();
|
|
|
12
17
|
<div class="sterling-checkbox">
|
|
13
18
|
<div class="container">
|
|
14
19
|
<input
|
|
20
|
+
{disabled}
|
|
21
|
+
{id}
|
|
15
22
|
type="checkbox"
|
|
16
23
|
on:blur
|
|
17
24
|
on:click
|
|
@@ -35,15 +42,13 @@ const inputId = uuid();
|
|
|
35
42
|
on:wheel
|
|
36
43
|
bind:checked
|
|
37
44
|
{...$$restProps}
|
|
38
|
-
id={inputId}
|
|
39
|
-
{disabled}
|
|
40
45
|
/>
|
|
41
46
|
<div class="indicator" />
|
|
42
47
|
</div>
|
|
43
|
-
{#if $$slots.
|
|
48
|
+
{#if $$slots.default}
|
|
44
49
|
<div class="label">
|
|
45
|
-
<Label {disabled} for={
|
|
46
|
-
<slot
|
|
50
|
+
<Label {disabled} for={id}>
|
|
51
|
+
<slot {checked} {disabled} />
|
|
47
52
|
</Label>
|
|
48
53
|
</div>
|
|
49
54
|
{/if}
|
|
@@ -94,10 +99,10 @@ const inputId = uuid();
|
|
|
94
99
|
and there is not a parent CSS selector.
|
|
95
100
|
*/
|
|
96
101
|
.indicator {
|
|
97
|
-
background-color: var(--Input__background-color);
|
|
98
|
-
border-color: var(--Input__border-color);
|
|
99
|
-
border-style: var(--Input__border-style);
|
|
100
|
-
border-width: var(--Input__border-width);
|
|
102
|
+
background-color: var(--stsv-Input__background-color);
|
|
103
|
+
border-color: var(--stsv-Input__border-color);
|
|
104
|
+
border-style: var(--stsv-Input__border-style);
|
|
105
|
+
border-width: var(--stsv-Input__border-width);
|
|
101
106
|
box-sizing: border-box;
|
|
102
107
|
display: inline-block;
|
|
103
108
|
height: 20px;
|
|
@@ -108,27 +113,27 @@ const inputId = uuid();
|
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
input:checked + .indicator {
|
|
111
|
-
background-color: var(--Input__background-color);
|
|
112
|
-
border-color: var(--Input__border-color);
|
|
116
|
+
background-color: var(--stsv-Input__background-color);
|
|
117
|
+
border-color: var(--stsv-Input__border-color);
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
input:focus-visible + .indicator {
|
|
116
|
-
outline-color: var(--Common__outline-color);
|
|
117
|
-
outline-offset: var(--Common__outline-offset);
|
|
118
|
-
outline-style: var(--Common__outline-style);
|
|
119
|
-
outline-width: var(--Common__outline-width);
|
|
121
|
+
outline-color: var(--stsv-Common__outline-color);
|
|
122
|
+
outline-offset: var(--stsv-Common__outline-offset);
|
|
123
|
+
outline-style: var(--stsv-Common__outline-style);
|
|
124
|
+
outline-width: var(--stsv-Common__outline-width);
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
input:disabled + .indicator {
|
|
123
|
-
background-color: var(--
|
|
124
|
-
border-color: var(--
|
|
128
|
+
background-color: var(--stsv-Common__background-color--disabled);
|
|
129
|
+
border-color: var(--stsv-Common__border-color--disabled);
|
|
125
130
|
}
|
|
126
131
|
|
|
127
132
|
/*
|
|
128
133
|
The checkmark is a rotated L centered in the box.
|
|
129
134
|
*/
|
|
130
135
|
input:checked + .indicator::after {
|
|
131
|
-
border-color: var(--Input__color);
|
|
136
|
+
border-color: var(--stsv-Input__color);
|
|
132
137
|
border-style: solid;
|
|
133
138
|
border-width: 0 3px 3px 0;
|
|
134
139
|
box-sizing: border-box;
|
|
@@ -145,7 +150,7 @@ const inputId = uuid();
|
|
|
145
150
|
}
|
|
146
151
|
|
|
147
152
|
input:checked:disabled + .indicator::after {
|
|
148
|
-
border-color: var(--
|
|
153
|
+
border-color: var(--stsv-Common__color--disabled);
|
|
149
154
|
}
|
|
150
155
|
|
|
151
156
|
.label {
|
|
@@ -4,6 +4,7 @@ declare const __propDef: {
|
|
|
4
4
|
[x: string]: any;
|
|
5
5
|
checked?: boolean | undefined;
|
|
6
6
|
disabled?: boolean | undefined;
|
|
7
|
+
id?: string | undefined;
|
|
7
8
|
};
|
|
8
9
|
events: {
|
|
9
10
|
blur: FocusEvent;
|
|
@@ -30,7 +31,7 @@ declare const __propDef: {
|
|
|
30
31
|
[evt: string]: CustomEvent<any>;
|
|
31
32
|
};
|
|
32
33
|
slots: {
|
|
33
|
-
|
|
34
|
+
default: {
|
|
34
35
|
checked: boolean;
|
|
35
36
|
disabled: boolean;
|
|
36
37
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script>import { createEventDispatcher, onMount, tick } from "svelte";
|
|
2
|
-
import Button from "
|
|
3
|
-
import CloseX from "./CloseX.svelte";
|
|
2
|
+
import Button from "./Button.svelte";
|
|
4
3
|
const dialogFadeDuration = 250;
|
|
5
4
|
export let open = false;
|
|
6
5
|
export let returnValue = "";
|
|
@@ -108,9 +107,7 @@ A styled <dialog> element
|
|
|
108
107
|
</div>
|
|
109
108
|
<div class="close">
|
|
110
109
|
<Button variant="ghost" shape="circular" on:click={() => closeDialog()}>
|
|
111
|
-
<div class="close-x"
|
|
112
|
-
<CloseX />
|
|
113
|
-
</div>
|
|
110
|
+
<div class="close-x" />
|
|
114
111
|
</Button>
|
|
115
112
|
</div>
|
|
116
113
|
</slot>
|
|
@@ -150,17 +147,17 @@ A styled <dialog> element
|
|
|
150
147
|
}
|
|
151
148
|
|
|
152
149
|
.header {
|
|
153
|
-
background-color: var(--Display__background-color);
|
|
150
|
+
background-color: var(--stsv-Display__background-color);
|
|
154
151
|
}
|
|
155
152
|
|
|
156
153
|
.content {
|
|
157
|
-
background-color: var(--Common__background-color);
|
|
158
|
-
border-color: var(--Common__border-color);
|
|
159
|
-
border-radius: var(--Common__border-radius);
|
|
160
|
-
border-style: var(--Common__border-style);
|
|
161
|
-
border-width: var(--Common__border-width);
|
|
154
|
+
background-color: var(--stsv-Common__background-color);
|
|
155
|
+
border-color: var(--stsv-Common__border-color);
|
|
156
|
+
border-radius: var(--stsv-Common__border-radius);
|
|
157
|
+
border-style: var(--stsv-Common__border-style);
|
|
158
|
+
border-width: var(--stsv-Common__border-width);
|
|
162
159
|
box-sizing: border-box;
|
|
163
|
-
color: var(--Common__color);
|
|
160
|
+
color: var(--stsv-Common__color);
|
|
164
161
|
display: grid;
|
|
165
162
|
grid-template-columns: 1fr;
|
|
166
163
|
grid-template-rows: auto 1fr auto auto;
|
|
@@ -203,13 +200,29 @@ A styled <dialog> element
|
|
|
203
200
|
}
|
|
204
201
|
|
|
205
202
|
.close-x {
|
|
206
|
-
width:
|
|
207
|
-
height:
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
203
|
+
width: 1em;
|
|
204
|
+
height: 1em;
|
|
205
|
+
position: relative;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.close-x:before,
|
|
209
|
+
.close-x:after {
|
|
210
|
+
content: '';
|
|
211
|
+
position: absolute;
|
|
212
|
+
width: 0.75em;
|
|
213
|
+
height: 0.125em;
|
|
214
|
+
background-color: currentColor;
|
|
215
|
+
top: 0.45em;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
.close-x:before {
|
|
219
|
+
transform: rotate(45deg);
|
|
220
|
+
left: 0.125em;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.close-x:after {
|
|
224
|
+
transform: rotate(-45deg);
|
|
225
|
+
right: 0.125em;
|
|
213
226
|
}
|
|
214
227
|
|
|
215
228
|
.body {
|
|
@@ -217,8 +230,8 @@ A styled <dialog> element
|
|
|
217
230
|
}
|
|
218
231
|
|
|
219
232
|
.separator {
|
|
220
|
-
background-color: var(--Display__background-color);
|
|
221
|
-
height: var(--Common__border-width);
|
|
233
|
+
background-color: var(--stsv-Display__background-color);
|
|
234
|
+
height: var(--stsv-Common__border-width);
|
|
222
235
|
margin: 0 0.25em;
|
|
223
236
|
}
|
|
224
237
|
|
package/Field.svelte
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
<script>import { createKeyborg } from "keyborg";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
import Tooltip from "./Tooltip.svelte";
|
|
4
|
+
export let forwardClick = false;
|
|
5
|
+
let htmlFor = void 0;
|
|
6
|
+
export { htmlFor as for };
|
|
7
|
+
export let label = void 0;
|
|
8
|
+
export let message = void 0;
|
|
9
|
+
export let required = false;
|
|
10
|
+
export let requiredTip = "This field is required";
|
|
11
|
+
export let status = "none";
|
|
12
|
+
let fieldRef;
|
|
13
|
+
let targetDisabled = false;
|
|
14
|
+
let targetRef = null;
|
|
15
|
+
const findTarget = () => {
|
|
16
|
+
let candidate = null;
|
|
17
|
+
if (htmlFor) {
|
|
18
|
+
candidate = fieldRef?.querySelector(`[id="${htmlFor}"]`);
|
|
19
|
+
}
|
|
20
|
+
if (!candidate) {
|
|
21
|
+
candidate = fieldRef?.querySelector(
|
|
22
|
+
'a[href], audio[controls], button, details, div[contenteditable], form, input, select, textarea, video[controls], [tabindex]:not([tabindex="-1"])'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
targetRef = candidate;
|
|
26
|
+
};
|
|
27
|
+
const isElementDisabled = (element) => {
|
|
28
|
+
if (element) {
|
|
29
|
+
return element.getAttribute("aria-disabled") === "true" || element?.matches(":disabled") || element?.disabled === true || element?.classList.contains("disabled");
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
};
|
|
33
|
+
$:
|
|
34
|
+
$$slots.default, fieldRef, htmlFor, findTarget();
|
|
35
|
+
$: {
|
|
36
|
+
targetDisabled = isElementDisabled(targetRef);
|
|
37
|
+
}
|
|
38
|
+
const mutationCallback = (mutations) => {
|
|
39
|
+
let disabled = void 0;
|
|
40
|
+
for (let i = 0; i < mutations.length; i++) {
|
|
41
|
+
const mutation = mutations[i];
|
|
42
|
+
if (mutation.type === "attributes") {
|
|
43
|
+
if (mutation.attributeName === "aria-disabled" || mutation.attributeName === "disabled" || mutation.attributeName === "class") {
|
|
44
|
+
if (isElementDisabled(targetRef)) {
|
|
45
|
+
disabled = true;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
disabled = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (disabled !== void 0) {
|
|
53
|
+
targetDisabled = disabled;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
let mutationObserver = new MutationObserver(mutationCallback);
|
|
57
|
+
$: {
|
|
58
|
+
mutationObserver.disconnect();
|
|
59
|
+
if (targetRef) {
|
|
60
|
+
mutationObserver.observe(targetRef, {
|
|
61
|
+
attributes: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let keyborg = createKeyborg(window);
|
|
66
|
+
let usingKeyboard = keyborg.isNavigatingWithKeyboard();
|
|
67
|
+
const keyborgHandler = (value) => {
|
|
68
|
+
usingKeyboard = value;
|
|
69
|
+
};
|
|
70
|
+
onMount(() => {
|
|
71
|
+
keyborg.subscribe(keyborgHandler);
|
|
72
|
+
return () => {
|
|
73
|
+
keyborg.unsubscribe(keyborgHandler);
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
const onClick = () => {
|
|
77
|
+
if (forwardClick) {
|
|
78
|
+
targetRef?.click();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<label
|
|
84
|
+
aria-disabled={targetDisabled}
|
|
85
|
+
bind:this={fieldRef}
|
|
86
|
+
class="sterling-field"
|
|
87
|
+
class:disabled={targetDisabled}
|
|
88
|
+
class:using-keyboard={usingKeyboard}
|
|
89
|
+
for={htmlFor}
|
|
90
|
+
on:blur
|
|
91
|
+
on:click
|
|
92
|
+
on:click={onClick}
|
|
93
|
+
on:copy
|
|
94
|
+
on:cut
|
|
95
|
+
on:dblclick
|
|
96
|
+
on:focus
|
|
97
|
+
on:focusin
|
|
98
|
+
on:focusout
|
|
99
|
+
on:keydown
|
|
100
|
+
on:keypress
|
|
101
|
+
on:keyup
|
|
102
|
+
on:mousedown
|
|
103
|
+
on:mouseenter
|
|
104
|
+
on:mouseleave
|
|
105
|
+
on:mousemove
|
|
106
|
+
on:mouseover
|
|
107
|
+
on:mouseout
|
|
108
|
+
on:mouseup
|
|
109
|
+
on:scroll
|
|
110
|
+
on:wheel
|
|
111
|
+
on:paste
|
|
112
|
+
{...$$restProps}
|
|
113
|
+
>
|
|
114
|
+
<slot name="label" disabled={targetDisabled} for={htmlFor} {label} {required}>
|
|
115
|
+
<div class="label-text">
|
|
116
|
+
{label}
|
|
117
|
+
</div>
|
|
118
|
+
</slot>
|
|
119
|
+
<slot />
|
|
120
|
+
{#if message}
|
|
121
|
+
<slot name="message" disabled={targetDisabled} {message} {required} {status}>
|
|
122
|
+
<div
|
|
123
|
+
class="message"
|
|
124
|
+
class:info={status === 'info'}
|
|
125
|
+
class:success={status === 'success'}
|
|
126
|
+
class:warning={status === 'warning'}
|
|
127
|
+
class:error={status === 'error'}
|
|
128
|
+
>
|
|
129
|
+
{message}
|
|
130
|
+
</div>
|
|
131
|
+
</slot>
|
|
132
|
+
{/if}
|
|
133
|
+
{#if required}
|
|
134
|
+
<slot name="required" {requiredTip}>
|
|
135
|
+
<Tooltip autoShow="hover">
|
|
136
|
+
<span class="required-tip" slot="tip">{requiredTip}</span>
|
|
137
|
+
<div class="required">*</div>
|
|
138
|
+
</Tooltip>
|
|
139
|
+
</slot>
|
|
140
|
+
{/if}
|
|
141
|
+
</label>
|
|
142
|
+
|
|
143
|
+
<style>
|
|
144
|
+
.sterling-field {
|
|
145
|
+
background-color: var(--stsv-Input__background-color);
|
|
146
|
+
border-color: var(--stsv-Input__border-color);
|
|
147
|
+
border-radius: var(--stsv-Input__border-radius);
|
|
148
|
+
border-style: var(--stsv-Input__border-style);
|
|
149
|
+
border-width: var(--stsv-Input__border-width);
|
|
150
|
+
box-sizing: border-box;
|
|
151
|
+
color: var(--stsv-Input__color);
|
|
152
|
+
display: flex;
|
|
153
|
+
flex-direction: column;
|
|
154
|
+
font: inherit;
|
|
155
|
+
margin: 0;
|
|
156
|
+
overflow: visible;
|
|
157
|
+
padding: 0;
|
|
158
|
+
position: relative;
|
|
159
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.sterling-field:hover {
|
|
163
|
+
background-color: var(--stsv-Input__background-color--hover);
|
|
164
|
+
border-color: var(--stsv-Input__border-color--hover);
|
|
165
|
+
color: var(--stsv-Input__color--hover);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.sterling-field.using-keyboard:focus-within {
|
|
169
|
+
border-color: var(--stsv-Common__border-color--focus);
|
|
170
|
+
color: var(--stsv-Common__color--focus);
|
|
171
|
+
outline-color: var(--stsv-Common__outline-color);
|
|
172
|
+
outline-offset: var(--stsv-Common__outline-offset);
|
|
173
|
+
outline-style: var(--stsv-Common__outline-style);
|
|
174
|
+
outline-width: var(--stsv-Common__outline-width);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.sterling-field.disabled {
|
|
178
|
+
background-color: var(--stsv-Common__background-color--disabled);
|
|
179
|
+
border-color: var(--stsv--Common__border-color--disabled);
|
|
180
|
+
color: var(--stsv-Common__color--disabled);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
.label-text {
|
|
184
|
+
color: var(--stsv-Display__color);
|
|
185
|
+
font-size: 0.8em;
|
|
186
|
+
margin: 0.5em 0.7em 0.2em 0.2em;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
.label-text:empty {
|
|
190
|
+
margin: 0;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.sterling-field.disabled .label-text {
|
|
194
|
+
color: var(--stsv-Common__color--disabled);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.message {
|
|
198
|
+
font-size: 0.8em;
|
|
199
|
+
background-color: var(--stsv-Display__background-color);
|
|
200
|
+
color: var(--stsv-Display__color);
|
|
201
|
+
padding: 0.5em;
|
|
202
|
+
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.message.info {
|
|
206
|
+
background-color: var(--stsv-Info__background-color);
|
|
207
|
+
border-color: var(--stsv-Info__border-color);
|
|
208
|
+
color: var(--stsv-Info__color);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.message.success {
|
|
212
|
+
background-color: var(--stsv-Success__background-color);
|
|
213
|
+
border-color: var(--stsv-Success__border-color);
|
|
214
|
+
color: var(--stsv-Success__color);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.message.warning {
|
|
218
|
+
background-color: var(--stsv-Warning__background-color);
|
|
219
|
+
border-color: var(--stsv-Warning__border-color);
|
|
220
|
+
color: var(--stsv-Warning__color);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
.message.error {
|
|
224
|
+
background-color: var(--stsv-Error__background-color);
|
|
225
|
+
border-color: var(--stsv__Error-color);
|
|
226
|
+
color: var(--stsv-Error__color);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.sterling-field.disabled .message {
|
|
230
|
+
background-color: var(--stsv-Common__background-color--disabled);
|
|
231
|
+
border-color: var(--stsv--Common__border-color--disabled);
|
|
232
|
+
color: var(--stsv-Common__color--disabled);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
.required {
|
|
236
|
+
text-align: center;
|
|
237
|
+
font-weight: bold;
|
|
238
|
+
box-sizing: border-box;
|
|
239
|
+
width: 1em;
|
|
240
|
+
height: 1em;
|
|
241
|
+
position: absolute;
|
|
242
|
+
top: 0;
|
|
243
|
+
right: 0;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.required-tip {
|
|
247
|
+
display: block;
|
|
248
|
+
padding: 4px;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
@media (prefers-reduced-motion) {
|
|
252
|
+
.sterling-field,
|
|
253
|
+
.message {
|
|
254
|
+
transition: none;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
</style>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
import type { FieldStatus } from './Field.types';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
forwardClick?: boolean | undefined;
|
|
7
|
+
for?: string | undefined;
|
|
8
|
+
label?: string | undefined;
|
|
9
|
+
message?: string | undefined;
|
|
10
|
+
required?: boolean | undefined;
|
|
11
|
+
requiredTip?: string | undefined;
|
|
12
|
+
status?: FieldStatus | undefined;
|
|
13
|
+
};
|
|
14
|
+
events: {
|
|
15
|
+
blur: FocusEvent;
|
|
16
|
+
click: MouseEvent;
|
|
17
|
+
copy: ClipboardEvent;
|
|
18
|
+
cut: ClipboardEvent;
|
|
19
|
+
dblclick: MouseEvent;
|
|
20
|
+
focus: FocusEvent;
|
|
21
|
+
focusin: FocusEvent;
|
|
22
|
+
focusout: FocusEvent;
|
|
23
|
+
keydown: KeyboardEvent;
|
|
24
|
+
keypress: KeyboardEvent;
|
|
25
|
+
keyup: KeyboardEvent;
|
|
26
|
+
mousedown: MouseEvent;
|
|
27
|
+
mouseenter: MouseEvent;
|
|
28
|
+
mouseleave: MouseEvent;
|
|
29
|
+
mousemove: MouseEvent;
|
|
30
|
+
mouseover: MouseEvent;
|
|
31
|
+
mouseout: MouseEvent;
|
|
32
|
+
mouseup: MouseEvent;
|
|
33
|
+
scroll: Event;
|
|
34
|
+
wheel: WheelEvent;
|
|
35
|
+
paste: ClipboardEvent;
|
|
36
|
+
} & {
|
|
37
|
+
[evt: string]: CustomEvent<any>;
|
|
38
|
+
};
|
|
39
|
+
slots: {
|
|
40
|
+
label: {
|
|
41
|
+
disabled: boolean;
|
|
42
|
+
for: string | undefined;
|
|
43
|
+
label: string | undefined;
|
|
44
|
+
required: boolean;
|
|
45
|
+
};
|
|
46
|
+
default: {};
|
|
47
|
+
message: {
|
|
48
|
+
disabled: boolean;
|
|
49
|
+
message: string | undefined;
|
|
50
|
+
required: boolean;
|
|
51
|
+
status: FieldStatus;
|
|
52
|
+
};
|
|
53
|
+
required: {
|
|
54
|
+
requiredTip: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export type FieldProps = typeof __propDef.props;
|
|
59
|
+
export type FieldEvents = typeof __propDef.events;
|
|
60
|
+
export type FieldSlots = typeof __propDef.slots;
|
|
61
|
+
export default class Field extends SvelteComponentTyped<FieldProps, FieldEvents, FieldSlots> {
|
|
62
|
+
}
|
|
63
|
+
export {};
|
package/Field.types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type FieldStatus = 'none' | 'info' | 'success' | 'warning' | 'error';
|