@aws-amplify/ui 6.0.17 → 6.2.0
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/esm/i18n/dictionaries/authenticator/de.mjs +4 -4
- package/dist/esm/i18n/dictionaries/authenticator/ja.mjs +2 -2
- package/dist/esm/i18n/dictionaries/authenticator/kr.mjs +10 -0
- package/dist/esm/i18n/dictionaries/authenticator/th.mjs +101 -0
- package/dist/esm/i18n/dictionaries/index.mjs +3 -1
- package/dist/esm/i18n/translations.mjs +2 -1
- package/dist/esm/index.mjs +6 -3
- package/dist/esm/theme/createTheme/createAnimationCSS.mjs +23 -0
- package/dist/esm/theme/createTheme/createColorPalette.mjs +21 -0
- package/dist/esm/theme/createTheme/createComponentCSS.mjs +86 -0
- package/dist/esm/theme/createTheme/createComponentClasses.mjs +60 -0
- package/dist/esm/theme/{createTheme.mjs → createTheme/createTheme.mjs} +33 -44
- package/dist/esm/theme/createTheme/defineComponentTheme.mjs +55 -0
- package/dist/esm/theme/createTheme/utils.mjs +236 -0
- package/dist/esm/utils/humanFileSize.mjs +29 -0
- package/dist/esm/utils/utils.mjs +21 -1
- package/dist/index.js +566 -41
- package/dist/styles/breadcrumbs.css +2 -4
- package/dist/styles/breadcrumbs.layer.css +2 -4
- package/dist/styles/button.css +10 -19
- package/dist/styles/button.layer.css +10 -19
- package/dist/styles/input.css +2 -3
- package/dist/styles/input.layer.css +2 -3
- package/dist/styles/link.css +5 -10
- package/dist/styles/link.layer.css +5 -10
- package/dist/styles/reset.css +1 -3
- package/dist/styles/reset.layer.css +1 -3
- package/dist/styles/sliderField.css +2 -3
- package/dist/styles/sliderField.layer.css +2 -3
- package/dist/styles/textArea.css +2 -3
- package/dist/styles/textArea.layer.css +2 -3
- package/dist/styles.css +23 -42
- package/dist/styles.layer.css +23 -42
- package/dist/types/i18n/dictionaries/authenticator/index.d.ts +1 -0
- package/dist/types/i18n/dictionaries/authenticator/th.d.ts +2 -0
- package/dist/types/i18n/dictionaries/index.d.ts +52 -0
- package/dist/types/theme/components/accordion.d.ts +4 -0
- package/dist/types/theme/components/alert.d.ts +4 -0
- package/dist/types/theme/components/autocomplete.d.ts +8 -0
- package/dist/types/theme/components/badge.d.ts +4 -0
- package/dist/types/theme/components/breadcrumbs.d.ts +7 -0
- package/dist/types/theme/components/button.d.ts +7 -0
- package/dist/types/theme/components/buttonGroup.d.ts +2 -0
- package/dist/types/theme/components/card.d.ts +2 -0
- package/dist/types/theme/components/checkbox.d.ts +7 -0
- package/dist/types/theme/components/checkboxField.d.ts +2 -0
- package/dist/types/theme/components/collection.d.ts +4 -0
- package/dist/types/theme/components/divider.d.ts +2 -0
- package/dist/types/theme/components/dropZone.d.ts +2 -0
- package/dist/types/theme/components/field.d.ts +6 -0
- package/dist/types/theme/components/fieldGroup.d.ts +11 -0
- package/dist/types/theme/components/fieldset.d.ts +4 -0
- package/dist/types/theme/components/heading.d.ts +4 -0
- package/dist/types/theme/components/highlightMatch.d.ts +4 -0
- package/dist/types/theme/components/index.d.ts +92 -0
- package/dist/types/theme/components/input.d.ts +2 -0
- package/dist/types/theme/components/loader.d.ts +4 -0
- package/dist/types/theme/components/menu.d.ts +4 -0
- package/dist/types/theme/components/message.d.ts +4 -0
- package/dist/types/theme/components/pagination.d.ts +4 -0
- package/dist/types/theme/components/placeholder.d.ts +2 -0
- package/dist/types/theme/components/radio.d.ts +6 -0
- package/dist/types/theme/components/rating.d.ts +5 -0
- package/dist/types/theme/components/scrollview.d.ts +2 -0
- package/dist/types/theme/components/searchField.d.ts +4 -0
- package/dist/types/theme/components/select.d.ts +5 -0
- package/dist/types/theme/components/selectField.d.ts +2 -0
- package/dist/types/theme/components/sliderField.d.ts +9 -0
- package/dist/types/theme/components/stepperField.d.ts +6 -0
- package/dist/types/theme/components/storageManager.d.ts +20 -0
- package/dist/types/theme/components/switchField.d.ts +8 -0
- package/dist/types/theme/components/table.d.ts +4 -0
- package/dist/types/theme/components/tabs.d.ts +6 -0
- package/dist/types/theme/components/text.d.ts +3 -0
- package/dist/types/theme/components/textField.d.ts +2 -0
- package/dist/types/theme/components/textarea.d.ts +2 -0
- package/dist/types/theme/components/textareaField.d.ts +2 -0
- package/dist/types/theme/components/toggleButton.d.ts +3 -0
- package/dist/types/theme/components/utils.d.ts +52 -0
- package/dist/types/theme/createTheme/createAnimationCSS.d.ts +6 -0
- package/dist/types/theme/createTheme/createColorPalette.d.ts +16 -0
- package/dist/types/theme/createTheme/createComponentCSS.d.ts +7 -0
- package/dist/types/theme/createTheme/createComponentClasses.d.ts +25 -0
- package/dist/types/theme/{createTheme.d.ts → createTheme/createTheme.d.ts} +3 -2
- package/dist/types/theme/createTheme/defineComponentTheme.d.ts +54 -0
- package/dist/types/theme/createTheme/index.d.ts +4 -0
- package/dist/types/theme/createTheme/utils.d.ts +92 -0
- package/dist/types/theme/index.d.ts +1 -2
- package/dist/types/theme/types.d.ts +20 -3
- package/dist/types/utils/classNames.d.ts +1 -1
- package/dist/types/utils/humanFileSize.d.ts +11 -0
- package/dist/types/utils/index.d.ts +2 -1
- package/dist/types/utils/utils.d.ts +8 -0
- package/package.json +3 -3
- package/dist/esm/theme/utils.mjs +0 -81
- package/dist/types/theme/utils.d.ts +0 -35
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import kebabCase from 'lodash/kebabCase.js';
|
|
2
|
+
import '@aws-amplify/core/internals/utils';
|
|
3
|
+
import '../../utils/setUserAgent/constants.mjs';
|
|
4
|
+
import { isObject, has, isString } from '../../utils/utils.mjs';
|
|
5
|
+
|
|
6
|
+
const CSS_VARIABLE_PREFIX = 'amplify';
|
|
7
|
+
/**
|
|
8
|
+
* This will take an object like:
|
|
9
|
+
* {paddingTop:'20px',color:'{colors.font.primary}'}
|
|
10
|
+
* and turn it into a CSS string:
|
|
11
|
+
* `padding-top:20px; color: var(--colors-font-primary);`
|
|
12
|
+
*/
|
|
13
|
+
function propsToString(props) {
|
|
14
|
+
return Object.entries(props)
|
|
15
|
+
.map(([key, value]) => {
|
|
16
|
+
const _value = isDesignToken(value)
|
|
17
|
+
? value.toString()
|
|
18
|
+
: // @ts-ignore
|
|
19
|
+
cssValue({ value });
|
|
20
|
+
return `${kebabCase(key)}:${_value}; `;
|
|
21
|
+
})
|
|
22
|
+
.join(' ');
|
|
23
|
+
}
|
|
24
|
+
function cssNameTransform({ path = [] }) {
|
|
25
|
+
return `${kebabCase([CSS_VARIABLE_PREFIX, ...path].join(' '))}`;
|
|
26
|
+
}
|
|
27
|
+
// Important: these properties should not be altered in
|
|
28
|
+
// order to maintain the expected order of the CSS `box-shadow` property
|
|
29
|
+
const SHADOW_PROPERTIES = [
|
|
30
|
+
'offsetX',
|
|
31
|
+
'offsetY',
|
|
32
|
+
'blurRadius',
|
|
33
|
+
'spreadRadius',
|
|
34
|
+
'color',
|
|
35
|
+
];
|
|
36
|
+
/**
|
|
37
|
+
* Will take a design token in a theme and return its value as CSS
|
|
38
|
+
*
|
|
39
|
+
* @param token
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
function cssValue(token) {
|
|
43
|
+
const { value } = token;
|
|
44
|
+
if (isString(value)) {
|
|
45
|
+
return referenceValue(value);
|
|
46
|
+
}
|
|
47
|
+
if (isShadowTokenObject(value)) {
|
|
48
|
+
return SHADOW_PROPERTIES.map((property) => {
|
|
49
|
+
return referenceValue(
|
|
50
|
+
// lookup property against `token` first for custom non-nested value, then lookup
|
|
51
|
+
// property against `value` for design token value
|
|
52
|
+
isShadowTokenObject(token) ? token[property] : value[property]);
|
|
53
|
+
}).join(' ');
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Helper function to test if something is a design token or not.
|
|
59
|
+
* Used in the React component style props.
|
|
60
|
+
*
|
|
61
|
+
* @param value - thing to test if it is a design token or not
|
|
62
|
+
* @returns boolean
|
|
63
|
+
*/
|
|
64
|
+
function isDesignToken(value) {
|
|
65
|
+
return isObject(value) && has(value, 'value');
|
|
66
|
+
}
|
|
67
|
+
function isShadowTokenObject(value) {
|
|
68
|
+
return isObject(value) && has(value, 'offsetX');
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Function that sees if a string contains a design token reference
|
|
72
|
+
* and if so will turn that into a CSS variable.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} value
|
|
75
|
+
* @returns string
|
|
76
|
+
*/
|
|
77
|
+
function referenceValue(value) {
|
|
78
|
+
if (!value)
|
|
79
|
+
return '';
|
|
80
|
+
if (usesReference(value)) {
|
|
81
|
+
const path = value.replace(/\{|\}/g, '').replace('.value', '').split('.');
|
|
82
|
+
return `var(--${cssNameTransform({ path })})`;
|
|
83
|
+
}
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* This will take a design token and add some data to it for it
|
|
88
|
+
* to be used in JS/CSS. It will create its CSS var name and update
|
|
89
|
+
* the value to use a CSS var if it is a reference. It will also
|
|
90
|
+
* add a `.toString()` method to make it easier to use in JS.
|
|
91
|
+
*
|
|
92
|
+
* We should see if there is a way to share this logic with style dictionary...
|
|
93
|
+
*/
|
|
94
|
+
const setupToken = ({ token, path }) => {
|
|
95
|
+
const name = `--${cssNameTransform({ path })}`;
|
|
96
|
+
const { value: original } = token;
|
|
97
|
+
const value = cssValue(token);
|
|
98
|
+
return { name, original, path, value, toString: () => `var(${name})` };
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Recursive function that will walk down the token object
|
|
102
|
+
* and perform the setupToken function on each token.
|
|
103
|
+
* Similar to what Style Dictionary does.
|
|
104
|
+
*/
|
|
105
|
+
function setupTokens({ tokens, path = [], setupToken, }) {
|
|
106
|
+
if (has(tokens, 'value')) {
|
|
107
|
+
return setupToken({ token: tokens, path });
|
|
108
|
+
}
|
|
109
|
+
const output = {};
|
|
110
|
+
for (const name in tokens) {
|
|
111
|
+
if (has(tokens, name)) {
|
|
112
|
+
const value = tokens[name];
|
|
113
|
+
const nextTokens = isObject(value) ? value : { value };
|
|
114
|
+
output[name] = setupTokens({
|
|
115
|
+
tokens: nextTokens,
|
|
116
|
+
path: path.concat(name),
|
|
117
|
+
setupToken,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return output;
|
|
122
|
+
}
|
|
123
|
+
// Internal Style Dictionary methods
|
|
124
|
+
// copied from amzn/style-dictionary with the owner's permission
|
|
125
|
+
/**
|
|
126
|
+
* Takes an plain javascript object and will make a flat array of all the leaf nodes.
|
|
127
|
+
* A leaf node in this context has a 'value' property. Potentially refactor this to
|
|
128
|
+
* be more generic.
|
|
129
|
+
* @private
|
|
130
|
+
* @param {Object} properties - The plain object you want flattened into an array.
|
|
131
|
+
* @param {Array} [to_ret=[]] - Properties array. This function is recursive therefore this is what gets passed along.
|
|
132
|
+
* @return {Array}
|
|
133
|
+
*/
|
|
134
|
+
function flattenProperties(properties, to_ret) {
|
|
135
|
+
to_ret = to_ret || [];
|
|
136
|
+
for (var name in properties) {
|
|
137
|
+
if (has(properties, name)) {
|
|
138
|
+
if (isObject(properties[name]) && 'value' in properties[name]) {
|
|
139
|
+
to_ret.push(properties[name]);
|
|
140
|
+
}
|
|
141
|
+
else if (isObject(properties[name])) {
|
|
142
|
+
flattenProperties(properties[name], to_ret);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return to_ret;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Performs an deep extend on the objects, from right to left.
|
|
150
|
+
* @private
|
|
151
|
+
* @param {Object[]} objects - An array of JS objects
|
|
152
|
+
* @param {Function} collision - A function to be called when a merge collision happens.
|
|
153
|
+
* @param {string[]} path - (for internal use) An array of strings which is the current path down the object when this is called recursively.
|
|
154
|
+
* @returns {Object}
|
|
155
|
+
*/
|
|
156
|
+
function deepExtend(objects, collision, path) {
|
|
157
|
+
if (objects == null)
|
|
158
|
+
return {};
|
|
159
|
+
var src, copyIsArray, copy, name, options, clone, target = objects[0] || {}, i = 1, length = objects.length;
|
|
160
|
+
path = path || [];
|
|
161
|
+
// Handle case when target is a string or something (possible in deep copy)
|
|
162
|
+
if (typeof target !== 'object') {
|
|
163
|
+
target = {};
|
|
164
|
+
}
|
|
165
|
+
for (; i < length; i++) {
|
|
166
|
+
// Only deal with non-null/undefined values
|
|
167
|
+
if ((options = objects[i]) != null) {
|
|
168
|
+
// Extend the base object
|
|
169
|
+
for (name in options) {
|
|
170
|
+
if (!has(options, name))
|
|
171
|
+
continue;
|
|
172
|
+
if (name === '__proto__')
|
|
173
|
+
continue;
|
|
174
|
+
src = target[name];
|
|
175
|
+
copy = options[name];
|
|
176
|
+
// Prevent never-ending loop
|
|
177
|
+
if (target === copy) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
// Recurse if we're merging plain objects or arrays
|
|
181
|
+
if (copy && (isObject(copy) || (copyIsArray = Array.isArray(copy)))) {
|
|
182
|
+
if (copyIsArray) {
|
|
183
|
+
copyIsArray = false;
|
|
184
|
+
clone = src && Array.isArray(src) ? src : [];
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
clone = src && isObject(src) ? src : {};
|
|
188
|
+
}
|
|
189
|
+
var nextPath = path.slice(0);
|
|
190
|
+
nextPath.push(name);
|
|
191
|
+
// Never move original objects, clone them
|
|
192
|
+
target[name] = deepExtend([clone, copy], collision, nextPath);
|
|
193
|
+
// Don't bring in undefined values
|
|
194
|
+
}
|
|
195
|
+
else if (copy !== undefined) {
|
|
196
|
+
if (src != null && typeof collision == 'function') {
|
|
197
|
+
collision({ target: target, copy: options, path: path, key: name });
|
|
198
|
+
}
|
|
199
|
+
target[name] = copy;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return target;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Checks if the value uses a value reference.
|
|
208
|
+
* @param {string} value
|
|
209
|
+
* @returns {boolean} - True, if the value uses a value reference
|
|
210
|
+
*/
|
|
211
|
+
function usesReference(value) {
|
|
212
|
+
const regex = new RegExp('\\{([^}]+)\\}', 'g');
|
|
213
|
+
if (typeof value === 'string') {
|
|
214
|
+
return regex.test(value);
|
|
215
|
+
}
|
|
216
|
+
if (typeof value === 'object') {
|
|
217
|
+
let hasReference = false;
|
|
218
|
+
// iterate over each property in the object,
|
|
219
|
+
// if any element passes the regex test,
|
|
220
|
+
// the whole thing should be true
|
|
221
|
+
for (const key in value) {
|
|
222
|
+
if (has(value, key)) {
|
|
223
|
+
const element = value[key];
|
|
224
|
+
let reference = usesReference(element);
|
|
225
|
+
if (reference) {
|
|
226
|
+
hasReference = true;
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return hasReference;
|
|
232
|
+
}
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export { CSS_VARIABLE_PREFIX, cssNameTransform, cssValue, deepExtend, flattenProperties, isDesignToken, isShadowTokenObject, propsToString, referenceValue, setupToken, setupTokens, usesReference };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format bytes as human-readable text.
|
|
3
|
+
*
|
|
4
|
+
* @param bytes Number of bytes.
|
|
5
|
+
* @param si True to use metric (SI) units, aka powers of 1000. False to use
|
|
6
|
+
* binary (IEC), aka powers of 1024.
|
|
7
|
+
* @param dp Number of decimal places to display.
|
|
8
|
+
*
|
|
9
|
+
* @return Formatted string.
|
|
10
|
+
*/
|
|
11
|
+
function humanFileSize(bytes, si = false, dp = 1) {
|
|
12
|
+
const thresh = si ? 1000 : 1024;
|
|
13
|
+
if (Math.abs(bytes) < thresh) {
|
|
14
|
+
return `${bytes} B`;
|
|
15
|
+
}
|
|
16
|
+
const units = si
|
|
17
|
+
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
18
|
+
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
19
|
+
let unit = -1;
|
|
20
|
+
const range = 10 ** dp;
|
|
21
|
+
do {
|
|
22
|
+
bytes /= thresh;
|
|
23
|
+
++unit;
|
|
24
|
+
} while (Math.round(Math.abs(bytes) * range) / range >= thresh &&
|
|
25
|
+
unit < units.length - 1);
|
|
26
|
+
return bytes.toFixed(dp) + ' ' + units[unit];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { humanFileSize };
|
package/dist/esm/utils/utils.mjs
CHANGED
|
@@ -223,5 +223,25 @@ function groupLog(groupName, ...events) {
|
|
|
223
223
|
console.log(groupName);
|
|
224
224
|
}
|
|
225
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* Splits an object into 2 objects based on a predicate
|
|
228
|
+
*
|
|
229
|
+
* @param {object} obj an object to split into two
|
|
230
|
+
* @param {function} predicate function to determin where an element should go
|
|
231
|
+
* @returns
|
|
232
|
+
*/
|
|
233
|
+
function splitObject(obj, predicate) {
|
|
234
|
+
const left = {};
|
|
235
|
+
const right = {};
|
|
236
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
237
|
+
if (predicate(key)) {
|
|
238
|
+
left[key] = value;
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
right[key] = value;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
return [left, right];
|
|
245
|
+
}
|
|
226
246
|
|
|
227
|
-
export { areEmptyArrays, areEmptyObjects, capitalize, classNameModifier, classNameModifierByFlag, groupLog, has, isEmpty, isEmptyObject, isFunction, isMap, isNil, isObject, isSet, isString, isTypedFunction, isUndefined, noop, sanitizeNamespaceImport, templateJoin };
|
|
247
|
+
export { areEmptyArrays, areEmptyObjects, capitalize, classNameModifier, classNameModifierByFlag, groupLog, has, isEmpty, isEmptyObject, isFunction, isMap, isNil, isObject, isSet, isString, isTypedFunction, isUndefined, noop, sanitizeNamespaceImport, splitObject, templateJoin };
|