@linzjs/step-ag-grid 2.1.2 → 2.2.0
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/README.md +2 -2
- package/dist/index.js +122 -25
- package/dist/index.js.map +1 -1
- package/dist/src/components/Grid.d.ts +1 -0
- package/dist/src/components/GridCell.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormEditBearing.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMessage.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormMultiSelect.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormPopoutMenu.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoverEditBearing.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoverEditDropDown.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoverMenu.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoverMessage.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoverTextArea.d.ts +1 -1
- package/dist/src/components/gridPopoverEdit/GridPopoverTextInput.d.ts +1 -1
- package/dist/src/components/gridRender/GridRenderGenericCell.d.ts +1 -1
- package/dist/src/contexts/GridContext.d.ts +1 -1
- package/dist/src/index.d.ts +29 -28
- package/dist/src/lui/ActionButton.d.ts +15 -0
- package/dist/src/lui/reactUtils.d.ts +6 -0
- package/dist/src/lui/reactUtils.test.d.ts +1 -0
- package/dist/src/lui/stateDeferredHook.d.ts +4 -0
- package/dist/src/lui/timeoutHook.d.ts +8 -0
- package/dist/src/lui/timeoutHook.test.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +123 -27
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +6 -4
- package/src/components/Grid.tsx +5 -4
- package/src/components/GridCell.tsx +7 -7
- package/src/components/GridPopoverHook.tsx +3 -3
- package/src/components/PostSortRowsHook.ts +8 -2
- package/src/components/gridForm/GridFormDropDown.tsx +2 -2
- package/src/components/gridForm/GridFormEditBearing.tsx +2 -2
- package/src/components/gridForm/GridFormMessage.tsx +1 -1
- package/src/components/gridForm/GridFormMultiSelect.tsx +3 -3
- package/src/components/gridForm/GridFormPopoutMenu.tsx +3 -3
- package/src/components/gridForm/GridFormTextArea.tsx +1 -1
- package/src/components/gridForm/GridFormTextInput.tsx +1 -1
- package/src/components/gridPopoverEdit/GridPopoutEditMultiSelect.ts +1 -3
- package/src/components/gridPopoverEdit/GridPopoverEditBearing.ts +2 -4
- package/src/components/gridPopoverEdit/GridPopoverEditDropDown.ts +1 -3
- package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +1 -1
- package/src/components/gridPopoverEdit/GridPopoverMessage.ts +1 -1
- package/src/components/gridPopoverEdit/GridPopoverTextArea.ts +1 -1
- package/src/components/gridPopoverEdit/GridPopoverTextInput.ts +1 -1
- package/src/components/gridRender/GridRenderGenericCell.tsx +2 -2
- package/src/components/gridRender/GridRenderPopoutMenuCell.tsx +1 -1
- package/src/contexts/GridContext.tsx +1 -1
- package/src/contexts/GridContextProvider.tsx +2 -2
- package/src/contexts/GridPopoverContextProvider.tsx +2 -2
- package/src/index.ts +34 -32
- package/src/lui/ActionButton.scss +32 -0
- package/src/lui/ActionButton.tsx +76 -0
- package/src/lui/reactUtils.test.tsx +47 -0
- package/src/lui/reactUtils.tsx +14 -0
- package/src/lui/stateDeferredHook.tsx +29 -0
- package/src/lui/timeoutHook.test.tsx +38 -0
- package/src/lui/timeoutHook.tsx +40 -0
- package/src/react-menu3/components/ControlledMenu.tsx +1 -1
- package/src/stories/components/ActionButton.stories.tsx +33 -0
- package/src/stories/{components → grid}/FormTest.scss +0 -0
- package/src/stories/{components → grid}/FormTest.tsx +4 -4
- package/src/stories/{components → grid}/GridPopoutBearing.stories.tsx +13 -16
- package/src/stories/{components → grid}/GridPopoutEditDropDown.stories.tsx +27 -30
- package/src/stories/{components → grid}/GridPopoutEditGeneric.stories.tsx +10 -13
- package/src/stories/{components → grid}/GridPopoutEditGenericTextArea.stories.tsx +64 -25
- package/src/stories/{components → grid}/GridPopoutEditMultiSelect.stories.tsx +15 -18
- package/src/stories/{components → grid}/GridReadOnly.stories.tsx +13 -15
- package/src/stories/{components → react-menu}/ReactMenu.stories.tsx +2 -2
package/README.md
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
> Reusable [ag-grid](https://www.ag-grid.com/) component for LINZ / Toitū te whenua.
|
|
4
4
|
|
|
5
|
-
Storybook deployed at: https://linz.github.io/step-ag-grid/
|
|
6
|
-
|
|
7
5
|
## Features
|
|
8
6
|
|
|
9
7
|
- [ag-grid-community](https://www.npmjs.com/package/ag-grid-community) based grid with custom popover components
|
|
@@ -39,6 +37,8 @@ yarn add @linz/step-ag-grid
|
|
|
39
37
|
npm run storybook
|
|
40
38
|
```
|
|
41
39
|
|
|
40
|
+
Storybook demo deployed at: https://linz.github.io/step-ag-grid/
|
|
41
|
+
|
|
42
42
|
## Usage
|
|
43
43
|
|
|
44
44
|
```tsx
|
package/dist/index.js
CHANGED
|
@@ -2218,7 +2218,11 @@ var usePostSortRowsHook = function (_a) {
|
|
|
2218
2218
|
var restorePreviousSortColumnState = function () { return columnApi.applyColumnState({ state: previousColSort.current }); };
|
|
2219
2219
|
var hasNewRows = function () { return nodes.some(function (row) { return previousRowSortIndex[row.data.id] == null; }); };
|
|
2220
2220
|
var sortIsStale = function () {
|
|
2221
|
-
|
|
2221
|
+
// If there are new rows we want to them to be at the bottom of the grid, so we treat it as sort not stale
|
|
2222
|
+
if (hasNewRows())
|
|
2223
|
+
return false;
|
|
2224
|
+
// Otherwise check if the stored sort index matches the new sort index
|
|
2225
|
+
return nodes.some(function (node, index) { return previousRowSortIndex[node.data.id] != index; });
|
|
2222
2226
|
};
|
|
2223
2227
|
var sortNodesByPreviousSort = function () {
|
|
2224
2228
|
return nodes.sort(function (a, b) {
|
|
@@ -2274,6 +2278,7 @@ var usePostSortRowsHook = function (_a) {
|
|
|
2274
2278
|
if (!sortWasStale.current) {
|
|
2275
2279
|
// backup sort state, so we can restore it when sort is clicked on a stale column
|
|
2276
2280
|
previousColSort.current = copyCurrentSortSettings();
|
|
2281
|
+
backupSortOrder();
|
|
2277
2282
|
sortWasStale.current = true;
|
|
2278
2283
|
setStaleGrid(true);
|
|
2279
2284
|
}
|
|
@@ -2323,12 +2328,12 @@ var GridHeaderSelect = function (_a) {
|
|
|
2323
2328
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
2324
2329
|
*/
|
|
2325
2330
|
var Grid = function (params) {
|
|
2326
|
-
var _a;
|
|
2327
|
-
var
|
|
2331
|
+
var _a, _b;
|
|
2332
|
+
var _c = react.useContext(GridContext), gridReady = _c.gridReady, setGridApi = _c.setGridApi, setQuickFilter = _c.setQuickFilter, ensureRowVisible = _c.ensureRowVisible, selectRowsById = _c.selectRowsById, ensureSelectedRowIsVisible = _c.ensureSelectedRowIsVisible, sizeColumnsToFit = _c.sizeColumnsToFit;
|
|
2328
2333
|
var checkUpdating = react.useContext(GridUpdatingContext).checkUpdating;
|
|
2329
|
-
var
|
|
2334
|
+
var _d = react.useState(""), internalQuickFilter = _d[0], setInternalQuickFilter = _d[1];
|
|
2330
2335
|
var lastSelectedIds = react.useRef([]);
|
|
2331
|
-
var
|
|
2336
|
+
var _e = react.useState(false), staleGrid = _e[0], setStaleGrid = _e[1];
|
|
2332
2337
|
var postSortRows = usePostSortRowsHook({ setStaleGrid: setStaleGrid });
|
|
2333
2338
|
/**
|
|
2334
2339
|
* AgGrid checkbox select does not pass clicks within cell but not on the checkbox to checkbox.
|
|
@@ -2472,7 +2477,7 @@ var Grid = function (params) {
|
|
|
2472
2477
|
}, [columnDefs === null || columnDefs === void 0 ? void 0 : columnDefs.length, sizeColumnsToFit]);
|
|
2473
2478
|
return (jsxRuntime.jsxs("div", __assign({ "data-testid": params.dataTestId, className: clsx("Grid-container", "ag-theme-alpine", staleGrid && "Grid-sortIsStale") }, { children: [params.quickFilter && (jsxRuntime.jsx("div", __assign({ className: "Grid-quickFilter" }, { children: jsxRuntime.jsx("input", { "aria-label": "Search", className: "lui-margin-top-xxs lui-margin-bottom-xxs Grid-quickFilterBox", type: "text", placeholder: (_a = params.quickFilterPlaceholder) !== null && _a !== void 0 ? _a : "Search...", value: internalQuickFilter, onChange: function (event) {
|
|
2474
2479
|
setInternalQuickFilter(event.target.value);
|
|
2475
|
-
} }) }))), jsxRuntime.jsx(agGridReact.AgGridReact, { getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: "multiple", suppressBrowserResizeObserver: true, colResizeDefault: "shift", onFirstDataRendered: sizeColumnsToFit, onGridSizeChanged: sizeColumnsToFit, suppressClickEdit: true, onCellKeyDown: onCellKeyDown, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, columnDefs: columnDefs, rowData: params.rowData, noRowsOverlayComponent: noRowsOverlayComponent, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection })] })));
|
|
2480
|
+
} }) }))), jsxRuntime.jsx(agGridReact.AgGridReact, { getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: "multiple", suppressBrowserResizeObserver: true, colResizeDefault: "shift", onFirstDataRendered: sizeColumnsToFit, onGridSizeChanged: sizeColumnsToFit, suppressClickEdit: true, onCellKeyDown: onCellKeyDown, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, columnDefs: columnDefs, rowData: params.rowData, noRowsOverlayComponent: noRowsOverlayComponent, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_b = params.postSortRows) !== null && _b !== void 0 ? _b : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection })] })));
|
|
2476
2481
|
};
|
|
2477
2482
|
|
|
2478
2483
|
var GenericMultiEditCellClass = function (props) {
|
|
@@ -2515,11 +2520,11 @@ function styleInject(css, ref) {
|
|
|
2515
2520
|
}
|
|
2516
2521
|
}
|
|
2517
2522
|
|
|
2518
|
-
var css_248z$
|
|
2519
|
-
styleInject(css_248z$
|
|
2523
|
+
var css_248z$7 = ".AgGridGenericCellRenderer-icon{margin-right:4px}.AgGridGenericCellRenderer-ic_infoIcon{fill:#3a7cdf;margin-right:4px}.AgGridGenericCellRenderer-ic_warningIcon{fill:#ea6a2e;margin-right:4px}";
|
|
2524
|
+
styleInject(css_248z$7);
|
|
2520
2525
|
|
|
2521
|
-
var css_248z$
|
|
2522
|
-
styleInject(css_248z$
|
|
2526
|
+
var css_248z$6 = ".GridLoadableCell-container{align-items:center;display:flex}";
|
|
2527
|
+
styleInject(css_248z$6);
|
|
2523
2528
|
|
|
2524
2529
|
var GridLoadableCell = function (props) {
|
|
2525
2530
|
if (props.isLoading) {
|
|
@@ -2614,7 +2619,7 @@ var GridCellRenderer = function (props) {
|
|
|
2614
2619
|
return ((_a = colDef === null || colDef === void 0 ? void 0 : colDef.cellRendererParams) === null || _a === void 0 ? void 0 : _a.originalCellRenderer) ? (jsxRuntime.jsx(GridLoadableCell, __assign({ isLoading: checkUpdating((_c = (_b = colDef.field) !== null && _b !== void 0 ? _b : colDef.colId) !== null && _c !== void 0 ? _c : "", props.data.id) }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [typeof warningText === "string" && jsxRuntime.jsx(GridIcon, { icon: "ic_warning", title: warningText }), typeof infoText === "string" && jsxRuntime.jsx(GridIcon, { icon: "ic_info", title: infoText }), jsxRuntime.jsx(colDef.cellRendererParams.originalCellRenderer, __assign({}, props))] }) }))) : (jsxRuntime.jsx(GridRendererGenericCell, __assign({}, props)));
|
|
2615
2620
|
};
|
|
2616
2621
|
/*
|
|
2617
|
-
*
|
|
2622
|
+
* All cells should use this
|
|
2618
2623
|
*/
|
|
2619
2624
|
var GridCell = function (props, custom) {
|
|
2620
2625
|
var _a;
|
|
@@ -2650,7 +2655,7 @@ var GenericCellEditorComponent3 = function (props) {
|
|
|
2650
2655
|
var multiEdit = (_a = cellEditorParams === null || cellEditorParams === void 0 ? void 0 : cellEditorParams.multiEdit) !== null && _a !== void 0 ? _a : false;
|
|
2651
2656
|
// TODO don't need all these props in context
|
|
2652
2657
|
setProps(props, multiEdit);
|
|
2653
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(
|
|
2658
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(colDef.cellRenderer, __assign({}, props)), (props === null || props === void 0 ? void 0 : props.editor) && jsxRuntime.jsx(props.editor, __assign({}, cellEditorParams, propsRef.current))] }));
|
|
2654
2659
|
};
|
|
2655
2660
|
|
|
2656
2661
|
/**
|
|
@@ -2741,11 +2746,11 @@ var GridRenderPopoutMenuCell = function (props) {
|
|
|
2741
2746
|
return (jsxRuntime.jsx(GridLoadableCell, __assign({ isLoading: isLoading, className: disabled ? "GridPopoutMenu-burgerDisabled" : "GridPopoutMenu-burger" }, { children: jsxRuntime.jsx(lui.LuiIcon, { name: "ic_more_vert", alt: "More actions", size: "md" }) })));
|
|
2742
2747
|
};
|
|
2743
2748
|
|
|
2744
|
-
var css_248z$
|
|
2745
|
-
styleInject(css_248z$
|
|
2749
|
+
var css_248z$5 = ".GridMultiSelect-containerSmall .GridFormMultiSelect-options{max-height:130px;overflow-y:auto}.GridMultiSelect-containerMedium .GridFormMultiSelect-options{max-height:190px;overflow-y:auto}.GridMultiSelect-containerLarge .GridFormMultiSelect-options{max-height:320px;overflow-y:auto}.GridMultiSelect-containerUnlimited .GridFormMultiSelect-options{overflow-y:auto}";
|
|
2750
|
+
styleInject(css_248z$5);
|
|
2746
2751
|
|
|
2747
|
-
var css_248z$
|
|
2748
|
-
styleInject(css_248z$
|
|
2752
|
+
var css_248z$4 = ".GridPopoverEditDropDown-containerSmall .GridFormDropDown-options{max-height:120px;overflow-y:auto}.GridPopoverEditDropDown-containerMedium .GridFormDropDown-options{max-height:200px;overflow-y:auto}.GridPopoverEditDropDown-containerLarge .GridFormDropDown-options{max-height:400px;overflow-y:auto}.GridPopoverEditDropDown-containerUnlimited .GridFormDropDown-options{overflow-y:auto}";
|
|
2753
|
+
styleInject(css_248z$4);
|
|
2749
2754
|
|
|
2750
2755
|
/* global setTimeout, clearTimeout */
|
|
2751
2756
|
|
|
@@ -3114,11 +3119,11 @@ var GridFormMultiSelect = function (props) {
|
|
|
3114
3119
|
};
|
|
3115
3120
|
|
|
3116
3121
|
var GridPopoutEditMultiSelect = function (colDef, props) {
|
|
3117
|
-
return GridCell(__assign({ initialWidth: 65, maxWidth: 150
|
|
3122
|
+
return GridCell(__assign({ initialWidth: 65, maxWidth: 150 }, colDef), __assign(__assign({ editor: GridFormMultiSelect }, props), { editorParams: __assign({ className: "GridMultiSelect-containerMedium" }, props.editorParams) }));
|
|
3118
3123
|
};
|
|
3119
3124
|
|
|
3120
|
-
var css_248z$
|
|
3121
|
-
styleInject(css_248z$
|
|
3125
|
+
var css_248z$3 = ".GridPopoutMenu-burger{cursor:pointer}.GridPopoutMenu-burger svg{fill:#007198}.GridPopoutMenu-burgerDisabled svg{fill:#989189}";
|
|
3126
|
+
styleInject(css_248z$3);
|
|
3122
3127
|
|
|
3123
3128
|
/** Menu configuration types **/
|
|
3124
3129
|
var PopoutMenuSeparator = Object.freeze({ __isMenuSeparator__: true });
|
|
@@ -3281,11 +3286,11 @@ var convertDDToDMS = function (dd, showPositiveSymbol, addTrailingZeros) {
|
|
|
3281
3286
|
return dmsString;
|
|
3282
3287
|
};
|
|
3283
3288
|
|
|
3284
|
-
var css_248z$
|
|
3285
|
-
styleInject(css_248z$
|
|
3289
|
+
var css_248z$2 = ".GridFormEditBearing-input{width:320px}";
|
|
3290
|
+
styleInject(css_248z$2);
|
|
3286
3291
|
|
|
3287
|
-
var css_248z = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#beb9b4;line-height:48px;position:absolute;right:14px;top:0}";
|
|
3288
|
-
styleInject(css_248z);
|
|
3292
|
+
var css_248z$1 = ".LuiTextInput{margin-bottom:0}.LuiTextInput-formatted{color:#beb9b4;line-height:48px;position:absolute;right:14px;top:0}";
|
|
3293
|
+
styleInject(css_248z$1);
|
|
3289
3294
|
|
|
3290
3295
|
var TextInputFormatted = function (props) {
|
|
3291
3296
|
return (jsxRuntime.jsxs("div", __assign({ className: clsx("LuiTextInput Grid-popoverContainer", props.error && "hasError", props.warning && "hasWarning", props.className) }, { children: [jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-inputWrapper" }, { children: [jsxRuntime.jsx("input", __assign({ type: "text", className: "LuiTextInput-input", min: "0", value: props.value, onChange: props.onChange }, props.inputProps)), jsxRuntime.jsx("span", __assign({ className: "LuiTextInput-formatted" }, { children: props.formatted }))] })), props.error && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-error" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "error", name: "ic_error", className: "LuiTextInput-error-icon", size: "sm", status: "error" }), props.error] }))), props.warning && (jsxRuntime.jsxs("span", __assign({ className: "LuiTextInput-warning" }, { children: [jsxRuntime.jsx(lui.LuiIcon, { alt: "warning", name: "ic_warning", className: "LuiTextInput-warning-icon", size: "sm", status: "warning" }), props.warning] })))] })));
|
|
@@ -3338,7 +3343,7 @@ var GridFormEditBearing = function (_props) {
|
|
|
3338
3343
|
};
|
|
3339
3344
|
|
|
3340
3345
|
var GridPopoverEditBearingLike = function (colDef, props) {
|
|
3341
|
-
return GridCell(__assign({ initialWidth: 65, maxWidth: 150, valueFormatter: bearingValueFormatter
|
|
3346
|
+
return GridCell(__assign({ initialWidth: 65, maxWidth: 150, valueFormatter: bearingValueFormatter }, colDef), __assign({ editor: GridFormEditBearing }, props));
|
|
3342
3347
|
};
|
|
3343
3348
|
var GridPopoverEditBearing = function (colDef, props) {
|
|
3344
3349
|
return GridPopoverEditBearingLike(__assign({ valueFormatter: bearingValueFormatter }, colDef), {
|
|
@@ -3370,7 +3375,7 @@ var GridPopoverEditBearingCorrection = function (colDef, props) {
|
|
|
3370
3375
|
};
|
|
3371
3376
|
|
|
3372
3377
|
var GridPopoverEditDropDown = function (colDef, props) {
|
|
3373
|
-
return GridCell(__assign({ initialWidth: 65, maxWidth: 150
|
|
3378
|
+
return GridCell(__assign({ initialWidth: 65, maxWidth: 150 }, colDef), __assign(__assign({ editor: GridFormDropDown }, props), { editorParams: __assign({
|
|
3374
3379
|
// Defaults to medium size container
|
|
3375
3380
|
className: "GridPopoverEditDropDown-containerMedium" }, props.editorParams) }));
|
|
3376
3381
|
};
|
|
@@ -3587,6 +3592,98 @@ var GridSubComponentTextArea = function (props) {
|
|
|
3587
3592
|
return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx("textarea", { autoFocus: true, maxLength: 10000, spellCheck: true, className: "free-text-input", onChange: function (e) { return setValue(e.target.value); }, defaultValue: value }) })));
|
|
3588
3593
|
};
|
|
3589
3594
|
|
|
3595
|
+
var css_248z = ".ActionButton{align-items:center;display:flex}.ActionButton .LuiIcon{margin:0 4px!important}.ActionButton-minimalArea{position:relative}.ActionButton-minimalAreaDisplay{position:absolute}.ActionButton-minimalAreaExpand{visibility:hidden}.ActionButton-inProgress{background-color:#e2f3f7!important;color:#007198!important;cursor:progress}.ActionButton-inProgress svg *{fill:#0000!important}";
|
|
3596
|
+
styleInject(css_248z);
|
|
3597
|
+
|
|
3598
|
+
/**
|
|
3599
|
+
* Track previous values of states.
|
|
3600
|
+
*
|
|
3601
|
+
* @param value Value to track.
|
|
3602
|
+
*/
|
|
3603
|
+
var usePrevious = function (value) {
|
|
3604
|
+
var ref = react.useRef();
|
|
3605
|
+
react.useEffect(function () {
|
|
3606
|
+
ref.current = value;
|
|
3607
|
+
}, [value]);
|
|
3608
|
+
return ref.current;
|
|
3609
|
+
};
|
|
3610
|
+
|
|
3611
|
+
/**
|
|
3612
|
+
* Cancels timeouts on scope being destroyed.
|
|
3613
|
+
*
|
|
3614
|
+
* This could almost be a debounce, but debounce tracks by function reference, this tracks by hook reference.
|
|
3615
|
+
* This could have been implemented using debounce if the callers function was wrapped in useCallback,
|
|
3616
|
+
* but there's no way to enforce that, so it would lead to bugs.
|
|
3617
|
+
*/
|
|
3618
|
+
var useTimeoutHook = function () {
|
|
3619
|
+
var timeout = react.useRef();
|
|
3620
|
+
/**
|
|
3621
|
+
* Clear any pending timeouts.
|
|
3622
|
+
*/
|
|
3623
|
+
var clearTimeouts = function () {
|
|
3624
|
+
if (timeout.current) {
|
|
3625
|
+
var tc = timeout.current;
|
|
3626
|
+
timeout.current = undefined;
|
|
3627
|
+
clearTimeout(tc);
|
|
3628
|
+
}
|
|
3629
|
+
};
|
|
3630
|
+
/**
|
|
3631
|
+
* Call this when your action has completed.
|
|
3632
|
+
*/
|
|
3633
|
+
var invoke = react.useCallback(function (fn, waitTimeMs) {
|
|
3634
|
+
clearTimeouts();
|
|
3635
|
+
timeout.current = setTimeout(fn, waitTimeMs);
|
|
3636
|
+
}, []);
|
|
3637
|
+
/**
|
|
3638
|
+
* Clear timeout on loss of scope.
|
|
3639
|
+
*/
|
|
3640
|
+
react.useEffect(function () {
|
|
3641
|
+
return function () { return clearTimeouts(); };
|
|
3642
|
+
}, []);
|
|
3643
|
+
return invoke;
|
|
3644
|
+
};
|
|
3645
|
+
|
|
3646
|
+
/**
|
|
3647
|
+
* Defers state change up to a minimum time since last state change.
|
|
3648
|
+
*/
|
|
3649
|
+
var useStateDeferred = function (initialValue) {
|
|
3650
|
+
var startTime = react.useRef(0);
|
|
3651
|
+
var timeoutHook = useTimeoutHook();
|
|
3652
|
+
var _a = react.useState(initialValue), value = _a[0], _setValue = _a[1];
|
|
3653
|
+
var setValue = react.useCallback(function (newValue) {
|
|
3654
|
+
startTime.current = Date.now();
|
|
3655
|
+
_setValue(newValue);
|
|
3656
|
+
}, []);
|
|
3657
|
+
var setValueDeferred = react.useCallback(function (newValue, minimumWaitTimeMs) {
|
|
3658
|
+
var waitTimeMs = Math.max(minimumWaitTimeMs - (Date.now() - startTime.current), 0);
|
|
3659
|
+
timeoutHook(function () { return _setValue(newValue); }, waitTimeMs);
|
|
3660
|
+
}, [timeoutHook]);
|
|
3661
|
+
return [value, setValue, setValueDeferred];
|
|
3662
|
+
};
|
|
3663
|
+
|
|
3664
|
+
// Kept this less than one second, so I don't have issues with waitFor as it defaults to 1s
|
|
3665
|
+
var minimumInProgressTimeMs = 950;
|
|
3666
|
+
var ActionButton = function (_a) {
|
|
3667
|
+
var _b;
|
|
3668
|
+
var _c;
|
|
3669
|
+
var icon = _a.icon, name = _a.name, inProgressName = _a.inProgressName, dataTestId = _a.dataTestId, inProgress = _a.inProgress, className = _a.className, title = _a.title, onClick = _a.onClick, _d = _a.size, size = _d === void 0 ? "sm" : _d;
|
|
3670
|
+
var lastInProgress = usePrevious(inProgress !== null && inProgress !== void 0 ? inProgress : false);
|
|
3671
|
+
var _e = useStateDeferred(!!inProgress), localInProgress = _e[0], setLocalInProgress = _e[1], setLocalInProgressDeferred = _e[2];
|
|
3672
|
+
react.useEffect(function () {
|
|
3673
|
+
if (inProgress == lastInProgress)
|
|
3674
|
+
return;
|
|
3675
|
+
inProgress ? setLocalInProgress(true) : setLocalInProgressDeferred(false, minimumInProgressTimeMs);
|
|
3676
|
+
}, [inProgress, lastInProgress, setLocalInProgress, setLocalInProgressDeferred]);
|
|
3677
|
+
return (jsxRuntime.jsxs(lui.LuiButton, __assign({ "data-testid": dataTestId, type: "button", level: "tertiary", title: title !== null && title !== void 0 ? title : name, "aria-label": name, className: clsx("lui-button-icon", "ActionButton", className, localInProgress && "ActionButton-inProgress"), size: "lg", onClick: onClick, disabled: localInProgress }, { children: [localInProgress ? (jsxRuntime.jsx(lui.LuiMiniSpinner, { size: 16, divProps: (_b = {
|
|
3678
|
+
"data-testid": "loading-spinner",
|
|
3679
|
+
style: { padding: 0, margin: 0, paddingRight: 8 },
|
|
3680
|
+
role: "status"
|
|
3681
|
+
},
|
|
3682
|
+
_b["aria-label"] = "Loading",
|
|
3683
|
+
_b) })) : (jsxRuntime.jsx(lui.LuiIcon, { name: icon, alt: name, size: size })), jsxRuntime.jsxs("span", __assign({ className: "ActionButton-minimalArea" }, { children: [jsxRuntime.jsx("span", __assign({ className: "ActionButton-minimalAreaDisplay" }, { children: (_c = (localInProgress ? inProgressName : name)) !== null && _c !== void 0 ? _c : name })), jsxRuntime.jsx("span", __assign({ className: "ActionButton-minimalAreaExpand" }, { children: name }))] }))] })));
|
|
3684
|
+
};
|
|
3685
|
+
|
|
3686
|
+
exports.ActionButton = ActionButton;
|
|
3590
3687
|
exports.ComponentLoadingWrapper = ComponentLoadingWrapper;
|
|
3591
3688
|
exports.ControlledMenu = ControlledMenu;
|
|
3592
3689
|
exports.FocusableItem = FocusableItem;
|