react-input-material 0.0.402 → 0.0.405
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/GenericInput.js +1 -1
- package/components/GenericInput.tsx +130 -127
- package/components/Inputs.js +1 -1
- package/components/Interval.js +1 -1
- package/helper.d.ts +2 -2
- package/helper.js +1 -1
- package/index.js +1 -1
- package/package.json +3 -1
- package/type.d.ts +8 -6
|
@@ -1270,9 +1270,25 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1270
1270
|
(eventOrValue as GenericEvent).target as HTMLInputElement ||
|
|
1271
1271
|
(eventOrValue as GenericEvent).detail as HTMLInputElement
|
|
1272
1272
|
if (target)
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1273
|
+
/*
|
|
1274
|
+
NOTE: Enhanced select fields (menus) do not provide the
|
|
1275
|
+
selected value but index.
|
|
1276
|
+
*/
|
|
1277
|
+
if (typeof (
|
|
1278
|
+
target as unknown as {index:number}
|
|
1279
|
+
).index === 'number') {
|
|
1280
|
+
const index:number = (
|
|
1281
|
+
target as unknown as {index:number}
|
|
1282
|
+
).index - (properties.placeholder ? 1 : 0)
|
|
1283
|
+
properties.value =
|
|
1284
|
+
index >= 0 &&
|
|
1285
|
+
index < suggestionValues.length ?
|
|
1286
|
+
suggestionValues[index] as Type :
|
|
1287
|
+
null
|
|
1288
|
+
} else
|
|
1289
|
+
properties.value = typeof target.value === 'undefined' ?
|
|
1290
|
+
null :
|
|
1291
|
+
target.value as unknown as Type
|
|
1276
1292
|
else
|
|
1277
1293
|
properties.value = eventOrValue as null|Type
|
|
1278
1294
|
} else
|
|
@@ -1957,7 +1973,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1957
1973
|
]}
|
|
1958
1974
|
key={index}
|
|
1959
1975
|
>
|
|
1960
|
-
{Tools.stringMark(
|
|
1976
|
+
{(Tools.stringMark(
|
|
1961
1977
|
suggestion,
|
|
1962
1978
|
properties.representation?.split(' ') || '',
|
|
1963
1979
|
(value:unknown):string =>
|
|
@@ -1970,7 +1986,11 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1970
1986
|
{foundWord}
|
|
1971
1987
|
</span>,
|
|
1972
1988
|
null
|
|
1973
|
-
) as Array<ReactElement
|
|
1989
|
+
) as Array<ReactElement|string>).map((
|
|
1990
|
+
item:ReactElement|string, index:number
|
|
1991
|
+
):ReactElement =>
|
|
1992
|
+
<span key={index}>{item}</span>
|
|
1993
|
+
)}
|
|
1974
1994
|
</MenuItem>
|
|
1975
1995
|
)
|
|
1976
1996
|
currentSuggestionLabels.push(suggestion)
|
|
@@ -1984,6 +2004,47 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
1984
2004
|
(Boolean(normalizedSelection) || Boolean(properties.labels)) &&
|
|
1985
2005
|
!useSuggestions
|
|
1986
2006
|
/// endregion
|
|
2007
|
+
/// region determine type specific constraints
|
|
2008
|
+
const constraints:Mapping<unknown> = {}
|
|
2009
|
+
if (properties.type === 'number') {
|
|
2010
|
+
constraints.step = properties.step
|
|
2011
|
+
|
|
2012
|
+
if (properties.maximum !== Infinity)
|
|
2013
|
+
constraints.max = properties.maximum
|
|
2014
|
+
if (properties.minimum !== -Infinity)
|
|
2015
|
+
constraints.min = properties.minimum
|
|
2016
|
+
} else if (properties.type === 'string') {
|
|
2017
|
+
if (
|
|
2018
|
+
properties.maximumLength >= 0 &&
|
|
2019
|
+
properties.maximumLength !== Infinity
|
|
2020
|
+
)
|
|
2021
|
+
constraints.maxLength = properties.maximumLength
|
|
2022
|
+
if (properties.minimumLength > 0)
|
|
2023
|
+
constraints.minLength = properties.minimumLength
|
|
2024
|
+
|
|
2025
|
+
if (properties.editor !== 'plain')
|
|
2026
|
+
constraints.rows = properties.rows
|
|
2027
|
+
} else if (['date', 'datetime-local', 'time'].includes(properties.type)) {
|
|
2028
|
+
constraints.step = properties.step
|
|
2029
|
+
|
|
2030
|
+
if (properties.maximum !== Infinity)
|
|
2031
|
+
constraints.max = formatValue<Type>(
|
|
2032
|
+
properties,
|
|
2033
|
+
properties.maximum as
|
|
2034
|
+
unknown as
|
|
2035
|
+
Type,
|
|
2036
|
+
transformer
|
|
2037
|
+
)
|
|
2038
|
+
if (properties.minimum !== -Infinity)
|
|
2039
|
+
constraints.min = formatValue<Type>(
|
|
2040
|
+
properties,
|
|
2041
|
+
properties.minimum as
|
|
2042
|
+
unknown as
|
|
2043
|
+
Type,
|
|
2044
|
+
transformer
|
|
2045
|
+
)
|
|
2046
|
+
}
|
|
2047
|
+
/// endregion
|
|
1987
2048
|
/// region main markup
|
|
1988
2049
|
return <WrapConfigurations
|
|
1989
2050
|
strict={GenericInput.strict}
|
|
@@ -2248,47 +2309,7 @@ export const GenericInputInner = function<Type = unknown>(
|
|
|
2248
2309
|
<TextField
|
|
2249
2310
|
{...genericProperties as TextFieldProps}
|
|
2250
2311
|
{...materialProperties as TextFieldProps}
|
|
2251
|
-
{...
|
|
2252
|
-
{
|
|
2253
|
-
max: properties.maximum,
|
|
2254
|
-
min: properties.minimum,
|
|
2255
|
-
step: properties.step
|
|
2256
|
-
} :
|
|
2257
|
-
properties.type === 'string' ?
|
|
2258
|
-
{
|
|
2259
|
-
maxLength: properties.maximumLength >= 0 ?
|
|
2260
|
-
properties.maximumLength :
|
|
2261
|
-
Infinity,
|
|
2262
|
-
minLength: properties.minimumLength >= 0 ?
|
|
2263
|
-
properties.minimumLength :
|
|
2264
|
-
0,
|
|
2265
|
-
...(properties.editor === 'plain' ?
|
|
2266
|
-
{} :
|
|
2267
|
-
{rows: properties.rows}
|
|
2268
|
-
)
|
|
2269
|
-
} :
|
|
2270
|
-
['date', 'datetime-local', 'time'].includes(
|
|
2271
|
-
properties.type
|
|
2272
|
-
) ?
|
|
2273
|
-
{
|
|
2274
|
-
max: formatValue<Type>(
|
|
2275
|
-
properties,
|
|
2276
|
-
properties.maximum as
|
|
2277
|
-
unknown as
|
|
2278
|
-
Type,
|
|
2279
|
-
transformer
|
|
2280
|
-
),
|
|
2281
|
-
min: formatValue<Type>(
|
|
2282
|
-
properties,
|
|
2283
|
-
properties.minimum as
|
|
2284
|
-
unknown as
|
|
2285
|
-
Type,
|
|
2286
|
-
transformer
|
|
2287
|
-
),
|
|
2288
|
-
step: properties.step
|
|
2289
|
-
} :
|
|
2290
|
-
{}
|
|
2291
|
-
)}
|
|
2312
|
+
{...constraints}
|
|
2292
2313
|
align={properties.align}
|
|
2293
2314
|
characterCount={
|
|
2294
2315
|
typeof properties.maximumLength === 'number' &&
|
|
@@ -2434,34 +2455,21 @@ GenericInput.transformer = {
|
|
|
2434
2455
|
type: 'text'
|
|
2435
2456
|
},
|
|
2436
2457
|
date: {
|
|
2437
|
-
format: {
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
return ''
|
|
2458
|
+
format: {final: {transform: (value:number):string => {
|
|
2459
|
+
value = typeof value === 'number' ? value : parseFloat(value)
|
|
2460
|
+
|
|
2461
|
+
if (value === Infinity)
|
|
2462
|
+
return 'Infinitely far in the future'
|
|
2463
|
+
if (value === -Infinity)
|
|
2464
|
+
return 'Infinitely early in the past'
|
|
2465
|
+
if (!isFinite(value))
|
|
2466
|
+
return ''
|
|
2447
2467
|
|
|
2448
|
-
|
|
2449
|
-
|
|
2468
|
+
const formattedValue:string =
|
|
2469
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2450
2470
|
|
|
2451
|
-
|
|
2452
|
-
|
|
2453
|
-
intermediate: {transform: (
|
|
2454
|
-
value:number,
|
|
2455
|
-
configuration:DefaultProperties<number>,
|
|
2456
|
-
transformer:InputDataTransformation
|
|
2457
|
-
):string =>
|
|
2458
|
-
transformer.date.format?.final.transform ?
|
|
2459
|
-
transformer.date.format.final.transform(
|
|
2460
|
-
value, configuration, transformer
|
|
2461
|
-
) :
|
|
2462
|
-
`${value}`
|
|
2463
|
-
}
|
|
2464
|
-
},
|
|
2471
|
+
return formattedValue.substring(0, formattedValue.indexOf('T'))
|
|
2472
|
+
}}},
|
|
2465
2473
|
parse: (value:Date|number|string):number =>
|
|
2466
2474
|
typeof value === 'number' ?
|
|
2467
2475
|
value :
|
|
@@ -2473,34 +2481,21 @@ GenericInput.transformer = {
|
|
|
2473
2481
|
},
|
|
2474
2482
|
// TODO respect local to utc conversion.
|
|
2475
2483
|
'datetime-local': {
|
|
2476
|
-
format: {
|
|
2477
|
-
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
|
|
2484
|
-
|
|
2485
|
-
return ''
|
|
2484
|
+
format: {final: {transform: (value:number):string => {
|
|
2485
|
+
value = typeof value === 'number' ? value : parseFloat(value)
|
|
2486
|
+
|
|
2487
|
+
if (value === Infinity)
|
|
2488
|
+
return 'Infinitely far in the future'
|
|
2489
|
+
if (value === -Infinity)
|
|
2490
|
+
return 'Infinitely early in the past'
|
|
2491
|
+
if (!isFinite(value))
|
|
2492
|
+
return ''
|
|
2486
2493
|
|
|
2487
|
-
|
|
2488
|
-
|
|
2494
|
+
const formattedValue:string =
|
|
2495
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2489
2496
|
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
intermediate: {transform: (
|
|
2493
|
-
value:number,
|
|
2494
|
-
configuration:DefaultProperties<number>,
|
|
2495
|
-
transformer:InputDataTransformation
|
|
2496
|
-
):string =>
|
|
2497
|
-
transformer['datetime-local'].format?.final.transform ?
|
|
2498
|
-
transformer['datetime-local'].format.final.transform(
|
|
2499
|
-
value, configuration, transformer
|
|
2500
|
-
) :
|
|
2501
|
-
`${value}`
|
|
2502
|
-
}
|
|
2503
|
-
},
|
|
2497
|
+
return formattedValue.substring(0, formattedValue.length - 1)
|
|
2498
|
+
}}},
|
|
2504
2499
|
parse: (
|
|
2505
2500
|
value:number|string,
|
|
2506
2501
|
configuration:DefaultProperties<number>,
|
|
@@ -2511,49 +2506,57 @@ GenericInput.transformer = {
|
|
|
2511
2506
|
Date.parse(value as string) / 1000
|
|
2512
2507
|
},
|
|
2513
2508
|
time: {
|
|
2514
|
-
format: {
|
|
2515
|
-
|
|
2516
|
-
|
|
2509
|
+
format: {final: {transform: (
|
|
2510
|
+
value:number, configuration:DefaultProperties<number>
|
|
2511
|
+
):string => {
|
|
2512
|
+
value = typeof value === 'number' ? value : parseFloat(value)
|
|
2513
|
+
|
|
2514
|
+
if (value === Infinity)
|
|
2515
|
+
return 'Infinitely far in the future'
|
|
2516
|
+
if (value === -Infinity)
|
|
2517
|
+
return 'Infinitely early in the past'
|
|
2518
|
+
if (!isFinite(value))
|
|
2519
|
+
return ''
|
|
2517
2520
|
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
if (value === -Infinity)
|
|
2521
|
-
return 'infinitely early in the past'
|
|
2522
|
-
if (!isFinite(value))
|
|
2523
|
-
return ''
|
|
2521
|
+
let formattedValue:string =
|
|
2522
|
+
(new Date(Math.round(value * 1000))).toISOString()
|
|
2524
2523
|
|
|
2525
|
-
|
|
2526
|
-
|
|
2524
|
+
formattedValue = formattedValue.substring(
|
|
2525
|
+
formattedValue.indexOf('T') + 1, formattedValue.length - 1
|
|
2526
|
+
)
|
|
2527
2527
|
|
|
2528
|
+
if (
|
|
2529
|
+
configuration.step &&
|
|
2530
|
+
configuration.step >= 60 &&
|
|
2531
|
+
(configuration.step % 60) === 0
|
|
2532
|
+
)
|
|
2528
2533
|
return formattedValue.substring(
|
|
2529
|
-
formattedValue.
|
|
2534
|
+
0, formattedValue.lastIndexOf(':')
|
|
2530
2535
|
)
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
configuration:DefaultProperties<number>,
|
|
2535
|
-
transformer:InputDataTransformation
|
|
2536
|
-
):string =>
|
|
2537
|
-
transformer.time.format?.final.transform ?
|
|
2538
|
-
transformer.time.format.final.transform(
|
|
2539
|
-
value, configuration, transformer
|
|
2540
|
-
) :
|
|
2541
|
-
`${value}`
|
|
2542
|
-
}
|
|
2543
|
-
},
|
|
2536
|
+
|
|
2537
|
+
return formattedValue
|
|
2538
|
+
}}},
|
|
2544
2539
|
parse: (value:Date|number|string):number =>
|
|
2545
2540
|
typeof value === 'number' ?
|
|
2546
2541
|
value :
|
|
2547
2542
|
value instanceof Date ?
|
|
2548
2543
|
value.getTime() / 1000 :
|
|
2549
|
-
|
|
2550
|
-
/^([0-9]{2}):([0-9]{2})
|
|
2551
|
-
(
|
|
2544
|
+
parseFloat(value.replace(
|
|
2545
|
+
/^([0-9]{2}):([0-9]{2})(:([0-9]{2}(\.[0-9]+)?))?$/,
|
|
2546
|
+
(
|
|
2547
|
+
_match:string,
|
|
2548
|
+
hour:string,
|
|
2549
|
+
minute:string,
|
|
2550
|
+
secondsSuffix?:string,
|
|
2551
|
+
seconds?:string,
|
|
2552
|
+
_millisecondsSuffix?:string
|
|
2553
|
+
):string =>
|
|
2552
2554
|
String(
|
|
2553
2555
|
parseInt(hour) *
|
|
2554
2556
|
60 ** 2 +
|
|
2555
2557
|
parseInt(minute) *
|
|
2556
|
-
60
|
|
2558
|
+
60 +
|
|
2559
|
+
(secondsSuffix ? parseFloat(seconds!) : 0)
|
|
2557
2560
|
)
|
|
2558
2561
|
))
|
|
2559
2562
|
},
|