@panneau/action-upload 3.0.182
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/assets/css/styles.css +0 -0
- package/es/index.js +117 -0
- package/lib/index.js +121 -0
- package/package.json +60 -0
|
File without changes
|
package/es/index.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
+
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
+
import classNames from 'classnames';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import React, { useState, useCallback, useMemo } from 'react';
|
|
7
|
+
import { FormattedMessage } from 'react-intl';
|
|
8
|
+
import Button from '@panneau/element-button';
|
|
9
|
+
|
|
10
|
+
var styles = {};
|
|
11
|
+
|
|
12
|
+
var _excluded = ["title", "description", "fields", "endpoint", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "withConfirmation", "className"];
|
|
13
|
+
|
|
14
|
+
// TODO: fix this
|
|
15
|
+
|
|
16
|
+
var propTypes = {
|
|
17
|
+
title: PropTypes.node,
|
|
18
|
+
description: PropTypes.node,
|
|
19
|
+
fields: PropTypes.arrayOf(PropTypes.shape({})),
|
|
20
|
+
endpoint: PropTypes.string,
|
|
21
|
+
label: PropTypes.string,
|
|
22
|
+
value: PropTypes.bool,
|
|
23
|
+
icon: PropTypes.string,
|
|
24
|
+
theme: PropTypes.string,
|
|
25
|
+
disabled: PropTypes.bool,
|
|
26
|
+
onChange: PropTypes.func,
|
|
27
|
+
onConfirmed: PropTypes.func,
|
|
28
|
+
withConfirmation: PropTypes.bool,
|
|
29
|
+
className: PropTypes.string
|
|
30
|
+
};
|
|
31
|
+
var defaultProps = {
|
|
32
|
+
title: null,
|
|
33
|
+
description: null,
|
|
34
|
+
fields: null,
|
|
35
|
+
endpoint: null,
|
|
36
|
+
label: /*#__PURE__*/React.createElement(FormattedMessage, {
|
|
37
|
+
id: "rklw2v",
|
|
38
|
+
defaultMessage: [{
|
|
39
|
+
"type": 0,
|
|
40
|
+
"value": "Add a file"
|
|
41
|
+
}]
|
|
42
|
+
}),
|
|
43
|
+
icon: 'upload',
|
|
44
|
+
value: null,
|
|
45
|
+
theme: 'primary',
|
|
46
|
+
disabled: false,
|
|
47
|
+
onChange: null,
|
|
48
|
+
onConfirmed: null,
|
|
49
|
+
withConfirmation: false,
|
|
50
|
+
className: null
|
|
51
|
+
};
|
|
52
|
+
var UploadAction = function UploadAction(_ref) {
|
|
53
|
+
_ref.title;
|
|
54
|
+
_ref.description;
|
|
55
|
+
_ref.fields;
|
|
56
|
+
_ref.endpoint;
|
|
57
|
+
var label = _ref.label,
|
|
58
|
+
icon = _ref.icon,
|
|
59
|
+
value = _ref.value,
|
|
60
|
+
theme = _ref.theme,
|
|
61
|
+
disabled = _ref.disabled,
|
|
62
|
+
onChange = _ref.onChange,
|
|
63
|
+
onConfirmed = _ref.onConfirmed,
|
|
64
|
+
withConfirmation = _ref.withConfirmation,
|
|
65
|
+
className = _ref.className,
|
|
66
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
67
|
+
var _useState = useState(false),
|
|
68
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
69
|
+
showModal = _useState2[0],
|
|
70
|
+
setShowModal = _useState2[1];
|
|
71
|
+
var onOpen = useCallback(function () {
|
|
72
|
+
setShowModal(true);
|
|
73
|
+
}, [setShowModal]);
|
|
74
|
+
useCallback(function (newValue) {
|
|
75
|
+
setShowModal(false);
|
|
76
|
+
if (onConfirmed !== null) {
|
|
77
|
+
onConfirmed(newValue);
|
|
78
|
+
}
|
|
79
|
+
if (onChange !== null) {
|
|
80
|
+
onChange(newValue);
|
|
81
|
+
}
|
|
82
|
+
}, [onChange, setShowModal]);
|
|
83
|
+
useCallback(function () {
|
|
84
|
+
setShowModal(false);
|
|
85
|
+
}, [setShowModal]);
|
|
86
|
+
var ids = useMemo(function () {
|
|
87
|
+
return (value || []).map(function () {
|
|
88
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
89
|
+
_ref2$id = _ref2.id,
|
|
90
|
+
id = _ref2$id === void 0 ? null : _ref2$id;
|
|
91
|
+
return id;
|
|
92
|
+
}).filter(function (id) {
|
|
93
|
+
return id !== null;
|
|
94
|
+
});
|
|
95
|
+
}, [value]);
|
|
96
|
+
useMemo(function () {
|
|
97
|
+
return (ids || []).map(function (id) {
|
|
98
|
+
return "#".concat(id);
|
|
99
|
+
}).join(', ');
|
|
100
|
+
}, [ids]);
|
|
101
|
+
useMemo(function () {
|
|
102
|
+
return value !== null && value.length > 1;
|
|
103
|
+
}, [value]);
|
|
104
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
|
|
105
|
+
className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
|
|
106
|
+
label: label,
|
|
107
|
+
icon: icon,
|
|
108
|
+
onClick: withConfirmation ? onOpen : null,
|
|
109
|
+
disabled: disabled,
|
|
110
|
+
theme: disabled ? 'secondary' : theme
|
|
111
|
+
}, props)), showModal ? 'Something' : null);
|
|
112
|
+
};
|
|
113
|
+
UploadAction.propTypes = propTypes;
|
|
114
|
+
UploadAction.defaultProps = defaultProps;
|
|
115
|
+
var UploadAction$1 = UploadAction;
|
|
116
|
+
|
|
117
|
+
export { UploadAction$1 as default };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
7
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
|
+
var classNames = require('classnames');
|
|
9
|
+
var PropTypes = require('prop-types');
|
|
10
|
+
var React = require('react');
|
|
11
|
+
var reactIntl = require('react-intl');
|
|
12
|
+
var Button = require('@panneau/element-button');
|
|
13
|
+
|
|
14
|
+
var styles = {};
|
|
15
|
+
|
|
16
|
+
var _excluded = ["title", "description", "fields", "endpoint", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "withConfirmation", "className"];
|
|
17
|
+
|
|
18
|
+
// TODO: fix this
|
|
19
|
+
|
|
20
|
+
var propTypes = {
|
|
21
|
+
title: PropTypes.node,
|
|
22
|
+
description: PropTypes.node,
|
|
23
|
+
fields: PropTypes.arrayOf(PropTypes.shape({})),
|
|
24
|
+
endpoint: PropTypes.string,
|
|
25
|
+
label: PropTypes.string,
|
|
26
|
+
value: PropTypes.bool,
|
|
27
|
+
icon: PropTypes.string,
|
|
28
|
+
theme: PropTypes.string,
|
|
29
|
+
disabled: PropTypes.bool,
|
|
30
|
+
onChange: PropTypes.func,
|
|
31
|
+
onConfirmed: PropTypes.func,
|
|
32
|
+
withConfirmation: PropTypes.bool,
|
|
33
|
+
className: PropTypes.string
|
|
34
|
+
};
|
|
35
|
+
var defaultProps = {
|
|
36
|
+
title: null,
|
|
37
|
+
description: null,
|
|
38
|
+
fields: null,
|
|
39
|
+
endpoint: null,
|
|
40
|
+
label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
|
|
41
|
+
id: "rklw2v",
|
|
42
|
+
defaultMessage: [{
|
|
43
|
+
"type": 0,
|
|
44
|
+
"value": "Add a file"
|
|
45
|
+
}]
|
|
46
|
+
}),
|
|
47
|
+
icon: 'upload',
|
|
48
|
+
value: null,
|
|
49
|
+
theme: 'primary',
|
|
50
|
+
disabled: false,
|
|
51
|
+
onChange: null,
|
|
52
|
+
onConfirmed: null,
|
|
53
|
+
withConfirmation: false,
|
|
54
|
+
className: null
|
|
55
|
+
};
|
|
56
|
+
var UploadAction = function UploadAction(_ref) {
|
|
57
|
+
_ref.title;
|
|
58
|
+
_ref.description;
|
|
59
|
+
_ref.fields;
|
|
60
|
+
_ref.endpoint;
|
|
61
|
+
var label = _ref.label,
|
|
62
|
+
icon = _ref.icon,
|
|
63
|
+
value = _ref.value,
|
|
64
|
+
theme = _ref.theme,
|
|
65
|
+
disabled = _ref.disabled,
|
|
66
|
+
onChange = _ref.onChange,
|
|
67
|
+
onConfirmed = _ref.onConfirmed,
|
|
68
|
+
withConfirmation = _ref.withConfirmation,
|
|
69
|
+
className = _ref.className,
|
|
70
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
71
|
+
var _useState = React.useState(false),
|
|
72
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
73
|
+
showModal = _useState2[0],
|
|
74
|
+
setShowModal = _useState2[1];
|
|
75
|
+
var onOpen = React.useCallback(function () {
|
|
76
|
+
setShowModal(true);
|
|
77
|
+
}, [setShowModal]);
|
|
78
|
+
React.useCallback(function (newValue) {
|
|
79
|
+
setShowModal(false);
|
|
80
|
+
if (onConfirmed !== null) {
|
|
81
|
+
onConfirmed(newValue);
|
|
82
|
+
}
|
|
83
|
+
if (onChange !== null) {
|
|
84
|
+
onChange(newValue);
|
|
85
|
+
}
|
|
86
|
+
}, [onChange, setShowModal]);
|
|
87
|
+
React.useCallback(function () {
|
|
88
|
+
setShowModal(false);
|
|
89
|
+
}, [setShowModal]);
|
|
90
|
+
var ids = React.useMemo(function () {
|
|
91
|
+
return (value || []).map(function () {
|
|
92
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
93
|
+
_ref2$id = _ref2.id,
|
|
94
|
+
id = _ref2$id === void 0 ? null : _ref2$id;
|
|
95
|
+
return id;
|
|
96
|
+
}).filter(function (id) {
|
|
97
|
+
return id !== null;
|
|
98
|
+
});
|
|
99
|
+
}, [value]);
|
|
100
|
+
React.useMemo(function () {
|
|
101
|
+
return (ids || []).map(function (id) {
|
|
102
|
+
return "#".concat(id);
|
|
103
|
+
}).join(', ');
|
|
104
|
+
}, [ids]);
|
|
105
|
+
React.useMemo(function () {
|
|
106
|
+
return value !== null && value.length > 1;
|
|
107
|
+
}, [value]);
|
|
108
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
|
|
109
|
+
className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
|
|
110
|
+
label: label,
|
|
111
|
+
icon: icon,
|
|
112
|
+
onClick: withConfirmation ? onOpen : null,
|
|
113
|
+
disabled: disabled,
|
|
114
|
+
theme: disabled ? 'secondary' : theme
|
|
115
|
+
}, props)), showModal ? 'Something' : null);
|
|
116
|
+
};
|
|
117
|
+
UploadAction.propTypes = propTypes;
|
|
118
|
+
UploadAction.defaultProps = defaultProps;
|
|
119
|
+
var UploadAction$1 = UploadAction;
|
|
120
|
+
|
|
121
|
+
exports.default = UploadAction$1;
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@panneau/action-upload",
|
|
3
|
+
"version": "3.0.182",
|
|
4
|
+
"description": "Upload action",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"javascript"
|
|
7
|
+
],
|
|
8
|
+
"homepage": "https://github.com/folkloreinc/panneau-js",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/folkloreinc/panneau-js.git"
|
|
12
|
+
},
|
|
13
|
+
"author": {
|
|
14
|
+
"name": "Folklore",
|
|
15
|
+
"email": "info@folklore.email"
|
|
16
|
+
},
|
|
17
|
+
"contributors": [
|
|
18
|
+
{
|
|
19
|
+
"name": "David Mongeau-Petitpas",
|
|
20
|
+
"email": "dmp@folklore.email"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "Nicolas Roy-Bourdages",
|
|
24
|
+
"email": "nrb@folklore.email"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"license": "ISC",
|
|
28
|
+
"main": "lib/index.js",
|
|
29
|
+
"module": "es/index.js",
|
|
30
|
+
"files": [
|
|
31
|
+
"lib",
|
|
32
|
+
"es",
|
|
33
|
+
"assets"
|
|
34
|
+
],
|
|
35
|
+
"scripts": {
|
|
36
|
+
"prepublishOnly": "npm run build",
|
|
37
|
+
"build": "../../scripts/prepare-package.sh"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
41
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
45
|
+
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
46
|
+
},
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@babel/runtime": "^7.12.5",
|
|
49
|
+
"@panneau/core": "^3.0.182",
|
|
50
|
+
"@panneau/element-button": "^3.0.182",
|
|
51
|
+
"@panneau/themes": "^3.0.182",
|
|
52
|
+
"classnames": "^2.5.1",
|
|
53
|
+
"prop-types": "^15.7.2",
|
|
54
|
+
"react-intl": "^5.15.8||^6.0.0"
|
|
55
|
+
},
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public"
|
|
58
|
+
},
|
|
59
|
+
"gitHead": "27626681ce1bcf3e4779ecabeb5d69c58df4d351"
|
|
60
|
+
}
|