@rancher/shell 1.2.1 → 1.2.2

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.
Files changed (56) hide show
  1. package/package.json +1 -1
  2. package/rancher-components/BadgeState/BadgeState.vue +3 -3
  3. package/rancher-components/Banner/Banner.test.ts +5 -1
  4. package/rancher-components/Banner/Banner.vue +2 -2
  5. package/rancher-components/Card/Card.vue +4 -4
  6. package/rancher-components/Form/Checkbox/Checkbox.vue +3 -4
  7. package/rancher-components/Form/LabeledInput/LabeledInput.test.ts +1 -18
  8. package/rancher-components/Form/LabeledInput/LabeledInput.vue +37 -65
  9. package/rancher-components/Form/Radio/RadioButton.test.ts +3 -1
  10. package/rancher-components/Form/Radio/RadioButton.vue +7 -13
  11. package/rancher-components/Form/Radio/RadioGroup.vue +3 -4
  12. package/rancher-components/Form/TextArea/TextAreaAutoGrow.vue +4 -6
  13. package/rancher-components/Form/ToggleSwitch/ToggleSwitch.vue +4 -7
  14. package/rancher-components/LabeledTooltip/LabeledTooltip.vue +4 -9
  15. package/rancher-components/StringList/StringList.test.ts +0 -270
  16. package/rancher-components/StringList/StringList.vue +26 -65
  17. package/scripts/publish-shell.sh +1 -0
  18. package/rancher-components/Accordion/Accordion.test.ts +0 -45
  19. package/rancher-components/Accordion/Accordion.vue +0 -86
  20. package/rancher-components/Accordion/index.ts +0 -1
  21. package/rancher-components/BadgeState/BadgeState.test.ts +0 -12
  22. package/rancher-components/components/Accordion/Accordion.test.ts +0 -45
  23. package/rancher-components/components/Accordion/Accordion.vue +0 -86
  24. package/rancher-components/components/Accordion/index.ts +0 -1
  25. package/rancher-components/components/BadgeState/BadgeState.test.ts +0 -12
  26. package/rancher-components/components/BadgeState/BadgeState.vue +0 -111
  27. package/rancher-components/components/BadgeState/index.ts +0 -1
  28. package/rancher-components/components/Banner/Banner.test.ts +0 -63
  29. package/rancher-components/components/Banner/Banner.vue +0 -244
  30. package/rancher-components/components/Banner/index.ts +0 -1
  31. package/rancher-components/components/Card/Card.test.ts +0 -37
  32. package/rancher-components/components/Card/Card.vue +0 -167
  33. package/rancher-components/components/Card/index.ts +0 -1
  34. package/rancher-components/components/Form/Checkbox/Checkbox.test.ts +0 -68
  35. package/rancher-components/components/Form/Checkbox/Checkbox.vue +0 -420
  36. package/rancher-components/components/Form/Checkbox/index.ts +0 -1
  37. package/rancher-components/components/Form/LabeledInput/LabeledInput.test.ts +0 -23
  38. package/rancher-components/components/Form/LabeledInput/LabeledInput.vue +0 -369
  39. package/rancher-components/components/Form/LabeledInput/index.ts +0 -1
  40. package/rancher-components/components/Form/Radio/RadioButton.test.ts +0 -35
  41. package/rancher-components/components/Form/Radio/RadioButton.vue +0 -287
  42. package/rancher-components/components/Form/Radio/RadioGroup.test.ts +0 -30
  43. package/rancher-components/components/Form/Radio/RadioGroup.vue +0 -258
  44. package/rancher-components/components/Form/Radio/index.ts +0 -2
  45. package/rancher-components/components/Form/TextArea/TextAreaAutoGrow.vue +0 -170
  46. package/rancher-components/components/Form/TextArea/index.ts +0 -1
  47. package/rancher-components/components/Form/ToggleSwitch/ToggleSwitch.test.ts +0 -94
  48. package/rancher-components/components/Form/ToggleSwitch/ToggleSwitch.vue +0 -149
  49. package/rancher-components/components/Form/ToggleSwitch/index.ts +0 -1
  50. package/rancher-components/components/Form/index.ts +0 -5
  51. package/rancher-components/components/LabeledTooltip/LabeledTooltip.vue +0 -151
  52. package/rancher-components/components/LabeledTooltip/index.ts +0 -1
  53. package/rancher-components/components/StringList/StringList.test.ts +0 -484
  54. package/rancher-components/components/StringList/StringList.vue +0 -611
  55. package/rancher-components/components/StringList/index.ts +0 -1
  56. /package/rancher-components/{components/BadgeState → BadgeState}/BadgeState.spec.ts +0 -0
