tide-design-system 2.4.2 → 2.4.4

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 (50) hide show
  1. package/README.md +10 -9
  2. package/dist/css/fonts.css +36 -0
  3. package/dist/css/grid-layout.css +34 -0
  4. package/dist/css/main.css +5 -0
  5. package/dist/css/realm/aero.css +25 -0
  6. package/dist/css/realm/atv.css +25 -0
  7. package/dist/css/realm/boatmart.css +25 -0
  8. package/dist/css/realm/cycle.css +24 -0
  9. package/dist/css/realm/equipment.css +25 -0
  10. package/dist/css/realm/pwc.css +25 -0
  11. package/dist/css/realm/rv.css +25 -0
  12. package/dist/css/realm/snow.css +25 -0
  13. package/dist/css/realm/truck.css +25 -0
  14. package/dist/css/reset.css +95 -0
  15. package/dist/css/storybook.css +18 -0
  16. package/dist/css/utilities-base.css +545 -0
  17. package/dist/css/utilities-responsive.css +2737 -0
  18. package/dist/css/utilities.css +16 -0
  19. package/dist/css/variables.css +205 -0
  20. package/dist/style.css +1 -1
  21. package/dist/tide-design-system.cjs +2 -2
  22. package/dist/tide-design-system.esm.d.ts +9 -2
  23. package/dist/tide-design-system.esm.js +1767 -1707
  24. package/dist/utilities/event.ts +4 -0
  25. package/dist/utilities/format.ts +184 -0
  26. package/dist/utilities/forms.ts +22 -0
  27. package/dist/utilities/storybook.ts +352 -0
  28. package/dist/utilities/validation-deprecated.ts +252 -0
  29. package/dist/utilities/validation.ts +132 -0
  30. package/dist/utilities/viewport.ts +63 -0
  31. package/{src/docs → docs}/integration-full.md +1 -1
  32. package/{src/docs → docs}/integration-partial.md +1 -1
  33. package/docs/token-cheatsheet.md +63 -0
  34. package/package.json +2 -2
  35. package/src/assets/css/storybook.css +1 -0
  36. package/src/assets/css/variables.css +2 -2
  37. package/src/components/TideCarousel.vue +131 -28
  38. package/src/components/TideInputRadioDeprecated.vue +1 -0
  39. package/src/components/TideInputTextDeprecated.vue +1 -0
  40. package/src/stories/TideCarousel.stories.ts +21 -23
  41. package/src/types/Icon.ts +3 -0
  42. /package/{src/docs → docs}/assets/native-input-validation.png +0 -0
  43. /package/{src/docs → docs}/development.md +0 -0
  44. /package/{src/docs → docs}/figma.md +0 -0
  45. /package/{src/docs → docs}/forms.md +0 -0
  46. /package/{src/docs → docs}/migration.md +0 -0
  47. /package/{src/docs → docs}/storybook.md +0 -0
  48. /package/{src/docs → docs}/style-guide.md +0 -0
  49. /package/{src/docs → docs}/upgrading.md +0 -0
  50. /package/{src/docs → docs}/workflows.md +0 -0
