tide-design-system 2.4.1 → 2.4.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.
- package/dist/style.css +1 -1
- package/dist/tide-design-system.cjs +2 -2
- package/dist/tide-design-system.esm.d.ts +15 -15
- package/dist/tide-design-system.esm.js +6 -6
- package/netlify.toml +3 -0
- package/package.json +5 -3
- package/src/components/TideChipAction.vue +1 -1
- package/src/components/TideImageBackground.vue +2 -2
- package/src/components/TideInputCheckboxDeprecated.vue +2 -2
- package/src/components/TideInputRadioDeprecated.vue +2 -2
- package/src/components/TideInputTextDeprecated.vue +2 -2
- package/src/stories/FoundationsTypography.stories.ts +24 -0
- package/src/types/Storybook.ts +10 -0
- package/vite.config.sandbox.ts +29 -0
- package/dist/css/fonts.css +0 -36
- package/dist/css/grid-layout.css +0 -34
- package/dist/css/main.css +0 -5
- package/dist/css/realm/aero.css +0 -25
- package/dist/css/realm/atv.css +0 -25
- package/dist/css/realm/boatmart.css +0 -25
- package/dist/css/realm/cycle.css +0 -24
- package/dist/css/realm/equipment.css +0 -25
- package/dist/css/realm/pwc.css +0 -25
- package/dist/css/realm/rv.css +0 -25
- package/dist/css/realm/snow.css +0 -25
- package/dist/css/realm/truck.css +0 -25
- package/dist/css/reset.css +0 -95
- package/dist/css/storybook.css +0 -17
- package/dist/css/utilities-base.css +0 -545
- package/dist/css/utilities-responsive.css +0 -2737
- package/dist/css/utilities.css +0 -16
- package/dist/css/variables.css +0 -205
- package/dist/utilities/event.ts +0 -4
- package/dist/utilities/format.ts +0 -184
- package/dist/utilities/forms.ts +0 -22
- package/dist/utilities/storybook.ts +0 -352
- package/dist/utilities/validation-deprecated.ts +0 -252
- package/dist/utilities/validation.ts +0 -132
- package/dist/utilities/viewport.ts +0 -63
|
@@ -1,352 +0,0 @@
|
|
|
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);
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import { priceToNumber } from '@/utilities/format';
|
|
2
|
-
|
|
3
|
-
import type { StringInput } from '@/types/FormDeprecated';
|
|
4
|
-
import type { SelectOption } from '@/types/Select';
|
|
5
|
-
import type { ValidationError, ValidationLength, ValidationResult, Validator } from '@/types/ValidationDeprecated';
|
|
6
|
-
import type { Ref } from 'vue';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @deprecated
|
|
10
|
-
*/
|
|
11
|
-
type RangeData = {
|
|
12
|
-
min: number | null;
|
|
13
|
-
max: number | null;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @deprecated
|
|
18
|
-
*/
|
|
19
|
-
export const errorMessageDefault = 'Please enter a valid value.';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated
|
|
23
|
-
*/
|
|
24
|
-
export const noError = {
|
|
25
|
-
message: '',
|
|
26
|
-
valid: true,
|
|
27
|
-
} as Readonly<ValidationResult>;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @deprecated
|
|
31
|
-
*/
|
|
32
|
-
export const checkFormat = (format: RegExp) => {
|
|
33
|
-
return (value: string): ValidationResult => {
|
|
34
|
-
let result = noError;
|
|
35
|
-
|
|
36
|
-
if (!value.trim().match(format)) {
|
|
37
|
-
result = {
|
|
38
|
-
message: errorMessageDefault,
|
|
39
|
-
valid: false,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
return result;
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @deprecated
|
|
49
|
-
*/
|
|
50
|
-
export const getErrorMessage = (errorFromProps: ValidationError, errorFromRef: ValidationError) => {
|
|
51
|
-
// error in props takes precedence over validation error
|
|
52
|
-
if (typeof errorFromProps === 'string' && errorFromProps.length > 0) return errorFromProps;
|
|
53
|
-
|
|
54
|
-
return typeof errorFromRef === 'string' && errorFromRef.length > 0 ? errorFromRef : errorMessageDefault;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* @deprecated
|
|
59
|
-
*/
|
|
60
|
-
export const getFieldHasError = (errorFromProps: ValidationError, errorFromRef: ValidationError) =>
|
|
61
|
-
errorFromProps !== false || errorFromRef !== false;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @deprecated
|
|
65
|
-
*/
|
|
66
|
-
export const getFieldLengthIsValid = ({ maxlength, minlength, required, value }: ValidationLength) => {
|
|
67
|
-
const isEmptyAndUnrequired = value.length === 0 && !required;
|
|
68
|
-
const isTooLong = maxlength && value.length > maxlength;
|
|
69
|
-
const isTooShort = !isEmptyAndUnrequired && minlength && value.length < minlength;
|
|
70
|
-
|
|
71
|
-
return !isTooShort && !isTooLong;
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated
|
|
76
|
-
*/
|
|
77
|
-
export const getMaxRangeIsValid = ({ min }: Pick<RangeData, 'min'>, type?: 'price') => {
|
|
78
|
-
return (value: string): ValidationResult => {
|
|
79
|
-
let newMax: number | null = type === 'price' ? priceToNumber(value) : Number(value);
|
|
80
|
-
newMax = !isNaN(newMax) ? newMax : null;
|
|
81
|
-
if (min && newMax) {
|
|
82
|
-
if (newMax >= min) {
|
|
83
|
-
return {
|
|
84
|
-
message: '',
|
|
85
|
-
valid: true,
|
|
86
|
-
};
|
|
87
|
-
} else {
|
|
88
|
-
return {
|
|
89
|
-
message: `Must be greater than min`,
|
|
90
|
-
valid: false,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
return noError;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @deprecated
|
|
101
|
-
*/
|
|
102
|
-
export const getMinRangeIsValid = ({ max }: Pick<RangeData, 'max'>, type?: 'price') => {
|
|
103
|
-
return (value: string): ValidationResult => {
|
|
104
|
-
let newMin: number | null = type === 'price' ? priceToNumber(value) : Number(value);
|
|
105
|
-
newMin = !isNaN(newMin) ? newMin : null;
|
|
106
|
-
if (max && newMin) {
|
|
107
|
-
if (newMin <= max) {
|
|
108
|
-
return {
|
|
109
|
-
message: '',
|
|
110
|
-
valid: true,
|
|
111
|
-
};
|
|
112
|
-
} else {
|
|
113
|
-
return {
|
|
114
|
-
message: `Must be less than max`,
|
|
115
|
-
valid: false,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
} else {
|
|
119
|
-
return noError;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* @deprecated
|
|
126
|
-
*/
|
|
127
|
-
export const getSelectOptionsFromStrings = (strings: string[]) =>
|
|
128
|
-
strings.map(
|
|
129
|
-
(option) =>
|
|
130
|
-
({
|
|
131
|
-
label: option,
|
|
132
|
-
value: option,
|
|
133
|
-
} as SelectOption)
|
|
134
|
-
);
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* @deprecated
|
|
138
|
-
*/
|
|
139
|
-
export const handleFieldValidation = ({
|
|
140
|
-
error,
|
|
141
|
-
errorFromProps,
|
|
142
|
-
maxlength,
|
|
143
|
-
minlength,
|
|
144
|
-
required = false,
|
|
145
|
-
validators,
|
|
146
|
-
value,
|
|
147
|
-
}: {
|
|
148
|
-
error: Ref<ValidationError>;
|
|
149
|
-
errorFromProps: ValidationError;
|
|
150
|
-
maxlength?: number;
|
|
151
|
-
minlength?: number;
|
|
152
|
-
required?: boolean;
|
|
153
|
-
validators?: Validator[];
|
|
154
|
-
value?: Ref<string | undefined>;
|
|
155
|
-
}) => {
|
|
156
|
-
// error in props takes precedence over validation error
|
|
157
|
-
|
|
158
|
-
error.value = errorFromProps ? errorFromProps : false;
|
|
159
|
-
|
|
160
|
-
if (!error.value && validators) {
|
|
161
|
-
const validation = validateProperty(value?.value || '', validators);
|
|
162
|
-
|
|
163
|
-
if (!validation.valid) {
|
|
164
|
-
error.value = validation.message;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (!error.value && (maxlength || minlength)) {
|
|
169
|
-
const lengthValidation = validateLength({
|
|
170
|
-
maxlength,
|
|
171
|
-
minlength,
|
|
172
|
-
required,
|
|
173
|
-
value: value?.value || '',
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
if (!lengthValidation.valid) {
|
|
177
|
-
error.value = lengthValidation.message;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* @deprecated
|
|
184
|
-
*/
|
|
185
|
-
export function validateFieldsFromRefs(fields: { [key: string]: Ref<StringInput | null> }) {
|
|
186
|
-
let valid = true;
|
|
187
|
-
|
|
188
|
-
for (const key in fields) {
|
|
189
|
-
if (fields[key].value?.required) {
|
|
190
|
-
const value = fields[key].value?.value;
|
|
191
|
-
valid = valid && !!value && value.trim() !== '';
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
const error = fields[key].value?.error;
|
|
195
|
-
valid = valid && !error;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return valid;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* @deprecated
|
|
203
|
-
*/
|
|
204
|
-
export const validateLength = ({
|
|
205
|
-
maxlength,
|
|
206
|
-
minlength,
|
|
207
|
-
required = false,
|
|
208
|
-
value,
|
|
209
|
-
}: ValidationLength): ValidationResult => {
|
|
210
|
-
const response = {
|
|
211
|
-
message: '',
|
|
212
|
-
valid: true,
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
response.valid = getFieldLengthIsValid({
|
|
216
|
-
maxlength,
|
|
217
|
-
minlength,
|
|
218
|
-
required,
|
|
219
|
-
value,
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
if (response.valid) return response;
|
|
223
|
-
|
|
224
|
-
response.message = errorMessageDefault;
|
|
225
|
-
|
|
226
|
-
if (maxlength && minlength) {
|
|
227
|
-
response.message = `Please enter a value between ${minlength} and ${maxlength} characters in length.`;
|
|
228
|
-
} else if (maxlength) {
|
|
229
|
-
response.message = `Please enter a value no more than ${maxlength} characters in length.`;
|
|
230
|
-
} else if (minlength) {
|
|
231
|
-
response.message = `Please enter a value no less than ${minlength} characters in length.`;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return response;
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @deprecated
|
|
239
|
-
*/
|
|
240
|
-
export function validateProperty(value: string, validators: ((value: string) => ValidationResult)[]): ValidationResult {
|
|
241
|
-
for (const validator of validators) {
|
|
242
|
-
const validation = validator(value);
|
|
243
|
-
if (!validation.valid) {
|
|
244
|
-
return validation;
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
return {
|
|
249
|
-
message: '',
|
|
250
|
-
valid: true,
|
|
251
|
-
};
|
|
252
|
-
}
|