@equinor/apollo-components 3.6.1 → 3.7.1

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.
@@ -0,0 +1,342 @@
1
+ import { IconData } from '@equinor/eds-icons';
2
+ import * as react from 'react';
3
+ import { ReactNode, ReactElement, HTMLProps, MutableRefObject, Dispatch, SetStateAction, SyntheticEvent } from 'react';
4
+ import { CellContext, Table, Row, SortingState, OnChangeFn, Cell, ColumnDef, ColumnResizeMode, RowSelectionState, ExpandedState, ColumnPinningState, VisibilityState, HeaderContext, Column, Header } from '@tanstack/react-table';
5
+ export { Cell, CellContext, ColumnDef, ColumnPinningState, ColumnResizeMode, ColumnSort, ExpandedState, HeaderContext, OnChangeFn, Row, RowSelectionState, SortingState, Table, VisibilityState, createColumnHelper } from '@tanstack/react-table';
6
+ import * as styled_components from 'styled-components';
7
+ import * as _equinor_eds_core_react from '@equinor/eds-core-react';
8
+ import { CellProps, TypographyProps as TypographyProps$1 } from '@equinor/eds-core-react';
9
+ import { ColumnDef as ColumnDef$1 } from '@tanstack/table-core';
10
+ import { SetRequired } from 'type-fest';
11
+ import { Variants } from '@equinor/eds-core-react/dist/types/components/types';
12
+ import { FieldError } from 'react-hook-form';
13
+
14
+ interface AppShellProps {
15
+ children?: ReactNode;
16
+ sidebar?: ReactNode;
17
+ icon?: IconData;
18
+ title?: string;
19
+ }
20
+ declare const AppShell: ({ children, icon, title, sidebar }: AppShellProps) => JSX.Element;
21
+
22
+ declare function AppSidebar(): JSX.Element;
23
+
24
+ declare function CheckboxCell<T>(context: CellContext<T, boolean>): JSX.Element;
25
+
26
+ declare const ChipsCell: (props: {
27
+ values?: string[];
28
+ }) => JSX.Element;
29
+
30
+ interface ColumnSelectProps<T> {
31
+ table: Table<T>;
32
+ columnSelectPlaceholder?: string;
33
+ }
34
+ declare function ColumnSelect<T>({ table, columnSelectPlaceholder }: ColumnSelectProps<T>): JSX.Element;
35
+
36
+ interface TableHeaderProps<T> {
37
+ table: Table<T>;
38
+ sticky?: boolean;
39
+ }
40
+ declare function TableHeader<T>({ table, sticky }: TableHeaderProps<T>): JSX.Element;
41
+
42
+ interface TableRowWrapper<T> {
43
+ (props: TableRowWrapperProps<T>): ReactElement;
44
+ }
45
+ interface TableRowWrapperProps<T> {
46
+ row: Row<T>;
47
+ children: ReactNode;
48
+ }
49
+ interface RowConfig<T> {
50
+ /**
51
+ * ! Unstable - Row Wrapper has not been tested for compatibility with virtualization. Use with caution.
52
+ */
53
+ rowWrapper?: TableRowWrapper<T>;
54
+ getRowBackground?: (row: Row<T>) => string | undefined;
55
+ onClick?: (row: Row<T>) => void;
56
+ onMouseEnter?: (row: Row<T>) => void;
57
+ onMouseLeave?: (row: Row<T>) => void;
58
+ /**
59
+ * Whatever is returned from this function will be added as a data-id attribute on the tr in the dom.
60
+ */
61
+ getDataIdAttribute?: (row: Row<T>) => string | undefined;
62
+ }
63
+ type TruncateMode = 'wrap' | 'hover';
64
+ type SortConfig = {
65
+ enableSorting?: boolean;
66
+ manualSorting?: boolean;
67
+ sorting?: SortingState;
68
+ onSortingChange?: OnChangeFn<SortingState>;
69
+ };
70
+ interface CellConfig<T> {
71
+ getStickyCellColor?: (cell: Cell<T, unknown>) => string;
72
+ getShouldHighlight?: (cell: Cell<T, unknown>) => boolean;
73
+ /**
74
+ * Whether to wrap or truncate default cells. Accepts `"wrap"` or `"hover"` and or a function returning a boolean.
75
+ * Defauls to `"hover"` (i.e. all cells is truncated by default).
76
+ *
77
+ * ***Note**: This only applies to default cells. Custom cells need custom implementation.*
78
+ */
79
+ truncateMode?: TruncateMode | ((cell: Cell<T, unknown>) => TruncateMode);
80
+ /**
81
+ * Manually set the cell background color. Prioritized over highlight color.
82
+ *
83
+ * @param cell
84
+ * @returns color in hex, rgb or rgba, undefined to use default
85
+ */
86
+ getCellColor?: (cell: Cell<T, unknown>) => string | undefined;
87
+ }
88
+ type RowSelectionMode = 'single' | 'multiple';
89
+ type TableLayout = 'auto' | 'fixed';
90
+ interface HTMLPropsRef<T extends HTMLElement> extends HTMLProps<T> {
91
+ ref?: MutableRefObject<T | null> | null;
92
+ }
93
+ interface InfiniteScrollConfig {
94
+ /** Called on scroll below offset. */
95
+ onBottomScroll: () => void;
96
+ /** Pixels above bottom. Defines when the onBottomScroll should be called. Defaults to `300`. */
97
+ offset?: number;
98
+ }
99
+ interface DataTableProps<T> {
100
+ tableCaption: string;
101
+ data: T[];
102
+ columns: ColumnDef<T, any>[];
103
+ cellConfig?: CellConfig<T>;
104
+ rowConfig?: RowConfig<T>;
105
+ isLoading?: boolean;
106
+ height?: string;
107
+ width?: string;
108
+ stickyHeader?: boolean;
109
+ /**
110
+ * Defaults to `'auto'`.
111
+ *
112
+ * `'auto'` determines column width based on cell content.
113
+ *
114
+ * `'fixed'` uses fixed column width. Specify width (`size` property) in ColumnDef.
115
+ * Default size is 150px.
116
+ */
117
+ tableLayout?: TableLayout;
118
+ virtual?: boolean;
119
+ getRowId?: (originalRow: T, index: number, parent: Row<T> | undefined) => string;
120
+ getSubRows?: (originalRow: T) => T[] | undefined;
121
+ columnResizing?: boolean | ColumnResizeMode;
122
+ rowSelection?: Partial<ControlledState<RowSelectionState>> & {
123
+ mode?: RowSelectionMode;
124
+ selectColumn?: 'default' | ((options?: Record<string, any>) => ColumnDef<T, any>);
125
+ includeExpansionButton?: boolean;
126
+ };
127
+ expansion?: Partial<ControlledState<ExpandedState>> & {
128
+ expandAllByDefault?: boolean;
129
+ };
130
+ sorting?: Partial<ControlledState<SortingState>> & {
131
+ enableSorting?: boolean;
132
+ manualSorting?: boolean;
133
+ };
134
+ columnPinning?: boolean | (ControlledState<ColumnPinningState> & {
135
+ enable?: boolean;
136
+ });
137
+ globalFilter?: ControlledState<string>;
138
+ columnVisibility?: ControlledState<VisibilityState>;
139
+ /**
140
+ * Everything that has todo with the area (banner) over the table
141
+ */
142
+ bannerConfig?: {
143
+ enableTableCaption?: boolean;
144
+ totalRowCount?: number;
145
+ enableColumnSelect?: boolean;
146
+ enableGlobalFilterInput?: boolean;
147
+ globalFilterPlaceholder?: string;
148
+ columnSelectPlaceholder?: string;
149
+ filterFromLeafRows?: boolean;
150
+ /**
151
+ * @deprecated Use `customActionsLeft` instead
152
+ */
153
+ customActions?: <T>(table: Table<T>) => ReactNode;
154
+ customActionsLeft?: <T>(table: Table<T>) => ReactNode;
155
+ customActionsRight?: <T>(table: Table<T>) => ReactNode;
156
+ /**
157
+ * Default 1rem
158
+ * Accepts any CSS padding value
159
+ */
160
+ padding?: string;
161
+ };
162
+ tableContainerProps?: HTMLPropsRef<HTMLDivElement>;
163
+ infiniteScroll?: InfiniteScrollConfig;
164
+ }
165
+ type ControlledState<T> = {
166
+ state?: T;
167
+ /** Callback when state chagnes. Using this requires the state to be fully controlled. */
168
+ onChange?: Dispatch<SetStateAction<T>>;
169
+ };
170
+
171
+ declare function DataTable<T>(props: DataTableProps<T>): JSX.Element;
172
+
173
+ /**
174
+ * Capitalize the table header.
175
+ *
176
+ * React table utility function.
177
+ * @param context
178
+ * @returns A capitalized header
179
+ */
180
+ declare function capitalizeHeader<T>(context: HeaderContext<T, any>): string;
181
+ /**
182
+ * Used to conditionally return any given value.
183
+ *
184
+ * @param enabled - A bool whether the value should be enabled or not
185
+ * @param value - Any given value.
186
+ * @returns Value or undefined
187
+ */
188
+ declare function enableOrUndefined<T>(enabled: boolean | undefined, value: T): T | undefined;
189
+ /**
190
+ * Get column header if set
191
+ * @param column
192
+ * @returns Column label
193
+ */
194
+ declare function getColumnHeader<T>(column: Column<T, any>): string;
195
+ /** Prepend a column definition array with a select column if enabled in the config. */
196
+ declare function prependSelectColumnIfEnabled<T>(columns: ColumnDef<T, any>[], config?: DataTableProps<T>['rowSelection']): ColumnDef<T, any>[];
197
+ /** Prepend a column definition array with a select column. */
198
+ declare function prependSelectColumn<T>(columns: ColumnDef<T>[], config?: DataTableProps<T>['rowSelection']): ColumnDef<T>[];
199
+ /** Useful in cases where you either have a value, function or undefined. */
200
+ declare function getFunctionValueOrDefault<T extends boolean | string | number, P>(valueOrFn: ((props: P) => T) | T | undefined, fnProps: P, defaultValue: T): T;
201
+
202
+ type TableCellProps<T> = {
203
+ cell: Cell<T, unknown>;
204
+ cellConfig?: CellConfig<T>;
205
+ };
206
+ type StyledStickyCellProps = {
207
+ backgroundColor?: string;
208
+ };
209
+ declare const StyledStickyCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<_equinor_eds_core_react.CellProps & react.RefAttributes<HTMLTableCellElement>>, any, ({} & _equinor_eds_core_react.CellProps) & StyledStickyCellProps, never>;
210
+ declare function DynamicCell<T>({ cell, cellConfig }: TableCellProps<T>): JSX.Element;
211
+
212
+ interface HeaderCellProps<TData, TValue> {
213
+ header: Header<TData, TValue>;
214
+ /** Needed for column resizing */
215
+ table: Table<TData>;
216
+ }
217
+ declare const HeaderCell: <TData, TValue>({ header, table }: HeaderCellProps<TData, TValue>) => JSX.Element;
218
+
219
+ type HierarchyCellOptions = {
220
+ getRowDepth?: () => number;
221
+ getDisplayName?: () => string;
222
+ };
223
+ declare function HierarchyCell<T>(cell: CellContext<T, any>, options?: HierarchyCellOptions): JSX.Element;
224
+
225
+ interface PopoverCellProps {
226
+ id: string;
227
+ value: string;
228
+ title?: string | JSX.Element | ReactNode;
229
+ }
230
+ declare function PopoverCell(props: PopoverCellProps): JSX.Element;
231
+
232
+ declare function SelectColumnDef<T>(props: SetRequired<DataTableProps<T>, 'rowSelection'>['rowSelection']): ColumnDef$1<T, any>;
233
+
234
+ declare const leftCellShadow: styled_components.FlattenSimpleInterpolation;
235
+ declare const StickyCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<CellProps & react.RefAttributes<HTMLTableCellElement>>, any, {} & CellProps, never>;
236
+ declare const StickyHeaderCell: styled_components.StyledComponent<react.ForwardRefExoticComponent<CellProps & react.RefAttributes<HTMLTableCellElement>>, any, ({} & CellProps) & CellProps, never>;
237
+
238
+ type TypographyProps = {
239
+ truncate?: boolean;
240
+ enableShowAllOnHover?: boolean;
241
+ } & TypographyProps$1;
242
+ declare const TypographyCustom: (props: TypographyProps) => JSX.Element;
243
+
244
+ /**
245
+ * Generate a HSL color based on a given string.
246
+ *
247
+ * @param str - Any given string
248
+ * @returns A valid hsl color
249
+ */
250
+ declare function stringToHslColor(str: string, s?: number, l?: number): string;
251
+ /** Wrap an event handler and stop event propagation */
252
+ declare function stopPropagation<T extends HTMLElement>(handler: (e: SyntheticEvent<T>) => void): (e: SyntheticEvent<T>) => void;
253
+ /** Used for calculating the `right` px value of pinned cells */
254
+ declare function getTotalRight<TData>(table: Table<TData>, column: Column<TData>): number;
255
+ declare function getIsFirstRightPinnedColumn<TData>(column: Column<TData>): boolean;
256
+ declare function getIsLastLeftPinnedColumn<TData>(table: Table<TData>, column: Column<TData>): boolean;
257
+
258
+ type FormMeta = {
259
+ _isNew?: boolean;
260
+ _editMode?: boolean;
261
+ _hasRemoteChange?: boolean;
262
+ };
263
+ type WithoutFormMeta<T extends FormMeta> = Omit<T, keyof FormMeta>;
264
+
265
+ /**
266
+ * Subscribes to the `_editMode` field in a `react-hook-form` context.
267
+ *
268
+ * @returns edit mode value
269
+ */
270
+ declare function useEditMode(): boolean;
271
+ /**
272
+ * Subscribes to the `_hasRemoteChange` field in a `react-hook-form` context.
273
+ *
274
+ * @returns edit mode value
275
+ */
276
+ declare function useHasRemoteChange(): boolean;
277
+ /**
278
+ * @returns function getting is new meta
279
+ */
280
+ declare function useGetIsNew(): () => boolean;
281
+ declare function useSetFormMeta<T extends FormMeta>(): (newValues: Partial<T>) => void;
282
+ declare function removeFormMeta<T extends FormMeta>(withFormMeta: T): Omit<T, keyof FormMeta>;
283
+ declare function addFormMeta<T>(withoutFormMeta: T): T & FormMeta;
284
+
285
+ interface GetHelperTextPropsProps {
286
+ error?: {
287
+ message?: string;
288
+ };
289
+ warning?: {
290
+ message: string;
291
+ };
292
+ helperText?: string;
293
+ }
294
+ interface GetHelperTextProps {
295
+ variant?: Variants;
296
+ helperText?: string;
297
+ helperIcon: JSX.Element | null;
298
+ }
299
+ interface EditableCellBaseProps<T extends FormMeta, Value> extends CellContext<T, Value> {
300
+ /**
301
+ * FieldError object used to overwrite react-hook-form validation result. It is prioritized over react-hook-form's validation. If prefixed with the exported `WARNING_PREFIX` it will be displayed as an warning.
302
+ */
303
+ error?: FieldError;
304
+ /**
305
+ * Custom `onChange` called on input change after react-hook-form's `onChange`. E.g. used to trigger actions on change.
306
+ */
307
+ onChange?: (value: Value) => void;
308
+ }
309
+
310
+ declare function EditableCheckboxCell<T extends FormMeta>({ onChange: onChangeFromProps, ...context }: EditableCellBaseProps<T, boolean>): JSX.Element;
311
+
312
+ interface EditableDateCellProps<T extends FormMeta> extends EditableCellBaseProps<T, string> {
313
+ dateStringFormatter?: (date: string) => string;
314
+ }
315
+ declare function EditableDateCell<T extends FormMeta>({ dateStringFormatter, error: errorFromProps, onChange: onChangeFromProps, ...context }: EditableDateCellProps<T>): JSX.Element;
316
+
317
+ interface Option {
318
+ label: string;
319
+ value: string;
320
+ }
321
+ interface EditableDropdownSingleCellProps<T extends FormMeta> extends Omit<EditableCellBaseProps<T, unknown>, 'onChange'> {
322
+ /**
323
+ * `Option.value` is used internally to get and update selection state. `Option.label` is *only* for visual purposes.
324
+ */
325
+ options: Option[];
326
+ onChange?: (value: Option) => void;
327
+ }
328
+ declare function EditableDropdownSingleCell<T extends FormMeta>({ options, error: errorFromProps, onChange: onChangeFromProps, ...context }: EditableDropdownSingleCellProps<T>): JSX.Element;
329
+
330
+ declare function EditableNumberCell<T extends FormMeta>({ error: errorFromProps, ...context }: EditableCellBaseProps<T, number>): JSX.Element;
331
+
332
+ interface EdtiableTextAreaProps<T extends FormMeta> extends EditableCellBaseProps<T, string> {
333
+ title: string;
334
+ }
335
+ declare function EditableTextAreaCell<T extends FormMeta>({ title, error: errorFromProps, onChange: onChangeFromProps, ...context }: EdtiableTextAreaProps<T>): JSX.Element;
336
+
337
+ declare function EditableTextFieldCell<T extends FormMeta>({ error: errorFromProps, ...context }: EditableCellBaseProps<T, string>): JSX.Element;
338
+
339
+ declare const WARNING_PREFIX = "WARNING";
340
+ declare function getHelperTextProps({ error, warning, helperText, }: GetHelperTextPropsProps): GetHelperTextProps;
341
+
342
+ export { AppShell, AppSidebar, type CellConfig, CheckboxCell, ChipsCell, ColumnSelect, DataTable, type DataTableProps, DynamicCell, type EditableCellBaseProps, EditableCheckboxCell, EditableDateCell, type EditableDateCellProps, EditableDropdownSingleCell, type EditableDropdownSingleCellProps, EditableNumberCell, EditableTextAreaCell, EditableTextFieldCell, type FormMeta, type GetHelperTextProps, type GetHelperTextPropsProps, type HTMLPropsRef, HeaderCell, HierarchyCell, type InfiniteScrollConfig, type Option, PopoverCell, type RowConfig, type RowSelectionMode, SelectColumnDef, type SortConfig, StickyCell, StickyHeaderCell, StyledStickyCell, TableHeader, type TableLayout, type TableRowWrapper, type TableRowWrapperProps, type TruncateMode, TypographyCustom, type TypographyProps, WARNING_PREFIX, type WithoutFormMeta, addFormMeta, capitalizeHeader, enableOrUndefined, getColumnHeader, getFunctionValueOrDefault, getHelperTextProps, getIsFirstRightPinnedColumn, getIsLastLeftPinnedColumn, getTotalRight, leftCellShadow, prependSelectColumn, prependSelectColumnIfEnabled, removeFormMeta, stopPropagation, stringToHslColor, useEditMode, useGetIsNew, useHasRemoteChange, useSetFormMeta };
package/dist/index.d.ts CHANGED
@@ -29,8 +29,9 @@ declare const ChipsCell: (props: {
29
29
 
30
30
  interface ColumnSelectProps<T> {
31
31
  table: Table<T>;
32
+ columnSelectPlaceholder?: string;
32
33
  }
33
- declare function ColumnSelect<T>({ table }: ColumnSelectProps<T>): JSX.Element;
34
+ declare function ColumnSelect<T>({ table, columnSelectPlaceholder }: ColumnSelectProps<T>): JSX.Element;
34
35
 
35
36
  interface TableHeaderProps<T> {
36
37
  table: Table<T>;
@@ -144,6 +145,7 @@ interface DataTableProps<T> {
144
145
  enableColumnSelect?: boolean;
145
146
  enableGlobalFilterInput?: boolean;
146
147
  globalFilterPlaceholder?: string;
148
+ columnSelectPlaceholder?: string;
147
149
  filterFromLeafRows?: boolean;
148
150
  /**
149
151
  * @deprecated Use `customActionsLeft` instead
@@ -337,4 +339,4 @@ declare function EditableTextFieldCell<T extends FormMeta>({ error: errorFromPro
337
339
  declare const WARNING_PREFIX = "WARNING";
338
340
  declare function getHelperTextProps({ error, warning, helperText, }: GetHelperTextPropsProps): GetHelperTextProps;
339
341
 
340
- export { AppShell, AppSidebar, CellConfig, CheckboxCell, ChipsCell, ColumnSelect, DataTable, DataTableProps, DynamicCell, EditableCellBaseProps, EditableCheckboxCell, EditableDateCell, EditableDateCellProps, EditableDropdownSingleCell, EditableDropdownSingleCellProps, EditableNumberCell, EditableTextAreaCell, EditableTextFieldCell, FormMeta, GetHelperTextProps, GetHelperTextPropsProps, HTMLPropsRef, HeaderCell, HierarchyCell, InfiniteScrollConfig, Option, PopoverCell, RowConfig, RowSelectionMode, SelectColumnDef, SortConfig, StickyCell, StickyHeaderCell, StyledStickyCell, TableHeader, TableLayout, TableRowWrapper, TableRowWrapperProps, TruncateMode, TypographyCustom, TypographyProps, WARNING_PREFIX, WithoutFormMeta, addFormMeta, capitalizeHeader, enableOrUndefined, getColumnHeader, getFunctionValueOrDefault, getHelperTextProps, getIsFirstRightPinnedColumn, getIsLastLeftPinnedColumn, getTotalRight, leftCellShadow, prependSelectColumn, prependSelectColumnIfEnabled, removeFormMeta, stopPropagation, stringToHslColor, useEditMode, useGetIsNew, useHasRemoteChange, useSetFormMeta };
342
+ export { AppShell, AppSidebar, type CellConfig, CheckboxCell, ChipsCell, ColumnSelect, DataTable, type DataTableProps, DynamicCell, type EditableCellBaseProps, EditableCheckboxCell, EditableDateCell, type EditableDateCellProps, EditableDropdownSingleCell, type EditableDropdownSingleCellProps, EditableNumberCell, EditableTextAreaCell, EditableTextFieldCell, type FormMeta, type GetHelperTextProps, type GetHelperTextPropsProps, type HTMLPropsRef, HeaderCell, HierarchyCell, type InfiniteScrollConfig, type Option, PopoverCell, type RowConfig, type RowSelectionMode, SelectColumnDef, type SortConfig, StickyCell, StickyHeaderCell, StyledStickyCell, TableHeader, type TableLayout, type TableRowWrapper, type TableRowWrapperProps, type TruncateMode, TypographyCustom, type TypographyProps, WARNING_PREFIX, type WithoutFormMeta, addFormMeta, capitalizeHeader, enableOrUndefined, getColumnHeader, getFunctionValueOrDefault, getHelperTextProps, getIsFirstRightPinnedColumn, getIsLastLeftPinnedColumn, getTotalRight, leftCellShadow, prependSelectColumn, prependSelectColumnIfEnabled, removeFormMeta, stopPropagation, stringToHslColor, useEditMode, useGetIsNew, useHasRemoteChange, useSetFormMeta };