@digigov/ui 2.0.0-6e3977bc → 2.0.0-834daea4

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.
Files changed (322) hide show
  1. package/app/Header/__stories__/WithServiceNameAndLogo/index.js +2 -2
  2. package/app/Header/__stories__/WithServiceNameAndLogo.js.map +2 -2
  3. package/app/Loader/index.d.ts +1 -1
  4. package/app/Loader/index.js +1 -1
  5. package/app/Loader/index.js.map +1 -1
  6. package/app/Loader/index.native/index.js +102 -0
  7. package/{api/APIErrors → app/Loader/index.native}/package.json +1 -1
  8. package/app/Loader/index.native.d.ts +3 -0
  9. package/app/Loader/index.native.js.map +7 -0
  10. package/app/Loader/index.web/index.js +2 -0
  11. package/{api/fetchAPI → app/Loader/index.web}/package.json +1 -1
  12. package/app/Loader/index.web.d.ts +1 -0
  13. package/app/Loader/index.web.js.map +7 -0
  14. package/app/Masthead/Masthead.stories/index.js +2 -0
  15. package/app/Masthead/Masthead.stories.d.ts +1 -0
  16. package/app/Masthead/Masthead.stories.js.map +2 -2
  17. package/app/Masthead/__stories__/Secondary/index.js +13 -0
  18. package/app/Masthead/__stories__/Secondary/package.json +6 -0
  19. package/app/Masthead/__stories__/Secondary.d.ts +3 -0
  20. package/app/Masthead/__stories__/Secondary.js.map +7 -0
  21. package/app/Modal/auto/index.js +1 -1
  22. package/app/Modal/auto.js.map +2 -2
  23. package/app/Modal/index.d.ts +2 -2
  24. package/app/Modal/index.js +2 -2
  25. package/app/Modal/index.js.map +1 -1
  26. package/app/Modal/index.native/index.js +20 -0
  27. package/{api → app/Modal/index.native}/package.json +1 -1
  28. package/app/Modal/index.native.d.ts +7 -0
  29. package/app/Modal/index.native.js.map +7 -0
  30. package/app/Modal/{Modal → index.web}/index.js +3 -3
  31. package/{api/APIProvider → app/Modal/index.web}/package.json +1 -1
  32. package/app/Modal/{Modal.js.map → index.web.js.map} +2 -2
  33. package/app/QrCodeScanner/index.js.map +2 -2
  34. package/cjs/app/Header/__stories__/WithServiceNameAndLogo.js.map +3 -3
  35. package/cjs/app/Loader/index.js +3 -3
  36. package/cjs/app/Loader/index.js.map +2 -2
  37. package/cjs/app/Loader/index.native/index.js +135 -0
  38. package/cjs/app/Loader/index.native.js.map +7 -0
  39. package/cjs/app/Loader/index.web/index.js +22 -0
  40. package/cjs/app/Loader/index.web.js.map +7 -0
  41. package/cjs/app/Masthead/Masthead.stories/index.js +3 -0
  42. package/cjs/app/Masthead/Masthead.stories.js.map +2 -2
  43. package/cjs/app/Masthead/__stories__/Secondary/index.js +46 -0
  44. package/cjs/app/Masthead/__stories__/Secondary.js.map +7 -0
  45. package/cjs/app/Modal/auto/index.js +1 -1
  46. package/cjs/app/Modal/auto.js.map +2 -2
  47. package/cjs/app/Modal/index.js +3 -3
  48. package/cjs/app/Modal/index.js.map +2 -2
  49. package/cjs/{api/APIProvider → app/Modal/index.native}/index.js +20 -26
  50. package/cjs/app/Modal/index.native.js.map +7 -0
  51. package/cjs/app/Modal/{Modal → index.web}/index.js +6 -6
  52. package/cjs/app/Modal/{Modal.js.map → index.web.js.map} +2 -2
  53. package/cjs/app/QrCodeScanner/index.js.map +2 -2
  54. package/cjs/content/Table/Table.stories/index.js +3 -3
  55. package/cjs/content/Table/Table.stories.js.map +2 -2
  56. package/cjs/content/Table/__stories__/{Densed → Dense}/index.js +9 -9
  57. package/cjs/content/Table/__stories__/{Densed.js.map → Dense.js.map} +3 -3
  58. package/cjs/feedback/CopyToClipboard/__stories__/Default/index.js +1 -1
  59. package/cjs/feedback/CopyToClipboard/__stories__/Default.js.map +2 -2
  60. package/cjs/form/DateInputContainer/__stories__/MultipleQuestions/index.js +1 -1
  61. package/cjs/form/DateInputContainer/__stories__/MultipleQuestions.js.map +1 -1
  62. package/cjs/form/SearchContainer/SearchContainer.stories/index.js +46 -0
  63. package/cjs/form/SearchContainer/SearchContainer.stories.js.map +7 -0
  64. package/cjs/{api/APIErrors → form/SearchContainer/__stories__/Default}/index.js +12 -42
  65. package/cjs/form/SearchContainer/__stories__/Default.js.map +7 -0
  66. package/cjs/i18n/locales/el/index.js +7 -1
  67. package/cjs/i18n/locales/el.js.map +2 -2
  68. package/cjs/layouts/Basic/Bottom/__stories__/Default/index.js +7 -5
  69. package/cjs/layouts/Basic/Bottom/__stories__/Default.js.map +3 -3
  70. package/cjs/layouts/Basic/Container/__stories__/Default/index.js +6 -4
  71. package/cjs/layouts/Basic/Container/__stories__/Default.js.map +3 -3
  72. package/cjs/layouts/Basic/Main/__stories__/Default/index.js +6 -4
  73. package/cjs/layouts/Basic/Main/__stories__/Default.js.map +3 -3
  74. package/cjs/layouts/Basic/Top/__stories__/Default/index.js +6 -4
  75. package/cjs/layouts/Basic/Top/__stories__/Default.js.map +3 -3
  76. package/cjs/lazy/index.js +3 -7
  77. package/cjs/lazy.js.map +2 -2
  78. package/cjs/navigation/Breadcrumbs/Breadcrumbs.stories.js.map +1 -1
  79. package/cjs/navigation/Drawer/__stories__/Auto/index.js +3 -1
  80. package/cjs/navigation/Drawer/__stories__/Auto.js.map +2 -2
  81. package/cjs/navigation/Drawer/__stories__/Default/index.js +2 -2
  82. package/cjs/navigation/Drawer/__stories__/Default.js.map +3 -3
  83. package/cjs/navigation/NavList/__stories__/UsingNavListAuto/index.js +22 -22
  84. package/cjs/navigation/NavList/__stories__/UsingNavListAuto.js.map +2 -2
  85. package/cjs/navigation/NavList/__stories__/Vertical/index.js +25 -17
  86. package/cjs/navigation/NavList/__stories__/Vertical.js.map +2 -2
  87. package/cjs/navigation/Pagination/__stories__/Auto/index.js +7 -9
  88. package/cjs/navigation/Pagination/__stories__/Auto.js.map +3 -3
  89. package/cjs/registry/index.js +6 -18
  90. package/cjs/registry.js.map +2 -2
  91. package/content/Table/Table.stories/index.js +2 -2
  92. package/content/Table/Table.stories.d.ts +1 -1
  93. package/content/Table/Table.stories.js.map +2 -2
  94. package/content/Table/__stories__/{Densed → Dense}/index.js +5 -5
  95. package/content/Table/__stories__/Dense/package.json +6 -0
  96. package/content/Table/__stories__/Dense.d.ts +3 -0
  97. package/content/Table/__stories__/{Densed.js.map → Dense.js.map} +3 -3
  98. package/feedback/CopyToClipboard/__stories__/Default/index.js +1 -1
  99. package/feedback/CopyToClipboard/__stories__/Default.js.map +2 -2
  100. package/form/DateInputContainer/__stories__/MultipleQuestions/index.js +1 -1
  101. package/form/DateInputContainer/__stories__/MultipleQuestions.js.map +1 -1
  102. package/form/SearchContainer/SearchContainer.stories/index.js +13 -0
  103. package/form/SearchContainer/SearchContainer.stories/package.json +6 -0
  104. package/form/SearchContainer/SearchContainer.stories.d.ts +9 -0
  105. package/form/SearchContainer/SearchContainer.stories.js.map +7 -0
  106. package/form/SearchContainer/__stories__/Default/index.js +11 -0
  107. package/form/SearchContainer/__stories__/Default/package.json +6 -0
  108. package/form/SearchContainer/__stories__/Default.d.ts +3 -0
  109. package/form/SearchContainer/__stories__/Default.js.map +7 -0
  110. package/form/SearchContainer/index.test.d.ts +1 -0
  111. package/i18n/locales/el/index.js +7 -1
  112. package/i18n/locales/el.d.ts +6 -0
  113. package/i18n/locales/el.js.map +2 -2
  114. package/index.js +1 -1
  115. package/layouts/Basic/Bottom/__stories__/Default/index.js +7 -5
  116. package/layouts/Basic/Bottom/__stories__/Default.js.map +2 -2
  117. package/layouts/Basic/Container/__stories__/Default/index.js +6 -4
  118. package/layouts/Basic/Container/__stories__/Default.js.map +2 -2
  119. package/layouts/Basic/Main/__stories__/Default/index.js +6 -4
  120. package/layouts/Basic/Main/__stories__/Default.js.map +2 -2
  121. package/layouts/Basic/Top/__stories__/Default/index.js +6 -4
  122. package/layouts/Basic/Top/__stories__/Default.js.map +2 -2
  123. package/lazy/index.js +3 -7
  124. package/lazy.d.ts +1 -5
  125. package/lazy.js.map +2 -2
  126. package/navigation/Breadcrumbs/Breadcrumbs.stories.js.map +1 -1
  127. package/navigation/Drawer/__stories__/Auto/index.js +3 -1
  128. package/navigation/Drawer/__stories__/Auto.d.ts +1 -0
  129. package/navigation/Drawer/__stories__/Auto.js.map +2 -2
  130. package/navigation/Drawer/__stories__/Default/index.js +1 -1
  131. package/navigation/Drawer/__stories__/Default.js.map +2 -2
  132. package/navigation/NavList/__stories__/UsingNavListAuto/index.js +23 -23
  133. package/navigation/NavList/__stories__/UsingNavListAuto.js.map +2 -2
  134. package/navigation/NavList/__stories__/Vertical/index.js +25 -17
  135. package/navigation/NavList/__stories__/Vertical.js.map +2 -2
  136. package/navigation/Pagination/__stories__/Auto/index.js +8 -12
  137. package/navigation/Pagination/__stories__/Auto.js.map +2 -2
  138. package/package.json +10 -8
  139. package/registry/index.js +6 -18
  140. package/registry.d.ts +4 -9
  141. package/registry.js.map +2 -2
  142. package/src/app/Footer/{index.mdx → doc.mdx} +7 -23
  143. package/src/app/Header/__snapshots__/index.spec.tsx.snap +42 -36
  144. package/src/app/Header/__stories__/WithServiceNameAndLogo.tsx +2 -2
  145. package/src/app/Header/doc.mdx +32 -0
  146. package/src/app/Loader/index.native.tsx +98 -0
  147. package/src/app/Loader/index.tsx +1 -1
  148. package/src/app/Loader/index.web.tsx +1 -0
  149. package/src/app/Masthead/Masthead.stories.js +1 -0
  150. package/src/app/Masthead/__stories__/Secondary.tsx +26 -0
  151. package/src/app/Masthead/{index.mdx → doc.mdx} +13 -1
  152. package/src/app/Masthead/index.test.tsx +4 -0
  153. package/src/app/Modal/auto.tsx +1 -1
  154. package/src/app/Modal/{index.mdx → doc.mdx} +9 -6
  155. package/src/app/Modal/index.native.tsx +17 -0
  156. package/src/app/Modal/index.tsx +2 -2
  157. package/src/app/NotFound/{index.mdx → doc.mdx} +2 -4
  158. package/src/app/Panel/{index.mdx → doc.mdx} +3 -1
  159. package/src/app/PhaseBannerHeader/{index.mdx → doc.mdx} +3 -5
  160. package/src/app/QrCodeScanner/__snapshots__/index.spec.tsx.snap +6 -10
  161. package/src/app/QrCodeScanner/index.tsx +1 -0
  162. package/src/app/QrCodeViewer/{index.mdx → doc.mdx} +4 -12
  163. package/src/app/Skeleton/doc.mdx +42 -0
  164. package/src/content/Accordion/__snapshots__/index.spec.tsx.snap +48 -147
  165. package/src/content/Accordion/{index.mdx → doc.mdx} +2 -13
  166. package/src/content/Blockquote/__snapshots__/index.spec.tsx.snap +6 -9
  167. package/src/content/Blockquote/{index.mdx → doc.mdx} +5 -5
  168. package/src/content/Card/doc.mdx +71 -0
  169. package/src/content/Chip/doc.mdx +34 -0
  170. package/src/content/Details/__snapshots__/index.spec.tsx.snap +32 -69
  171. package/src/content/Details/{index.mdx → doc.mdx} +1 -5
  172. package/src/content/List/__snapshots__/index.spec.tsx.snap +3 -3
  173. package/src/content/List/doc.mdx +28 -0
  174. package/src/content/StepNav/{index.mdx → doc.mdx} +5 -19
  175. package/src/content/SummaryList/__snapshots__/index.spec.tsx.snap +37 -89
  176. package/src/content/SummaryList/{index.mdx → doc.mdx} +6 -18
  177. package/src/content/Table/Table.stories.js +1 -1
  178. package/src/content/Table/__stories__/{Densed.tsx → Dense.tsx} +2 -2
  179. package/src/content/Table/doc.mdx +81 -0
  180. package/src/content/Table/index.test.tsx +3 -3
  181. package/src/content/TaskList/{index.mdx → doc.mdx} +4 -6
  182. package/src/content/Timeline/{index.mdx → doc.mdx} +4 -6
  183. package/src/feedback/CopyToClipboard/__stories__/Default.tsx +1 -1
  184. package/src/feedback/CopyToClipboard/doc.mdx +22 -0
  185. package/src/feedback/ErrorSummary/__snapshots__/index.spec.tsx.snap +3 -3
  186. package/src/feedback/ErrorSummary/{index.mdx → doc.mdx} +6 -22
  187. package/src/feedback/NotificationBanner/__snapshots__/index.spec.tsx.snap +1 -1
  188. package/src/feedback/NotificationBanner/{index.mdx → doc.mdx} +8 -19
  189. package/src/feedback/PhaseBanner/{index.mdx → doc.mdx} +2 -12
  190. package/src/feedback/WarningText/__snapshots__/index.spec.tsx.snap +3 -3
  191. package/src/feedback/WarningText/{index.mdx → doc.mdx} +8 -6
  192. package/src/form/AutoComplete/doc.mdx +50 -0
  193. package/src/form/Button/__snapshots__/index.spec.tsx.snap +6 -10
  194. package/src/form/Button/{index.mdx → doc.mdx} +12 -27
  195. package/src/form/Checkbox/{index.mdx → doc.mdx} +10 -36
  196. package/src/form/DateInputContainer/__stories__/MultipleQuestions.tsx +1 -1
  197. package/src/form/DateInputContainer/{index.mdx → doc.mdx} +7 -21
  198. package/src/form/ErrorMessage/{index.mdx → doc.mdx} +1 -5
  199. package/src/form/FileUpload/{index.mdx → doc.mdx} +2 -10
  200. package/src/form/RadioContainer/{index.mdx → doc.mdx} +10 -36
  201. package/src/form/SearchContainer/SearchContainer.stories.js +9 -0
  202. package/src/form/SearchContainer/__stories__/Default.tsx +13 -0
  203. package/src/form/SearchContainer/doc.mdx +16 -0
  204. package/src/form/SearchContainer/index.test.tsx +20 -0
  205. package/src/form/SelectContainer/{index.mdx → doc.mdx} +3 -19
  206. package/src/form/SingleCharacterInputs/{index.mdx → doc.mdx} +3 -11
  207. package/src/form/TextArea/doc.mdx +48 -0
  208. package/src/form/TextInput/{index.mdx → doc.mdx} +12 -44
  209. package/src/i18n/locales/el.ts +15 -8
  210. package/src/layouts/Basic/Bottom/__stories__/Default.tsx +13 -9
  211. package/src/layouts/Basic/Bottom/{index.mdx → doc.mdx} +1 -5
  212. package/src/layouts/Basic/Container/__stories__/Default.tsx +15 -8
  213. package/src/layouts/Basic/Container/{index.mdx → doc.mdx} +1 -6
  214. package/src/layouts/Basic/Main/__stories__/Default.tsx +15 -8
  215. package/src/layouts/Basic/Main/{index.mdx → doc.mdx} +3 -5
  216. package/src/layouts/Basic/Top/__stories__/Default.tsx +13 -6
  217. package/src/layouts/Basic/Top/doc.mdx +19 -0
  218. package/src/layouts/Basic/__snapshots__/index.spec.tsx.snap +30 -102
  219. package/src/layouts/Basic/{index.mdx → doc.mdx} +7 -18
  220. package/src/layouts/Grid/doc.mdx +26 -0
  221. package/src/layouts/Stack/doc.mdx +38 -0
  222. package/src/lazy.js +4 -8
  223. package/src/navigation/BackLink/{index.mdx → doc.mdx} +1 -5
  224. package/src/navigation/Breadcrumbs/Breadcrumbs.stories.js +0 -1
  225. package/src/navigation/Breadcrumbs/{index.mdx → doc.mdx} +5 -5
  226. package/src/navigation/Drawer/__stories__/Auto.tsx +3 -1
  227. package/src/navigation/Drawer/__stories__/Default.tsx +2 -2
  228. package/src/navigation/Drawer/{index.mdx → doc.mdx} +5 -1
  229. package/src/navigation/Dropdown/{index.mdx → doc.mdx} +3 -15
  230. package/src/navigation/Link/__snapshots__/index.spec.tsx.snap +16 -30
  231. package/src/navigation/Link/{index.mdx → doc.mdx} +7 -19
  232. package/src/navigation/NavList/__snapshots__/index.spec.tsx.snap +3 -3
  233. package/src/navigation/NavList/__stories__/UsingNavListAuto.tsx +26 -27
  234. package/src/navigation/NavList/__stories__/Vertical.tsx +16 -12
  235. package/src/navigation/NavList/{index.mdx → doc.mdx} +19 -22
  236. package/src/navigation/Pagination/__stories__/Auto.tsx +29 -31
  237. package/src/navigation/Pagination/doc.mdx +32 -0
  238. package/src/navigation/Tabs/doc.mdx +47 -0
  239. package/src/registry.js +6 -18
  240. package/src/typography/CodeBlock/doc.mdx +30 -0
  241. package/src/typography/Heading/{index.mdx → doc.mdx} +3 -5
  242. package/src/typography/HeadingCaption/{index.mdx → doc.mdx} +5 -5
  243. package/src/typography/Hint/{index.mdx → doc.mdx} +4 -10
  244. package/src/typography/NormalText/doc.mdx +30 -0
  245. package/src/typography/Paragraph/doc.mdx +34 -0
  246. package/src/typography/Typography/doc.mdx +14 -0
  247. package/src/utils/VisuallyHidden/{index.mdx → doc.mdx} +3 -6
  248. package/api/APIErrors/index.js +0 -40
  249. package/api/APIErrors.d.ts +0 -23
  250. package/api/APIErrors.js.map +0 -7
  251. package/api/APIProvider/index.js +0 -24
  252. package/api/APIProvider.d.ts +0 -16
  253. package/api/APIProvider.js.map +0 -7
  254. package/api/fetchAPI/index.js +0 -29
  255. package/api/fetchAPI.d.ts +0 -14
  256. package/api/fetchAPI.js.map +0 -7
  257. package/api/index.d.ts +0 -8
  258. package/api/index.js +0 -12
  259. package/api/index.js.map +0 -7
  260. package/api/index.spec.d.ts +0 -1
  261. package/api/useResource/index.js +0 -79
  262. package/api/useResource/package.json +0 -6
  263. package/api/useResource.d.ts +0 -11
  264. package/api/useResource.js.map +0 -7
  265. package/api/useResourceAction/index.js +0 -74
  266. package/api/useResourceAction/package.json +0 -6
  267. package/api/useResourceAction.d.ts +0 -2
  268. package/api/useResourceAction.js.map +0 -7
  269. package/api/useResourceQuery/index.js +0 -149
  270. package/api/useResourceQuery/package.json +0 -6
  271. package/api/useResourceQuery.d.ts +0 -18
  272. package/api/useResourceQuery.js.map +0 -7
  273. package/api/utils/index.js +0 -131
  274. package/api/utils/package.json +0 -6
  275. package/api/utils.d.ts +0 -10
  276. package/api/utils.js.map +0 -7
  277. package/app/Modal/Modal/package.json +0 -6
  278. package/cjs/api/APIErrors.js.map +0 -7
  279. package/cjs/api/APIProvider.js.map +0 -7
  280. package/cjs/api/fetchAPI/index.js +0 -49
  281. package/cjs/api/fetchAPI.js.map +0 -7
  282. package/cjs/api/index.js +0 -41
  283. package/cjs/api/index.js.map +0 -7
  284. package/cjs/api/useResource/index.js +0 -102
  285. package/cjs/api/useResource.js.map +0 -7
  286. package/cjs/api/useResourceAction/index.js +0 -97
  287. package/cjs/api/useResourceAction.js.map +0 -7
  288. package/cjs/api/useResourceQuery/index.js +0 -173
  289. package/cjs/api/useResourceQuery.js.map +0 -7
  290. package/cjs/api/utils/index.js +0 -157
  291. package/cjs/api/utils.js.map +0 -7
  292. package/content/Table/__stories__/Densed/package.json +0 -6
  293. package/content/Table/__stories__/Densed.d.ts +0 -3
  294. package/src/api/APIErrors.tsx +0 -46
  295. package/src/api/APIProvider.tsx +0 -31
  296. package/src/api/fetchAPI.ts +0 -43
  297. package/src/api/index.spec.tsx +0 -417
  298. package/src/api/index.tsx +0 -9
  299. package/src/api/introduction.md +0 -6
  300. package/src/api/useResource.tsx +0 -96
  301. package/src/api/useResourceAction.tsx +0 -80
  302. package/src/api/useResourceQuery.tsx +0 -178
  303. package/src/api/utils.tsx +0 -162
  304. package/src/app/Header/index.mdx +0 -49
  305. package/src/content/Card/index.mdx +0 -103
  306. package/src/content/Chip/index.mdx +0 -53
  307. package/src/content/List/index.mdx +0 -40
  308. package/src/content/Table/index.mdx +0 -111
  309. package/src/feedback/CopyToClipboard/index.mdx +0 -28
  310. package/src/form/AutoComplete/index.mdx +0 -70
  311. package/src/form/TextArea/index.mdx +0 -74
  312. package/src/govgr/Footer/index.mdx +0 -101
  313. package/src/layouts/Basic/Top/index.mdx +0 -23
  314. package/src/layouts/Grid/index.mdx +0 -39
  315. package/src/navigation/Pagination/index.mdx +0 -48
  316. package/src/navigation/Tabs/index.mdx +0 -31
  317. package/src/typography/NormalText/index.mdx +0 -44
  318. package/src/typography/Paragraph/index.mdx +0 -32
  319. package/src/typography/Typography/index.mdx +0 -12
  320. /package/app/Modal/{Modal.d.ts → index.web.d.ts} +0 -0
  321. /package/src/app/Modal/{Modal.tsx → index.web.tsx} +0 -0
  322. /package/src/utils/Base/{index.mdx → doc.mdx} +0 -0
