generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alx-chernigin
committed
Oct 22, 2024
1 parent
f63db62
commit 38d9f38
Showing
4 changed files
with
100 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
|
||
import type {CellContext} from '@tanstack/react-table'; | ||
|
||
import {RowActions} from './RowActions'; | ||
import type {TableActionsSettings} from './types'; | ||
|
||
export const ACTIONS_COLUMN_ID = '_actions'; | ||
|
||
interface ActionsCellProps<TValue extends unknown> extends TableActionsSettings<TValue> { | ||
cellContext: CellContext<TValue, unknown>; | ||
} | ||
|
||
export const ActionsCell = <TValue extends unknown>({ | ||
getRowActions, | ||
renderRowActions, | ||
rowActionsSize, | ||
cellContext, | ||
}: ActionsCellProps<TValue>) => { | ||
const {original: item, index} = cellContext.row; | ||
|
||
if (renderRowActions) { | ||
return renderRowActions({row: cellContext.row}); | ||
} | ||
|
||
return ( | ||
<RowActions<TValue> | ||
item={item} | ||
index={index} | ||
getRowActions={getRowActions} | ||
rowActionsSize={rowActionsSize} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export type * from './types'; | ||
export {RowActions} from './RowActions'; | ||
export {ActionsCell} from './ActionsCell'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,22 @@ | ||
import React from 'react'; | ||
|
||
import type {CellContext, ColumnDef, ColumnDefTemplate} from '@tanstack/react-table'; | ||
import type {ColumnDef} from '@tanstack/react-table'; | ||
|
||
import type {TableActionsSettings} from '../components'; | ||
import {RowActions} from '../components'; | ||
import {ActionsCell} from '../components'; | ||
|
||
export const ACTIONS_COLUMN_ID = '_actions'; | ||
const ACTIONS_COLUMN_SIZE = 44; | ||
|
||
export const getActionsCell = <TData extends unknown>({ | ||
getRowActions, | ||
renderRowActions, | ||
rowActionsSize, | ||
}: TableActionsSettings<TData>): ColumnDefTemplate<CellContext<TData, unknown>> => { | ||
const ActionsCell = (props: CellContext<TData, unknown>) => { | ||
const {original: item, index} = props.row; | ||
|
||
if (renderRowActions) { | ||
return renderRowActions({row: props.row}); | ||
} | ||
|
||
return ( | ||
<RowActions<TData> | ||
item={item} | ||
index={index} | ||
getRowActions={getRowActions} | ||
rowActionsSize={rowActionsSize} | ||
/> | ||
); | ||
}; | ||
|
||
ActionsCell.displayName = 'ActionsCell'; | ||
return ActionsCell; | ||
}; | ||
|
||
export const getActionsColumn = <TData extends unknown>( | ||
export const getActionsColumn = <TValue extends unknown>( | ||
columnId = ACTIONS_COLUMN_ID, | ||
options: TableActionsSettings<TData>, | ||
): ColumnDef<TData> => { | ||
options: TableActionsSettings<TValue>, | ||
): ColumnDef<TValue> => { | ||
return { | ||
id: columnId, | ||
header: '', | ||
size: ACTIONS_COLUMN_SIZE, | ||
minSize: ACTIONS_COLUMN_SIZE, | ||
cell: getActionsCell<TData>(options), | ||
cell: (props) => <ActionsCell {...options} cellContext={props} />, | ||
}; | ||
}; |