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
Showing
12 changed files
with
68 additions
and
16 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
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
3 changes: 3 additions & 0 deletions
3
src/components/SelectionCheckbox/SelectionCheckbox.classname.ts
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,3 @@ | ||
import {block} from '../../utils'; | ||
|
||
export const b = block('selection-checkbox'); |
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,14 @@ | ||
import React from 'react'; | ||
|
||
import type {CheckboxProps} from '@gravity-ui/uikit'; | ||
import {Checkbox} from '@gravity-ui/uikit'; | ||
|
||
import {b} from './SelectionCheckbox.classname'; | ||
|
||
export const SelectionCheckbox = React.forwardRef( | ||
({className, ...restProps}: CheckboxProps, ref: React.Ref<HTMLLabelElement>) => { | ||
return <Checkbox ref={ref} className={b(null, className)} {...restProps} />; | ||
}, | ||
); | ||
|
||
SelectionCheckbox.displayName = 'SelectionCheckbox'; |
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 @@ | ||
export * from './SelectionCheckbox'; |
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
29 changes: 29 additions & 0 deletions
29
src/components/Table/__stories__/stories/WithSelectionStory.tsx
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,29 @@ | ||
import React from 'react'; | ||
|
||
import type {ColumnDef, RowSelectionState} from '@tanstack/react-table'; | ||
|
||
import {selectionColumn} from '../../../../constants'; | ||
import {useTable} from '../../../../hooks'; | ||
import {columns as originalColumns} from '../../../BaseTable/__stories__/constants/columns'; | ||
import {data} from '../../../BaseTable/__stories__/constants/data'; | ||
import type {Item} from '../../../BaseTable/__stories__/types'; | ||
import {Table} from '../../Table'; | ||
|
||
const columns: ColumnDef<Item>[] = [selectionColumn as ColumnDef<Item>, ...originalColumns]; | ||
|
||
export const WithSelectionStory = () => { | ||
const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({}); | ||
|
||
const table = useTable({ | ||
columns, | ||
data, | ||
enableRowSelection: true, | ||
enableMultiRowSelection: true, | ||
onRowSelectionChange: setRowSelection, | ||
state: { | ||
rowSelection, | ||
}, | ||
}); | ||
|
||
return <Table table={table} />; | ||
}; |
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,2 @@ | ||
export * from './defaultDragHandleColumn'; | ||
export * from './defaultSelectionColumn'; | ||
export * from './selectionColumn'; |
15 changes: 7 additions & 8 deletions
15
src/constants/defaultSelectionColumn.tsx → src/constants/selectionColumn.tsx
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,28 +1,27 @@ | ||
import React from 'react'; | ||
|
||
import {Checkbox} from '@gravity-ui/uikit'; | ||
import type {ColumnDef} from '@tanstack/react-table'; | ||
|
||
export const defaultSelectionColumn: ColumnDef<unknown> = { | ||
import {SelectionCheckbox} from '../components'; | ||
|
||
export const selectionColumn: ColumnDef<unknown> = { | ||
id: '_select', | ||
header: ({table}) => ( | ||
<Checkbox | ||
size="l" | ||
<SelectionCheckbox | ||
checked={table.getIsAllRowsSelected()} | ||
disabled={!table.options.enableRowSelection} | ||
indeterminate={table.getIsSomeRowsSelected()} | ||
onChange={table.getToggleAllRowsSelectedHandler()} | ||
/> | ||
), | ||
cell: ({row}) => ( | ||
<Checkbox | ||
size="l" | ||
<SelectionCheckbox | ||
checked={row.getIsSelected()} | ||
disabled={!row.getCanSelect()} | ||
indeterminate={row.getIsSomeSelected()} | ||
onChange={row.getToggleSelectedHandler()} | ||
/> | ||
), | ||
size: 41, | ||
minSize: 41, | ||
size: 32, | ||
minSize: 32, | ||
}; |
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