@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vygruppen/spor-react",
3
3
  "type": "module",
4
- "version": "12.23.0",
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/tsconfig": "0.1.1",
72
- "@vygruppen/eslint-config": "2.1.0"
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",
@@ -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
- DropdownDownFill18Icon,
14
- DropdownUpFill18Icon,
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, onClick, ...rest }, ref) => {
124
+ >(({ children, ...rest }, ref) => {
123
125
  const { enabled, sortState, onSort } = useTableSort();
124
126
  const key = getSortKey(children);
125
- const isActive = enabled && key != null && key === sortState.key;
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
- {isActive &&
142
- (sortState.direction === "asc" ? (
143
- <DropdownUpFill18Icon />
144
- ) : (
145
- <DropdownDownFill18Icon />
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
  );
@@ -11,12 +11,12 @@ export const getNextSortState = (
11
11
  current: SortState,
12
12
  key: string,
13
13
  columnIndex: number,
14
- ): SortState => ({
15
- key,
16
- columnIndex,
17
- direction:
18
- current.key === key && current.direction === "asc" ? "desc" : "asc",
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;