@@ -1,178 +0,0 @@
1
- import { useEffect, useMemo, useState, useCallback } from 'react';
2
- import { usePaginatedQuery, QueryFunction, queryCache } from 'react-query';
3
- import { useAPI } from '@digigov/ui/api/APIProvider';
4
- import { getQueryKey, processResponse } from '@digigov/ui/api/utils';
5
-
6
- const DEFAULT_PAGINATION_LIMIT = 30;
7
- const DEFAULT_LIMIT_OPTIONS = [10, 30, 60, 100];
8
-
9
- export function useResourceManyBase(
10
- resource: string,
11
- query?: Record<string, any> | null | ((...args: any) => any),
12
- options?: RequestInit | null
13
- ): any {
14
- const {
15
- config: { baseURL },
16
- token,
17
- } = useAPI();
18
- const [{ url, dataSet }, setFetchOpts] = useState({
19
- url: '',
20
- dataSet: false,
21
- });
22
- const customFetcher: QueryFunction<any> = useCallback(
23
- async (fetchUrl, options) => {
24
- setFetchOpts({ url: fetchUrl, dataSet: false });
25
- const response = await fetch(fetchUrl, options);
26
- try {
27
- const { data } = await processResponse(response, true);
28
- if (data) {
29
- return Promise.resolve(data);
30
- }
31
- } catch (error) {
32
- return Promise.reject(error.error);
33
- }
34
- },
35
- []
36
- );
37
- const queryKey = getQueryKey(
38
- resource,
39
- null,
40
- query,
41
- null,
42
- options,
43
- 'GET',
44
- baseURL,
45
- token
46
- );
47
- let enabled = true;
48
- let resolvedQueryKey;
49
- if (typeof queryKey === 'function') {
50
- try {
51
- resolvedQueryKey = queryKey();
52
- } catch (err) {
53
- enabled = false;
54
- }
55
- }
56
-
57
- const {
58
- resolvedData,
59
- latestData: data,
60
- error,
61
- isFetching,
62
- refetch,
63
- } = usePaginatedQuery({
64
- queryKey: resolvedQueryKey || queryKey,
65
- queryFn: customFetcher,
66
- config: {
67
- enabled,
68
- suspense: true,
69
- cacheTime: 30000,
70
- refetchOnMount: false,
71
- },
72
- });
73
-
74
- return {
75
- data: data || resolvedData,
76
- loading: isFetching,
77
- loaded: !!data || !!error,
78
- error,
79
- invalidate: (): void => {
80
- queryCache.invalidateQueries(resolvedQueryKey || queryKey);
81
- },
82
- fetch: refetch,
83
- dataSet,
84
- url,
85
- };
86
- }
87
-
88
- export type UseResourceManyResponse = {
89
- data?: any;
90
- meta?: {
91
- total?: number;
92
- count?: number;
93
- };
94
- page: number;
95
- limit: number;
96
- totalPages: number;
97
- total: number;
98
- limitOptions: number[];
99
- setPage: (page: number) => void;
100
- setLimit: (limit: number) => void;
101
- hasNext: boolean;
102
- hasPrevious: boolean;
103
- };
104
- export function useResourceMany(
105
- resource: string,
106
- query?: Record<string, any> | null,
107
- options?: RequestInit | null
108
- ): UseResourceManyResponse {
109
- // allow developer to set a custom limit, fallback to a common value
110
- const [limit, setLimit] = useState(
111
- (query && query.limit) || DEFAULT_PAGINATION_LIMIT
112
- );
113
- const [pageParams, setPageParams] = useState({
114
- offset: (query && query.offset) || 0,
115
- limit,
116
- });
117
- // update options when limit is changed
118
- useEffect(() => {
119
- if (pageParams.limit !== limit) {
120
- setPageParams({ ...pageParams, limit: limit });
121
- }
122
- }, [limit]);
123
- // update user provided query with pagination params
124
- const queryKey = JSON.stringify(query);
125
- const pageParamsKey = JSON.stringify(pageParams);
126
- const q = useMemo(() => {
127
- return { ...pageParams, ...query };
128
- }, [queryKey, pageParamsKey]);
129
- const { data, ...rest } = useResourceManyBase(resource, q, options);
130
- // extract data/metadata from response
131
- const resp = data ? data.data : data;
132
- const meta = data ? data.meta : data;
133
- const totalPages = useMemo(
134
- () => (data && data.meta && data.meta.total) || 1,
135
- [data]
136
- );
137
- const total = useMemo(
138
- () => (data && data.meta && data.meta.count) || 0,
139
- [data]
140
- );
141
- const limitOptions = useMemo(() => DEFAULT_LIMIT_OPTIONS, []);
142
- const page = useMemo(() => {
143
- const offset = parseInt(pageParams.offset) || 0;
144
- const _limit = parseInt(`${pageParams.limit}`) || parseInt(`${limit}`);
145
- return offset / _limit;
146
- }, [pageParams]);
147
- // set params to specific page
148
- const setPage = useCallback(
149
- (page) => {
150
- if (page > totalPages) {
151
- page = totalPages;
152
- }
153
- if (page <= 0) {
154
- page = 0;
155
- }
156
- const _limit = limit || DEFAULT_PAGINATION_LIMIT;
157
- const offset = _limit * page;
158
- setPageParams({ offset, limit });
159
- },
160
- [setPageParams]
161
- );
162
- const hasNext = page < totalPages - 1;
163
- const hasPrevious = page > 0;
164
- return {
165
- data: resp,
166
- meta,
167
- page,
168
- limit,
169
- totalPages,
170
- total,
171
- limitOptions,
172
- setPage,
173
- setLimit,
174
- hasNext,
175
- hasPrevious,
176
- ...rest,
177
- };
178
- }
package/src/api/utils.tsx DELETED
@@ -1,162 +0,0 @@
1
- import { ArrayQueryKey } from 'react-query/types';
2
- import { APIError } from '@digigov/ui/api/APIErrors';
3
-
4
- export interface ProcessedResponse {
5
- data?: any;
6
- status: number;
7
- error?: any;
8
- }
9
-
10
- export async function parseErrors(response: Response): Promise<string[]> {
11
- const errors: string[] = [];
12
- const error = {
13
- message: response.statusText,
14
- code: response.status,
15
- meta: {},
16
- };
17
- // do our best to resolve as more specific details for the error
18
- try {
19
- const json: Record<string, string> = await response.json();
20
- error.meta = json;
21
- // this is the way synnefo reports errors
22
- try {
23
- const apiErrors = Object.keys(json);
24
- apiErrors.forEach((key) => json[key] && errors.push(json[key]));
25
- } catch (err) {
26
- console.error('Cannot parse json error', json);
27
- }
28
- } catch (err) {
29
- try {
30
- const text = await response.text();
31
- error.message = text;
32
- // error.meta.statusText = response.statusText; // keep reference to statusText
33
- // eslint-disable-next-line no-empty
34
- } catch (err) {}
35
- }
36
- return errors;
37
- }
38
-
39
- export async function processResponse(
40
- response,
41
- raiseError = false
42
- ): Promise<ProcessedResponse> {
43
- const status = response.status;
44
- try {
45
- if (!response.ok) {
46
- const errors = await parseErrors(response);
47
- if (raiseError) {
48
- throw new APIError(errors, status);
49
- }
50
- return {
51
- error: errors[0],
52
- status,
53
- };
54
- }
55
- const contentType = response.headers.get('content-type');
56
- if (contentType && contentType.indexOf('application/json') !== -1) {
57
- const data = await response.json();
58
- return {
59
- data,
60
- status,
61
- };
62
- } else {
63
- const data = await response.text();
64
- return {
65
- data,
66
- status,
67
- };
68
- }
69
- } catch (error) {
70
- if (raiseError) {
71
- throw new APIError([error], status);
72
- }
73
- return {
74
- status,
75
- error,
76
- };
77
- }
78
- }
79
-
80
- export function getArgs(
81
- resource: any,
82
- id: any,
83
- query: any,
84
- data: any,
85
- options,
86
- method,
87
- baseURL,
88
- token
89
- ) {
90
- let body, params;
91
- if (typeof query === 'function') {
92
- params = new URLSearchParams(query()).toString();
93
- } else if (query) {
94
- params = new URLSearchParams(query).toString();
95
- }
96
- if (typeof data === 'function') {
97
- body = JSON.stringify(data());
98
- } else if (data) {
99
- body = JSON.stringify(data);
100
- }
101
- if (typeof id === 'function') {
102
- id = id();
103
- }
104
- if (!options) {
105
- options = {};
106
- }
107
- const url = `${baseURL}/${resource}${id ? `/${id}/` : ''}${
108
- params ? `?${params}` : ''
109
- }`;
110
- const _options = {
111
- headers: {
112
- 'content-type': 'application/json',
113
- },
114
- body,
115
- method,
116
- ...options,
117
- };
118
- if (token) {
119
- _options.headers.Authorization = `Token ${token}`;
120
- }
121
- return [url, _options];
122
- }
123
-
124
- export function getQueryKey(
125
- resource: string,
126
- id: string | number | null | undefined | ((...args: any) => void),
127
- query: Record<string, any> | null | undefined | ((...args: any) => void),
128
- data: Record<string, any> | null | undefined | ((...args: any) => void),
129
- options: RequestInit | null | undefined,
130
- method: string | null | undefined,
131
- baseURL: string,
132
- token: string | null | undefined
133
- ): ArrayQueryKey | ((...args: any) => ArrayQueryKey) {
134
- let queryKey;
135
-
136
- if ([id, query, data].some((param) => typeof param === 'function')) {
137
- queryKey = () => {
138
- return getArgs(
139
- resource,
140
- id,
141
- query,
142
- data,
143
- options,
144
- method,
145
- baseURL,
146
- token
147
- );
148
- };
149
- } else {
150
- queryKey = getArgs(
151
- resource,
152
- id,
153
- query,
154
- data,
155
- options,
156
- method,
157
- baseURL,
158
- token
159
- );
160
- }
161
- return queryKey;
162
- }
@@ -1,49 +0,0 @@
1
- ---
2
- id: header
3
- title: Header
4
- ---
5
-
6
- ## How to use
7
-
8
- ### Default header
9
-
10
- <Story
11
- title="### Default"
12
- packageName="@digigov/ui"
13
- component="app/Header"
14
- story="Default.tsx"
15
- />
16
-
17
- ### Header with service name
18
-
19
- <Story
20
- packageName="@digigov/ui"
21
- component="app/Header"
22
- story="WithServiceName.tsx"
23
- />
24
-
25
- ### Header with service logo and service name
26
-
27
- <Story
28
- packageName="@digigov/ui"
29
- component="app/Header"
30
- story="WithServiceNameAndLogo.tsx"
31
- />
32
-
33
- ### Default header with navigation
34
-
35
- <Story
36
- packageName="@digigov/ui"
37
- component="app/Header"
38
- story="WithNavigation.tsx"
39
- />
40
-
41
- ## API
42
-
43
- See below for a complete reference to all of the props available to the components mentioned here.
44
-
45
- <ComponentProps componentName={[
46
- "Header",
47
- "HeaderContent",
48
- "HeaderSection",]}
49
- />
@@ -1,103 +0,0 @@
1
- ---
2
- id: card
3
- title: Card
4
- ---
5
-
6
- # Card
7
-
8
- Cards can be used to divide and organise interface content for better understandability and readability.
9
- When used correctly, Cards can help users to scan through vast amounts of information quicker.
10
-
11
- ## How to use
12
-
13
- <Story packageName="@digigov/ui" component="content/Card" story="Default.tsx" />
14
-
15
- ### Card with border
16
-
17
- You can set the color of the Card's border. You can choose between `dark` and `grey` color respectively.
18
-
19
- #### Card with gray border color
20
-
21
- <Story
22
- packageName="@digigov/ui"
23
- component="content/Card"
24
- story="WithGrayBorder.tsx"
25
- />
26
-
27
- #### Card with dark border color
28
-
29
- <Story
30
- packageName="@digigov/ui"
31
- component="content/Card"
32
- story="WithDarkBorder.tsx"
33
- />
34
-
35
- ### Card with top border
36
-
37
- You can set the color of the Card's top border. You can choose between dark and grey color respectively. By default the top border color is grey
38
-
39
- #### Card with grey top border
40
-
41
- <Story
42
- packageName="@digigov/ui"
43
- component="content/Card"
44
- story="WithGrayTopBorder.tsx"
45
- />
46
-
47
- #### Card with dark top border
48
-
49
- <Story
50
- packageName="@digigov/ui"
51
- component="content/Card"
52
- story="WithDarkTopBorder.tsx"
53
- />
54
-
55
- ### Card with divider
56
-
57
- <Story
58
- packageName="@digigov/ui"
59
- component="content/Card"
60
- story="WithDivider.tsx"
61
- />
62
-
63
- ### Card with actions
64
-
65
- #### Card with title link
66
-
67
- Cards can be used without an action button, but with a clickable title.
68
-
69
- <Story
70
- packageName="@digigov/ui"
71
- component="content/Card"
72
- story="WithClickableLink.tsx"
73
- />
74
-
75
- #### Card with clickable content
76
-
77
- You can expand the clickable area of the link to fill Card's content.
78
-
79
- <Story
80
- packageName="@digigov/ui"
81
- component="content/Card"
82
- story="WithClickableContent.tsx"
83
- />
84
-
85
- Cards also provides styles for actionable elements such as Buttons or Links.
86
-
87
- #### Card with button or link
88
-
89
- <Story packageName="@digigov/ui" component="content/Card" story="Default.tsx" />
90
-
91
- #### Card with a group of actions
92
-
93
- <Story
94
- packageName="@digigov/ui"
95
- component="content/Card"
96
- story="WithGroupButton.tsx"
97
- />
98
-
99
- ## API
100
-
101
- See below for a complete reference to all of the props available to the components mentioned here.
102
-
103
- <ComponentProps componentName={["Card", "CardHeading", "CardContent", "CardAction"]} />
@@ -1,53 +0,0 @@
1
- ---
2
- id: chip
3
- title: Chip
4
- ---
5
-
6
- # Chip
7
-
8
- Chips allow users to enter information, make selections, filter content, or trigger actions.
9
- While buttons are expected to appear consistently and with familiar calls to action,
10
- chips should appear dynamically as a group of multiple interactive elements.
11
-
12
- ## How to use
13
-
14
- <Story packageName="@digigov/ui" component="content/Chip" story="Default.tsx" />
15
-
16
- ### Clickable Chip
17
-
18
- <Story
19
- packageName="@digigov/ui"
20
- component="content/Chip"
21
- story="ClickableChip.tsx"
22
- />
23
-
24
- ### Chip with close icon
25
-
26
- <Story
27
- packageName="@digigov/ui"
28
- component="content/Chip"
29
- story="DeletableChip.tsx"
30
- />
31
-
32
- ### Clickable Chip with close icon
33
-
34
- <Story
35
- packageName="@digigov/ui"
36
- component="content/Chip"
37
- story="ClickableDeletableChip.tsx"
38
- />
39
-
40
- ### Group of Chips
41
-
42
- <Story
43
- packageName="@digigov/ui"
44
- component="content/Chip"
45
- story="GroupOfChips.tsx"
46
- />
47
-
48
- ## API
49
-
50
- See below for a complete reference to all of the props available to the components mentioned here.
51
-
52
- <ComponentProps componentName={["Chip"]} />
53
-
@@ -1,40 +0,0 @@
1
- ---
2
- id: list
3
- title: List
4
- ---
5
-
6
- ## How to use
7
-
8
- ### Default
9
-
10
- <Story packageName="@digigov/ui" component="content/List" story="Default.tsx" />
11
-
12
- ### List with bullets
13
-
14
- <Story
15
- packageName="@digigov/ui"
16
- component="content/List"
17
- story="BulletList.tsx"
18
- />
19
-
20
- ### List with numbers
21
-
22
- <Story
23
- packageName="@digigov/ui"
24
- component="content/List"
25
- story="NumberedList.tsx"
26
- />
27
-
28
- ### List with extra space
29
-
30
- <Story
31
- packageName="@digigov/ui"
32
- component="content/List"
33
- story="WithExtraSpace.tsx"
34
- />
35
-
36
- ## API
37
-
38
- See below for a complete reference to all of the props available to the components mentioned here.
39
-
40
- <ComponentProps componentName={["List", "ListItem"]} />
@@ -1,111 +0,0 @@
1
- ---
2
- id: table
3
- title: Table
4
- ---
5
-
6
- # Table
7
-
8
- ## How to use
9
-
10
- <Story
11
- packageName="@digigov/ui"
12
- component="content/Table"
13
- story="Default.tsx"
14
- />
15
-
16
- ### Table with dark header
17
-
18
- <Story
19
- packageName="@digigov/ui"
20
- component="content/Table"
21
- story="DarkVariant.tsx"
22
- />
23
-
24
- ### Table captions
25
-
26
- Use the `<TableCaption>` element to describe a table in the same way you would use a heading. A caption helps users find, navigate and understand tables.
27
-
28
- <Story
29
- packageName="@digigov/ui"
30
- component="content/Table"
31
- story="TableCaptions.tsx"
32
- />
33
-
34
- ### Numbers in a table
35
-
36
- <Story
37
- packageName="@digigov/ui"
38
- component="content/Table"
39
- story="NumericDataType.tsx"
40
- />
41
-
42
- ### Zebra rows
43
-
44
- <Story
45
- packageName="@digigov/ui"
46
- component="content/Table"
47
- story="ZebraProp.tsx"
48
- />
49
-
50
- ### Rows with primary or secondary color
51
-
52
- The prop `color='primary'` or `color='secondary'` is only functional when Table component has `variant='default'`.
53
-
54
- <Story
55
- packageName="@digigov/ui"
56
- component="content/Table"
57
- story="RowColors.tsx"
58
- />
59
-
60
- ### Vertical lines
61
-
62
- <Story
63
- packageName="@digigov/ui"
64
- component="content/Table"
65
- story="VerticalBorders.tsx"
66
- />
67
-
68
- ### Dense tables
69
-
70
- <Story packageName="@digigov/ui" component="content/Table" story="Densed.tsx" />
71
-
72
- ### Custom column widths
73
-
74
- <Story
75
- packageName="@digigov/ui"
76
- component="content/Table"
77
- story="DefinedWidth.tsx"
78
- />
79
-
80
- ### No data
81
-
82
- <Story packageName="@digigov/ui" component="content/Table" story="NoData.tsx" />
83
-
84
- ### Using loader
85
-
86
- <Story
87
- packageName="@digigov/ui"
88
- component="content/Table"
89
- story="WithLoader.tsx"
90
- />
91
-
92
- ## Accessibility
93
-
94
- You can read more about the accessibility patterns used in our Table
95
- implementation in the ARIA Authoring Practices Guide (APG) at [Table](https://www.w3.org/WAI/ARIA/apg/patterns/table/) section.
96
-
97
- ## API
98
-
99
- See below for a complete reference to all of the props available to the components mentioned here.
100
-
101
- <ComponentProps componentName={[
102
- "TableContainer",
103
- "Table",
104
- "TableCaption",
105
- "TableHead",
106
- "TableRow",
107
- "TableBody",
108
- "TableHeadCell",
109
- "TableDataCell"
110
- ]
111
- } />