@@ -1,611 +0,0 @@
1
- <script lang="ts">
2
- import Vue, { PropType } from 'vue';
3
-
4
- import LabeledInput from '@components/Form/LabeledInput/LabeledInput.vue';
5
- import { findStringIndex, hasDuplicatedStrings } from '@shell/utils/array';
6
-
7
- type Error = 'duplicate';
8
- type ErrorMessages = Record<Error, string>;
9
-
10
- type Arrow = 'up' | 'down';
11
-
12
- const DIRECTION: Record<Arrow, number> = {
13
- up: -1,
14
- down: 1,
15
- };
16
-
17
- const INPUT = {
18
- create: 'item-create',
19
- edit: 'item-edit',
20
- };
21
-
22
- const BOX = 'box';
23
-
24
- const CLASS = {
25
- item: 'item',
26
- error: 'error',
27
- };
28
-
29
- /**
30
- * Manage a list of strings
31
- */
32
- export default Vue.extend({
33
-
34
- name: 'StringList',
35
- components: { LabeledInput },
36
-
37
- props: {
38
- /**
39
- * The items source
40
- */
41
- items: {
42
- type: Array as PropType<string[]>,
43
- default() {
44
- return [];
45
- },
46
- },
47
- /**
48
- * Determines if items with same text will be treated differently, depending on the letters case
49
- * It is used to compare items during create/edit actions and detect duplicates.
50
- */
51
- caseSensitive: {
52
- type: Boolean,
53
- default: false,
54
- },
55
- /**
56
- * Determines if the list of items is editable or view-only
57
- */
58
- readonly: {
59
- type: Boolean,
60
- default: false,
61
- },
62
- /**
63
- * The placeholder to show in input field when create or edit items
64
- */
65
- placeholder: {
66
- type: String,
67
- default: null,
68
- },
69
- /**
70
- * Determines the action buttons position at the bottom of the main box
71
- */
72
- actionsPosition: {
73
- type: String,
74
- default: 'right',
75
- },
76
- /**
77
- * Custom Error messages
78
- */
79
- errorMessages: {
80
- type: Object as PropType<ErrorMessages>,
81
- default() {
82
- return {} as ErrorMessages;
83
- },
84
- },
85
- },
86
- data() {
87
- return {
88
- value: null as string | null,
89
- selected: null as string | null,
90
- editedItem: null as string | null,
91
- isCreateItem: false,
92
- errors: { duplicate: false } as Record<Error, boolean>
93
- };
94
- },
95
-
96
- computed: {
97
-
98
- /**
99
- * Create an array of error messages, one for each current error
100
- */
101
- errorMessagesArray(): string[] {
102
- return (Object.keys(this.errors) as Error[])
103
- .filter((f) => this.errors[f] && this.errorMessages[f])
104
- .map((k) => this.errorMessages[k]);
105
- },
106
- },
107
-
108
- watch: {
109
- /**
110
- * Shutdown any user actions on the component when it becomes readonly
111
- */
112
- readonly() {
113
- this.toggleEditMode(false);
114
- this.toggleCreateMode(false);
115
- },
116
- value(val) {
117
- this.$emit('type:item', val);
118
- },
119
- errors: {
120
- handler(val) {
121
- this.$emit('errors', val);
122
- },
123
- deep: true
124
- }
125
- },
126
-
127
- methods: {
128
- onChange(value: string) {
129
- this.value = value;
130
-
131
- const items = [
132
- ...this.items,
133
- this.value
134
- ];
135
-
136
- this.toggleError(
137
- 'duplicate',
138
- hasDuplicatedStrings(items, this.caseSensitive),
139
- this.isCreateItem ? INPUT.create : INPUT.edit
140
- );
141
- },
142
-
143
- onSelect(item: string) {
144
- if (this.readonly || this.isCreateItem || this.editedItem === item) {
145
- return;
146
- }
147
- this.selected = item;
148
- },
149
-
150
- onSelectNext(arrow: Arrow) {
151
- const index = findStringIndex(
152
- this.items,
153
- this.selected as string,
154
- );
155
-
156
- if (index !== -1) {
157
- /**
158
- * Select next item in the arrow's direction if it exists,
159
- * else select again this.selected (do nothing)
160
- */
161
- const item = (this.items[index + DIRECTION[arrow]] || this.selected) as string;
162
-
163
- this.onSelect(item);
164
- this.moveScrollbar(arrow);
165
- }
166
- },
167
-
168
- onSelectLeave(item?: string) {
169
- if (item === this.selected) {
170
- this.selected = null;
171
- }
172
- },
173
-
174
- onClickEmptyBody() {
175
- if (!this.isCreateItem && !this.editedItem) {
176
- this.toggleCreateMode(true);
177
- }
178
- },
179
-
180
- onClickPlusButton() {
181
- this.onSelectLeave();
182
- this.toggleCreateMode(true);
183
- },
184
-
185
- onClickMinusButton() {
186
- if (this.isCreateItem) {
187
- this.toggleCreateMode(false);
188
-
189
- return;
190
- }
191
- if (this.editedItem) {
192
- this.deleteAndSelectNext(this.editedItem);
193
- this.toggleEditMode(false);
194
-
195
- return;
196
- }
197
- if (this.selected) {
198
- this.deleteAndSelectNext(this.selected);
199
- }
200
- },
201
-
202
- deleteAndSelectNext(currItem: string) {
203
- const index = findStringIndex(this.items, currItem, false);
204
-
205
- if (index !== -1) {
206
- /**
207
- * Select the next item in the list.
208
- */
209
- const item = (this.items[index + 1] || this.items[index - 1]);
210
-
211
- this.onSelect(item);
212
- this.setFocus(item);
213
-
214
- this.deleteItem(this.items[index]);
215
- }
216
- },
217
-
218
- setFocus(refId: string) {
219
- this.$nextTick(() => (this.getElemByRef(refId) as Vue & HTMLElement)?.focus());
220
- },
221
-
222
- /**
223
- * Move scrollbar when the selected item is over the top or bottom side of the box
224
- */
225
- moveScrollbar(arrow: Arrow, value?: number) {
226
- const box = this.getElemByRef(BOX) as HTMLElement;
227
- const item = this.getElemByRef(this.selected || '') as HTMLElement;
228
-
229
- if (box && item && item.className.includes(CLASS.item)) {
230
- const boxRect = box.getClientRects()[0];
231
- const itemRect = item.getClientRects()[0];
232
-
233
- if (
234
- (arrow === 'down' && itemRect.bottom > boxRect.bottom) ||
235
- (arrow === 'up' && itemRect.top < boxRect.top)
236
- ) {
237
- const top = (value ?? itemRect.height) * DIRECTION[arrow];
238
-
239
- box.scrollBy({ top });
240
- }
241
- }
242
- },
243
-
244
- /**
245
- * Set an error and eventually assign an error class to the element
246
- */
247
- toggleError(type: Error, val: boolean, refId?: string) {
248
- this.errors[type] = val;
249
-
250
- if (refId) {
251
- this.toggleErrorClass(refId, val);
252
- }
253
- },
254
-
255
- toggleErrorClass(refId: string, val: boolean) {
256
- const input = (this.getElemByRef(refId) as Vue)?.$el;
257
-
258
- if (input) {
259
- if (val) {
260
- input.classList.add(CLASS.error);
261
- } else {
262
- input.classList.remove(CLASS.error);
263
- }
264
- }
265
- },
266
-
267
- /**
268
- * Show/Hide the input line to create new item
269
- */
270
- toggleCreateMode(show: boolean) {
271
- if (this.readonly) {
272
- return;
273
- }
274
- if (show) {
275
- this.toggleEditMode(false);
276
- this.value = '';
277
-
278
- this.isCreateItem = true;
279
- this.setFocus(INPUT.create);
280
- } else {
281
- this.value = null;
282
- this.toggleError('duplicate', false);
283
- this.onSelectLeave();
284
-
285
- this.isCreateItem = false;
286
- }
287
- },
288
-
289
- /**
290
- * Show/Hide the in-line editing to edit an existing item
291
- */
292
- toggleEditMode(show: boolean, item?: string) {
293
- if (this.readonly) {
294
- return;
295
- }
296
- if (show) {
297
- this.toggleCreateMode(false);
298
- this.value = this.editedItem;
299
-
300
- this.editedItem = item || '';
301
- this.setFocus(INPUT.edit);
302
- } else {
303
- this.value = null;
304
- this.toggleError('duplicate', false);
305
- this.onSelectLeave();
306
-
307
- this.editedItem = null;
308
- }
309
- },
310
-
311
- getElemByRef(id: string) {
312
- const ref = this.$refs[id];
313
-
314
- return Array.isArray(ref) ? ref[0] : ref;
315
- },
316
-
317
- /**
318
- * Create a new item and insert in the items list
319
- */
320
- saveItem(closeInput = true) {
321
- const value = this.value?.trim();
322
-
323
- if (value) {
324
- const items = [
325
- ...this.items,
326
- value,
327
- ];
328
-
329
- if (!hasDuplicatedStrings(items, this.caseSensitive)) {
330
- this.updateItems(items);
331
- }
332
- }
333
-
334
- if (closeInput) {
335
- this.toggleCreateMode(false);
336
- }
337
- },
338
-
339
- /**
340
- * Update an existing item in the items list
341
- */
342
- updateItem(item: string, closeInput = true) {
343
- const value = this.value?.trim();
344
-
345
- if (value) {
346
- const items = [...this.items];
347
- const index = findStringIndex(items, item, false);
348
-
349
- if (index !== -1) {
350
- items[index] = value;
351
- }
352
-
353
- if (!hasDuplicatedStrings(items, this.caseSensitive)) {
354
- this.updateItems(items);
355
- }
356
- }
357
-
358
- if (closeInput) {
359
- this.toggleEditMode(false);
360
- }
361
- },
362
-
363
- /**
364
- * Remove an item from items list
365
- */
366
- deleteItem(item?: string) {
367
- const items = this.items.filter((f) => f !== item);
368
-
369
- this.updateItems(items);
370
- },
371
-
372
- /**
373
- * Update items list and emit to parent component
374
- */
375
- updateItems(items: string[]) {
376
- this.$emit('change', items);
377
- },
378
- },
379
-
380
- });
381
- </script>
382
-
383
- <template>
384
- <div
385
- class="string-list"
386
- :class="{ readonly }"
387
- >
388
- <div
389
- ref="box"
390
- data-testid="div-string-list-box"
391
- class="string-list-box"
392
- tabindex="0"
393
- @dblclick="onClickEmptyBody()"
394
- >
395
- <div
396
- v-for="item in items"
397
- :key="item"
398
- :ref="item"
399
- :class="{
400
- selected: selected === item,
401
- readonly
402
- }"
403
- :data-testid="`div-item-${item}`"
404
- class="item static"
405
- tabindex="0"
406
- @mousedown="onSelect(item)"
407
- @dblclick.stop="toggleEditMode(true, item)"
408
- @keydown.down.prevent="onSelectNext('down')"
409
- @keydown.up.prevent="onSelectNext('up')"
410
- @blur="onSelectLeave(item)"
411
- >
412
- <span
413
- v-if="!editedItem || editedItem !== item"
414
- class="label static"
415
- >
416
- {{ item }}
417
- </span>
418
- <LabeledInput
419
- v-if="editedItem && editedItem === item"
420
- ref="item-edit"
421
- :data-testid="`item-edit-${item}`"
422
- class="edit-input static"
423
- :value="value != null ? value : item"
424
- @input="onChange($event)"
425
- @blur.prevent="updateItem(item)"
426
- @keydown.native.enter="updateItem(item, !errors.duplicate)"
427
- />
428
- </div>
429
- <div
430
- v-if="isCreateItem"
431
- class="create-field static"
432
- >
433
- <LabeledInput
434
- ref="item-create"
435
- data-testid="item-create"
436
- class="create-input static"
437
- type="text"
438
- :value="value"
439
- :placeholder="placeholder"
440
- @input="onChange($event)"
441
- @blur.prevent="saveItem"
442
- @keydown.native.enter="saveItem(!errors.duplicate)"
443
- />
444
- </div>
445
- </div>
446
- <div
447
- v-if="!readonly"
448
- class="string-list-footer"
449
- :class="{[actionsPosition]: true }"
450
- >
451
- <div
452
- data-testid="div-action-buttons"
453
- class="action-buttons"
454
- >
455
- <button
456
- data-testid="button-remove"
457
- class="btn btn-sm role-tertiary remove-button"
458
- :disabled="!selected && !isCreateItem && !editedItem"
459
- @mousedown.prevent="onClickMinusButton"
460
- >
461
- <span class="icon icon-minus icon-sm" />
462
- </button>
463
- <button
464
- data-testid="button-add"
465
- class="btn btn-sm role-tertiary add-button"
466
- :disabled="isCreateItem || editedItem"
467
- @click.prevent="onClickPlusButton"
468
- >
469
- <span class="icon icon-plus icon-sm" />
470
- </button>
471
- </div>
472
- <div class="messages">
473
- <i
474
- v-if="errorMessagesArray.length > 0"
475
- data-testid="i-warning-icon"
476
- class="icon icon-warning icon-lg"
477
- />
478
- <span
479
- v-for="(msg, idx) in errorMessagesArray"
480
- :key="idx"
481
- :data-testid="`span-error-message-${msg}`"
482
- class="error"
483
- >
484
- {{ idx > 0 ? '; ' : '' }}
485
- {{ msg }}
486
- </span>
487
- </div>
488
- </div>
489
- </div>
490
- </template>
491
-
492
- <style lang="scss" scoped>
493
-
494
- .string-list {
495
- display: flex;
496
- flex-direction: column;
497
- width: auto;
498
-
499
- &.readonly {
500
- cursor: default;
501
- opacity: 0.4;
502
- }
503
-
504
- .string-list-box {
505
- min-height: 200px;
506
- height: 100%;
507
- outline: none;
508
- overflow-y: auto;
509
- overflow-x: hidden;
510
- border: solid var(--border-width) var(--input-border);
511
- padding-top: 3px;
512
-
513
- .static {
514
- height: 25px;
515
- padding: 3px;
516
- }
517
-
518
- .item {
519
- outline: none;
520
-
521
- &.selected {
522
- background: var(--primary);
523
- color: var(--primary-hover-text);
524
- }
525
-
526
- &.readonly {
527
- pointer-events: none;
528
- }
529
-
530
- .label {
531
- display: block;
532
- width: auto;
533
- user-select: none;
534
- overflow: hidden;
535
- white-space: no-wrap;
536
- text-overflow: ellipsis;
537
- padding-top: 1px;
538
- }
539
- }
540
-
541
- .create-field {
542
- padding-top: 1px;
543
- margin-bottom: 7px;
544
- }
545
-
546
- .labeled-input {
547
- padding-top: 0;
548
- padding-bottom: 0;
549
- border-radius: 0;
550
- &.error {
551
- border: none;
552
- box-shadow: 0 0 0 var(--outline-width) var(--error);
553
- }
554
- }
555
- }
556
-
557
- .string-list-footer {
558
- --footer-height: 28px;
559
- height: var(--footer-height);
560
- margin-top: 5px;
561
- display: flex;
562
- justify-content: space-between;
563
- gap: 0.5rem;
564
-
565
- &.left {
566
- flex-direction: row;
567
- }
568
-
569
- &.right {
570
- flex-direction: row-reverse;
571
- }
572
-
573
- .action-buttons {
574
- display: flex;
575
- flex-direction: row-reverse;
576
- gap: 0.5rem;
577
-
578
- .btn {
579
- min-height: var(--footer-height);
580
- line-height: 0;
581
- border-radius: 2px;
582
-
583
- &:disabled {
584
- cursor: default;
585
- pointer-events: none;
586
- }
587
- }
588
- }
589
-
590
- .messages {
591
- line-height: var(--footer-height);
592
-
593
- .error, .icon-warning {
594
- color: var(--error);
595
- line-height: inherit;
596
- }
597
- }
598
- }
599
- }
600
-
601
- ::v-deep {
602
- .labeled-input INPUT.no-label,
603
- .labeled-input INPUT:hover.no-label,
604
- .labeled-input INPUT:focus.no-label {
605
- padding: 1px 0px 0px 0px;
606
- }
607
- .labeled-input.compact-input {
608
- min-height: 0;
609
- }
610
- }
611
- </style>
@@ -1 +0,0 @@
1
- export { default as StringList } from './StringList.vue';