@geoffcox/sterling-svelte 0.0.23 → 0.0.24

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/Tree.svelte CHANGED
@@ -100,7 +100,9 @@ setContext(TREE_CONTEXT_KEY, {
100
100
  on:wheel
101
101
  {...$$restProps}
102
102
  >
103
- <slot {composed} {disabled} />
103
+ <div class="container">
104
+ <slot {composed} {disabled} />
105
+ </div>
104
106
  </div>
105
107
 
106
108
  <style>
@@ -112,14 +114,10 @@ setContext(TREE_CONTEXT_KEY, {
112
114
  border-width: var(--stsv-Common__border-width);
113
115
  box-sizing: border-box;
114
116
  color: var(--stsv-Common__color);
115
- display: flex;
116
- flex-direction: column;
117
- flex-wrap: nowrap;
118
117
  height: 100%;
119
118
  overflow-x: hidden;
120
- overflow-y: scroll;
119
+ overflow-y: auto;
121
120
  margin: 0;
122
- position: relative;
123
121
  transition: background-color 250ms, color 250ms, border-color 250ms;
124
122
  }
125
123
 
@@ -137,18 +135,51 @@ setContext(TREE_CONTEXT_KEY, {
137
135
  outline-width: var(--stsv-Common__outline-width);
138
136
  }
139
137
 
140
- .sterling-tree.disabled {
141
- background-color: var(--stsv-Common__background-color--disabled);
142
- border-color: var(--stsv--Common__border-color--disabled);
143
- color: var(--stsv-Common__color--disabled);
144
- cursor: not-allowed;
145
- }
146
-
147
138
  .sterling-tree.composed,
148
139
  .sterling-tree.composed:hover,
149
140
  .sterling-tree.composed.using-keyboard:focus-visible,
150
141
  .sterling-tree.composed.disabled {
142
+ background: none;
151
143
  border: none;
152
144
  outline: none;
153
145
  }
146
+
147
+ .sterling-tree.disabled * {
148
+ cursor: not-allowed;
149
+ }
150
+
151
+ /* ----- container - a layout panel that grows with the items ----- */
152
+
153
+ .container {
154
+ display: flex;
155
+ flex-direction: column;
156
+ flex-wrap: nowrap;
157
+ position: relative;
158
+ }
159
+
160
+ .container::after {
161
+ background: var(--stsv-Disabled__background);
162
+ bottom: 0;
163
+ content: '';
164
+ left: 0;
165
+ opacity: 0;
166
+ position: absolute;
167
+ pointer-events: none;
168
+ right: 0;
169
+ top: 0;
170
+ transition: opacity 250ms;
171
+ }
172
+
173
+ .sterling-tree.disabled .container::after {
174
+ opacity: 1;
175
+ }
176
+
177
+ /* ----- media queries ----- */
178
+
179
+ @media (prefers-reduced-motion) {
180
+ .sterling-tree,
181
+ .container::after {
182
+ transition: none;
183
+ }
184
+ }
154
185
  </style>
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, disabled: parentDisabled } = getContext(TREE_ITEM_CONTEXT_KEY) || {};
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 || $parentDisabled || $treeDisabled;
23
- const disabledStore = writable(_disabled);
22
+ _disabled = disabled || $treeDisabled;
23
+ const disabledStore = writable(disabled);
24
24
  $: {
25
- disabledStore.set(_disabled);
25
+ disabledStore.set(disabled);
26
26
  }
27
27
  const collapseItem = (index) => {
28
- if (!disabled) {
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 (!disabled) {
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 (!disabled) {
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} {disabled} {selected} {value} />
297
+ <slot {depth} {selected} {value} />
298
298
  </div>
299
299
  {/if}
300
300
  </div>
@@ -69,7 +69,6 @@ declare const __propDef: {
69
69
  };
70
70
  default: {
71
71
  depth: number;
72
- disabled: boolean;
73
72
  selected: boolean;
74
73
  value: string;
75
74
  };
@@ -1,10 +1,16 @@
1
- <script>import TreeChevron from "./TreeChevron.svelte";
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geoffcox/sterling-svelte",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "author": "Geoff Cox",
5
5
  "description": "A modern, accessible, and lightweight component library for Svelte.",
6
6
  "license": "MIT",
@@ -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,
@@ -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,