@@ -0,0 +1,4 @@
1
+ export const isClickOutside = (event: MouseEvent, elements: HTMLElement | HTMLElement[]): boolean => {
2
+ const targets = Array.isArray(elements) ? elements : [elements];
3
+ return !targets.some((el) => el.contains(event.target as Node));
4
+ };
@@ -0,0 +1,184 @@
1
+ const capitalizeFirst = (string: string) => {
2
+ return string.charAt(0).toUpperCase() + string.slice(1);
3
+ };
4
+
5
+ const formatCamelCase = (input: string): string => {
6
+ return input && typeof input === 'string'
7
+ ? input
8
+ .replace(/^[\s_-]/, '')
9
+ .replace(/([a-z]{1})([A-Z]{1})/g, '$1 $2')
10
+ .replace(/[\s_-]/g, ' ')
11
+ .toLowerCase()
12
+ .split(' ')
13
+ .map((word, index) => (index === 0 ? word : word.slice(0, 1).toUpperCase() + word.slice(1)))
14
+ .join('')
15
+ : input;
16
+ };
17
+
18
+ const formatKebabCase = (input: string): string => {
19
+ return input && typeof input === 'string'
20
+ ? input
21
+ .replace(/([a-z]{1})([A-Z]{1})/g, '$1 $2')
22
+ .toLowerCase()
23
+ .replace(/[\s_-]/g, '-')
24
+ : input;
25
+ };
26
+
27
+ const formatLabel = (value: string) => {
28
+ const labelMap: { [key: string]: string } = {
29
+ false: 'No',
30
+ true: 'Yes',
31
+ };
32
+ return Object.hasOwn(labelMap, value) ? labelMap[value] : value;
33
+ };
34
+
35
+ const formatNumber = (input: number | string): string => {
36
+ let output = input && typeof input === 'number' ? new Intl.NumberFormat().format(input) : String(input || '');
37
+ let digits = output;
38
+
39
+ if (input && typeof input === 'string') {
40
+ digits = digits.replace(/\D/g, '');
41
+ if (Number(digits)) {
42
+ output = new Intl.NumberFormat().format(Number(digits));
43
+ } else {
44
+ output = '0';
45
+ }
46
+ }
47
+
48
+ return output;
49
+ };
50
+
51
+ const formatPascalCase = (input: string): string => {
52
+ return input && typeof input === 'string'
53
+ ? input
54
+ .replace(/([a-z]{1})([A-Z]{1})/g, '$1 $2')
55
+ .replace(/[\s_-]/g, ' ')
56
+ .toLowerCase()
57
+ .split(' ')
58
+ .map((word) => word.slice(0, 1).toUpperCase() + word.slice(1))
59
+ .join('')
60
+ : input;
61
+ };
62
+
63
+ const formatPhone = (input: number | string): string => {
64
+ let output = input && typeof input === 'number' ? String(input) : String(input || '');
65
+ let digits = output;
66
+ digits = digits.replace(/\D/g, '');
67
+
68
+ switch (digits.length) {
69
+ case 7:
70
+ output = `${digits.slice(0, 3)}-${digits.slice(3)}`;
71
+ break;
72
+ case 10:
73
+ output = `${digits.slice(0, 3)}-${digits.slice(3, 6)}-${digits.slice(6)}`;
74
+ break;
75
+ case 11:
76
+ output = `${digits.slice(0, 1)}-${digits.slice(1, 4)}-${digits.slice(4, 7)}-${digits.slice(7)}`;
77
+ break;
78
+ default:
79
+ output = digits;
80
+ break;
81
+ }
82
+
83
+ return output;
84
+ };
85
+
86
+ const formatPrice = (input: number | string): string => {
87
+ const output = input ? formatNumber(input) : String(input || '0');
88
+ return `$${output}`;
89
+ };
90
+
91
+ const formatQuotes = (value: string) => {
92
+ if (value.startsWith('"') && value.endsWith('"')) {
93
+ return value.slice(1, -1);
94
+ } else {
95
+ return value;
96
+ }
97
+ };
98
+
99
+ const formatSentenceCase = (input: string): string => {
100
+ let sentenceCase = input;
101
+
102
+ if (input && typeof input === 'string') {
103
+ const lowerCase = input
104
+ .replace(/([a-z]{1})([A-Z]{1})/g, '$1 $2')
105
+ .toLowerCase()
106
+ .replace(/[\s_-]/g, ' ');
107
+
108
+ sentenceCase = lowerCase.slice(0, 1).toUpperCase() + lowerCase.slice(1);
109
+ }
110
+
111
+ return sentenceCase;
112
+ };
113
+
114
+ const formatSnakeCase = (input: string): string => {
115
+ return input && typeof input === 'string'
116
+ ? input
117
+ .replace(/([a-z]{1})([A-Z]{1})/g, '$1 $2')
118
+ .toLowerCase()
119
+ .replace(/[\s_-]/g, '_')
120
+ : input;
121
+ };
122
+
123
+ const formatTitleCase = (input: string): string => {
124
+ return input && typeof input === 'string'
125
+ ? input
126
+ .replace(/([a-z]{1})([A-Z]{1})/g, '$1 $2')
127
+ .toLowerCase()
128
+ .replace(/[\s_-]/g, ' ')
129
+ .split(' ')
130
+ .map((word) => word.slice(0, 1).toUpperCase() + word.slice(1))
131
+ .join(' ')
132
+ : input;
133
+ };
134
+
135
+ const formatUrlFromRoot = (url: string) => {
136
+ const urlFormatted = url.split('.com/');
137
+
138
+ return urlFormatted.length > 1 ? `/${urlFormatted[1]}` : url;
139
+ };
140
+
141
+ const formatWeight = (input: number | string): string => {
142
+ const output = input ? formatNumber(input) : String(input || '0');
143
+ return `${output} lbs`;
144
+ };
145
+
146
+ const getArticle = (noun: string, isPlural = false, isDefinite = false) => {
147
+ const vowels = ['a', 'e', 'i', 'o', 'u'];
148
+ const isVowelLeading = vowels.includes(noun.charAt(0));
149
+
150
+ return isDefinite ? 'the' : isPlural ? 'some' : isVowelLeading ? 'an' : 'a';
151
+ };
152
+
153
+ const priceToNumber = (value: string) => {
154
+ if (Number.isNaN(Number(value))) {
155
+ value = value.replace('$', '');
156
+ value = value.replace(/,/g, '');
157
+ }
158
+ return parseInt(value, 10);
159
+ };
160
+
161
+ const unformatPrice = (input: string): string => {
162
+ const output = input.replace(/\$/g, '').replace(/,/g, '');
163
+ return `${output}`;
164
+ };
165
+
166
+ export {
167
+ capitalizeFirst,
168
+ formatCamelCase,
169
+ formatKebabCase,
170
+ formatLabel,
171
+ formatNumber,
172
+ formatPascalCase,
173
+ formatPhone,
174
+ formatPrice,
175
+ formatQuotes,
176
+ formatSentenceCase,
177
+ formatSnakeCase,
178
+ formatTitleCase,
179
+ formatUrlFromRoot,
180
+ formatWeight,
181
+ getArticle,
182
+ priceToNumber,
183
+ unformatPrice,
184
+ };
@@ -0,0 +1,22 @@
1
+ import { INPUT_MODE, TEXT_INPUT_TYPE } from '@/types/TextInput';
2
+
3
+ import type { InputMode, TextInputType } from '@/types/TextInput';
4
+
5
+ export const getTextInputMode = (type: TextInputType, inputmode?: InputMode): InputMode | undefined => {
6
+ if (inputmode) return inputmode;
7
+
8
+ switch (type) {
9
+ case TEXT_INPUT_TYPE.TEL:
10
+ return INPUT_MODE.TEL;
11
+ case TEXT_INPUT_TYPE.SEARCH:
12
+ return INPUT_MODE.SEARCH;
13
+ case TEXT_INPUT_TYPE.NUMBER:
14
+ return INPUT_MODE.NUMERIC;
15
+ case TEXT_INPUT_TYPE.EMAIL:
16
+ return INPUT_MODE.EMAIL;
17
+ case TEXT_INPUT_TYPE.URL:
18
+ return INPUT_MODE.URL;
19
+ }
20
+
21
+ return undefined;
22
+ };
@@ -0,0 +1,352 @@
1
+ import { ELEMENT, ELEMENT_TEXT_AS_ICON } from '@/types/Element';
2
+ import { BOOLEAN, BOOLEAN_UNREQUIRED, NoneAsEmpty, NoneAsUndefined } from '@/types/Storybook';
3
+ import { CSS } from '@/types/Styles';
4
+ import { formatKebabCase } from '@/utilities/format';
5
+
6
+ import type { ArgTypes, StoryContext } from '@storybook/vue3';
7
+
8
+ type KeyString = { [key: string]: string };
9
+
10
+ // Extensible object of key/value pairs
11
+ type KeyValue = { [key: string]: any };
12
+
13
+ // Object with a retrievable key and an extensible object of key/value pairs as the value
14
+ type KeyValueNamed = {
15
+ [key: string]: KeyValue;
16
+ };
17
+
18
+ type Nested = {
19
+ [key: string]: string | Nested;
20
+ };
21
+
22
+ export const lineBreak = '\r';
23
+ export const tab = ' ';
24
+
25
+ export const argTypeBoolean = {
26
+ control: 'select',
27
+ description: 'Determines whether CSS utility is present',
28
+ options: BOOLEAN,
29
+ table: {
30
+ defaultValue: { summary: 'False' },
31
+ type: { summary: 'boolean' },
32
+ },
33
+ };
34
+
35
+ export const argTypeBooleanUnrequired = {
36
+ control: 'select',
37
+ description: 'True, False, or undefined<br />(for demonstration purposes)',
38
+ options: BOOLEAN_UNREQUIRED,
39
+ table: {
40
+ defaultValue: { summary: 'None' },
41
+ type: { summary: 'boolean' },
42
+ },
43
+ };
44
+
45
+ export const argTypeDimension = {
46
+ control: {
47
+ max: 500,
48
+ min: 100,
49
+ step: 100,
50
+ type: 'number',
51
+ },
52
+ table: {
53
+ defaultValue: { summary: 'None' },
54
+ type: { summary: 'number (px)' },
55
+ },
56
+ };
57
+
58
+ export const change = {
59
+ control: 'text',
60
+ description: 'JS code or function to execute on change event',
61
+ isEmit: true,
62
+ name: 'change',
63
+ table: {
64
+ defaultValue: { summary: 'None' },
65
+ type: { summary: '() => void' },
66
+ },
67
+ };
68
+
69
+ export const click = {
70
+ control: 'text',
71
+ description: 'JS code or function to execute on click event',
72
+ isEmit: true,
73
+ table: {
74
+ defaultValue: { summary: 'None' },
75
+ type: { summary: '() => void' },
76
+ },
77
+ };
78
+
79
+ export const close = {
80
+ control: 'text',
81
+ description: 'JS code or function to execute on close event',
82
+ isEmit: true,
83
+ table: {
84
+ defaultValue: { summary: 'None' },
85
+ type: { summary: '() => void' },
86
+ },
87
+ };
88
+
89
+ export const dataTrack = {
90
+ control: 'text',
91
+ description: 'Data attribute for external tracking',
92
+ table: {
93
+ defaultValue: { summary: 'None' },
94
+ type: { summary: 'string' },
95
+ },
96
+ };
97
+
98
+ export const disabledArgType = {
99
+ table: {
100
+ disable: true,
101
+ },
102
+ };
103
+
104
+ export const isProduction = process.env.NODE_ENV === 'production';
105
+
106
+ export const doSomething = (message: string = 'Did something.') => {
107
+ const doSomethingAlert = document.getElementById('do-something-alert');
108
+
109
+ if (!doSomethingAlert) return;
110
+
111
+ doSomethingAlert.innerHTML = message;
112
+ doSomethingAlert.style.opacity = '1';
113
+
114
+ setTimeout(() => {
115
+ doSomethingAlert.style.opacity = '0';
116
+ }, 1000);
117
+ };
118
+
119
+ export const doSomethingElse = () => {
120
+ doSomething('Did something else.');
121
+ };
122
+
123
+ // Flatten a nested constant into a simple constant.
124
+ export const flatten = (input: Nested): KeyString => {
125
+ const output: KeyString = {};
126
+
127
+ Object.entries(input).forEach(([key, value]) => {
128
+ if (typeof value === 'string') {
129
+ output[key] = value;
130
+ } else {
131
+ const flattened = flatten(value);
132
+
133
+ Object.entries(flattened).forEach(([key2, value2]) => {
134
+ output[`${key}.${key2}`] = value2;
135
+ });
136
+ }
137
+ });
138
+
139
+ return output;
140
+ };
141
+
142
+ // Accept a KeyValue as the value of an object with a retrievable key as a Storybook argType.
143
+ export const formatArgType = (collection: KeyValueNamed) => {
144
+ const constant = getKey(collection);
145
+ const keyValues: KeyValue = collection[constant];
146
+
147
+ return {
148
+ constant,
149
+ control: 'select',
150
+ options: {
151
+ ...keyValues,
152
+ },
153
+ table: {
154
+ defaultValue: { summary: 'None' },
155
+ type: { summary: constant },
156
+ },
157
+ };
158
+ };
159
+
160
+ export const formatArgTypeCheck = (collection: KeyValueNamed) => {
161
+ const constant = getKey(collection);
162
+ const keyValues: KeyValue = collection[constant];
163
+
164
+ return {
165
+ constant,
166
+ control: 'check',
167
+ options: {
168
+ ...keyValues,
169
+ },
170
+ table: {
171
+ defaultValue: { summary: 'None' },
172
+ type: { summary: constant },
173
+ },
174
+ };
175
+ };
176
+
177
+ export const formatValueAsConstant = (keyValue: KeyValue, argTypes: ArgTypes) => {
178
+ const [key, value] = Object.entries(keyValue)[0];
179
+ let constant;
180
+
181
+ const arg: ArgTypes = argTypes[key];
182
+
183
+ Object.entries(arg.options).forEach(([optionKey, optionValue]) => {
184
+ if (value === optionValue) {
185
+ constant = `${argTypes[key].constant}.${optionKey}`;
186
+ }
187
+ });
188
+
189
+ return constant;
190
+ };
191
+
192
+ export const formatSnippet = (code: string, context: StoryContext) => {
193
+ const tag = context.component?.__name;
194
+ const { args, argTypes } = context;
195
+
196
+ let classNames: string[] = [];
197
+
198
+ let attributes = Object.entries(args).map((arg: any) => {
199
+ const key = arg[0];
200
+ let value = arg[1];
201
+ const argType: ArgTypes = argTypes[key];
202
+ const conditionKey = argType.if?.arg;
203
+ const conditionValue = argType.if?.eq;
204
+
205
+ // TODO: TypeScript doesn't seem to believe the implict shapes of Storybook's native types?
206
+ const controlType = argType?.control?.type as any;
207
+
208
+ // If arg is conditional, hide when conditional is not met.
209
+ const isClick = key === 'click';
210
+ const isConditionMet = argType.if ? args[conditionKey] === conditionValue : true;
211
+ const isConstant = Object.keys(argTypes).includes(key) && !!argType.constant && controlType === 'select';
212
+ const isConstants = Object.keys(argTypes).includes(key) && !!argType.constant && controlType === 'check';
213
+ const isCustom = argType.isCustom;
214
+ const isDynamic = argType.isDynamic || isConstant || isConstants || typeof value === 'boolean';
215
+ const isEmpty = !isDynamic && value === '';
216
+ const isExcluded = value === undefined || (Array.isArray(value) && !value.length);
217
+ const isEmit = argType.isEmit;
218
+ const isSlot = key === 'default';
219
+
220
+ if (argType.isCss) {
221
+ classNames.push(value);
222
+ }
223
+
224
+ if (isConstant && value !== 'None') {
225
+ const arg: ArgTypes = argType;
226
+
227
+ Object.entries(arg.options).forEach(([optionKey, optionValue]) => {
228
+ if (value === optionValue) {
229
+ value = `${argType.constant}.${optionKey}`;
230
+ }
231
+ });
232
+ }
233
+
234
+ if (isConstants && value.length) {
235
+ const constantSlots: string[] = [];
236
+
237
+ Object.entries(argType.options).forEach(([optionKey, optionValue]) => {
238
+ value.forEach((valueSlot: any) => {
239
+ if (valueSlot === optionValue) {
240
+ constantSlots.push(`${argTypes[key].constant}.${optionKey}`);
241
+ }
242
+ });
243
+ });
244
+
245
+ value = `[${constantSlots.join(', ')}]`;
246
+ }
247
+
248
+ if (isCustom) {
249
+ return `:${formatKebabCase(key)}="${key}"`;
250
+ }
251
+
252
+ if (
253
+ isClick &&
254
+ value &&
255
+ (!args.element || args.element === ELEMENT.BUTTON || args.element === ELEMENT_TEXT_AS_ICON.BUTTON)
256
+ ) {
257
+ return `@click="${value}"`;
258
+ }
259
+
260
+ if (isEmit) {
261
+ if (value) {
262
+ return `@${argType.name}="${value}"`;
263
+ }
264
+ }
265
+
266
+ if (isConditionMet && !isClick && !isCustom && !isEmpty && !isExcluded && !isSlot) {
267
+ return `${isDynamic ? ':' : ''}${formatKebabCase(key)}="${value}"`;
268
+ }
269
+ });
270
+
271
+ classNames = classNames.filter((className) => !!className);
272
+
273
+ if (classNames.length > 0) attributes.push(`class="${classNames.join(' ')}"`);
274
+
275
+ attributes = attributes.filter((attribute) => !!attribute).sort();
276
+
277
+ if (attributes) attributes.unshift('');
278
+
279
+ return args.default
280
+ ? `<${tag}${attributes.join(' ')}>${lineBreak}${tab}${args.default}${lineBreak}</${tag}>`
281
+ : `<${tag}${attributes.join(' ')} />`;
282
+ };
283
+
284
+ export const formatSnippetMinimal = (code: string) => {
285
+ return code.replace(/<[/]*template>/g, '');
286
+ };
287
+
288
+ export const getConstantByValue = (value: string) => {
289
+ const compareRecursively = (basis: string, shape: string | object, depth: number = 0): string | void => {
290
+ let output;
291
+
292
+ Object.entries(shape).forEach((entry: string[]) => {
293
+ const key = entry[0];
294
+ const value = entry[1];
295
+ const type = typeof value;
296
+
297
+ if (type === 'string' && basis === value) {
298
+ output = key;
299
+ return;
300
+ } else if (type === 'object') {
301
+ const match = compareRecursively(basis, value, depth + 1);
302
+
303
+ if (match) {
304
+ output = `${key}.${match}`;
305
+ return;
306
+ }
307
+ }
308
+ });
309
+
310
+ return output;
311
+ };
312
+
313
+ const constant = compareRecursively(value, CSS);
314
+
315
+ return constant ? `CSS.${constant}` : undefined;
316
+ };
317
+
318
+ export const getConstantsByValues = (classNames: string[]) =>
319
+ classNames.map((className) => getConstantByValue(className));
320
+
321
+ export const getKey = (input: any) => Object.keys(input)[0];
322
+
323
+ // Invert key/value pairs bc Storybook control option format is unintuitive.
324
+ export const getLabelsFromOptions = (options: any) => {
325
+ const labels: { [key: string]: string } = {};
326
+
327
+ Object.entries(options).forEach(([key, value]) => {
328
+ labels[`${value}`] = key;
329
+ });
330
+
331
+ return labels;
332
+ };
333
+
334
+ export const parameters = {
335
+ docs: {
336
+ source: {
337
+ format: 'vue',
338
+ language: 'html',
339
+ transform: formatSnippet,
340
+ },
341
+ },
342
+ };
343
+
344
+ // Prepend a key/value pair to a constant.
345
+ export const prependKeyValue = (collection: KeyValue, keyValue: KeyValue) => ({
346
+ ...keyValue,
347
+ ...collection,
348
+ });
349
+
350
+ export const prependNoneAsUndefined = (collection: KeyValue) => prependKeyValue(collection, NoneAsUndefined);
351
+
352
+ export const prependNoneAsEmpty = (collection: KeyValue) => prependKeyValue(collection, NoneAsEmpty);