@linzjs/step-ag-grid 34.0.1 → 34.0.2
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/src/lui/TextInputFormatted.d.ts +1 -0
- package/dist/step-ag-grid.cjs +18 -3
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +18 -3
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/gridForm/GridFormTextInput.tsx +1 -1
- package/src/lui/TextInputFormatted.tsx +25 -2
- package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +1 -0
package/package.json
CHANGED
|
@@ -73,8 +73,8 @@ export const GridFormTextInput = <TData extends GridBaseRow>(props: GridFormText
|
|
|
73
73
|
setValue(e.target.value);
|
|
74
74
|
}}
|
|
75
75
|
error={invalid()}
|
|
76
|
+
width={props.width ?? 264}
|
|
76
77
|
formatted={props.units}
|
|
77
|
-
style={{ width: props.width ?? 240 }}
|
|
78
78
|
placeholder={props.placeholder ?? 'Type here'}
|
|
79
79
|
helpText={helpText}
|
|
80
80
|
validationSummary={textInputValidatorPropsToSummary(props)}
|
|
@@ -2,13 +2,14 @@ import './TextInputFormatted.scss';
|
|
|
2
2
|
|
|
3
3
|
import clsx from 'clsx';
|
|
4
4
|
import { omit } from 'lodash-es';
|
|
5
|
-
import { DetailedHTMLProps, InputHTMLAttributes, ReactElement } from 'react';
|
|
5
|
+
import { DetailedHTMLProps, InputHTMLAttributes, ReactElement, useLayoutEffect, useRef, useState } from 'react';
|
|
6
6
|
|
|
7
7
|
import { FormError } from './FormError';
|
|
8
8
|
|
|
9
9
|
export interface LuiTextInputProps extends DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> {
|
|
10
10
|
// overrides value in base class to be string type only
|
|
11
11
|
value: string;
|
|
12
|
+
width?: string | number;
|
|
12
13
|
|
|
13
14
|
// Custom fields
|
|
14
15
|
helpText?: string;
|
|
@@ -18,7 +19,23 @@ export interface LuiTextInputProps extends DetailedHTMLProps<InputHTMLAttributes
|
|
|
18
19
|
validationSummary?: string;
|
|
19
20
|
}
|
|
20
21
|
|
|
22
|
+
// gap between the end of the typed text and the start of the formatted units label
|
|
23
|
+
const FORMATTED_GAP = 8;
|
|
24
|
+
|
|
21
25
|
export const TextInputFormatted = (props: LuiTextInputProps): ReactElement => {
|
|
26
|
+
const formattedRef = useRef<HTMLSpanElement>(null);
|
|
27
|
+
const [formattedPadding, setFormattedPadding] = useState<number | undefined>(undefined);
|
|
28
|
+
|
|
29
|
+
useLayoutEffect(() => {
|
|
30
|
+
if (!props.formatted) {
|
|
31
|
+
setFormattedPadding(undefined);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const formattedWidth = formattedRef.current?.offsetWidth ?? 0;
|
|
35
|
+
// right offset the formatted span sits at, see TextInputFormatted.scss
|
|
36
|
+
setFormattedPadding(formattedWidth + 14 + FORMATTED_GAP);
|
|
37
|
+
}, [props.formatted]);
|
|
38
|
+
|
|
22
39
|
return (
|
|
23
40
|
<div
|
|
24
41
|
className={clsx(
|
|
@@ -26,6 +43,7 @@ export const TextInputFormatted = (props: LuiTextInputProps): ReactElement => {
|
|
|
26
43
|
props.error && 'hasError',
|
|
27
44
|
props.className,
|
|
28
45
|
)}
|
|
46
|
+
style={{ width: props.width, ...props.style }}
|
|
29
47
|
>
|
|
30
48
|
<span className="LuiTextInput-inputWrapper">
|
|
31
49
|
{/* wrapper div used for error styling */}
|
|
@@ -35,14 +53,17 @@ export const TextInputFormatted = (props: LuiTextInputProps): ReactElement => {
|
|
|
35
53
|
defaultValue={props.value}
|
|
36
54
|
{...omit(props, [
|
|
37
55
|
'error',
|
|
56
|
+
'width',
|
|
38
57
|
'value',
|
|
39
58
|
'helpText',
|
|
40
59
|
'formatted',
|
|
41
60
|
'className',
|
|
42
61
|
'allowTabToSave',
|
|
43
62
|
'validationSummary',
|
|
63
|
+
'style',
|
|
44
64
|
])}
|
|
45
65
|
className={'LuiTextInput-input'}
|
|
66
|
+
style={formattedPadding != null ? { paddingRight: formattedPadding } : undefined}
|
|
46
67
|
onMouseEnter={(e) => {
|
|
47
68
|
e.currentTarget.focus();
|
|
48
69
|
props.onMouseEnter?.(e);
|
|
@@ -50,7 +71,9 @@ export const TextInputFormatted = (props: LuiTextInputProps): ReactElement => {
|
|
|
50
71
|
data-allowtabtosave={props.allowTabToSave}
|
|
51
72
|
data-validationsummary={props.validationSummary}
|
|
52
73
|
/>
|
|
53
|
-
<span className={'LuiTextInput-formatted'}
|
|
74
|
+
<span className={'LuiTextInput-formatted'} ref={formattedRef}>
|
|
75
|
+
{props.formatted}
|
|
76
|
+
</span>
|
|
54
77
|
</span>
|
|
55
78
|
|
|
56
79
|
<FormError error={props.error} helpText={props.helpText} />
|
|
@@ -9,6 +9,7 @@ const Template = (props: GridFormTextInputProps<any>) => {
|
|
|
9
9
|
['Text input', {}],
|
|
10
10
|
['Text input with text', {}, 'Some text'],
|
|
11
11
|
['Text input with error & placeholder', { required: true, placeholder: 'Custom placeholder' }],
|
|
12
|
+
['Text input with units', { units: 'km/h', maxLength: 1 }, '123456789'],
|
|
12
13
|
];
|
|
13
14
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
14
15
|
const anchorRefs = configs.map(() => useRef<HTMLHeadingElement>(null));
|