mgh-components 1.1.1 → 1.1.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/README.md CHANGED
@@ -166,13 +166,55 @@ apiRef.current?.state; // current models (sort, filter, p
166
166
  1. Change the import: `MGHDataGrid` → `MGHGrid`, `GridColDef` → `MGHGridColDef`.
167
167
  2. Column definitions keep the MUI v8 signatures (`valueGetter(value, row, column, api)`,
168
168
  `valueFormatter(value, row, column, api)`, `renderCell(params)`), so most columns work unchanged.
169
- 3. `sx`, `cardSx` and `boxSx` are accepted but treated as plain inline styles (`cardStyle`, `boxStyle`,
170
- `style` are the preferred names). Nested MUI selectors such as `'& .MuiDataGrid-row'` are ignored.
169
+ 3. `sx`, `cardSx` and `boxSx` work as before, including nested selectors (see *Styling rows and cells*).
170
+ Only selectors that target MUI's own class names (`'& .MuiDataGrid-row'`) need rewriting to the
171
+ `.mgh-grid-*` equivalents.
171
172
  4. `rowSelectionModel` uses the same shape as MUI v8 (`{ type: 'include', ids: Set }`).
172
173
  5. `slots.toolbar` components must be rewritten without MUI internals; use the exported building blocks.
173
174
  6. Custom export menu items receive a `hideMenu` prop (like MUI) – use `MGHGridExportMenuItem`.
174
175
  7. The no-rows overlay no longer needs `useSettingsContext`; pass `themeMode="dark"` to the grid instead.
175
176
 
177
+ ### Styling rows and cells (`sx` with nested selectors)
178
+
179
+ `sx`, `cardSx` and `boxSx` (and their `style` / `cardStyle` / `boxStyle` twins) accept plain CSS
180
+ properties, which are applied inline, **plus nested selectors** in the spirit of MUI's `sx`. Nested
181
+ selectors are compiled into a `<style>` block scoped to that grid instance, so the common
182
+ "colour a row by class" pattern works unchanged:
183
+
184
+ ```tsx
185
+ <MGHGrid
186
+ rows={rows}
187
+ columns={columns}
188
+ getRowClassName={({ row }) => (row.needsApproval ? 'needsApproval' : row.isSubmitted ? 'isSubmitted' : '')}
189
+ sx={{
190
+ '.needsApproval': { color: 'goldenrod' },
191
+ '.isSubmitted': { color: themeMode === 'dark' ? 'lightgreen' : 'green' },
192
+ '&:hover .mgh-grid-row': { opacity: 0.95 }, // `&` = this grid
193
+ '@media (max-width: 600px)': { '.mgh-grid-toolbar': { display: 'none' } },
194
+ }}
195
+ />
196
+ ```
197
+
198
+ Useful class names to target: `.mgh-grid-row` (`--selected`, `--group`, `--pinned`, `--footer`),
199
+ `.mgh-grid-cell`, `.mgh-grid-header-cell`, `.mgh-grid-toolbar`, `.mgh-grid-footer`,
200
+ `.mgh-grid-detail-panel`. Legacy `.MuiDataGrid-*` selectors will not match anything.
201
+
202
+ ### MUI-compatible constants
203
+
204
+ For `pinnedColumns` and similar configs the internal column fields are exported under both
205
+ `MGH_GRID_*` names and the MUI names, so existing code keeps working:
206
+
207
+ ```tsx
208
+ import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_DETAIL_PANEL_TOGGLE_FIELD } from 'mgh-components';
209
+
210
+ initialState={{
211
+ pinnedColumns: { left: [GRID_CHECKBOX_SELECTION_COL_DEF.field, 'isoWeekId'], right: ['enterCount'] },
212
+ }}
213
+ ```
214
+
215
+ (The checkbox and detail-toggle columns are always pinned left automatically, so listing them is
216
+ optional but harmless.)
217
+
176
218
  ### Theming
177
219
 
