uikit-react-public 0.17.4 → 0.21.9
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/README.md +2 -4
- package/dist/components/Accordion/Accordion.Heading.d.ts +1 -0
- package/dist/components/AppHeader/AppHeader.d.ts +1 -1
- package/dist/components/AppHeader/AppHeaderBottom.d.ts +1 -1
- package/dist/components/AppHeader/AppHeaderNav.d.ts +1 -1
- package/dist/components/AppHeader/AppHeaderTop.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumb.d.ts +3 -4
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.stories.d.ts +1 -1
- package/dist/components/Button/Button.d.ts +7 -3
- package/dist/components/Button/Button.stories.d.ts +17 -7
- package/dist/components/Button/style/buttonAccentStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonPrimaryDestructiveStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonPrimaryStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonPrimarySubtleStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonPrimaryWarningStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonSecondaryDestructiveStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonSecondaryStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonSecondarySubtleStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonTertiaryDestructiveStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonTertiaryNoPaddingStyle.d.ts +4 -0
- package/dist/components/Button/style/buttonTertiaryStyle.d.ts +4 -0
- package/dist/components/Checkbox/Checkbox.d.ts +1 -0
- package/dist/components/FooterNew/BackToTop.d.ts +8 -0
- package/dist/components/FooterNew/Footer.d.ts +23 -0
- package/dist/components/FooterNew/FooterColumn.d.ts +8 -0
- package/dist/components/FooterNew/FooterLinks.d.ts +7 -0
- package/dist/components/FooterNew/FooterNavLink.d.ts +8 -0
- package/dist/components/FooterNew/LegalAndCopyright.d.ts +14 -0
- package/dist/components/FooterNew/LogoAddressAndSocial.d.ts +10 -0
- package/dist/components/FooterNew/SocialLink.d.ts +8 -0
- package/dist/components/FooterNew/__tests__/Footer.test.d.ts +1 -0
- package/dist/components/FooterNew/index.d.ts +2 -0
- package/dist/components/HeaderNew/Header.d.ts +18 -0
- package/dist/components/HeaderNew/HeaderBorder.d.ts +7 -0
- package/dist/components/HeaderNew/HeaderLogo.d.ts +9 -0
- package/dist/components/HeaderNew/HeaderMenuContainer.d.ts +7 -0
- package/dist/components/HeaderNew/HeaderTitle.d.ts +9 -0
- package/dist/components/HeaderNew/__tests__/Header.test.d.ts +1 -0
- package/dist/components/HeaderNew/constants.d.ts +3 -0
- package/dist/components/HeaderNew/index.d.ts +3 -0
- package/dist/components/Heading/Heading.d.ts +6 -4
- package/dist/components/Heading/Heading.stories.d.ts +8 -6
- package/dist/components/Icon/svgImports.d.ts +7 -881
- package/dist/components/Link/BaseLink.d.ts +14 -5
- package/dist/components/Link/Link.d.ts +8 -3
- package/dist/components/Link/Link.stories.d.ts +3 -1
- package/dist/components/MenuNew/Menu.context.d.ts +14 -0
- package/dist/components/MenuNew/Menu.d.ts +20 -0
- package/dist/components/MenuNew/MenuContent.d.ts +9 -0
- package/dist/components/MenuNew/MenuItem.d.ts +10 -0
- package/dist/components/MenuNew/MenuSection.d.ts +7 -0
- package/dist/components/MenuNew/index.d.ts +6 -0
- package/dist/components/MenuNew/trigger/ButtonMenuTrigger.d.ts +8 -0
- package/dist/components/MenuNew/trigger/IconMenuTrigger.d.ts +8 -0
- package/dist/components/Overlay/Overlay.stories.d.ts +12 -12
- package/dist/components/Paragraph/Paragraph.d.ts +5 -2
- package/dist/components/Paragraph/Paragraph.stories.d.ts +6 -3
- package/dist/components/Select/Select.d.ts +2 -1
- package/dist/components/Select/Select.stories.d.ts +13 -1
- package/dist/components/Select/Select.types.d.ts +40 -13
- package/dist/components/Select/subcomponents/CustomSelect.d.ts +3 -3
- package/dist/components/Select/subcomponents/FilterInput.d.ts +3 -1
- package/dist/components/Select/subcomponents/NativeSelect.d.ts +2 -2
- package/dist/components/Select/subcomponents/VisibleField.d.ts +4 -1
- package/dist/components/Spinner/Spinner.d.ts +2 -0
- package/dist/components/StandaloneLink/StandaloneLink.d.ts +8 -5
- package/dist/components/StandaloneLink/StandaloneLink.stories.d.ts +3 -1
- package/dist/components/Table/Table.d.ts +3 -3
- package/dist/components/Table/Table.stories.d.ts +3 -3
- package/dist/components/Table/Table.types.d.ts +1 -0
- package/dist/components/Table/subcomponents/Cell/Cell.d.ts +5 -1
- package/dist/components/Table/subcomponents/Cell/Cell.stories.d.ts +15 -13
- package/dist/components/Table/subcomponents/Cell/CellContent.d.ts +5 -1
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.d.ts +2 -1
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.stories.d.ts +14 -13
- package/dist/components/Table/subcomponents/HeadCell/HeadCellContent.d.ts +2 -1
- package/dist/components/Table/subcomponents/__tests__/Row.test.d.ts +1 -0
- package/dist/components/UclLogoNew/UclLogo.d.ts +8 -0
- package/dist/components/UclLogoNew/index.d.ts +2 -0
- package/dist/components/index.d.ts +12 -0
- package/dist/index.js +20104 -15317
- package/dist/theme/__tests__/fonts.test.d.ts +1 -0
- package/dist/theme/common/themeCommon.d.ts +904 -0
- package/dist/theme/fonts.d.ts +18 -0
- package/dist/theme/index.d.ts +6 -3
- package/dist/theme/light/lightColour.d.ts +126 -0
- package/dist/theme/light/lightTheme.d.ts +3 -0
- package/dist/theme/original/color.d.ts +166 -0
- package/dist/theme/original/defaultTheme.d.ts +1340 -0
- package/dist/theme/original/originalColourNewStructure.d.ts +126 -0
- package/dist/theme/useTheme.d.ts +2174 -0
- package/dist/utils/addAlphaToHex.d.ts +5 -0
- package/dist/utils/scrollToTop.d.ts +2 -0
- package/lib/components/Accordion/Accordion.Heading.tsx +51 -39
- package/lib/components/Accordion/Accordion.Panel.tsx +0 -4
- package/lib/components/Accordion/Accordion.tsx +34 -28
- package/lib/components/Accordion/__tests__/__snapshots__/Accordion.test.tsx.snap +12 -10
- package/lib/components/Alert/Alert.tsx +12 -12
- package/lib/components/Alert/__tests__/__snapshots__/Alert.test.tsx.snap +13 -39
- package/lib/components/AppHeader/AppHeader.tsx +6 -11
- package/lib/components/AppHeader/AppHeaderBottom.tsx +2 -3
- package/lib/components/AppHeader/AppHeaderNav.tsx +2 -3
- package/lib/components/AppHeader/AppHeaderTop.tsx +1 -1
- package/lib/components/AppHeader/__tests__/__snapshots__/AppHeader.test.tsx.snap +2 -2
- package/lib/components/AppMenu/__tests__/__snapshots__/AppMenu.test.tsx.snap +6 -19
- package/lib/components/Badge/Badge.stories.tsx +1 -1
- package/lib/components/Breadcrumbs/Breadcrumb.tsx +26 -12
- package/lib/components/Breadcrumbs/Breadcrumbs.tsx +1 -1
- package/lib/components/Breadcrumbs/__tests__/Breadcrumbs.test.tsx +9 -27
- package/lib/components/Breadcrumbs/__tests__/__snapshots__/Breadcrumbs.test.tsx.snap +24 -20
- package/lib/components/Button/Button.mdx +32 -279
- package/lib/components/Button/Button.stories.tsx +43 -50
- package/lib/components/Button/Button.tsx +165 -25
- package/lib/components/Button/__tests__/Button.test.tsx +49 -15
- package/lib/components/Button/__tests__/__snapshots__/Button.test.tsx.snap +80 -73
- package/lib/components/Button/style/buttonAccentStyle.ts +53 -0
- package/lib/components/Button/style/buttonPrimaryDestructiveStyle.ts +55 -0
- package/lib/components/Button/style/buttonPrimaryStyle.ts +53 -0
- package/lib/components/Button/style/buttonPrimarySubtleStyle.ts +64 -0
- package/lib/components/Button/style/buttonPrimaryWarningStyle.ts +56 -0
- package/lib/components/Button/style/buttonSecondaryDestructiveStyle.ts +63 -0
- package/lib/components/Button/style/buttonSecondaryStyle.ts +62 -0
- package/lib/components/Button/style/buttonSecondarySubtleStyle.ts +72 -0
- package/lib/components/Button/style/buttonTertiaryDestructiveStyle.ts +65 -0
- package/lib/components/Button/style/buttonTertiaryNoPaddingStyle.ts +52 -0
- package/lib/components/Button/style/buttonTertiaryStyle.ts +62 -0
- package/lib/components/Calendar/Calendar.stories.tsx +33 -13
- package/lib/components/Calendar/Calendar.tsx +2 -2
- package/lib/components/Calendar/__tests__/__snapshots__/Calendar.test.tsx.snap +99 -95
- package/lib/components/Calendar/subcomponents/AcademicWeek.tsx +2 -1
- package/lib/components/Calendar/subcomponents/AcademicWeeks.tsx +2 -3
- package/lib/components/Calendar/subcomponents/ColumnHeading.tsx +3 -7
- package/lib/components/Calendar/subcomponents/Controls.tsx +1 -1
- package/lib/components/Calendar/subcomponents/Day.stories.tsx +1 -1
- package/lib/components/Calendar/subcomponents/Day.tsx +7 -9
- package/lib/components/Calendar/subcomponents/EventDot.tsx +4 -8
- package/lib/components/Checkbox/Checkbox.stories.tsx +1 -1
- package/lib/components/Checkbox/Checkbox.tsx +12 -10
- package/lib/components/Checkbox/__tests__/Checkbox.test.tsx +29 -0
- package/lib/components/Checkbox/__tests__/__snapshots__/Checkbox.test.tsx.snap +4 -4
- package/lib/components/Datepicker/__tests__/Datepicker.test.tsx +117 -0
- package/lib/components/Datepicker/__tests__/__snapshots__/Datepicker.test.tsx.snap +16 -44
- package/lib/components/Datepicker/subcomponents/CustomDatepicker.tsx +10 -1
- package/lib/components/Datepicker/subcomponents/VisibleField.tsx +24 -23
- package/lib/components/Dialog/BaseDialog.tsx +2 -2
- package/lib/components/Dialog/Dialog.stories.tsx +1 -1
- package/lib/components/Divider/__tests__/__snapshots__/Breadcrumbs.test.tsx.snap +12 -12
- package/lib/components/FeedbackDialog/FeedbackDialog.stories.tsx +1 -1
- package/lib/components/FeedbackDialog/FeedbackDialog.tsx +4 -6
- package/lib/components/Field/CharacterCount.tsx +2 -2
- package/lib/components/Field/ErrorText.tsx +1 -1
- package/lib/components/Field/Field.tsx +1 -1
- package/lib/components/Field/HelperText.tsx +3 -1
- package/lib/components/FileInput/FileInput.stories.tsx +1 -1
- package/lib/components/FileInput/__tests__/__snapshots__/FileInput.test.tsx.snap +4 -20
- package/lib/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap +70 -79
- package/lib/components/FooterNew/BackToTop.tsx +83 -0
- package/lib/components/FooterNew/Footer.tsx +110 -0
- package/lib/components/FooterNew/FooterColumn.tsx +79 -0
- package/lib/components/FooterNew/FooterLinks.tsx +44 -0
- package/lib/components/FooterNew/FooterNavLink.tsx +63 -0
- package/lib/components/FooterNew/LegalAndCopyright.tsx +150 -0
- package/lib/components/FooterNew/LogoAddressAndSocial.tsx +154 -0
- package/lib/components/FooterNew/SocialLink.tsx +108 -0
- package/lib/components/FooterNew/__tests__/Footer.test.tsx +51 -0
- package/lib/components/FooterNew/__tests__/__snapshots__/Footer.test.tsx.snap +1107 -0
- package/lib/components/FooterNew/index.ts +2 -0
- package/lib/components/HeaderDraft/__tests__/__snapshots__/Header.test.tsx.snap +3 -2
- package/lib/components/HeaderNew/Header.tsx +93 -0
- package/lib/components/HeaderNew/HeaderBorder.tsx +55 -0
- package/lib/components/HeaderNew/HeaderLogo.tsx +70 -0
- package/lib/components/HeaderNew/HeaderMenuContainer.tsx +35 -0
- package/lib/components/HeaderNew/HeaderTitle.tsx +53 -0
- package/lib/components/HeaderNew/__tests__/Header.test.tsx +42 -0
- package/lib/components/HeaderNew/__tests__/__snapshots__/Header.test.tsx.snap +79 -0
- package/lib/components/HeaderNew/constants.ts +3 -0
- package/lib/components/HeaderNew/index.ts +7 -0
- package/lib/components/Heading/Heading.stories.tsx +34 -41
- package/lib/components/Heading/Heading.tsx +180 -49
- package/lib/components/Heading/__tests__/__snapshots__/Heading.test.tsx.snap +4 -4
- package/lib/components/Icon/__tests__/__snapshots__/Icon.test.tsx.snap +16 -12
- package/lib/components/Icon/svgImports.ts +318 -296
- package/lib/components/IconButton/IconButton.tsx +3 -4
- package/lib/components/IconButton/__tests__/__snapshots__/IconButton.test.tsx.snap +12 -9
- package/lib/components/Link/BaseLink.tsx +114 -71
- package/lib/components/Link/Link.stories.tsx +1 -1
- package/lib/components/Link/Link.tsx +120 -109
- package/lib/components/Link/__tests__/__snapshots__/link.test.tsx.snap +2 -2
- package/lib/components/MenuNew/Menu.context.tsx +149 -0
- package/lib/components/MenuNew/Menu.tsx +75 -0
- package/lib/components/MenuNew/MenuContent.tsx +140 -0
- package/lib/components/MenuNew/MenuItem.tsx +101 -0
- package/lib/components/MenuNew/MenuSection.tsx +47 -0
- package/lib/components/MenuNew/index.ts +8 -0
- package/lib/components/MenuNew/trigger/ButtonMenuTrigger.tsx +42 -0
- package/lib/components/MenuNew/trigger/IconMenuTrigger.tsx +40 -0
- package/lib/components/Pagination/Pagination.stories.tsx +1 -1
- package/lib/components/Pagination/PaginationControls.tsx +4 -5
- package/lib/components/Pagination/PaginationInfo.tsx +2 -3
- package/lib/components/Paragraph/Paragraph.stories.tsx +29 -27
- package/lib/components/Paragraph/Paragraph.tsx +212 -81
- package/lib/components/Paragraph/__tests__/__snapshots__/Paragraph.test.tsx.snap +5 -5
- package/lib/components/Radio/Radio.stories.tsx +1 -1
- package/lib/components/Radio/Radio.tsx +8 -8
- package/lib/components/Radio/__tests__/__snapshots__/Radio.test.tsx.snap +4 -4
- package/lib/components/Search/__tests__/__snapshots__/Search.test.tsx.snap +12 -32
- package/lib/components/Select/Select.mdx +23 -0
- package/lib/components/Select/Select.stories.tsx +43 -10
- package/lib/components/Select/Select.tsx +14 -3
- package/lib/components/Select/Select.types.ts +53 -16
- package/lib/components/Select/__tests__/Select.test.tsx +250 -1
- package/lib/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +5 -4
- package/lib/components/Select/subcomponents/CustomOption.tsx +10 -3
- package/lib/components/Select/subcomponents/CustomSelect.tsx +110 -10
- package/lib/components/Select/subcomponents/FilterInput.tsx +13 -3
- package/lib/components/Select/subcomponents/NativeSelect.tsx +10 -18
- package/lib/components/Select/subcomponents/Panel.tsx +2 -2
- package/lib/components/Select/subcomponents/VisibleField.tsx +48 -3
- package/lib/components/Snackbar/__tests__/__snapshots__/Snackbar.test.tsx.snap +9 -15
- package/lib/components/Spinner/Spinner.tsx +24 -5
- package/lib/components/Spinner/__tests__/Spinner.test.tsx +35 -5
- package/lib/components/Spinner/__tests__/__snapshots__/Spinner.test.tsx.snap +40 -16
- package/lib/components/StandaloneLink/StandaloneLink.stories.tsx +1 -1
- package/lib/components/StandaloneLink/StandaloneLink.tsx +180 -163
- package/lib/components/StandaloneLink/__tests__/__snapshots__/StandaloneLink.test.tsx.snap +2 -2
- package/lib/components/Table/Table.stories.tsx +1 -1
- package/lib/components/Table/Table.tsx +2 -0
- package/lib/components/Table/Table.types.ts +1 -0
- package/lib/components/Table/__tests__/Table.test.tsx +19 -0
- package/lib/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +7 -3
- package/lib/components/Table/subcomponents/Cell/Cell.stories.tsx +1 -1
- package/lib/components/Table/subcomponents/Cell/Cell.tsx +23 -2
- package/lib/components/Table/subcomponents/Cell/CellContent.tsx +12 -1
- package/lib/components/Table/subcomponents/Cell/__tests__/Cell.test.tsx +106 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/__snapshots__/Cell.test.tsx.snap +4 -3
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.stories.tsx +1 -1
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.tsx +28 -6
- package/lib/components/Table/subcomponents/HeadCell/HeadCellContent.tsx +3 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.tsx +221 -2
- package/lib/components/Table/subcomponents/HeadCell/__tests__/__snapshots__/HeadCell.test.tsx.snap +6 -4
- package/lib/components/Table/subcomponents/Row.tsx +2 -2
- package/lib/components/Table/subcomponents/SortIcon.tsx +1 -0
- package/lib/components/Table/subcomponents/__tests__/Row.test.tsx +59 -0
- package/lib/components/Tabs/Tab.tsx +3 -3
- package/lib/components/Tabs/Tabs.stories.tsx +1 -1
- package/lib/components/Tabs/Tabs.tsx +5 -3
- package/lib/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +4 -4
- package/lib/components/Timepicker/Timepicker.stories.tsx +1 -1
- package/lib/components/Toggle/Toggle.tsx +5 -5
- package/lib/components/Toggle/ToggleHandle.tsx +2 -3
- package/lib/components/Tooltip/Tooltip.tsx +2 -2
- package/lib/components/Tooltip/__tests__/__snapshots__/tooltip.test.tsx.snap +2 -2
- package/lib/components/UclLogoNew/UclLogo.tsx +42 -0
- package/lib/components/UclLogoNew/index.ts +2 -0
- package/lib/components/WeekPicker/WeekPicker.stories.tsx +3 -5
- package/lib/components/common/Common.mdx +0 -1
- package/lib/components/index.ts +19 -1
- package/lib/theme/Colours.mdx +1 -1
- package/lib/theme/Theme.mdx +1 -1
- package/lib/theme/Typography.mdx +1 -1
- package/lib/theme/__tests__/fonts.test.ts +37 -0
- package/lib/theme/common/themeCommon.ts +515 -0
- package/lib/theme/fonts.ts +110 -0
- package/lib/theme/index.ts +6 -6
- package/lib/theme/light/lightColour.ts +232 -0
- package/lib/theme/light/lightTheme.ts +37 -0
- package/lib/theme/{defaultTheme.ts → original/color.ts} +17 -199
- package/lib/theme/original/defaultTheme.ts +207 -0
- package/lib/theme/original/originalColourNewStructure.ts +185 -0
- package/lib/theme/useTheme.tsx +72 -15
- package/lib/types/assets.d.ts +10 -0
- package/lib/utils/addAlphaToHex.ts +29 -0
- package/lib/utils/scrollToTop.ts +5 -0
- package/package.json +11 -6
- package/dist/components/Button/buttonPrimaryStyle.d.ts +0 -4
- package/dist/components/Button/buttonSecondaryStyle.d.ts +0 -4
- package/dist/components/Button/buttonTertiaryStyle.d.ts +0 -4
- package/dist/theme/defaultTheme.d.ts +0 -274
- package/lib/components/Button/buttonPrimaryStyle.ts +0 -62
- package/lib/components/Button/buttonSecondaryStyle.ts +0 -65
- package/lib/components/Button/buttonTertiaryStyle.ts +0 -54
|
@@ -10,17 +10,18 @@ exports[`IconButton > snapshot: disabled prop 1`] = `
|
|
|
10
10
|
class="ucl-uikit-icon css-148hpxb"
|
|
11
11
|
data-testid="ucl-uikit-icon"
|
|
12
12
|
fill="none"
|
|
13
|
+
focusable="false"
|
|
13
14
|
height="24"
|
|
14
15
|
stroke="currentColor"
|
|
15
16
|
stroke-linecap="round"
|
|
16
17
|
stroke-linejoin="round"
|
|
17
|
-
stroke-width="
|
|
18
|
+
stroke-width="2"
|
|
18
19
|
viewBox="0 0 24 24"
|
|
19
20
|
width="24"
|
|
20
21
|
xmlns="http://www.w3.org/2000/svg"
|
|
21
22
|
>
|
|
22
|
-
<
|
|
23
|
-
|
|
23
|
+
<path
|
|
24
|
+
d="M20 6 9 17l-5-5"
|
|
24
25
|
/>
|
|
25
26
|
</svg>
|
|
26
27
|
</button>
|
|
@@ -35,17 +36,18 @@ exports[`IconButton > snapshot: no props 1`] = `
|
|
|
35
36
|
class="ucl-uikit-icon css-148hpxb"
|
|
36
37
|
data-testid="ucl-uikit-icon"
|
|
37
38
|
fill="none"
|
|
39
|
+
focusable="false"
|
|
38
40
|
height="24"
|
|
39
41
|
stroke="currentColor"
|
|
40
42
|
stroke-linecap="round"
|
|
41
43
|
stroke-linejoin="round"
|
|
42
|
-
stroke-width="
|
|
44
|
+
stroke-width="2"
|
|
43
45
|
viewBox="0 0 24 24"
|
|
44
46
|
width="24"
|
|
45
47
|
xmlns="http://www.w3.org/2000/svg"
|
|
46
48
|
>
|
|
47
|
-
<
|
|
48
|
-
|
|
49
|
+
<path
|
|
50
|
+
d="M20 6 9 17l-5-5"
|
|
49
51
|
/>
|
|
50
52
|
</svg>
|
|
51
53
|
</button>
|
|
@@ -60,17 +62,18 @@ exports[`IconButton > snapshot: testId prop 1`] = `
|
|
|
60
62
|
class="ucl-uikit-icon css-148hpxb"
|
|
61
63
|
data-testid="ucl-uikit-icon"
|
|
62
64
|
fill="none"
|
|
65
|
+
focusable="false"
|
|
63
66
|
height="24"
|
|
64
67
|
stroke="currentColor"
|
|
65
68
|
stroke-linecap="round"
|
|
66
69
|
stroke-linejoin="round"
|
|
67
|
-
stroke-width="
|
|
70
|
+
stroke-width="2"
|
|
68
71
|
viewBox="0 0 24 24"
|
|
69
72
|
width="24"
|
|
70
73
|
xmlns="http://www.w3.org/2000/svg"
|
|
71
74
|
>
|
|
72
|
-
<
|
|
73
|
-
|
|
75
|
+
<path
|
|
76
|
+
d="M20 6 9 17l-5-5"
|
|
74
77
|
/>
|
|
75
78
|
</svg>
|
|
76
79
|
</button>
|
|
@@ -1,84 +1,127 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ComponentPropsWithoutRef,
|
|
3
|
+
ElementType,
|
|
4
|
+
forwardRef,
|
|
5
|
+
useCallback,
|
|
6
|
+
} from 'react';
|
|
2
7
|
import { css, cx } from '@emotion/css';
|
|
3
8
|
import useTheme from '../../theme/useTheme';
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
type AnchorishProps = {
|
|
11
|
+
href?: string;
|
|
12
|
+
onClick?: React.MouseEventHandler;
|
|
13
|
+
tabIndex?: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function isAnchorProps(props: unknown): props is AnchorishProps {
|
|
17
|
+
return (
|
|
18
|
+
typeof (props as AnchorishProps).href === 'string' ||
|
|
19
|
+
'onClick' in (props as object)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type BaseLinkOwnProps = {
|
|
7
24
|
size?: 'small' | 'default';
|
|
8
25
|
noVisited?: boolean;
|
|
9
26
|
disabled?: boolean;
|
|
10
27
|
testId?: string;
|
|
11
|
-
|
|
28
|
+
className?: string;
|
|
29
|
+
children?: React.ReactNode;
|
|
30
|
+
to?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type PolymorphicRef<C extends ElementType> =
|
|
34
|
+
React.ComponentPropsWithRef<C>['ref'];
|
|
35
|
+
|
|
36
|
+
export type BaseLinkProps<C extends ElementType = 'a'> = BaseLinkOwnProps & {
|
|
37
|
+
component?: C;
|
|
38
|
+
} & Omit<
|
|
39
|
+
ComponentPropsWithoutRef<C>,
|
|
40
|
+
keyof BaseLinkOwnProps | 'component' | 'disabled'
|
|
41
|
+
>;
|
|
12
42
|
|
|
13
43
|
const NAME = 'ucl-uikit-base-link';
|
|
14
44
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
45
|
+
type BaseLinkComponent = <C extends ElementType = 'a'>(
|
|
46
|
+
props: BaseLinkProps<C> & { ref?: PolymorphicRef<C> }
|
|
47
|
+
) => React.JSX.Element;
|
|
48
|
+
|
|
49
|
+
const BaseLink = forwardRef(function BaseLinkInner(
|
|
50
|
+
{
|
|
51
|
+
testId = NAME,
|
|
52
|
+
className,
|
|
53
|
+
children,
|
|
54
|
+
size = 'default',
|
|
55
|
+
disabled = false,
|
|
56
|
+
component,
|
|
57
|
+
to,
|
|
58
|
+
...props
|
|
59
|
+
}: BaseLinkProps<ElementType>,
|
|
60
|
+
ref: React.Ref<Element>
|
|
61
|
+
) {
|
|
62
|
+
const [theme] = useTheme();
|
|
63
|
+
const Component = (component || 'a') as ElementType;
|
|
64
|
+
const anchorProps = isAnchorProps(props) ? props : {};
|
|
65
|
+
const { href, onClick, ...rest } = anchorProps;
|
|
66
|
+
|
|
67
|
+
const isAnchor = Component === 'a';
|
|
68
|
+
|
|
69
|
+
const disabledHandleClick = useCallback(
|
|
70
|
+
(ev: React.MouseEvent<HTMLAnchorElement>) => {
|
|
71
|
+
ev.preventDefault();
|
|
72
|
+
ev.stopPropagation();
|
|
73
|
+
return false;
|
|
25
74
|
},
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
>
|
|
78
|
-
{children}
|
|
79
|
-
</Component>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
);
|
|
75
|
+
[]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const baseStyle = css`
|
|
79
|
+
font-family: ${theme.font.family.primary};
|
|
80
|
+
font-size: ${theme.font.size.f16};
|
|
81
|
+
|
|
82
|
+
&:focus-visible {
|
|
83
|
+
outline: none;
|
|
84
|
+
box-shadow: ${theme.boxShadow.focus};
|
|
85
|
+
}
|
|
86
|
+
`;
|
|
87
|
+
|
|
88
|
+
const smallStyle = css`
|
|
89
|
+
font-size: ${theme.font.size.f14};
|
|
90
|
+
`;
|
|
91
|
+
|
|
92
|
+
const disabledStyle = css`
|
|
93
|
+
cursor: not-allowed;
|
|
94
|
+
color: ${theme.colour.link.disabled};
|
|
95
|
+
pointer-events: none;
|
|
96
|
+
|
|
97
|
+
&:hover {
|
|
98
|
+
color: ${theme.colour.link.disabled};
|
|
99
|
+
}
|
|
100
|
+
`;
|
|
101
|
+
|
|
102
|
+
const style = cx(
|
|
103
|
+
NAME,
|
|
104
|
+
baseStyle,
|
|
105
|
+
size === 'small' && smallStyle,
|
|
106
|
+
disabled && disabledStyle,
|
|
107
|
+
className
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
return (
|
|
111
|
+
<Component
|
|
112
|
+
ref={ref}
|
|
113
|
+
className={style}
|
|
114
|
+
data-testid={testId}
|
|
115
|
+
aria-disabled={disabled || undefined}
|
|
116
|
+
tabIndex={disabled ? -1 : props.tabIndex}
|
|
117
|
+
href={isAnchor ? (disabled ? undefined : (href ?? to)) : undefined}
|
|
118
|
+
onClick={disabled ? disabledHandleClick : onClick}
|
|
119
|
+
{...(isAnchor ? {} : to ? { to } : href ? { href } : {})}
|
|
120
|
+
{...rest}
|
|
121
|
+
>
|
|
122
|
+
{children}
|
|
123
|
+
</Component>
|
|
124
|
+
);
|
|
125
|
+
}) as unknown as BaseLinkComponent;
|
|
83
126
|
|
|
84
127
|
export default BaseLink;
|
|
@@ -1,126 +1,137 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, {
|
|
2
|
+
ComponentPropsWithoutRef,
|
|
3
|
+
ElementType,
|
|
4
|
+
forwardRef,
|
|
5
|
+
} from 'react';
|
|
2
6
|
import { css, cx } from '@emotion/css';
|
|
3
7
|
import useTheme from '../../theme/useTheme';
|
|
4
8
|
import BaseLink, { BaseLinkProps } from './BaseLink';
|
|
5
9
|
|
|
6
|
-
|
|
10
|
+
type LinkOwnProps = {
|
|
7
11
|
variant?: 'primary' | 'secondary';
|
|
8
|
-
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type LinkProps<C extends ElementType = 'a'> = LinkOwnProps &
|
|
15
|
+
BaseLinkProps<C> &
|
|
16
|
+
Omit<ComponentPropsWithoutRef<C>, keyof LinkOwnProps>;
|
|
9
17
|
|
|
10
18
|
const NAME = 'ucl-uikit-link';
|
|
11
19
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
20
|
+
type LinkComponent = <C extends ElementType = 'a'>(
|
|
21
|
+
props: LinkProps<C> & { ref?: React.ComponentPropsWithRef<C>['ref'] }
|
|
22
|
+
) => React.JSX.Element;
|
|
23
|
+
|
|
24
|
+
const Link = forwardRef(function LinkInner(
|
|
25
|
+
{
|
|
26
|
+
noVisited = false,
|
|
27
|
+
variant = 'primary',
|
|
28
|
+
disabled = false,
|
|
29
|
+
testId = NAME,
|
|
30
|
+
className,
|
|
31
|
+
children,
|
|
32
|
+
...props
|
|
33
|
+
}: LinkProps<ElementType>,
|
|
34
|
+
ref: React.Ref<Element>
|
|
35
|
+
) {
|
|
36
|
+
const [theme] = useTheme();
|
|
37
|
+
|
|
38
|
+
const baseStyle = css`
|
|
39
|
+
text-decoration-skip-ink: none;
|
|
40
|
+
text-decoration-thickness: 10%;
|
|
41
|
+
text-underline-offset: 25%;
|
|
42
|
+
text-underline-position: from-font;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const primaryStyle = css`
|
|
46
|
+
color: ${theme.colour.link.default};
|
|
47
|
+
&:active {
|
|
48
|
+
color: ${theme.colour.link.brandHover};
|
|
49
|
+
}
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
// todo: deprecate secondary
|
|
53
|
+
const secondaryStyle = css`
|
|
54
|
+
color: ${theme.color.link.secondaryDefault};
|
|
55
|
+
|
|
56
|
+
&:active {
|
|
57
|
+
color: ${theme.color.link.secondaryHover};
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
const visitedStyle = css`
|
|
62
|
+
&:visited {
|
|
63
|
+
color: ${theme.colour.link.visited};
|
|
64
|
+
}
|
|
65
|
+
`;
|
|
66
|
+
|
|
67
|
+
const primaryNoVisitedStyle = css`
|
|
68
|
+
&:visited {
|
|
69
|
+
color: ${theme.colour.link.default};
|
|
70
|
+
}
|
|
71
|
+
`;
|
|
72
|
+
|
|
73
|
+
const secondaryNoVisitedStyle = css`
|
|
74
|
+
&:visited {
|
|
42
75
|
color: ${theme.color.link.secondaryDefault};
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
43
78
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
`;
|
|
48
|
-
|
|
49
|
-
const visitedStyle = css`
|
|
50
|
-
&:visited {
|
|
51
|
-
color: ${theme.color.link.visited};
|
|
52
|
-
}
|
|
53
|
-
`;
|
|
54
|
-
|
|
55
|
-
const primaryNoVisitedStyle = css`
|
|
56
|
-
&:visited {
|
|
57
|
-
color: ${theme.color.link.default};
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
const secondaryNoVisitedStyle = css`
|
|
62
|
-
&:visited {
|
|
63
|
-
color: ${theme.color.link.secondaryDefault};
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
|
|
67
|
-
const primaryHoverStyle = css`
|
|
68
|
-
&:hover {
|
|
69
|
-
color: ${theme.color.link.hover};
|
|
70
|
-
}
|
|
71
|
-
`;
|
|
72
|
-
|
|
73
|
-
const secondaryHoverStyle = css`
|
|
74
|
-
&:hover {
|
|
75
|
-
color: ${theme.color.link.secondaryHover};
|
|
76
|
-
}
|
|
77
|
-
`;
|
|
78
|
-
|
|
79
|
-
const disabledStyle = css`
|
|
80
|
-
cursor: not-allowed;
|
|
81
|
-
color: ${theme.color.link.disabled};
|
|
82
|
-
|
|
83
|
-
&:hover {
|
|
84
|
-
color: ${theme.color.link.disabled};
|
|
85
|
-
}
|
|
86
|
-
`;
|
|
87
|
-
|
|
88
|
-
let variantStyle = undefined;
|
|
89
|
-
if (variant === 'primary') {
|
|
90
|
-
variantStyle = cx(
|
|
91
|
-
primaryStyle,
|
|
92
|
-
noVisited && !disabled && primaryNoVisitedStyle,
|
|
93
|
-
!disabled && primaryHoverStyle
|
|
94
|
-
);
|
|
95
|
-
} else if (variant === 'secondary') {
|
|
96
|
-
variantStyle = cx(
|
|
97
|
-
secondaryStyle,
|
|
98
|
-
noVisited && !disabled && secondaryNoVisitedStyle,
|
|
99
|
-
!disabled && secondaryHoverStyle
|
|
100
|
-
);
|
|
79
|
+
const primaryHoverStyle = css`
|
|
80
|
+
&:hover {
|
|
81
|
+
color: ${theme.colour.link.brandHover};
|
|
101
82
|
}
|
|
83
|
+
`;
|
|
102
84
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
disabled && disabledStyle,
|
|
109
|
-
className
|
|
110
|
-
);
|
|
85
|
+
const secondaryHoverStyle = css`
|
|
86
|
+
&:hover {
|
|
87
|
+
color: ${theme.color.link.secondaryHover};
|
|
88
|
+
}
|
|
89
|
+
`;
|
|
111
90
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
91
|
+
const disabledStyle = css`
|
|
92
|
+
cursor: not-allowed;
|
|
93
|
+
color: ${theme.colour.link.disabled};
|
|
94
|
+
|
|
95
|
+
&:hover {
|
|
96
|
+
color: ${theme.colour.link.disabled};
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
|
|
100
|
+
let variantStyle: string | undefined = undefined;
|
|
101
|
+
if (variant === 'primary') {
|
|
102
|
+
variantStyle = cx(
|
|
103
|
+
primaryStyle,
|
|
104
|
+
noVisited && !disabled && primaryNoVisitedStyle,
|
|
105
|
+
!disabled && primaryHoverStyle
|
|
106
|
+
);
|
|
107
|
+
} else if (variant === 'secondary') {
|
|
108
|
+
variantStyle = cx(
|
|
109
|
+
secondaryStyle,
|
|
110
|
+
noVisited && !disabled && secondaryNoVisitedStyle,
|
|
111
|
+
!disabled && secondaryHoverStyle
|
|
122
112
|
);
|
|
123
113
|
}
|
|
124
|
-
|
|
114
|
+
|
|
115
|
+
const style = cx(
|
|
116
|
+
NAME,
|
|
117
|
+
baseStyle,
|
|
118
|
+
variantStyle,
|
|
119
|
+
!noVisited && !disabled && visitedStyle,
|
|
120
|
+
disabled && disabledStyle,
|
|
121
|
+
className
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<BaseLink
|
|
126
|
+
ref={ref}
|
|
127
|
+
className={style}
|
|
128
|
+
testId={testId}
|
|
129
|
+
disabled={disabled}
|
|
130
|
+
{...props}
|
|
131
|
+
>
|
|
132
|
+
{children}
|
|
133
|
+
</BaseLink>
|
|
134
|
+
);
|
|
135
|
+
}) as unknown as LinkComponent;
|
|
125
136
|
|
|
126
137
|
export default Link;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports[`Link > snapshot: no props 1`] = `
|
|
4
4
|
<a
|
|
5
|
-
class="ucl-uikit-base-link ucl-uikit-link css-
|
|
5
|
+
class="ucl-uikit-base-link ucl-uikit-link css-x04ks2"
|
|
6
6
|
data-testid="ucl-uikit-link"
|
|
7
7
|
>
|
|
8
8
|
test
|
|
@@ -11,7 +11,7 @@ exports[`Link > snapshot: no props 1`] = `
|
|
|
11
11
|
|
|
12
12
|
exports[`Link > snapshot: testId prop 1`] = `
|
|
13
13
|
<a
|
|
14
|
-
class="ucl-uikit-base-link ucl-uikit-link css-
|
|
14
|
+
class="ucl-uikit-base-link ucl-uikit-link css-x04ks2"
|
|
15
15
|
data-testid="test123"
|
|
16
16
|
>
|
|
17
17
|
testidlink
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useState,
|
|
5
|
+
useRef,
|
|
6
|
+
useEffect,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import useMediaQuery from '../../hooks/useMediaQuery';
|
|
9
|
+
import { useTheme } from '../../theme';
|
|
10
|
+
|
|
11
|
+
interface IContext {
|
|
12
|
+
isOpen: boolean;
|
|
13
|
+
toggleMenu: () => void;
|
|
14
|
+
triggerRef: React.RefObject<HTMLButtonElement | null>;
|
|
15
|
+
contentRef: React.RefObject<HTMLDivElement | null>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const AppMenuContext = createContext({} as IContext);
|
|
19
|
+
|
|
20
|
+
export const useAppMenu = () => useContext(AppMenuContext);
|
|
21
|
+
|
|
22
|
+
const MenuProvider = ({
|
|
23
|
+
defaultOpen = false,
|
|
24
|
+
children,
|
|
25
|
+
}: {
|
|
26
|
+
defaultOpen?: boolean;
|
|
27
|
+
children: React.ReactNode;
|
|
28
|
+
}) => {
|
|
29
|
+
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
30
|
+
const [theme] = useTheme();
|
|
31
|
+
const isDesktop = useMediaQuery(
|
|
32
|
+
`(min-width: ${theme.breakpoints.desktop}px)`
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const triggerRef = useRef<HTMLButtonElement>(null);
|
|
36
|
+
const contentRef = useRef<HTMLDivElement>(null);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const originalStyle = document.body.style.overflow;
|
|
40
|
+
if (isOpen && !isDesktop) {
|
|
41
|
+
// Prevent background scrolling when menu is open and on mobile
|
|
42
|
+
document.body.style.overflow = 'hidden';
|
|
43
|
+
} else {
|
|
44
|
+
document.body.style.overflow = originalStyle;
|
|
45
|
+
}
|
|
46
|
+
return () => {
|
|
47
|
+
document.body.style.overflow = originalStyle;
|
|
48
|
+
};
|
|
49
|
+
}, [isOpen, isDesktop]);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
const closeMenuOutsideClick = (event: MouseEvent) => {
|
|
53
|
+
if (
|
|
54
|
+
triggerRef.current &&
|
|
55
|
+
!triggerRef.current.contains(event.target as Node) &&
|
|
56
|
+
contentRef.current &&
|
|
57
|
+
!contentRef.current.contains(event.target as Node)
|
|
58
|
+
) {
|
|
59
|
+
setIsOpen(false);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
64
|
+
if (event.key === 'Escape') {
|
|
65
|
+
setIsOpen(false);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!isOpen || !contentRef.current) return;
|
|
69
|
+
|
|
70
|
+
const focusableElements = Array.from(
|
|
71
|
+
contentRef.current.querySelectorAll(
|
|
72
|
+
'[role="menuitem"], [aria-label="Close menu"]'
|
|
73
|
+
)
|
|
74
|
+
).filter((el) => {
|
|
75
|
+
const element = el as HTMLElement;
|
|
76
|
+
return (
|
|
77
|
+
element.getAttribute('aria-disabled') !== 'true' &&
|
|
78
|
+
element.tabIndex >= 0 &&
|
|
79
|
+
element.offsetParent !== null
|
|
80
|
+
);
|
|
81
|
+
}) as HTMLElement[];
|
|
82
|
+
|
|
83
|
+
if (focusableElements.length === 0) return;
|
|
84
|
+
|
|
85
|
+
const firstElement = focusableElements[0];
|
|
86
|
+
const lastElement = focusableElements[focusableElements.length - 1];
|
|
87
|
+
|
|
88
|
+
const currentIndex = focusableElements.indexOf(
|
|
89
|
+
document.activeElement as HTMLElement
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
if (event.key === 'Tab') {
|
|
93
|
+
// Loop focus on Tab/Shift+Tab
|
|
94
|
+
if (event.shiftKey && document.activeElement === firstElement) {
|
|
95
|
+
lastElement.focus();
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
} else if (!event.shiftKey && document.activeElement === lastElement) {
|
|
98
|
+
firstElement.focus();
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
}
|
|
101
|
+
} else if (event.key === 'ArrowDown') {
|
|
102
|
+
// Move focus to next item
|
|
103
|
+
if (currentIndex !== -1) {
|
|
104
|
+
const nextIndex = (currentIndex + 1) % focusableElements.length;
|
|
105
|
+
focusableElements[nextIndex].focus();
|
|
106
|
+
event.preventDefault();
|
|
107
|
+
} else {
|
|
108
|
+
firstElement.focus();
|
|
109
|
+
event.preventDefault();
|
|
110
|
+
}
|
|
111
|
+
} else if (event.key === 'ArrowUp') {
|
|
112
|
+
// Move focus to previous item
|
|
113
|
+
if (currentIndex !== -1) {
|
|
114
|
+
const prevIndex =
|
|
115
|
+
(currentIndex - 1 + focusableElements.length) %
|
|
116
|
+
focusableElements.length;
|
|
117
|
+
focusableElements[prevIndex].focus();
|
|
118
|
+
event.preventDefault();
|
|
119
|
+
} else {
|
|
120
|
+
lastElement.focus();
|
|
121
|
+
event.preventDefault();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
document.addEventListener('mousedown', closeMenuOutsideClick);
|
|
127
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
128
|
+
|
|
129
|
+
return () => {
|
|
130
|
+
document.removeEventListener('mousedown', closeMenuOutsideClick);
|
|
131
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
132
|
+
};
|
|
133
|
+
}, [isOpen]);
|
|
134
|
+
|
|
135
|
+
const toggleMenu = () => setIsOpen((prevOpen) => !prevOpen);
|
|
136
|
+
|
|
137
|
+
const value = {
|
|
138
|
+
isOpen,
|
|
139
|
+
toggleMenu,
|
|
140
|
+
triggerRef,
|
|
141
|
+
contentRef,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<AppMenuContext.Provider value={value}>{children}</AppMenuContext.Provider>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default MenuProvider;
|