@digigov/ui 0.11.0 → 0.12.2
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/.eslintrc.js +4 -0
- package/.prettierrc.js +3 -0
- package/.rush/temp/package-deps_build.json +176 -0
- package/.rush/temp/shrinkwrap-deps.json +278 -0
- package/CHANGELOG.json +796 -0
- package/CHANGELOG.md +22 -1
- package/docs/components.mdx +1 -0
- package/docs/create-a-new-service.mdx +93 -0
- package/docs/create-common-page-layout.mdx +205 -0
- package/docs/create-static-page.mdx +179 -0
- package/docs/edit-start-page.mdx +143 -0
- package/docs/index.mdx +66 -0
- package/docs/introduction.mdx +34 -0
- package/package.json +31 -8
- package/src/api/APIErrors.tsx +44 -0
- package/src/api/APIProvider.tsx +27 -0
- package/src/api/fetchAPI.ts +45 -0
- package/src/api/index.spec.tsx +419 -0
- package/{esm/api/index.js → src/api/index.tsx} +6 -3
- package/{api → src/api}/introduction.md +0 -0
- package/src/api/useResource.tsx +96 -0
- package/src/api/useResourceAction.tsx +80 -0
- package/src/api/useResourceQuery.tsx +177 -0
- package/src/api/utils.tsx +156 -0
- package/src/app/App.tsx +33 -0
- package/{app/Confirmation/index.d.ts → src/app/Confirmation/index.tsx} +0 -0
- package/{app/Footer/index.d.ts → src/app/Footer/index.tsx} +0 -0
- package/{es/app/Header/HeaderLogo.js → src/app/Header/HeaderLogo.tsx} +9 -7
- package/src/app/Header/HeaderSection.tsx +13 -0
- package/src/app/Header/HeaderTitle.tsx +24 -0
- package/{app → src/app}/Header/__snapshots__/index.spec.tsx.snap +0 -0
- package/{app → src/app}/Header/index.mdx +0 -0
- package/src/app/Header/index.spec.tsx +32 -0
- package/{esm/app/Header/index.js → src/app/Header/index.tsx} +10 -4
- package/src/app/NotFound/index.tsx +21 -0
- package/src/app/OutdatedBrowserBanner.tsx +37 -0
- package/src/app/PageTitle.tsx +70 -0
- package/{app → src/app}/QrCodeScanner/__snapshots__/index.spec.tsx.snap +0 -0
- package/{app → src/app}/QrCodeScanner/index.mdx +0 -0
- package/src/app/QrCodeScanner/index.spec.tsx +19 -0
- package/src/app/QrCodeScanner/index.tsx +90 -0
- package/src/app/i18n.tsx +44 -0
- package/{app/index.d.ts → src/app/index.ts} +0 -0
- package/{core → src/core}/Accordion/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/Accordion/index.mdx +0 -0
- package/src/core/Accordion/index.spec.tsx +30 -0
- package/src/core/Accordion/index.tsx +86 -0
- package/{core → src/core}/Blockquote/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/Blockquote/index.mdx +0 -0
- package/src/core/Blockquote/index.spec.tsx +10 -0
- package/{esm/core/Blockquote/index.js → src/core/Blockquote/index.tsx} +9 -7
- package/{core/Breadcrumbs/index.d.ts → src/core/Breadcrumbs/index.tsx} +0 -0
- package/{esm/core/Button/BackButton.js → src/core/Button/BackButton.tsx} +10 -8
- package/src/core/Button/ButtonLink.tsx +20 -0
- package/src/core/Button/CallToAction.tsx +31 -0
- package/src/core/Button/Icon.tsx +9 -0
- package/{core → src/core}/Button/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/Button/index.mdx +0 -0
- package/src/core/Button/index.spec.tsx +8 -0
- package/src/core/Button/index.tsx +46 -0
- package/{core/Card/index.d.ts → src/core/Card/index.tsx} +0 -0
- package/{core → src/core}/Details/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/Details/index.mdx +0 -0
- package/src/core/Details/index.spec.tsx +38 -0
- package/{core/Details/index.d.ts → src/core/Details/index.tsx} +2 -0
- package/src/core/Divider/index.tsx +13 -0
- package/{core → src/core}/ErrorSummary/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/ErrorSummary/index.mdx +0 -0
- package/src/core/ErrorSummary/index.spec.tsx +10 -0
- package/{core/ErrorSummary/index.d.ts → src/core/ErrorSummary/index.tsx} +1 -0
- package/{core/Hidden/index.d.ts → src/core/Hidden/index.tsx} +0 -0
- package/{core → src/core}/Link/__snapshots__/index.spec.tsx.snap +0 -0
- package/src/core/Link/index.spec.tsx +22 -0
- package/src/core/Link/index.tsx +41 -0
- package/{core/List/List.d.ts → src/core/List/List.tsx} +2 -0
- package/{core/List/ListItem.d.ts → src/core/List/ListItem.tsx} +2 -0
- package/src/core/List/ListItemContent.tsx +32 -0
- package/src/core/List/ListItemIcon.tsx +31 -0
- package/src/core/List/ListItemText.tsx +23 -0
- package/src/core/List/ListItemTitle.tsx +37 -0
- package/{core → src/core}/List/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/List/index.mdx +0 -0
- package/src/core/List/index.spec.tsx +10 -0
- package/{core/List/index.d.ts → src/core/List/index.tsx} +0 -0
- package/src/core/NavList/NavList.tsx +103 -0
- package/src/core/NavList/NavListContext.tsx +85 -0
- package/src/core/NavList/NavListItem.tsx +143 -0
- package/src/core/NavList/NavListItemBase.tsx +146 -0
- package/src/core/NavList/NavListSubMenu.tsx +33 -0
- package/{core → src/core}/NavList/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/NavList/index.mdx +0 -0
- package/src/core/NavList/index.spec.tsx +10 -0
- package/{core/NavList/index.d.ts → src/core/NavList/index.tsx} +0 -0
- package/{core → src/core}/NotificationBanner/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/NotificationBanner/index.mdx +0 -0
- package/src/core/NotificationBanner/index.spec.tsx +27 -0
- package/src/core/NotificationBanner/index.tsx +52 -0
- package/{core → src/core}/ServiceBadge/ServiceBadge.mdx +0 -0
- package/{core → src/core}/ServiceBadge/index.mdx +0 -0
- package/src/core/ServiceBadge/index.tsx +35 -0
- package/{core → src/core}/SummaryList/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/SummaryList/index.mdx +0 -0
- package/src/core/SummaryList/index.spec.tsx +28 -0
- package/{core/SummaryList/index.d.ts → src/core/SummaryList/index.tsx} +2 -0
- package/{core/Table/index.d.ts → src/core/Table/index.tsx} +0 -0
- package/{core → src/core}/Tabs/index.mdx +0 -0
- package/src/core/Tabs/index.tsx +36 -0
- package/{core/VisuallyHidden/index.d.ts → src/core/VisuallyHidden/index.tsx} +0 -0
- package/{core → src/core}/WarningText/__snapshots__/index.spec.tsx.snap +0 -0
- package/{core → src/core}/WarningText/index.mdx +0 -0
- package/src/core/WarningText/index.spec.tsx +10 -0
- package/{core/WarningText/index.d.ts → src/core/WarningText/index.tsx} +1 -0
- package/{core/index.d.ts → src/core/index.ts} +3 -0
- package/src/custom.d.ts +8 -0
- package/{es → src}/form/inputs/Input/index.mdx +0 -0
- package/src/govgr/Footer/Copyright.tsx +64 -0
- package/{govgr/Footer/HellenicRepublicLogo.d.ts → src/govgr/Footer/HellenicRepublicLogo.tsx} +1 -0
- package/src/govgr/Footer/LicenseCCSA.tsx +24 -0
- package/{es → src}/govgr/Footer/index.mdx +0 -0
- package/src/govgr/Footer/index.tsx +49 -0
- package/{esm/govgr/Footer/logo.js → src/govgr/Footer/logo.ts} +1 -1
- package/{esm/govgr/Footer/logos/logo-el.js → src/govgr/Footer/logos/logo-el.ts} +1 -1
- package/{esm/govgr/Footer/logos/logo-en.js → src/govgr/Footer/logos/logo-en.ts} +1 -1
- package/{es → src}/govgr/Logo/govgr-logo.svg +0 -0
- package/{govgr/Logo/index.d.ts → src/govgr/Logo/index.tsx} +2 -0
- package/{es/govgr/Logo/logo.js → src/govgr/Logo/logo.ts} +1 -1
- package/{govgr/index.d.ts → src/govgr/index.ts} +0 -0
- package/src/hooks/useDebounce.ts +50 -0
- package/src/hooks/useLatest.ts +12 -0
- package/{esm/hooks/useOutdatedBrowserCheck.js → src/hooks/useOutdatedBrowserCheck.ts} +16 -15
- package/src/hooks/useSearch.ts +47 -0
- package/src/hooks/useTogglableSections.tsx +102 -0
- package/{index.d.ts → src/index.ts} +0 -0
- package/{es → src}/layouts/Basic/Bottom/index.mdx +0 -0
- package/{layouts/Basic/Bottom/index.d.ts → src/layouts/Basic/Bottom/index.tsx} +1 -0
- package/{es → src}/layouts/Basic/Content/index.mdx +0 -0
- package/src/layouts/Basic/Content/index.tsx +24 -0
- package/{es → src}/layouts/Basic/Main/index.mdx +0 -0
- package/{layouts/Basic/Main/index.d.ts → src/layouts/Basic/Main/index.tsx} +1 -0
- package/{es → src}/layouts/Basic/Masthead/index.mdx +0 -0
- package/{layouts/Basic/Masthead/index.d.ts → src/layouts/Basic/Masthead/index.tsx} +2 -0
- package/{es → src}/layouts/Basic/Side/index.mdx +0 -0
- package/{esm/layouts/Basic/Side/index.js → src/layouts/Basic/Side/index.tsx} +5 -3
- package/{es → src}/layouts/Basic/Top/index.mdx +0 -0
- package/{es/layouts/Basic/Top/index.js → src/layouts/Basic/Top/index.tsx} +7 -5
- package/{es → src}/layouts/Basic/__snapshots__/index.spec.tsx.snap +0 -0
- package/{es → src}/layouts/Basic/index.mdx +0 -0
- package/src/layouts/Basic/index.spec.tsx +24 -0
- package/{layouts/Basic/index.d.ts → src/layouts/Basic/index.tsx} +2 -0
- package/{layouts/Grid/index.d.ts → src/layouts/Grid/index.tsx} +0 -0
- package/{layouts/index.d.ts → src/layouts/index.ts} +0 -0
- package/src/locales/el.ts +60 -0
- package/{esm/locales/en.js → src/locales/en.ts} +25 -11
- package/{es → src}/router/index.mdx +0 -0
- package/src/router/index.tsx +28 -0
- package/src/test-utils/delay.ts +9 -0
- package/src/test-utils/mountWithTheme.tsx +33 -0
- package/{es → src}/themes/govgr.js +33 -29
- package/src/themes/grnet.js +109 -0
- package/src/themes/index.tsx +38 -0
- package/src/typography/Caption.tsx +15 -0
- package/src/typography/NormalText.tsx +7 -0
- package/src/typography/Paragraph.tsx +9 -0
- package/src/typography/Title.tsx +51 -0
- package/{es → src}/typography/index.mdx +0 -0
- package/{typography/index.d.ts → src/typography/index.ts} +0 -0
- package/src/utils/evaluateBrowserVersion.ts +346 -0
- package/src/utils/withDeprecation.tsx +97 -0
- package/tsconfig.json +18 -0
- package/tsconfig.production.json +27 -0
- package/ui.build.log +17 -0
- package/LICENSE +0 -0
- package/api/APIErrors.d.ts +0 -22
- package/api/APIErrors.js +0 -117
- package/api/APIProvider.d.ts +0 -15
- package/api/APIProvider.js +0 -43
- package/api/fetchAPI.d.ts +0 -18
- package/api/fetchAPI.js +0 -64
- package/api/index.d.ts +0 -9
- package/api/index.js +0 -104
- package/api/index.spec.d.ts +0 -1
- package/api/index.spec.js +0 -584
- package/api/useResource.d.ts +0 -11
- package/api/useResource.js +0 -144
- package/api/useResourceAction.d.ts +0 -2
- package/api/useResourceAction.js +0 -157
- package/api/useResourceQuery.d.ts +0 -18
- package/api/useResourceQuery.js +0 -229
- package/api/utils.d.ts +0 -6
- package/api/utils.js +0 -250
- package/app/App.d.ts +0 -14
- package/app/App.js +0 -49
- package/app/Confirmation/index.js +0 -44
- package/app/Footer/index.js +0 -200
- package/app/Header/HeaderLogo.d.ts +0 -3
- package/app/Header/HeaderLogo.js +0 -30
- package/app/Header/HeaderSection.d.ts +0 -5
- package/app/Header/HeaderSection.js +0 -20
- package/app/Header/HeaderTitle.d.ts +0 -5
- package/app/Header/HeaderTitle.js +0 -30
- package/app/Header/index.d.ts +0 -11
- package/app/Header/index.js +0 -106
- package/app/Header/index.spec.d.ts +0 -1
- package/app/Header/index.spec.js +0 -45
- package/app/NotFound/index.d.ts +0 -3
- package/app/NotFound/index.js +0 -29
- package/app/OutdatedBrowserBanner.d.ts +0 -2
- package/app/OutdatedBrowserBanner.js +0 -41
- package/app/PageTitle.d.ts +0 -10
- package/app/PageTitle.js +0 -76
- package/app/QrCodeScanner/index.d.ts +0 -29
- package/app/QrCodeScanner/index.js +0 -85
- package/app/QrCodeScanner/index.spec.d.ts +0 -1
- package/app/QrCodeScanner/index.spec.js +0 -26
- package/app/i18n.d.ts +0 -10
- package/app/i18n.js +0 -57
- package/app/index.js +0 -70
- package/core/Accordion/index.d.ts +0 -21
- package/core/Accordion/index.js +0 -127
- package/core/Accordion/index.spec.d.ts +0 -1
- package/core/Accordion/index.spec.js +0 -19
- package/core/Blockquote/index.d.ts +0 -3
- package/core/Blockquote/index.js +0 -29
- package/core/Blockquote/index.spec.d.ts +0 -1
- package/core/Blockquote/index.spec.js +0 -21
- package/core/Breadcrumbs/index.js +0 -44
- package/core/Button/BackButton.d.ts +0 -3
- package/core/Button/BackButton.js +0 -34
- package/core/Button/ButtonLink.d.ts +0 -4
- package/core/Button/ButtonLink.js +0 -28
- package/core/Button/CallToAction.d.ts +0 -7
- package/core/Button/CallToAction.js +0 -41
- package/core/Button/Icon.d.ts +0 -2
- package/core/Button/Icon.js +0 -19
- package/core/Button/index.d.ts +0 -15
- package/core/Button/index.js +0 -121
- package/core/Button/index.spec.d.ts +0 -1
- package/core/Button/index.spec.js +0 -21
- package/core/Card/index.js +0 -57
- package/core/Details/index.js +0 -35
- package/core/Details/index.spec.d.ts +0 -1
- package/core/Details/index.spec.js +0 -27
- package/core/Divider/index.d.ts +0 -5
- package/core/Divider/index.js +0 -20
- package/core/ErrorSummary/index.js +0 -19
- package/core/ErrorSummary/index.spec.d.ts +0 -1
- package/core/ErrorSummary/index.spec.js +0 -21
- package/core/Hidden/index.js +0 -18
- package/core/Link/index.d.ts +0 -12
- package/core/Link/index.js +0 -50
- package/core/Link/index.spec.d.ts +0 -1
- package/core/Link/index.spec.js +0 -31
- package/core/List/List.js +0 -19
- package/core/List/ListItem.js +0 -19
- package/core/List/ListItemContent.d.ts +0 -7
- package/core/List/ListItemContent.js +0 -45
- package/core/List/ListItemIcon.d.ts +0 -7
- package/core/List/ListItemIcon.js +0 -48
- package/core/List/ListItemText.d.ts +0 -8
- package/core/List/ListItemText.js +0 -36
- package/core/List/ListItemTitle.d.ts +0 -10
- package/core/List/ListItemTitle.js +0 -44
- package/core/List/index.js +0 -96
- package/core/List/index.spec.d.ts +0 -1
- package/core/List/index.spec.js +0 -21
- package/core/NavList/NavList.d.ts +0 -17
- package/core/NavList/NavList.js +0 -99
- package/core/NavList/NavListContext.d.ts +0 -20
- package/core/NavList/NavListContext.js +0 -102
- package/core/NavList/NavListItem.d.ts +0 -13
- package/core/NavList/NavListItem.js +0 -171
- package/core/NavList/NavListItemBase.d.ts +0 -16
- package/core/NavList/NavListItemBase.js +0 -161
- package/core/NavList/NavListSubMenu.d.ts +0 -8
- package/core/NavList/NavListSubMenu.js +0 -52
- package/core/NavList/index.js +0 -68
- package/core/NavList/index.spec.d.ts +0 -1
- package/core/NavList/index.spec.js +0 -21
- package/core/NotificationBanner/index.d.ts +0 -18
- package/core/NotificationBanner/index.js +0 -78
- package/core/NotificationBanner/index.spec.d.ts +0 -1
- package/core/NotificationBanner/index.spec.js +0 -32
- package/core/ServiceBadge/index.d.ts +0 -9
- package/core/ServiceBadge/index.js +0 -36
- package/core/SummaryList/index.js +0 -79
- package/core/SummaryList/index.spec.d.ts +0 -1
- package/core/SummaryList/index.spec.js +0 -19
- package/core/Table/index.js +0 -96
- package/core/Tabs/index.d.ts +0 -16
- package/core/Tabs/index.js +0 -88
- package/core/VisuallyHidden/index.js +0 -18
- package/core/WarningText/index.js +0 -19
- package/core/WarningText/index.spec.d.ts +0 -1
- package/core/WarningText/index.spec.js +0 -21
- package/core/index.js +0 -199
- package/custom.d.js +0 -1
- package/es/api/APIErrors.js +0 -96
- package/es/api/APIProvider.js +0 -25
- package/es/api/fetchAPI.js +0 -49
- package/es/api/index.js +0 -13
- package/es/api/index.spec.js +0 -546
- package/es/api/introduction.md +0 -6
- package/es/api/useResource.js +0 -128
- package/es/api/useResourceAction.js +0 -141
- package/es/api/useResourceQuery.js +0 -208
- package/es/api/utils.js +0 -233
- package/es/app/App.js +0 -27
- package/es/app/Confirmation/index.js +0 -3
- package/es/app/Footer/index.js +0 -15
- package/es/app/Header/HeaderSection.js +0 -7
- package/es/app/Header/HeaderTitle.js +0 -17
- package/es/app/Header/__snapshots__/index.spec.tsx.snap +0 -393
- package/es/app/Header/index.js +0 -13
- package/es/app/Header/index.mdx +0 -50
- package/es/app/Header/index.spec.js +0 -32
- package/es/app/NotFound/index.js +0 -12
- package/es/app/OutdatedBrowserBanner.js +0 -24
- package/es/app/PageTitle.js +0 -57
- package/es/app/QrCodeScanner/__snapshots__/index.spec.tsx.snap +0 -22
- package/es/app/QrCodeScanner/index.js +0 -64
- package/es/app/QrCodeScanner/index.mdx +0 -22
- package/es/app/QrCodeScanner/index.spec.js +0 -13
- package/es/app/i18n.js +0 -36
- package/es/app/index.js +0 -5
- package/es/core/Accordion/__snapshots__/index.spec.tsx.snap +0 -78
- package/es/core/Accordion/index.js +0 -67
- package/es/core/Accordion/index.mdx +0 -104
- package/es/core/Accordion/index.spec.js +0 -9
- package/es/core/Blockquote/__snapshots__/index.spec.tsx.snap +0 -13
- package/es/core/Blockquote/index.js +0 -16
- package/es/core/Blockquote/index.mdx +0 -61
- package/es/core/Blockquote/index.spec.js +0 -9
- package/es/core/Breadcrumbs/index.js +0 -3
- package/es/core/Button/BackButton.js +0 -21
- package/es/core/Button/ButtonLink.js +0 -16
- package/es/core/Button/CallToAction.js +0 -27
- package/es/core/Button/Icon.js +0 -7
- package/es/core/Button/__snapshots__/index.spec.tsx.snap +0 -13
- package/es/core/Button/index.js +0 -36
- package/es/core/Button/index.mdx +0 -65
- package/es/core/Button/index.spec.js +0 -9
- package/es/core/Card/index.js +0 -4
- package/es/core/Details/__snapshots__/index.spec.tsx.snap +0 -50
- package/es/core/Details/index.js +0 -5
- package/es/core/Details/index.mdx +0 -34
- package/es/core/Details/index.spec.js +0 -17
- package/es/core/Divider/index.js +0 -7
- package/es/core/ErrorSummary/__snapshots__/index.spec.tsx.snap +0 -322
- package/es/core/ErrorSummary/index.js +0 -3
- package/es/core/ErrorSummary/index.mdx +0 -61
- package/es/core/ErrorSummary/index.spec.js +0 -9
- package/es/core/Hidden/index.js +0 -1
- package/es/core/Link/__snapshots__/index.spec.tsx.snap +0 -31
- package/es/core/Link/index.js +0 -26
- package/es/core/Link/index.spec.js +0 -21
- package/es/core/List/List.js +0 -3
- package/es/core/List/ListItem.js +0 -3
- package/es/core/List/ListItemContent.js +0 -27
- package/es/core/List/ListItemIcon.js +0 -29
- package/es/core/List/ListItemText.js +0 -19
- package/es/core/List/ListItemTitle.js +0 -25
- package/es/core/List/__snapshots__/index.spec.tsx.snap +0 -322
- package/es/core/List/index.js +0 -7
- package/es/core/List/index.mdx +0 -40
- package/es/core/List/index.spec.js +0 -9
- package/es/core/NavList/NavList.js +0 -78
- package/es/core/NavList/NavListContext.js +0 -80
- package/es/core/NavList/NavListItem.js +0 -141
- package/es/core/NavList/NavListItemBase.js +0 -133
- package/es/core/NavList/NavListSubMenu.js +0 -27
- package/es/core/NavList/__snapshots__/index.spec.tsx.snap +0 -334
- package/es/core/NavList/index.js +0 -5
- package/es/core/NavList/index.mdx +0 -185
- package/es/core/NavList/index.spec.js +0 -9
- package/es/core/NotificationBanner/__snapshots__/index.spec.tsx.snap +0 -737
- package/es/core/NotificationBanner/index.js +0 -35
- package/es/core/NotificationBanner/index.mdx +0 -77
- package/es/core/NotificationBanner/index.spec.js +0 -20
- package/es/core/ServiceBadge/ServiceBadge.mdx +0 -0
- package/es/core/ServiceBadge/index.js +0 -20
- package/es/core/ServiceBadge/index.mdx +0 -42
- package/es/core/SummaryList/__snapshots__/index.spec.tsx.snap +0 -57
- package/es/core/SummaryList/index.js +0 -7
- package/es/core/SummaryList/index.mdx +0 -82
- package/es/core/SummaryList/index.spec.js +0 -9
- package/es/core/Table/index.js +0 -7
- package/es/core/Tabs/index.js +0 -37
- package/es/core/Tabs/index.mdx +0 -54
- package/es/core/VisuallyHidden/index.js +0 -1
- package/es/core/WarningText/__snapshots__/index.spec.tsx.snap +0 -336
- package/es/core/WarningText/index.js +0 -3
- package/es/core/WarningText/index.mdx +0 -46
- package/es/core/WarningText/index.spec.js +0 -9
- package/es/core/index.js +0 -14
- package/es/custom.d.js +0 -0
- package/es/govgr/Footer/Copyright.js +0 -37
- package/es/govgr/Footer/HellenicRepublicLogo.js +0 -3
- package/es/govgr/Footer/LicenseCCSA.js +0 -18
- package/es/govgr/Footer/index.js +0 -21
- package/es/govgr/Footer/logo.js +0 -1
- package/es/govgr/Footer/logos/logo-el.js +0 -1
- package/es/govgr/Footer/logos/logo-en.js +0 -1
- package/es/govgr/Logo/index.js +0 -3
- package/es/govgr/index.js +0 -4
- package/es/hooks/useDebounce.js +0 -41
- package/es/hooks/useLatest.js +0 -12
- package/es/hooks/useOutdatedBrowserCheck.js +0 -46
- package/es/hooks/useSearch.js +0 -25
- package/es/hooks/useTogglableSections.js +0 -96
- package/es/index.js +0 -5
- package/es/layouts/Basic/Bottom/index.js +0 -3
- package/es/layouts/Basic/Content/index.js +0 -18
- package/es/layouts/Basic/Main/index.js +0 -3
- package/es/layouts/Basic/Masthead/index.js +0 -4
- package/es/layouts/Basic/Side/index.js +0 -7
- package/es/layouts/Basic/index.js +0 -8
- package/es/layouts/Basic/index.spec.js +0 -10
- package/es/layouts/Grid/index.js +0 -1
- package/es/layouts/index.js +0 -2
- package/es/locales/el.js +0 -45
- package/es/locales/en.js +0 -45
- package/es/router/index.js +0 -15
- package/es/test-utils/delay.js +0 -31
- package/es/test-utils/mountWithTheme.js +0 -30
- package/es/themes/grnet.js +0 -110
- package/es/themes/index.js +0 -2
- package/es/typography/Caption.js +0 -7
- package/es/typography/NormalText.js +0 -3
- package/es/typography/Paragraph.js +0 -2
- package/es/typography/Title.js +0 -48
- package/es/typography/index.js +0 -8
- package/es/utils/evaluateBrowserVersion.js +0 -201
- package/es/utils/withDeprecation.js +0 -103
- package/esm/api/APIErrors.js +0 -96
- package/esm/api/APIProvider.js +0 -25
- package/esm/api/fetchAPI.js +0 -49
- package/esm/api/index.spec.js +0 -546
- package/esm/api/introduction.md +0 -6
- package/esm/api/useResource.js +0 -128
- package/esm/api/useResourceAction.js +0 -141
- package/esm/api/useResourceQuery.js +0 -208
- package/esm/api/utils.js +0 -233
- package/esm/app/App.js +0 -27
- package/esm/app/Confirmation/index.js +0 -3
- package/esm/app/Footer/index.js +0 -15
- package/esm/app/Header/HeaderLogo.js +0 -17
- package/esm/app/Header/HeaderSection.js +0 -7
- package/esm/app/Header/HeaderTitle.js +0 -17
- package/esm/app/Header/__snapshots__/index.spec.tsx.snap +0 -393
- package/esm/app/Header/index.mdx +0 -50
- package/esm/app/Header/index.spec.js +0 -32
- package/esm/app/NotFound/index.js +0 -12
- package/esm/app/OutdatedBrowserBanner.js +0 -24
- package/esm/app/PageTitle.js +0 -57
- package/esm/app/QrCodeScanner/__snapshots__/index.spec.tsx.snap +0 -22
- package/esm/app/QrCodeScanner/index.js +0 -64
- package/esm/app/QrCodeScanner/index.mdx +0 -22
- package/esm/app/QrCodeScanner/index.spec.js +0 -13
- package/esm/app/i18n.js +0 -36
- package/esm/app/index.js +0 -5
- package/esm/core/Accordion/__snapshots__/index.spec.tsx.snap +0 -78
- package/esm/core/Accordion/index.js +0 -67
- package/esm/core/Accordion/index.mdx +0 -104
- package/esm/core/Accordion/index.spec.js +0 -9
- package/esm/core/Blockquote/__snapshots__/index.spec.tsx.snap +0 -13
- package/esm/core/Blockquote/index.mdx +0 -61
- package/esm/core/Blockquote/index.spec.js +0 -9
- package/esm/core/Breadcrumbs/index.js +0 -3
- package/esm/core/Button/ButtonLink.js +0 -16
- package/esm/core/Button/CallToAction.js +0 -27
- package/esm/core/Button/Icon.js +0 -7
- package/esm/core/Button/__snapshots__/index.spec.tsx.snap +0 -13
- package/esm/core/Button/index.js +0 -36
- package/esm/core/Button/index.mdx +0 -65
- package/esm/core/Button/index.spec.js +0 -9
- package/esm/core/Card/index.js +0 -4
- package/esm/core/Details/__snapshots__/index.spec.tsx.snap +0 -50
- package/esm/core/Details/index.js +0 -5
- package/esm/core/Details/index.mdx +0 -34
- package/esm/core/Details/index.spec.js +0 -17
- package/esm/core/Divider/index.js +0 -7
- package/esm/core/ErrorSummary/__snapshots__/index.spec.tsx.snap +0 -322
- package/esm/core/ErrorSummary/index.js +0 -3
- package/esm/core/ErrorSummary/index.mdx +0 -61
- package/esm/core/ErrorSummary/index.spec.js +0 -9
- package/esm/core/Hidden/index.js +0 -1
- package/esm/core/Link/__snapshots__/index.spec.tsx.snap +0 -31
- package/esm/core/Link/index.js +0 -26
- package/esm/core/Link/index.spec.js +0 -21
- package/esm/core/List/List.js +0 -3
- package/esm/core/List/ListItem.js +0 -3
- package/esm/core/List/ListItemContent.js +0 -27
- package/esm/core/List/ListItemIcon.js +0 -29
- package/esm/core/List/ListItemText.js +0 -19
- package/esm/core/List/ListItemTitle.js +0 -25
- package/esm/core/List/__snapshots__/index.spec.tsx.snap +0 -322
- package/esm/core/List/index.js +0 -7
- package/esm/core/List/index.mdx +0 -40
- package/esm/core/List/index.spec.js +0 -9
- package/esm/core/NavList/NavList.js +0 -78
- package/esm/core/NavList/NavListContext.js +0 -80
- package/esm/core/NavList/NavListItem.js +0 -141
- package/esm/core/NavList/NavListItemBase.js +0 -133
- package/esm/core/NavList/NavListSubMenu.js +0 -27
- package/esm/core/NavList/__snapshots__/index.spec.tsx.snap +0 -334
- package/esm/core/NavList/index.js +0 -5
- package/esm/core/NavList/index.mdx +0 -185
- package/esm/core/NavList/index.spec.js +0 -9
- package/esm/core/NotificationBanner/__snapshots__/index.spec.tsx.snap +0 -737
- package/esm/core/NotificationBanner/index.js +0 -35
- package/esm/core/NotificationBanner/index.mdx +0 -77
- package/esm/core/NotificationBanner/index.spec.js +0 -20
- package/esm/core/ServiceBadge/ServiceBadge.mdx +0 -0
- package/esm/core/ServiceBadge/index.js +0 -20
- package/esm/core/ServiceBadge/index.mdx +0 -42
- package/esm/core/SummaryList/__snapshots__/index.spec.tsx.snap +0 -57
- package/esm/core/SummaryList/index.js +0 -7
- package/esm/core/SummaryList/index.mdx +0 -82
- package/esm/core/SummaryList/index.spec.js +0 -9
- package/esm/core/Table/index.js +0 -7
- package/esm/core/Tabs/index.js +0 -37
- package/esm/core/Tabs/index.mdx +0 -54
- package/esm/core/VisuallyHidden/index.js +0 -1
- package/esm/core/WarningText/__snapshots__/index.spec.tsx.snap +0 -336
- package/esm/core/WarningText/index.js +0 -3
- package/esm/core/WarningText/index.mdx +0 -46
- package/esm/core/WarningText/index.spec.js +0 -9
- package/esm/core/index.js +0 -14
- package/esm/custom.d.js +0 -0
- package/esm/form/inputs/Input/index.mdx +0 -10
- package/esm/govgr/Footer/Copyright.js +0 -37
- package/esm/govgr/Footer/HellenicRepublicLogo.js +0 -3
- package/esm/govgr/Footer/LicenseCCSA.js +0 -18
- package/esm/govgr/Footer/index.js +0 -21
- package/esm/govgr/Footer/index.mdx +0 -97
- package/esm/govgr/Logo/govgr-logo.svg +0 -1
- package/esm/govgr/Logo/index.js +0 -3
- package/esm/govgr/Logo/logo.js +0 -1
- package/esm/govgr/index.js +0 -4
- package/esm/hooks/useDebounce.js +0 -41
- package/esm/hooks/useLatest.js +0 -12
- package/esm/hooks/useSearch.js +0 -25
- package/esm/hooks/useTogglableSections.js +0 -96
- package/esm/index.js +0 -10
- package/esm/layouts/Basic/Bottom/index.js +0 -3
- package/esm/layouts/Basic/Bottom/index.mdx +0 -37
- package/esm/layouts/Basic/Content/index.js +0 -18
- package/esm/layouts/Basic/Content/index.mdx +0 -64
- package/esm/layouts/Basic/Main/index.js +0 -3
- package/esm/layouts/Basic/Main/index.mdx +0 -64
- package/esm/layouts/Basic/Masthead/index.js +0 -4
- package/esm/layouts/Basic/Masthead/index.mdx +0 -74
- package/esm/layouts/Basic/Side/index.mdx +0 -71
- package/esm/layouts/Basic/Top/index.js +0 -11
- package/esm/layouts/Basic/Top/index.mdx +0 -74
- package/esm/layouts/Basic/__snapshots__/index.spec.tsx.snap +0 -54
- package/esm/layouts/Basic/index.js +0 -8
- package/esm/layouts/Basic/index.mdx +0 -62
- package/esm/layouts/Basic/index.spec.js +0 -10
- package/esm/layouts/Grid/index.js +0 -1
- package/esm/layouts/index.js +0 -2
- package/esm/locales/el.js +0 -45
- package/esm/router/index.js +0 -15
- package/esm/router/index.mdx +0 -40
- package/esm/test-utils/delay.js +0 -31
- package/esm/test-utils/mountWithTheme.js +0 -30
- package/esm/themes/govgr.js +0 -79
- package/esm/themes/grnet.js +0 -110
- package/esm/themes/index.js +0 -2
- package/esm/typography/Caption.js +0 -7
- package/esm/typography/NormalText.js +0 -3
- package/esm/typography/Paragraph.js +0 -2
- package/esm/typography/Title.js +0 -48
- package/esm/typography/index.js +0 -8
- package/esm/typography/index.mdx +0 -32
- package/esm/utils/evaluateBrowserVersion.js +0 -201
- package/esm/utils/withDeprecation.js +0 -103
- package/form/inputs/Input/index.mdx +0 -10
- package/govgr/Footer/Copyright.d.ts +0 -8
- package/govgr/Footer/Copyright.js +0 -52
- package/govgr/Footer/HellenicRepublicLogo.js +0 -19
- package/govgr/Footer/LicenseCCSA.d.ts +0 -3
- package/govgr/Footer/LicenseCCSA.js +0 -33
- package/govgr/Footer/index.d.ts +0 -13
- package/govgr/Footer/index.js +0 -39
- package/govgr/Footer/index.mdx +0 -97
- package/govgr/Footer/logo.d.ts +0 -2
- package/govgr/Footer/logo.js +0 -8
- package/govgr/Footer/logos/logo-el.d.ts +0 -2
- package/govgr/Footer/logos/logo-el.js +0 -8
- package/govgr/Footer/logos/logo-en.d.ts +0 -2
- package/govgr/Footer/logos/logo-en.js +0 -8
- package/govgr/Logo/govgr-logo.svg +0 -1
- package/govgr/Logo/index.js +0 -19
- package/govgr/Logo/logo.d.ts +0 -2
- package/govgr/Logo/logo.js +0 -8
- package/govgr/index.js +0 -57
- package/hooks/useDebounce.d.ts +0 -3
- package/hooks/useDebounce.js +0 -63
- package/hooks/useLatest.d.ts +0 -3
- package/hooks/useLatest.js +0 -26
- package/hooks/useOutdatedBrowserCheck.d.ts +0 -2
- package/hooks/useOutdatedBrowserCheck.js +0 -60
- package/hooks/useSearch.d.ts +0 -4
- package/hooks/useSearch.js +0 -40
- package/hooks/useTogglableSections.d.ts +0 -18
- package/hooks/useTogglableSections.js +0 -108
- package/index.js +0 -70
- package/layouts/Basic/Bottom/index.js +0 -19
- package/layouts/Basic/Bottom/index.mdx +0 -37
- package/layouts/Basic/Content/index.d.ts +0 -5
- package/layouts/Basic/Content/index.js +0 -31
- package/layouts/Basic/Content/index.mdx +0 -64
- package/layouts/Basic/Main/index.js +0 -19
- package/layouts/Basic/Main/index.mdx +0 -64
- package/layouts/Basic/Masthead/index.js +0 -27
- package/layouts/Basic/Masthead/index.mdx +0 -74
- package/layouts/Basic/Side/index.d.ts +0 -3
- package/layouts/Basic/Side/index.js +0 -20
- package/layouts/Basic/Side/index.mdx +0 -71
- package/layouts/Basic/Top/index.d.ts +0 -3
- package/layouts/Basic/Top/index.js +0 -24
- package/layouts/Basic/Top/index.mdx +0 -74
- package/layouts/Basic/__snapshots__/index.spec.tsx.snap +0 -54
- package/layouts/Basic/index.js +0 -97
- package/layouts/Basic/index.mdx +0 -62
- package/layouts/Basic/index.spec.d.ts +0 -1
- package/layouts/Basic/index.spec.js +0 -20
- package/layouts/Grid/index.js +0 -18
- package/layouts/index.js +0 -34
- package/locales/el.d.ts +0 -46
- package/locales/el.js +0 -52
- package/locales/en.d.ts +0 -46
- package/locales/en.js +0 -52
- package/router/index.d.ts +0 -9
- package/router/index.js +0 -37
- package/router/index.mdx +0 -40
- package/test-utils/delay.d.ts +0 -2
- package/test-utils/delay.js +0 -45
- package/test-utils/mountWithTheme.d.ts +0 -3
- package/test-utils/mountWithTheme.js +0 -43
- package/themes/govgr.d.ts +0 -3
- package/themes/govgr.js +0 -89
- package/themes/grnet.d.ts +0 -2
- package/themes/grnet.js +0 -128
- package/themes/index.d.ts +0 -32
- package/themes/index.js +0 -19
- package/typography/Caption.d.ts +0 -7
- package/typography/Caption.js +0 -20
- package/typography/NormalText.d.ts +0 -5
- package/typography/NormalText.js +0 -19
- package/typography/Paragraph.d.ts +0 -6
- package/typography/Paragraph.js +0 -13
- package/typography/Title.d.ts +0 -9
- package/typography/Title.js +0 -63
- package/typography/index.js +0 -97
- package/typography/index.mdx +0 -32
- package/utils/evaluateBrowserVersion.d.ts +0 -15
- package/utils/evaluateBrowserVersion.js +0 -216
- package/utils/withDeprecation.d.ts +0 -16
- package/utils/withDeprecation.js +0 -116
package/docs/index.mdx
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: DigiGOV UI Toolkit
|
|
3
|
+
order: 0
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# DigiGOV UI Toolkit
|
|
7
|
+
|
|
8
|
+
**@digigov UI toolkit** is a set of libraries and tools written in javascript
|
|
9
|
+
which mainly focuses on providing developers with an easy and streamlined way
|
|
10
|
+
to design and develop frontend applications that target the gov.gr ecosystem.
|
|
11
|
+
|
|
12
|
+
The project consists of the following packages,
|
|
13
|
+
|
|
14
|
+
### @digigov/ui
|
|
15
|
+
|
|
16
|
+
A set of components written in [React](https://reactjs.com) and powered by
|
|
17
|
+
[Material Design](https://material.io) using the exceptional [React Material
|
|
18
|
+
UI toolkit](https://material-ui.com) which implement the [DigiGOV Design
|
|
19
|
+
System](/docs/site/design) guidelines.
|
|
20
|
+
|
|
21
|
+
<hr />
|
|
22
|
+
|
|
23
|
+
### @digigov/nextjs
|
|
24
|
+
|
|
25
|
+
A small set of utilities to facilitate developing @digigov/ui powered apps
|
|
26
|
+
using [Next.js](https://nextjs.com) framework.
|
|
27
|
+
|
|
28
|
+
<hr />
|
|
29
|
+
|
|
30
|
+
### @digigov/dev
|
|
31
|
+
|
|
32
|
+
Software package utilities and pre-bundled configurations and scripts for
|
|
33
|
+
day-to-day developer's needs (test, lint, serve).
|
|
34
|
+
|
|
35
|
+
<hr />
|
|
36
|
+
|
|
37
|
+
## Getting started
|
|
38
|
+
|
|
39
|
+
The simplest way to set up a project using the toolkit, assuming that [node](https://nodejs.org)
|
|
40
|
+
and [yarn](http://yarnpkg.com/) and [npx](https://github.com/npm/npx#install) are already installed and configured on your system, is by using
|
|
41
|
+
the `create-digigov-app` generator,
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
$ npx create-digigov-app my-service
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Fill the questions asked and once the dependencies of the project are
|
|
48
|
+
installed (it may take a while) use the following command to start up the
|
|
49
|
+
development server of your new app,
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
$ cd my-server
|
|
53
|
+
$ yarn dev
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Your app is now accessible at [http://localhost:3000](http://localhost:3000)
|
|
57
|
+
|
|
58
|
+
### Next steps
|
|
59
|
+
|
|
60
|
+
- Get familiar with next.js and learn how to set up new pages for your service
|
|
61
|
+
- [Next.js Tutorial](https://nextjs.org/learn/basics/getting-started)
|
|
62
|
+
- [Next.js Docs](https://nextjs.org/docs/getting-started)
|
|
63
|
+
- Learn how to design your service by following the DigiGOV guidelines
|
|
64
|
+
- [DigiGOV Design System](/docs/site/design)
|
|
65
|
+
- Become familiar with the available components
|
|
66
|
+
- [@digigov/ui components](/ui/components)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Introduction
|
|
3
|
+
parent: docs/ui
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
The `@digigov/ui` is a collection of libraries and tools (in short, an SDK -
|
|
7
|
+
Software Development Kit) written in the latest Ecmascript and Typescript
|
|
8
|
+
specifications that are developed by the [GRNET](https://www.grnet.gr) Devs.
|
|
9
|
+
Their purpose is to provide software engineers inside GRNET (or in other
|
|
10
|
+
external teams) an easy, battle-tested and scalable way to design and develop
|
|
11
|
+
high quality [gov.gr](https://www.gov.gr) services and web applications.
|
|
12
|
+
|
|
13
|
+
The technologies used includes a plethora of tools, such as
|
|
14
|
+
[node.js](https://nodejs.org/), [React](https://reactjs.org/) and
|
|
15
|
+
[Next](https://nextjs.org/). GRNET Devs team has built-upon those technologies
|
|
16
|
+
but also developed custom software solutions to meet our unique demands and
|
|
17
|
+
specifications.
|
|
18
|
+
|
|
19
|
+
## Overview of Digigov SDKs
|
|
20
|
+
|
|
21
|
+
Some of the tools and libraries currently used in development are:
|
|
22
|
+
|
|
23
|
+
- **create-digigov-app** - Create a fresh Digigov app with one command
|
|
24
|
+
- **@digigov/ui** - Ready-to-use UI components for the [DigiGOV Design System](/docs/site/design) implemented in [React](https://reactjs.com) and based on
|
|
25
|
+
[Google Material Design Language](https://material.io) and the
|
|
26
|
+
[React Material UI](https://material-ui.com) library
|
|
27
|
+
- **@digigov/auth** - A library that contains React Providers and functions
|
|
28
|
+
for the authentication system of gov.gr services
|
|
29
|
+
- **@digigov/dev** - Software package utilities and pre-bundled configurations
|
|
30
|
+
and scripts for day-to-day developer's needs (test, lint, serve)
|
|
31
|
+
- **@digigov/nextjs** - A small set of utilities to facilitate developing
|
|
32
|
+
@digigov/ui powered apps using [Next.js](https://nextjs.com) framework
|
|
33
|
+
|
|
34
|
+
[Continue in the next section “Create a new service“](/docs/ui/create-a-new-service)
|
package/package.json
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digigov/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "@digigov reusable components toolkit",
|
|
5
|
-
"module": "
|
|
5
|
+
"module": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"directory": "dist"
|
|
8
8
|
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"lint": "digigov lint",
|
|
11
|
+
"test": "digigov test",
|
|
12
|
+
"build": "digigov build --subpackages",
|
|
13
|
+
"prepublish": "digigov build --subpackages"
|
|
14
|
+
},
|
|
9
15
|
"dependencies": {
|
|
10
16
|
"google-libphonenumber": "3.2.8",
|
|
11
17
|
"react-qr-reader": "2.2.1",
|
|
@@ -18,10 +24,27 @@
|
|
|
18
24
|
"clsx": "1.1.1",
|
|
19
25
|
"react": "16.14.0",
|
|
20
26
|
"react-dom": "16.14.0",
|
|
21
|
-
"@digigov/react-core": "0.
|
|
27
|
+
"@digigov/react-core": "0.6.1"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@digigov/cli": "0.5.27",
|
|
31
|
+
"@digigov/cli-lint": "0.5.28",
|
|
32
|
+
"@digigov/cli-build": "0.7.1",
|
|
33
|
+
"@digigov/cli-test": "0.6.0",
|
|
34
|
+
"@testing-library/react": "11.2.1",
|
|
35
|
+
"@testing-library/react-hooks": "3.4.2",
|
|
36
|
+
"@types/react-qr-reader": "2.1.2",
|
|
37
|
+
"typescript": "4.2.3",
|
|
38
|
+
"@types/node": "14.14.9",
|
|
39
|
+
"@types/react": "16.9.56",
|
|
40
|
+
"@types/react-dom": "16.9.9",
|
|
41
|
+
"@types/enzyme": "3.10.8",
|
|
42
|
+
"@types/enzyme-adapter-react-16": "1.0.5",
|
|
43
|
+
"@types/jest": "26.0.15",
|
|
44
|
+
"enzyme": "3.11.0",
|
|
45
|
+
"fetch-mock": "9.3.1",
|
|
46
|
+
"eslint": "7.24.0",
|
|
47
|
+
"prettier": "2.2.1"
|
|
22
48
|
},
|
|
23
|
-
"gitHead": "c903a46306f77f55ad7fc4d2e274006f39a6c871"
|
|
24
|
-
|
|
25
|
-
"main": "./index.js",
|
|
26
|
-
"typings": "./index.d.ts"
|
|
27
|
-
}
|
|
49
|
+
"gitHead": "c903a46306f77f55ad7fc4d2e274006f39a6c871"
|
|
50
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export class APIErrors extends React.Component<{
|
|
3
|
+
fallback: React.ElementType<any>;
|
|
4
|
+
}> {
|
|
5
|
+
state = { hasError: false, error: null };
|
|
6
|
+
static getDerivedStateFromError(error: Error): object {
|
|
7
|
+
return {
|
|
8
|
+
hasError: true,
|
|
9
|
+
error,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
render(): React.ReactNode {
|
|
14
|
+
if (this.state.hasError) {
|
|
15
|
+
const Comp = this.props.fallback;
|
|
16
|
+
return <Comp error={this.state.error} />;
|
|
17
|
+
}
|
|
18
|
+
return this.props.children;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default APIErrors;
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
The type of `error` variable of the `useRequest` hook result.
|
|
26
|
+
|
|
27
|
+
We expect a request to fail for at least one reason (`error` property). In
|
|
28
|
+
case of multiple errors, developers may use `errors` property to construct
|
|
29
|
+
a more verbose error report.
|
|
30
|
+
*/
|
|
31
|
+
export class APIError extends Error {
|
|
32
|
+
error: null | { data: { invalid_fields: Record<string, any>[] } } = null;
|
|
33
|
+
errors = null;
|
|
34
|
+
status = 200;
|
|
35
|
+
|
|
36
|
+
constructor(errors, status, ...args) {
|
|
37
|
+
super(...args);
|
|
38
|
+
this.name = 'APIError';
|
|
39
|
+
Error.captureStackTrace(this, APIError);
|
|
40
|
+
this.error = (errors && errors.length && errors[0]) || errors;
|
|
41
|
+
this.errors = errors;
|
|
42
|
+
this.status = status;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React, { createContext, useMemo } from 'react';
|
|
2
|
+
export interface APIConfig {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
}
|
|
5
|
+
export interface APIContextData {
|
|
6
|
+
config: APIConfig;
|
|
7
|
+
token: string | null | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface APIProviderProps {
|
|
10
|
+
token: string | null | undefined;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
config: APIConfig;
|
|
13
|
+
}
|
|
14
|
+
export const APIContext = createContext<APIContextData>({
|
|
15
|
+
config: {
|
|
16
|
+
baseURL: '',
|
|
17
|
+
},
|
|
18
|
+
token: null,
|
|
19
|
+
});
|
|
20
|
+
export const APIProvider: React.FC<APIProviderProps> = ({
|
|
21
|
+
token = null,
|
|
22
|
+
config = { baseURL: '' },
|
|
23
|
+
children,
|
|
24
|
+
}) => {
|
|
25
|
+
const data = useMemo(() => ({ token, config }), [token, config]);
|
|
26
|
+
return <APIContext.Provider value={data}>{children}</APIContext.Provider>;
|
|
27
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { APIContextData } from '@digigov/ui/api/APIProvider';
|
|
2
|
+
import { getArgs, processResponse } from '@digigov/ui/api/utils';
|
|
3
|
+
|
|
4
|
+
export interface ProcessedResponse {
|
|
5
|
+
data?: any;
|
|
6
|
+
status: number;
|
|
7
|
+
error?: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface FetchAPIProps {
|
|
11
|
+
resource: string;
|
|
12
|
+
options?: {
|
|
13
|
+
query?: Record<string, any>;
|
|
14
|
+
path?: string;
|
|
15
|
+
method?: string;
|
|
16
|
+
body?: any;
|
|
17
|
+
};
|
|
18
|
+
getAPI?: (...args) => APIContextData;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function fetchAPI(
|
|
22
|
+
resource: string,
|
|
23
|
+
{ query = {}, path = '', method = 'GET', body = null }: any,
|
|
24
|
+
apiConfig: any
|
|
25
|
+
): Promise<ProcessedResponse> {
|
|
26
|
+
const {
|
|
27
|
+
config: { baseURL },
|
|
28
|
+
token,
|
|
29
|
+
} = apiConfig;
|
|
30
|
+
const [url, options] = getArgs(
|
|
31
|
+
resource,
|
|
32
|
+
path,
|
|
33
|
+
query,
|
|
34
|
+
body,
|
|
35
|
+
null,
|
|
36
|
+
method,
|
|
37
|
+
baseURL,
|
|
38
|
+
token
|
|
39
|
+
);
|
|
40
|
+
const response = await window.fetch(url, options);
|
|
41
|
+
const { data, error, status } = await processResponse(response);
|
|
42
|
+
return { data, error, status };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default fetchAPI;
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-function-return-type */
|
|
2
|
+
import React, { FunctionComponent, Suspense, useEffect } from 'react';
|
|
3
|
+
import { render, fireEvent } from '@testing-library/react';
|
|
4
|
+
import fetchMock from 'fetch-mock';
|
|
5
|
+
import {
|
|
6
|
+
APIProvider,
|
|
7
|
+
useResource,
|
|
8
|
+
useResourceAction,
|
|
9
|
+
useResourceMany,
|
|
10
|
+
APIContextData,
|
|
11
|
+
APIErrors,
|
|
12
|
+
} from '@digigov/ui/api/index';
|
|
13
|
+
import delay from '@digigov/ui/test-utils/delay';
|
|
14
|
+
import fetchAPI from '@digigov/ui/api/fetchAPI';
|
|
15
|
+
import 'whatwg-fetch';
|
|
16
|
+
|
|
17
|
+
const HandleError = ({ error }) => {
|
|
18
|
+
if (error.name === 'APIError') {
|
|
19
|
+
error = error.error;
|
|
20
|
+
if (error.status === 404) {
|
|
21
|
+
return <>Not found</>;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// TODO: render the <SomethingWentWrong /> page here
|
|
25
|
+
return <span>something went wrong</span>;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const makeWrapper = ({ config, token }: APIContextData): FunctionComponent => ({
|
|
29
|
+
children,
|
|
30
|
+
}: {
|
|
31
|
+
children: React.ReactNode;
|
|
32
|
+
}): any => (
|
|
33
|
+
<Suspense fallback={'Loading'}>
|
|
34
|
+
<APIErrors fallback={HandleError}>
|
|
35
|
+
<APIProvider config={config} token={token}>
|
|
36
|
+
{children}
|
|
37
|
+
</APIProvider>
|
|
38
|
+
</APIErrors>
|
|
39
|
+
</Suspense>
|
|
40
|
+
);
|
|
41
|
+
const BASE_URL = 'http://test/api';
|
|
42
|
+
const TOKEN = 'mytoken';
|
|
43
|
+
const DELAY = 100;
|
|
44
|
+
const buildMockOptions = ({
|
|
45
|
+
resource,
|
|
46
|
+
method = 'GET',
|
|
47
|
+
authenticated = true,
|
|
48
|
+
query = {},
|
|
49
|
+
response,
|
|
50
|
+
delay = DELAY / 2,
|
|
51
|
+
}): [any, any, any] => {
|
|
52
|
+
const headers: any = {
|
|
53
|
+
'content-type': 'application/json',
|
|
54
|
+
};
|
|
55
|
+
const options = { delay };
|
|
56
|
+
if (authenticated) {
|
|
57
|
+
headers.Authorization = `Token ${TOKEN}`;
|
|
58
|
+
}
|
|
59
|
+
const params = new URLSearchParams(query).toString();
|
|
60
|
+
return [
|
|
61
|
+
`${BASE_URL}/${resource}${params && `?${params}`}`,
|
|
62
|
+
response,
|
|
63
|
+
{
|
|
64
|
+
headers,
|
|
65
|
+
method,
|
|
66
|
+
...options,
|
|
67
|
+
},
|
|
68
|
+
];
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getAPI = () => {
|
|
72
|
+
return {
|
|
73
|
+
config: {
|
|
74
|
+
baseURL: BASE_URL,
|
|
75
|
+
},
|
|
76
|
+
token: TOKEN,
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const wrapper = makeWrapper(getAPI());
|
|
81
|
+
|
|
82
|
+
describe('fetchAPI', () => {
|
|
83
|
+
fetchMock.config.overwriteRoutes = true;
|
|
84
|
+
afterAll(() => {
|
|
85
|
+
fetchMock.restore();
|
|
86
|
+
});
|
|
87
|
+
beforeEach(fetchMock.resetBehavior);
|
|
88
|
+
beforeEach(fetchMock.resetHistory);
|
|
89
|
+
it('fetchAPI gets', async () => {
|
|
90
|
+
const resource = 'resource';
|
|
91
|
+
const path = 'some_id';
|
|
92
|
+
fetchMock.mock(
|
|
93
|
+
...buildMockOptions({
|
|
94
|
+
resource: `${resource}/${path}/`,
|
|
95
|
+
response: { value: 'SWR' },
|
|
96
|
+
})
|
|
97
|
+
);
|
|
98
|
+
const { data } = await fetchAPI(resource, { path }, getAPI());
|
|
99
|
+
expect(data.value).toBe('SWR');
|
|
100
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
describe('useResource', () => {
|
|
105
|
+
fetchMock.config.overwriteRoutes = true;
|
|
106
|
+
afterAll(() => {
|
|
107
|
+
fetchMock.restore();
|
|
108
|
+
});
|
|
109
|
+
beforeEach(fetchMock.resetBehavior);
|
|
110
|
+
beforeEach(fetchMock.resetHistory);
|
|
111
|
+
it('useResource should return data', async () => {
|
|
112
|
+
const resource = 'resource';
|
|
113
|
+
function Page() {
|
|
114
|
+
const { data } = useResource(resource);
|
|
115
|
+
return <div>hello, {data?.value}</div>;
|
|
116
|
+
}
|
|
117
|
+
fetchMock.mock(
|
|
118
|
+
...buildMockOptions({ resource, response: { value: 'SWR' } })
|
|
119
|
+
);
|
|
120
|
+
const { container } = render(<Page />, {
|
|
121
|
+
wrapper,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
expect(container.firstChild).not.toBe(null);
|
|
125
|
+
|
|
126
|
+
if (container.firstChild) {
|
|
127
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
128
|
+
`"hello, "`
|
|
129
|
+
);
|
|
130
|
+
await delay(DELAY);
|
|
131
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
132
|
+
`"hello, SWR"`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should run duplicate request once', async () => {
|
|
140
|
+
const resource = 'dupliresource';
|
|
141
|
+
function Page() {
|
|
142
|
+
useResource(resource);
|
|
143
|
+
const { data: duplData } = useResource(resource);
|
|
144
|
+
return <div>hello, {duplData?.value}</div>;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
fetchMock.mock(
|
|
148
|
+
...buildMockOptions({ resource, response: { value: 'myvalue' } })
|
|
149
|
+
);
|
|
150
|
+
const { container } = render(<Page />, {
|
|
151
|
+
wrapper,
|
|
152
|
+
});
|
|
153
|
+
expect(container.firstChild).not.toBe(null);
|
|
154
|
+
|
|
155
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
156
|
+
`"hello, "`
|
|
157
|
+
);
|
|
158
|
+
await delay(DELAY);
|
|
159
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
160
|
+
`"hello, myvalue"`
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe('useResourceAction', () => {
|
|
168
|
+
fetchMock.config.overwriteRoutes = true;
|
|
169
|
+
afterAll(() => {
|
|
170
|
+
fetchMock.restore();
|
|
171
|
+
});
|
|
172
|
+
beforeEach(fetchMock.resetBehavior);
|
|
173
|
+
beforeEach(fetchMock.resetHistory);
|
|
174
|
+
|
|
175
|
+
it('useResourceAction should return result ', async () => {
|
|
176
|
+
const resource = 'resourceaction';
|
|
177
|
+
function Page() {
|
|
178
|
+
const { data, fetch } = useResourceAction(
|
|
179
|
+
resource,
|
|
180
|
+
undefined,
|
|
181
|
+
'POST',
|
|
182
|
+
{
|
|
183
|
+
some: 'data',
|
|
184
|
+
},
|
|
185
|
+
undefined
|
|
186
|
+
);
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
fetch();
|
|
189
|
+
}, []);
|
|
190
|
+
return <div>hello, {data && data.value}</div>;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
fetchMock.mock(
|
|
194
|
+
...buildMockOptions({
|
|
195
|
+
resource,
|
|
196
|
+
response: { value: 'myvalue' },
|
|
197
|
+
method: 'POST',
|
|
198
|
+
})
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const { container } = render(<Page />, {
|
|
202
|
+
wrapper,
|
|
203
|
+
});
|
|
204
|
+
expect(container.firstChild).not.toBe(null);
|
|
205
|
+
|
|
206
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
207
|
+
`"hello, "`
|
|
208
|
+
);
|
|
209
|
+
await delay(DELAY * 2);
|
|
210
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
211
|
+
`"hello, myvalue"`
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it('useResourceAction should be invalidated and run twice', async () => {
|
|
218
|
+
const resource = 'resourceactiondouble';
|
|
219
|
+
function Page() {
|
|
220
|
+
const { data, fetch, invalidate } = useResourceAction(
|
|
221
|
+
resource,
|
|
222
|
+
undefined,
|
|
223
|
+
'POST',
|
|
224
|
+
{
|
|
225
|
+
some: 'data',
|
|
226
|
+
},
|
|
227
|
+
undefined
|
|
228
|
+
);
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
fetch();
|
|
231
|
+
}, []);
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
setTimeout(() => {
|
|
234
|
+
invalidate();
|
|
235
|
+
}, DELAY * 2);
|
|
236
|
+
setTimeout(() => {
|
|
237
|
+
fetch();
|
|
238
|
+
}, DELAY * 3);
|
|
239
|
+
}, []);
|
|
240
|
+
return <div>hello, {data && data.value}</div>;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
fetchMock.mock(
|
|
244
|
+
...buildMockOptions({
|
|
245
|
+
resource,
|
|
246
|
+
response: { value: 'myvalue' },
|
|
247
|
+
method: 'POST',
|
|
248
|
+
})
|
|
249
|
+
);
|
|
250
|
+
const { container } = render(<Page />, {
|
|
251
|
+
wrapper,
|
|
252
|
+
});
|
|
253
|
+
expect(container.firstChild).not.toBe(null);
|
|
254
|
+
|
|
255
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
256
|
+
`"hello, "`
|
|
257
|
+
);
|
|
258
|
+
await delay(DELAY);
|
|
259
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
260
|
+
`"hello, myvalue"`
|
|
261
|
+
);
|
|
262
|
+
await delay(DELAY);
|
|
263
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
264
|
+
`"hello, "`
|
|
265
|
+
);
|
|
266
|
+
await delay(DELAY * 2);
|
|
267
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
268
|
+
`"hello, myvalue"`
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
expect(fetchMock.calls()).toHaveLength(2);
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
describe('useResourceMany', () => {
|
|
276
|
+
fetchMock.config.overwriteRoutes = true;
|
|
277
|
+
afterAll(() => {
|
|
278
|
+
fetchMock.restore();
|
|
279
|
+
});
|
|
280
|
+
beforeEach(fetchMock.resetBehavior);
|
|
281
|
+
beforeEach(fetchMock.resetHistory);
|
|
282
|
+
|
|
283
|
+
//check this test again (loading/hello)
|
|
284
|
+
|
|
285
|
+
it('useResourceMany should return data', async () => {
|
|
286
|
+
const resource = 'resourceMany';
|
|
287
|
+
function Page() {
|
|
288
|
+
const { data } = useResourceMany(resource);
|
|
289
|
+
return <div>hello, {data && data.join('')}</div>;
|
|
290
|
+
}
|
|
291
|
+
fetchMock.mock(
|
|
292
|
+
...buildMockOptions({
|
|
293
|
+
resource,
|
|
294
|
+
query: { offset: 0, limit: 30 },
|
|
295
|
+
response: {
|
|
296
|
+
data: ['S', 'W', 'R'],
|
|
297
|
+
meta: {
|
|
298
|
+
total: 1,
|
|
299
|
+
count: 3,
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
})
|
|
303
|
+
);
|
|
304
|
+
const { container } = render(<Page />, {
|
|
305
|
+
wrapper,
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
expect(container.firstChild).not.toBe(null);
|
|
309
|
+
|
|
310
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
311
|
+
`"Loading"`
|
|
312
|
+
);
|
|
313
|
+
await delay(DELAY * 2);
|
|
314
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
315
|
+
`"hello, SWR"`
|
|
316
|
+
);
|
|
317
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('useResourceMany should handle hasNext, hasPrevious', async () => {
|
|
321
|
+
const resource = 'resourceManyhasNext';
|
|
322
|
+
function Page() {
|
|
323
|
+
const { hasNext, hasPrevious } = useResourceMany(resource);
|
|
324
|
+
return (
|
|
325
|
+
<div>
|
|
326
|
+
{hasNext ? '' : 'no'} next,{hasPrevious ? '' : 'no'} previous
|
|
327
|
+
</div>
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
fetchMock.mock(
|
|
331
|
+
...buildMockOptions({
|
|
332
|
+
resource,
|
|
333
|
+
query: { offset: 0, limit: 30 },
|
|
334
|
+
response: {
|
|
335
|
+
data: ['S', 'W', 'R'],
|
|
336
|
+
meta: {
|
|
337
|
+
total: 1,
|
|
338
|
+
count: 3,
|
|
339
|
+
},
|
|
340
|
+
},
|
|
341
|
+
})
|
|
342
|
+
);
|
|
343
|
+
const { container } = render(<Page />, {
|
|
344
|
+
wrapper,
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
expect(container.firstChild).not.toBe(null);
|
|
348
|
+
|
|
349
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
350
|
+
`"Loading"`
|
|
351
|
+
);
|
|
352
|
+
await delay(DELAY);
|
|
353
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
354
|
+
`"no next,no previous"`
|
|
355
|
+
);
|
|
356
|
+
expect(fetchMock.calls()).toHaveLength(1);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('useResourceMany should handle setPage with custom limit option', async () => {
|
|
360
|
+
const resource = 'resourceManysetpage';
|
|
361
|
+
function Page() {
|
|
362
|
+
const { data, setPage, page } = useResourceMany(resource, { limit: 10 });
|
|
363
|
+
const nextPage = () => {
|
|
364
|
+
setPage(page + 1);
|
|
365
|
+
};
|
|
366
|
+
return (
|
|
367
|
+
<div>
|
|
368
|
+
hello, {data.join('')}
|
|
369
|
+
<button onClick={nextPage}>next</button>
|
|
370
|
+
</div>
|
|
371
|
+
);
|
|
372
|
+
}
|
|
373
|
+
fetchMock.mock(
|
|
374
|
+
...buildMockOptions({
|
|
375
|
+
resource,
|
|
376
|
+
query: { offset: 0, limit: 10 },
|
|
377
|
+
response: {
|
|
378
|
+
data: ['S', 'W', 'R'],
|
|
379
|
+
meta: {
|
|
380
|
+
total: 3,
|
|
381
|
+
count: 100,
|
|
382
|
+
},
|
|
383
|
+
},
|
|
384
|
+
})
|
|
385
|
+
);
|
|
386
|
+
fetchMock.mock(
|
|
387
|
+
...buildMockOptions({
|
|
388
|
+
resource,
|
|
389
|
+
query: { offset: 10, limit: 10 },
|
|
390
|
+
response: {
|
|
391
|
+
data: ['R', 'W', 'S'],
|
|
392
|
+
meta: {
|
|
393
|
+
total: 3,
|
|
394
|
+
count: 100,
|
|
395
|
+
},
|
|
396
|
+
},
|
|
397
|
+
})
|
|
398
|
+
);
|
|
399
|
+
const { container, getByText } = render(<Page />, {
|
|
400
|
+
wrapper,
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
expect(container.firstChild).not.toBe(null);
|
|
404
|
+
|
|
405
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
406
|
+
`"Loading"`
|
|
407
|
+
);
|
|
408
|
+
await delay(DELAY);
|
|
409
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
410
|
+
`"hello, SWRnext"`
|
|
411
|
+
);
|
|
412
|
+
fireEvent.click(getByText('next'));
|
|
413
|
+
await delay(DELAY * 2);
|
|
414
|
+
expect(container?.firstChild?.textContent).toMatchInlineSnapshot(
|
|
415
|
+
`"hello, RWSnext"`
|
|
416
|
+
);
|
|
417
|
+
expect(fetchMock.calls()).toHaveLength(2);
|
|
418
|
+
});
|
|
419
|
+
});
|