@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.
Files changed (71) hide show
  1. package/dist/esm/i18n/dictionaries/authenticator/ja.mjs +2 -2
  2. package/dist/esm/i18n/dictionaries/authenticator/kr.mjs +10 -0
  3. package/dist/esm/index.mjs +5 -3
  4. package/dist/esm/theme/createTheme/createAnimationCSS.mjs +23 -0
  5. package/dist/esm/theme/createTheme/createColorPalette.mjs +21 -0
  6. package/dist/esm/theme/createTheme/createComponentCSS.mjs +86 -0
  7. package/dist/esm/theme/createTheme/createComponentClasses.mjs +60 -0
  8. package/dist/esm/theme/{createTheme.mjs → createTheme/createTheme.mjs} +33 -44
  9. package/dist/esm/theme/createTheme/defineComponentTheme.mjs +55 -0
  10. package/dist/esm/theme/createTheme/utils.mjs +236 -0
  11. package/dist/esm/utils/utils.mjs +21 -1
  12. package/dist/index.js +431 -37
  13. package/dist/types/theme/components/accordion.d.ts +4 -0
  14. package/dist/types/theme/components/alert.d.ts +4 -0
  15. package/dist/types/theme/components/autocomplete.d.ts +8 -0
  16. package/dist/types/theme/components/badge.d.ts +4 -0
  17. package/dist/types/theme/components/breadcrumbs.d.ts +7 -0
  18. package/dist/types/theme/components/button.d.ts +7 -0
  19. package/dist/types/theme/components/buttonGroup.d.ts +2 -0
  20. package/dist/types/theme/components/card.d.ts +2 -0
  21. package/dist/types/theme/components/checkbox.d.ts +7 -0
  22. package/dist/types/theme/components/checkboxField.d.ts +2 -0
  23. package/dist/types/theme/components/collection.d.ts +4 -0
  24. package/dist/types/theme/components/divider.d.ts +2 -0
  25. package/dist/types/theme/components/dropZone.d.ts +2 -0
  26. package/dist/types/theme/components/field.d.ts +6 -0
  27. package/dist/types/theme/components/fieldGroup.d.ts +11 -0
  28. package/dist/types/theme/components/fieldset.d.ts +4 -0
  29. package/dist/types/theme/components/heading.d.ts +4 -0
  30. package/dist/types/theme/components/highlightMatch.d.ts +4 -0
  31. package/dist/types/theme/components/index.d.ts +92 -0
  32. package/dist/types/theme/components/input.d.ts +2 -0
  33. package/dist/types/theme/components/loader.d.ts +4 -0
  34. package/dist/types/theme/components/menu.d.ts +4 -0
  35. package/dist/types/theme/components/message.d.ts +4 -0
  36. package/dist/types/theme/components/pagination.d.ts +4 -0
  37. package/dist/types/theme/components/placeholder.d.ts +2 -0
  38. package/dist/types/theme/components/radio.d.ts +6 -0
  39. package/dist/types/theme/components/rating.d.ts +5 -0
  40. package/dist/types/theme/components/scrollview.d.ts +2 -0
  41. package/dist/types/theme/components/searchField.d.ts +4 -0
  42. package/dist/types/theme/components/select.d.ts +5 -0
  43. package/dist/types/theme/components/selectField.d.ts +2 -0
  44. package/dist/types/theme/components/sliderField.d.ts +9 -0
  45. package/dist/types/theme/components/stepperField.d.ts +6 -0
  46. package/dist/types/theme/components/storageManager.d.ts +20 -0
  47. package/dist/types/theme/components/switchField.d.ts +8 -0
  48. package/dist/types/theme/components/table.d.ts +4 -0
  49. package/dist/types/theme/components/tabs.d.ts +6 -0
  50. package/dist/types/theme/components/text.d.ts +3 -0
  51. package/dist/types/theme/components/textField.d.ts +2 -0
  52. package/dist/types/theme/components/textarea.d.ts +2 -0
  53. package/dist/types/theme/components/textareaField.d.ts +2 -0
  54. package/dist/types/theme/components/toggleButton.d.ts +3 -0
  55. package/dist/types/theme/components/utils.d.ts +52 -0
  56. package/dist/types/theme/createTheme/createAnimationCSS.d.ts +6 -0
  57. package/dist/types/theme/createTheme/createColorPalette.d.ts +16 -0
  58. package/dist/types/theme/createTheme/createComponentCSS.d.ts +7 -0
  59. package/dist/types/theme/createTheme/createComponentClasses.d.ts +25 -0
  60. package/dist/types/theme/{createTheme.d.ts → createTheme/createTheme.d.ts} +3 -2
  61. package/dist/types/theme/createTheme/defineComponentTheme.d.ts +54 -0
  62. package/dist/types/theme/createTheme/index.d.ts +4 -0
  63. package/dist/types/theme/createTheme/utils.d.ts +92 -0
  64. package/dist/types/theme/index.d.ts +1 -2
  65. package/dist/types/theme/types.d.ts +20 -3
  66. package/dist/types/utils/classNames.d.ts +1 -1
  67. package/dist/types/utils/index.d.ts +1 -1
  68. package/dist/types/utils/utils.d.ts +8 -0
  69. package/package.json +3 -3
  70. package/dist/esm/theme/utils.mjs +0 -81
  71. package/dist/types/theme/utils.d.ts +0 -35
