@geoffcox/sterling-svelte 0.0.23 → 0.0.25
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/Button.svelte +17 -22
- package/Button.svelte.d.ts +1 -0
- package/Checkbox.svelte +41 -14
- package/Dropdown.svelte +42 -45
- package/Field.svelte +11 -12
- package/Input.svelte +78 -60
- package/List.svelte +45 -16
- package/ListItem.svelte +30 -7
- package/MenuItem.svelte +6 -7
- package/MenuItemDisplay.svelte +33 -2
- package/MenuItemDisplay.svelte.d.ts +1 -0
- package/Popover.svelte +135 -0
- package/Popover.svelte.d.ts +51 -0
- package/Progress.svelte +0 -2
- package/Radio.svelte +67 -31
- package/Select.svelte +44 -67
- package/Slider.svelte +19 -10
- package/Switch.svelte +38 -14
- package/Tab.svelte +25 -3
- package/TabList.svelte +2 -2
- package/TextArea.svelte +82 -55
- package/TextArea.svelte.d.ts +2 -1
- package/Tree.svelte +44 -13
- package/TreeItem.svelte +8 -8
- package/TreeItem.svelte.d.ts +0 -1
- package/TreeItemDisplay.svelte +36 -11
- package/actions/clickOutside.d.ts +12 -1
- package/actions/clickOutside.js +13 -2
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/package.json +2 -1
- package/theme/darkTheme.js +9 -0
- package/theme/lightTheme.js +9 -0
package/TreeItem.svelte
CHANGED
|
@@ -10,7 +10,7 @@ const {
|
|
|
10
10
|
selectedValue,
|
|
11
11
|
disabled: treeDisabled
|
|
12
12
|
} = getContext(TREE_CONTEXT_KEY);
|
|
13
|
-
const { depth = 0
|
|
13
|
+
const { depth = 0 } = getContext(TREE_ITEM_CONTEXT_KEY) || {};
|
|
14
14
|
let treeItemRef;
|
|
15
15
|
$:
|
|
16
16
|
hasChildren = $$slots.default;
|
|
@@ -19,13 +19,13 @@ $:
|
|
|
19
19
|
$:
|
|
20
20
|
selected = $selectedValue === value;
|
|
21
21
|
$:
|
|
22
|
-
_disabled = disabled || $
|
|
23
|
-
const disabledStore = writable(
|
|
22
|
+
_disabled = disabled || $treeDisabled;
|
|
23
|
+
const disabledStore = writable(disabled);
|
|
24
24
|
$: {
|
|
25
|
-
disabledStore.set(
|
|
25
|
+
disabledStore.set(disabled);
|
|
26
26
|
}
|
|
27
27
|
const collapseItem = (index) => {
|
|
28
|
-
if (!
|
|
28
|
+
if (!_disabled) {
|
|
29
29
|
index = index ?? $expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
30
30
|
if (index !== -1) {
|
|
31
31
|
expandedValues.set([
|
|
@@ -39,7 +39,7 @@ const collapseItem = (index) => {
|
|
|
39
39
|
};
|
|
40
40
|
export const collapse = () => collapseItem();
|
|
41
41
|
const expandItem = (index) => {
|
|
42
|
-
if (!
|
|
42
|
+
if (!_disabled) {
|
|
43
43
|
index = index ?? $expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
44
44
|
if (index === -1) {
|
|
45
45
|
expandedValues.set([...$expandedValues, value]);
|
|
@@ -50,7 +50,7 @@ const expandItem = (index) => {
|
|
|
50
50
|
};
|
|
51
51
|
export const expand = () => expandItem();
|
|
52
52
|
export const toggleExpanded = () => {
|
|
53
|
-
if (!
|
|
53
|
+
if (!_disabled) {
|
|
54
54
|
const index = $expandedValues.findIndex((expandedValue) => expandedValue === value);
|
|
55
55
|
return index !== -1 ? collapseItem(index) : expandItem(index);
|
|
56
56
|
}
|
|
@@ -294,7 +294,7 @@ A item in a Tree displaying the item and children.
|
|
|
294
294
|
</div>
|
|
295
295
|
{#if expanded && hasChildren}
|
|
296
296
|
<div class="children" transition:slide={{ duration: 200 }} role="group">
|
|
297
|
-
<slot {depth} {
|
|
297
|
+
<slot {depth} {selected} {value} />
|
|
298
298
|
</div>
|
|
299
299
|
{/if}
|
|
300
300
|
</div>
|
package/TreeItem.svelte.d.ts
CHANGED
package/TreeItemDisplay.svelte
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
<script>import
|
|
1
|
+
<script>import { getContext } from "svelte";
|
|
2
|
+
import { TREE_CONTEXT_KEY } from "./Tree.constants";
|
|
3
|
+
import TreeChevron from "./TreeChevron.svelte";
|
|
4
|
+
import { readable } from "svelte/store";
|
|
2
5
|
export let depth = 0;
|
|
3
6
|
export let disabled = false;
|
|
4
7
|
export let expanded = false;
|
|
5
8
|
export let hasChildren = false;
|
|
6
9
|
export let value;
|
|
7
10
|
export let selected = false;
|
|
11
|
+
const { disabled: treeDisabled } = getContext(TREE_CONTEXT_KEY) || {
|
|
12
|
+
disabled: readable(false)
|
|
13
|
+
};
|
|
8
14
|
let divRef;
|
|
9
15
|
export const click = () => {
|
|
10
16
|
divRef?.click();
|
|
@@ -19,8 +25,9 @@ export const focus = (options) => {
|
|
|
19
25
|
|
|
20
26
|
<div
|
|
21
27
|
bind:this={divRef}
|
|
22
|
-
class="sterling-tree-item"
|
|
23
|
-
class:disabled
|
|
28
|
+
class="sterling-tree-item-display"
|
|
29
|
+
class:disabled={disabled && !$treeDisabled}
|
|
30
|
+
class:item-disabled={disabled}
|
|
24
31
|
class:expanded
|
|
25
32
|
class:selected
|
|
26
33
|
style={`--sterling-tree-item-depth: ${depth}`}
|
|
@@ -62,7 +69,7 @@ export const focus = (options) => {
|
|
|
62
69
|
</div>
|
|
63
70
|
|
|
64
71
|
<style>
|
|
65
|
-
.sterling-tree-item {
|
|
72
|
+
.sterling-tree-item-display {
|
|
66
73
|
align-content: center;
|
|
67
74
|
align-items: center;
|
|
68
75
|
background-color: transparent;
|
|
@@ -74,29 +81,46 @@ export const focus = (options) => {
|
|
|
74
81
|
margin: 0;
|
|
75
82
|
outline: none;
|
|
76
83
|
padding: 0.5em;
|
|
84
|
+
position: relative;
|
|
77
85
|
padding-left: calc(0.2em + (0.5em * var(--sterling-tree-item-depth)));
|
|
78
86
|
text-overflow: ellipsis;
|
|
79
87
|
transition: background-color 250ms, color 250ms, border-color 250ms;
|
|
80
88
|
white-space: nowrap;
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
.sterling-tree-item:hover {
|
|
91
|
+
.sterling-tree-item-display:not(.item-disabled):not(.selected):hover {
|
|
84
92
|
background-color: var(--stsv-Button__background-color--hover);
|
|
85
93
|
color: var(--stsv-Button__color--hover);
|
|
86
94
|
}
|
|
87
95
|
|
|
88
|
-
.sterling-tree-item.selected {
|
|
96
|
+
.sterling-tree-item-display.selected {
|
|
89
97
|
background-color: var(--stsv-Input__background-color--selected);
|
|
90
98
|
color: var(--stsv-Input__color--selected);
|
|
91
99
|
}
|
|
92
100
|
|
|
93
|
-
.sterling-tree-item.disabled {
|
|
94
|
-
background-color: var(--stsv-Input__background-color--disabled);
|
|
95
|
-
color: var(--stsv-Common__color--disabled);
|
|
101
|
+
.sterling-tree-item-display.disabled {
|
|
96
102
|
cursor: not-allowed;
|
|
103
|
+
outline: none;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
.sterling-tree-item-display::after {
|
|
107
|
+
background: var(--stsv-Disabled__background);
|
|
108
|
+
bottom: 0;
|
|
109
|
+
content: '';
|
|
110
|
+
left: 0;
|
|
111
|
+
opacity: 0;
|
|
112
|
+
pointer-events: none;
|
|
113
|
+
position: absolute;
|
|
114
|
+
right: 0;
|
|
115
|
+
top: 0;
|
|
116
|
+
transition: opacity 250ms;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.sterling-tree-item-display.disabled::after {
|
|
120
|
+
opacity: 1;
|
|
97
121
|
}
|
|
98
122
|
|
|
99
|
-
.sterling-tree-item.leaf {
|
|
123
|
+
.sterling-tree-item-display.leaf {
|
|
100
124
|
border: none;
|
|
101
125
|
background: currentColor;
|
|
102
126
|
border-radius: 50%;
|
|
@@ -107,7 +131,8 @@ export const focus = (options) => {
|
|
|
107
131
|
}
|
|
108
132
|
|
|
109
133
|
@media (prefers-reduced-motion) {
|
|
110
|
-
.sterling-tree-item
|
|
134
|
+
.sterling-tree-item-display,
|
|
135
|
+
.sterling-tree-item-display::after {
|
|
111
136
|
transition: none;
|
|
112
137
|
}
|
|
113
138
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
type Params = {
|
|
2
|
+
/** Other elements should not raise the event if clicked. */
|
|
3
|
+
ignoreOthers?: HTMLElement[];
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Raises the click_outside event when the user clicks outside the node.
|
|
7
|
+
* @param node The node to check and receive the event.
|
|
8
|
+
* @param params Additional parameters
|
|
9
|
+
*/
|
|
10
|
+
export declare const clickOutside: (node: HTMLElement, params?: Params) => {
|
|
11
|
+
update(params: Params): void;
|
|
2
12
|
destroy(): void;
|
|
3
13
|
};
|
|
14
|
+
export {};
|
package/actions/clickOutside.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Raises the click_outside event when the user clicks outside the node.
|
|
3
|
+
* @param node The node to check and receive the event.
|
|
4
|
+
* @param params Additional parameters
|
|
5
|
+
*/
|
|
6
|
+
export const clickOutside = (node, params) => {
|
|
7
|
+
let ignoreOthers = params?.ignoreOthers;
|
|
2
8
|
const handleClick = (event) => {
|
|
3
9
|
const targetNode = event?.target;
|
|
4
|
-
if (targetNode &&
|
|
10
|
+
if (targetNode &&
|
|
11
|
+
!node.contains(targetNode) &&
|
|
12
|
+
(!ignoreOthers || ignoreOthers.every((x) => !x.contains(targetNode)))) {
|
|
5
13
|
node.dispatchEvent(new CustomEvent('click_outside', {
|
|
6
14
|
detail: { mouseEvent: event }
|
|
7
15
|
}));
|
|
@@ -9,6 +17,9 @@ export const clickOutside = (node) => {
|
|
|
9
17
|
};
|
|
10
18
|
document.addEventListener('click', handleClick, true);
|
|
11
19
|
return {
|
|
20
|
+
update(params) {
|
|
21
|
+
ignoreOthers = params.ignoreOthers;
|
|
22
|
+
},
|
|
12
23
|
destroy() {
|
|
13
24
|
document.removeEventListener('click', handleClick, true);
|
|
14
25
|
}
|
package/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ import MenuButton from './MenuButton.svelte';
|
|
|
51
51
|
import MenuItem from './MenuItem.svelte';
|
|
52
52
|
import MenuItemDisplay from './MenuItemDisplay.svelte';
|
|
53
53
|
import MenuSeparator from './MenuSeparator.svelte';
|
|
54
|
+
import Popover from './Popover.svelte';
|
|
54
55
|
import Progress from './Progress.svelte';
|
|
55
56
|
import Radio from './Radio.svelte';
|
|
56
57
|
import Select from './Select.svelte';
|
|
@@ -64,4 +65,4 @@ import Tree from './Tree.svelte';
|
|
|
64
65
|
import TreeChevron from './TreeChevron.svelte';
|
|
65
66
|
import TreeItem from './TreeItem.svelte';
|
|
66
67
|
import TreeItemDisplay from './TreeItemDisplay.svelte';
|
|
67
|
-
export { Button, Checkbox, Dialog, Dropdown, Field, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuItemDisplay, MenuSeparator, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem, TreeItemDisplay };
|
|
68
|
+
export { Button, Checkbox, Dialog, Dropdown, Field, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuItemDisplay, MenuSeparator, Popover, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem, TreeItemDisplay };
|
package/index.js
CHANGED
|
@@ -43,6 +43,7 @@ import MenuButton from './MenuButton.svelte';
|
|
|
43
43
|
import MenuItem from './MenuItem.svelte';
|
|
44
44
|
import MenuItemDisplay from './MenuItemDisplay.svelte';
|
|
45
45
|
import MenuSeparator from './MenuSeparator.svelte';
|
|
46
|
+
import Popover from './Popover.svelte';
|
|
46
47
|
import Progress from './Progress.svelte';
|
|
47
48
|
import Radio from './Radio.svelte';
|
|
48
49
|
import Select from './Select.svelte';
|
|
@@ -56,4 +57,4 @@ import Tree from './Tree.svelte';
|
|
|
56
57
|
import TreeChevron from './TreeChevron.svelte';
|
|
57
58
|
import TreeItem from './TreeItem.svelte';
|
|
58
59
|
import TreeItemDisplay from './TreeItemDisplay.svelte';
|
|
59
|
-
export { Button, Checkbox, Dialog, Dropdown, Field, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuItemDisplay, MenuSeparator, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem, TreeItemDisplay };
|
|
60
|
+
export { Button, Checkbox, Dialog, Dropdown, Field, Input, Label, Link, List, ListItem, Menu, MenuBar, MenuButton, MenuItem, MenuItemDisplay, MenuSeparator, Popover, Progress, Radio, Select, Slider, Switch, Tab, TabList, TextArea, Tooltip, Tree, TreeChevron, TreeItem, TreeItemDisplay };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geoffcox/sterling-svelte",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.25",
|
|
4
4
|
"author": "Geoff Cox",
|
|
5
5
|
"description": "A modern, accessible, and lightweight component library for Svelte.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -78,6 +78,7 @@
|
|
|
78
78
|
"./MenuItem.utils": "./MenuItem.utils.js",
|
|
79
79
|
"./MenuItemDisplay.svelte": "./MenuItemDisplay.svelte",
|
|
80
80
|
"./MenuSeparator.svelte": "./MenuSeparator.svelte",
|
|
81
|
+
"./Popover.svelte": "./Popover.svelte",
|
|
81
82
|
"./Progress.constants": "./Progress.constants.js",
|
|
82
83
|
"./Progress.svelte": "./Progress.svelte",
|
|
83
84
|
"./Progress.types": "./Progress.types.js",
|
package/theme/darkTheme.js
CHANGED
|
@@ -21,6 +21,15 @@ export const darkTheme = {
|
|
|
21
21
|
'--stsv-Common__outline-style': 'solid',
|
|
22
22
|
'--stsv-Common__outline-width': '2px',
|
|
23
23
|
// disabled
|
|
24
|
+
'--stsv-Common__background-color1--disabled': 'hsla(0, 0%, 0%, 20%)',
|
|
25
|
+
'--stsv-Common__background-color2--disabled': `hsla(0, 0%, 100%, 20%)`,
|
|
26
|
+
'--stsv-Disabled__background': 'repeating-linear-gradient(' +
|
|
27
|
+
'45deg,' +
|
|
28
|
+
'var(--stsv-Common__background-color1--disabled),' +
|
|
29
|
+
'var(--stsv-Common__background-color1--disabled) 3px,' +
|
|
30
|
+
'var(--stsv-Common__background-color2--disabled) 3px,' +
|
|
31
|
+
'var(--stsv-Common__background-color2--disabled) 6px' +
|
|
32
|
+
')',
|
|
24
33
|
'--stsv-Common__background-color--disabled': neutralColors.neutral45,
|
|
25
34
|
'--stsv-Common__border-color--disabled': neutralColors.neutral92,
|
|
26
35
|
'--stsv-Common__color--disabled': neutralColors.neutral60,
|
package/theme/lightTheme.js
CHANGED
|
@@ -21,6 +21,15 @@ export const lightTheme = {
|
|
|
21
21
|
'--stsv-Common__outline-style': 'solid',
|
|
22
22
|
'--stsv-Common__outline-width': '2px',
|
|
23
23
|
// disabled
|
|
24
|
+
'--stsv-Common__background-color1--disabled': 'hsla(0, 0%, 0%, 20%)',
|
|
25
|
+
'--stsv-Common__background-color2--disabled': `hsla(0, 0%, 100%, 20%)`,
|
|
26
|
+
'--stsv-Disabled__background': 'repeating-linear-gradient(' +
|
|
27
|
+
'45deg,' +
|
|
28
|
+
'var(--stsv-Common__background-color1--disabled),' +
|
|
29
|
+
'var(--stsv-Common__background-color1--disabled) 3px,' +
|
|
30
|
+
'var(--stsv-Common__background-color2--disabled) 3px,' +
|
|
31
|
+
'var(--stsv-Common__background-color2--disabled) 6px' +
|
|
32
|
+
')',
|
|
24
33
|
'--stsv-Common__background-color--disabled': neutralColors.neutral96,
|
|
25
34
|
'--stsv-Common__border-color--disabled': neutralColors.neutral75,
|
|
26
35
|
'--stsv-Common__color--disabled': neutralColors.neutral75,
|