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.
feat(Table): styled SortIndicator added
- Loading branch information
Showing
27 changed files
with
131 additions
and
17 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
2 changes: 1 addition & 1 deletion
2
src/components/BaseTable/__stories__/stories/EmptyContentStory.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
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
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
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
2 changes: 1 addition & 1 deletion
2
src/components/BaseTable/__stories__/stories/StickyHeaderStory.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
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
2 changes: 1 addition & 1 deletion
2
src/components/BaseTable/__stories__/stories/VirtualizationStory.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
2 changes: 1 addition & 1 deletion
2
src/components/BaseTable/__stories__/stories/WindowVirtualizationStory.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
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
2 changes: 1 addition & 1 deletion
2
src/components/BaseTable/__stories__/stories/WithoutHeaderStory.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
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('styled-sort-indicator'); |
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,15 @@ | ||
@use '../variables'; | ||
|
||
$block: '.#{variables.$ns}styled-sort-indicator'; | ||
|
||
#{$block} { | ||
display: inline-flex; | ||
padding-block: 1px; | ||
|
||
color: var(--g-color-text-hint); | ||
|
||
&_order_asc, | ||
&_order_desc { | ||
color: var(--g-color-text-primary); | ||
} | ||
} |
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,25 @@ | ||
import React from 'react'; | ||
|
||
import {Icon} from '@gravity-ui/uikit'; | ||
|
||
import {getSortIndicatorIcon} from '../../utils'; | ||
import type {BaseSortIndicatorProps} from '../BaseSortIndicator'; | ||
|
||
import {b} from './SortIndicator.classname'; | ||
|
||
import './SortIndicator.scss'; | ||
|
||
export interface SortIndicatorProps<TData, TValue> extends BaseSortIndicatorProps<TData, TValue> {} | ||
|
||
export const SortIndicator = <TData, TValue>({ | ||
className, | ||
header, | ||
}: SortIndicatorProps<TData, TValue>) => { | ||
const order = header.column.getIsSorted(); | ||
|
||
return ( | ||
<span className={b({order}, className)}> | ||
<Icon data={getSortIndicatorIcon(order)} size={16} /> | ||
</span> | ||
); | ||
}; |
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 './SortIndicator'; |
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/Table/__stories__/stories/SortingStory.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 {cn} from '../../../../utils'; | ||
|
||
export const cnSortingStory = cn('sorting-story'); |
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,6 @@ | ||
.sorting-story { | ||
&__sort-indicator { | ||
margin-inline-start: var(--g-spacing-1); | ||
vertical-align: top; | ||
} | ||
} |
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,37 @@ | ||
import React from 'react'; | ||
|
||
import type {SortingState} from '@tanstack/react-table'; | ||
|
||
import {useTable} from '../../../../hooks'; | ||
import {columns} from '../../../BaseTable/__stories__/constants/columns'; | ||
import {data} from '../../../BaseTable/__stories__/constants/data'; | ||
import {SortIndicator} from '../../../SortIndicator'; | ||
import {Table} from '../../Table'; | ||
|
||
import {cnSortingStory} from './SortingStory.classname'; | ||
|
||
import './SortingStory.scss'; | ||
|
||
export const SortingStory = () => { | ||
const [sorting, setSorting] = React.useState<SortingState>([]); | ||
|
||
const table = useTable({ | ||
columns, | ||
data, | ||
enableSorting: true, | ||
getRowId: (item) => item.id, | ||
onSortingChange: setSorting, | ||
state: { | ||
sorting, | ||
}, | ||
}); | ||
|
||
return ( | ||
<Table | ||
table={table} | ||
className={cnSortingStory()} | ||
renderSortIndicator={(sortIndicatorProps) => <SortIndicator {...sortIndicatorProps} />} | ||
sortIndicatorClassName={cnSortingStory('sort-indicator')} | ||
/> | ||
); | ||
}; |
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,18 @@ | ||
import { | ||
ArrowDown as ArrowDownIcon, | ||
ArrowUpArrowDown as ArrowUpArrowDownIcon, | ||
ArrowUp as ArrowUpIcon, | ||
} from '@gravity-ui/icons'; | ||
import type {SortDirection} from '@tanstack/react-table'; | ||
|
||
export const getSortIndicatorIcon = (sortDirection: SortDirection | false) => { | ||
if (sortDirection === 'asc') { | ||
return ArrowUpIcon; | ||
} | ||
|
||
if (sortDirection === 'desc') { | ||
return ArrowDownIcon; | ||
} | ||
|
||
return ArrowUpArrowDownIcon; | ||
}; |
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