@@ -0,0 +1,92 @@
1
+ import { WebDesignToken } from '../types';
2
+ import { ShadowValue } from '../tokens/types/designToken';
3
+ import { CSSProperties } from '../components/utils';
4
+ export declare const CSS_VARIABLE_PREFIX = "amplify";
5
+ interface NameTransformProps {
6
+ path?: Array<string>;
7
+ }
8
+ /**
9
+ * This will take an object like:
10
+ * {paddingTop:'20px',color:'{colors.font.primary}'}
11
+ * and turn it into a CSS string:
12
+ * `padding-top:20px; color: var(--colors-font-primary);`
13
+ */
14
+ export declare function propsToString(props: CSSProperties): string;
15
+ export declare function cssNameTransform({ path }: NameTransformProps): string;
16
+ type BaseDesignToken = {
17
+ value: string | number;
18
+ };
19
+ /**
20
+ * Will take a design token in a theme and return its value as CSS
21
+ *
22
+ * @param token
23
+ * @returns
24
+ */
25
+ export declare function cssValue(token: BaseDesignToken): string | number;
26
+ /**
27
+ * Helper function to test if something is a design token or not.
28
+ * Used in the React component style props.
29
+ *
30
+ * @param value - thing to test if it is a design token or not
31
+ * @returns boolean
32
+ */
33
+ export declare function isDesignToken(value: unknown): value is WebDesignToken;
34
+ export declare function isShadowTokenObject(value: unknown): value is ShadowValue & object;
35
+ /**
36
+ * Function that sees if a string contains a design token reference
37
+ * and if so will turn that into a CSS variable.
38
+ *
39
+ * @param {string} value
40
+ * @returns string
41
+ */
42
+ export declare function referenceValue(value?: string): string;
43
+ export type SetupToken<ReturnType = any> = (args: {
44
+ token: BaseDesignToken;
45
+ path: Array<string>;
46
+ }) => ReturnType;
47
+ /**
48
+ * This will take a design token and add some data to it for it
49
+ * to be used in JS/CSS. It will create its CSS var name and update
50
+ * the value to use a CSS var if it is a reference. It will also
51
+ * add a `.toString()` method to make it easier to use in JS.
52
+ *
53
+ * We should see if there is a way to share this logic with style dictionary...
54
+ */
55
+ export declare const setupToken: SetupToken<WebDesignToken>;
56
+ type SetupTokensProps = {
57
+ tokens?: Record<string | number, any>;
58
+ path?: Array<string>;
59
+ setupToken: SetupToken;
60
+ };
61
+ /**
62
+ * Recursive function that will walk down the token object
63
+ * and perform the setupToken function on each token.
64
+ * Similar to what Style Dictionary does.
65
+ */
66
+ export declare function setupTokens({ tokens, path, setupToken, }: SetupTokensProps): any;
67
+ /**
68
+ * Takes an plain javascript object and will make a flat array of all the leaf nodes.
69
+ * A leaf node in this context has a 'value' property. Potentially refactor this to
70
+ * be more generic.
71
+ * @private
72
+ * @param {Object} properties - The plain object you want flattened into an array.
73
+ * @param {Array} [to_ret=[]] - Properties array. This function is recursive therefore this is what gets passed along.
74
+ * @return {Array}
75
+ */
76
+ export declare function flattenProperties(properties: object, to_ret?: object[]): object[];
77
+ /**
78
+ * Performs an deep extend on the objects, from right to left.
79
+ * @private
80
+ * @param {Object[]} objects - An array of JS objects
81
+ * @param {Function} collision - A function to be called when a merge collision happens.
82
+ * @param {string[]} path - (for internal use) An array of strings which is the current path down the object when this is called recursively.
83
+ * @returns {Object}
84
+ */
85
+ export declare function deepExtend<T>(objects?: (object | undefined)[], collision?: Function, path?: string[]): T;
86
+ /**
87
+ * Checks if the value uses a value reference.
88
+ * @param {string} value
89
+ * @returns {boolean} - True, if the value uses a value reference
90
+ */
91
+ export declare function usesReference(value: any): boolean;
92
+ export {};
@@ -1,6 +1,5 @@
1
- export { createTheme } from './createTheme';
1
+ export { createTheme, defineComponentTheme, createComponentClasses, cssNameTransform, isDesignToken, setupTokens, SetupToken, } from './createTheme';
2
2
  export { defaultTheme } from './defaultTheme';
