@entur/fileupload 0.3.43 → 0.3.46
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/CHANGELOG.md +14 -0
- package/dist/FileUpload.d.ts +6 -2
- package/dist/fileupload.cjs.development.js +7 -4
- package/dist/fileupload.cjs.development.js.map +1 -1
- package/dist/fileupload.cjs.production.min.js +1 -1
- package/dist/fileupload.cjs.production.min.js.map +1 -1
- package/dist/fileupload.esm.js +7 -4
- package/dist/fileupload.esm.js.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.3.46](https://bitbucket.org/enturas/design-system/compare/@entur/fileupload@0.3.45...@entur/fileupload@0.3.46) (2022-08-31)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **file upload:** add descriptive screen reader text to remove file button ([42c37d1](https://bitbucket.org/enturas/design-system/commits/42c37d131e2db5f712b1ce7cf3336b6d536cadd2))
|
|
11
|
+
|
|
12
|
+
## [0.3.45](https://bitbucket.org/enturas/design-system/compare/@entur/fileupload@0.3.44...@entur/fileupload@0.3.45) (2022-08-24)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @entur/fileupload
|
|
15
|
+
|
|
16
|
+
## [0.3.44](https://bitbucket.org/enturas/design-system/compare/@entur/fileupload@0.3.43...@entur/fileupload@0.3.44) (2022-08-09)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @entur/fileupload
|
|
19
|
+
|
|
6
20
|
## [0.3.43](https://bitbucket.org/enturas/design-system/compare/@entur/fileupload@0.3.42...@entur/fileupload@0.3.43) (2022-07-05)
|
|
7
21
|
|
|
8
22
|
**Note:** Version bump only for package @entur/fileupload
|
package/dist/FileUpload.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { DropzoneOptions, FileRejection, DropEvent } from 'react-dropzone';
|
|
2
|
+
import { DropzoneOptions, FileRejection, DropEvent, FileWithPath } from 'react-dropzone';
|
|
3
3
|
import './FileUpload.scss';
|
|
4
4
|
declare type FileUploadProps = DropzoneOptions & {
|
|
5
5
|
/** Tekst som vises ved fullført opplasting
|
|
@@ -21,7 +21,7 @@ declare type FileUploadProps = DropzoneOptions & {
|
|
|
21
21
|
/** Callback for når en fil legges til */
|
|
22
22
|
onDrop?<T extends File>(acceptedFiles: T[], fileRejections: FileRejection[], event: DropEvent): void;
|
|
23
23
|
/** Callback for når en fil slettes fra lista */
|
|
24
|
-
onDelete: (file:
|
|
24
|
+
onDelete: (file: FileWithPath) => void;
|
|
25
25
|
/** Hvilken filtyper som skal aksepteres */
|
|
26
26
|
accept?: string | string[];
|
|
27
27
|
/** Filene som er aktive i komponenten */
|
|
@@ -34,6 +34,10 @@ declare type FileUploadProps = DropzoneOptions & {
|
|
|
34
34
|
minSize?: number;
|
|
35
35
|
/**Største filstørrelse */
|
|
36
36
|
maxSize?: number;
|
|
37
|
+
/**Tekst som leses opp av skjermleser på søppelbøtte-ikonet
|
|
38
|
+
* @default "Fjern fil"
|
|
39
|
+
*/
|
|
40
|
+
removeFileButtonDescription?: string;
|
|
37
41
|
[key: string]: any;
|
|
38
42
|
};
|
|
39
43
|
export declare const FileUpload: React.FC<FileUploadProps>;
|
|
@@ -5,10 +5,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var utils = require('@entur/utils');
|
|
6
6
|
var React = require('react');
|
|
7
7
|
var reactDropzone = require('react-dropzone');
|
|
8
|
+
var classNames = require('classnames');
|
|
8
9
|
var icons = require('@entur/icons');
|
|
9
10
|
var button = require('@entur/button');
|
|
10
11
|
var typography = require('@entur/typography');
|
|
11
|
-
var
|
|
12
|
+
var a11y = require('@entur/a11y');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
15
|
|
|
@@ -48,7 +49,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
48
49
|
return target;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
var _excluded = ["standbyText", "errorText", "successText", "errorUpload", "onDrop", "onDelete", "accept", "files", "label", "style"];
|
|
52
|
+
var _excluded = ["standbyText", "errorText", "successText", "errorUpload", "onDrop", "onDelete", "accept", "files", "label", "removeFileButtonDescription", "style"];
|
|
52
53
|
var FileUpload = function FileUpload(_ref) {
|
|
53
54
|
var _ref$standbyText = _ref.standbyText,
|
|
54
55
|
standbyText = _ref$standbyText === void 0 ? 'Dra fil eller klikk for å laste opp' : _ref$standbyText,
|
|
@@ -68,6 +69,8 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
68
69
|
_ref$files = _ref.files,
|
|
69
70
|
files = _ref$files === void 0 ? [] : _ref$files,
|
|
70
71
|
label = _ref.label,
|
|
72
|
+
_ref$removeFileButton = _ref.removeFileButtonDescription,
|
|
73
|
+
removeFileButtonDescription = _ref$removeFileButton === void 0 ? 'Fjern fil' : _ref$removeFileButton,
|
|
71
74
|
style = _ref.style,
|
|
72
75
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
73
76
|
|
|
@@ -97,7 +100,7 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
97
100
|
}, {
|
|
98
101
|
'eds-file-upload__dropzone--reject': isDragReject
|
|
99
102
|
}, {
|
|
100
|
-
'eds-file-
|
|
103
|
+
'eds-file-upload__dropzone--error': errorUpload
|
|
101
104
|
})
|
|
102
105
|
}, success ? successText : errorUpload ? errorText : standbyText)), React__default["default"].createElement("div", {
|
|
103
106
|
className: "eds-file-upload__file-list"
|
|
@@ -113,7 +116,7 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
113
116
|
onClick: function onClick() {
|
|
114
117
|
return onDelete(file);
|
|
115
118
|
}
|
|
116
|
-
}, React__default["default"].createElement(icons.DeleteIcon, null)));
|
|
119
|
+
}, React__default["default"].createElement(a11y.VisuallyHidden, null, removeFileButtonDescription, ", ", file.name), React__default["default"].createElement(icons.DeleteIcon, null)));
|
|
117
120
|
})));
|
|
118
121
|
};
|
|
119
122
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileupload.cjs.development.js","sources":["../src/FileUpload.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport {\n useDropzone,\n DropzoneOptions,\n FileRejection,\n DropEvent,\n} from 'react-dropzone';\nimport { FileIcon, DeleteIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Label } from '@entur/typography';\nimport
|
|
1
|
+
{"version":3,"file":"fileupload.cjs.development.js","sources":["../src/FileUpload.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport {\n useDropzone,\n DropzoneOptions,\n FileRejection,\n DropEvent,\n FileWithPath,\n} from 'react-dropzone';\nimport classNames from 'classnames';\n\nimport { FileIcon, DeleteIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Label } from '@entur/typography';\nimport { VisuallyHidden } from '@entur/a11y';\n\nimport './FileUpload.scss';\n\ntype FileUploadProps = DropzoneOptions & {\n /** Tekst som vises ved fullført opplasting\n * @default \"Opplasting fullført\"\n */\n successText?: string;\n /** Tekst som vises om opplasting feilet\n * @default \"Feil ved opplasting av fil\"\n */\n errorText?: string;\n /** Tekst som vises før man laster opp noe\n * @default \"Dra fil eller klikk for å laste opp\"\n */\n standbyText?: string;\n /** Boolean for hvis opplastingen feiler.\n * @default false\n */\n errorUpload?: boolean;\n /** Callback for når en fil legges til */\n onDrop?<T extends File>(\n acceptedFiles: T[],\n fileRejections: FileRejection[],\n event: DropEvent,\n ): void;\n /** Callback for når en fil slettes fra lista */\n onDelete: (file: FileWithPath) => void;\n /** Hvilken filtyper som skal aksepteres */\n accept?: string | string[];\n /** Filene som er aktive i komponenten */\n files: File[];\n /** Beskrivende tekst som forklarer feltet */\n label?: string;\n /** Mulighet for å laste opp flere filer */\n multiple?: boolean;\n /**Minste filstørrelse */\n minSize?: number;\n /**Største filstørrelse */\n maxSize?: number;\n /**Tekst som leses opp av skjermleser på søppelbøtte-ikonet\n * @default \"Fjern fil\"\n */\n removeFileButtonDescription?: string;\n [key: string]: any;\n};\n\nexport const FileUpload: React.FC<FileUploadProps> = ({\n standbyText = 'Dra fil eller klikk for å laste opp',\n errorText = 'Feil ved opplasting av fil',\n successText = 'Opplasting fullført',\n errorUpload = false,\n onDrop,\n onDelete = file => console.log(file),\n accept = '',\n files = [],\n label,\n removeFileButtonDescription = 'Fjern fil',\n style,\n ...rest\n}) => {\n const { getRootProps, getInputProps, isDragActive, isDragReject } =\n useDropzone({\n onDrop,\n accept: accept,\n ...rest,\n });\n\n const success = files.length > 0;\n\n return (\n <div className=\"eds-file-upload__wrapper\" {...style}>\n <div className=\"eds-file-upload__input\" {...getRootProps()}>\n {label && <Label style={{ display: 'flex' }}>{label}</Label>}\n <input {...getInputProps()} />\n <span\n className={classNames(\n 'eds-file-upload__dropzone',\n {\n 'eds-file-upload__dropzone--success': success,\n },\n { 'eds-file-upload__dropzone--active': isDragActive },\n { 'eds-file-upload__dropzone--reject': isDragReject },\n { 'eds-file-upload__dropzone--error': errorUpload },\n )}\n >\n {success ? successText : errorUpload ? errorText : standbyText}\n </span>\n </div>\n <div className=\"eds-file-upload__file-list\">\n {files.map((file: FileWithPath, index) => (\n <div className=\"eds-file-upload__file-name\" key={index}>\n <FileIcon className=\"eds-file-upload__file-name-icon\" />\n <span className=\"eds-field-upload__file-name-path\">\n {file.path} - {convertSizeToHuman(file.size)}{' '}\n </span>\n <IconButton onClick={() => onDelete(file)}>\n <VisuallyHidden>\n {removeFileButtonDescription}, {file.name}\n </VisuallyHidden>\n <DeleteIcon />\n </IconButton>\n </div>\n ))}\n </div>\n </div>\n );\n};\n\nfunction convertSizeToHuman(size: number) {\n if (size < 1000) {\n return size + 'bytes;';\n } else if (size < 1000000) {\n return `${size / 1000} KB`;\n } else {\n return `${(size / 1000000).toPrecision(4)} MB`;\n }\n}\n","import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('fileupload');\n\nexport * from './FileUpload';\n"],"names":["FileUpload","standbyText","errorText","successText","errorUpload","onDrop","onDelete","file","console","log","accept","files","label","removeFileButtonDescription","style","rest","useDropzone","getRootProps","getInputProps","isDragActive","isDragReject","success","length","React","className","Label","display","classNames","map","index","key","FileIcon","path","convertSizeToHuman","size","IconButton","onClick","VisuallyHidden","name","DeleteIcon","toPrecision","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6DaA,UAAU,GAA8B,SAAxCA,UAAwC;8BACnDC;MAAAA,4CAAc;4BACdC;MAAAA,wCAAY;8BACZC;MAAAA,4CAAc;8BACdC;MAAAA,4CAAc;MACdC,cAAAA;2BACAC;MAAAA,sCAAW,UAAAC,IAAI;AAAA,WAAIC,OAAO,CAACC,GAAR,CAAYF,IAAZ,CAAJ;AAAA;yBACfG;MAAAA,kCAAS;wBACTC;MAAAA,gCAAQ;MACRC,aAAAA;mCACAC;MAAAA,iEAA8B;MAC9BC,aAAAA;MACGC;;AAEH,qBACEC,yBAAW;AACTX,IAAAA,MAAM,EAANA,MADS;AAETK,IAAAA,MAAM,EAAEA;AAFC,KAGNK,IAHM,EADb;AAAA,MAAQE,YAAR,gBAAQA,YAAR;AAAA,MAAsBC,aAAtB,gBAAsBA,aAAtB;AAAA,MAAqCC,YAArC,gBAAqCA,YAArC;AAAA,MAAmDC,YAAnD,gBAAmDA,YAAnD;;AAOA,MAAMC,OAAO,GAAGV,KAAK,CAACW,MAAN,GAAe,CAA/B;AAEA,SACEC,uCAAA,MAAA;AAAKC,IAAAA,SAAS,EAAC;AAAf,KAA8CV,KAA9C,GACES,uCAAA,MAAA;AAAKC,IAA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AA4BC,IAA5B;AACE,MAAIA,IAAI,GAAG,IAAX,EAAiB;AACf,WAAOA,IAAI,GAAG,QAAd;AACD,GAFD,MAEO,IAAIA,IAAI,GAAG,OAAX,EAAoB;AACzB,WAAUA,IAAI,GAAG,IAAjB;AACD,GAFM,MAEA;AACL,WAAU,CAACA,IAAI,GAAG,OAAR,EAAiBM,WAAjB,CAA6B,CAA7B,CAAV;AACD;AACF;;AChIDC,4BAAsB,CAAC,YAAD,CAAtB;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@entur/utils"),t=require("react"),l=require("react-dropzone"),r=require("@entur/icons"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@entur/utils"),t=require("react"),l=require("react-dropzone"),r=require("classnames"),a=require("@entur/icons"),n=require("@entur/button"),o=require("@entur/typography"),i=require("@entur/a11y");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=s(t),d=s(r);function c(){return c=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var r in l)Object.prototype.hasOwnProperty.call(l,r)&&(e[r]=l[r])}return e},c.apply(this,arguments)}var p=["standbyText","errorText","successText","errorUpload","onDrop","onDelete","accept","files","label","removeFileButtonDescription","style"];e.warnAboutMissingStyles("fileupload"),exports.FileUpload=function(e){var t=e.standbyText,r=void 0===t?"Dra fil eller klikk for å laste opp":t,s=e.errorText,f=void 0===s?"Feil ved opplasting av fil":s,v=e.successText,m=void 0===v?"Opplasting fullført":v,_=e.errorUpload,y=void 0!==_&&_,b=e.onDrop,g=e.onDelete,D=void 0===g?function(e){return console.log(e)}:g,E=e.accept,x=void 0===E?"":E,h=e.files,j=void 0===h?[]:h,q=e.label,z=e.removeFileButtonDescription,N=void 0===z?"Fjern fil":z,O=e.style,k=function(e,t){if(null==e)return{};var l,r,a={},n=Object.keys(e);for(r=0;r<n.length;r++)t.indexOf(l=n[r])>=0||(a[l]=e[l]);return a}(e,p),F=l.useDropzone(c({onDrop:b,accept:x},k)),T=F.getRootProps,B=F.getInputProps,P=F.isDragActive,I=F.isDragReject,w=j.length>0;return u.default.createElement("div",c({className:"eds-file-upload__wrapper"},O),u.default.createElement("div",c({className:"eds-file-upload__input"},T()),q&&u.default.createElement(o.Label,{style:{display:"flex"}},q),u.default.createElement("input",c({},B())),u.default.createElement("span",{className:d.default("eds-file-upload__dropzone",{"eds-file-upload__dropzone--success":w},{"eds-file-upload__dropzone--active":P},{"eds-file-upload__dropzone--reject":I},{"eds-file-upload__dropzone--error":y})},w?m:y?f:r)),u.default.createElement("div",{className:"eds-file-upload__file-list"},j.map((function(e,t){return u.default.createElement("div",{className:"eds-file-upload__file-name",key:t},u.default.createElement(a.FileIcon,{className:"eds-file-upload__file-name-icon"}),u.default.createElement("span",{className:"eds-field-upload__file-name-path"},e.path," - ",(l=e.size)<1e3?l+"bytes;":l<1e6?l/1e3+" KB":(l/1e6).toPrecision(4)+" MB"," "),u.default.createElement(n.IconButton,{onClick:function(){return D(e)}},u.default.createElement(i.VisuallyHidden,null,N,", ",e.name),u.default.createElement(a.DeleteIcon,null)));var l}))))};
|
|
2
2
|
//# sourceMappingURL=fileupload.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileupload.cjs.production.min.js","sources":["../src/index.tsx","../src/FileUpload.tsx"],"sourcesContent":["import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('fileupload');\n\nexport * from './FileUpload';\n","import React from 'react';\nimport {\n useDropzone,\n DropzoneOptions,\n FileRejection,\n DropEvent,\n} from 'react-dropzone';\nimport { FileIcon, DeleteIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Label } from '@entur/typography';\nimport
|
|
1
|
+
{"version":3,"file":"fileupload.cjs.production.min.js","sources":["../src/index.tsx","../src/FileUpload.tsx"],"sourcesContent":["import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('fileupload');\n\nexport * from './FileUpload';\n","import React from 'react';\nimport {\n useDropzone,\n DropzoneOptions,\n FileRejection,\n DropEvent,\n FileWithPath,\n} from 'react-dropzone';\nimport classNames from 'classnames';\n\nimport { FileIcon, DeleteIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Label } from '@entur/typography';\nimport { VisuallyHidden } from '@entur/a11y';\n\nimport './FileUpload.scss';\n\ntype FileUploadProps = DropzoneOptions & {\n /** Tekst som vises ved fullført opplasting\n * @default \"Opplasting fullført\"\n */\n successText?: string;\n /** Tekst som vises om opplasting feilet\n * @default \"Feil ved opplasting av fil\"\n */\n errorText?: string;\n /** Tekst som vises før man laster opp noe\n * @default \"Dra fil eller klikk for å laste opp\"\n */\n standbyText?: string;\n /** Boolean for hvis opplastingen feiler.\n * @default false\n */\n errorUpload?: boolean;\n /** Callback for når en fil legges til */\n onDrop?<T extends File>(\n acceptedFiles: T[],\n fileRejections: FileRejection[],\n event: DropEvent,\n ): void;\n /** Callback for når en fil slettes fra lista */\n onDelete: (file: FileWithPath) => void;\n /** Hvilken filtyper som skal aksepteres */\n accept?: string | string[];\n /** Filene som er aktive i komponenten */\n files: File[];\n /** Beskrivende tekst som forklarer feltet */\n label?: string;\n /** Mulighet for å laste opp flere filer */\n multiple?: boolean;\n /**Minste filstørrelse */\n minSize?: number;\n /**Største filstørrelse */\n maxSize?: number;\n /**Tekst som leses opp av skjermleser på søppelbøtte-ikonet\n * @default \"Fjern fil\"\n */\n removeFileButtonDescription?: string;\n [key: string]: any;\n};\n\nexport const FileUpload: React.FC<FileUploadProps> = ({\n standbyText = 'Dra fil eller klikk for å laste opp',\n errorText = 'Feil ved opplasting av fil',\n successText = 'Opplasting fullført',\n errorUpload = false,\n onDrop,\n onDelete = file => console.log(file),\n accept = '',\n files = [],\n label,\n removeFileButtonDescription = 'Fjern fil',\n style,\n ...rest\n}) => {\n const { getRootProps, getInputProps, isDragActive, isDragReject } =\n useDropzone({\n onDrop,\n accept: accept,\n ...rest,\n });\n\n const success = files.length > 0;\n\n return (\n <div className=\"eds-file-upload__wrapper\" {...style}>\n <div className=\"eds-file-upload__input\" {...getRootProps()}>\n {label && <Label style={{ display: 'flex' }}>{label}</Label>}\n <input {...getInputProps()} />\n <span\n className={classNames(\n 'eds-file-upload__dropzone',\n {\n 'eds-file-upload__dropzone--success': success,\n },\n { 'eds-file-upload__dropzone--active': isDragActive },\n { 'eds-file-upload__dropzone--reject': isDragReject },\n { 'eds-file-upload__dropzone--error': errorUpload },\n )}\n >\n {success ? successText : errorUpload ? errorText : standbyText}\n </span>\n </div>\n <div className=\"eds-file-upload__file-list\">\n {files.map((file: FileWithPath, index) => (\n <div className=\"eds-file-upload__file-name\" key={index}>\n <FileIcon className=\"eds-file-upload__file-name-icon\" />\n <span className=\"eds-field-upload__file-name-path\">\n {file.path} - {convertSizeToHuman(file.size)}{' '}\n </span>\n <IconButton onClick={() => onDelete(file)}>\n <VisuallyHidden>\n {removeFileButtonDescription}, {file.name}\n </VisuallyHidden>\n <DeleteIcon />\n </IconButton>\n </div>\n ))}\n </div>\n </div>\n );\n};\n\nfunction convertSizeToHuman(size: number) {\n if (size < 1000) {\n return size + 'bytes;';\n } else if (size < 1000000) {\n return `${size / 1000} KB`;\n } else {\n return `${(size / 1000000).toPrecision(4)} MB`;\n }\n}\n"],"names":["warnAboutMissingStyles","standbyText","errorText","successText","errorUpload","onDrop","onDelete","file","console","log","accept","files","label","removeFileButtonDescription","style","rest","useDropzone","getRootProps","getInputProps","isDragActive","isDragReject","success","length","React","className","Label","display","classNames","map","index","key","FileIcon","path","size","toPrecision","IconButton","onClick","VisuallyHidden","name","DeleteIcon"],"mappings":"itBAGAA,yBAAuB,iCC0D8B,oBACnDC,YAAAA,aAAc,4CACdC,UAAAA,aAAY,mCACZC,YAAAA,aAAc,4BACdC,YAAAA,gBACAC,IAAAA,WACAC,SAAAA,aAAW,SAAAC,UAAQC,QAAQC,IAAIF,UAC/BG,OAAAA,aAAS,SACTC,MAAAA,aAAQ,KACRC,IAAAA,UACAC,4BAAAA,aAA8B,cAC9BC,IAAAA,MACGC,4IAGDC,iBACEX,OAAAA,EACAK,OAAQA,GACLK,IAJCE,IAAAA,aAAcC,IAAAA,cAAeC,IAAAA,aAAcC,IAAAA,aAO7CC,EAAUV,EAAMW,OAAS,SAG7BC,iCAAKC,UAAU,4BAA+BV,GAC5CS,iCAAKC,UAAU,0BAA6BP,KACzCL,GAASW,wBAACE,SAAMX,MAAO,CAAEY,QAAS,SAAWd,GAC9CW,qCAAWL,MACXK,gCACEC,UAAWG,UACT,4BACA,sCACwCN,GAExC,qCAAuCF,GACvC,qCAAuCC,GACvC,oCAAsChB,KAGvCiB,EAAUlB,EAAcC,EAAcF,EAAYD,IAGvDsB,+BAAKC,UAAU,8BACZb,EAAMiB,KAAI,SAACrB,EAAoBsB,UAC9BN,+BAAKC,UAAU,6BAA6BM,IAAKD,GAC/CN,wBAACQ,YAASP,UAAU,oCACpBD,gCAAMC,UAAU,oCACbjB,EAAKyB,YAeQC,EAfoB1B,EAAK0B,MAgBxC,IACFA,EAAO,SACLA,EAAO,IACNA,EAAO,YAENA,EAAO,KAASC,YAAY,SArBiB,KAEhDX,wBAACY,cAAWC,QAAS,kBAAM9B,EAASC,KAClCgB,wBAACc,sBACExB,OAA+BN,EAAK+B,MAEvCf,wBAACgB,qBASf,IAA4BN"}
|
package/dist/fileupload.esm.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { warnAboutMissingStyles } from '@entur/utils';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { useDropzone } from 'react-dropzone';
|
|
4
|
+
import classNames from 'classnames';
|
|
4
5
|
import { FileIcon, DeleteIcon } from '@entur/icons';
|
|
5
6
|
import { IconButton } from '@entur/button';
|
|
6
7
|
import { Label } from '@entur/typography';
|
|
7
|
-
import
|
|
8
|
+
import { VisuallyHidden } from '@entur/a11y';
|
|
8
9
|
|
|
9
10
|
function _extends() {
|
|
10
11
|
_extends = Object.assign || function (target) {
|
|
@@ -39,7 +40,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
39
40
|
return target;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
var _excluded = ["standbyText", "errorText", "successText", "errorUpload", "onDrop", "onDelete", "accept", "files", "label", "style"];
|
|
43
|
+
var _excluded = ["standbyText", "errorText", "successText", "errorUpload", "onDrop", "onDelete", "accept", "files", "label", "removeFileButtonDescription", "style"];
|
|
43
44
|
var FileUpload = function FileUpload(_ref) {
|
|
44
45
|
var _ref$standbyText = _ref.standbyText,
|
|
45
46
|
standbyText = _ref$standbyText === void 0 ? 'Dra fil eller klikk for å laste opp' : _ref$standbyText,
|
|
@@ -59,6 +60,8 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
59
60
|
_ref$files = _ref.files,
|
|
60
61
|
files = _ref$files === void 0 ? [] : _ref$files,
|
|
61
62
|
label = _ref.label,
|
|
63
|
+
_ref$removeFileButton = _ref.removeFileButtonDescription,
|
|
64
|
+
removeFileButtonDescription = _ref$removeFileButton === void 0 ? 'Fjern fil' : _ref$removeFileButton,
|
|
62
65
|
style = _ref.style,
|
|
63
66
|
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
64
67
|
|
|
@@ -88,7 +91,7 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
88
91
|
}, {
|
|
89
92
|
'eds-file-upload__dropzone--reject': isDragReject
|
|
90
93
|
}, {
|
|
91
|
-
'eds-file-
|
|
94
|
+
'eds-file-upload__dropzone--error': errorUpload
|
|
92
95
|
})
|
|
93
96
|
}, success ? successText : errorUpload ? errorText : standbyText)), React.createElement("div", {
|
|
94
97
|
className: "eds-file-upload__file-list"
|
|
@@ -104,7 +107,7 @@ var FileUpload = function FileUpload(_ref) {
|
|
|
104
107
|
onClick: function onClick() {
|
|
105
108
|
return onDelete(file);
|
|
106
109
|
}
|
|
107
|
-
}, React.createElement(DeleteIcon, null)));
|
|
110
|
+
}, React.createElement(VisuallyHidden, null, removeFileButtonDescription, ", ", file.name), React.createElement(DeleteIcon, null)));
|
|
108
111
|
})));
|
|
109
112
|
};
|
|
110
113
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileupload.esm.js","sources":["../src/FileUpload.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport {\n useDropzone,\n DropzoneOptions,\n FileRejection,\n DropEvent,\n} from 'react-dropzone';\nimport { FileIcon, DeleteIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Label } from '@entur/typography';\nimport
|
|
1
|
+
{"version":3,"file":"fileupload.esm.js","sources":["../src/FileUpload.tsx","../src/index.tsx"],"sourcesContent":["import React from 'react';\nimport {\n useDropzone,\n DropzoneOptions,\n FileRejection,\n DropEvent,\n FileWithPath,\n} from 'react-dropzone';\nimport classNames from 'classnames';\n\nimport { FileIcon, DeleteIcon } from '@entur/icons';\nimport { IconButton } from '@entur/button';\nimport { Label } from '@entur/typography';\nimport { VisuallyHidden } from '@entur/a11y';\n\nimport './FileUpload.scss';\n\ntype FileUploadProps = DropzoneOptions & {\n /** Tekst som vises ved fullført opplasting\n * @default \"Opplasting fullført\"\n */\n successText?: string;\n /** Tekst som vises om opplasting feilet\n * @default \"Feil ved opplasting av fil\"\n */\n errorText?: string;\n /** Tekst som vises før man laster opp noe\n * @default \"Dra fil eller klikk for å laste opp\"\n */\n standbyText?: string;\n /** Boolean for hvis opplastingen feiler.\n * @default false\n */\n errorUpload?: boolean;\n /** Callback for når en fil legges til */\n onDrop?<T extends File>(\n acceptedFiles: T[],\n fileRejections: FileRejection[],\n event: DropEvent,\n ): void;\n /** Callback for når en fil slettes fra lista */\n onDelete: (file: FileWithPath) => void;\n /** Hvilken filtyper som skal aksepteres */\n accept?: string | string[];\n /** Filene som er aktive i komponenten */\n files: File[];\n /** Beskrivende tekst som forklarer feltet */\n label?: string;\n /** Mulighet for å laste opp flere filer */\n multiple?: boolean;\n /**Minste filstørrelse */\n minSize?: number;\n /**Største filstørrelse */\n maxSize?: number;\n /**Tekst som leses opp av skjermleser på søppelbøtte-ikonet\n * @default \"Fjern fil\"\n */\n removeFileButtonDescription?: string;\n [key: string]: any;\n};\n\nexport const FileUpload: React.FC<FileUploadProps> = ({\n standbyText = 'Dra fil eller klikk for å laste opp',\n errorText = 'Feil ved opplasting av fil',\n successText = 'Opplasting fullført',\n errorUpload = false,\n onDrop,\n onDelete = file => console.log(file),\n accept = '',\n files = [],\n label,\n removeFileButtonDescription = 'Fjern fil',\n style,\n ...rest\n}) => {\n const { getRootProps, getInputProps, isDragActive, isDragReject } =\n useDropzone({\n onDrop,\n accept: accept,\n ...rest,\n });\n\n const success = files.length > 0;\n\n return (\n <div className=\"eds-file-upload__wrapper\" {...style}>\n <div className=\"eds-file-upload__input\" {...getRootProps()}>\n {label && <Label style={{ display: 'flex' }}>{label}</Label>}\n <input {...getInputProps()} />\n <span\n className={classNames(\n 'eds-file-upload__dropzone',\n {\n 'eds-file-upload__dropzone--success': success,\n },\n { 'eds-file-upload__dropzone--active': isDragActive },\n { 'eds-file-upload__dropzone--reject': isDragReject },\n { 'eds-file-upload__dropzone--error': errorUpload },\n )}\n >\n {success ? successText : errorUpload ? errorText : standbyText}\n </span>\n </div>\n <div className=\"eds-file-upload__file-list\">\n {files.map((file: FileWithPath, index) => (\n <div className=\"eds-file-upload__file-name\" key={index}>\n <FileIcon className=\"eds-file-upload__file-name-icon\" />\n <span className=\"eds-field-upload__file-name-path\">\n {file.path} - {convertSizeToHuman(file.size)}{' '}\n </span>\n <IconButton onClick={() => onDelete(file)}>\n <VisuallyHidden>\n {removeFileButtonDescription}, {file.name}\n </VisuallyHidden>\n <DeleteIcon />\n </IconButton>\n </div>\n ))}\n </div>\n </div>\n );\n};\n\nfunction convertSizeToHuman(size: number) {\n if (size < 1000) {\n return size + 'bytes;';\n } else if (size < 1000000) {\n return `${size / 1000} KB`;\n } else {\n return `${(size / 1000000).toPrecision(4)} MB`;\n }\n}\n","import { warnAboutMissingStyles } from '@entur/utils';\nimport './index.scss';\n\nwarnAboutMissingStyles('fileupload');\n\nexport * from './FileUpload';\n"],"names":["FileUpload","standbyText","errorText","successText","errorUpload","onDrop","onDelete","file","console","log","accept","files","label","removeFileButtonDescription","style","rest","useDropzone","getRootProps","getInputProps","isDragActive","isDragReject","success","length","React","className","Label","display","classNames","map","index","key","FileIcon","path","convertSizeToHuman","size","IconButton","onClick","VisuallyHidden","name","DeleteIcon","toPrecision","warnAboutMissingStyles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA6DaA,UAAU,GAA8B,SAAxCA,UAAwC;8BACnDC;MAAAA,4CAAc;4BACdC;MAAAA,wCAAY;8BACZC;MAAAA,4CAAc;8BACdC;MAAAA,4CAAc;MACdC,cAAAA;2BACAC;MAAAA,sCAAW,UAAAC,IAAI;AAAA,WAAIC,OAAO,CAACC,GAAR,CAAYF,IAAZ,CAAJ;AAAA;yBACfG;MAAAA,kCAAS;wBACTC;MAAAA,gCAAQ;MACRC,aAAAA;mCACAC;MAAAA,iEAA8B;MAC9BC,aAAAA;MACGC;;AAEH,qBACEC,WAAW;AACTX,IAAAA,MAAM,EAANA,MADS;AAETK,IAAAA,MAAM,EAAEA;AAFC,KAGNK,IAHM,EADb;AAAA,MAAQE,YAAR,gBAAQA,YAAR;AAAA,MAAsBC,aAAtB,gBAAsBA,aAAtB;AAAA,MAAqCC,YAArC,gBAAqCA,YAArC;AAAA,MAAmDC,YAAnD,gBAAmDA,YAAnD;;AAOA,MAAMC,OAAO,GAAGV,KAAK,CAACW,MAAN,GAAe,CAA/B;AAEA,SACEC,mBAAA,MAAA;AAAKC,IAAAA,SAAS,EAAC;AAAf,KAA8CV,KAA9C,GACES,mBAAA,MAAA;AAAKC,IAAAA,SAAS,EAAC;AAAf,KAA4CP,YAAY,EAAxD,GACGL,KAAK,IAAIW,mBAAA,CAACE,KAAD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GAFD,MAEO,IAAIA,IAAI,GAAG,OAAX,EAAoB;AACzB,WAAUA,IAAI,GAAG,IAAjB;AACD,GAFM,MAEA;AACL,WAAU,CAACA,IAAI,GAAG,OAAR,EAAiBM,WAAjB,CAA6B,CAA7B,CAAV;AACD;AACF;;AChIDC,sBAAsB,CAAC,YAAD,CAAtB;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@entur/fileupload",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.46",
|
|
4
4
|
"license": "EUPL-1.2",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/fileupload.esm.js",
|
|
@@ -23,11 +23,12 @@
|
|
|
23
23
|
"lint": "dts lint"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@entur/
|
|
27
|
-
"@entur/
|
|
28
|
-
"@entur/
|
|
29
|
-
"@entur/
|
|
30
|
-
"@entur/
|
|
26
|
+
"@entur/a11y": "0.2.47",
|
|
27
|
+
"@entur/button": "^2.10.2",
|
|
28
|
+
"@entur/icons": "^4.3.2",
|
|
29
|
+
"@entur/tokens": "^3.4.1",
|
|
30
|
+
"@entur/typography": "^1.6.16",
|
|
31
|
+
"@entur/utils": "^0.4.4",
|
|
31
32
|
"classnames": "^2.3.1",
|
|
32
33
|
"react-dropzone": "^11.3.4"
|
|
33
34
|
},
|
|
@@ -35,5 +36,5 @@
|
|
|
35
36
|
"react": ">=16.8.0",
|
|
36
37
|
"react-dom": ">=16.8.0"
|
|
37
38
|
},
|
|
38
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "f3bffb3de2412430d4d5d37dbd397f4dd995522b"
|
|
39
40
|
}
|