@aws-amplify/ui-react 6.5.0 → 6.5.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/{Field-4b189104.js → Field-CIQvkMkM.js} +25 -106
- package/dist/{ThemeStyle-1fee4302.js → ThemeStyle-CgfvQJ7V.js} +10 -13
- package/dist/esm/components/ThemeProvider/ComponentStyle.mjs +6 -8
- package/dist/esm/components/ThemeProvider/GlobalStyle.mjs +18 -0
- package/dist/esm/components/ThemeProvider/Style.mjs +6 -8
- package/dist/esm/components/ThemeProvider/ThemeStyle.mjs +6 -8
- package/dist/esm/internal.mjs +1 -1
- package/dist/esm/primitives/Accordion/AccordionTrigger.mjs +2 -2
- package/dist/esm/primitives/DropZone/DropZone.mjs +1 -1
- package/dist/esm/primitives/Tabs/TabsItem.mjs +2 -2
- package/dist/esm/primitives/shared/responsive/getMediaQueries.mjs +1 -0
- package/dist/esm/primitives/shared/responsive/useBreakpoint.mjs +1 -0
- package/dist/esm/server.mjs +1 -0
- package/dist/esm/version.mjs +1 -1
- package/dist/index.js +295 -297
- package/dist/internal.js +6 -7
- package/dist/server.js +23 -11
- package/dist/types/components/ThemeProvider/ComponentStyle.d.ts +6 -4
- package/dist/types/components/ThemeProvider/GlobalStyle.d.ts +20 -0
- package/dist/types/components/ThemeProvider/Style.d.ts +6 -4
- package/dist/types/components/ThemeProvider/ThemeStyle.d.ts +6 -4
- package/dist/types/internal.d.ts +1 -1
- package/dist/types/primitives/DropZone/DropZoneProvider.d.ts +1 -1
- package/dist/types/primitives/DropZone/types.d.ts +2 -17
- package/dist/types/primitives/shared/responsive/utils.d.ts +1 -1
- package/dist/types/server.d.ts +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +6 -5
- package/dist/esm/primitives/DropZone/filterAllowedFiles.mjs +0 -34
- package/dist/esm/primitives/DropZone/useDropZone.mjs +0 -65
- package/dist/primitiveWithForwardRef-7e929242.js +0 -36
- package/dist/types/primitives/Card/__test__/Card.test.d.ts +0 -1
- package/dist/types/primitives/DropZone/filterAllowedFiles.d.ts +0 -10
- package/dist/types/primitives/DropZone/useDropZone.d.ts +0 -2
package/dist/internal.js
CHANGED
|
@@ -2,16 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var Field = require('./Field-
|
|
5
|
+
var Field = require('./Field-CIQvkMkM.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var Storage = require('aws-amplify/storage');
|
|
8
8
|
var ui = require('@aws-amplify/ui');
|
|
9
9
|
var uiReactCore = require('@aws-amplify/ui-react-core');
|
|
10
10
|
require('@aws-amplify/core');
|
|
11
11
|
require('aws-amplify/auth');
|
|
12
|
-
require('./primitiveWithForwardRef-7e929242.js');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
12
|
|
|
16
13
|
function _interopNamespace(e) {
|
|
17
14
|
if (e && e.__esModule) return e;
|
|
@@ -32,7 +29,6 @@ function _interopNamespace(e) {
|
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
35
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
36
32
|
var Storage__namespace = /*#__PURE__*/_interopNamespace(Storage);
|
|
37
33
|
|
|
38
34
|
const useStorageURL = ({ key, options, fallbackURL, onStorageGetError, }) => {
|
|
@@ -87,7 +83,7 @@ const useThemeBreakpoint = () => {
|
|
|
87
83
|
const FilterChildren = ({ allowedFilters, children = null, targetFilter, }) => {
|
|
88
84
|
const showContent = Array.isArray(allowedFilters) &&
|
|
89
85
|
allowedFilters.some((filter) => filter === targetFilter);
|
|
90
|
-
return showContent ?
|
|
86
|
+
return showContent ? React__namespace["default"].createElement(React__namespace["default"].Fragment, null, children) : null;
|
|
91
87
|
};
|
|
92
88
|
|
|
93
89
|
/**
|
|
@@ -16706,8 +16702,11 @@ exports.IconWarning = Field.IconWarning;
|
|
|
16706
16702
|
exports.useAuth = Field.useAuth;
|
|
16707
16703
|
exports.useColorMode = Field.useColorMode;
|
|
16708
16704
|
exports.useDeprecationWarning = Field.useDeprecationWarning;
|
|
16709
|
-
exports.useDropZone = Field.useDropZone;
|
|
16710
16705
|
exports.useIcons = Field.useIcons;
|
|
16706
|
+
Object.defineProperty(exports, "useDropZone", {
|
|
16707
|
+
enumerable: true,
|
|
16708
|
+
get: function () { return uiReactCore.useDropZone; }
|
|
16709
|
+
});
|
|
16711
16710
|
exports.FilterChildren = FilterChildren;
|
|
16712
16711
|
exports.IconAssistant = IconAssistant;
|
|
16713
16712
|
exports.IconAttach = IconAttach;
|
package/dist/server.js
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var ThemeStyle = require('./ThemeStyle-
|
|
5
|
+
var ThemeStyle = require('./ThemeStyle-CgfvQJ7V.js');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var ui = require('@aws-amplify/ui');
|
|
8
|
-
var primitiveWithForwardRef = require('./primitiveWithForwardRef-7e929242.js');
|
|
9
8
|
|
|
10
9
|
function _interopNamespace(e) {
|
|
11
10
|
if (e && e.__esModule) return e;
|
|
@@ -27,7 +26,11 @@ function _interopNamespace(e) {
|
|
|
27
26
|
|
|
28
27
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* @experimental
|
|
31
|
+
* [📖 Docs](https://ui.docs.amplify.aws/react/components/theme)
|
|
32
|
+
*/
|
|
33
|
+
const ComponentStyle = ({ theme, componentThemes = [], ...rest }) => {
|
|
31
34
|
if (!theme || !componentThemes.length) {
|
|
32
35
|
return null;
|
|
33
36
|
}
|
|
@@ -35,34 +38,43 @@ const ComponentStylePrimitive = ({ theme, componentThemes = [], ...rest }, ref)
|
|
|
35
38
|
theme,
|
|
36
39
|
components: componentThemes,
|
|
37
40
|
});
|
|
38
|
-
return React__namespace.createElement(ThemeStyle.Style, { ...rest,
|
|
41
|
+
return React__namespace.createElement(ThemeStyle.Style, { ...rest, cssText: cssText });
|
|
39
42
|
};
|
|
43
|
+
ComponentStyle.displayName = 'ComponentStyle';
|
|
44
|
+
|
|
40
45
|
/**
|
|
41
46
|
* @experimental
|
|
42
47
|
* [📖 Docs](https://ui.docs.amplify.aws/react/components/theme)
|
|
43
48
|
*/
|
|
44
|
-
const
|
|
45
|
-
|
|
49
|
+
const GlobalStyle = ({ styles, ...rest }) => {
|
|
50
|
+
if (!styles) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const cssText = ui.createGlobalCSS(styles);
|
|
54
|
+
return React__namespace.createElement(ThemeStyle.Style, { ...rest, cssText: cssText });
|
|
55
|
+
};
|
|
56
|
+
GlobalStyle.displayName = 'GlobalStyle';
|
|
46
57
|
|
|
47
58
|
exports.ThemeStyle = ThemeStyle.ThemeStyle;
|
|
48
|
-
Object.defineProperty(exports,
|
|
59
|
+
Object.defineProperty(exports, "createComponentClasses", {
|
|
49
60
|
enumerable: true,
|
|
50
61
|
get: function () { return ui.createComponentClasses; }
|
|
51
62
|
});
|
|
52
|
-
Object.defineProperty(exports,
|
|
63
|
+
Object.defineProperty(exports, "createTheme", {
|
|
53
64
|
enumerable: true,
|
|
54
65
|
get: function () { return ui.createTheme; }
|
|
55
66
|
});
|
|
56
|
-
Object.defineProperty(exports,
|
|
67
|
+
Object.defineProperty(exports, "defaultDarkModeOverride", {
|
|
57
68
|
enumerable: true,
|
|
58
69
|
get: function () { return ui.defaultDarkModeOverride; }
|
|
59
70
|
});
|
|
60
|
-
Object.defineProperty(exports,
|
|
71
|
+
Object.defineProperty(exports, "defaultTheme", {
|
|
61
72
|
enumerable: true,
|
|
62
73
|
get: function () { return ui.defaultTheme; }
|
|
63
74
|
});
|
|
64
|
-
Object.defineProperty(exports,
|
|
75
|
+
Object.defineProperty(exports, "defineComponentTheme", {
|
|
65
76
|
enumerable: true,
|
|
66
77
|
get: function () { return ui.defineComponentTheme; }
|
|
67
78
|
});
|
|
68
79
|
exports.ComponentStyle = ComponentStyle;
|
|
80
|
+
exports.GlobalStyle = GlobalStyle;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { WebTheme } from '@aws-amplify/ui';
|
|
2
|
-
import { BaseComponentProps, ElementType, ForwardRefPrimitive, PrimitiveProps } from '../../primitives/types';
|
|
3
3
|
import { BaseComponentTheme } from '@aws-amplify/ui';
|
|
4
|
-
interface
|
|
4
|
+
interface ComponentStyleProps extends React.ComponentProps<'style'> {
|
|
5
5
|
/**
|
|
6
6
|
* Provide a server generated nonce which matches your CSP `style-src` rule.
|
|
7
7
|
* This will be attached to the generated <style> tag.
|
|
@@ -11,10 +11,12 @@ interface BaseComponentStyleProps extends BaseComponentProps {
|
|
|
11
11
|
theme: Pick<WebTheme, 'name' | 'breakpoints' | 'tokens'>;
|
|
12
12
|
componentThemes: BaseComponentTheme[];
|
|
13
13
|
}
|
|
14
|
-
export type ComponentStyleProps<Element extends ElementType = 'style'> = PrimitiveProps<BaseComponentStyleProps, Element>;
|
|
15
14
|
/**
|
|
16
15
|
* @experimental
|
|
17
16
|
* [📖 Docs](https://ui.docs.amplify.aws/react/components/theme)
|
|
18
17
|
*/
|
|
19
|
-
export declare const ComponentStyle:
|
|
18
|
+
export declare const ComponentStyle: {
|
|
19
|
+
({ theme, componentThemes, ...rest }: ComponentStyleProps): JSX.Element | null;
|
|
20
|
+
displayName: string;
|
|
21
|
+
};
|
|
20
22
|
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { createGlobalCSS } from '@aws-amplify/ui';
|
|
3
|
+
interface GlobalStyleProps extends React.ComponentProps<'style'> {
|
|
4
|
+
/**
|
|
5
|
+
* Provide a server generated nonce which matches your CSP `style-src` rule.
|
|
6
|
+
* This will be attached to the generated <style> tag.
|
|
7
|
+
* @see: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
|
|
8
|
+
*/
|
|
9
|
+
nonce?: string;
|
|
10
|
+
styles: Parameters<typeof createGlobalCSS>[0];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* @experimental
|
|
14
|
+
* [📖 Docs](https://ui.docs.amplify.aws/react/components/theme)
|
|
15
|
+
*/
|
|
16
|
+
export declare const GlobalStyle: {
|
|
17
|
+
({ styles, ...rest }: GlobalStyleProps): JSX.Element | null;
|
|
18
|
+
displayName: string;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
interface
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
interface StyleProps extends React.ComponentProps<'style'> {
|
|
3
3
|
cssText?: string;
|
|
4
4
|
}
|
|
5
|
-
export type StyleProps<Element extends ElementType = 'style'> = PrimitiveProps<BaseStyleProps, Element>;
|
|
6
5
|
/**
|
|
7
6
|
* @experimental
|
|
8
7
|
* [📖 Docs](https://ui.docs.amplify.aws/react/components/theme)
|
|
9
8
|
*/
|
|
10
|
-
export declare const Style:
|
|
9
|
+
export declare const Style: {
|
|
10
|
+
({ cssText, ...rest }: StyleProps): JSX.Element | null;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
11
13
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { WebTheme } from '@aws-amplify/ui';
|
|
2
|
-
|
|
3
|
-
interface BaseStyleThemeProps extends BaseComponentProps {
|
|
3
|
+
interface ThemeStyleProps extends React.ComponentProps<'style'> {
|
|
4
4
|
/**
|
|
5
5
|
* Provide a server generated nonce which matches your CSP `style-src` rule.
|
|
6
6
|
* This will be attached to the generated <style> tag.
|
|
@@ -9,10 +9,12 @@ interface BaseStyleThemeProps extends BaseComponentProps {
|
|
|
9
9
|
nonce?: string;
|
|
10
10
|
theme?: WebTheme;
|
|
11
11
|
}
|
|
12
|
-
export type ThemeStyleProps<Element extends ElementType = 'style'> = PrimitiveProps<BaseStyleThemeProps, Element>;
|
|
13
12
|
/**
|
|
14
13
|
* @experimental
|
|
15
14
|
* [📖 Docs](https://ui.docs.amplify.aws/react/components/theme)
|
|
16
15
|
*/
|
|
17
|
-
export declare const ThemeStyle:
|
|
16
|
+
export declare const ThemeStyle: {
|
|
17
|
+
({ theme, ...rest }: ThemeStyleProps): JSX.Element | null;
|
|
18
|
+
displayName: string;
|
|
19
|
+
};
|
|
18
20
|
export {};
|
package/dist/types/internal.d.ts
CHANGED
|
@@ -3,9 +3,9 @@ export * from './hooks/useStorageURL';
|
|
|
3
3
|
export * from './hooks/useThemeBreakpoint';
|
|
4
4
|
export { useDeprecationWarning } from './hooks/useDeprecationWarning';
|
|
5
5
|
export { useColorMode } from './hooks/useTheme';
|
|
6
|
+
export { useDropZone } from '@aws-amplify/ui-react-core';
|
|
6
7
|
export * from './components/FilterChildren';
|
|
7
8
|
export { AlertIcon } from './primitives/Alert/AlertIcon';
|
|
8
9
|
export * from './primitives/Icon/internal';
|
|
9
|
-
export { useDropZone } from './primitives/DropZone/useDropZone';
|
|
10
10
|
export { Field } from './primitives/Field';
|
|
11
11
|
export { PrimitiveCatalog } from './PrimitiveCatalog';
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ElementType, PrimitiveProps, BaseViewProps } from '../types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
rejectedFiles: File[];
|
|
6
|
-
}
|
|
7
|
-
export interface UseDropZoneProps extends Partial<DragEvents> {
|
|
8
|
-
onDropComplete?: (props: DropProps) => void;
|
|
9
|
-
/**
|
|
10
|
-
* List of accepted File types, values of `['*']` or undefined allow any files
|
|
11
|
-
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept
|
|
12
|
-
*/
|
|
13
|
-
acceptedFileTypes?: string[];
|
|
14
|
-
}
|
|
15
|
-
export interface BaseDropZoneProps extends BaseViewProps, UseDropZoneProps {
|
|
3
|
+
import { UseDropZoneParams } from '@aws-amplify/ui-react-core';
|
|
4
|
+
export interface BaseDropZoneProps extends BaseViewProps, UseDropZoneParams {
|
|
16
5
|
}
|
|
17
6
|
export type DropZoneProps<Element extends ElementType = 'div'> = PrimitiveProps<BaseDropZoneProps, Element>;
|
|
18
7
|
interface DragEvents {
|
|
@@ -22,10 +11,6 @@ interface DragEvents {
|
|
|
22
11
|
onDragOver: (event: React.DragEvent<HTMLDivElement>) => void;
|
|
23
12
|
onDrop: (event: React.DragEvent<HTMLDivElement>) => void;
|
|
24
13
|
}
|
|
25
|
-
export type DragState = 'accept' | 'reject' | 'inactive';
|
|
26
|
-
export interface UseDropZoneReturn extends DragEvents {
|
|
27
|
-
dragState: DragState;
|
|
28
|
-
}
|
|
29
14
|
export interface BaseDropZoneContainerProps extends BaseViewProps, DragEvents {
|
|
30
15
|
}
|
|
31
16
|
export type DropZoneContainerProps<Element extends ElementType = 'div'> = PrimitiveProps<BaseDropZoneContainerProps, Element>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Breakpoint, Breakpoints, ValueBreakpoints } from '../../types/responsive';
|
|
2
2
|
export declare const getValueAtCurrentBreakpoint: <Value = string | number>({ breakpoint, breakpoints, values, }: {
|
|
3
|
-
values: Partial<Record<"small" | "large" | "medium" | "xl" | "xxl"
|
|
3
|
+
values: Partial<Record<"base" | "small" | "large" | "medium" | "xl" | "xxl", Value>> | Value[];
|
|
4
4
|
breakpoint: Breakpoint;
|
|
5
5
|
breakpoints: Breakpoints;
|
|
6
6
|
}) => string | number | Value | null;
|
package/dist/types/server.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { ThemeStyle } from './components/ThemeProvider/ThemeStyle';
|
|
2
2
|
export { ComponentStyle } from './components/ThemeProvider/ComponentStyle';
|
|
3
|
+
export { GlobalStyle } from './components/ThemeProvider/GlobalStyle';
|
|
3
4
|
export { createTheme, defineComponentTheme, createComponentClasses, defaultTheme, defaultDarkModeOverride, } from '@aws-amplify/ui';
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "6.5.
|
|
1
|
+
export declare const VERSION = "6.5.2";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/ui-react",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/esm/index.mjs",
|
|
6
6
|
"exports": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"check:esm": "node --input-type=module --eval 'import \"@aws-amplify/ui-react\"'",
|
|
48
48
|
"clean": "rimraf dist node_modules",
|
|
49
49
|
"dev": "yarn build:rollup --watch",
|
|
50
|
-
"lint": "yarn typecheck && eslint
|
|
50
|
+
"lint": "yarn typecheck && eslint .",
|
|
51
51
|
"prebuild": "rimraf dist",
|
|
52
52
|
"size": "yarn size-limit",
|
|
53
53
|
"test": "jest",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"typecheck": "tsc --noEmit"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@aws-amplify/ui": "6.6.
|
|
59
|
-
"@aws-amplify/ui-react-core": "3.0.
|
|
58
|
+
"@aws-amplify/ui": "6.6.2",
|
|
59
|
+
"@aws-amplify/ui-react-core": "3.0.26",
|
|
60
60
|
"@radix-ui/react-direction": "1.0.0",
|
|
61
61
|
"@radix-ui/react-dropdown-menu": "1.0.0",
|
|
62
62
|
"@radix-ui/react-slider": "1.0.0",
|
|
@@ -66,7 +66,8 @@
|
|
|
66
66
|
"tslib": "^2.5.2"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"aws-amplify": "
|
|
69
|
+
"@aws-amplify/core": "*",
|
|
70
|
+
"aws-amplify": "^6.6.0",
|
|
70
71
|
"react": "^16.14.0 || ^17.0 || ^18.0",
|
|
71
72
|
"react-dom": "^16.14.0 || ^17.0 || ^18.0"
|
|
72
73
|
},
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
function filterAllowedFiles(files, acceptedFileTypes) {
|
|
2
|
-
// Allow any files if acceptedFileTypes is undefined, empty array, or contains '*'
|
|
3
|
-
if (!acceptedFileTypes ||
|
|
4
|
-
acceptedFileTypes.length === 0 ||
|
|
5
|
-
acceptedFileTypes.includes('*')) {
|
|
6
|
-
return { acceptedFiles: files, rejectedFiles: [] };
|
|
7
|
-
}
|
|
8
|
-
const acceptedFiles = [];
|
|
9
|
-
const rejectedFiles = [];
|
|
10
|
-
function filterFile(file) {
|
|
11
|
-
const { type = '', name = '' } = file;
|
|
12
|
-
const mimeType = type.toLowerCase();
|
|
13
|
-
const baseMimeType = mimeType.split('/')[0];
|
|
14
|
-
return acceptedFileTypes.some((type) => {
|
|
15
|
-
const validType = type.trim().toLowerCase();
|
|
16
|
-
// if the accepted file type is a file extension
|
|
17
|
-
// it will start with '.', check against the file name
|
|
18
|
-
if (validType.charAt(0) === '.') {
|
|
19
|
-
return name.toLowerCase().endsWith(validType);
|
|
20
|
-
}
|
|
21
|
-
// This is something like a image/* mime type
|
|
22
|
-
if (validType.endsWith('/*')) {
|
|
23
|
-
return baseMimeType === validType.split('/')[0];
|
|
24
|
-
}
|
|
25
|
-
return mimeType === validType;
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
files.forEach((file) => {
|
|
29
|
-
(filterFile(file) ? acceptedFiles : rejectedFiles).push(file);
|
|
30
|
-
});
|
|
31
|
-
return { acceptedFiles, rejectedFiles };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { filterAllowedFiles };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import { isFunction } from '@aws-amplify/ui';
|
|
3
|
-
import { filterAllowedFiles } from './filterAllowedFiles.mjs';
|
|
4
|
-
|
|
5
|
-
function useDropZone({ onDropComplete, onDragEnter: _onDragEnter, onDragLeave: _onDragLeave, onDragOver: _onDragOver, onDragStart: _onDragStart, onDrop: _onDrop, acceptedFileTypes = [], }) {
|
|
6
|
-
const [dragState, setDragState] = useState('inactive');
|
|
7
|
-
const onDragStart = (event) => {
|
|
8
|
-
event.dataTransfer.clearData();
|
|
9
|
-
if (isFunction(_onDragStart)) {
|
|
10
|
-
_onDragStart(event);
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const onDragEnter = (event) => {
|
|
14
|
-
event.preventDefault();
|
|
15
|
-
event.stopPropagation();
|
|
16
|
-
if (isFunction(_onDragEnter)) {
|
|
17
|
-
_onDragEnter(event);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
const onDragLeave = (event) => {
|
|
21
|
-
event.preventDefault();
|
|
22
|
-
event.stopPropagation();
|
|
23
|
-
setDragState('inactive');
|
|
24
|
-
if (isFunction(_onDragLeave)) {
|
|
25
|
-
_onDragLeave(event);
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const onDragOver = (event) => {
|
|
29
|
-
event.preventDefault();
|
|
30
|
-
event.stopPropagation();
|
|
31
|
-
event.dataTransfer.dropEffect = 'copy';
|
|
32
|
-
if (isFunction(_onDragOver)) {
|
|
33
|
-
_onDragOver(event);
|
|
34
|
-
}
|
|
35
|
-
const files = Array.from(event.dataTransfer.items).map(({ kind, type }) => ({
|
|
36
|
-
kind,
|
|
37
|
-
type,
|
|
38
|
-
}));
|
|
39
|
-
const { rejectedFiles } = filterAllowedFiles(files, acceptedFileTypes);
|
|
40
|
-
setDragState(rejectedFiles.length > 0 ? 'reject' : 'accept');
|
|
41
|
-
};
|
|
42
|
-
const onDrop = (event) => {
|
|
43
|
-
event.preventDefault();
|
|
44
|
-
event.stopPropagation();
|
|
45
|
-
setDragState('inactive');
|
|
46
|
-
const files = Array.from(event.dataTransfer.files);
|
|
47
|
-
const { acceptedFiles, rejectedFiles } = filterAllowedFiles(files, acceptedFileTypes);
|
|
48
|
-
if (isFunction(_onDrop)) {
|
|
49
|
-
_onDrop(event);
|
|
50
|
-
}
|
|
51
|
-
if (isFunction(onDropComplete)) {
|
|
52
|
-
onDropComplete({ acceptedFiles, rejectedFiles });
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
onDragStart,
|
|
57
|
-
onDragEnter,
|
|
58
|
-
onDragLeave,
|
|
59
|
-
onDragOver,
|
|
60
|
-
onDrop,
|
|
61
|
-
dragState,
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export { useDropZone };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var React = require('react');
|
|
4
|
-
|
|
5
|
-
function _interopNamespace(e) {
|
|
6
|
-
if (e && e.__esModule) return e;
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n["default"] = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Updates the return type for primitives wrapped in `React.forwardRef` to
|
|
27
|
-
* `React.ReactElement`. In React 18 the return type of `React.ExoticComponent`
|
|
28
|
-
* was changed from `React.ReactElement` to `React.ReactNode`, which breaks
|
|
29
|
-
* clients using React 16 and 17.
|
|
30
|
-
*
|
|
31
|
-
* @param primitive UI Primitive to be wrapped with `React.forwardRef`
|
|
32
|
-
* @returns ForwaredRef wrapped UI Primitive
|
|
33
|
-
*/
|
|
34
|
-
const primitiveWithForwardRef = (primitive) => React__namespace.forwardRef(primitive);
|
|
35
|
-
|
|
36
|
-
exports.primitiveWithForwardRef = primitiveWithForwardRef;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
type DragFile = {
|
|
2
|
-
kind: string;
|
|
3
|
-
type: string;
|
|
4
|
-
name?: string;
|
|
5
|
-
} | File;
|
|
6
|
-
export declare function filterAllowedFiles<FileType extends DragFile = DragFile>(files: FileType[], acceptedFileTypes: string[]): {
|
|
7
|
-
acceptedFiles: FileType[];
|
|
8
|
-
rejectedFiles: FileType[];
|
|
9
|
-
};
|
|
10
|
-
export {};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import { UseDropZoneProps, UseDropZoneReturn } from './types';
|
|
2
|
-
export declare function useDropZone({ onDropComplete, onDragEnter: _onDragEnter, onDragLeave: _onDragLeave, onDragOver: _onDragOver, onDragStart: _onDragStart, onDrop: _onDrop, acceptedFileTypes, }: UseDropZoneProps): UseDropZoneReturn;
|