|
| 1 | +import { OnChangeFn, Updater } from '../../types' |
| 2 | + |
| 3 | +export interface ColumnResizingTableState { |
| 4 | + columnSizingInfo: ColumnResizingInfoState |
| 5 | +} |
| 6 | + |
| 7 | +export interface ColumnResizingInfoState { |
| 8 | + columnSizingStart: [string, number][] |
| 9 | + deltaOffset: null | number |
| 10 | + deltaPercentage: null | number |
| 11 | + isResizingColumn: false | string |
| 12 | + startOffset: null | number |
| 13 | + startSize: null | number |
| 14 | +} |
| 15 | + |
| 16 | +export type ColumnResizeMode = 'onChange' | 'onEnd' |
| 17 | + |
| 18 | +export type ColumnResizeDirection = 'ltr' | 'rtl' |
| 19 | + |
| 20 | +export interface ColumnResizingOptions { |
| 21 | + /** |
| 22 | + * Determines when the columnSizing state is updated. `onChange` updates the state when the user is dragging the resize handle. `onEnd` updates the state when the user releases the resize handle. |
| 23 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#columnresizemode) |
| 24 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 25 | + */ |
| 26 | + columnResizeMode?: ColumnResizeMode |
| 27 | + /** |
| 28 | + * Enables or disables column resizing for the column. |
| 29 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#enablecolumnresizing) |
| 30 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 31 | + */ |
| 32 | + enableColumnResizing?: boolean |
| 33 | + /** |
| 34 | + * Enables or disables right-to-left support for resizing the column. defaults to 'ltr'. |
| 35 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#columnResizeDirection) |
| 36 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 37 | + */ |
| 38 | + columnResizeDirection?: ColumnResizeDirection |
| 39 | + /** |
| 40 | + * If provided, this function will be called with an `updaterFn` when `state.columnSizingInfo` changes. This overrides the default internal state management, so you will also need to supply `state.columnSizingInfo` from your own managed state. |
| 41 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#oncolumnsizinginfochange) |
| 42 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 43 | + */ |
| 44 | + onColumnSizingInfoChange?: OnChangeFn<ColumnResizingInfoState> |
| 45 | +} |
| 46 | + |
| 47 | +export type ColumnResizingDefaultOptions = Pick< |
| 48 | + ColumnResizingOptions, |
| 49 | + 'columnResizeMode' | 'onColumnSizingInfoChange' | 'columnResizeDirection' |
| 50 | +> |
| 51 | + |
| 52 | +export interface ColumnResizingInstance { |
| 53 | + /** |
| 54 | + * Resets column sizing info to its initial state. If `defaultState` is `true`, the default state for the table will be used instead of the initialValue provided to the table. |
| 55 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#resetheadersizeinfo) |
| 56 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 57 | + */ |
| 58 | + resetHeaderSizeInfo: (defaultState?: boolean) => void |
| 59 | + /** |
| 60 | + * Sets the column sizing info state using an updater function or a value. This will trigger the underlying `onColumnSizingInfoChange` function if one is passed to the table options, otherwise the state will be managed automatically by the table. |
| 61 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#setcolumnsizinginfo) |
| 62 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 63 | + */ |
| 64 | + setColumnSizingInfo: (updater: Updater<ColumnResizingInfoState>) => void |
| 65 | +} |
| 66 | + |
| 67 | +export interface ColumnResizingColumnDef { |
| 68 | + /** |
| 69 | + * Enables or disables column resizing for the column. |
| 70 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#enableresizing) |
| 71 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 72 | + */ |
| 73 | + enableResizing?: boolean |
| 74 | +} |
| 75 | + |
| 76 | +export interface ColumnResizingColumn { |
| 77 | + /** |
| 78 | + * Returns `true` if the column can be resized. |
| 79 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getcanresize) |
| 80 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 81 | + */ |
| 82 | + getCanResize: () => boolean |
| 83 | + /** |
| 84 | + * Returns `true` if the column is currently being resized. |
| 85 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getisresizing) |
| 86 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 87 | + */ |
| 88 | + getIsResizing: () => boolean |
| 89 | +} |
| 90 | + |
| 91 | +export interface ColumnResizingHeader { |
| 92 | + /** |
| 93 | + * Returns an event handler function that can be used to resize the header. It can be used as an: |
| 94 | + * - `onMouseDown` handler |
| 95 | + * - `onTouchStart` handler |
| 96 | + * |
| 97 | + * The dragging and release events are automatically handled for you. |
| 98 | + * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/column-sizing#getresizehandler) |
| 99 | + * @link [Guide](https://tanstack.com/table/v8/docs/guide/column-sizing) |
| 100 | + */ |
| 101 | + getResizeHandler: (context?: Document) => (event: unknown) => void |
| 102 | +} |
0 commit comments