@vygruppen/spor-react 12.23.0 → 12.24.0
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.
- package/.turbo/turbo-build.log +8 -8
- package/.turbo/turbo-postinstall.log +2 -2
- package/CHANGELOG.md +10 -0
- package/dist/index.cjs +34 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +35 -26
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
- package/src/table/Table.tsx +33 -21
- package/src/table/sort-utils.ts +6 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vygruppen/spor-react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.24.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"react-stately": "^3.31.1",
|
|
47
47
|
"react-swipeable": "^7.0.1",
|
|
48
48
|
"usehooks-ts": "^3.1.0",
|
|
49
|
+
"@vygruppen/spor-icon-react": "4.5.1",
|
|
49
50
|
"@vygruppen/spor-design-tokens": "4.3.2",
|
|
50
|
-
"@vygruppen/spor-loader": "0.7.0"
|
|
51
|
-
"@vygruppen/spor-icon-react": "4.5.1"
|
|
51
|
+
"@vygruppen/spor-loader": "0.7.0"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@react-types/datepicker": "^3.10.0",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"vitest": "^0.26.3",
|
|
69
69
|
"vitest-axe": "^0.1.0",
|
|
70
70
|
"vitest-canvas-mock": "^0.2.2",
|
|
71
|
-
"@vygruppen/
|
|
72
|
-
"@vygruppen/
|
|
71
|
+
"@vygruppen/eslint-config": "2.1.0",
|
|
72
|
+
"@vygruppen/tsconfig": "0.1.1"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"react": ">=18.0.0 <19.0.0",
|
package/src/table/Table.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
+
Button,
|
|
3
4
|
HStack,
|
|
4
5
|
RecipeVariantProps,
|
|
5
6
|
Table as ChakraTable,
|
|
@@ -10,8 +11,9 @@ import {
|
|
|
10
11
|
useSlotRecipe,
|
|
11
12
|
} from "@chakra-ui/react";
|
|
12
13
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
ArrowDownFill18Icon,
|
|
15
|
+
ArrowUpFill18Icon,
|
|
16
|
+
ChangeDirectionFill18Icon,
|
|
15
17
|
} from "@vygruppen/spor-icon-react";
|
|
16
18
|
import {
|
|
17
19
|
createContext,
|
|
@@ -119,31 +121,41 @@ export type TableColumnHeaderProps = ChakraTableColumnHeaderProps;
|
|
|
119
121
|
export const TableColumnHeader = forwardRef<
|
|
120
122
|
HTMLTableCellElement,
|
|
121
123
|
TableColumnHeaderProps
|
|
122
|
-
>(({ children,
|
|
124
|
+
>(({ children, ...rest }, ref) => {
|
|
123
125
|
const { enabled, sortState, onSort } = useTableSort();
|
|
124
126
|
const key = getSortKey(children);
|
|
125
|
-
const
|
|
127
|
+
const props = rest as Record<string, unknown>;
|
|
128
|
+
const columnSortable = enabled && key != null && !("data-nosort" in props);
|
|
129
|
+
const isActive = columnSortable && key === sortState.key;
|
|
126
130
|
|
|
127
131
|
return (
|
|
128
|
-
<ChakraTable.ColumnHeader
|
|
129
|
-
ref={ref}
|
|
130
|
-
onClick={(event) => {
|
|
131
|
-
if (enabled && key) {
|
|
132
|
-
onSort(key, getColumnIndex(event.currentTarget));
|
|
133
|
-
}
|
|
134
|
-
onClick?.(event);
|
|
135
|
-
}}
|
|
136
|
-
cursor={enabled && key ? "pointer" : undefined}
|
|
137
|
-
{...rest}
|
|
138
|
-
>
|
|
132
|
+
<ChakraTable.ColumnHeader ref={ref} {...rest}>
|
|
139
133
|
<HStack>
|
|
140
134
|
{children}
|
|
141
|
-
{
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
135
|
+
{columnSortable && (
|
|
136
|
+
<Button
|
|
137
|
+
variant="ghost"
|
|
138
|
+
onClick={(event) => {
|
|
139
|
+
const th = event.currentTarget.closest("th");
|
|
140
|
+
if (th) onSort(key, getColumnIndex(th));
|
|
141
|
+
}}
|
|
142
|
+
p="0px !important"
|
|
143
|
+
size="xs"
|
|
144
|
+
>
|
|
145
|
+
{isActive ? (
|
|
146
|
+
sortState.direction === "asc" ? (
|
|
147
|
+
<ArrowUpFill18Icon color="outline.focus" />
|
|
148
|
+
) : (
|
|
149
|
+
<ArrowDownFill18Icon color="outline.focus" />
|
|
150
|
+
)
|
|
151
|
+
) : (
|
|
152
|
+
<ChangeDirectionFill18Icon
|
|
153
|
+
transform="rotate(90deg)"
|
|
154
|
+
color="icon.disabled"
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
</Button>
|
|
158
|
+
)}
|
|
147
159
|
</HStack>
|
|
148
160
|
</ChakraTable.ColumnHeader>
|
|
149
161
|
);
|
package/src/table/sort-utils.ts
CHANGED
|
@@ -11,12 +11,12 @@ export const getNextSortState = (
|
|
|
11
11
|
current: SortState,
|
|
12
12
|
key: string,
|
|
13
13
|
columnIndex: number,
|
|
14
|
-
): SortState =>
|
|
15
|
-
key,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
14
|
+
): SortState => {
|
|
15
|
+
if (current.key !== key) return { key, columnIndex, direction: "asc" };
|
|
16
|
+
if (current.direction === "asc")
|
|
17
|
+
return { key, columnIndex, direction: "desc" };
|
|
18
|
+
return { key: null, direction: "asc", columnIndex: null }; // Initial sort state
|
|
19
|
+
};
|
|
20
20
|
|
|
21
21
|
export const getSortKey = (children: ReactNode) =>
|
|
22
22
|
typeof children === "string" ? children.trim() : null;
|