@comet/admin 9.0.0-beta.4 → 9.0.0-beta.5
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/lib/common/DeleteDialog.d.ts +1 -0
- package/lib/common/DeleteDialog.d.ts.map +1 -1
- package/lib/common/DeleteDialog.js +8 -1
- package/lib/common/buttons/clearinput/ClearInputButton.js +1 -1
- package/lib/common/toolbar/__stories__/DataGridToolbar.stories.js +76 -0
- package/lib/common/toolbar/__stories__/Toolbar.stories.js +82 -0
- package/lib/dataGrid/__stories__/ClickableRows.stories.js +109 -0
- package/lib/dataGrid/__stories__/CrudMoreActionsMenu.stories.js +50 -0
- package/lib/dataGrid/__stories__/DataGrid.stories.js +94 -0
- package/lib/dataGrid/__stories__/DataGridSingleSelectFilter.stories.js +492 -0
- package/lib/form/__stories__/AsyncAutocompleteField.stories.js +660 -0
- package/lib/form/__stories__/AsyncSelectField.stories.js +513 -0
- package/lib/form/__stories__/Autocomplete.stories.js +188 -0
- package/lib/form/__stories__/AutocompleteField.stories.js +48 -0
- package/lib/form/__stories__/Checkbox.stories.js +70 -0
- package/lib/form/__stories__/CheckboxField.stories.js +87 -0
- package/lib/form/__stories__/CheckboxListField.stories.js +172 -0
- package/lib/form/__stories__/CustomButtons.stories.js +78 -0
- package/lib/form/__stories__/DependentAsyncSelects.stories.js +91 -0
- package/lib/form/__stories__/DisableAutoNavigation.stories.js +132 -0
- package/lib/form/__stories__/DisabledSubmitIfNotDirty.stories.js +54 -0
- package/lib/form/__stories__/FieldContainer.stories.js +87 -0
- package/lib/form/__stories__/FinalFormFileSelect.stories.js +155 -0
- package/lib/form/__stories__/FormInStack.stories.js +133 -0
- package/lib/form/__stories__/FormLayouts.stories.js +174 -0
- package/lib/form/__stories__/FormValidation.stories.js +82 -0
- package/lib/form/__stories__/Input.stories.js +37 -0
- package/lib/form/__stories__/NumberField.stories.js +38 -0
- package/lib/form/__stories__/Radio.stories.js +101 -0
- package/lib/form/__stories__/RadioGroupField.stories.js +172 -0
- package/lib/form/__stories__/RangeInput.stories.js +239 -0
- package/lib/form/__stories__/RouterTabs.stories.js +96 -0
- package/lib/form/__stories__/RouterTabsInForm.stories.js +73 -0
- package/lib/form/__stories__/RouterTabsInFormWithSubroutes.stories.js +96 -0
- package/lib/form/__stories__/ScrollToErrorField.stories.js +82 -0
- package/lib/form/__stories__/SearchField.stories.js +38 -0
- package/lib/form/__stories__/Select.stories.js +187 -0
- package/lib/form/__stories__/SelectField.stories.js +100 -0
- package/lib/form/__stories__/ShowErrorStrategies.stories.js +107 -0
- package/lib/form/__stories__/SingleTextField.stories.js +108 -0
- package/lib/form/__stories__/StackInForm.stories.js +53 -0
- package/lib/form/__stories__/SubmitErrors.stories.js +90 -0
- package/lib/form/__stories__/Switch.stories.js +49 -0
- package/lib/form/__stories__/SwitchField.stories.js +87 -0
- package/lib/form/__stories__/Tabs.stories.js +78 -0
- package/lib/form/__stories__/TextAreaField.stories.js +38 -0
- package/lib/form/__stories__/TextField.stories.js +67 -0
- package/lib/form/__stories__/ToggleButtonGroupField.stories.js +312 -0
- package/lib/form/__stories__/TwoLevelValidation.stories.js +168 -0
- package/lib/form/__stories__/Typography.stories.js +71 -0
- package/lib/form/file/__stories__/FileDropzone.stories.js +81 -0
- package/lib/form/file/__stories__/FileSelect.stories.js +139 -0
- package/lib/form/file/__stories__/FileSelectListItem.stories.js +108 -0
- package/lib/form/file/__stories__/FileSelectMultipleExamples.stories.js +187 -0
- package/lib/helpers/useTopOffset.js +1 -1
- package/lib/tabs/__stories__/DynamicTabs.stories.js +84 -0
- package/lib/tabs/__stories__/NestedStackSwitchWithRouterTabs.stories.js +84 -0
- package/lib/tabs/__stories__/OverflowIssues.stories.js +224 -0
- package/lib/tabs/__stories__/RouterTabs.stories.js +31 -0
- package/lib/tabs/__stories__/RouterTabsInStack.stories.js +74 -0
- package/lib/tabs/__stories__/RouterTabsInSubroute.stories.js +68 -0
- package/lib/tabs/__stories__/Tabs.stories.js +219 -0
- package/lib/theme/componentsTheme/MuiDataGrid.js +1 -1
- package/package.json +13 -13
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
2
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
3
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
4
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
|
|
5
|
+
import { Card, CardContent, Grid } from "@mui/material";
|
|
6
|
+
import { FinalForm } from "../../FinalForm";
|
|
7
|
+
import { Field } from "../../form/Field";
|
|
8
|
+
import { FinalFormInput } from "../../form/FinalFormInput";
|
|
9
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
var validateWarning = function validateWarning(value) {
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
if (value < 10) {
|
|
15
|
+
return "Value should be >= 10";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var validateWarningAsync = function validateWarningAsync(value) {
|
|
19
|
+
return new Promise(function (resolve) {
|
|
20
|
+
setTimeout(function () {
|
|
21
|
+
resolve(validateWarning(value));
|
|
22
|
+
}, 5000);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var validateError = function validateError(value) {
|
|
26
|
+
if (value === undefined) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (value < 5) {
|
|
30
|
+
return "Value must be >= 5";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
export default {
|
|
34
|
+
title: "components/form"
|
|
35
|
+
};
|
|
36
|
+
export var TwoLevelValidationWarningAndError = {
|
|
37
|
+
render: function render() {
|
|
38
|
+
return /*#__PURE__*/_jsxs(Grid, {
|
|
39
|
+
container: true,
|
|
40
|
+
spacing: 4,
|
|
41
|
+
style: {
|
|
42
|
+
maxWidth: 800
|
|
43
|
+
},
|
|
44
|
+
children: [/*#__PURE__*/_jsx(Grid, {
|
|
45
|
+
size: 6,
|
|
46
|
+
children: /*#__PURE__*/_jsx(FinalForm, {
|
|
47
|
+
mode: "add",
|
|
48
|
+
onSubmit: function onSubmit() {},
|
|
49
|
+
render: function render(_ref) {
|
|
50
|
+
var handleSubmit = _ref.handleSubmit;
|
|
51
|
+
return /*#__PURE__*/_jsx(Card, {
|
|
52
|
+
variant: "outlined",
|
|
53
|
+
children: /*#__PURE__*/_jsx(CardContent, {
|
|
54
|
+
children: /*#__PURE__*/_jsxs("form", {
|
|
55
|
+
onSubmit: handleSubmit,
|
|
56
|
+
children: [/*#__PURE__*/_jsx(Field, {
|
|
57
|
+
name: "input1",
|
|
58
|
+
type: "number",
|
|
59
|
+
label: "Required only validation",
|
|
60
|
+
placeholder: "Must be >= 5, should be >= 10",
|
|
61
|
+
component: FinalFormInput,
|
|
62
|
+
required: true,
|
|
63
|
+
fullWidth: true
|
|
64
|
+
}), /*#__PURE__*/_jsx(Field, {
|
|
65
|
+
name: "input2",
|
|
66
|
+
type: "number",
|
|
67
|
+
label: "Error only validation",
|
|
68
|
+
placeholder: "Must be >= 5, should be >= 10",
|
|
69
|
+
component: FinalFormInput,
|
|
70
|
+
required: true,
|
|
71
|
+
validate: validateError,
|
|
72
|
+
fullWidth: true
|
|
73
|
+
}), /*#__PURE__*/_jsx(Field, {
|
|
74
|
+
name: "input3",
|
|
75
|
+
type: "number",
|
|
76
|
+
label: "Warning only validation",
|
|
77
|
+
placeholder: "Must be >= 5, should be >= 10",
|
|
78
|
+
component: FinalFormInput,
|
|
79
|
+
required: true,
|
|
80
|
+
validateWarning: validateWarning,
|
|
81
|
+
fullWidth: true
|
|
82
|
+
}), /*#__PURE__*/_jsx(Field, {
|
|
83
|
+
name: "input4",
|
|
84
|
+
type: "number",
|
|
85
|
+
label: "Error and warning validation",
|
|
86
|
+
placeholder: "Must be >= 5, should be >= 10",
|
|
87
|
+
component: FinalFormInput,
|
|
88
|
+
required: true,
|
|
89
|
+
validate: validateError,
|
|
90
|
+
validateWarning: validateWarning,
|
|
91
|
+
fullWidth: true
|
|
92
|
+
}), /*#__PURE__*/_jsx(Field, {
|
|
93
|
+
name: "input5",
|
|
94
|
+
type: "number",
|
|
95
|
+
label: "Async warning validation",
|
|
96
|
+
placeholder: "Must be >= 5, should be >= 10",
|
|
97
|
+
component: FinalFormInput,
|
|
98
|
+
required: true,
|
|
99
|
+
validateWarning: validateWarningAsync,
|
|
100
|
+
fullWidth: true
|
|
101
|
+
})]
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
}), /*#__PURE__*/_jsx(Grid, {
|
|
108
|
+
size: 6,
|
|
109
|
+
children: /*#__PURE__*/_jsx(FinalForm, {
|
|
110
|
+
mode: "add",
|
|
111
|
+
onSubmit: function onSubmit() {},
|
|
112
|
+
render: function render(_ref2) {
|
|
113
|
+
var handleSubmit = _ref2.handleSubmit;
|
|
114
|
+
return /*#__PURE__*/_jsx(Card, {
|
|
115
|
+
variant: "outlined",
|
|
116
|
+
children: /*#__PURE__*/_jsx(CardContent, {
|
|
117
|
+
children: /*#__PURE__*/_jsx("form", {
|
|
118
|
+
onSubmit: handleSubmit,
|
|
119
|
+
children: /*#__PURE__*/_jsx(Field, {
|
|
120
|
+
name: "input1",
|
|
121
|
+
type: "number",
|
|
122
|
+
label: "Record level validation",
|
|
123
|
+
placeholder: "Must be >= 5, should be >= 10",
|
|
124
|
+
component: FinalFormInput,
|
|
125
|
+
required: true,
|
|
126
|
+
fullWidth: true
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
validate: function validate(values) {
|
|
133
|
+
return {
|
|
134
|
+
input1: validateError(values.input1, values)
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
validateWarning: (/*#__PURE__*/function () {
|
|
138
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(values) {
|
|
139
|
+
var warning;
|
|
140
|
+
return _regenerator().w(function (_context) {
|
|
141
|
+
while (1) switch (_context.n) {
|
|
142
|
+
case 0:
|
|
143
|
+
_context.n = 1;
|
|
144
|
+
return validateWarningAsync(values.input1);
|
|
145
|
+
case 1:
|
|
146
|
+
warning = _context.v;
|
|
147
|
+
if (warning) {
|
|
148
|
+
_context.n = 2;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
return _context.a(2, undefined);
|
|
152
|
+
case 2:
|
|
153
|
+
return _context.a(2, {
|
|
154
|
+
input1: warning
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}, _callee);
|
|
158
|
+
}));
|
|
159
|
+
return function (_x) {
|
|
160
|
+
return _ref3.apply(this, arguments);
|
|
161
|
+
};
|
|
162
|
+
}())
|
|
163
|
+
})
|
|
164
|
+
})]
|
|
165
|
+
});
|
|
166
|
+
},
|
|
167
|
+
name: "Two level validation (warning and error)"
|
|
168
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Card, CardContent, Divider, Typography } from "@mui/material";
|
|
2
|
+
import { Form } from "react-final-form";
|
|
3
|
+
import { FormattedDate } from "react-intl";
|
|
4
|
+
import { Field } from "../../form/Field";
|
|
5
|
+
import { FieldContainer } from "../../form/FieldContainer";
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
export default {
|
|
8
|
+
title: "components/form"
|
|
9
|
+
};
|
|
10
|
+
export var TypographyStaticTextInForm = {
|
|
11
|
+
render: function render() {
|
|
12
|
+
var initialValues = {
|
|
13
|
+
foo: "FooValue",
|
|
14
|
+
bar: "BarValue"
|
|
15
|
+
};
|
|
16
|
+
return /*#__PURE__*/_jsx("div", {
|
|
17
|
+
style: {
|
|
18
|
+
width: "500px"
|
|
19
|
+
},
|
|
20
|
+
children: /*#__PURE__*/_jsx(Form, {
|
|
21
|
+
onSubmit: function onSubmit(values) {
|
|
22
|
+
//
|
|
23
|
+
},
|
|
24
|
+
initialValues: initialValues,
|
|
25
|
+
render: function render(_ref) {
|
|
26
|
+
var handleSubmit = _ref.handleSubmit;
|
|
27
|
+
return /*#__PURE__*/_jsx("form", {
|
|
28
|
+
onSubmit: handleSubmit,
|
|
29
|
+
children: /*#__PURE__*/_jsxs(Card, {
|
|
30
|
+
variant: "outlined",
|
|
31
|
+
children: [/*#__PURE__*/_jsxs(CardContent, {
|
|
32
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
|
33
|
+
children: "Render field value as static text (using MUI Typography)"
|
|
34
|
+
}), /*#__PURE__*/_jsx(Field, {
|
|
35
|
+
name: "foo",
|
|
36
|
+
label: "Foo",
|
|
37
|
+
children: function children(fieldRenderProps) {
|
|
38
|
+
return /*#__PURE__*/_jsx(Typography, {
|
|
39
|
+
children: fieldRenderProps.input.value
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
})]
|
|
43
|
+
}), /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsxs(CardContent, {
|
|
44
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
|
45
|
+
children: "Or, simpler, if the value isn't part of the form (doesn't change), render it without final-form:"
|
|
46
|
+
}), /*#__PURE__*/_jsx(FieldContainer, {
|
|
47
|
+
label: "Bar",
|
|
48
|
+
children: /*#__PURE__*/_jsx(Typography, {
|
|
49
|
+
children: initialValues.bar
|
|
50
|
+
})
|
|
51
|
+
})]
|
|
52
|
+
}), /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsxs(CardContent, {
|
|
53
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
|
54
|
+
children: "Of course you can use any formatting:"
|
|
55
|
+
}), /*#__PURE__*/_jsx(FieldContainer, {
|
|
56
|
+
label: "Today",
|
|
57
|
+
children: /*#__PURE__*/_jsx(Typography, {
|
|
58
|
+
children: /*#__PURE__*/_jsx(FormattedDate, {
|
|
59
|
+
value: new Date()
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
})]
|
|
63
|
+
})]
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
name: "Typography Static Text in Form"
|
|
71
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
4
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
6
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
7
|
+
import { Card, CardContent, Stack } from "@mui/material";
|
|
8
|
+
import { useState } from "react";
|
|
9
|
+
import { FileDropzone } from "../../../form/file/FileDropzone";
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
export default {
|
|
12
|
+
title: "components/form/File",
|
|
13
|
+
decorators: [function (story) {
|
|
14
|
+
return /*#__PURE__*/_jsx(Card, {
|
|
15
|
+
sx: {
|
|
16
|
+
maxWidth: 440
|
|
17
|
+
},
|
|
18
|
+
children: /*#__PURE__*/_jsx(CardContent, {
|
|
19
|
+
children: /*#__PURE__*/_jsx(Stack, {
|
|
20
|
+
spacing: 4,
|
|
21
|
+
children: story()
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
}],
|
|
26
|
+
args: {
|
|
27
|
+
disabled: false,
|
|
28
|
+
multiple: false,
|
|
29
|
+
hasError: false
|
|
30
|
+
},
|
|
31
|
+
argTypes: {
|
|
32
|
+
disabled: {
|
|
33
|
+
name: "Disabled",
|
|
34
|
+
control: "boolean"
|
|
35
|
+
},
|
|
36
|
+
multiple: {
|
|
37
|
+
name: "Multiple",
|
|
38
|
+
control: "boolean"
|
|
39
|
+
},
|
|
40
|
+
hasError: {
|
|
41
|
+
name: "Has errors",
|
|
42
|
+
control: "boolean"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export var _FileDropzone = {
|
|
47
|
+
render: function render(_ref) {
|
|
48
|
+
var disabled = _ref.disabled,
|
|
49
|
+
multiple = _ref.multiple,
|
|
50
|
+
hasError = _ref.hasError;
|
|
51
|
+
var _useState = useState([]),
|
|
52
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
53
|
+
files = _useState2[0],
|
|
54
|
+
setFiles = _useState2[1];
|
|
55
|
+
var _useState3 = useState([]),
|
|
56
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
57
|
+
rejectedFiles = _useState4[0],
|
|
58
|
+
setRejectedFiles = _useState4[1];
|
|
59
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
60
|
+
children: [/*#__PURE__*/_jsx(FileDropzone, {
|
|
61
|
+
disabled: disabled,
|
|
62
|
+
multiple: multiple,
|
|
63
|
+
hasError: hasError,
|
|
64
|
+
onDrop: function onDrop(files) {
|
|
65
|
+
setFiles(files);
|
|
66
|
+
setRejectedFiles([]);
|
|
67
|
+
},
|
|
68
|
+
onDropRejected: function onDropRejected(rejectedFiles) {
|
|
69
|
+
setFiles([]);
|
|
70
|
+
setRejectedFiles(rejectedFiles);
|
|
71
|
+
}
|
|
72
|
+
}), /*#__PURE__*/_jsx("pre", {
|
|
73
|
+
children: JSON.stringify({
|
|
74
|
+
files: files,
|
|
75
|
+
rejectedFiles: rejectedFiles
|
|
76
|
+
}, null, 2)
|
|
77
|
+
})]
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
name: "FileDropzone"
|
|
81
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Card, CardContent, Stack } from "@mui/material";
|
|
2
|
+
import { FileSelect } from "../../../form/file/FileSelect";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
export default {
|
|
5
|
+
title: "components/form/File",
|
|
6
|
+
decorators: [function (story, context) {
|
|
7
|
+
return /*#__PURE__*/_jsx(Card, {
|
|
8
|
+
sx: {
|
|
9
|
+
maxWidth: context.args.layout === "grid" ? 960 : 440
|
|
10
|
+
},
|
|
11
|
+
children: /*#__PURE__*/_jsx(CardContent, {
|
|
12
|
+
children: /*#__PURE__*/_jsx(Stack, {
|
|
13
|
+
spacing: 4,
|
|
14
|
+
children: story()
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
});
|
|
18
|
+
}],
|
|
19
|
+
args: {
|
|
20
|
+
layout: "list",
|
|
21
|
+
disabled: false,
|
|
22
|
+
readOnly: false,
|
|
23
|
+
multiple: false,
|
|
24
|
+
hasError: false,
|
|
25
|
+
hasMaxFileSize: false,
|
|
26
|
+
hasMaxFiles: false,
|
|
27
|
+
onlyAllowImages: false,
|
|
28
|
+
filesSelection: "No files"
|
|
29
|
+
},
|
|
30
|
+
argTypes: {
|
|
31
|
+
layout: {
|
|
32
|
+
name: "Layout",
|
|
33
|
+
control: "select",
|
|
34
|
+
options: ["list", "grid"]
|
|
35
|
+
},
|
|
36
|
+
disabled: {
|
|
37
|
+
name: "Disabled",
|
|
38
|
+
control: "boolean"
|
|
39
|
+
},
|
|
40
|
+
readOnly: {
|
|
41
|
+
name: "Readonly",
|
|
42
|
+
control: "boolean"
|
|
43
|
+
},
|
|
44
|
+
multiple: {
|
|
45
|
+
name: "Multiple",
|
|
46
|
+
control: "boolean"
|
|
47
|
+
},
|
|
48
|
+
hasError: {
|
|
49
|
+
name: "Has Error",
|
|
50
|
+
control: "boolean"
|
|
51
|
+
},
|
|
52
|
+
hasMaxFileSize: {
|
|
53
|
+
name: "Limit file size (5 MB)",
|
|
54
|
+
control: "boolean"
|
|
55
|
+
},
|
|
56
|
+
hasMaxFiles: {
|
|
57
|
+
name: "Max number of files (4)",
|
|
58
|
+
control: "boolean"
|
|
59
|
+
},
|
|
60
|
+
onlyAllowImages: {
|
|
61
|
+
name: "Only allow images",
|
|
62
|
+
control: "boolean"
|
|
63
|
+
},
|
|
64
|
+
filesSelection: {
|
|
65
|
+
name: "Existing files",
|
|
66
|
+
control: "select",
|
|
67
|
+
options: ["No files", "One valid file", "Three valid files", "Four files (one too large)", "Four files (one uploading)"]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
export var _FileSelect = {
|
|
72
|
+
render: function render(_ref) {
|
|
73
|
+
var layout = _ref.layout,
|
|
74
|
+
disabled = _ref.disabled,
|
|
75
|
+
readOnly = _ref.readOnly,
|
|
76
|
+
multiple = _ref.multiple,
|
|
77
|
+
hasError = _ref.hasError,
|
|
78
|
+
hasMaxFileSize = _ref.hasMaxFileSize,
|
|
79
|
+
hasMaxFiles = _ref.hasMaxFiles,
|
|
80
|
+
onlyAllowImages = _ref.onlyAllowImages,
|
|
81
|
+
filesSelection = _ref.filesSelection;
|
|
82
|
+
console.log(layout);
|
|
83
|
+
var exampleFiles = {
|
|
84
|
+
"fileName.xyz": {
|
|
85
|
+
name: "Filename.xyz",
|
|
86
|
+
size: 4.3 * 1024 * 1024 // 4.3 MB
|
|
87
|
+
},
|
|
88
|
+
"anotherFile.png": {
|
|
89
|
+
name: "Another file.png",
|
|
90
|
+
size: 568 * 1024 // 568 KB
|
|
91
|
+
},
|
|
92
|
+
"fileNumberThree.jpg": {
|
|
93
|
+
name: "File number three.jpg",
|
|
94
|
+
size: 1.8 * 1024 * 1024 // 1.8 MB
|
|
95
|
+
},
|
|
96
|
+
"fileUploading.jpg": {
|
|
97
|
+
name: "File that is uploading.jpg",
|
|
98
|
+
loading: true
|
|
99
|
+
},
|
|
100
|
+
"fileTooLarge.png": {
|
|
101
|
+
name: "Failed to upload.png",
|
|
102
|
+
size: 200 * 1024 * 1024,
|
|
103
|
+
// 200 MB
|
|
104
|
+
error: "The file is too large"
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
var filesMapping = {
|
|
108
|
+
"No files": [],
|
|
109
|
+
"One valid file": [exampleFiles["fileName.xyz"]],
|
|
110
|
+
"Three valid files": [exampleFiles["fileName.xyz"], exampleFiles["anotherFile.png"], exampleFiles["fileNumberThree.jpg"]],
|
|
111
|
+
"Four files (one too large)": [exampleFiles["fileName.xyz"], exampleFiles["anotherFile.png"], exampleFiles["fileNumberThree.jpg"], exampleFiles["fileTooLarge.png"]],
|
|
112
|
+
"Four files (one uploading)": [exampleFiles["fileName.xyz"], exampleFiles["anotherFile.png"], exampleFiles["fileNumberThree.jpg"], exampleFiles["fileUploading.jpg"]]
|
|
113
|
+
};
|
|
114
|
+
return /*#__PURE__*/_jsx(FileSelect, {
|
|
115
|
+
onDrop: function onDrop(acceptedFiles, rejectedFiles) {
|
|
116
|
+
console.log(acceptedFiles, rejectedFiles);
|
|
117
|
+
},
|
|
118
|
+
onRemove: function onRemove() {
|
|
119
|
+
console.log("Removing file");
|
|
120
|
+
},
|
|
121
|
+
onDownload: function onDownload() {
|
|
122
|
+
console.log("Downloading file");
|
|
123
|
+
},
|
|
124
|
+
layout: layout,
|
|
125
|
+
files: filesMapping[filesSelection],
|
|
126
|
+
disabled: disabled,
|
|
127
|
+
readOnly: readOnly,
|
|
128
|
+
multiple: multiple,
|
|
129
|
+
maxFileSize: hasMaxFileSize ? 5 * 1024 * 1024 // 5 MB
|
|
130
|
+
: undefined,
|
|
131
|
+
maxFiles: hasMaxFiles ? 4 : undefined,
|
|
132
|
+
error: hasError ? "An error occurred" : undefined,
|
|
133
|
+
accept: onlyAllowImages ? {
|
|
134
|
+
"image/*": []
|
|
135
|
+
} : undefined
|
|
136
|
+
});
|
|
137
|
+
},
|
|
138
|
+
name: "FileSelect"
|
|
139
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { Card, CardContent, Stack } from "@mui/material";
|
|
2
|
+
import { FileSelectListItem } from "../../../form/file/FileSelectListItem";
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
var fileSize = 1.8 * 1024 * 1024; // 1.8 MB
|
|
5
|
+
|
|
6
|
+
var fileItems = {
|
|
7
|
+
"Valid File": {
|
|
8
|
+
name: "Filename.xyz",
|
|
9
|
+
size: fileSize
|
|
10
|
+
},
|
|
11
|
+
"Long File Name": {
|
|
12
|
+
name: "This is a really long file name that should cause the text to be truncated and show a tooltip.png",
|
|
13
|
+
size: fileSize
|
|
14
|
+
},
|
|
15
|
+
Loading: {
|
|
16
|
+
name: "Filename.xyz",
|
|
17
|
+
loading: true
|
|
18
|
+
},
|
|
19
|
+
"Error (no details)": {
|
|
20
|
+
name: "Filename.xyz",
|
|
21
|
+
error: true
|
|
22
|
+
},
|
|
23
|
+
"Error (with details)": {
|
|
24
|
+
name: "Filename.xyz",
|
|
25
|
+
error: "File too large"
|
|
26
|
+
},
|
|
27
|
+
Skeleton: {
|
|
28
|
+
loading: true
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var filePreviewOptions = {
|
|
32
|
+
None: undefined,
|
|
33
|
+
"Generic Preview": true,
|
|
34
|
+
"Image Preview": "https://picsum.photos/756/756"
|
|
35
|
+
};
|
|
36
|
+
var downloadMethods = ["No download", "Download function", "Download URL"];
|
|
37
|
+
export default {
|
|
38
|
+
title: "components/form/File",
|
|
39
|
+
decorators: [function (story) {
|
|
40
|
+
return /*#__PURE__*/_jsx(Card, {
|
|
41
|
+
sx: {
|
|
42
|
+
maxWidth: 300
|
|
43
|
+
},
|
|
44
|
+
children: /*#__PURE__*/_jsx(CardContent, {
|
|
45
|
+
children: /*#__PURE__*/_jsx(Stack, {
|
|
46
|
+
spacing: 4,
|
|
47
|
+
children: story()
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
});
|
|
51
|
+
}],
|
|
52
|
+
args: {
|
|
53
|
+
selectedFile: fileItems["Valid File"],
|
|
54
|
+
showFilePreview: filePreviewOptions["None"],
|
|
55
|
+
downloadMethod: downloadMethods[0],
|
|
56
|
+
canBeDeleted: true,
|
|
57
|
+
disabled: false
|
|
58
|
+
},
|
|
59
|
+
argTypes: {
|
|
60
|
+
selectedFile: {
|
|
61
|
+
name: "File Item",
|
|
62
|
+
control: "select",
|
|
63
|
+
options: Object.keys(fileItems),
|
|
64
|
+
mapping: fileItems
|
|
65
|
+
},
|
|
66
|
+
showFilePreview: {
|
|
67
|
+
name: "Field Preview",
|
|
68
|
+
control: "select",
|
|
69
|
+
options: Object.keys(filePreviewOptions),
|
|
70
|
+
mapping: filePreviewOptions
|
|
71
|
+
},
|
|
72
|
+
downloadMethod: {
|
|
73
|
+
name: "Can be downloaded",
|
|
74
|
+
control: "select",
|
|
75
|
+
options: downloadMethods
|
|
76
|
+
},
|
|
77
|
+
canBeDeleted: {
|
|
78
|
+
name: "Can Be Deleted",
|
|
79
|
+
control: "boolean"
|
|
80
|
+
},
|
|
81
|
+
disabled: {
|
|
82
|
+
name: "Disabled",
|
|
83
|
+
control: "boolean"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
export var _FileSelectListItem = {
|
|
88
|
+
render: function render(_ref) {
|
|
89
|
+
var selectedFile = _ref.selectedFile,
|
|
90
|
+
showFilePreview = _ref.showFilePreview,
|
|
91
|
+
downloadMethod = _ref.downloadMethod,
|
|
92
|
+
canBeDeleted = _ref.canBeDeleted,
|
|
93
|
+
disabled = _ref.disabled;
|
|
94
|
+
return /*#__PURE__*/_jsx(FileSelectListItem, {
|
|
95
|
+
file: selectedFile,
|
|
96
|
+
onClickDownload: downloadMethod === "Download function" ? function () {
|
|
97
|
+
return alert("Downloading file");
|
|
98
|
+
} : undefined,
|
|
99
|
+
downloadUrl: downloadMethod === "Download URL" ? "https://example.com" : undefined,
|
|
100
|
+
onClickDelete: canBeDeleted ? function () {
|
|
101
|
+
return alert("Delete");
|
|
102
|
+
} : undefined,
|
|
103
|
+
filePreview: showFilePreview,
|
|
104
|
+
disabled: disabled
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
name: "FileSelectListItem"
|
|
108
|
+
};
|