@navikt/ds-react 0.18.6 → 0.18.7

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@navikt/ds-react",
3
- "version": "0.18.6",
3
+ "version": "0.18.7",
4
4
  "private": false,
5
5
  "description": "NAV designsystem react components",
6
6
  "author": "NAV Designsystem team",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@floating-ui/react-dom": "0.6.0",
40
40
  "@material-ui/core": "^4.12.3",
41
- "@navikt/ds-icons": "^0.8.12",
41
+ "@navikt/ds-icons": "^0.8.13",
42
42
  "@popperjs/core": "^2.10.1",
43
43
  "@radix-ui/react-tabs": "0.1.5",
44
44
  "@radix-ui/react-toggle-group": "0.1.5",
@@ -74,5 +74,5 @@
74
74
  "@types/react": "^17.0.30 || ^18.0.0",
75
75
  "react": "^17.0.0 || ^18.0.0"
76
76
  },
77
- "gitHead": "f14b5211dc8181b0b155c0e86c1652ce6854bca5"
77
+ "gitHead": "46b1186bb8614fd065e87c09b139a095b8993778"
78
78
  }
@@ -1,5 +1,4 @@
1
1
  import React, { useState } from "react";
2
- import { rest } from "msw";
3
2
  import useSWR from "swr";
4
3
  import people from "./people.json";
5
4
  import { Table } from "../index";
@@ -21,6 +20,42 @@ const queryString = (obj) =>
21
20
  .map((key) => key + "=" + obj[key])
22
21
  .join("&");
23
22
 
23
+ const updateData = async (url: string) => {
24
+ const newUrl = new URL(`https://www.example.com/${url}`);
25
+ const comparator = (a, b, orderBy) => {
26
+ if (b[orderBy] < a[orderBy]) {
27
+ return -1;
28
+ }
29
+ if (b[orderBy] > a[orderBy]) {
30
+ return 1;
31
+ }
32
+ return 0;
33
+ };
34
+
35
+ const page = Number(newUrl.searchParams.get("page"));
36
+ const sort = newUrl.searchParams.get("sort");
37
+
38
+ await new Promise((resolve) =>
39
+ setTimeout(resolve, Math.round(Math.random() * (1000 - 200) + 200))
40
+ );
41
+
42
+ return {
43
+ count: people.length,
44
+ results: people
45
+ .slice()
46
+ .sort((a, b) => {
47
+ if (sort) {
48
+ const [orderBy, direction] = sort.split(":");
49
+ return direction === "ascending"
50
+ ? comparator(b, a, orderBy)
51
+ : comparator(a, b, orderBy);
52
+ }
53
+ return 1;
54
+ })
55
+ .slice((page - 1) * rowsPerPage, page * rowsPerPage),
56
+ };
57
+ };
58
+
24
59
  export const Async = () => {
25
60
  const [page, setPage] = useState(1);
26
61
  const [sort, setSort] = useState<SortState>();
@@ -30,7 +65,7 @@ export const Async = () => {
30
65
  page,
31
66
  sort: sort ? `${sort.orderBy}:${sort.direction}` : undefined,
32
67
  })}`,
33
- (url) => fetch(url).then((res) => res.json())
68
+ (url) => updateData(url)
34
69
  );
35
70
 
36
71
  if (!data) {
@@ -128,42 +163,3 @@ export const Async = () => {
128
163
  </div>
129
164
  );
130
165
  };
131
-
132
- Async.parameters = {
133
- msw: {
134
- handlers: [
135
- rest.get("/people", (req, res, ctx) => {
136
- const comparator = (a, b, orderBy) => {
137
- if (b[orderBy] < a[orderBy]) {
138
- return -1;
139
- }
140
- if (b[orderBy] > a[orderBy]) {
141
- return 1;
142
- }
143
- return 0;
144
- };
145
-
146
- const page = Number(req.url.searchParams.get("page"));
147
- const sort = req.url.searchParams.get("sort");
148
- return res(
149
- //ctx.delay(),
150
- ctx.json({
151
- count: people.length,
152
- results: people
153
- .slice()
154
- .sort((a, b) => {
155
- if (sort) {
156
- const [orderBy, direction] = sort.split(":");
157
- return direction === "ascending"
158
- ? comparator(b, a, orderBy)
159
- : comparator(a, b, orderBy);
160
- }
161
- return 1;
162
- })
163
- .slice((page - 1) * rowsPerPage, page * rowsPerPage),
164
- })
165
- );
166
- }),
167
- ],
168
- },
169
- };