@linzjs/step-ag-grid 34.0.0 → 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 +25 -8
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +25 -8
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +9 -5
- package/src/components/gridForm/GridFormTextInput.tsx +1 -1
- package/src/contexts/GridContextProvider.tsx +1 -1
- package/src/lui/TextInputFormatted.tsx +25 -2
- package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +1 -0
package/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -172,7 +172,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
172
172
|
// ─── Spread Remaining Params ──────────────────
|
|
173
173
|
...params
|
|
174
174
|
}: GridProps<TData>): ReactElement => {
|
|
175
|
-
|
|
175
|
+
// 'fit' sizing is deterministic flex layout, not content-measured autosize - it doesn't need
|
|
176
|
+
// (and must keep working under) the Chromatic override below.
|
|
177
|
+
if (isChromatic() && sizeColumns !== 'fit') {
|
|
176
178
|
sizeColumns = 'none';
|
|
177
179
|
}
|
|
178
180
|
|
|
@@ -492,13 +494,15 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
492
494
|
'GridCell-readonly': (ccp: CellClassParams<TData>) =>
|
|
493
495
|
!suppressReadOnlyStyle && !editable(ccp as unknown as EditableCallbackParams<TData>),
|
|
494
496
|
},
|
|
495
|
-
// If chromatic we fix the size to minWidth if set otherwise 120px
|
|
496
|
-
//
|
|
497
|
-
|
|
497
|
+
// If chromatic we fix the size to minWidth if set otherwise 120px, so non-deterministic
|
|
498
|
+
// content measurement doesn't affect the snapshot - except under 'fit', which sizes via
|
|
499
|
+
// flex (proportional to the container) rather than measured content, so it's already
|
|
500
|
+
// deterministic and must keep the user's configured width.
|
|
501
|
+
width: isChromatic() && sizeColumns !== 'fit' ? colDef.minWidth || 120 : colDef.width,
|
|
498
502
|
};
|
|
499
503
|
}
|
|
500
504
|
},
|
|
501
|
-
[params.defaultColDef?.editable, params.loading, params.readOnly, suppressReadOnlyStyle],
|
|
505
|
+
[params.defaultColDef?.editable, params.loading, params.readOnly, suppressReadOnlyStyle, sizeColumns],
|
|
502
506
|
);
|
|
503
507
|
|
|
504
508
|
/**
|
|
@@ -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)}
|
|
@@ -451,7 +451,7 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
451
451
|
}, [gridApiOp]);
|
|
452
452
|
|
|
453
453
|
/**
|
|
454
|
-
* Resize columns to fit container
|
|
454
|
+
* Resize columns to fit container.
|
|
455
455
|
*
|
|
456
456
|
* This is used to calculate the preferred size of columns.
|
|
457
457
|
* It sizes the flex columns first and then clears the calculated width.
|
|
@@ -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));
|