@aws-amplify/ui 6.0.17 → 6.1.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/ja.mjs +2 -2
- package/dist/esm/i18n/dictionaries/authenticator/kr.mjs +10 -0
- package/dist/esm/index.mjs +5 -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/utils.mjs +21 -1
- package/dist/index.js +431 -37
- 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/index.d.ts +1 -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
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 };
|
package/dist/index.js
CHANGED
|
@@ -9,19 +9,13 @@ var awsAmplify = require('aws-amplify');
|
|
|
9
9
|
var xstate = require('xstate');
|
|
10
10
|
var pickBy = require('lodash/pickBy.js');
|
|
11
11
|
var merge = require('lodash/merge.js');
|
|
12
|
-
var deepExtend = require('style-dictionary/lib/utils/deepExtend.js');
|
|
13
|
-
var flattenProperties = require('style-dictionary/lib/utils/flattenProperties.js');
|
|
14
12
|
var kebabCase = require('lodash/kebabCase.js');
|
|
15
|
-
var usesReference = require('style-dictionary/lib/utils/references/usesReference.js');
|
|
16
13
|
|
|
17
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
15
|
|
|
19
16
|
var pickBy__default = /*#__PURE__*/_interopDefaultLegacy(pickBy);
|
|
20
17
|
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
|
|
21
|
-
var deepExtend__default = /*#__PURE__*/_interopDefaultLegacy(deepExtend);
|
|
22
|
-
var flattenProperties__default = /*#__PURE__*/_interopDefaultLegacy(flattenProperties);
|
|
23
18
|
var kebabCase__default = /*#__PURE__*/_interopDefaultLegacy(kebabCase);
|
|
24
|
-
var usesReference__default = /*#__PURE__*/_interopDefaultLegacy(usesReference);
|
|
25
19
|
|
|
26
20
|
/**
|
|
27
21
|
* This file contains helpers that lets you easily access current actor's state
|
|
@@ -307,6 +301,26 @@ function groupLog(groupName, ...events) {
|
|
|
307
301
|
console.log(groupName);
|
|
308
302
|
}
|
|
309
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Splits an object into 2 objects based on a predicate
|
|
306
|
+
*
|
|
307
|
+
* @param {object} obj an object to split into two
|
|
308
|
+
* @param {function} predicate function to determin where an element should go
|
|
309
|
+
* @returns
|
|
310
|
+
*/
|
|
311
|
+
function splitObject(obj, predicate) {
|
|
312
|
+
const left = {};
|
|
313
|
+
const right = {};
|
|
314
|
+
Object.entries(obj).forEach(([key, value]) => {
|
|
315
|
+
if (predicate(key)) {
|
|
316
|
+
left[key] = value;
|
|
317
|
+
}
|
|
318
|
+
else {
|
|
319
|
+
right[key] = value;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
return [left, right];
|
|
323
|
+
}
|
|
310
324
|
|
|
311
325
|
/**
|
|
312
326
|
* @example
|
|
@@ -1128,7 +1142,7 @@ const jaDict$1 = {
|
|
|
1128
1142
|
'Enter your Username': 'ユーザー名を入力 ',
|
|
1129
1143
|
'Forgot your password?': 'パスワードを忘れましたか? ',
|
|
1130
1144
|
'Hide password': 'パスワードを非表示',
|
|
1131
|
-
'It may take a minute to arrive': '到着するまでに 1
|
|
1145
|
+
'It may take a minute to arrive': '到着するまでに 1 分かかることがあります',
|
|
1132
1146
|
Loading: 'ロード中',
|
|
1133
1147
|
'New password': '新しいパスワード',
|
|
1134
1148
|
or: '又は',
|
|
@@ -1158,7 +1172,7 @@ const jaDict$1 = {
|
|
|
1158
1172
|
Verify: '確認',
|
|
1159
1173
|
'We Sent A Code': 'コードが送信されました',
|
|
1160
1174
|
'We Texted You': 'テキストが送信されました',
|
|
1161
|
-
'Your code is on the way. To log in, enter the code we sent you': '
|
|
1175
|
+
'Your code is on the way. To log in, enter the code we sent you': 'コードが途中です。ログインするには、送信したコードを入力してください',
|
|
1162
1176
|
// Additional translations provided by customers
|
|
1163
1177
|
'An account with the given email already exists.': '入力されたメールアドレスのアカウントが既に存在します',
|
|
1164
1178
|
'Confirm a Code': 'コードを確認',
|
|
@@ -1207,10 +1221,19 @@ const krDict$1 = {
|
|
|
1207
1221
|
'Creating Account': '회원가입중',
|
|
1208
1222
|
'Dismiss alert': '알림 무시',
|
|
1209
1223
|
Email: '이메일',
|
|
1224
|
+
'Enter your Birthdate': '생년월일 입력',
|
|
1210
1225
|
'Enter your code': '인증번호를 입력해주세요',
|
|
1226
|
+
'Enter your Confirmation Code': '확인 코드 입력',
|
|
1211
1227
|
'Enter your Email': '이메일 입력',
|
|
1228
|
+
'Enter your Family Name': '성 입력',
|
|
1229
|
+
'Enter your Given Name': '사용장 이름 입력',
|
|
1230
|
+
'Enter your Name': '이름 입력',
|
|
1231
|
+
'Enter your Nickname': '닉네임 입력',
|
|
1232
|
+
'Enter your Password': '비밀번호 입력',
|
|
1212
1233
|
'Enter your phone number': '전화번호 입력',
|
|
1234
|
+
'Enter your Preferred Username': '선호하는 아이디 입력',
|
|
1213
1235
|
'Enter your username': '아이디를 입력해주세요',
|
|
1236
|
+
'Forgot password?': '비밀번호를 잊으셨나요?',
|
|
1214
1237
|
'Hide password': '비밀번호 숨기기',
|
|
1215
1238
|
'It may take a minute to arrive': '도착하는 데 1분 정도 걸릴 수 있습니다',
|
|
1216
1239
|
Loading: '로딩중',
|
|
@@ -1218,6 +1241,7 @@ const krDict$1 = {
|
|
|
1218
1241
|
or: '또는',
|
|
1219
1242
|
Password: '비밀번호',
|
|
1220
1243
|
'Phone Number': '전화번호',
|
|
1244
|
+
'Please confirm your Password': '비밀번호를 확인해 주세요.',
|
|
1221
1245
|
'Resend Code': '인증번호 재전송',
|
|
1222
1246
|
'Reset your password': '비밀번호 재설정',
|
|
1223
1247
|
'Reset your Password': '비밀번호 재설정',
|
|
@@ -8073,6 +8097,26 @@ const defaultTheme = {
|
|
|
8073
8097
|
};
|
|
8074
8098
|
|
|
8075
8099
|
const CSS_VARIABLE_PREFIX = 'amplify';
|
|
8100
|
+
/**
|
|
8101
|
+
* This will take an object like:
|
|
8102
|
+
* {paddingTop:'20px',color:'{colors.font.primary}'}
|
|
8103
|
+
* and turn it into a CSS string:
|
|
8104
|
+
* `padding-top:20px; color: var(--colors-font-primary);`
|
|
8105
|
+
*/
|
|
8106
|
+
function propsToString(props) {
|
|
8107
|
+
return Object.entries(props)
|
|
8108
|
+
.map(([key, value]) => {
|
|
8109
|
+
const _value = isDesignToken(value)
|
|
8110
|
+
? value.toString()
|
|
8111
|
+
: // @ts-ignore
|
|
8112
|
+
cssValue({ value });
|
|
8113
|
+
return `${kebabCase__default["default"](key)}:${_value}; `;
|
|
8114
|
+
})
|
|
8115
|
+
.join(' ');
|
|
8116
|
+
}
|
|
8117
|
+
function cssNameTransform({ path = [] }) {
|
|
8118
|
+
return `${kebabCase__default["default"]([CSS_VARIABLE_PREFIX, ...path].join(' '))}`;
|
|
8119
|
+
}
|
|
8076
8120
|
// Important: these properties should not be altered in
|
|
8077
8121
|
// order to maintain the expected order of the CSS `box-shadow` property
|
|
8078
8122
|
const SHADOW_PROPERTIES = [
|
|
@@ -8082,15 +8126,12 @@ const SHADOW_PROPERTIES = [
|
|
|
8082
8126
|
'spreadRadius',
|
|
8083
8127
|
'color',
|
|
8084
8128
|
];
|
|
8085
|
-
|
|
8086
|
-
|
|
8087
|
-
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
}
|
|
8092
|
-
return value;
|
|
8093
|
-
}
|
|
8129
|
+
/**
|
|
8130
|
+
* Will take a design token in a theme and return its value as CSS
|
|
8131
|
+
*
|
|
8132
|
+
* @param token
|
|
8133
|
+
* @returns
|
|
8134
|
+
*/
|
|
8094
8135
|
function cssValue(token) {
|
|
8095
8136
|
const { value } = token;
|
|
8096
8137
|
if (isString(value)) {
|
|
@@ -8106,9 +8147,6 @@ function cssValue(token) {
|
|
|
8106
8147
|
}
|
|
8107
8148
|
return value;
|
|
8108
8149
|
}
|
|
8109
|
-
function cssNameTransform({ path = [] }) {
|
|
8110
|
-
return `${kebabCase__default["default"]([CSS_VARIABLE_PREFIX, ...path].join(' '))}`;
|
|
8111
|
-
}
|
|
8112
8150
|
/**
|
|
8113
8151
|
* Helper function to test if something is a design token or not.
|
|
8114
8152
|
* Used in the React component style props.
|
|
@@ -8122,6 +8160,36 @@ function isDesignToken(value) {
|
|
|
8122
8160
|
function isShadowTokenObject(value) {
|
|
8123
8161
|
return isObject(value) && has(value, 'offsetX');
|
|
8124
8162
|
}
|
|
8163
|
+
/**
|
|
8164
|
+
* Function that sees if a string contains a design token reference
|
|
8165
|
+
* and if so will turn that into a CSS variable.
|
|
8166
|
+
*
|
|
8167
|
+
* @param {string} value
|
|
8168
|
+
* @returns string
|
|
8169
|
+
*/
|
|
8170
|
+
function referenceValue(value) {
|
|
8171
|
+
if (!value)
|
|
8172
|
+
return '';
|
|
8173
|
+
if (usesReference(value)) {
|
|
8174
|
+
const path = value.replace(/\{|\}/g, '').replace('.value', '').split('.');
|
|
8175
|
+
return `var(--${cssNameTransform({ path })})`;
|
|
8176
|
+
}
|
|
8177
|
+
return value;
|
|
8178
|
+
}
|
|
8179
|
+
/**
|
|
8180
|
+
* This will take a design token and add some data to it for it
|
|
8181
|
+
* to be used in JS/CSS. It will create its CSS var name and update
|
|
8182
|
+
* the value to use a CSS var if it is a reference. It will also
|
|
8183
|
+
* add a `.toString()` method to make it easier to use in JS.
|
|
8184
|
+
*
|
|
8185
|
+
* We should see if there is a way to share this logic with style dictionary...
|
|
8186
|
+
*/
|
|
8187
|
+
const setupToken = ({ token, path }) => {
|
|
8188
|
+
const name = `--${cssNameTransform({ path })}`;
|
|
8189
|
+
const { value: original } = token;
|
|
8190
|
+
const value = cssValue(token);
|
|
8191
|
+
return { name, original, path, value, toString: () => `var(${name})` };
|
|
8192
|
+
};
|
|
8125
8193
|
/**
|
|
8126
8194
|
* Recursive function that will walk down the token object
|
|
8127
8195
|
* and perform the setupToken function on each token.
|
|
@@ -8145,22 +8213,199 @@ function setupTokens({ tokens, path = [], setupToken, }) {
|
|
|
8145
8213
|
}
|
|
8146
8214
|
return output;
|
|
8147
8215
|
}
|
|
8148
|
-
|
|
8149
8216
|
// Internal Style Dictionary methods
|
|
8217
|
+
// copied from amzn/style-dictionary with the owner's permission
|
|
8150
8218
|
/**
|
|
8151
|
-
*
|
|
8152
|
-
*
|
|
8153
|
-
*
|
|
8154
|
-
*
|
|
8219
|
+
* Takes an plain javascript object and will make a flat array of all the leaf nodes.
|
|
8220
|
+
* A leaf node in this context has a 'value' property. Potentially refactor this to
|
|
8221
|
+
* be more generic.
|
|
8222
|
+
* @private
|
|
8223
|
+
* @param {Object} properties - The plain object you want flattened into an array.
|
|
8224
|
+
* @param {Array} [to_ret=[]] - Properties array. This function is recursive therefore this is what gets passed along.
|
|
8225
|
+
* @return {Array}
|
|
8226
|
+
*/
|
|
8227
|
+
function flattenProperties(properties, to_ret) {
|
|
8228
|
+
to_ret = to_ret || [];
|
|
8229
|
+
for (var name in properties) {
|
|
8230
|
+
if (has(properties, name)) {
|
|
8231
|
+
if (isObject(properties[name]) && 'value' in properties[name]) {
|
|
8232
|
+
to_ret.push(properties[name]);
|
|
8233
|
+
}
|
|
8234
|
+
else if (isObject(properties[name])) {
|
|
8235
|
+
flattenProperties(properties[name], to_ret);
|
|
8236
|
+
}
|
|
8237
|
+
}
|
|
8238
|
+
}
|
|
8239
|
+
return to_ret;
|
|
8240
|
+
}
|
|
8241
|
+
/**
|
|
8242
|
+
* Performs an deep extend on the objects, from right to left.
|
|
8243
|
+
* @private
|
|
8244
|
+
* @param {Object[]} objects - An array of JS objects
|
|
8245
|
+
* @param {Function} collision - A function to be called when a merge collision happens.
|
|
8246
|
+
* @param {string[]} path - (for internal use) An array of strings which is the current path down the object when this is called recursively.
|
|
8247
|
+
* @returns {Object}
|
|
8248
|
+
*/
|
|
8249
|
+
function deepExtend(objects, collision, path) {
|
|
8250
|
+
if (objects == null)
|
|
8251
|
+
return {};
|
|
8252
|
+
var src, copyIsArray, copy, name, options, clone, target = objects[0] || {}, i = 1, length = objects.length;
|
|
8253
|
+
path = path || [];
|
|
8254
|
+
// Handle case when target is a string or something (possible in deep copy)
|
|
8255
|
+
if (typeof target !== 'object') {
|
|
8256
|
+
target = {};
|
|
8257
|
+
}
|
|
8258
|
+
for (; i < length; i++) {
|
|
8259
|
+
// Only deal with non-null/undefined values
|
|
8260
|
+
if ((options = objects[i]) != null) {
|
|
8261
|
+
// Extend the base object
|
|
8262
|
+
for (name in options) {
|
|
8263
|
+
if (!has(options, name))
|
|
8264
|
+
continue;
|
|
8265
|
+
if (name === '__proto__')
|
|
8266
|
+
continue;
|
|
8267
|
+
src = target[name];
|
|
8268
|
+
copy = options[name];
|
|
8269
|
+
// Prevent never-ending loop
|
|
8270
|
+
if (target === copy) {
|
|
8271
|
+
continue;
|
|
8272
|
+
}
|
|
8273
|
+
// Recurse if we're merging plain objects or arrays
|
|
8274
|
+
if (copy && (isObject(copy) || (copyIsArray = Array.isArray(copy)))) {
|
|
8275
|
+
if (copyIsArray) {
|
|
8276
|
+
copyIsArray = false;
|
|
8277
|
+
clone = src && Array.isArray(src) ? src : [];
|
|
8278
|
+
}
|
|
8279
|
+
else {
|
|
8280
|
+
clone = src && isObject(src) ? src : {};
|
|
8281
|
+
}
|
|
8282
|
+
var nextPath = path.slice(0);
|
|
8283
|
+
nextPath.push(name);
|
|
8284
|
+
// Never move original objects, clone them
|
|
8285
|
+
target[name] = deepExtend([clone, copy], collision, nextPath);
|
|
8286
|
+
// Don't bring in undefined values
|
|
8287
|
+
}
|
|
8288
|
+
else if (copy !== undefined) {
|
|
8289
|
+
if (src != null && typeof collision == 'function') {
|
|
8290
|
+
collision({ target: target, copy: options, path: path, key: name });
|
|
8291
|
+
}
|
|
8292
|
+
target[name] = copy;
|
|
8293
|
+
}
|
|
8294
|
+
}
|
|
8295
|
+
}
|
|
8296
|
+
}
|
|
8297
|
+
return target;
|
|
8298
|
+
}
|
|
8299
|
+
/**
|
|
8300
|
+
* Checks if the value uses a value reference.
|
|
8301
|
+
* @param {string} value
|
|
8302
|
+
* @returns {boolean} - True, if the value uses a value reference
|
|
8303
|
+
*/
|
|
8304
|
+
function usesReference(value) {
|
|
8305
|
+
const regex = new RegExp('\\{([^}]+)\\}', 'g');
|
|
8306
|
+
if (typeof value === 'string') {
|
|
8307
|
+
return regex.test(value);
|
|
8308
|
+
}
|
|
8309
|
+
if (typeof value === 'object') {
|
|
8310
|
+
let hasReference = false;
|
|
8311
|
+
// iterate over each property in the object,
|
|
8312
|
+
// if any element passes the regex test,
|
|
8313
|
+
// the whole thing should be true
|
|
8314
|
+
for (const key in value) {
|
|
8315
|
+
if (has(value, key)) {
|
|
8316
|
+
const element = value[key];
|
|
8317
|
+
let reference = usesReference(element);
|
|
8318
|
+
if (reference) {
|
|
8319
|
+
hasReference = true;
|
|
8320
|
+
break;
|
|
8321
|
+
}
|
|
8322
|
+
}
|
|
8323
|
+
}
|
|
8324
|
+
return hasReference;
|
|
8325
|
+
}
|
|
8326
|
+
return false;
|
|
8327
|
+
}
|
|
8328
|
+
|
|
8329
|
+
function addVars(selector, vars) {
|
|
8330
|
+
if (!vars)
|
|
8331
|
+
return '';
|
|
8332
|
+
return `${selector} { ${Object.entries(vars)
|
|
8333
|
+
.map(([key, value]) => {
|
|
8334
|
+
return `--${key}:${value}; `;
|
|
8335
|
+
})
|
|
8336
|
+
.join(' ')}}\n`;
|
|
8337
|
+
}
|
|
8338
|
+
function recursiveComponentCSS(baseSelector, theme) {
|
|
8339
|
+
let str = '';
|
|
8340
|
+
const { _modifiers = {}, _element = {}, _vars, ...props } = theme;
|
|
8341
|
+
// if there are no props, skip
|
|
8342
|
+
if (Object.keys(props).length) {
|
|
8343
|
+
// separate psuedo/attribute selectors
|
|
8344
|
+
const [selectors, other] = splitObject(props, (key) => key.startsWith(':') || key.startsWith('['));
|
|
8345
|
+
Object.entries(selectors).forEach(([selector, value]) => {
|
|
8346
|
+
// need to remove nested things like vars and elements
|
|
8347
|
+
const { _modifiers = {}, _element = {}, _vars, ...props } = value;
|
|
8348
|
+
str += `${baseSelector}${selector} { ${propsToString(props)} }\n`;
|
|
8349
|
+
str += addVars(`${baseSelector}${selector}`, _vars);
|
|
8350
|
+
});
|
|
8351
|
+
str += `${baseSelector} { ${propsToString(other)} }\n`;
|
|
8352
|
+
}
|
|
8353
|
+
str += addVars(baseSelector, _vars);
|
|
8354
|
+
Object.entries(_modifiers).forEach(([key, value]) => {
|
|
8355
|
+
if (value && Object.keys(value).length) {
|
|
8356
|
+
str += recursiveComponentCSS(`${baseSelector}--${key}`, value);
|
|
8357
|
+
}
|
|
8358
|
+
});
|
|
8359
|
+
Object.entries(_element).forEach(([key, value]) => {
|
|
8360
|
+
if (value && Object.keys(value).length) {
|
|
8361
|
+
str += recursiveComponentCSS(`${baseSelector}__${key}`, value);
|
|
8362
|
+
}
|
|
8363
|
+
});
|
|
8364
|
+
return str;
|
|
8365
|
+
}
|
|
8366
|
+
/**
|
|
8367
|
+
* This will take a component theme and create the appropriate CSS for it.
|
|
8155
8368
|
*
|
|
8156
|
-
* We should see if there is a way to share this logic with style dictionary...
|
|
8157
8369
|
*/
|
|
8158
|
-
|
|
8159
|
-
|
|
8160
|
-
|
|
8161
|
-
|
|
8162
|
-
|
|
8163
|
-
|
|
8370
|
+
function createComponentCSS(themeName, components, tokens, breakpoints) {
|
|
8371
|
+
let cssText = '';
|
|
8372
|
+
components.forEach(({ name, theme, overrides }) => {
|
|
8373
|
+
const baseComponentClassName = `amplify-${name}`;
|
|
8374
|
+
const componentClassName = `[data-amplify-theme="${themeName}"] .${baseComponentClassName}`;
|
|
8375
|
+
// unwrap the component theme
|
|
8376
|
+
// if it is a function: call it with the defaultTheme to get a static object
|
|
8377
|
+
const componentTheme = isFunction(theme)
|
|
8378
|
+
? theme(tokens)
|
|
8379
|
+
: theme;
|
|
8380
|
+
cssText += recursiveComponentCSS(componentClassName, componentTheme);
|
|
8381
|
+
// if the component theme has overrides
|
|
8382
|
+
// generate the appropriate CSS for each of them
|
|
8383
|
+
if (overrides) {
|
|
8384
|
+
overrides.forEach((override) => {
|
|
8385
|
+
// unwrap the override component theme just like above
|
|
8386
|
+
const componentTheme = isFunction(override.theme)
|
|
8387
|
+
? override.theme(tokens)
|
|
8388
|
+
: override.theme;
|
|
8389
|
+
if ('mediaQuery' in override) {
|
|
8390
|
+
cssText += `@media (${override.mediaQuery}) {\n ${recursiveComponentCSS(componentClassName, componentTheme)} \n}`;
|
|
8391
|
+
}
|
|
8392
|
+
if ('breakpoint' in override) {
|
|
8393
|
+
const breakpoint = breakpoints.values[override.breakpoint];
|
|
8394
|
+
cssText += `\n@media (min-width: ${breakpoint}px) {\n ${recursiveComponentCSS(componentClassName, componentTheme)} \n}`;
|
|
8395
|
+
}
|
|
8396
|
+
if ('selector' in override) {
|
|
8397
|
+
cssText += recursiveComponentCSS(`${override.selector} .${baseComponentClassName}`, componentTheme);
|
|
8398
|
+
}
|
|
8399
|
+
if ('colorMode' in override) {
|
|
8400
|
+
cssText += `\n@media (prefers-color-scheme: ${override.colorMode}) {\n${recursiveComponentCSS(`[data-amplify-theme="${themeName}"][data-amplify-color-mode="system"] .${baseComponentClassName}`, componentTheme)}\n}\n`;
|
|
8401
|
+
cssText += recursiveComponentCSS(`[data-amplify-theme="${themeName}"][data-amplify-color-mode="${override.colorMode}"] .${baseComponentClassName}`, componentTheme);
|
|
8402
|
+
}
|
|
8403
|
+
});
|
|
8404
|
+
}
|
|
8405
|
+
});
|
|
8406
|
+
return cssText;
|
|
8407
|
+
}
|
|
8408
|
+
|
|
8164
8409
|
/**
|
|
8165
8410
|
* Takes a set of keys and a color name and returns an object of design tokens,
|
|
8166
8411
|
* used for applying a primary color at the theme level to our tokens.
|
|
@@ -8180,6 +8425,24 @@ function createColorPalette({ keys, value }) {
|
|
|
8180
8425
|
};
|
|
8181
8426
|
}, {});
|
|
8182
8427
|
}
|
|
8428
|
+
|
|
8429
|
+
function createAnimationCSS({ animations, tokens, }) {
|
|
8430
|
+
let cssText = '';
|
|
8431
|
+
Object.entries(animations).forEach(([key, value]) => {
|
|
8432
|
+
cssText += `\n @keyframes ${key} {`;
|
|
8433
|
+
Object.entries(value).forEach(([step, properties]) => {
|
|
8434
|
+
cssText += `\n ${step} {\n`;
|
|
8435
|
+
const animationProperties = isFunction(properties)
|
|
8436
|
+
? properties(tokens)
|
|
8437
|
+
: properties;
|
|
8438
|
+
cssText += propsToString(animationProperties);
|
|
8439
|
+
cssText += `\n }`;
|
|
8440
|
+
});
|
|
8441
|
+
cssText += `\n }`;
|
|
8442
|
+
});
|
|
8443
|
+
return cssText;
|
|
8444
|
+
}
|
|
8445
|
+
|
|
8183
8446
|
/**
|
|
8184
8447
|
* This will be used like `const myTheme = createTheme({})`
|
|
8185
8448
|
* `myTheme` can then be passed to a Provider or the generated CSS
|
|
@@ -8192,7 +8455,14 @@ function createTheme(theme, DefaultTheme = defaultTheme) {
|
|
|
8192
8455
|
// deepExtend is an internal Style Dictionary method
|
|
8193
8456
|
// that performs a deep merge on n objects. We could change
|
|
8194
8457
|
// this to another 3p deep merge solution too.
|
|
8195
|
-
const mergedTheme =
|
|
8458
|
+
const mergedTheme = deepExtend([
|
|
8459
|
+
{},
|
|
8460
|
+
DefaultTheme,
|
|
8461
|
+
{
|
|
8462
|
+
...theme,
|
|
8463
|
+
components: {},
|
|
8464
|
+
},
|
|
8465
|
+
]);
|
|
8196
8466
|
const { primaryColor, secondaryColor } = mergedTheme;
|
|
8197
8467
|
// apply primaryColor and secondaryColor if present
|
|
8198
8468
|
if (isString(primaryColor)) {
|
|
@@ -8219,11 +8489,20 @@ function createTheme(theme, DefaultTheme = defaultTheme) {
|
|
|
8219
8489
|
// flattenProperties is another internal Style Dictionary function
|
|
8220
8490
|
// that creates an array of all tokens.
|
|
8221
8491
|
let cssText = `[data-amplify-theme="${name}"] {\n` +
|
|
8222
|
-
|
|
8492
|
+
flattenProperties(tokens)
|
|
8223
8493
|
.map((token) => `${token.name}: ${token.value};`)
|
|
8224
8494
|
.join('\n') +
|
|
8225
8495
|
`\n}\n`;
|
|
8496
|
+
if (theme?.components) {
|
|
8497
|
+
cssText += createComponentCSS(name, theme.components, tokens, mergedTheme.breakpoints);
|
|
8498
|
+
}
|
|
8226
8499
|
let overrides = [];
|
|
8500
|
+
if (mergedTheme.animations) {
|
|
8501
|
+
cssText += createAnimationCSS({
|
|
8502
|
+
animations: mergedTheme.animations,
|
|
8503
|
+
tokens,
|
|
8504
|
+
});
|
|
8505
|
+
}
|
|
8227
8506
|
/**
|
|
8228
8507
|
* For each override, we setup the tokens and then generate the CSS.
|
|
8229
8508
|
* This allows us to have one single CSS string for all possible overrides
|
|
@@ -8231,11 +8510,11 @@ function createTheme(theme, DefaultTheme = defaultTheme) {
|
|
|
8231
8510
|
*/
|
|
8232
8511
|
if (mergedTheme.overrides) {
|
|
8233
8512
|
overrides = mergedTheme.overrides.map((override) => {
|
|
8234
|
-
const
|
|
8513
|
+
const overrideTokens = setupTokens({
|
|
8235
8514
|
tokens: override.tokens,
|
|
8236
8515
|
setupToken,
|
|
8237
8516
|
});
|
|
8238
|
-
const customProperties =
|
|
8517
|
+
const customProperties = flattenProperties(overrideTokens)
|
|
8239
8518
|
.map((token) => `${token.name}: ${token.value};`)
|
|
8240
8519
|
.join('\n');
|
|
8241
8520
|
// Overrides can have a selector, media query, breakpoint, or color mode
|
|
@@ -8272,7 +8551,7 @@ function createTheme(theme, DefaultTheme = defaultTheme) {
|
|
|
8272
8551
|
}
|
|
8273
8552
|
return {
|
|
8274
8553
|
...override,
|
|
8275
|
-
tokens,
|
|
8554
|
+
tokens: overrideTokens,
|
|
8276
8555
|
};
|
|
8277
8556
|
});
|
|
8278
8557
|
}
|
|
@@ -8281,6 +8560,12 @@ function createTheme(theme, DefaultTheme = defaultTheme) {
|
|
|
8281
8560
|
breakpoints,
|
|
8282
8561
|
name,
|
|
8283
8562
|
cssText,
|
|
8563
|
+
containerProps: ({ colorMode } = {}) => {
|
|
8564
|
+
return {
|
|
8565
|
+
'data-amplify-theme': name,
|
|
8566
|
+
'data-amplify-color-mode': colorMode,
|
|
8567
|
+
};
|
|
8568
|
+
},
|
|
8284
8569
|
// keep overrides separate from base theme
|
|
8285
8570
|
// this allows web platforms to use plain CSS scoped to a
|
|
8286
8571
|
// selector and only override the CSS vars needed. This
|
|
@@ -8293,6 +8578,112 @@ function createTheme(theme, DefaultTheme = defaultTheme) {
|
|
|
8293
8578
|
};
|
|
8294
8579
|
}
|
|
8295
8580
|
|
|
8581
|
+
function createComponentClasses({ name, prefix = 'amplify-' }) {
|
|
8582
|
+
const className = (props = {}, extraClassnames = []) => {
|
|
8583
|
+
const baseComponentClassName = `${prefix}${name}`;
|
|
8584
|
+
// get the element if there is one
|
|
8585
|
+
// the _element argument can be a string
|
|
8586
|
+
// like { _element: 'icon' }
|
|
8587
|
+
// or it could be an object where the key is
|
|
8588
|
+
// the element name and the value is the modifiers
|
|
8589
|
+
// like { _element: { icon: [size] } }
|
|
8590
|
+
const element = isString(props._element)
|
|
8591
|
+
? props._element
|
|
8592
|
+
: isObject(props._element)
|
|
8593
|
+
? Object.keys(props._element)[0]
|
|
8594
|
+
: undefined;
|
|
8595
|
+
const className = element
|
|
8596
|
+
? `${baseComponentClassName}__${element}`
|
|
8597
|
+
: baseComponentClassName;
|
|
8598
|
+
const names = [className];
|
|
8599
|
+
if (element) {
|
|
8600
|
+
const modifiers = props._element[element];
|
|
8601
|
+
names.push(...modifierClassnames({ className, modifiers }));
|
|
8602
|
+
}
|
|
8603
|
+
else {
|
|
8604
|
+
names.push(...modifierClassnames({
|
|
8605
|
+
className,
|
|
8606
|
+
modifiers: props._modifiers,
|
|
8607
|
+
}));
|
|
8608
|
+
}
|
|
8609
|
+
return classNames([...names, ...extraClassnames]);
|
|
8610
|
+
};
|
|
8611
|
+
return className;
|
|
8612
|
+
}
|
|
8613
|
+
function modifierClassnames({ className, modifiers, }) {
|
|
8614
|
+
if (Array.isArray(modifiers)) {
|
|
8615
|
+
return modifiers.map((modifier) => {
|
|
8616
|
+
if (!modifier || !isString(modifier)) {
|
|
8617
|
+
return;
|
|
8618
|
+
}
|
|
8619
|
+
return `${className}--${modifier}`;
|
|
8620
|
+
});
|
|
8621
|
+
}
|
|
8622
|
+
if (isObject(modifiers)) {
|
|
8623
|
+
return Object.entries(modifiers).map(([key, value]) => {
|
|
8624
|
+
if (value) {
|
|
8625
|
+
return `${className}--${key}`;
|
|
8626
|
+
}
|
|
8627
|
+
});
|
|
8628
|
+
}
|
|
8629
|
+
if (isString(modifiers)) {
|
|
8630
|
+
return [`${className}--${modifiers}`];
|
|
8631
|
+
}
|
|
8632
|
+
return [];
|
|
8633
|
+
}
|
|
8634
|
+
|
|
8635
|
+
/**
|
|
8636
|
+
* Use this to create the theme of a component. You can use this
|
|
8637
|
+
* to both completely customize built-in components and
|
|
8638
|
+
* build your own components!
|
|
8639
|
+
*
|
|
8640
|
+
* @experimental
|
|
8641
|
+
*
|
|
8642
|
+
* ```ts
|
|
8643
|
+
* // built-in component styling
|
|
8644
|
+
* const alertTheme = defineComponentTheme({
|
|
8645
|
+
* name: 'alert',
|
|
8646
|
+
* theme: (tokens) => {
|
|
8647
|
+
* return {
|
|
8648
|
+
* padding: tokens.space.large
|
|
8649
|
+
* }
|
|
8650
|
+
* }
|
|
8651
|
+
* });
|
|
8652
|
+
*
|
|
8653
|
+
* // custom component styling
|
|
8654
|
+
* const avatarTheme = defineComponentTheme({
|
|
8655
|
+
* name: 'avatar',
|
|
8656
|
+
* theme: (tokens) => {
|
|
8657
|
+
* return {
|
|
8658
|
+
* padding: tokens.space.large
|
|
8659
|
+
* }
|
|
8660
|
+
* }
|
|
8661
|
+
* })
|
|
8662
|
+
*
|
|
8663
|
+
* const theme = createTheme({
|
|
8664
|
+
* name: 'my-theme',
|
|
8665
|
+
* components: [alertTheme, avatarTheme]
|
|
8666
|
+
* })
|
|
8667
|
+
* ```
|
|
8668
|
+
*
|
|
8669
|
+
* @param {Object} params
|
|
8670
|
+
* @param {string} params.name - The name of the component. Use a built-in component name like button to theme buttons.
|
|
8671
|
+
* @returns
|
|
8672
|
+
*/
|
|
8673
|
+
function defineComponentTheme({ name, theme, overrides, }) {
|
|
8674
|
+
const prefix = 'amplify-';
|
|
8675
|
+
const className = createComponentClasses({
|
|
8676
|
+
name,
|
|
8677
|
+
prefix,
|
|
8678
|
+
});
|
|
8679
|
+
return {
|
|
8680
|
+
className,
|
|
8681
|
+
theme,
|
|
8682
|
+
overrides,
|
|
8683
|
+
name,
|
|
8684
|
+
};
|
|
8685
|
+
}
|
|
8686
|
+
|
|
8296
8687
|
const darkModeTokens = {
|
|
8297
8688
|
colors: {
|
|
8298
8689
|
red: {
|
|
@@ -8440,6 +8831,7 @@ exports.classNameModifierByFlag = classNameModifierByFlag;
|
|
|
8440
8831
|
exports.classNames = classNames;
|
|
8441
8832
|
exports.countryDialCodes = countryDialCodes;
|
|
8442
8833
|
exports.createAuthenticatorMachine = createAuthenticatorMachine;
|
|
8834
|
+
exports.createComponentClasses = createComponentClasses;
|
|
8443
8835
|
exports.createTheme = createTheme;
|
|
8444
8836
|
exports.cssNameTransform = cssNameTransform;
|
|
8445
8837
|
exports.defaultAuthHubHandler = defaultAuthHubHandler;
|
|
@@ -8447,6 +8839,7 @@ exports.defaultDarkModeOverride = defaultDarkModeOverride;
|
|
|
8447
8839
|
exports.defaultFormFieldOptions = defaultFormFieldOptions;
|
|
8448
8840
|
exports.defaultFormFieldsGetters = defaultFormFieldsGetters;
|
|
8449
8841
|
exports.defaultTheme = defaultTheme;
|
|
8842
|
+
exports.defineComponentTheme = defineComponentTheme;
|
|
8450
8843
|
exports.deleteUser = deleteUser;
|
|
8451
8844
|
exports.emailRegex = emailRegex;
|
|
8452
8845
|
exports.getActorContext = getActorContext$1;
|
|
@@ -8500,6 +8893,7 @@ exports.setupTokens = setupTokens;
|
|
|
8500
8893
|
exports.signUpFieldsWithDefault = signUpFieldsWithDefault;
|
|
8501
8894
|
exports.signUpFieldsWithoutDefault = signUpFieldsWithoutDefault;
|
|
8502
8895
|
exports.sortFormFields = sortFormFields;
|
|
8896
|
+
exports.splitObject = splitObject;
|
|
8503
8897
|
exports.templateJoin = templateJoin;
|
|
8504
8898
|
exports.translate = translate;
|
|
8505
8899
|
exports.translations = translations;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Modifiers, ComponentStyles, Elements, ColorTheme } from './utils';
|
|
2
|
+
export type AlertTheme<Required extends boolean = false> = ComponentStyles & Modifiers<ColorTheme, Required> & Elements<{
|
|
3
|
+
[key in 'icon' | 'heading' | 'body' | 'dismiss']?: ComponentStyles;
|
|
4
|
+
}, Required>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Modifiers, ComponentStyles, Elements } from './utils';
|
|
2
|
+
export type AutoCompleteTheme<Required extends boolean = false> = ComponentStyles & Elements<{
|
|
3
|
+
menu?: ComponentStyles & Modifiers<'empty' | 'loading', Required>;
|
|
4
|
+
menu__option?: ComponentStyles & Modifiers<'active', Required>;
|
|
5
|
+
menu__options?: ComponentStyles;
|
|
6
|
+
menu__header?: ComponentStyles;
|
|
7
|
+
menu__footer?: ComponentStyles;
|
|
8
|
+
}, Required>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Modifiers, ComponentStyles, Elements, ColorTheme, Size } from './utils';
|
|
2
|
+
export type BadgeTheme<Required extends boolean = false> = ComponentStyles & Modifiers<Size | ColorTheme, Required> & Elements<{
|
|
3
|
+
[key in 'icon' | 'heading' | 'body' | 'dismiss']?: ComponentStyles;
|
|
4
|
+
}, Required>;
|