@plusscommunities/pluss-core-web 1.6.8 → 1.6.9
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/index.cjs.js +104 -104
- package/dist/index.esm.js +104 -104
- package/dist/index.umd.js +104 -104
- package/package.json +47 -47
- package/src/components/AudienceSelector.js +149 -101
- package/src/components/FileInput.js +94 -44
- package/src/components/ImageInput.js +3 -4
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React, { Component } from
|
|
2
|
-
import { connect } from
|
|
3
|
-
import _ from
|
|
4
|
-
import Dropzone from
|
|
5
|
-
import FontAwesome from
|
|
6
|
-
import { Button } from
|
|
7
|
-
import { fileActions } from
|
|
8
|
-
import { getFileName } from
|
|
1
|
+
import React, { Component } from "react";
|
|
2
|
+
import { connect } from "react-redux";
|
|
3
|
+
import _ from "lodash";
|
|
4
|
+
import Dropzone from "react-dropzone";
|
|
5
|
+
import FontAwesome from "react-fontawesome";
|
|
6
|
+
import { Button } from "./Button";
|
|
7
|
+
import { fileActions } from "../apis";
|
|
8
|
+
import { getFileName } from "../helper";
|
|
9
9
|
|
|
10
10
|
const DEFAULT_INPUT = {
|
|
11
11
|
uploadingFile: false,
|
|
12
|
-
value:
|
|
12
|
+
value: "",
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
class FileInputComponent extends Component {
|
|
@@ -17,7 +17,7 @@ class FileInputComponent extends Component {
|
|
|
17
17
|
inputs: [
|
|
18
18
|
{
|
|
19
19
|
uploadingFile: false,
|
|
20
|
-
value:
|
|
20
|
+
value: "",
|
|
21
21
|
},
|
|
22
22
|
],
|
|
23
23
|
};
|
|
@@ -41,7 +41,7 @@ class FileInputComponent extends Component {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
setValue(val) {
|
|
44
|
-
if (typeof val ===
|
|
44
|
+
if (typeof val === "string") {
|
|
45
45
|
this.setState({
|
|
46
46
|
inputs: [
|
|
47
47
|
{
|
|
@@ -58,41 +58,46 @@ class FileInputComponent extends Component {
|
|
|
58
58
|
value: str,
|
|
59
59
|
});
|
|
60
60
|
});
|
|
61
|
-
if (!this.props.limit || this.props.limit > inputs.length)
|
|
61
|
+
if (!this.props.limit || this.props.limit > inputs.length)
|
|
62
|
+
inputs.push(DEFAULT_INPUT);
|
|
62
63
|
this.setState({ inputs });
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
getClassNames(input, inputsLength) {
|
|
67
|
-
let classes =
|
|
68
|
+
let classes = "clearfix imageInput";
|
|
68
69
|
if (input.uploadingFile) {
|
|
69
|
-
classes +=
|
|
70
|
+
classes += " imageInput-uploading";
|
|
70
71
|
} else if (!_.isEmpty(input.value) && !this.props.onlyAllowUpload) {
|
|
71
|
-
classes +=
|
|
72
|
+
classes += " imageInput-hasImage";
|
|
72
73
|
}
|
|
73
74
|
if (inputsLength === 1) {
|
|
74
|
-
classes +=
|
|
75
|
+
classes += " imageInput-only";
|
|
75
76
|
}
|
|
76
|
-
if (
|
|
77
|
-
|
|
77
|
+
if (
|
|
78
|
+
this.props.style &&
|
|
79
|
+
this.props.style.height &&
|
|
80
|
+
this.props.style.height < 150
|
|
81
|
+
) {
|
|
82
|
+
classes += " imageInput-condensed";
|
|
78
83
|
}
|
|
79
84
|
return classes;
|
|
80
85
|
}
|
|
81
86
|
|
|
82
87
|
getErrorState() {
|
|
83
88
|
if (!_.isUndefined(this.props.showError) && this.props.showError()) {
|
|
84
|
-
return
|
|
89
|
+
return " imageInput_upload--error";
|
|
85
90
|
}
|
|
86
|
-
return
|
|
91
|
+
return "";
|
|
87
92
|
}
|
|
88
93
|
|
|
89
94
|
getAccept = () => {
|
|
90
|
-
if (typeof this.props.accept ===
|
|
95
|
+
if (typeof this.props.accept === "object") {
|
|
91
96
|
return this.props.accept;
|
|
92
97
|
}
|
|
93
|
-
if (typeof this.props.accept ===
|
|
98
|
+
if (typeof this.props.accept === "string") {
|
|
94
99
|
const accept = {
|
|
95
|
-
[this.props.accept]: [`.${_.last(this.props.accept.split(
|
|
100
|
+
[this.props.accept]: [`.${_.last(this.props.accept.split("/"))}`],
|
|
96
101
|
};
|
|
97
102
|
return accept;
|
|
98
103
|
}
|
|
@@ -165,14 +170,17 @@ class FileInputComponent extends Component {
|
|
|
165
170
|
this.checkRefreshCallback(newInputs);
|
|
166
171
|
if (this.props.handleFile) {
|
|
167
172
|
await this.props.handleFile(file, newInputs);
|
|
168
|
-
this.checkSetDisplayValue(input,
|
|
173
|
+
this.checkSetDisplayValue(input, "");
|
|
169
174
|
} else {
|
|
170
175
|
try {
|
|
171
176
|
let uploadFile = file;
|
|
172
|
-
const url = await fileActions.uploadMediaAsync(
|
|
177
|
+
const url = await fileActions.uploadMediaAsync(
|
|
178
|
+
uploadFile,
|
|
179
|
+
uploadFile.name,
|
|
180
|
+
);
|
|
173
181
|
this.checkSetDisplayValue(input, url);
|
|
174
182
|
} catch (error) {
|
|
175
|
-
console.log(
|
|
183
|
+
console.log("handleFile error", error);
|
|
176
184
|
this.setState({ uploadingFile: false });
|
|
177
185
|
}
|
|
178
186
|
}
|
|
@@ -181,13 +189,16 @@ class FileInputComponent extends Component {
|
|
|
181
189
|
removeFile(input) {
|
|
182
190
|
const newState = {};
|
|
183
191
|
|
|
184
|
-
input.value =
|
|
192
|
+
input.value = "";
|
|
185
193
|
|
|
186
194
|
const newInputs = _.clone(this.state.inputs);
|
|
187
195
|
|
|
188
196
|
if (newInputs.length > 1) {
|
|
189
197
|
newInputs.splice(newInputs.indexOf(input), 1);
|
|
190
|
-
if (
|
|
198
|
+
if (
|
|
199
|
+
newInputs.length === this.props.limit - 1 &&
|
|
200
|
+
!_.isEmpty(newInputs[newInputs.length - 1].value)
|
|
201
|
+
) {
|
|
191
202
|
// was full
|
|
192
203
|
newInputs.push(DEFAULT_INPUT);
|
|
193
204
|
}
|
|
@@ -214,7 +225,10 @@ class FileInputComponent extends Component {
|
|
|
214
225
|
className="imageInput_image"
|
|
215
226
|
style={{
|
|
216
227
|
...this.props.style,
|
|
217
|
-
height:
|
|
228
|
+
height:
|
|
229
|
+
this.props.style && this.props.style.height
|
|
230
|
+
? this.props.style.height - 62
|
|
231
|
+
: 80,
|
|
218
232
|
}}
|
|
219
233
|
>
|
|
220
234
|
<img
|
|
@@ -224,13 +238,20 @@ class FileInputComponent extends Component {
|
|
|
224
238
|
/>
|
|
225
239
|
<p className="imageInput_text">{getFileName(input.value)}</p>
|
|
226
240
|
</div>
|
|
227
|
-
<Dropzone
|
|
241
|
+
<Dropzone
|
|
242
|
+
accept={this.getAccept()}
|
|
243
|
+
onDrop={(files) => this.onDrop(files, true)}
|
|
244
|
+
>
|
|
228
245
|
{(state) => {
|
|
229
246
|
const { getRootProps, getInputProps } = state;
|
|
230
247
|
return (
|
|
231
248
|
<div style={{ padding: 10 }} {...getRootProps()}>
|
|
232
249
|
<input {...getInputProps()} />
|
|
233
|
-
<Button
|
|
250
|
+
<Button
|
|
251
|
+
buttonType="secondary"
|
|
252
|
+
className="imageInput_button"
|
|
253
|
+
disabled
|
|
254
|
+
>
|
|
234
255
|
Change file
|
|
235
256
|
</Button>
|
|
236
257
|
</div>
|
|
@@ -240,7 +261,9 @@ class FileInputComponent extends Component {
|
|
|
240
261
|
</div>
|
|
241
262
|
);
|
|
242
263
|
}
|
|
243
|
-
return
|
|
264
|
+
return (
|
|
265
|
+
<div className="imageInput_image" style={{ ...this.props.style }}></div>
|
|
266
|
+
);
|
|
244
267
|
};
|
|
245
268
|
|
|
246
269
|
const renderRemove = () => {
|
|
@@ -248,9 +271,16 @@ class FileInputComponent extends Component {
|
|
|
248
271
|
!this.props.disableRemove &&
|
|
249
272
|
!this.props.disabled &&
|
|
250
273
|
(this.props.simpleStyle ? (
|
|
251
|
-
<FontAwesome
|
|
274
|
+
<FontAwesome
|
|
275
|
+
name="remove"
|
|
276
|
+
className="imageInput_removeIcon"
|
|
277
|
+
onClick={this.removeFile.bind(this, input)}
|
|
278
|
+
/>
|
|
252
279
|
) : (
|
|
253
|
-
<p
|
|
280
|
+
<p
|
|
281
|
+
className="imageInput_remove"
|
|
282
|
+
onClick={this.removeFile.bind(this, input)}
|
|
283
|
+
>
|
|
254
284
|
remove
|
|
255
285
|
</p>
|
|
256
286
|
))
|
|
@@ -271,14 +301,24 @@ class FileInputComponent extends Component {
|
|
|
271
301
|
};
|
|
272
302
|
|
|
273
303
|
return (
|
|
274
|
-
<div
|
|
304
|
+
<div
|
|
305
|
+
key={index}
|
|
306
|
+
className={this.getClassNames(input, inputsLength)}
|
|
307
|
+
style={{ ...this.props.style }}
|
|
308
|
+
>
|
|
275
309
|
<Dropzone accept={this.getAccept()} onDrop={this.onDrop}>
|
|
276
310
|
{(state) => {
|
|
277
311
|
const { getRootProps, getInputProps, isDragActive } = state;
|
|
278
312
|
return (
|
|
279
|
-
<div
|
|
313
|
+
<div
|
|
314
|
+
className={`imageInput_upload ${this.getErrorState()}`}
|
|
315
|
+
style={{ ...this.props.style }}
|
|
316
|
+
{...getRootProps()}
|
|
317
|
+
>
|
|
280
318
|
<input {...getInputProps()} />
|
|
281
|
-
<div
|
|
319
|
+
<div
|
|
320
|
+
className={`${isDragActive ? "imageInput_dropZoneActive" : ""}`}
|
|
321
|
+
>
|
|
282
322
|
{!this.props.simpleStyle && (
|
|
283
323
|
<img
|
|
284
324
|
src="https://s3-ap-southeast-2.amazonaws.com/pluss60-dev-media/pluss/document.svg"
|
|
@@ -286,9 +326,15 @@ class FileInputComponent extends Component {
|
|
|
286
326
|
alt="file"
|
|
287
327
|
/>
|
|
288
328
|
)}
|
|
289
|
-
<p className="imageInput_helpText">
|
|
329
|
+
<p className="imageInput_helpText">
|
|
330
|
+
{isDragActive ? `Drop file here` : `Drag and drop file or`}
|
|
331
|
+
</p>
|
|
290
332
|
{!isDragActive && (
|
|
291
|
-
<Button
|
|
333
|
+
<Button
|
|
334
|
+
buttonType="secondary"
|
|
335
|
+
className="imageInput_button"
|
|
336
|
+
disabled
|
|
337
|
+
>
|
|
292
338
|
{this.props.multiple ? `Upload files` : `Upload a file`}
|
|
293
339
|
</Button>
|
|
294
340
|
)}
|
|
@@ -298,7 +344,10 @@ class FileInputComponent extends Component {
|
|
|
298
344
|
}}
|
|
299
345
|
</Dropzone>
|
|
300
346
|
<div className="imageInput_uploading" style={{ ...this.props.style }}>
|
|
301
|
-
<FontAwesome
|
|
347
|
+
<FontAwesome
|
|
348
|
+
className="spinner imageInput_spinner"
|
|
349
|
+
name="spinner fa-pulse fa-fw"
|
|
350
|
+
/>
|
|
302
351
|
</div>
|
|
303
352
|
{renderContent()}
|
|
304
353
|
{renderRemove()}
|
|
@@ -310,9 +359,8 @@ class FileInputComponent extends Component {
|
|
|
310
359
|
renderUploadFiles(inputs) {
|
|
311
360
|
return (
|
|
312
361
|
<div
|
|
313
|
-
className={`imageInputContainer clearfix ${inputs.length === 1 ?
|
|
314
|
-
|
|
315
|
-
}`}
|
|
362
|
+
className={`imageInputContainer clearfix ${inputs.length === 1 ? "imageInputContainer-noPadding" : ""} ${this.props.simpleStyle ? "imageInputContainer-simple" : ""
|
|
363
|
+
}`}
|
|
316
364
|
style={{ ...this.props.style }}
|
|
317
365
|
>
|
|
318
366
|
{inputs.map((input, index) => {
|
|
@@ -335,5 +383,7 @@ const mapStateToProps = () => {
|
|
|
335
383
|
return {};
|
|
336
384
|
};
|
|
337
385
|
|
|
338
|
-
const FileInput = connect(mapStateToProps, {}, null, {
|
|
386
|
+
const FileInput = connect(mapStateToProps, {}, null, { forwardRef: true })(
|
|
387
|
+
FileInputComponent,
|
|
388
|
+
);
|
|
339
389
|
export { FileInput };
|
|
@@ -593,9 +593,8 @@ class ImageInputComponent extends Component {
|
|
|
593
593
|
<div style={{ ...this.props.style }} className={`imageInput_upload ${this.getErrorState()}`} {...getRootProps()}>
|
|
594
594
|
<input {...getInputProps()} />
|
|
595
595
|
<div
|
|
596
|
-
className={`${isDragActive ? 'imageInput_dropZoneActive' : ''} ${
|
|
597
|
-
|
|
598
|
-
}`}
|
|
596
|
+
className={`${isDragActive ? 'imageInput_dropZoneActive' : ''} ${this.props.horizontalText ? ' imageInput_horizontalText' : ''
|
|
597
|
+
}`}
|
|
599
598
|
>
|
|
600
599
|
{!this.props.simpleStyle && (
|
|
601
600
|
<img
|
|
@@ -984,5 +983,5 @@ const mapStateToProps = (state) => {
|
|
|
984
983
|
};
|
|
985
984
|
};
|
|
986
985
|
|
|
987
|
-
const ImageInput = connect(mapStateToProps, {}, null, {
|
|
986
|
+
const ImageInput = connect(mapStateToProps, {}, null, { forwardRef: true })(ImageInputComponent);
|
|
988
987
|
export { ImageInput };
|