tide-design-system 2.1.4 → 2.1.6

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.
@@ -31,24 +31,31 @@ export const CSS = {
31
31
  START: 'tide-axis2-start',
32
32
  },
33
33
  BG: {
34
+ GLOBAL: {
35
+ PRIMARY: {
36
+ ERROR: 'tide-bg-primary-error',
37
+ INFO: 'tide-bg-primary-info',
38
+ SUCCESS: 'tide-bg-primary-success',
39
+ WARNING: 'tide-bg-primary-warning',
40
+ },
41
+ SURFACE: {
42
+ ERROR: 'tide-bg-surface-error',
43
+ INFO: 'tide-bg-surface-info',
44
+ SUCCESS: 'tide-bg-surface-success',
45
+ WARNING: 'tide-bg-surface-warning',
46
+ },
47
+ },
34
48
  INITIAL: 'tide-bg-initial',
35
49
  BLUR: 'tide-bg-blur',
36
- ERROR: 'tide-bg-error',
37
- INFO: 'tide-bg-info',
38
50
  PRIMARY: 'tide-bg-primary',
39
51
  SECONDARY: 'tide-bg-secondary',
40
- SUCCESS: 'tide-bg-success',
41
52
  SURFACE: {
42
53
  ACCENT: 'tide-bg-surface-accent',
43
54
  BRAND: 'tide-bg-surface-brand',
44
55
  DEFAULT: 'tide-bg-surface',
45
- ERROR: 'tide-bg-surface-error',
46
56
  FLOATING: 'tide-bg-surface-floating',
47
57
  GRADIENT: 'tide-bg-surface-gradient',
48
- INFO: 'tide-bg-surface-info',
49
- SUCCESS: 'tide-bg-surface-success',
50
58
  VARIANT: 'tide-bg-surface-variant',
51
- WARNING: 'tide-bg-surface-warning',
52
59
  },
53
60
  TRANSPARENT: {
54
61
  ONE_HUNDRED: 'tide-transparent-100',
@@ -56,10 +63,15 @@ export const CSS = {
56
63
  THREE_HUNDRED: 'tide-transparent-300',
57
64
  FOUR_HUNDRED: 'tide-transparent-400',
58
65
  },
59
- WARNING: 'tide-bg-warning',
60
66
  },
61
67
  BORDER: {
62
68
  COLOR: {
69
+ GLOBAL: {
70
+ ERROR: 'tide-border-error',
71
+ INFO: 'tide-border-info',
72
+ SUCCESS: 'tide-border-success',
73
+ WARNING: 'tide-border-warning',
74
+ },
63
75
  INITIAL: 'tide-border-color-initial',
64
76
  DEFAULT: 'tide-border',
65
77
  FLOATING: 'tide-border-floating',
@@ -154,6 +166,12 @@ export const CSS = {
154
166
  },
155
167
  FONT: {
156
168
  COLOR: {
169
+ GLOBAL: {
170
+ ERROR: 'tide-font-error',
171
+ INFO: 'tide-font-info',
172
+ SUCCESS: 'tide-font-success',
173
+ WARNING: 'tide-font-warning',
174
+ },
157
175
  PRIMARY: 'tide-font-on-primary',
158
176
  SECONDARY: 'tide-font-on-secondary',
159
177
  SURFACE: {
@@ -5,6 +5,8 @@ import { formatKebabCase } from '@/utilities/format';
5
5
 
6
6
  import type { ArgTypes, StoryContext } from '@storybook/vue3';
7
7
 
8
+ type KeyString = { [key: string]: string };
9
+
8
10
  // Extensible object of key/value pairs
9
11
  type KeyValue = { [key: string]: any };
10
12
 
@@ -13,6 +15,10 @@ type KeyValueNamed = {
13
15
  [key: string]: KeyValue;
14
16
  };
15
17
 
18
+ type Nested = {
19
+ [key: string]: string | Nested;
20
+ };
21
+
16
22
  export const lineBreak = '\r';
17
23
  export const tab = ' ';
18
24
 
@@ -89,6 +95,25 @@ export const doSomething = () => {
89
95
  alert('Did something.');
90
96
  };
91
97
 
98
+ // Flatten a nested constant into a simple constant.
99
+ export const flatten = (input: Nested): KeyString => {
100
+ const output: KeyString = {};
101
+
102
+ Object.entries(input).forEach(([key, value]) => {
103
+ if (typeof value === 'string') {
104
+ output[key] = value;
105
+ } else {
106
+ const flattened = flatten(value);
107
+
108
+ Object.entries(flattened).forEach(([key2, value2]) => {
109
+ output[`${key}.${key2}`] = value2;
110
+ });
111
+ }
112
+ });
113
+
114
+ return output;
115
+ };
116
+
92
117
  // Accept a KeyValue as the value of an object with a retrievable key as a Storybook argType.
93
118
  export const formatArgType = (collection: KeyValueNamed) => {
94
119
  const constant = getKey(collection);
@@ -114,14 +114,14 @@ export const handleFieldValidation = ({
114
114
  minlength?: number;
115
115
  required?: boolean;
116
116
  validators?: Validator[];
117
- value: Ref<string>;
117
+ value?: Ref<string | undefined>;
118
118
  }) => {
119
119
  // error in props takes precedence over validation error
120
120
 
121
121
  error.value = errorFromProps ? errorFromProps : false;
122
122
 
123
123
  if (!error.value && validators) {
124
- const validation = validateProperty(value.value, validators);
124
+ const validation = validateProperty(value?.value || '', validators);
125
125
 
126
126
  if (!validation.valid) {
127
127
  error.value = validation.message;
@@ -133,7 +133,7 @@ export const handleFieldValidation = ({
133
133
  maxlength,
134
134
  minlength,
135
135
  required,
136
- value: value.value,
136
+ value: value?.value || '',
137
137
  });
138
138
 
139
139
  if (!lengthValidation.valid) {
@@ -297,9 +297,9 @@ describe('@/src/utilities/format.ts', () => {
297
297
  expect(formatPrice(input)).toEqual(output);
298
298
  });
299
299
 
300
- it('ignores an empty string.', () => {
300
+ it('formats an empty string as zero dollars.', () => {
301
301
  const input = '';
302
- const output = '$--';
302
+ const output = '$0';
303
303
 
304
304
  expect(formatPrice(input)).toEqual(output);
305
305
  });
@@ -0,0 +1,99 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { flatten } from '../src/utilities/storybook';
4
+
5
+ describe('@/src/utilities/storybook.ts', () => {
6
+ describe('flatten', () => {
7
+ it('returns an empty object when an empty object is provided.', () => {
8
+ const input = {};
9
+
10
+ expect(flatten(input)).toEqual(input);
11
+ });
12
+
13
+ it('returns a shallow constant when a shallow constant is provided.', () => {
14
+ const input = {
15
+ A: 'a',
16
+ B: 'b',
17
+ C: 'c',
18
+ };
19
+
20
+ expect(flatten(input)).toEqual(input);
21
+ });
22
+
23
+ it('returns a shallow constant when a constant with 2 layers of depth is provided.', () => {
24
+ const input = {
25
+ A: 'a',
26
+ B: 'b',
27
+ C: {
28
+ D: 'd',
29
+ E: 'e',
30
+ },
31
+ };
32
+
33
+ const output = {
34
+ 'A': 'a',
35
+ 'B': 'b',
36
+ 'C.D': 'd',
37
+ 'C.E': 'e',
38
+ };
39
+
40
+ expect(flatten(input)).toEqual(output);
41
+ });
42
+
43
+ it('returns a shallow constant when a constant with 3 layers of depth is provided.', () => {
44
+ const input = {
45
+ A: 'a',
46
+ B: 'b',
47
+ C: {
48
+ D: 'd',
49
+ E: 'e',
50
+ F: {
51
+ G: 'g',
52
+ H: 'h',
53
+ },
54
+ },
55
+ };
56
+
57
+ const output = {
58
+ 'A': 'a',
59
+ 'B': 'b',
60
+ 'C.D': 'd',
61
+ 'C.E': 'e',
62
+ 'C.F.G': 'g',
63
+ 'C.F.H': 'h',
64
+ };
65
+
66
+ expect(flatten(input)).toEqual(output);
67
+ });
68
+
69
+ it('returns a shallow constant when a constant with complex depth is provided.', () => {
70
+ const input = {
71
+ A: 'a',
72
+ B: 'b',
73
+ C: {
74
+ D: 'd',
75
+ E: 'e',
76
+ },
77
+ F: {
78
+ G: 'g',
79
+ H: {
80
+ I: 'i',
81
+ J: 'j',
82
+ },
83
+ },
84
+ };
85
+
86
+ const output = {
87
+ 'A': 'a',
88
+ 'B': 'b',
89
+ 'C.D': 'd',
90
+ 'C.E': 'e',
91
+ 'F.G': 'g',
92
+ 'F.H.I': 'i',
93
+ 'F.H.J': 'j',
94
+ };
95
+
96
+ expect(flatten(input)).toEqual(output);
97
+ });
98
+ });
99
+ });
@@ -1,14 +0,0 @@
1
- .slide-down-from-top-enter-active,
2
- .slide-down-from-top-leave-active {
3
- transition: transform var(--tide-animate);
4
- }
5
-
6
- .slide-down-from-top-enter-from,
7
- .slide-down-from-top-leave-to {
8
- transform: translateY(-100%);
9
- }
10
-
11
- .slide-down-from-top-enter-to,
12
- .slide-down-from-top-leave-from {
13
- transform: translateY(0);
14
- }
@@ -1,14 +0,0 @@
1
- .slide-down-from-top-enter-active,
2
- .slide-down-from-top-leave-active {
3
- transition: transform var(--tide-animate);
4
- }
5
-
6
- .slide-down-from-top-enter-from,
7
- .slide-down-from-top-leave-to {
8
- transform: translateY(-100%);
9
- }
10
-
11
- .slide-down-from-top-enter-to,
12
- .slide-down-from-top-leave-from {
13
- transform: translateY(0);
14
- }