178
220
  ```tsx
@@ -322,6 +322,25 @@ export interface MGHGridPrintExportOptions extends MGHGridExportOptions {
322
322
  /** Extra CSS injected in the print document. */
323
323
  pageStyle?: string;
324
324
  }
325
+ /**
326
+ * Inline CSS properties plus nested selectors, in the spirit of MUI's `sx`:
327
+ *
328
+ * ```tsx
329
+ * sx={{
330
+ * height: '70vh', // applied inline
331
+ * '.needsApproval': { color: 'goldenrod' }, // -> `<grid> .needsApproval { color: goldenrod }`
332
+ * '&:hover .mgh-grid-row': { opacity: 0.9 },// `&` is replaced with the grid selector
333
+ * '@media (max-width: 600px)': { '.mgh-grid-toolbar': { display: 'none' } },
334
+ * }}
335
+ * ```
336
+ *
337
+ * Nested selectors are compiled into a `<style>` block scoped to this grid instance, so they can
338
+ * target the classes returned by `getRowClassName` / `cellClassName` or the grid's own
339
+ * `mgh-grid-*` classes. Legacy `.MuiDataGrid-*` selectors will simply not match anything.
340
+ */
341
+ export interface MGHGridSxProps extends React.CSSProperties {
342
+ [selector: string]: MGHGridSxProps | string | number | undefined;
343
+ }
325
344
  export type MGHGridPreferencePanelValue = 'columns' | 'filters';
326
345
  export interface MGHGridPreferencePanelState {
327
346
  open: boolean;
@@ -602,15 +621,15 @@ export interface MGHGridProps<R extends MGHGridValidRowModel = any> {
602
621
  className?: string;
603
622
  cardClassName?: string;
604
623
  boxClassName?: string;
605
- /** Inline style for the outer card. (`cardSx` is accepted as an alias for legacy code.) */
606
- cardStyle?: React.CSSProperties;
607
- cardSx?: React.CSSProperties;
608
- /** Inline style for the box wrapping the grid. (`boxSx` is accepted as an alias for legacy code.) */
609
- boxStyle?: React.CSSProperties;
610
- boxSx?: React.CSSProperties;
611
- /** Inline style for the grid root. (`sx` is accepted as an alias for legacy code.) */
612
- style?: React.CSSProperties;
613
- sx?: React.CSSProperties;
624
+ /** Styles for the outer card; supports nested selectors. (`cardSx` is an alias for legacy code.) */
625
+ cardStyle?: MGHGridSxProps;
626
+ cardSx?: MGHGridSxProps;
627
+ /** Styles for the box wrapping the grid; supports nested selectors. (`boxSx` is an alias for legacy code.) */
628
+ boxStyle?: MGHGridSxProps;
629
+ boxSx?: MGHGridSxProps;
630
+ /** Styles for the grid root; supports nested selectors. (`sx` is an alias for legacy code.) */
631
+ style?: MGHGridSxProps;
632
+ sx?: MGHGridSxProps;
614
633
  /** 'light' (default) or 'dark'. */
615
634
  themeMode?: MGHGridThemeMode;
616
635
  /** Override any `--mgh-grid-*` CSS variable. */
@@ -16,5 +16,5 @@ export { MGHGridActionsCellItem } from './components/ActionsCell';
16
16
  export type { MGHGridActionsCellItemProps } from './components/ActionsCell';
17
17
  export { Button as MGHGridButton, IconButton as MGHGridIconButton, Menu as MGHGridMenu, MenuItem as MGHGridMenuItem, MenuDivider as MGHGridMenuDivider, Popover as MGHGridPopover, Checkbox as MGHGridCheckbox, TextInput as MGHGridTextInput, Select as MGHGridSelect, } from './components/primitives';
18
18
  export * as MGHGridIcons from './icons';
19
- export { GROUPING_COLUMN_FIELD as MGH_GRID_GROUPING_COLUMN_FIELD, CHECKBOX_FIELD as MGH_GRID_CHECKBOX_FIELD, DETAIL_PANEL_TOGGLE_FIELD as MGH_GRID_DETAIL_PANEL_TOGGLE_FIELD, DEFAULT_LOCALE_TEXT as MGH_GRID_DEFAULT_LOCALE_TEXT, BUILT_IN_AGGREGATION_FUNCTIONS as MGH_GRID_AGGREGATION_FUNCTIONS, stringFilterOperators as mghGridStringFilterOperators, numberFilterOperators as mghGridNumberFilterOperators, booleanFilterOperators as mghGridBooleanFilterOperators, singleSelectFilterOperators as mghGridSingleSelectFilterOperators, getDateFilterOperators as mghGridGetDateFilterOperators, } from './utils';
19
+ export { GROUPING_COLUMN_FIELD as MGH_GRID_GROUPING_COLUMN_FIELD, CHECKBOX_FIELD as MGH_GRID_CHECKBOX_FIELD, DETAIL_PANEL_TOGGLE_FIELD as MGH_GRID_DETAIL_PANEL_TOGGLE_FIELD, CHECKBOX_COLUMN_DEF as MGH_GRID_CHECKBOX_SELECTION_COL_DEF, DETAIL_PANEL_TOGGLE_COLUMN_DEF as MGH_GRID_DETAIL_PANEL_TOGGLE_COL_DEF, CHECKBOX_COLUMN_DEF as GRID_CHECKBOX_SELECTION_COL_DEF, CHECKBOX_FIELD as GRID_CHECKBOX_SELECTION_FIELD, DETAIL_PANEL_TOGGLE_COLUMN_DEF as GRID_DETAIL_PANEL_TOGGLE_COL_DEF, DETAIL_PANEL_TOGGLE_FIELD as GRID_DETAIL_PANEL_TOGGLE_FIELD, GROUPING_COLUMN_FIELD as GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, buildScopedCss as mghGridBuildScopedCss, DEFAULT_LOCALE_TEXT as MGH_GRID_DEFAULT_LOCALE_TEXT, BUILT_IN_AGGREGATION_FUNCTIONS as MGH_GRID_AGGREGATION_FUNCTIONS, stringFilterOperators as mghGridStringFilterOperators, numberFilterOperators as mghGridNumberFilterOperators, booleanFilterOperators as mghGridBooleanFilterOperators, singleSelectFilterOperators as mghGridSingleSelectFilterOperators, getDateFilterOperators as mghGridGetDateFilterOperators, } from './utils';
20
20
  export { getDataAsCsv as mghGridGetDataAsCsv, buildXlsx as mghGridBuildXlsx } from './export';
@@ -56,6 +56,17 @@ export declare const singleSelectFilterOperators: MGHGridFilterOperator[];
56
56
  export declare const getDefaultFilterOperators: (type: MGHGridColType | undefined) => MGHGridFilterOperator[];
57
57
  export declare const getColumnFilterOperators: (col: MGHGridColDef) => MGHGridFilterOperator<any, any>[];
58
58
  export declare const normalizeColumn: <R extends MGHGridValidRowModel>(col: MGHGridColDef<R>) => MGHGridColDef<R>;
59
+ /** Definition of the checkbox-selection column (equivalent of MUI's GRID_CHECKBOX_SELECTION_COL_DEF). */
60
+ export declare const CHECKBOX_COLUMN_DEF: MGHGridColDef;
61
+ /** Definition of the detail-panel toggle column (equivalent of MUI's GRID_DETAIL_PANEL_TOGGLE_COL_DEF). */
62
+ export declare const DETAIL_PANEL_TOGGLE_COLUMN_DEF: MGHGridColDef;
63
+ /** Keys that are CSS selectors / at-rules rather than CSS properties. */
64
+ export declare const isSelectorKey: (key: string) => boolean;
65
+ /**
66
+ * Compiles the nested-selector part of an `sx`-like object into CSS scoped under `scope`.
67
+ * Top-level plain properties are ignored here (they are applied as inline styles instead).
68
+ */
69
+ export declare const buildScopedCss: (scope: string, sx: Record<string, unknown> | undefined, out?: string[]) => string[];
59
70
  export declare const BUILT_IN_AGGREGATION_FUNCTIONS: Record<string, MGHGridAggregationFunction>;
60
71
  export declare const DEFAULT_LOCALE_TEXT: MGHGridLocaleText;
61
72
  export declare const measureText: (text: string, font: string) => number;