3
3
  export { defaultDarkModeOverride, reactNativeDarkTokens, } from './defaultDarkModeOverride';
4
4
  export { reactNativeTokens, ReactNativeTokens } from './tokens';
5
5
  export * from './types';
6
- export { cssNameTransform, isDesignToken, setupTokens, SetupToken, } from './utils';
@@ -1,6 +1,8 @@
1
1
  import { PartialDeep } from '../types';
2
2
  import { DefaultTokens, Tokens, WebTokens } from './tokens';
3
3
  import { Breakpoints } from './breakpoints';
4
+ import { ComponentsTheme } from './components';
5
+ import { CSSProperties } from './components/utils';
4
6
  export * from './tokens/types/designToken';
5
7
  export type { BorderWidths } from './tokens/borderWidths';
6
8
  export type { FontSizes } from './tokens/fontSizes';
@@ -9,6 +11,7 @@ export type { LineHeights } from './tokens/lineHeights';
9
11
  export type { Radii } from './tokens/radii';
10
12
  export type { Shadows } from './tokens/shadows';
11
13
  export type { SpaceSizes } from './tokens/space';
14
+ export { Tokens };
12
15
  /**
13
16
  * An override is a set of tokens that override others
14
17
  * in certain contexts. On Android, these are like resource
@@ -82,7 +85,7 @@ export interface ColorModeOverride extends BaseOverride {
82
85
  * They can define any tokens or breakpoints they need, but they don't need a
83
86
  * complete theme with all tokens.
84
87
  */
