react-input-material 0.0.433 → 0.0.435
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/FileInput.js +1 -1
- package/components/FileInput.styles.css +3 -3
- package/components/GenericAnimate.d.ts +5 -3
- package/components/GenericAnimate.js +1 -1
- package/components/GenericInput.js +1 -1
- package/components/GenericInput.styles.css +1 -1
- package/components/Inputs.js +1 -1
- package/components/Inputs.styles.css +2 -2
- package/components/Interval.js +1 -1
- package/components/Interval.styles.css +2 -2
- package/components/RequireableCheckbox.styles.css +1 -1
- package/index.js +1 -1
- package/index.styles.css +6 -6
- package/package.json +4 -2
- package/type.d.ts +5 -0
- package/components/Dummy.tsx +0 -58
- package/components/FileInput.tsx +0 -1010
- package/components/GenericAnimate.tsx +0 -88
- package/components/GenericInput.tsx +0 -2875
- package/components/Inputs.tsx +0 -585
- package/components/Interval.tsx +0 -436
- package/components/RequireableCheckbox.tsx +0 -520
- package/components/WrapConfigurations.tsx +0 -127
- package/components/WrapStrict.tsx +0 -43
- package/components/WrapThemeProvider.tsx +0 -48
- package/components/WrapTooltip.tsx +0 -67
|
@@ -1,520 +0,0 @@
|
|
|
1
|
-
// #!/usr/bin/env babel-node
|
|
2
|
-
// -*- coding: utf-8 -*-
|
|
3
|
-
/** @module RequireableCheckbox */
|
|
4
|
-
'use strict'
|
|
5
|
-
/* !
|
|
6
|
-
region header
|
|
7
|
-
[Project page](https://torben.website/react-material-input)
|
|
8
|
-
|
|
9
|
-
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
|
|
10
|
-
|
|
11
|
-
License
|
|
12
|
-
-------
|
|
13
|
-
|
|
14
|
-
This library written by Torben Sickert stand under a creative commons
|
|
15
|
-
naming 3.0 unported license.
|
|
16
|
-
See https://creativecommons.org/licenses/by/3.0/deed.de
|
|
17
|
-
endregion
|
|
18
|
-
*/
|
|
19
|
-
// region imports
|
|
20
|
-
import Tools from 'clientnode'
|
|
21
|
-
import {Mapping} from 'clientnode/type'
|
|
22
|
-
import {
|
|
23
|
-
FocusEvent as ReactFocusEvent,
|
|
24
|
-
forwardRef,
|
|
25
|
-
ForwardRefRenderFunction,
|
|
26
|
-
memo as memorize,
|
|
27
|
-
MouseEvent as ReactMouseEvent,
|
|
28
|
-
MutableRefObject,
|
|
29
|
-
ReactElement,
|
|
30
|
-
SyntheticEvent,
|
|
31
|
-
useImperativeHandle,
|
|
32
|
-
useRef,
|
|
33
|
-
useState
|
|
34
|
-
} from 'react'
|
|
35
|
-
import {MDCCheckboxFoundation} from '@material/checkbox'
|
|
36
|
-
import {Checkbox} from '@rmwc/checkbox'
|
|
37
|
-
import {Theme} from '@rmwc/theme'
|
|
38
|
-
|
|
39
|
-
/*
|
|
40
|
-
"namedExport" version of css-loader:
|
|
41
|
-
|
|
42
|
-
import {requireableCheckboxClassName} from './RequireableCheckbox.module'
|
|
43
|
-
*/
|
|
44
|
-
import cssClassNames from './RequireableCheckbox.module'
|
|
45
|
-
import {WrapConfigurations} from './WrapConfigurations'
|
|
46
|
-
import {
|
|
47
|
-
deriveMissingPropertiesFromState,
|
|
48
|
-
determineInitialValue,
|
|
49
|
-
determineValidationState as determineBaseValidationState,
|
|
50
|
-
getConsolidatedProperties as getBaseConsolidatedProperties,
|
|
51
|
-
mapPropertiesIntoModel,
|
|
52
|
-
translateKnownSymbols,
|
|
53
|
-
triggerCallbackIfExists,
|
|
54
|
-
wrapStateSetter
|
|
55
|
-
} from '../helper'
|
|
56
|
-
import {
|
|
57
|
-
CheckboxAdapter as Adapter,
|
|
58
|
-
CheckboxProperties as Properties,
|
|
59
|
-
CheckboxProps as Props,
|
|
60
|
-
defaultModelState,
|
|
61
|
-
DefaultCheckboxProperties as DefaultProperties,
|
|
62
|
-
defaultCheckboxProperties as defaultProperties,
|
|
63
|
-
CheckboxModelState as ModelState,
|
|
64
|
-
checkboxPropertyTypes as propertyTypes,
|
|
65
|
-
CheckboxComponent,
|
|
66
|
-
CheckboxValueState as ValueState
|
|
67
|
-
} from '../type'
|
|
68
|
-
// endregion
|
|
69
|
-
const CSS_CLASS_NAMES:Mapping = cssClassNames as Mapping
|
|
70
|
-
// region helper
|
|
71
|
-
/**
|
|
72
|
-
* Derives validation state from provided properties and state.
|
|
73
|
-
* @param properties - Current component properties.
|
|
74
|
-
* @param currentState - Current component state.
|
|
75
|
-
*
|
|
76
|
-
* @returns Whether component is in an aggregated valid or invalid state.
|
|
77
|
-
*/
|
|
78
|
-
export function determineValidationState(
|
|
79
|
-
properties:DefaultProperties, currentState:Partial<ModelState>
|
|
80
|
-
):boolean {
|
|
81
|
-
return determineBaseValidationState<
|
|
82
|
-
DefaultProperties, Partial<ModelState>
|
|
83
|
-
>(
|
|
84
|
-
properties,
|
|
85
|
-
currentState,
|
|
86
|
-
{invalidRequired: ():boolean =>
|
|
87
|
-
properties.model.nullable === false && !properties.model.value
|
|
88
|
-
}
|
|
89
|
-
)
|
|
90
|
-
}
|
|
91
|
-
// endregion
|
|
92
|
-
/* eslint-disable jsdoc/require-description-complete-sentence */
|
|
93
|
-
/**
|
|
94
|
-
* Validateable checkbox wrapper component.
|
|
95
|
-
* @property static:displayName - Descriptive name for component to show in web
|
|
96
|
-
* developer tools.
|
|
97
|
-
*
|
|
98
|
-
* Dataflow:
|
|
99
|
-
*
|
|
100
|
-
* 1. On-Render all states are merged with given properties into a normalized
|
|
101
|
-
* property object.
|
|
102
|
-
* 2. Properties, corresponding state values and sub node instances are saved
|
|
103
|
-
* into a "ref" object (to make them accessible from the outside e.g. for
|
|
104
|
-
* wrapper like web-components).
|
|
105
|
-
* 3. Event handler saves corresponding data modifications into state and
|
|
106
|
-
* normalized properties object.
|
|
107
|
-
* 4. All state changes except selection changes trigger an "onChange" event
|
|
108
|
-
* which delivers the consolidated properties object (with latest
|
|
109
|
-
* modifications included).
|
|
110
|
-
* @property static:displayName - Descriptive name for component to show in web
|
|
111
|
-
* developer tools.
|
|
112
|
-
*
|
|
113
|
-
* @param props - Given components properties.
|
|
114
|
-
* @param reference - Reference object to forward internal state.
|
|
115
|
-
*
|
|
116
|
-
* @returns React elements.
|
|
117
|
-
*/
|
|
118
|
-
export const RequireableCheckboxInner = function(
|
|
119
|
-
props:Props, reference?:MutableRefObject<Adapter>
|
|
120
|
-
):ReactElement {
|
|
121
|
-
/* eslint-enable jsdoc/require-description-complete-sentence */
|
|
122
|
-
// region property aggregation
|
|
123
|
-
/**
|
|
124
|
-
* Calculate external properties (a set of all configurable properties).
|
|
125
|
-
* @param properties - Properties to merge.
|
|
126
|
-
*
|
|
127
|
-
* @returns External properties object.
|
|
128
|
-
*/
|
|
129
|
-
const getConsolidatedProperties = (properties:Props):Properties => {
|
|
130
|
-
let result:DefaultProperties =
|
|
131
|
-
mapPropertiesIntoModel<Props, DefaultProperties>(
|
|
132
|
-
properties, RequireableCheckbox.defaultProperties.model
|
|
133
|
-
)
|
|
134
|
-
|
|
135
|
-
determineValidationState(result, result.model.state)
|
|
136
|
-
|
|
137
|
-
result = getBaseConsolidatedProperties<Props, Properties>(result)
|
|
138
|
-
|
|
139
|
-
result.checked = Boolean(result.value)
|
|
140
|
-
|
|
141
|
-
return result as Properties
|
|
142
|
-
}
|
|
143
|
-
// endregion
|
|
144
|
-
// region event handler
|
|
145
|
-
/**
|
|
146
|
-
* Triggered on blur events.
|
|
147
|
-
* @param event - Event object.
|
|
148
|
-
*
|
|
149
|
-
* @returns Nothing.
|
|
150
|
-
*/
|
|
151
|
-
const onBlur = (event:SyntheticEvent):void => setValueState((
|
|
152
|
-
oldValueState:ValueState
|
|
153
|
-
):ValueState => {
|
|
154
|
-
let changed = false
|
|
155
|
-
|
|
156
|
-
if (oldValueState.modelState.focused) {
|
|
157
|
-
properties.focused = false
|
|
158
|
-
changed = true
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!oldValueState.modelState.visited) {
|
|
162
|
-
properties.visited = true
|
|
163
|
-
changed = true
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (changed) {
|
|
167
|
-
onChange(event)
|
|
168
|
-
|
|
169
|
-
triggerCallbackIfExists<Properties>(
|
|
170
|
-
properties,
|
|
171
|
-
'changeState',
|
|
172
|
-
controlled,
|
|
173
|
-
properties.model.state,
|
|
174
|
-
event,
|
|
175
|
-
properties
|
|
176
|
-
)
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
triggerCallbackIfExists<Properties>(
|
|
180
|
-
properties, 'blur', controlled, event, properties
|
|
181
|
-
)
|
|
182
|
-
|
|
183
|
-
return changed ?
|
|
184
|
-
{...oldValueState, modelState: properties.model.state} :
|
|
185
|
-
oldValueState
|
|
186
|
-
})
|
|
187
|
-
/**
|
|
188
|
-
* Triggered on any change events. Consolidates properties object and
|
|
189
|
-
* triggers given on change callbacks.
|
|
190
|
-
* @param event - Potential event object.
|
|
191
|
-
*
|
|
192
|
-
* @returns Nothing.
|
|
193
|
-
*/
|
|
194
|
-
const onChange = (event?:SyntheticEvent):void => {
|
|
195
|
-
Tools.extend(
|
|
196
|
-
true,
|
|
197
|
-
properties,
|
|
198
|
-
getConsolidatedProperties(
|
|
199
|
-
/*
|
|
200
|
-
Workaround since "Type" isn't identified as subset of
|
|
201
|
-
"RecursivePartial<Type>" yet.
|
|
202
|
-
*/
|
|
203
|
-
properties as unknown as Props
|
|
204
|
-
)
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
triggerCallbackIfExists<Properties>(
|
|
208
|
-
properties, 'change', controlled, properties, event
|
|
209
|
-
)
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Triggered when ever the value changes.
|
|
213
|
-
* @param event - Event object.
|
|
214
|
-
*
|
|
215
|
-
* @returns Nothing.
|
|
216
|
-
*/
|
|
217
|
-
const onChangeValue = (event:SyntheticEvent):void => {
|
|
218
|
-
if (!(properties.model.mutable && properties.model.writable))
|
|
219
|
-
return
|
|
220
|
-
|
|
221
|
-
properties.value = Boolean(
|
|
222
|
-
(event.target as unknown as {checked:boolean|null}).checked
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
setValueState((oldValueState:ValueState):ValueState => {
|
|
226
|
-
if (oldValueState.value === properties.value)
|
|
227
|
-
return oldValueState
|
|
228
|
-
|
|
229
|
-
let stateChanged = false
|
|
230
|
-
|
|
231
|
-
const result:ValueState =
|
|
232
|
-
{...oldValueState, value: properties.value as boolean|null}
|
|
233
|
-
|
|
234
|
-
if (oldValueState.modelState.pristine) {
|
|
235
|
-
properties.dirty = true
|
|
236
|
-
properties.pristine = false
|
|
237
|
-
stateChanged = true
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
onChange(event)
|
|
241
|
-
|
|
242
|
-
if (determineValidationState(properties, oldValueState.modelState))
|
|
243
|
-
stateChanged = true
|
|
244
|
-
|
|
245
|
-
triggerCallbackIfExists<Properties>(
|
|
246
|
-
properties,
|
|
247
|
-
'changeValue',
|
|
248
|
-
controlled,
|
|
249
|
-
properties.value,
|
|
250
|
-
event,
|
|
251
|
-
properties
|
|
252
|
-
)
|
|
253
|
-
|
|
254
|
-
if (stateChanged) {
|
|
255
|
-
result.modelState = properties.model.state
|
|
256
|
-
|
|
257
|
-
triggerCallbackIfExists<Properties>(
|
|
258
|
-
properties,
|
|
259
|
-
'changeState',
|
|
260
|
-
controlled,
|
|
261
|
-
properties.model.state,
|
|
262
|
-
event,
|
|
263
|
-
properties
|
|
264
|
-
)
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return result
|
|
268
|
-
})
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Triggered on click events.
|
|
272
|
-
* @param event - Mouse event object.
|
|
273
|
-
*
|
|
274
|
-
* @returns Nothing.
|
|
275
|
-
*/
|
|
276
|
-
const onClick = (event:ReactMouseEvent):void => {
|
|
277
|
-
triggerCallbackIfExists<Properties>(
|
|
278
|
-
properties, 'click', controlled, event, properties
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
onTouch(event)
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Triggered on focus events.
|
|
285
|
-
* @param event - Focus event object.
|
|
286
|
-
*
|
|
287
|
-
* @returns Nothing.
|
|
288
|
-
*/
|
|
289
|
-
const onFocus = (event:ReactFocusEvent):void => {
|
|
290
|
-
triggerCallbackIfExists<Properties>(
|
|
291
|
-
properties, 'focus', controlled, event, properties
|
|
292
|
-
)
|
|
293
|
-
|
|
294
|
-
onTouch(event)
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Triggers on start interacting with the input.
|
|
298
|
-
* @param event - Event object which triggered interaction.
|
|
299
|
-
*
|
|
300
|
-
* @returns Nothing.
|
|
301
|
-
*/
|
|
302
|
-
const onTouch = (event:ReactFocusEvent|ReactMouseEvent):void =>
|
|
303
|
-
setValueState((oldValueState:ValueState):ValueState => {
|
|
304
|
-
let changedState = false
|
|
305
|
-
|
|
306
|
-
if (!oldValueState.modelState.focused) {
|
|
307
|
-
properties.focused = true
|
|
308
|
-
changedState = true
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (oldValueState.modelState.untouched) {
|
|
312
|
-
properties.touched = true
|
|
313
|
-
properties.untouched = false
|
|
314
|
-
changedState = true
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
let result:ValueState = oldValueState
|
|
318
|
-
|
|
319
|
-
if (changedState) {
|
|
320
|
-
onChange(event)
|
|
321
|
-
|
|
322
|
-
result = {...oldValueState, modelState: properties.model.state}
|
|
323
|
-
|
|
324
|
-
triggerCallbackIfExists<Properties>(
|
|
325
|
-
properties,
|
|
326
|
-
'changeState',
|
|
327
|
-
controlled,
|
|
328
|
-
properties.model.state,
|
|
329
|
-
event,
|
|
330
|
-
properties
|
|
331
|
-
)
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
triggerCallbackIfExists<Properties>(
|
|
335
|
-
properties, 'touch', controlled, event, properties
|
|
336
|
-
)
|
|
337
|
-
|
|
338
|
-
return result
|
|
339
|
-
})
|
|
340
|
-
// endregion
|
|
341
|
-
// region properties
|
|
342
|
-
/// region references
|
|
343
|
-
const inputReference:MutableRefObject<HTMLInputElement|null> =
|
|
344
|
-
useRef<HTMLInputElement>(null)
|
|
345
|
-
const foundationRef:MutableRefObject<MDCCheckboxFoundation|null> =
|
|
346
|
-
useRef<MDCCheckboxFoundation>(null)
|
|
347
|
-
/// endregion
|
|
348
|
-
const givenProps:Props = translateKnownSymbols(props)
|
|
349
|
-
|
|
350
|
-
const initialValue:boolean|null = determineInitialValue<boolean>(
|
|
351
|
-
givenProps,
|
|
352
|
-
RequireableCheckbox.defaultProperties.model.default,
|
|
353
|
-
givenProps.checked
|
|
354
|
-
)
|
|
355
|
-
/*
|
|
356
|
-
NOTE: Extend default properties with given properties while letting
|
|
357
|
-
default property object untouched for unchanged usage in other
|
|
358
|
-
instances.
|
|
359
|
-
*/
|
|
360
|
-
const givenProperties:Props = Tools.extend(
|
|
361
|
-
true, Tools.copy(RequireableCheckbox.defaultProperties), givenProps
|
|
362
|
-
)
|
|
363
|
-
/*
|
|
364
|
-
NOTE: This values have to share the same state item since they have to
|
|
365
|
-
be updated in one event loop (set state callback).
|
|
366
|
-
*/
|
|
367
|
-
let [valueState, setValueState] = useState<ValueState>({
|
|
368
|
-
modelState: {...RequireableCheckbox.defaultModelState},
|
|
369
|
-
value: initialValue
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
const controlled:boolean =
|
|
373
|
-
!givenProperties.enforceUncontrolled &&
|
|
374
|
-
(
|
|
375
|
-
givenProps.model?.value !== undefined ||
|
|
376
|
-
givenProps.value !== undefined
|
|
377
|
-
) &&
|
|
378
|
-
Boolean(givenProps.onChange || givenProps.onChangeValue)
|
|
379
|
-
|
|
380
|
-
deriveMissingPropertiesFromState<Props, ValueState>(
|
|
381
|
-
givenProperties, valueState
|
|
382
|
-
)
|
|
383
|
-
|
|
384
|
-
const properties:Properties = getConsolidatedProperties(givenProperties)
|
|
385
|
-
|
|
386
|
-
const currentValueState:ValueState = {
|
|
387
|
-
modelState: properties.model.state,
|
|
388
|
-
value: properties.value as boolean|null
|
|
389
|
-
}
|
|
390
|
-
/*
|
|
391
|
-
NOTE: If value is controlled only trigger/save state changes when model
|
|
392
|
-
state has changed.
|
|
393
|
-
*/
|
|
394
|
-
if (
|
|
395
|
-
!controlled && properties.value !== valueState.value ||
|
|
396
|
-
!Tools.equals(properties.model.state, valueState.modelState)
|
|
397
|
-
)
|
|
398
|
-
setValueState(currentValueState)
|
|
399
|
-
if (controlled)
|
|
400
|
-
setValueState =
|
|
401
|
-
wrapStateSetter<ValueState>(setValueState, currentValueState)
|
|
402
|
-
// endregion
|
|
403
|
-
// region export references
|
|
404
|
-
useImperativeHandle(
|
|
405
|
-
reference,
|
|
406
|
-
():Adapter & {
|
|
407
|
-
references:{
|
|
408
|
-
foundationRef:MutableRefObject<MDCCheckboxFoundation|null>
|
|
409
|
-
inputReference:MutableRefObject<HTMLInputElement|null>
|
|
410
|
-
}
|
|
411
|
-
} => ({
|
|
412
|
-
properties,
|
|
413
|
-
references: {foundationRef, inputReference},
|
|
414
|
-
state: {
|
|
415
|
-
modelState: properties.model.state,
|
|
416
|
-
...(controlled ?
|
|
417
|
-
{} :
|
|
418
|
-
{value: properties.value as boolean|null}
|
|
419
|
-
)
|
|
420
|
-
}
|
|
421
|
-
})
|
|
422
|
-
)
|
|
423
|
-
// endregion
|
|
424
|
-
// region render
|
|
425
|
-
return <WrapConfigurations
|
|
426
|
-
strict={RequireableCheckbox.strict}
|
|
427
|
-
themeConfiguration={properties.themeConfiguration}
|
|
428
|
-
tooltip={properties.tooltip}
|
|
429
|
-
>
|
|
430
|
-
<div
|
|
431
|
-
className={[CSS_CLASS_NAMES['requireable-checkbox']]
|
|
432
|
-
.concat(properties.className ?? [])
|
|
433
|
-
.join(' ')
|
|
434
|
-
}
|
|
435
|
-
style={properties.styles}
|
|
436
|
-
>
|
|
437
|
-
<Checkbox
|
|
438
|
-
checked={Boolean(properties.value)}
|
|
439
|
-
disabled={properties.disabled}
|
|
440
|
-
foundationRef={foundationRef}
|
|
441
|
-
id={properties.id || properties.name}
|
|
442
|
-
indeterminate={properties.value === null}
|
|
443
|
-
inputRef={inputReference}
|
|
444
|
-
label={(
|
|
445
|
-
properties.invalid &&
|
|
446
|
-
(
|
|
447
|
-
properties.showInitialValidationState ||
|
|
448
|
-
/*
|
|
449
|
-
Material inputs show their validation state at
|
|
450
|
-
least after a blur event so we synchronize error
|
|
451
|
-
appearances.
|
|
452
|
-
*/
|
|
453
|
-
properties.visited
|
|
454
|
-
)
|
|
455
|
-
) ?
|
|
456
|
-
<Theme use="error">
|
|
457
|
-
{properties.description || properties.name}
|
|
458
|
-
</Theme> :
|
|
459
|
-
properties.description || properties.name
|
|
460
|
-
}
|
|
461
|
-
name={properties.name}
|
|
462
|
-
onBlur={onBlur}
|
|
463
|
-
onChange={onChangeValue}
|
|
464
|
-
onClick={onClick}
|
|
465
|
-
onFocus={onFocus}
|
|
466
|
-
ripple={properties.ripple}
|
|
467
|
-
value={`${properties.value as unknown as string}`}
|
|
468
|
-
/>
|
|
469
|
-
</div>
|
|
470
|
-
</WrapConfigurations>
|
|
471
|
-
// endregion
|
|
472
|
-
} as ForwardRefRenderFunction<Adapter, Props>
|
|
473
|
-
// NOTE: This is useful in react dev tools.
|
|
474
|
-
RequireableCheckboxInner.displayName = 'RequireableCheckbox'
|
|
475
|
-
/**
|
|
476
|
-
* Wrapping web component compatible react component.
|
|
477
|
-
* @property static:defaultModelState - Initial model state.
|
|
478
|
-
* @property static:defaultProperties - Initial property configuration.
|
|
479
|
-
* @property static:propTypes - Triggers reacts runtime property value checks.
|
|
480
|
-
* @property static:strict - Indicates whether we should wrap render output in
|
|
481
|
-
* reacts strict component.
|
|
482
|
-
* @property static:wrapped - Wrapped component.
|
|
483
|
-
*
|
|
484
|
-
* @param props - Given components properties.
|
|
485
|
-
* @param reference - Reference object to forward internal state.
|
|
486
|
-
*
|
|
487
|
-
* @returns React elements.
|
|
488
|
-
*/
|
|
489
|
-
export const RequireableCheckbox:CheckboxComponent =
|
|
490
|
-
memorize(forwardRef(RequireableCheckboxInner)) as
|
|
491
|
-
unknown as
|
|
492
|
-
CheckboxComponent
|
|
493
|
-
// region static properties
|
|
494
|
-
/// region web-component hints
|
|
495
|
-
RequireableCheckbox.wrapped = RequireableCheckboxInner
|
|
496
|
-
RequireableCheckbox.webComponentAdapterWrapped = 'react'
|
|
497
|
-
/// endregion
|
|
498
|
-
RequireableCheckbox.defaultModelState = defaultModelState
|
|
499
|
-
/*
|
|
500
|
-
NOTE: We set values to "undefined" to identify whether these values where
|
|
501
|
-
provided via "props" and should shadow a state saved valued.
|
|
502
|
-
*/
|
|
503
|
-
RequireableCheckbox.defaultProperties = {
|
|
504
|
-
...defaultProperties,
|
|
505
|
-
model: {
|
|
506
|
-
...defaultProperties.model,
|
|
507
|
-
// Trigger initial determination.
|
|
508
|
-
state: undefined as unknown as ModelState,
|
|
509
|
-
value: undefined
|
|
510
|
-
},
|
|
511
|
-
value: undefined
|
|
512
|
-
}
|
|
513
|
-
RequireableCheckbox.propTypes = propertyTypes
|
|
514
|
-
RequireableCheckbox.strict = false
|
|
515
|
-
// endregion
|
|
516
|
-
export default RequireableCheckbox
|
|
517
|
-
// region vim modline
|
|
518
|
-
// vim: set tabstop=4 shiftwidth=4 expandtab:
|
|
519
|
-
// vim: foldmethod=marker foldmarker=region,endregion:
|
|
520
|
-
// endregion
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
// #!/usr/bin/env babel-node
|
|
2
|
-
// -*- coding: utf-8 -*-
|
|
3
|
-
/** @module WrapConfigurations */
|
|
4
|
-
'use strict'
|
|
5
|
-
/* !
|
|
6
|
-
region header
|
|
7
|
-
[Project page](https://torben.website/react-material-input)
|
|
8
|
-
|
|
9
|
-
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
|
|
10
|
-
|
|
11
|
-
License
|
|
12
|
-
-------
|
|
13
|
-
|
|
14
|
-
This library written by Torben Sickert stand under a creative commons
|
|
15
|
-
naming 3.0 unported license.
|
|
16
|
-
See https://creativecommons.org/licenses/by/3.0/deed.de
|
|
17
|
-
endregion
|
|
18
|
-
*/
|
|
19
|
-
// region imports
|
|
20
|
-
import {AnyFunction, FirstParameter} from 'clientnode/type'
|
|
21
|
-
import {
|
|
22
|
-
forwardRef,
|
|
23
|
-
ForwardRefRenderFunction,
|
|
24
|
-
FunctionComponent,
|
|
25
|
-
MutableRefObject,
|
|
26
|
-
ReactElement
|
|
27
|
-
} from 'react'
|
|
28
|
-
import {Theme} from '@rmwc/theme'
|
|
29
|
-
import {ThemePropT} from '@rmwc/types'
|
|
30
|
-
|
|
31
|
-
import {WrapStrict} from './WrapStrict'
|
|
32
|
-
import {WrapThemeProvider} from './WrapThemeProvider'
|
|
33
|
-
import {WrapTooltip} from './WrapTooltip'
|
|
34
|
-
import {ConfigurationProperties} from '../type'
|
|
35
|
-
// endregion
|
|
36
|
-
/**
|
|
37
|
-
* Wraps a theme provider, strict wrapper and tooltip to given element if
|
|
38
|
-
* corresponding configurations are provided.
|
|
39
|
-
* @param properties - Component provided properties.
|
|
40
|
-
* @param properties.children - Component or string to wrap.
|
|
41
|
-
* @param properties.strict - Indicates whether to render in strict mode.
|
|
42
|
-
* @param properties.themeConfiguration - Optional theme configurations.
|
|
43
|
-
* @param properties.tooltip - Optional tooltip to show on hover.
|
|
44
|
-
* @param properties.wrap - Instead of injecting a div tag, wrap a child
|
|
45
|
-
* component by merging the theme styles directly onto it. Useful when you
|
|
46
|
-
* don't want to mess with layout.
|
|
47
|
-
*
|
|
48
|
-
* @returns Wrapped content.
|
|
49
|
-
*/
|
|
50
|
-
export const WrapConfigurations:FunctionComponent<
|
|
51
|
-
ConfigurationProperties & {children:ReactElement}
|
|
52
|
-
> = ({children, strict, themeConfiguration, tooltip, wrap}):ReactElement =>
|
|
53
|
-
<WrapStrict strict={Boolean(strict)}>
|
|
54
|
-
<WrapTooltip options={tooltip}>
|
|
55
|
-
<WrapThemeProvider configuration={themeConfiguration} wrap={wrap}>
|
|
56
|
-
{children}
|
|
57
|
-
</WrapThemeProvider>
|
|
58
|
-
</WrapTooltip>
|
|
59
|
-
</WrapStrict>
|
|
60
|
-
/**
|
|
61
|
-
* Component factory to dynamically create a wrapped component.
|
|
62
|
-
* @param WrappedComponent - Component to wrap.
|
|
63
|
-
* @param options - Options configure wrapping.
|
|
64
|
-
* @param options.withReference - Indicates whether to add a mutable reference
|
|
65
|
-
* to wrapping component.
|
|
66
|
-
* @param options.withThemeWrapper - Indicates whether all theme configurations
|
|
67
|
-
* should be provided.
|
|
68
|
-
*
|
|
69
|
-
* @returns Created wrapped component.
|
|
70
|
-
*/
|
|
71
|
-
export function createWrapConfigurationsComponent<
|
|
72
|
-
Type extends AnyFunction = AnyFunction, Reference = unknown
|
|
73
|
-
>(
|
|
74
|
-
WrappedComponent:Type,
|
|
75
|
-
options:{withReference?:boolean|null, withThemeWrapper?:boolean} = {}
|
|
76
|
-
):FunctionComponent<
|
|
77
|
-
FirstParameter<Type> & ConfigurationProperties & {theme?:ThemePropT}
|
|
78
|
-
> {
|
|
79
|
-
const component:FunctionComponent<
|
|
80
|
-
FirstParameter<Type> &
|
|
81
|
-
ConfigurationProperties &
|
|
82
|
-
{theme:ThemePropT}
|
|
83
|
-
> = (
|
|
84
|
-
{strict, theme, themeConfiguration, tooltip, wrap, ...properties},
|
|
85
|
-
reference?:MutableRefObject<Reference>
|
|
86
|
-
):ReactElement => {
|
|
87
|
-
const wrapped:ReactElement = <WrappedComponent {...{
|
|
88
|
-
...(properties as FirstParameter<Type>),
|
|
89
|
-
...(options.withReference === false ?
|
|
90
|
-
{} :
|
|
91
|
-
reference ? {ref: reference} : {}
|
|
92
|
-
),
|
|
93
|
-
...(options.withThemeWrapper && theme ?
|
|
94
|
-
{theme: theme as ThemePropT} :
|
|
95
|
-
{}
|
|
96
|
-
)
|
|
97
|
-
}} />
|
|
98
|
-
|
|
99
|
-
return <WrapConfigurations
|
|
100
|
-
{...{
|
|
101
|
-
strict: strict as boolean,
|
|
102
|
-
themeConfiguration: themeConfiguration as
|
|
103
|
-
ConfigurationProperties['themeConfiguration'],
|
|
104
|
-
tooltip: tooltip as ConfigurationProperties['tooltip'],
|
|
105
|
-
wrap: wrap as ConfigurationProperties['wrap']
|
|
106
|
-
}}
|
|
107
|
-
>
|
|
108
|
-
{options.withThemeWrapper && theme ?
|
|
109
|
-
<Theme
|
|
110
|
-
use={theme as ThemePropT}
|
|
111
|
-
wrap={wrap as ConfigurationProperties['wrap']}
|
|
112
|
-
>{wrapped}</Theme> :
|
|
113
|
-
wrapped
|
|
114
|
-
}
|
|
115
|
-
</WrapConfigurations>
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return options.withReference ?
|
|
119
|
-
forwardRef(component as ForwardRefRenderFunction<typeof component>) :
|
|
120
|
-
component
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export default WrapConfigurations
|
|
124
|
-
// region vim modline
|
|
125
|
-
// vim: set tabstop=4 shiftwidth=4 expandtab:
|
|
126
|
-
// vim: foldmethod=marker foldmarker=region,endregion:
|
|
127
|
-
// endregion
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// #!/usr/bin/env babel-node
|
|
2
|
-
// -*- coding: utf-8 -*-
|
|
3
|
-
/** @module wrap-strict */
|
|
4
|
-
'use strict'
|
|
5
|
-
/* !
|
|
6
|
-
region header
|
|
7
|
-
[Project page](https://torben.website/react-material-input)
|
|
8
|
-
|
|
9
|
-
Copyright Torben Sickert (info["~at~"]torben.website) 16.12.2012
|
|
10
|
-
|
|
11
|
-
License
|
|
12
|
-
-------
|
|
13
|
-
|
|
14
|
-
This library written by Torben Sickert stand under a creative commons
|
|
15
|
-
naming 3.0 unported license.
|
|
16
|
-
See https://creativecommons.org/licenses/by/3.0/deed.de
|
|
17
|
-
endregion
|
|
18
|
-
*/
|
|
19
|
-
// region imports
|
|
20
|
-
import {FunctionComponent, ReactElement, StrictMode} from 'react'
|
|
21
|
-
|
|
22
|
-
import {Renderable} from '../type'
|
|
23
|
-
// endregion
|
|
24
|
-
/**
|
|
25
|
-
* Generic strict wrapper component.
|
|
26
|
-
* @param properties - Provided component properties.
|
|
27
|
-
* @param properties.children - Components to wrap.
|
|
28
|
-
* @param properties.strict - Indicates whether to wrap with strict indicating
|
|
29
|
-
* component.
|
|
30
|
-
*
|
|
31
|
-
* @returns React component.
|
|
32
|
-
*/
|
|
33
|
-
export const WrapStrict:FunctionComponent<{
|
|
34
|
-
children:Renderable
|
|
35
|
-
strict:boolean
|
|
36
|
-
}> = ({children, strict}):ReactElement =>
|
|
37
|
-
strict ? <StrictMode>{children}</StrictMode> : <>{children}</>
|
|
38
|
-
|
|
39
|
-
export default WrapStrict
|
|
40
|
-
// region vim modline
|
|
41
|
-
// vim: set tabstop=4 shiftwidth=4 expandtab:
|
|
42
|
-
// vim: foldmethod=marker foldmarker=region,endregion:
|
|
43
|
-
// endregion
|