@poirazis/supercomponents-shared 1.0.26 → 1.0.28

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.
@@ -62,17 +62,17 @@
62
62
  class:sticky
63
63
  class:zebra={$stbSettings.appearance.zebraColors}
64
64
  >
65
- {#each $stbVisibleRows as index}
65
+ {#each $stbVisibleRows as visibleRow}
66
+ {@const row = $stbData?.rows?.[visibleRow]}
66
67
  <div
67
68
  class="super-row"
68
- on:mouseenter={() => ($stbHovered = index)}
69
+ on:mouseenter={() => ($stbHovered = visibleRow)}
69
70
  on:mouseleave={() => ($stbHovered = null)}
70
- class:is-selected={$stbSelected?.includes(
71
- $stbData.rows[index][idColumn]
72
- )}
73
- class:is-hovered={$stbHovered == index || $stbMenuID == index}
74
- class:is-editing={$stbEditing == index}
75
- style:min-height={$rowMetadata[index].height}
71
+ class:is-selected={$stbSelected?.includes(row[idColumn] ?? visibleRow)}
72
+ class:is-hovered={$stbHovered == visibleRow || $stbMenuID == visibleRow}
73
+ class:is-editing={$stbEditing == visibleRow}
74
+ class:is-disabled={$rowMetadata[visibleRow].disabled}
75
+ style:min-height={$rowMetadata[visibleRow].height}
76
76
  style:padding-right={canScroll && right ? "1.5rem" : "0.5rem"}
77
77
  >
78
78
  <!-- svelte-ignore a11y-click-events-have-key-events -->
@@ -86,10 +86,14 @@
86
86
  size="S"
87
87
  {icon}
88
88
  {text}
89
- disabled={disabled || $stbEditing == index}
89
+ disabled={disabled ||
90
+ $stbEditing == visibleRow ||
91
+ $rowMetadata[visibleRow].disabled}
90
92
  {quiet}
91
93
  type={type == "primary" ? "ink" : type}
92
- on:click={() => stbAPI.executeRowButtonAction(index, onClick)}
94
+ on:click={() => {
95
+ stbAPI.executeRowButtonAction(visibleRow, onClick);
96
+ }}
93
97
  />
94
98
  {/each}
95
99
  {/if}
@@ -101,7 +105,7 @@
101
105
  text=""
102
106
  quiet="true"
103
107
  type="secondary"
104
- on:click={(e) => handleMenu(e, index)}
108
+ on:click={(e) => handleMenu(e, visibleRow)}
105
109
  />
106
110
  {/if}
107
111
  </div>
@@ -157,6 +161,7 @@
157
161
  flex-direction: row;
158
162
  align-items: center;
159
163
  padding-left: 0.5rem;
164
+ background: transparent;
160
165
  }
161
166
 
162
167
  .action-menu {
@@ -8,7 +8,6 @@
8
8
  const stbHovered = getContext("stbHovered");
9
9
  const stbMenuID = getContext("stbMenuID");
10
10
  const stbSelected = getContext("stbSelected");
11
- const stbEditing = getContext("stbEditing");
12
11
  const stbAPI = getContext("stbAPI");
13
12
  const rowMetadata = getContext("stbRowMetadata");
14
13
  const stbVisibleRows = getContext("stbVisibleRows");
@@ -17,13 +16,16 @@
17
16
  export let hideSelectionColumn;
18
17
 
19
18
  $: idColumn = $stbSettings.data.idColumn;
20
- $: partialSelection = $stbSelected.length;
19
+ $: partialSelection =
20
+ $stbSelected.length && $stbSelected.length != $stbData.rows?.length;
21
+
21
22
  $: fullSelection =
22
23
  $stbSelected.length == $stbData.rows?.length && $stbData.rows?.length > 0;
23
24
 
24
25
  $: numbering = $stbSettings.appearance.numberingColumn;
25
26
  $: checkBoxes = $stbSettings.features.canSelect && !hideSelectionColumn;
26
27
  $: canDelete = $stbSettings.features.canDelete;
28
+
27
29
  $: sticky = $stbHorizontalScrollPos > 0;
28
30
 
29
31
  $: visible = numbering || checkBoxes || canDelete;
@@ -36,36 +38,30 @@
36
38
  {#if visible}
37
39
  <div class="super-column control-column" class:sticky>
38
40
  {#if $stbSettings?.showHeader}
39
- <div class="control-column-header">
41
+ <div class="control-column-header" style:gap={"1rem"}>
40
42
  {#if numbering}
41
- <div class="row-number"></div>
43
+ <span class="row-number"></span>
44
+ {/if}
45
+
46
+ {#if checkBoxes && $stbSettings.features.maxSelected != 1}
47
+ <div
48
+ class="checkbox"
49
+ class:selected={fullSelection}
50
+ class:partialSelection
51
+ on:click={stbAPI.selectAllRows}
52
+ >
53
+ <i class="ri-check-line" style:visibility={"hidden"} />
54
+ </div>
42
55
  {/if}
43
56
 
44
57
  {#if canDelete}
45
- {#if $stbSelected.length > 1}
58
+ {#if $stbSelected.length}
46
59
  <i
47
- class="ri-delete-bin-line"
60
+ class="ri-delete-bin-line delete"
48
61
  on:click={stbAPI.deleteSelectedRows}
49
62
  />
50
63
  {:else}
51
- <div class="row-number"></div>
52
- {/if}
53
- {/if}
54
-
55
- {#if $stbSettings.features.canSelect && $stbSettings.features.maxSelected != 1 && !hideSelectionColumn}
56
- {#if fullSelection}
57
- <i class="ri-check-line" on:click={stbAPI.selectAllRows} />
58
- {:else if partialSelection}
59
- <i
60
- class="ri-checkbox-indeterminate-line"
61
- on:click={stbAPI.selectAllRows}
62
- ></i>
63
- {:else}
64
- <i
65
- class="ri-checkbox-blank-line"
66
- style:color={"var(--spectrum-global-color-gray-500)"}
67
- on:click={stbAPI.selectAllRows}
68
- />
64
+ <i class="ri-delete-bin-line disabled" />
69
65
  {/if}
70
66
  {/if}
71
67
  </div>
@@ -80,54 +76,41 @@
80
76
  >
81
77
  {#each $stbVisibleRows as visibleRow}
82
78
  {@const row = $stbData?.rows?.[visibleRow]}
79
+ {@const selected = $stbSelected?.includes(row[idColumn] ?? visibleRow)}
83
80
  {#if row}
84
81
  <div
85
82
  class="super-row selection"
86
- class:is-selected={$stbSelected?.includes(
87
- row[idColumn] ?? visibleRow
88
- )}
83
+ class:is-selected={selected}
89
84
  class:is-hovered={$stbHovered == visibleRow ||
90
85
  $stbMenuID == visibleRow}
91
- class:is-editing={$stbEditing == row[idColumn]}
86
+ class:is-disabled={$rowMetadata[visibleRow]?.disabled}
92
87
  style:min-height={$rowMetadata[visibleRow]?.height}
93
88
  on:mouseenter={() => ($stbHovered = visibleRow)}
94
89
  on:mouseleave={() => ($stbHovered = null)}
95
90
  >
96
91
  {#if numbering}
97
- <span class="row-number">
98
- {#if $stbEditing == row[idColumn]}
99
- <i
100
- class="ri-edit-line"
101
- style:font-size={"14px"}
102
- style:color={"lime"}
103
- />
104
- {:else}
105
- {visibleRow + 1}
106
- {/if}
107
- </span>
92
+ <div class="row-number">
93
+ {visibleRow + 1}
94
+ </div>
95
+ {/if}
96
+
97
+ {#if $stbSettings.features.canSelect && !hideSelectionColumn}
98
+ <div
99
+ class="checkbox"
100
+ class:selected
101
+ on:click={() => stbAPI.selectRow(visibleRow)}
102
+ >
103
+ <i class="ri-check-line" style:visibility={"hidden"} />
104
+ </div>
108
105
  {/if}
109
106
 
110
107
  {#if canDelete}
111
108
  <i
112
109
  class="ri-delete-bin-line delete"
110
+ class:selected
113
111
  on:click={(e) => stbAPI.deleteRow(visibleRow)}
114
112
  />
115
113
  {/if}
116
-
117
- {#if $stbSettings.features.canSelect && !hideSelectionColumn}
118
- {#if $stbSelected?.includes(row[idColumn] ?? visibleRow)}
119
- <i
120
- class="ri-check-line"
121
- style:color={"var(--spectrum-global-color-gray-800)"}
122
- on:click={() => stbAPI.selectRow(visibleRow)}
123
- />
124
- {:else}
125
- <i
126
- class="ri-checkbox-blank-line"
127
- on:click={() => stbAPI.selectRow(visibleRow)}
128
- />
129
- {/if}
130
- {/if}
131
114
  </div>
132
115
  {/if}
133
116
  {/each}
@@ -149,26 +132,68 @@
149
132
  padding-left: 0.75rem;
150
133
  padding-right: 0.75rem;
151
134
  gap: 1rem;
152
- font-size: 14px;
135
+ font-size: 13px;
153
136
  font-weight: 500;
154
137
  align-items: center;
155
138
  &.is-hovered > .delete {
156
- color: var(--spectrum-global-color-red-700);
139
+ color: var(--spectrum-global-color-red-700) !important;
157
140
  }
158
141
  &.is-selected > .delete {
159
- color: var(--spectrum-global-color-red-700);
142
+ color: var(--spectrum-global-color-red-400);
160
143
  }
161
- &.is-hovered > i {
144
+ &.is-hovered > i:not(.delete) {
162
145
  color: var(--spectrum-global-color-gray-700);
163
146
  }
164
147
  }
165
148
 
166
149
  i {
167
- font-size: 16px;
150
+ font-size: 14px;
168
151
  color: var(--spectrum-global-color-gray-500);
169
152
 
170
- &:hover {
153
+ &.disabled {
154
+ color: var(--spectrum-global-color-gray-100);
155
+ }
156
+
157
+ &.delete {
158
+ &.selected {
159
+ color: var(--spectrum-global-color-red-400);
160
+ }
161
+
162
+ &:hover {
163
+ color: var(--spectrum-global-color-red-700);
164
+ }
165
+ }
166
+
167
+ &.full {
168
+ color: var(--spectrum-global-color-gray-900);
169
+ }
170
+
171
+ &:hover:not(.disabled) {
171
172
  cursor: pointer;
172
173
  }
173
174
  }
175
+
176
+ .checkbox {
177
+ width: 16px;
178
+ height: 16px;
179
+ border: 1px solid var(--spectrum-global-color-gray-500);
180
+ background-color: var(--spectrum-global-color-gray-50);
181
+ border-radius: 2px;
182
+ display: flex;
183
+ align-items: center;
184
+ justify-content: center;
185
+ cursor: pointer;
186
+
187
+ &.selected {
188
+ border: 1px solid var(--spectrum-global-color-gray-600);
189
+ & > i {
190
+ visibility: visible !important;
191
+ color: var(--spectrum-global-color-gray-700);
192
+ }
193
+ }
194
+
195
+ &.partialSelection {
196
+ border-color: var(--spectrum-global-color-green-700);
197
+ }
198
+ }
174
199
  </style>
@@ -40,11 +40,11 @@
40
40
  $: left = ($stbHorizontalScrollPos / scrollWidth) * 100 + "%";
41
41
  $: height = (clientHeight / scrollHeight) * 100 + "%";
42
42
  $: verticalRange = Math.max(scrollHeight - clientHeight, 0);
43
+ $: horizontalRange = anchor?.scrollWidth - anchor?.clientWidth;
43
44
  $: calculate(localWidth, $stbScrollPos);
44
45
 
45
46
  export const calculate = () => {
46
47
  if (!anchor) return;
47
- horizontalRange = anchor?.scrollWidth - anchor?.clientWidth;
48
48
  visible = verticalRange;
49
49
  horizontalVisible = horizontalRange;
50
50
  scrollWidth = anchor?.scrollWidth;
@@ -73,6 +73,8 @@
73
73
  $: inline = cellOptions.role == "inlineInput";
74
74
  $: inEdit = $cellState == "Editing";
75
75
  $: isDirty = inEdit && originalValue !== value;
76
+ $: checkbox = cellOptions?.controlType == "checkbox";
77
+ $: tableCell = cellOptions.role == "tableCell";
76
78
 
77
79
  const focus = (node) => {
78
80
  if (cellOptions.role == "tableCell") node.focus();
@@ -85,10 +87,10 @@
85
87
  <div
86
88
  class="superCell"
87
89
  class:inEdit
88
- class:isDirty
90
+ class:isDirty={isDirty && cellOptions.showDirty}
89
91
  class:inline
90
- class:tableCell={cellOptions.role == "tableCell"}
91
- class:formInput={cellOptions.role == "formInput"}
92
+ class:naked-field={!tableCell}
93
+ class:tableCell
92
94
  class:disabled={cellOptions.disabled}
93
95
  class:readonly={cellOptions.readonly}
94
96
  style:color={cellOptions.color}
@@ -96,29 +98,43 @@
96
98
  ? "var(--spectrum-global-color-gray-50)"
97
99
  : cellOptions.background}
98
100
  style:font-weight={cellOptions.fontWeight}
99
- style:padding-top={"unset"}
100
- style:padding-bottom={"unset"}
101
101
  >
102
102
  {#if cellOptions.icon}
103
- <i class={cellOptions.icon + " frontIcon"}></i>
103
+ <i class={cellOptions.icon + " icon"}></i>
104
104
  {/if}
105
105
 
106
106
  {#if $cellState == "Editing" || cellOptions.role != "tableCell"}
107
107
  <div
108
108
  class="editor"
109
- style:padding-left={cellOptions.icon ? "32px" : cellOptions.padding}
110
- style:padding-right={cellOptions.clearValueIcon
111
- ? "32px"
112
- : cellOptions.padding}
109
+ class:with-icon={cellOptions.icon}
110
+ class:naked-field={!tableCell}
113
111
  style:justify-content={cellOptions.align ?? "center"}
112
+ on:mousedown|self|preventDefault|stopPropagation={$cellState == "Editing"
113
+ ? () => {
114
+ value = !value;
115
+ }
116
+ : () => {
117
+ cellState.focus();
118
+ }}
114
119
  >
115
- <div
116
- class="spectrum-Switch spectrum-Switch--emphasized"
117
- style:--spectrum-switch-height={"22px"}
118
- style:margin={0}
119
- >
120
+ {#if !checkbox}
121
+ <div class="spectrum-Switch spectrum-Switch--emphasized">
122
+ <input
123
+ class="spectrum-Switch-input"
124
+ bind:checked={value}
125
+ bind:this={editor}
126
+ type="checkbox"
127
+ disabled={cellOptions.disabled || cellOptions.readonly}
128
+ on:focusin={cellState.focus}
129
+ on:focusout={cellState.submit}
130
+ on:change={cellState.change}
131
+ use:focus
132
+ />
133
+ <span class="spectrum-Switch-switch" />
134
+ </div>
135
+ {:else}
120
136
  <input
121
- class="spectrum-Switch-input"
137
+ class="checkbox"
122
138
  bind:checked={value}
123
139
  bind:this={editor}
124
140
  type="checkbox"
@@ -128,31 +144,23 @@
128
144
  on:change={cellState.change}
129
145
  use:focus
130
146
  />
131
- <span class="spectrum-Switch-switch" />
132
- </div>
147
+ {/if}
133
148
  </div>
134
149
  {:else}
135
150
  <div
136
151
  class="value"
137
152
  tabIndex="0"
138
153
  style:justify-content={cellOptions.align ?? "center"}
139
- style:padding-left={cellOptions.icon ? "32px" : cellOptions.padding}
154
+ class:with-icon={cellOptions.icon}
140
155
  on:focusin={cellState.focus}
141
156
  >
142
157
  {#if formattedValue}
143
158
  {formattedValue}
144
159
  {:else if value}
145
- <i class="ri-check-line icon"></i>
160
+ <i class="ri-check-line valueicon"></i>
146
161
  {:else if cellOptions.showFalse}
147
- <i class="ri-close-line icon"></i>
162
+ <i class="ri-close-line valueicon"></i>
148
163
  {/if}
149
164
  </div>
150
165
  {/if}
151
166
  </div>
152
-
153
- <style>
154
- .icon {
155
- font-size: 16px;
156
- color: var(--spectrum-global-color-green-400);
157
- }
158
- </style>
@@ -39,7 +39,11 @@
39
39
  position: absolute;
40
40
  right: 8px;
41
41
  color: var(--spectrum-global-color-red-500);
42
- cursor: pointer;
42
+
43
+ &:hover {
44
+ color: var(--spectrum-global-color-red-700);
45
+ cursor: pointer;
46
+ }
43
47
  }
44
48
 
45
49
  .value {
@@ -57,23 +61,27 @@
57
61
  }
58
62
 
59
63
  &.placeholder {
60
- font-style: italic;
61
64
  font-weight: 400;
62
65
  color: var(--spectrum-global-color-gray-500);
63
66
  justify-content: space-between;
64
67
  overflow: hidden;
65
68
  text-overflow: ellipsis;
66
69
  white-space: nowrap;
70
+
71
+ & > span {
72
+ font-style: italic !important;
73
+ }
67
74
  }
68
75
 
69
76
  &.with-icon {
70
77
  padding-left: 2rem !important;
71
78
  }
72
79
 
73
- span {
80
+ & > span {
74
81
  overflow: hidden;
75
82
  text-overflow: ellipsis;
76
83
  white-space: nowrap;
84
+ padding-right: 2.5rem;
77
85
 
78
86
  &.multiline {
79
87
  overflow: auto;
@@ -90,8 +98,15 @@
90
98
  }
91
99
 
92
100
  .controlIcon {
101
+ position: absolute;
93
102
  color: var(--spectrum-global-color-gray-600);
94
103
  cursor: pointer;
104
+ right: 0.5rem;
105
+ }
106
+
107
+ & > .valueicon {
108
+ font-size: 16px;
109
+ color: var(--spectrum-global-color-green-700);
95
110
  }
96
111
 
97
112
  .items {
@@ -101,11 +116,14 @@
101
116
  align-items: stretch;
102
117
  align-self: stretch;
103
118
  gap: 0.5rem;
119
+ margin-right: 1rem;
120
+ padding: 0.15rem 0rem;
104
121
 
105
122
  .item {
106
123
  display: flex;
107
124
  align-items: center;
108
125
  overflow: hidden;
126
+ padding: 0.15rem 0.5rem;
109
127
 
110
128
  i {
111
129
  display: none;
@@ -127,8 +145,7 @@
127
145
  );
128
146
  gap: 0.5rem;
129
147
  border-radius: 4px;
130
- padding-left: 0.75rem;
131
- padding-right: 0.75rem;
148
+
132
149
  i {
133
150
  display: none;
134
151
  }
@@ -139,8 +156,6 @@
139
156
  .item {
140
157
  gap: 0.5rem;
141
158
  border-radius: 4px;
142
- padding-left: 0.75rem;
143
- padding-right: 0.75rem;
144
159
  background-color: var(
145
160
  --option-color,
146
161
  var(--spectrum-global-color-gray-300)
@@ -158,14 +173,14 @@
158
173
  }
159
174
  }
160
175
  }
176
+
161
177
  .items.colorText {
162
178
  .item {
163
179
  gap: 0.5rem;
164
- margin-top: 4px;
165
- margin-bottom: 4px;
180
+ padding: unset;
166
181
 
167
182
  i {
168
- font-size: larger;
183
+ font-size: 18px;
169
184
  color: var(--option-color);
170
185
  display: block;
171
186
  }
@@ -188,14 +203,54 @@
188
203
  }
189
204
  }
190
205
 
191
- .item-count {
192
- border-radius: 50%;
193
- background-color: var(--spectrum-global-color-gray-200);
194
- width: 1.7rem;
195
- aspect-ratio: 1;
196
- display: flex;
197
- align-items: center;
198
- justify-content: center;
206
+ .items.withCount {
207
+ &.inEdit {
208
+ margin-right: 2.5rem;
209
+ }
210
+
211
+ & > .count {
212
+ flex: none;
213
+ font-weight: light;
214
+ color: var(--spectrum-global-color-gray-700);
215
+ }
216
+ }
217
+ }
218
+
219
+ &.error {
220
+ border: 1px solid var(--spectrum-global-color-red-400) !important;
221
+ }
222
+
223
+ & *.checkbox {
224
+ appearance: none;
225
+ width: 16px;
226
+ height: 16px;
227
+ border-radius: 2px;
228
+ position: relative;
229
+ background: var(--spectrum-global-color-gray-50);
230
+ border: 1px solid var(--spectrum-global-color-gray-500);
231
+ }
232
+ & *.checkbox:checked::before {
233
+ content: "\2713";
234
+ position: absolute;
235
+ top: 0px;
236
+ left: 2px;
237
+ color: var(--spectrum-global-color-green-400);
238
+ font-size: 12px;
239
+ }
240
+
241
+ & *.checkbox:focus {
242
+ outline: none;
243
+ }
244
+
245
+ &.naked-field,
246
+ & > .naked-field {
247
+ background-color: unset !important;
248
+ padding-left: 2px !important;
249
+ border-color: transparent !important;
250
+ border-width: 0px !important;
251
+
252
+ &.with-icon {
253
+ padding-left: 32px !important;
199
254
  }
200
255
  }
201
256
  }
@@ -250,8 +305,15 @@
250
305
  min-height: unset;
251
306
  border: 1px solid transparent;
252
307
 
308
+ &:hover:not(.readonly):not(.inEdit) {
309
+ border: 1px dashed var(--spectrum-global-color-blue-400);
310
+ cursor: pointer;
311
+ }
312
+
253
313
  &.inEdit {
254
- border-color: var(--spectrum-global-color-blue-500);
314
+ border-color: var(--spectrum-global-color-blue-400);
315
+ cursor: pointer;
316
+ background-color: var(--spectrum-global-color-gray-50);
255
317
  }
256
318
  }
257
319
 
@@ -270,6 +332,7 @@
270
332
  outline: none;
271
333
  border: none;
272
334
  color: inherit;
335
+ letter-spacing: inherit;
273
336
 
274
337
  &:focus {
275
338
  outline: none;
@@ -312,11 +375,13 @@
312
375
  min-height: 1.8rem;
313
376
  min-width: unset;
314
377
  }
378
+
315
379
  .superCell.inline.disabled {
316
380
  background-color: var(--spectrum-global-color-gray-100) !important;
317
381
  color: var(--spectrum-global-color-gray-600);
318
382
  cursor: not-allowed;
319
383
  }
384
+
320
385
  .superCell.inline.readonly {
321
386
  background-color: var(--spectrum-global-color-gray-100);
322
387
  color: var(--spectrum-global-color-gray-600);