diff --git a/demo/src/equipment-search.tsx b/demo/src/equipment-search.tsx index 76f1d1db..107934e7 100644 --- a/demo/src/equipment-search.tsx +++ b/demo/src/equipment-search.tsx @@ -15,7 +15,7 @@ import { equipmentStyles, EquipmentType, useElementSearch, -} from '../../src/index'; +} from '../../src'; interface AnyElementInterface { id: string; diff --git a/demo/src/right-resizable-box.jsx b/demo/src/right-resizable-box.tsx similarity index 73% rename from demo/src/right-resizable-box.jsx rename to demo/src/right-resizable-box.tsx index e6830167..6f2c31ad 100644 --- a/demo/src/right-resizable-box.jsx +++ b/demo/src/right-resizable-box.tsx @@ -4,15 +4,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -/* eslint-disable import/no-extraneous-dependencies */ -import { useState } from 'react'; +import { type PropsWithChildren, useState } from 'react'; import { MoreVert as ResizePanelHandleIcon } from '@mui/icons-material'; -import { ResizableBox } from 'react-resizable'; +// eslint-disable-next-line import/no-extraneous-dependencies +import { ResizableBox, type ResizableBoxProps } from 'react-resizable'; +// eslint-disable-next-line import/no-extraneous-dependencies import { useWindowWidth } from '@react-hook/window-size'; -import PropTypes from 'prop-types'; import { Box, styled } from '@mui/material'; -import { mergeSx } from '../../src/utils/styles'; +import { mergeSx, type MuiStyles } from '../../src/utils/styles'; const styles = { panel: { @@ -47,25 +47,35 @@ const styles = { color: theme.palette.text.disabled, transform: 'scale(0.5, 1.5)', }), -}; +} as const satisfies MuiStyles; // TODO can we avoid to define a component just to add sx support ? const ResizableBoxSx = styled(ResizableBox)({}); -function RightResizableBox(props) { - const { children, disableResize = false, fullscreen = false, hide = false } = props; +export type RightResizableBoxProps = PropsWithChildren<{ + disableResize?: boolean; + fullscreen?: boolean; + hide?: boolean; +}>; + +export default function RightResizableBox({ + children, + disableResize = false, + fullscreen = false, + hide = false, +}: Readonly) { const windowWidth = useWindowWidth(); const [resizedTreePercentage, setResizedTreePercentage] = useState(0.5); - const updateResizedTreePercentage = (treePanelWidth, totalWidth) => { + const updateResizedTreePercentage = (treePanelWidth: number, totalWidth: number) => { if (totalWidth > 0) { const newPercentage = treePanelWidth / totalWidth; setResizedTreePercentage(newPercentage); } }; // eslint-disable-next-line @typescript-eslint/no-unused-vars - const onResize = (event, { element, size }) => { + const onResize: NonNullable = (_event, { size }) => { updateResizedTreePercentage(size.width, windowWidth); }; @@ -73,7 +83,7 @@ function RightResizableBox(props) { ); } - -RightResizableBox.propTypes = { - children: PropTypes.node, - disableResize: PropTypes.bool, - fullscreen: PropTypes.bool, - hide: PropTypes.bool, -}; - -export default RightResizableBox; diff --git a/src/components/customAGGrid/customAggrid.style.ts b/src/components/customAGGrid/customAggrid.style.ts index 74a7fada..b277e12a 100644 --- a/src/components/customAGGrid/customAggrid.style.ts +++ b/src/components/customAGGrid/customAggrid.style.ts @@ -15,9 +15,13 @@ export const styles = { position: 'relative', [`&.${CUSTOM_AGGRID_THEME}`]: { - '--ag-value-change-value-highlight-background-color': theme.aggrid.valueChangeHighlightBackgroundColor, - '--ag-selected-row-background-color': theme.aggrid.highlightColor, - '--ag-row-hover-color': theme.aggrid.highlightColor, + ...(theme.agGrid?.valueChangeHighlightBackgroundColor && { + '--ag-value-change-value-highlight-background-color': theme.agGrid.valueChangeHighlightBackgroundColor, + }), + ...(theme.agGrid?.highlightColor && { + '--ag-selected-row-background-color': theme.agGrid.highlightColor, + '--ag-row-hover-color': theme.agGrid.highlightColor, + }), }, '& .ag-checkbox-input': { diff --git a/src/components/customAGGrid/customAggrid.tsx b/src/components/customAGGrid/customAggrid.tsx index 1df51e84..e206fcda 100644 --- a/src/components/customAGGrid/customAggrid.tsx +++ b/src/components/customAGGrid/customAggrid.tsx @@ -53,6 +53,7 @@ function onColumnResized({ api, column, finished, source }: ColumnResizedEvent) } } +// TODO try to expose of props that forwardRef don't permit export const CustomAGGrid = forwardRef( ({ overrideLocales, sx, ...agGridReactProps }, ref) => { const theme = useTheme(); @@ -61,7 +62,7 @@ export const CustomAGGrid = forwardRef( ({ - grid: (theme: any) => ({ - width: 'auto', - height: '100%', - position: 'relative', - - // - AG Grid colors override - - // It shouldn't be exactly like this, but I couldn't make it works otherwise - // https://www.ag-grid.com/react-data-grid/global-style-customisation/ - '--ag-alpine-active-color': `${theme.palette.primary.main} !important`, - '--ag-checkbox-indeterminate-color': `${theme.palette.primary.main} !important`, - '--ag-background-color': `${theme.agGridBackground.color} !important`, - '--ag-header-background-color': `${theme.agGridBackground.color} !important`, - '--ag-odd-row-background-color': `${theme.agGridBackground.color} !important`, - '--ag-modal-overlay-background-color': `${theme.agGridBackground.color} !important`, - '--ag-selected-row-background-color': 'transparent !important', - '--ag-range-selection-border-color': 'transparent !important', - - // overrides the default computed max height for ag grid default selector editor to make it more usable - // can be removed if a custom selector editor is implemented - '& .ag-select-list': { - maxHeight: '300px !important', - }, - '& .ag-root-wrapper-body': { - maxHeight: '500px', - }, - '& .ag-cell': { - boxShadow: 'none', - }, - '& .ag-cell-edit-wrapper': { - height: 'inherit', - }, - '& .ag-row-hover': { - cursor: 'text', - }, - '& .ag-overlay-loading-center': { - border: 'none', - boxShadow: 'none', - }, - '& .numeric-input': { - fontSize: 'calc(var(--ag-font-size) + 1px)', - paddingLeft: 'calc(var(--ag-cell-horizontal-padding) - 1px)', - width: '100%', +const style = (customProps: CSSObject) => + ({ + grid: (theme) => ({ + width: 'auto', height: '100%', - border: 'inherit', - outline: 'inherit', - backgroundColor: theme.agGridBackground.color, - }, - '& .Mui-focused .MuiOutlinedInput-root': { - // borders moves row height - outline: 'var(--ag-borders-input) var(--ag-input-focus-border-color)', - outlineOffset: '-1px', - backgroundColor: theme.agGridBackground.color, - }, - ...customProps, - }), -}); + position: 'relative', + + // - AG Grid colors override - + // It shouldn't be exactly like this, but I couldn't make it works otherwise + // https://www.ag-grid.com/react-data-grid/global-style-customisation/ + '--ag-alpine-active-color': `${theme.palette.primary.main} !important`, + '--ag-checkbox-indeterminate-color': `${theme.palette.primary.main} !important`, + ...(theme.agGrid?.backgroundColor && { + '--ag-background-color': `${theme.agGrid.backgroundColor} !important`, + '--ag-header-background-color': `${theme.agGrid.backgroundColor} !important`, + '--ag-odd-row-background-color': `${theme.agGrid.backgroundColor} !important`, + '--ag-modal-overlay-background-color': `${theme.agGrid.backgroundColor} !important`, + }), + '--ag-selected-row-background-color': 'transparent !important', + '--ag-range-selection-border-color': 'transparent !important', + + // overrides the default computed max height for ag grid default selector editor to make it more usable + // can be removed if a custom selector editor is implemented + '& .ag-select-list': { + maxHeight: '300px !important', + }, + '& .ag-root-wrapper-body': { + maxHeight: '500px', + }, + '& .ag-cell': { + boxShadow: 'none', + }, + '& .ag-cell-edit-wrapper': { + height: 'inherit', + }, + '& .ag-row-hover': { + cursor: 'text', + }, + '& .ag-overlay-loading-center': { + border: 'none', + boxShadow: 'none', + }, + '& .numeric-input': { + fontSize: 'calc(var(--ag-font-size) + 1px)', + paddingLeft: 'calc(var(--ag-cell-horizontal-padding) - 1px)', + width: '100%', + height: '100%', + border: 'inherit', + outline: 'inherit', + ...(theme.agGrid?.backgroundColor && { backgroundColor: theme.agGrid.backgroundColor }), + }, + '& .Mui-focused .MuiOutlinedInput-root': { + // borders moves row height + outline: 'var(--ag-borders-input) var(--ag-input-focus-border-color)', + outlineOffset: '-1px', + ...(theme.agGrid?.backgroundColor && { backgroundColor: theme.agGrid.backgroundColor }), + }, + ...customProps, + }), + }) as const satisfies MuiStyles; export type CustomAgGridTableProps = Required< Pick< @@ -86,7 +90,7 @@ export type CustomAgGridTableProps = Required< name: string; makeDefaultRowData: any; csvProps: unknown; - cssProps: unknown; + cssProps: CSSObject; }; export function CustomAgGridTable({ @@ -97,8 +101,6 @@ export function CustomAgGridTable({ rowSelection, ...props }: Readonly) { - // FIXME: right type => Theme --> not defined there ( gridStudy and gridExplore definition not the same ) - const theme: any = useTheme(); const [gridApi, setGridApi] = useState(null); const [selectedRows, setSelectedRows] = useState([]); const [newRowAdded, setNewRowAdded] = useState(false); @@ -208,27 +210,26 @@ export function CustomAgGridTable({ return ( <> - - move(getIndex(e.node.data), e.overIndex)} - detailRowAutoHeight - onSelectionChanged={() => { - setSelectedRows(gridApi.api.getSelectedRows()); - }} - onRowDataUpdated={newRowAdded ? onRowDataUpdated : undefined} - onCellEditingStopped={onCellEditingStopped} - onSortChanged={onSortChanged} - getRowId={(row) => row.data[FieldConstants.AG_GRID_ROW_UUID]} - theme="legacy" - {...props} - /> - + move(getIndex(e.node.data), e.overIndex)} + detailRowAutoHeight + onSelectionChanged={() => { + setSelectedRows(gridApi.api.getSelectedRows()); + }} + onRowDataUpdated={newRowAdded ? onRowDataUpdated : undefined} + onCellEditingStopped={onCellEditingStopped} + onSortChanged={onSortChanged} + getRowId={(row) => row.data[FieldConstants.AG_GRID_ROW_UUID]} + theme="legacy" + sx={useMemo(() => style(cssProps).grid, [cssProps])} + {...props} + /> >) { +export type CancelButtonProps = Omit; + +export function CancelButton(inProps: Readonly) { const props = useThemeProps({ props: inProps, name: 'CancelButton' }); return (