85
- export interface Theme {
88
+ export interface Theme<TokensType extends WebTokens = WebTokens> {
86
89
  /**
87
90
  * The name of the theme. This is used to create scoped CSS to allow for
88
91
  * multiple themes on a page.
@@ -99,22 +102,36 @@ export interface Theme {
99
102
  * and a generic selector override.
100
103
  */
101
104
  overrides?: Array<Override>;
105
+ components?: Array<ComponentsTheme<TokensType>>;
106
+ animations?: Animations;
107
+ }
108
+ export interface Animations {
109
+ [key: string]: {
110
+ [key in 'to' | 'from' | `${string}%`]?: CSSProperties | ((tokens: WebTokens) => CSSProperties);
111
+ };
102
112
  }
103
113
  /**
104
114
  * A DefaultTheme has all tokens and breakpoints required
105
115
  */
106
- export interface DefaultTheme extends Pick<Theme, 'name' | 'overrides' | 'primaryColor' | 'secondaryColor'> {
116
+ export interface DefaultTheme extends Pick<Theme, 'name' | 'overrides' | 'primaryColor' | 'secondaryColor' | 'components' | 'animations'> {
107
117
  tokens: DefaultTokens;
108
118
  breakpoints: Breakpoints;
109
119
  }
120
+ interface ContainerPropsArgs {
121
+ colorMode?: ColorMode | 'system';
122
+ }
110
123
  /**
111
124
  * WebTheme is a fully built theme that has cssText based
112
125
  * on the design tokens and all design tokens have added fields
113
126
  * to be used in Javascript/Typescript.
114
127
  */
115
- export interface WebTheme extends Pick<DefaultTheme, 'breakpoints' | 'name' | 'overrides'> {
128
+ export interface WebTheme extends Pick<DefaultTheme, 'breakpoints' | 'name' | 'overrides' | 'components' | 'animations'> {
116
129
  primaryColor?: string;
117
130
  secondaryColor?: string;
118
131
  cssText: string;
132
+ containerProps: (containerProps?: ContainerPropsArgs) => {
133
+ 'data-amplify-theme'?: string;
134
+ 'data-amplify-color-mode'?: string;
135
+ };
119
136
  tokens: WebTokens;
120
137
  }
@@ -1,4 +1,4 @@
1
1
  type ClassNamesInput = string | number | boolean | undefined | null | Record<string, unknown> | ClassNamesArgs;
2
- type ClassNamesArgs = Array<ClassNamesInput>;
2
+ export type ClassNamesArgs = Array<ClassNamesInput>;
3
3
  export declare const classNames: (...args: ClassNamesArgs) => string;
4
4
  export {};
@@ -1,3 +1,3 @@
1
1
  export { setUserAgent, SetUserAgentOptions } from './setUserAgent';
2
2
  export * from './utils';
3
- export { classNames } from './classNames';
3
+ export { classNames, ClassNamesArgs } from './classNames';
@@ -145,3 +145,11 @@ export declare function noop(..._: any[]): void;
145
145
  * @param events string values related to group
146
146
  */
147
147
  export declare function groupLog(groupName: string, ...events: any[]): void;
148
+ /**
149
+ * Splits an object into 2 objects based on a predicate
150
+ *
151
+ * @param {object} obj an object to split into two
152
+ * @param {function} predicate function to determin where an element should go
153
+ * @returns
154
+ */
155
+ export declare function splitObject(obj: Record<string, unknown>, predicate: (key: string) => boolean): readonly [Record<string, unknown>, Record<string, unknown>];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui",
3
- "version": "6.0.17",
3
+ "version": "6.1.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "exports": {
@@ -46,7 +46,6 @@
46
46
  "dependencies": {
47
47
  "csstype": "^3.1.1",
48
48
  "lodash": "4.17.21",
49
- "style-dictionary": "3.9.1",
50
49
  "tslib": "^2.5.2"
51
50
  },
52
51
  "peerDependencies": {
@@ -64,7 +63,8 @@
64
63
  "autoprefixer": "^10.3.1",
65
64
  "glob": "^10.3.10",
66
65
  "postcss": "^8.4.31",
67
- "sass": "^1.35.2"
66
+ "sass": "^1.35.2",
67
+ "style-dictionary": "3.9.1"
68
68
  },
69
69
  "sideEffects": [
70
70
  "dist/**/*.css"
@@ -1,81 +0,0 @@
1
- import kebabCase from 'lodash/kebabCase.js';
2
- import usesReference from 'style-dictionary/lib/utils/references/usesReference.js';
3
- import '@aws-amplify/core/internals/utils';
4
- import '../utils/setUserAgent/constants.mjs';
5
- import { isObject, has, isString } from '../utils/utils.mjs';
6
-
7
- const CSS_VARIABLE_PREFIX = 'amplify';
8
- // Important: these properties should not be altered in
9
- // order to maintain the expected order of the CSS `box-shadow` property
10
- const SHADOW_PROPERTIES = [
11
- 'offsetX',
12
- 'offsetY',
13
- 'blurRadius',
14
- 'spreadRadius',
15
- 'color',
16
- ];
17
- function referenceValue(value) {
18
- if (!value)
19
- return '';
20
- if (usesReference(value)) {
21
- const path = value.replace(/\{|\}/g, '').replace('.value', '').split('.');
22
- return `var(--${cssNameTransform({ path })})`;
23
- }
24
- return value;
25
- }
26
- function cssValue(token) {
27
- const { value } = token;
28
- if (isString(value)) {
29
- return referenceValue(value);
30
- }
31
- if (isShadowTokenObject(value)) {
32
- return SHADOW_PROPERTIES.map((property) => {
33
- return referenceValue(
34
- // lookup property against `token` first for custom non-nested value, then lookup
35
- // property against `value` for design token value
36
- isShadowTokenObject(token) ? token[property] : value[property]);
37
- }).join(' ');
38
- }
39
- return value;
40
- }
41
- function cssNameTransform({ path = [] }) {
42
- return `${kebabCase([CSS_VARIABLE_PREFIX, ...path].join(' '))}`;
43
- }
44
- /**
45
- * Helper function to test if something is a design token or not.
46
- * Used in the React component style props.
47
- *
48
- * @param value - thing to test if it is a design token or not
49
- * @returns boolean
50
- */
51
- function isDesignToken(value) {
52
- return isObject(value) && has(value, 'value');
53
- }
54
- function isShadowTokenObject(value) {
55
- return isObject(value) && has(value, 'offsetX');
56
- }
57
- /**
58
- * Recursive function that will walk down the token object
59
- * and perform the setupToken function on each token.
60
- * Similar to what Style Dictionary does.
61
- */
62
- function setupTokens({ tokens, path = [], setupToken, }) {
63
- if (has(tokens, 'value')) {
64
- return setupToken({ token: tokens, path });
65
- }
66
- const output = {};
67
- for (const name in tokens) {
68
- if (has(tokens, name)) {
69
- const value = tokens[name];
70
- const nextTokens = isObject(value) ? value : { value };
71
- output[name] = setupTokens({
72
- tokens: nextTokens,
73
- path: path.concat(name),
74
- setupToken,
75
- });
76
- }
77
- }
78
- return output;
79
- }
80
-
81
- export { CSS_VARIABLE_PREFIX, cssNameTransform, cssValue, isDesignToken, isShadowTokenObject, setupTokens };
@@ -1,35 +0,0 @@
1
- import { ShadowValue, WebDesignToken } from './tokens/types/designToken';
2
- export declare const CSS_VARIABLE_PREFIX = "amplify";
3
- export declare function cssValue(token: BaseDesignToken): string | number;
4
- interface NameTransformProps {
5
- path?: Array<string>;
6
- }
7
- export declare function cssNameTransform({ path }: NameTransformProps): string;
8
- /**
9
- * Helper function to test if something is a design token or not.
10
- * Used in the React component style props.
11
- *
12
- * @param value - thing to test if it is a design token or not
13
- * @returns boolean
14
- */
15
- export declare function isDesignToken(value: unknown): value is WebDesignToken;
16
- export declare function isShadowTokenObject(value: unknown): value is ShadowValue & object;
17
- type SetupTokensProps = {
18
- tokens?: Record<string | number, any>;
19
- path?: Array<string>;
20
- setupToken: SetupToken;
21
- };
22
- export type SetupToken<ReturnType = any> = (args: {
23
- token: BaseDesignToken;
24
- path: Array<string>;
25
- }) => ReturnType;
26
- type BaseDesignToken = {
27
- value: string | number;
28
- };
29
- /**
30
- * Recursive function that will walk down the token object
31
- * and perform the setupToken function on each token.
32
- * Similar to what Style Dictionary does.
33
- */
34
- export declare function setupTokens({ tokens, path, setupToken, }: SetupTokensProps): any;
35
- export {};