react-input-material 0.0.352 → 0.0.356
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/components/Dummy.d.ts +9 -5
- package/components/Dummy.tsx +11 -6
- package/components/FileInput.d.ts +3 -2
- package/components/FileInput.js +1 -1
- package/components/FileInput.module.css +12 -24
- package/components/FileInput.styles.css +3 -3
- package/components/FileInput.tsx +239 -203
- package/components/GenericAnimate.d.ts +3 -0
- package/components/GenericAnimate.module.css +0 -1
- package/components/GenericAnimate.tsx +17 -10
- package/components/GenericInput.d.ts +26 -2
- package/components/GenericInput.js +1 -1
- package/components/GenericInput.module.css +32 -45
- package/components/GenericInput.styles.css +1 -1
- package/components/GenericInput.tsx +471 -348
- package/components/Inputs.d.ts +3 -3
- package/components/Inputs.js +1 -1
- package/components/Inputs.module.css +10 -9
- package/components/Inputs.styles.css +2 -2
- package/components/Inputs.tsx +20 -21
- package/components/Interval.d.ts +4 -6
- package/components/Interval.js +1 -1
- package/components/Interval.module.css +16 -15
- package/components/Interval.styles.css +2 -2
- package/components/Interval.tsx +7 -13
- package/components/RequireableCheckbox.d.ts +10 -3
- package/components/RequireableCheckbox.js +1 -1
- package/components/RequireableCheckbox.module.css +4 -4
- package/components/RequireableCheckbox.styles.css +1 -1
- package/components/RequireableCheckbox.tsx +66 -51
- package/components/WrapConfigurations.d.ts +13 -0
- package/components/WrapConfigurations.tsx +17 -5
- package/components/WrapStrict.d.ts +6 -0
- package/components/WrapStrict.tsx +7 -0
- package/components/WrapThemeProvider.d.ts +7 -5
- package/components/WrapThemeProvider.tsx +8 -5
- package/components/WrapTooltip.d.ts +4 -2
- package/components/WrapTooltip.tsx +14 -6
- package/helper.d.ts +39 -9
- package/helper.js +1 -1
- package/index.js +1 -1
- package/index.styles.css +10 -10
- package/package.json +36 -28
- package/readme.md +38 -2
- package/type.d.ts +42 -42
package/components/FileInput.tsx
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
// region imports
|
|
20
20
|
import {blobToBase64String, dataURLToBlob} from 'blob-util'
|
|
21
21
|
import Tools from 'clientnode'
|
|
22
|
-
import {FirstParameter} from 'clientnode/type'
|
|
23
22
|
import {
|
|
24
23
|
FocusEvent as ReactFocusEvent,
|
|
25
24
|
ForwardedRef,
|
|
@@ -28,7 +27,6 @@ import {
|
|
|
28
27
|
MouseEvent as ReactMouseEvent,
|
|
29
28
|
MutableRefObject,
|
|
30
29
|
ReactElement,
|
|
31
|
-
RefCallback,
|
|
32
30
|
SyntheticEvent,
|
|
33
31
|
useEffect,
|
|
34
32
|
useImperativeHandle,
|
|
@@ -46,7 +44,6 @@ import {
|
|
|
46
44
|
import {CircularProgress} from '@rmwc/circular-progress'
|
|
47
45
|
import {Theme} from '@rmwc/theme'
|
|
48
46
|
import {Typography} from '@rmwc/typography'
|
|
49
|
-
import {ComponentAdapter} from 'web-component-wrapper/type'
|
|
50
47
|
|
|
51
48
|
/*
|
|
52
49
|
"namedExport" version of css-loader:
|
|
@@ -78,11 +75,9 @@ import {
|
|
|
78
75
|
defaultFileInputProperties as defaultProperties,
|
|
79
76
|
defaultFileNameInputProperties,
|
|
80
77
|
FileInputAdapter as Adapter,
|
|
81
|
-
FileInputModel as Model,
|
|
82
78
|
FileInputModelState as ModelState,
|
|
83
79
|
FileInputProperties as Properties,
|
|
84
80
|
FileInputProps as Props,
|
|
85
|
-
FileInputState as State,
|
|
86
81
|
FileValue,
|
|
87
82
|
FileInputValueState as ValueState,
|
|
88
83
|
fileInputPropertyTypes as propertyTypes,
|
|
@@ -94,27 +89,36 @@ import {
|
|
|
94
89
|
} from '../type'
|
|
95
90
|
// endregion
|
|
96
91
|
// region constants
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
92
|
+
/*
|
|
93
|
+
NOTE: Caused by a bug transpiling regular expression which ignores needed
|
|
94
|
+
escape sequences for "/" when using the nativ regular expression type.
|
|
95
|
+
*/
|
|
96
|
+
const imageContentTypeRegularExpression = new RegExp(
|
|
97
|
+
'^image\\/(?:p?jpe?g|png|svg(?:\\+xml)?|vnd\\.microsoft\\.icon|gif|tiff|' +
|
|
98
|
+
'webp|vnd\\.wap\\.wbmp|x-(?:icon|jng|ms-bmp))$',
|
|
99
|
+
'i'
|
|
100
100
|
)
|
|
101
|
-
const textContentTypeRegularExpression
|
|
102
|
-
'^(?:application
|
|
103
|
-
'
|
|
101
|
+
const textContentTypeRegularExpression = new RegExp(
|
|
102
|
+
'^(?:application\\/xml)|(?:text\\/(?:plain|x-ndpb[wy]html|(?:x-)?csv' +
|
|
103
|
+
'|x?html?|xml))$',
|
|
104
|
+
'i'
|
|
104
105
|
)
|
|
105
|
-
const representableTextContentTypeRegularExpression
|
|
106
|
+
const representableTextContentTypeRegularExpression =
|
|
106
107
|
// Plain version:
|
|
107
|
-
/^text\/plain$/
|
|
108
|
+
/^text\/plain$/i
|
|
108
109
|
// Rendered version:
|
|
109
|
-
//
|
|
110
|
-
const videoContentTypeRegularExpression
|
|
111
|
-
'^video
|
|
112
|
-
'
|
|
113
|
-
'(?:application
|
|
110
|
+
// /^(application\/xml)|(text\/(plain|x?html?|xml))$/i
|
|
111
|
+
const videoContentTypeRegularExpression = new RegExp(
|
|
112
|
+
'^video\\/(?:(?:x-)?(?:x-)?webm|3gpp|mp2t|mp4|mpeg|quicktime|(?:x-)?flv' +
|
|
113
|
+
'|(?:x-)?m4v|(?:x-)mng|x-ms-as|x-ms-wmv|x-msvideo)' +
|
|
114
|
+
'|(?:application\\/(?:x-)?shockwave-flash)$',
|
|
115
|
+
'i'
|
|
114
116
|
)
|
|
115
117
|
// endregion
|
|
116
118
|
// region helper
|
|
117
|
-
export const preserveStaticFileBaseNameInputGenerator:Properties[
|
|
119
|
+
export const preserveStaticFileBaseNameInputGenerator:Properties[
|
|
120
|
+
'generateFileNameInputProperties'
|
|
121
|
+
] = (
|
|
118
122
|
prototype:InputProps<string>, {name, value: {name: fileName}}
|
|
119
123
|
):InputProps<string> => ({
|
|
120
124
|
...prototype,
|
|
@@ -200,9 +204,11 @@ export const determineValidationState = <P extends DefaultProperties>(
|
|
|
200
204
|
}
|
|
201
205
|
)
|
|
202
206
|
export const readBinaryDataIntoText = (
|
|
203
|
-
blob:Blob, encoding
|
|
207
|
+
blob:Blob, encoding = 'utf-8'
|
|
204
208
|
):Promise<string> =>
|
|
205
|
-
new Promise<string>((
|
|
209
|
+
new Promise<string>((
|
|
210
|
+
resolve:(_value:string) => void, reject:(_reason:Error) => void
|
|
211
|
+
):void => {
|
|
206
212
|
const fileReader:FileReader = new FileReader()
|
|
207
213
|
|
|
208
214
|
fileReader.onload = (event:Event):void => {
|
|
@@ -220,8 +226,8 @@ export const readBinaryDataIntoText = (
|
|
|
220
226
|
resolve(content)
|
|
221
227
|
}
|
|
222
228
|
|
|
223
|
-
fileReader.onabort = ():void => reject('abort')
|
|
224
|
-
fileReader.onerror = ():void => reject(
|
|
229
|
+
fileReader.onabort = ():void => reject(new Error('abort'))
|
|
230
|
+
fileReader.onerror = ():void => reject(new Error())
|
|
225
231
|
|
|
226
232
|
fileReader.readAsText(
|
|
227
233
|
blob,
|
|
@@ -233,7 +239,6 @@ export const readBinaryDataIntoText = (
|
|
|
233
239
|
// endregion
|
|
234
240
|
/**
|
|
235
241
|
* Validateable checkbox wrapper component.
|
|
236
|
-
*
|
|
237
242
|
* @property static:displayName - Descriptive name for component to show in web
|
|
238
243
|
* developer tools.
|
|
239
244
|
*
|
|
@@ -255,6 +260,7 @@ export const readBinaryDataIntoText = (
|
|
|
255
260
|
*
|
|
256
261
|
* @param props - Given components properties.
|
|
257
262
|
* @param reference - Reference object to forward internal state.
|
|
263
|
+
*
|
|
258
264
|
* @returns React elements.
|
|
259
265
|
*/
|
|
260
266
|
export const FileInputInner = function(
|
|
@@ -264,10 +270,11 @@ export const FileInputInner = function(
|
|
|
264
270
|
/**
|
|
265
271
|
* Calculate external properties (a set of all configurable properties).
|
|
266
272
|
* @param properties - Properties to merge.
|
|
273
|
+
*
|
|
267
274
|
* @returns External properties object.
|
|
268
275
|
*/
|
|
269
276
|
const getConsolidatedProperties = (properties:Props):Properties => {
|
|
270
|
-
|
|
277
|
+
const result:DefaultProperties =
|
|
271
278
|
mapPropertiesIntoModel<Props, DefaultProperties>(
|
|
272
279
|
properties, FileInput.defaultProperties.model
|
|
273
280
|
)
|
|
@@ -276,11 +283,13 @@ export const FileInputInner = function(
|
|
|
276
283
|
result,
|
|
277
284
|
// TODO not available
|
|
278
285
|
false
|
|
279
|
-
/*
|
|
286
|
+
/*
|
|
287
|
+
nameInputReference.current?.properties.invalid ??
|
|
280
288
|
result.fileNameInputProperties.invalid ??
|
|
281
289
|
result.model.fileName.invalid ??
|
|
282
|
-
result.model!.state.invalidName
|
|
283
|
-
|
|
290
|
+
result.model!.state.invalidName
|
|
291
|
+
*/,
|
|
292
|
+
result.model.state
|
|
284
293
|
)
|
|
285
294
|
|
|
286
295
|
return getBaseConsolidatedProperties<Props, Properties>(result)
|
|
@@ -290,12 +299,13 @@ export const FileInputInner = function(
|
|
|
290
299
|
/**
|
|
291
300
|
* Triggered on blur events.
|
|
292
301
|
* @param event - Event object.
|
|
302
|
+
*
|
|
293
303
|
* @returns Nothing.
|
|
294
304
|
*/
|
|
295
305
|
const onBlur = (event:SyntheticEvent):void => setValueState((
|
|
296
306
|
oldValueState:ValueState
|
|
297
307
|
):ValueState => {
|
|
298
|
-
let changed
|
|
308
|
+
let changed = false
|
|
299
309
|
|
|
300
310
|
if (oldValueState.modelState.focused) {
|
|
301
311
|
properties.focused = false
|
|
@@ -332,6 +342,7 @@ export const FileInputInner = function(
|
|
|
332
342
|
* Triggered on any change events. Consolidates properties object and
|
|
333
343
|
* triggers given on change callbacks.
|
|
334
344
|
* @param event - Potential event object.
|
|
345
|
+
*
|
|
335
346
|
* @returns Nothing.
|
|
336
347
|
*/
|
|
337
348
|
const onChange = (event?:SyntheticEvent):void => {
|
|
@@ -366,13 +377,14 @@ export const FileInputInner = function(
|
|
|
366
377
|
* @param inputProperties - Current properties state.
|
|
367
378
|
* @param attachBlobProperty - Indicates whether additional data is added
|
|
368
379
|
* through post processed data properties.
|
|
380
|
+
*
|
|
369
381
|
* @returns Nothing.
|
|
370
382
|
*/
|
|
371
383
|
const onChangeValue = (
|
|
372
384
|
eventSourceOrName:FileValue|null|string|SyntheticEvent,
|
|
373
385
|
event?:SyntheticEvent|undefined,
|
|
374
386
|
inputProperties?:InputProperties<string>|undefined,
|
|
375
|
-
attachBlobProperty
|
|
387
|
+
attachBlobProperty = false
|
|
376
388
|
):void => {
|
|
377
389
|
if (!(properties.model.mutable && properties.model.writable))
|
|
378
390
|
return
|
|
@@ -418,7 +430,7 @@ export const FileInputInner = function(
|
|
|
418
430
|
if (Tools.equals(oldValueState.value, properties.value))
|
|
419
431
|
return oldValueState
|
|
420
432
|
|
|
421
|
-
let stateChanged
|
|
433
|
+
let stateChanged = false
|
|
422
434
|
|
|
423
435
|
const result:ValueState = {
|
|
424
436
|
...oldValueState, value: properties.value as FileValue|null
|
|
@@ -471,6 +483,7 @@ export const FileInputInner = function(
|
|
|
471
483
|
/**
|
|
472
484
|
* Triggered on click events.
|
|
473
485
|
* @param event - Mouse event object.
|
|
486
|
+
*
|
|
474
487
|
* @returns Nothing.
|
|
475
488
|
*/
|
|
476
489
|
const onClick = (event:ReactMouseEvent):void => {
|
|
@@ -483,6 +496,7 @@ export const FileInputInner = function(
|
|
|
483
496
|
/**
|
|
484
497
|
* Triggered on focus events.
|
|
485
498
|
* @param event - Focus event object.
|
|
499
|
+
*
|
|
486
500
|
* @returns Nothing.
|
|
487
501
|
*/
|
|
488
502
|
const onFocus = (event:ReactFocusEvent):void => {
|
|
@@ -495,11 +509,12 @@ export const FileInputInner = function(
|
|
|
495
509
|
/**
|
|
496
510
|
* Triggers on start interacting with the input.
|
|
497
511
|
* @param event - Event object which triggered interaction.
|
|
512
|
+
*
|
|
498
513
|
* @returns Nothing.
|
|
499
514
|
*/
|
|
500
515
|
const onTouch = (event:ReactFocusEvent|ReactMouseEvent):void =>
|
|
501
516
|
setValueState((oldValueState:ValueState):ValueState => {
|
|
502
|
-
let changedState
|
|
517
|
+
let changedState = false
|
|
503
518
|
|
|
504
519
|
if (!oldValueState.modelState.focused) {
|
|
505
520
|
properties.focused = true
|
|
@@ -552,7 +567,7 @@ export const FileInputInner = function(
|
|
|
552
567
|
const givenProps:Props = translateKnownSymbols(props)
|
|
553
568
|
|
|
554
569
|
const initialValue:FileValue|null = determineInitialValue<FileValue>(
|
|
555
|
-
givenProps, FileInput.defaultProperties.model
|
|
570
|
+
givenProps, FileInput.defaultProperties.model.default
|
|
556
571
|
)
|
|
557
572
|
/*
|
|
558
573
|
NOTE: Extend default properties with given properties while letting
|
|
@@ -593,7 +608,7 @@ export const FileInputInner = function(
|
|
|
593
608
|
properties.value =
|
|
594
609
|
Tools.extend<FileValue>(true, valueState.value, properties.value!)
|
|
595
610
|
|
|
596
|
-
// / region synchronize properties into state
|
|
611
|
+
// / region synchronize uncontrolled properties into state
|
|
597
612
|
const currentValueState:ValueState = {
|
|
598
613
|
attachBlobProperty: false,
|
|
599
614
|
modelState: properties.model.state,
|
|
@@ -657,7 +672,7 @@ export const FileInputInner = function(
|
|
|
657
672
|
typeof Blob === 'undefined' ?
|
|
658
673
|
(properties.value.toString as
|
|
659
674
|
unknown as
|
|
660
|
-
(
|
|
675
|
+
(_encoding:string) => string
|
|
661
676
|
)('base64') :
|
|
662
677
|
await blobToBase64String(properties.value.blob)
|
|
663
678
|
}
|
|
@@ -694,6 +709,7 @@ export const FileInputInner = function(
|
|
|
694
709
|
if (valueChanged)
|
|
695
710
|
onChangeValue(valueChanged, undefined, undefined, true)
|
|
696
711
|
})()
|
|
712
|
+
.catch(console.error)
|
|
697
713
|
})
|
|
698
714
|
// region render
|
|
699
715
|
const representationType:RepresentationType =
|
|
@@ -716,186 +732,205 @@ export const FileInputInner = function(
|
|
|
716
732
|
strict={FileInput.strict}
|
|
717
733
|
themeConfiguration={properties.themeConfiguration}
|
|
718
734
|
tooltip={properties.tooltip}
|
|
719
|
-
><Card
|
|
720
|
-
className={
|
|
721
|
-
[styles['file-input']].concat(properties.className ?? []).join(' ')
|
|
722
|
-
}
|
|
723
|
-
onBlur={onBlur}
|
|
724
|
-
onClick={onClick}
|
|
725
|
-
onFocus={onFocus}
|
|
726
|
-
style={properties.styles}
|
|
727
735
|
>
|
|
728
|
-
<
|
|
729
|
-
{
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
{...properties.media}
|
|
733
|
-
style={{backgroundImage: `url(${properties.value.url})`}}
|
|
734
|
-
/> :
|
|
735
|
-
representationType === 'video' ?
|
|
736
|
-
<video autoPlay loop muted>
|
|
737
|
-
<source
|
|
738
|
-
src={properties.value.url}
|
|
739
|
-
type={properties.value.blob!.type}
|
|
740
|
-
/>
|
|
741
|
-
</video> :
|
|
742
|
-
representationType === 'renderableText' ?
|
|
743
|
-
<div className={
|
|
744
|
-
[styles['file-input__iframe-wrapper']].concat(
|
|
745
|
-
['text/html', 'text/plain'].includes(
|
|
746
|
-
properties.value.blob!.type!
|
|
747
|
-
) ?
|
|
748
|
-
styles['file-input__iframe-wrapper--padding'] :
|
|
749
|
-
[]
|
|
750
|
-
)
|
|
751
|
-
.join(' ')
|
|
752
|
-
}>
|
|
753
|
-
<iframe
|
|
754
|
-
frameBorder="no"
|
|
755
|
-
scrolling="no"
|
|
756
|
-
src={properties.value.url}
|
|
757
|
-
/>
|
|
758
|
-
</div> :
|
|
759
|
-
properties.value?.source && representationType === 'text' ?
|
|
760
|
-
<pre className={styles['file-input__text-representation']}>
|
|
761
|
-
{properties.value.source}
|
|
762
|
-
</pre> :
|
|
763
|
-
'' :
|
|
764
|
-
properties.value?.blob && properties.value.blob instanceof Blob ?
|
|
765
|
-
// NOTE: Only blobs have to red asynchronously.
|
|
766
|
-
<CircularProgress size="large" /> :
|
|
767
|
-
''
|
|
736
|
+
<Card
|
|
737
|
+
className={
|
|
738
|
+
[styles['file-input']].concat(properties.className ?? [])
|
|
739
|
+
.join(' ')
|
|
768
740
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
741
|
+
onBlur={onBlur}
|
|
742
|
+
onClick={onClick}
|
|
743
|
+
onFocus={onFocus}
|
|
744
|
+
style={properties.styles}
|
|
745
|
+
>
|
|
746
|
+
<CardPrimaryAction>
|
|
747
|
+
{properties.value?.url ?
|
|
748
|
+
representationType === 'image' ?
|
|
749
|
+
<CardMedia
|
|
750
|
+
{...properties.media}
|
|
751
|
+
style={{
|
|
752
|
+
backgroundImage: `url(${properties.value.url})`
|
|
753
|
+
}}
|
|
754
|
+
/> :
|
|
755
|
+
representationType === 'video' ?
|
|
756
|
+
<video autoPlay loop muted>
|
|
757
|
+
<source
|
|
758
|
+
src={properties.value.url}
|
|
759
|
+
type={properties.value.blob!.type}
|
|
760
|
+
/>
|
|
761
|
+
</video> :
|
|
762
|
+
representationType === 'renderableText' ?
|
|
763
|
+
<div className={
|
|
764
|
+
[styles['file-input__iframe-wrapper']]
|
|
765
|
+
.concat(
|
|
766
|
+
['text/html', 'text/plain']
|
|
767
|
+
.includes(
|
|
768
|
+
properties.value.blob!.type!
|
|
769
|
+
) ?
|
|
770
|
+
styles[
|
|
771
|
+
'file-input__iframe-' +
|
|
772
|
+
'wrapper--padding'
|
|
773
|
+
] :
|
|
774
|
+
[]
|
|
775
|
+
)
|
|
776
|
+
.join(' ')
|
|
777
|
+
}>
|
|
778
|
+
<iframe
|
|
779
|
+
frameBorder="no"
|
|
780
|
+
scrolling="no"
|
|
781
|
+
src={properties.value.url}
|
|
782
|
+
/>
|
|
783
|
+
</div> :
|
|
784
|
+
properties.value?.source &&
|
|
785
|
+
representationType === 'text' ?
|
|
786
|
+
<pre
|
|
787
|
+
className={styles[
|
|
788
|
+
'file-input__text-representation'
|
|
789
|
+
]}
|
|
790
|
+
>
|
|
791
|
+
{properties.value.source}
|
|
792
|
+
</pre> :
|
|
793
|
+
'' :
|
|
794
|
+
properties.value?.blob &&
|
|
795
|
+
properties.value.blob instanceof Blob ?
|
|
796
|
+
// NOTE: Only blobs have to red asynchronously.
|
|
797
|
+
<CircularProgress size="large" /> :
|
|
798
|
+
''
|
|
799
|
+
}
|
|
800
|
+
<div>
|
|
801
|
+
<Typography tag="h2" use="headline6">
|
|
802
|
+
{invalid ?
|
|
803
|
+
<Theme use="error">{
|
|
804
|
+
properties.description ?
|
|
805
|
+
properties.description :
|
|
806
|
+
properties.name
|
|
807
|
+
}</Theme> :
|
|
773
808
|
properties.description ?
|
|
774
809
|
properties.description :
|
|
775
810
|
properties.name
|
|
776
|
-
}</Theme> :
|
|
777
|
-
properties.description ?
|
|
778
|
-
properties.description :
|
|
779
|
-
properties.name
|
|
780
|
-
}
|
|
781
|
-
</Typography>
|
|
782
|
-
{properties.declaration ?
|
|
783
|
-
<Typography
|
|
784
|
-
style={{marginTop: '-1rem'}}
|
|
785
|
-
tag="h3"
|
|
786
|
-
theme="textSecondaryOnBackground"
|
|
787
|
-
use="subtitle2"
|
|
788
|
-
>
|
|
789
|
-
{invalid ?
|
|
790
|
-
<Theme use="error">
|
|
791
|
-
{properties.declaration}
|
|
792
|
-
</Theme> :
|
|
793
|
-
properties.declaration
|
|
794
811
|
}
|
|
795
|
-
</Typography>
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
{
|
|
803
|
-
disabled: properties.disabled,
|
|
804
|
-
value: properties.value?.name,
|
|
805
|
-
...defaultFileNameInputProperties,
|
|
806
|
-
model: properties.model.fileName,
|
|
807
|
-
onChangeValue: onChangeValue,
|
|
808
|
-
default: properties.value.name
|
|
809
|
-
},
|
|
810
|
-
properties as
|
|
811
|
-
Omit<Properties, 'value'> &
|
|
812
|
-
{value:FileValue & {name:string}}
|
|
813
|
-
)}
|
|
814
|
-
/> :
|
|
815
|
-
''
|
|
816
|
-
}
|
|
817
|
-
{properties.children ?
|
|
818
|
-
properties.children({
|
|
819
|
-
declaration: properties.declaration,
|
|
820
|
-
invalid,
|
|
821
|
-
properties,
|
|
822
|
-
value: properties.value
|
|
823
|
-
}) :
|
|
824
|
-
''
|
|
825
|
-
}
|
|
826
|
-
</div>
|
|
827
|
-
{/*TODO use "accept" attribute*/}
|
|
828
|
-
<input
|
|
829
|
-
disabled={properties.disabled}
|
|
830
|
-
className={styles['file-input__native']}
|
|
831
|
-
id={properties.id || properties.name}
|
|
832
|
-
name={properties.name}
|
|
833
|
-
onChange={onChangeValue}
|
|
834
|
-
ref={fileInputReference}
|
|
835
|
-
type="file"
|
|
836
|
-
/>
|
|
837
|
-
</CardPrimaryAction>
|
|
838
|
-
{!properties.disabled || properties.value ?
|
|
839
|
-
<CardActions>
|
|
840
|
-
<CardActionButtons>
|
|
841
|
-
{!properties.disabled ?
|
|
842
|
-
<CardActionButton
|
|
843
|
-
onClick={():void =>
|
|
844
|
-
fileInputReference.current?.click()
|
|
845
|
-
}
|
|
846
|
-
ref={uploadButtonReference}
|
|
847
|
-
ripple={properties.ripple}
|
|
812
|
+
</Typography>
|
|
813
|
+
{properties.declaration ?
|
|
814
|
+
<Typography
|
|
815
|
+
style={{marginTop: '-1rem'}}
|
|
816
|
+
tag="h3"
|
|
817
|
+
theme="textSecondaryOnBackground"
|
|
818
|
+
use="subtitle2"
|
|
848
819
|
>
|
|
849
|
-
{
|
|
850
|
-
|
|
851
|
-
|
|
820
|
+
{invalid ?
|
|
821
|
+
<Theme use="error">
|
|
822
|
+
{properties.declaration}
|
|
823
|
+
</Theme> :
|
|
824
|
+
properties.declaration
|
|
852
825
|
}
|
|
853
|
-
</
|
|
826
|
+
</Typography> :
|
|
854
827
|
''
|
|
855
828
|
}
|
|
856
829
|
{properties.value ?
|
|
857
|
-
|
|
858
|
-
{
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
<a
|
|
874
|
-
className={
|
|
875
|
-
styles['file-input__download']
|
|
876
|
-
}
|
|
877
|
-
download={properties.value.name}
|
|
878
|
-
href={properties.value.url}
|
|
879
|
-
ref={downloadLinkReference}
|
|
880
|
-
target="_blank"
|
|
881
|
-
{...(properties.value.blob?.type ?
|
|
882
|
-
{type:
|
|
883
|
-
properties.value.blob.type
|
|
884
|
-
} :
|
|
885
|
-
{}
|
|
886
|
-
)}
|
|
887
|
-
>{properties.downloadButton}</a>
|
|
888
|
-
</CardActionButton> :
|
|
889
|
-
''
|
|
890
|
-
}
|
|
891
|
-
</> :
|
|
830
|
+
<GenericInput
|
|
831
|
+
ref={nameInputReference}
|
|
832
|
+
{...properties.generateFileNameInputProperties(
|
|
833
|
+
{
|
|
834
|
+
disabled: properties.disabled,
|
|
835
|
+
value: properties.value?.name,
|
|
836
|
+
...defaultFileNameInputProperties,
|
|
837
|
+
model: properties.model.fileName,
|
|
838
|
+
onChangeValue: onChangeValue,
|
|
839
|
+
default: properties.value.name
|
|
840
|
+
},
|
|
841
|
+
properties as
|
|
842
|
+
Omit<Properties, 'value'> &
|
|
843
|
+
{value:FileValue & {name:string}}
|
|
844
|
+
)}
|
|
845
|
+
/> :
|
|
892
846
|
''
|
|
893
847
|
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
848
|
+
{properties.children ?
|
|
849
|
+
properties.children({
|
|
850
|
+
declaration: properties.declaration,
|
|
851
|
+
invalid,
|
|
852
|
+
properties,
|
|
853
|
+
value: properties.value
|
|
854
|
+
}) :
|
|
855
|
+
''
|
|
856
|
+
}
|
|
857
|
+
</div>
|
|
858
|
+
{/* TODO use "accept" attribute for better validation. */}
|
|
859
|
+
<input
|
|
860
|
+
disabled={properties.disabled}
|
|
861
|
+
className={styles['file-input__native']}
|
|
862
|
+
id={properties.id || properties.name}
|
|
863
|
+
name={properties.name}
|
|
864
|
+
onChange={onChangeValue}
|
|
865
|
+
ref={fileInputReference}
|
|
866
|
+
type="file"
|
|
867
|
+
/>
|
|
868
|
+
</CardPrimaryAction>
|
|
869
|
+
{!properties.disabled || properties.value ?
|
|
870
|
+
<CardActions>
|
|
871
|
+
<CardActionButtons>
|
|
872
|
+
{!properties.disabled ?
|
|
873
|
+
<CardActionButton
|
|
874
|
+
onClick={():void =>
|
|
875
|
+
fileInputReference.current?.click()
|
|
876
|
+
}
|
|
877
|
+
ref={uploadButtonReference}
|
|
878
|
+
ripple={properties.ripple}
|
|
879
|
+
>
|
|
880
|
+
{properties.value ?
|
|
881
|
+
properties.editButton :
|
|
882
|
+
properties.newButton
|
|
883
|
+
}
|
|
884
|
+
</CardActionButton> :
|
|
885
|
+
''
|
|
886
|
+
}
|
|
887
|
+
{properties.value ?
|
|
888
|
+
<>
|
|
889
|
+
{!properties.disabled ?
|
|
890
|
+
<CardActionButton
|
|
891
|
+
onClick={():void => onChangeValue(null)}
|
|
892
|
+
ref={deleteButtonReference}
|
|
893
|
+
ripple={properties.ripple}
|
|
894
|
+
>
|
|
895
|
+
{properties.deleteButton}
|
|
896
|
+
</CardActionButton> :
|
|
897
|
+
''
|
|
898
|
+
}
|
|
899
|
+
{properties.value.url ?
|
|
900
|
+
<CardActionButton
|
|
901
|
+
onClick={():void =>
|
|
902
|
+
downloadLinkReference
|
|
903
|
+
.current?.click()
|
|
904
|
+
}
|
|
905
|
+
ripple={properties.ripple}
|
|
906
|
+
>
|
|
907
|
+
<a
|
|
908
|
+
className={
|
|
909
|
+
styles['file-input__download']
|
|
910
|
+
}
|
|
911
|
+
download={properties.value.name}
|
|
912
|
+
href={properties.value.url}
|
|
913
|
+
ref={downloadLinkReference}
|
|
914
|
+
target="_blank"
|
|
915
|
+
{...(properties.value.blob?.type ?
|
|
916
|
+
{type:
|
|
917
|
+
properties.value.blob.type
|
|
918
|
+
} :
|
|
919
|
+
{}
|
|
920
|
+
)}
|
|
921
|
+
>{properties.downloadButton}</a>
|
|
922
|
+
</CardActionButton> :
|
|
923
|
+
''
|
|
924
|
+
}
|
|
925
|
+
</> :
|
|
926
|
+
''
|
|
927
|
+
}
|
|
928
|
+
</CardActionButtons>
|
|
929
|
+
</CardActions> :
|
|
930
|
+
''
|
|
931
|
+
}
|
|
932
|
+
</Card>
|
|
933
|
+
</WrapConfigurations>
|
|
899
934
|
// endregion
|
|
900
935
|
}
|
|
901
936
|
// NOTE: This is useful in react dev tools.
|
|
@@ -904,13 +939,14 @@ FileInputInner.displayName = 'FileInput'
|
|
|
904
939
|
* Wrapping web component compatible react component.
|
|
905
940
|
* @property static:defaultModelState - Initial model state.
|
|
906
941
|
* @property static:defaultProperties - Initial property configuration.
|
|
907
|
-
* @property static:propTypes - Triggers reacts runtime property value checks
|
|
942
|
+
* @property static:propTypes - Triggers reacts runtime property value checks.
|
|
908
943
|
* @property static:strict - Indicates whether we should wrap render output in
|
|
909
944
|
* reacts strict component.
|
|
910
945
|
* @property static:wrapped - Wrapped component.
|
|
911
946
|
*
|
|
912
947
|
* @param props - Given components properties.
|
|
913
948
|
* @param reference - Reference object to forward internal state.
|
|
949
|
+
*
|
|
914
950
|
* @returns React elements.
|
|
915
951
|
*/
|
|
916
952
|
export const FileInput:FileInputComponent =
|
|
@@ -2,6 +2,9 @@ import { FunctionComponent } from 'react';
|
|
|
2
2
|
import { TransitionProps } from 'react-transition-group/Transition';
|
|
3
3
|
/**
|
|
4
4
|
* Generic animation wrapper component.
|
|
5
|
+
* @param properties - Component given properties object.
|
|
6
|
+
*
|
|
7
|
+
* @returns React elements.
|
|
5
8
|
*/
|
|
6
9
|
export declare const GenericAnimate: FunctionComponent<Partial<TransitionProps<HTMLElement | undefined>>>;
|
|
7
10
|
export default GenericAnimate;
|