uikit-react-public 0.11.24 → 0.17.4
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 +4 -2
- package/dist/components/Accordion/Accordion.Heading.d.ts +4 -4
- package/dist/components/Accordion/Accordion.Panel.d.ts +2 -2
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Accordion/Accordion.stories.d.ts +57 -0
- package/dist/components/Accordion/index.d.ts +2 -0
- package/dist/components/Avatar/Avatar.stories.d.ts +107 -1
- package/dist/components/Badge/Badge.d.ts +6 -0
- package/dist/components/Badge/Badge.stories.d.ts +15 -0
- package/dist/components/Badge/index.d.ts +2 -0
- package/dist/components/Button/Button.d.ts +3 -1
- package/dist/components/Calendar/index.d.ts +1 -1
- package/dist/components/CookieNotice/CookieNotice.d.ts +16 -0
- package/dist/components/CookieNotice/index.d.ts +2 -0
- package/dist/components/Datepicker/Datepicker.d.ts +1 -1
- package/dist/components/Datepicker/Datepicker.stories.d.ts +4 -3
- package/dist/components/Datepicker/Datepicker.types.d.ts +4 -5
- package/dist/components/Datepicker/subcomponents/CustomDatepicker.d.ts +4 -1
- package/dist/components/Datepicker/subcomponents/DatepickerInput.d.ts +15 -2
- package/dist/components/Datepicker/subcomponents/Panel.d.ts +1 -1
- package/dist/components/Datepicker/subcomponents/VisibleField.d.ts +6 -1
- package/dist/components/Datepicker/subcomponents/index.d.ts +0 -1
- package/dist/components/Datepicker/utils/index.d.ts +0 -1
- package/dist/components/Dialog/BaseDialog.d.ts +8 -2
- package/dist/components/Dialog/Dialog.d.ts +2 -0
- package/dist/components/FileInput/FileInput.d.ts +8 -0
- package/dist/components/FileInput/FileInput.stories.d.ts +16 -0
- package/dist/components/FileInput/index.d.ts +2 -0
- package/dist/components/Header/Header.d.ts +7 -1
- package/dist/components/Header/Header.stories.d.ts +40 -0
- package/dist/components/Heading/Heading.d.ts +1 -1
- package/dist/components/Link/BaseLink.d.ts +10 -0
- package/dist/components/Link/Link.d.ts +5 -10
- package/dist/components/Link/Link.stories.d.ts +1 -1
- package/dist/components/Link/index.d.ts +1 -1
- package/dist/components/Main/Main.d.ts +21 -0
- package/dist/components/Main/Main.stories.d.ts +15 -0
- package/dist/components/Main/__tests__/Main.test.d.ts +1 -0
- package/dist/components/Main/index.d.ts +2 -0
- package/dist/components/Menu/MenuContent.d.ts +1 -1
- package/dist/components/Menu/MenuItem.d.ts +2 -0
- package/dist/components/Menu/MenuSection.d.ts +1 -1
- package/dist/components/NativeDatepicker/NativeDatepicker.d.ts +3 -0
- package/dist/components/NativeDatepicker/NativeDatepicker.stories.d.ts +36 -0
- package/dist/components/NativeDatepicker/NativeDatepicker.types.d.ts +10 -0
- package/dist/components/NativeDatepicker/index.d.ts +2 -0
- package/dist/components/{Datepicker → NativeDatepicker}/utils/dateToLocaleISOString/dateToLocaleISOString.d.ts +1 -1
- package/dist/components/NativeDatepicker/utils/dateToLocaleISOString/dateToLocaleISOString.test.d.ts +1 -0
- package/dist/components/NativeDatepicker/utils/index.d.ts +1 -0
- package/dist/components/Search/Search.d.ts +16 -0
- package/dist/components/Search/Search.stories.d.ts +34 -0
- package/dist/components/Search/__tests__/Search.test.d.ts +1 -0
- package/dist/components/Search/index.d.ts +2 -0
- package/dist/components/Select/Select.d.ts +1 -1
- package/dist/components/Select/Select.stories.d.ts +157 -9
- package/dist/components/Select/Select.types.d.ts +66 -32
- package/dist/components/Select/subcomponents/CustomOption.d.ts +1 -1
- package/dist/components/Select/subcomponents/CustomSelect.d.ts +3 -3
- package/dist/components/Select/subcomponents/FilterInput.d.ts +14 -0
- package/dist/components/Select/subcomponents/NativeSelect.d.ts +5 -1
- package/dist/components/Select/subcomponents/Panel.d.ts +1 -1
- package/dist/components/Select/subcomponents/VisibleField.d.ts +6 -4
- package/dist/components/Select/subcomponents/index.d.ts +1 -0
- package/dist/components/StandaloneLink/StandaloneLink.d.ts +12 -0
- package/dist/components/StandaloneLink/StandaloneLink.stories.d.ts +13 -0
- package/dist/components/StandaloneLink/__tests__/StandaloneLink.test.d.ts +1 -0
- package/dist/components/StandaloneLink/index.d.ts +2 -0
- package/dist/components/Table/Table.d.ts +10 -8
- package/dist/components/Table/Table.stories.d.ts +21 -0
- package/dist/components/Table/Table.types.d.ts +11 -0
- package/dist/components/Table/__tests__/Table.test.d.ts +1 -0
- package/dist/components/Table/index.d.ts +2 -1
- package/dist/components/Table/subcomponents/Body.d.ts +4 -0
- package/dist/components/Table/subcomponents/Cell/Cell.d.ts +12 -0
- package/dist/components/Table/subcomponents/Cell/Cell.stories.d.ts +313 -0
- package/dist/components/Table/subcomponents/Cell/CellContent.d.ts +10 -0
- package/dist/components/Table/subcomponents/Cell/__tests__/Cell.test.d.ts +1 -0
- package/dist/components/Table/subcomponents/Head.d.ts +4 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.d.ts +13 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.stories.d.ts +312 -0
- package/dist/components/Table/subcomponents/HeadCell/HeadCellContent.d.ts +10 -0
- package/dist/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.d.ts +1 -0
- package/dist/components/Table/subcomponents/Row.d.ts +5 -0
- package/dist/components/Table/subcomponents/SortIcon.d.ts +7 -0
- package/dist/components/Table/subcomponents/index.d.ts +10 -0
- package/dist/components/Tabs/Tab.d.ts +1 -1
- package/dist/components/Tabs/TabContext.d.ts +1 -0
- package/dist/components/Tabs/Tabs.d.ts +3 -1
- package/dist/components/Tabs/Tabs.stories.d.ts +3 -0
- package/dist/components/Timepicker/Timepicker.d.ts +10 -0
- package/dist/components/Timepicker/Timepicker.stories.d.ts +7 -0
- package/dist/components/Timepicker/__tests__/Timepicker.test.d.ts +1 -0
- package/dist/components/Timepicker/index.d.ts +2 -0
- package/dist/components/Timepicker/utils/convertDateToTimeString.d.ts +2 -0
- package/dist/components/Timepicker/utils/convertDateToTimeString.test.d.ts +1 -0
- package/dist/components/Timepicker/utils/index.d.ts +1 -0
- package/dist/components/WeekPicker/WeekPicker.d.ts +3 -0
- package/dist/components/WeekPicker/WeekPicker.stories.d.ts +41 -0
- package/dist/components/WeekPicker/WeekPicker.types.d.ts +16 -0
- package/dist/components/WeekPicker/index.d.ts +2 -0
- package/dist/components/WeekPicker/subcomponents/CustomDatepicker.d.ts +17 -0
- package/dist/components/WeekPicker/subcomponents/DatepickerInput.d.ts +13 -0
- package/dist/components/WeekPicker/subcomponents/VisibleField.d.ts +15 -0
- package/dist/components/WeekPicker/subcomponents/index.d.ts +3 -0
- package/dist/components/index.d.ts +19 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useFocusTrap.d.ts +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +6460 -4607
- package/dist/theme/defaultTheme.d.ts +7 -0
- package/dist/theme/useTheme.d.ts +14 -0
- package/dist/utils/__tests__/announce.test.d.ts +1 -0
- package/dist/utils/__tests__/capitalise.test.d.ts +1 -0
- package/dist/utils/announce.d.ts +6 -0
- package/dist/utils/capitalise.d.ts +2 -0
- package/dist/utils/index.d.ts +1 -0
- package/lib/components/Accordion/Accordion.Heading.tsx +27 -8
- package/lib/components/Accordion/Accordion.Panel.tsx +11 -3
- package/lib/components/Accordion/Accordion.stories.tsx +139 -0
- package/lib/components/Accordion/Accordion.tsx +10 -8
- package/lib/components/Accordion/__tests__/__snapshots__/Accordion.test.tsx.snap +7 -7
- package/lib/components/Accordion/index.ts +2 -0
- package/lib/components/Alert/Alert.stories.tsx +1 -1
- package/lib/components/Alert/Alert.tsx +7 -1
- package/lib/components/Alert/__tests__/__snapshots__/Alert.test.tsx.snap +4 -0
- package/lib/components/Avatar/Avatar.mdx +117 -0
- package/lib/components/Avatar/Avatar.stories.tsx +110 -2
- package/lib/components/Badge/Badge.stories.tsx +19 -0
- package/lib/components/Badge/Badge.tsx +48 -0
- package/lib/components/Badge/index.ts +2 -0
- package/lib/components/Blanket/Blanket.stories.tsx +1 -1
- package/lib/components/Breadcrumbs/__tests__/__snapshots__/Breadcrumbs.test.tsx.snap +4 -4
- package/lib/components/Button/Button.stories.tsx +1 -1
- package/lib/components/Button/Button.tsx +6 -2
- package/lib/components/Calendar/Calendar.stories.tsx +12 -32
- package/lib/components/Calendar/__tests__/Calendar.test.tsx +23 -15
- package/lib/components/Calendar/index.ts +1 -5
- package/lib/components/Calendar/subcomponents/AcademicWeeks.tsx +2 -1
- package/lib/components/Calendar/subcomponents/ColumnHeading.tsx +5 -1
- package/lib/components/Calendar/subcomponents/EventDot.tsx +2 -1
- package/lib/components/Calendar/subcomponents/Grid.tsx +0 -1
- package/lib/components/Calendar/subcomponents/index.ts +1 -1
- package/lib/components/Calendar/utils/getDatesForCalendarGrid/getDatesForCalendarGrid.ts +43 -11
- package/lib/components/Calendar/utils/normaliseMonth/normaliseMonth.test.ts +5 -5
- package/lib/components/CookieNotice/CookieNotice.tsx +114 -0
- package/lib/components/CookieNotice/index.ts +2 -0
- package/lib/components/Datepicker/Datepicker.lld.md +108 -0
- package/lib/components/Datepicker/Datepicker.stories.tsx +44 -5
- package/lib/components/Datepicker/Datepicker.tsx +14 -36
- package/lib/components/Datepicker/Datepicker.types.ts +5 -14
- package/lib/components/Datepicker/__tests__/Datepicker.test.tsx +150 -8
- package/lib/components/Datepicker/__tests__/__snapshots__/Datepicker.test.tsx.snap +10 -4
- package/lib/components/Datepicker/subcomponents/CustomDatepicker.tsx +39 -5
- package/lib/components/Datepicker/subcomponents/DatepickerInput.tsx +30 -17
- package/lib/components/Datepicker/subcomponents/Panel.tsx +6 -2
- package/lib/components/Datepicker/subcomponents/VisibleField.tsx +40 -3
- package/lib/components/Datepicker/subcomponents/index.ts +0 -1
- package/lib/components/Datepicker/utils/index.ts +0 -1
- package/lib/components/Dialog/BaseDialog.tsx +55 -4
- package/lib/components/Dialog/Dialog.tsx +8 -1
- package/lib/components/Dialog/DialogBody.tsx +5 -1
- package/lib/components/Dialog/DialogHeader.tsx +2 -1
- package/lib/components/Divider/Divider.stories.tsx +1 -1
- package/lib/components/Field/ErrorText.tsx +1 -0
- package/lib/components/Field/Field.stories.tsx +1 -1
- package/lib/components/Field/__tests__/Field.test.tsx +161 -148
- package/lib/components/FileInput/FileInput.stories.tsx +70 -0
- package/lib/components/FileInput/FileInput.tsx +68 -0
- package/lib/components/FileInput/__tests__/FileInput.test.tsx +99 -0
- package/lib/components/FileInput/__tests__/__snapshots__/FileInput.test.tsx.snap +91 -0
- package/lib/components/FileInput/index.ts +2 -0
- package/lib/components/Footer/Footer.stories.tsx +1 -1
- package/lib/components/Footer/__tests__/__snapshots__/Footer.test.tsx.snap +28 -28
- package/lib/components/Header/Header.mdx +52 -0
- package/lib/components/Header/Header.stories.tsx +98 -0
- package/lib/components/Header/Header.tsx +65 -3
- package/lib/components/Header/__tests__/Header.test.tsx +17 -1
- package/lib/components/Header/__tests__/__snapshots__/Header.test.tsx.snap +4 -4
- package/lib/components/Heading/Documentation.mdx +1 -1
- package/lib/components/Heading/Heading.stories.tsx +1 -1
- package/lib/components/Heading/Heading.tsx +1 -1
- package/lib/components/Heading/__tests__/Heading.test.tsx +7 -19
- package/lib/components/Heading/__tests__/__snapshots__/Heading.test.tsx.snap +7 -7
- package/lib/components/Icon/Icon.stories.tsx +1 -1
- package/lib/components/IconButton/IconButton.stories.tsx +1 -1
- package/lib/components/Input/Input.stories.tsx +1 -1
- package/lib/components/Label/Label.stories.tsx +1 -1
- package/lib/components/Label/Label.tsx +0 -2
- package/lib/components/Label/__tests__/__snapshots__/Label.test.tsx.snap +7 -7
- package/lib/components/Link/BaseLink.tsx +84 -0
- package/lib/components/Link/Link.tsx +72 -32
- package/lib/components/Link/__tests__/__snapshots__/link.test.tsx.snap +3 -3
- package/lib/components/Link/__tests__/link.test.tsx +6 -13
- package/lib/components/Link/index.ts +1 -1
- package/lib/components/Main/Main.stories.tsx +36 -0
- package/lib/components/Main/Main.tsx +46 -0
- package/lib/components/Main/__tests__/Main.test.tsx +80 -0
- package/lib/components/Main/__tests__/__snapshots__/Main.test.tsx.snap +33 -0
- package/lib/components/Main/index.ts +2 -0
- package/lib/components/Menu/Menu.context.tsx +3 -1
- package/lib/components/Menu/Menu.tsx +2 -2
- package/lib/components/Menu/MenuContent.tsx +5 -5
- package/lib/components/Menu/MenuItem.tsx +20 -3
- package/lib/components/Menu/MenuSection.tsx +4 -3
- package/lib/components/NativeDatepicker/NativeDatepicker.stories.tsx +100 -0
- package/lib/components/{Datepicker/subcomponents → NativeDatepicker}/NativeDatepicker.tsx +14 -15
- package/lib/components/NativeDatepicker/NativeDatepicker.types.ts +19 -0
- package/lib/components/NativeDatepicker/index.ts +2 -0
- package/lib/components/{Datepicker → NativeDatepicker}/utils/dateToLocaleISOString/dateToLocaleISOString.ts +1 -1
- package/lib/components/NativeDatepicker/utils/index.ts +1 -0
- package/lib/components/Pagination/PaginationControls.tsx +56 -15
- package/lib/components/Pagination/PaginationInfo.tsx +5 -1
- package/lib/components/Paragraph/Paragraph.stories.tsx +1 -1
- package/lib/components/Search/Search.stories.tsx +41 -0
- package/lib/components/Search/Search.tsx +170 -0
- package/lib/components/Search/__tests__/Search.test.tsx +112 -0
- package/lib/components/Search/__tests__/__snapshots__/Search.test.tsx.snap +179 -0
- package/lib/components/Search/index.ts +2 -0
- package/lib/components/Select/Select.mdx +169 -0
- package/lib/components/Select/Select.stories.tsx +198 -77
- package/lib/components/Select/Select.tsx +37 -13
- package/lib/components/Select/Select.types.ts +77 -54
- package/lib/components/Select/__tests__/Select.test.tsx +448 -7
- package/lib/components/Select/__tests__/__snapshots__/Select.test.tsx.snap +3 -3
- package/lib/components/Select/subcomponents/CustomOption.tsx +24 -10
- package/lib/components/Select/subcomponents/CustomSelect.tsx +333 -52
- package/lib/components/Select/subcomponents/FilterInput.tsx +80 -0
- package/lib/components/Select/subcomponents/NativeSelect.tsx +13 -1
- package/lib/components/Select/subcomponents/Panel.tsx +4 -5
- package/lib/components/Select/subcomponents/VisibleField.tsx +36 -24
- package/lib/components/Select/subcomponents/index.tsx +1 -0
- package/lib/components/Snackbar/Snackbar.stories.tsx +1 -1
- package/lib/components/Spinner/Spinner.stories.tsx +1 -1
- package/lib/components/StandaloneLink/StandaloneLink.stories.tsx +32 -0
- package/lib/components/StandaloneLink/StandaloneLink.tsx +183 -0
- package/lib/components/StandaloneLink/__tests__/StandaloneLink.test.tsx +57 -0
- package/lib/components/StandaloneLink/__tests__/__snapshots__/StandaloneLink.test.tsx.snap +19 -0
- package/lib/components/StandaloneLink/index.ts +2 -0
- package/lib/components/Table/Table.stories.tsx +337 -0
- package/lib/components/Table/Table.tsx +42 -67
- package/lib/components/Table/Table.types.ts +14 -0
- package/lib/components/Table/__tests__/Table.test.tsx +121 -0
- package/lib/components/Table/__tests__/__snapshots__/Table.test.tsx.snap +210 -0
- package/lib/components/Table/index.ts +8 -1
- package/lib/components/Table/subcomponents/Body.tsx +18 -0
- package/lib/components/Table/subcomponents/Cell/Cell.stories.tsx +151 -0
- package/lib/components/Table/subcomponents/Cell/Cell.tsx +72 -0
- package/lib/components/Table/subcomponents/Cell/CellContent.tsx +91 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/Cell.test.tsx +115 -0
- package/lib/components/Table/subcomponents/Cell/__tests__/__snapshots__/Cell.test.tsx.snap +107 -0
- package/lib/components/Table/subcomponents/Head.tsx +34 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.stories.tsx +85 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.tsx +99 -0
- package/lib/components/Table/subcomponents/HeadCell/HeadCellContent.tsx +61 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/HeadCell.test.tsx +137 -0
- package/lib/components/Table/subcomponents/HeadCell/__tests__/__snapshots__/HeadCell.test.tsx.snap +110 -0
- package/lib/components/Table/subcomponents/Row.tsx +49 -0
- package/lib/components/Table/subcomponents/SortIcon.tsx +63 -0
- package/lib/components/Table/subcomponents/index.ts +14 -0
- package/lib/components/Tabs/Tab.tsx +3 -3
- package/lib/components/Tabs/TabContext.tsx +1 -0
- package/lib/components/Tabs/Tabs.stories.tsx +9 -3
- package/lib/components/Tabs/Tabs.tsx +10 -32
- package/lib/components/Tabs/__tests__/Tabs.test.tsx +10 -4
- package/lib/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +32 -32
- package/lib/components/Textarea/Textarea.stories.tsx +1 -1
- package/lib/components/Timepicker/Timepicker.stories.tsx +43 -0
- package/lib/components/Timepicker/Timepicker.tsx +100 -0
- package/lib/components/Timepicker/__tests__/Timepicker.test.tsx +55 -0
- package/lib/components/Timepicker/__tests__/__snapshots__/Timepicker.test.tsx.snap +19 -0
- package/lib/components/Timepicker/index.tsx +2 -0
- package/lib/components/Timepicker/utils/convertDateToTimeString.test.ts +54 -0
- package/lib/components/Timepicker/utils/convertDateToTimeString.ts +10 -0
- package/lib/components/Timepicker/utils/index.ts +1 -0
- package/lib/components/Toggle/Toggle.stories.tsx +1 -1
- package/lib/components/Tooltip/Tooltip.stories.tsx +1 -1
- package/lib/components/WeekPicker/WeekPicker.stories.tsx +147 -0
- package/lib/components/WeekPicker/WeekPicker.tsx +26 -0
- package/lib/components/WeekPicker/WeekPicker.types.ts +21 -0
- package/lib/components/WeekPicker/index.ts +2 -0
- package/lib/components/WeekPicker/subcomponents/CustomDatepicker.tsx +298 -0
- package/lib/components/WeekPicker/subcomponents/DatepickerInput.tsx +111 -0
- package/lib/components/WeekPicker/subcomponents/VisibleField.tsx +126 -0
- package/lib/components/WeekPicker/subcomponents/index.ts +3 -0
- package/lib/components/common/Common.mdx +1 -1
- package/lib/components/index.ts +28 -2
- package/lib/hooks/index.ts +2 -0
- package/lib/hooks/useFocusTrap.ts +159 -0
- package/lib/index.ts +2 -0
- package/lib/theme/defaultTheme.ts +7 -0
- package/lib/utils/__tests__/announce.test.ts +121 -0
- package/lib/utils/__tests__/capitalise.test.ts +40 -0
- package/lib/utils/announce.ts +134 -0
- package/lib/utils/capitalise.ts +4 -0
- package/lib/utils/index.ts +1 -0
- package/package.json +3 -6
- package/dist/components/Datepicker/subcomponents/NativeDatepicker.d.ts +0 -6
- package/lib/components/Accordion/Accordion.stories.tsx.NOT_READY +0 -93
- package/lib/components/Field/__tests__/__snapshots__/Field.test.tsx.snap +0 -300
- /package/dist/components/{Datepicker/utils/dateToLocaleISOString/dateToLocaleISOString.test.d.ts → FileInput/__tests__/FileInput.test.d.ts} +0 -0
- /package/lib/components/{Datepicker → NativeDatepicker}/utils/dateToLocaleISOString/dateToLocaleISOString.test.ts +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
1
|
+
import { createContext, useId } from 'react';
|
|
2
2
|
import { css, cx } from '@emotion/css';
|
|
3
3
|
import useTheme from '../../theme/useTheme';
|
|
4
4
|
import BaseDialog, { BaseDialogProps } from './BaseDialog';
|
|
@@ -9,6 +9,8 @@ import DialogFooter from './DialogFooter';
|
|
|
9
9
|
export const NAME = 'ucl-uikit-dialog';
|
|
10
10
|
|
|
11
11
|
interface DialogContextValue {
|
|
12
|
+
dialogHeaderId?: string;
|
|
13
|
+
dialogBodyId?: string;
|
|
12
14
|
onClose?: (ev: React.MouseEvent) => void;
|
|
13
15
|
onSecondaryAction?: () => void;
|
|
14
16
|
onAction?: () => void;
|
|
@@ -31,8 +33,12 @@ const Dialog = ({
|
|
|
31
33
|
...props
|
|
32
34
|
}: DialogProps) => {
|
|
33
35
|
const [theme] = useTheme();
|
|
36
|
+
const dialogHeaderId = useId();
|
|
37
|
+
const dialogBodyId = useId();
|
|
34
38
|
|
|
35
39
|
const contextValue: DialogContextValue = {
|
|
40
|
+
dialogHeaderId,
|
|
41
|
+
dialogBodyId,
|
|
36
42
|
onClose,
|
|
37
43
|
onAction,
|
|
38
44
|
onSecondaryAction,
|
|
@@ -50,6 +56,7 @@ const Dialog = ({
|
|
|
50
56
|
onClose={onClose}
|
|
51
57
|
testId={testId}
|
|
52
58
|
className={style}
|
|
59
|
+
skipCloseOnInitialFocus={true}
|
|
53
60
|
{...props}
|
|
54
61
|
>
|
|
55
62
|
{children}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { memo, HTMLAttributes } from 'react';
|
|
1
|
+
import { memo, HTMLAttributes, useContext } from 'react';
|
|
2
2
|
import { css, cx } from '@emotion/css';
|
|
3
3
|
import useTheme from '../../theme/useTheme';
|
|
4
|
+
import { DialogContext } from './Dialog';
|
|
4
5
|
|
|
5
6
|
export const NAME = 'ucl-uikit-dialog__body';
|
|
6
7
|
|
|
@@ -15,6 +16,8 @@ const DialogBody = ({
|
|
|
15
16
|
}: DialogBodyProps) => {
|
|
16
17
|
const [theme] = useTheme();
|
|
17
18
|
|
|
19
|
+
const { dialogBodyId } = useContext(DialogContext);
|
|
20
|
+
|
|
18
21
|
const contentStyle = css`
|
|
19
22
|
margin: ${theme.padding.p24} ${theme.padding.p32};
|
|
20
23
|
`;
|
|
@@ -23,6 +26,7 @@ const DialogBody = ({
|
|
|
23
26
|
|
|
24
27
|
return (
|
|
25
28
|
<div
|
|
29
|
+
id={dialogBodyId}
|
|
26
30
|
className={style}
|
|
27
31
|
data-testid={testId}
|
|
28
32
|
role='document'
|
|
@@ -23,7 +23,7 @@ const DialogHeader = ({
|
|
|
23
23
|
testId = NAME,
|
|
24
24
|
className,
|
|
25
25
|
}: DialogHeaderProps) => {
|
|
26
|
-
const { onClose } = useContext(DialogContext);
|
|
26
|
+
const { onClose, dialogHeaderId } = useContext(DialogContext);
|
|
27
27
|
|
|
28
28
|
const [theme] = useTheme();
|
|
29
29
|
|
|
@@ -73,6 +73,7 @@ const DialogHeader = ({
|
|
|
73
73
|
level={3}
|
|
74
74
|
margins={false}
|
|
75
75
|
{...headingProps}
|
|
76
|
+
id={dialogHeaderId}
|
|
76
77
|
>
|
|
77
78
|
{children}
|
|
78
79
|
</Heading>
|
|
@@ -9,7 +9,7 @@ import Input from '../Input/Input';
|
|
|
9
9
|
import Textarea from '../Textarea/Textarea';
|
|
10
10
|
|
|
11
11
|
const meta = {
|
|
12
|
-
title: 'Components/
|
|
12
|
+
title: 'Components/Field',
|
|
13
13
|
component: Field,
|
|
14
14
|
parameters: { layout: 'padded' },
|
|
15
15
|
} satisfies Meta<typeof Field>;
|
|
@@ -9,154 +9,154 @@ import { ThemeContextProvider } from '../../../theme/useTheme';
|
|
|
9
9
|
describe('Field', () => {
|
|
10
10
|
// Snapshot tests
|
|
11
11
|
|
|
12
|
-
test('Snapshot: Default (no children)', () => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('Snapshot: Field.HelperText alone', () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('Snapshot: Field.ErrorText alone', () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('Snapshot: With Label, Input', () => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
test('Snapshot: With Label, HelperText, ErrorText, Input', () => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test('Snapshot: With Label, HelperText, ErrorText, Input, & prop disabled', () => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('Snapshot: With Label, HelperText, ErrorText, Input, & prop error', () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
test('Snapshot: With Label, HelperText, ErrorText, Input, & prop optional', () => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
test('Snapshot: With Label, Textarea', () => {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
test('Snapshot: With Label, HelperText, ErrorText, Textarea', () => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('Snapshot: With Label, HelperText, ErrorText, Textarea, & prop disabled', () => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('Snapshot: With Textarea & prop maxChar', () => {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
});
|
|
12
|
+
// test('Snapshot: Default (no children)', () => {
|
|
13
|
+
// const renderResult = render(
|
|
14
|
+
// <ThemeContextProvider>
|
|
15
|
+
// <Field />
|
|
16
|
+
// </ThemeContextProvider>
|
|
17
|
+
// );
|
|
18
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
19
|
+
// });
|
|
20
|
+
|
|
21
|
+
// test('Snapshot: Field.HelperText alone', () => {
|
|
22
|
+
// const renderResult = render(
|
|
23
|
+
// <ThemeContextProvider>
|
|
24
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
25
|
+
// </ThemeContextProvider>
|
|
26
|
+
// );
|
|
27
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
28
|
+
// });
|
|
29
|
+
|
|
30
|
+
// test('Snapshot: Field.ErrorText alone', () => {
|
|
31
|
+
// const renderResult = render(
|
|
32
|
+
// <ThemeContextProvider>
|
|
33
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
34
|
+
// </ThemeContextProvider>
|
|
35
|
+
// );
|
|
36
|
+
// // Expected behaviour here is to return `null`
|
|
37
|
+
// // unless <Field> provides `error` via context
|
|
38
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
39
|
+
// });
|
|
40
|
+
|
|
41
|
+
// test('Snapshot: With Label, Input', () => {
|
|
42
|
+
// const renderResult = render(
|
|
43
|
+
// <ThemeContextProvider>
|
|
44
|
+
// <Field>
|
|
45
|
+
// <Label>Name</Label>
|
|
46
|
+
// <Input />
|
|
47
|
+
// </Field>
|
|
48
|
+
// </ThemeContextProvider>
|
|
49
|
+
// );
|
|
50
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
51
|
+
// });
|
|
52
|
+
|
|
53
|
+
// test('Snapshot: With Label, HelperText, ErrorText, Input', () => {
|
|
54
|
+
// const renderResult = render(
|
|
55
|
+
// <ThemeContextProvider>
|
|
56
|
+
// <Field>
|
|
57
|
+
// <Label>Name</Label>
|
|
58
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
59
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
60
|
+
// <Input />
|
|
61
|
+
// </Field>
|
|
62
|
+
// </ThemeContextProvider>
|
|
63
|
+
// );
|
|
64
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
65
|
+
// });
|
|
66
|
+
|
|
67
|
+
// test('Snapshot: With Label, HelperText, ErrorText, Input, & prop disabled', () => {
|
|
68
|
+
// const renderResult = render(
|
|
69
|
+
// <ThemeContextProvider>
|
|
70
|
+
// <Field disabled>
|
|
71
|
+
// <Label>Name</Label>
|
|
72
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
73
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
74
|
+
// <Input />
|
|
75
|
+
// </Field>
|
|
76
|
+
// </ThemeContextProvider>
|
|
77
|
+
// );
|
|
78
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
79
|
+
// });
|
|
80
|
+
|
|
81
|
+
// test('Snapshot: With Label, HelperText, ErrorText, Input, & prop error', () => {
|
|
82
|
+
// const renderResult = render(
|
|
83
|
+
// <ThemeContextProvider>
|
|
84
|
+
// <Field error>
|
|
85
|
+
// <Label>Name</Label>
|
|
86
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
87
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
88
|
+
// <Input />
|
|
89
|
+
// </Field>
|
|
90
|
+
// </ThemeContextProvider>
|
|
91
|
+
// );
|
|
92
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
93
|
+
// });
|
|
94
|
+
|
|
95
|
+
// test('Snapshot: With Label, HelperText, ErrorText, Input, & prop optional', () => {
|
|
96
|
+
// const renderResult = render(
|
|
97
|
+
// <ThemeContextProvider>
|
|
98
|
+
// <Field optional>
|
|
99
|
+
// <Label>Name</Label>
|
|
100
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
101
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
102
|
+
// <Input />
|
|
103
|
+
// </Field>
|
|
104
|
+
// </ThemeContextProvider>
|
|
105
|
+
// );
|
|
106
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
107
|
+
// });
|
|
108
|
+
|
|
109
|
+
// test('Snapshot: With Label, Textarea', () => {
|
|
110
|
+
// const renderResult = render(
|
|
111
|
+
// <ThemeContextProvider>
|
|
112
|
+
// <Field>
|
|
113
|
+
// <Label>Name</Label>
|
|
114
|
+
// <Textarea />
|
|
115
|
+
// </Field>
|
|
116
|
+
// </ThemeContextProvider>
|
|
117
|
+
// );
|
|
118
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
119
|
+
// });
|
|
120
|
+
|
|
121
|
+
// test('Snapshot: With Label, HelperText, ErrorText, Textarea', () => {
|
|
122
|
+
// const renderResult = render(
|
|
123
|
+
// <ThemeContextProvider>
|
|
124
|
+
// <Field>
|
|
125
|
+
// <Label>Name</Label>
|
|
126
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
127
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
128
|
+
// <Textarea />
|
|
129
|
+
// </Field>
|
|
130
|
+
// </ThemeContextProvider>
|
|
131
|
+
// );
|
|
132
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
133
|
+
// });
|
|
134
|
+
|
|
135
|
+
// test('Snapshot: With Label, HelperText, ErrorText, Textarea, & prop disabled', () => {
|
|
136
|
+
// const renderResult = render(
|
|
137
|
+
// <ThemeContextProvider>
|
|
138
|
+
// <Field disabled>
|
|
139
|
+
// <Label>Name</Label>
|
|
140
|
+
// <Field.HelperText>Helper text</Field.HelperText>
|
|
141
|
+
// <Field.ErrorText>Error text</Field.ErrorText>
|
|
142
|
+
// <Textarea />
|
|
143
|
+
// </Field>
|
|
144
|
+
// </ThemeContextProvider>
|
|
145
|
+
// );
|
|
146
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
147
|
+
// });
|
|
148
|
+
|
|
149
|
+
// test('Snapshot: With Textarea & prop maxChar', () => {
|
|
150
|
+
// const renderResult = render(
|
|
151
|
+
// <ThemeContextProvider>
|
|
152
|
+
// <Field>
|
|
153
|
+
// <Textarea />
|
|
154
|
+
// <Field.CharacterCount maxChars={100} />
|
|
155
|
+
// </Field>
|
|
156
|
+
// </ThemeContextProvider>
|
|
157
|
+
// );
|
|
158
|
+
// expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
159
|
+
// });
|
|
160
160
|
|
|
161
161
|
// Interation tests
|
|
162
162
|
|
|
@@ -507,4 +507,17 @@ describe('Field', () => {
|
|
|
507
507
|
expect(label2).not.toHaveAttribute('for', idForField2);
|
|
508
508
|
expect(textarea1).not.toHaveAttribute('id', idForField1);
|
|
509
509
|
});
|
|
510
|
+
|
|
511
|
+
test('Field.ErrorText has role alert', () => {
|
|
512
|
+
const testId = 'error-text-01';
|
|
513
|
+
render(
|
|
514
|
+
<ThemeContextProvider>
|
|
515
|
+
<Field error>
|
|
516
|
+
<Field.ErrorText testId={testId}> Error text </Field.ErrorText>
|
|
517
|
+
</Field>
|
|
518
|
+
</ThemeContextProvider>
|
|
519
|
+
);
|
|
520
|
+
const errorText = screen.getByTestId(testId);
|
|
521
|
+
expect(errorText).toHaveAttribute('role', 'alert');
|
|
522
|
+
});
|
|
510
523
|
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
import FileInput from './FileInput';
|
|
3
|
+
|
|
4
|
+
const meta = {
|
|
5
|
+
title: 'Components/Work in progress/FileInput',
|
|
6
|
+
component: FileInput,
|
|
7
|
+
parameters: {
|
|
8
|
+
layout: 'centered',
|
|
9
|
+
},
|
|
10
|
+
tags: ['autodocs'],
|
|
11
|
+
} satisfies Meta<typeof FileInput>;
|
|
12
|
+
|
|
13
|
+
export default meta;
|
|
14
|
+
type Story = StoryObj<typeof meta>;
|
|
15
|
+
|
|
16
|
+
export const Default: Story = {
|
|
17
|
+
args: {
|
|
18
|
+
children: 'Upload file or images',
|
|
19
|
+
testId: 'file-input-default',
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const WithCustomClass: Story = {
|
|
24
|
+
args: {
|
|
25
|
+
children: 'Custom Styled File Input',
|
|
26
|
+
className: 'custom-class',
|
|
27
|
+
testId: 'file-input-custom',
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const MultipleFiles: Story = {
|
|
32
|
+
args: {
|
|
33
|
+
children: 'Upload multiple files',
|
|
34
|
+
testId: 'file-input-multiple',
|
|
35
|
+
multiple: true,
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const NoChildren: Story = {
|
|
40
|
+
args: {
|
|
41
|
+
testId: 'file-input-no-children',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export const WithDecorator: Story = {
|
|
46
|
+
name: 'FileInput with decorator',
|
|
47
|
+
args: {
|
|
48
|
+
children: 'FileInput with a decorator',
|
|
49
|
+
testId: 'file-input-decorator',
|
|
50
|
+
},
|
|
51
|
+
decorators: [
|
|
52
|
+
(Story) => (
|
|
53
|
+
<div>
|
|
54
|
+
<div
|
|
55
|
+
style={{
|
|
56
|
+
height: '16px',
|
|
57
|
+
backgroundColor: '#0d68cf',
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
60
|
+
<Story />
|
|
61
|
+
<div
|
|
62
|
+
style={{
|
|
63
|
+
height: '16px',
|
|
64
|
+
backgroundColor: '#0d68cf',
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
68
|
+
),
|
|
69
|
+
],
|
|
70
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { css, cx } from '@emotion/css';
|
|
2
|
+
import { useTheme } from '../../theme';
|
|
3
|
+
import { InputHTMLAttributes } from 'react';
|
|
4
|
+
import { Icon } from '..';
|
|
5
|
+
import { useRef } from 'react';
|
|
6
|
+
|
|
7
|
+
export const NAME = 'ucl-uikit-fileinput';
|
|
8
|
+
|
|
9
|
+
export interface FileInputProps extends InputHTMLAttributes<HTMLInputElement> {
|
|
10
|
+
testId?: string;
|
|
11
|
+
labelId?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const FileInput = ({
|
|
15
|
+
testId = NAME,
|
|
16
|
+
children,
|
|
17
|
+
labelId = '1',
|
|
18
|
+
...props
|
|
19
|
+
}: FileInputProps) => {
|
|
20
|
+
const [theme] = useTheme();
|
|
21
|
+
const fileInputRef = useRef<HTMLInputElement>(null);
|
|
22
|
+
|
|
23
|
+
const baseStyle = css`
|
|
24
|
+
font-size: ${theme.font.size.f16};
|
|
25
|
+
font-family: ${theme.font.family.primary};
|
|
26
|
+
color: ${theme.color.link.default};
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
const hiddenInputContainerStyle = css`
|
|
30
|
+
opacity: 0;
|
|
31
|
+
width: 0;
|
|
32
|
+
height: 0;
|
|
33
|
+
position: absolute;
|
|
34
|
+
`;
|
|
35
|
+
|
|
36
|
+
const labelStyle = css`
|
|
37
|
+
display: inline-flex;
|
|
38
|
+
text-decoration: underline;
|
|
39
|
+
gap: 6px;
|
|
40
|
+
font-weight: 700;
|
|
41
|
+
margin-top: 3px;
|
|
42
|
+
cursor: pointer;
|
|
43
|
+
`;
|
|
44
|
+
|
|
45
|
+
const style = cx(NAME, baseStyle, props.className);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div className={style}>
|
|
49
|
+
<label
|
|
50
|
+
htmlFor={`file-input-${labelId}`}
|
|
51
|
+
className={labelStyle}
|
|
52
|
+
>
|
|
53
|
+
<Icon.Upload />
|
|
54
|
+
{children}
|
|
55
|
+
</label>
|
|
56
|
+
<input
|
|
57
|
+
ref={fileInputRef}
|
|
58
|
+
type='file'
|
|
59
|
+
data-testid={testId}
|
|
60
|
+
className={hiddenInputContainerStyle}
|
|
61
|
+
id={`file-input-${labelId}`}
|
|
62
|
+
{...props}
|
|
63
|
+
/>
|
|
64
|
+
</div>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export default FileInput;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import userEvent from '@testing-library/user-event';
|
|
4
|
+
import FileInput from '../';
|
|
5
|
+
import { ThemeContextProvider } from '../../../theme/useTheme';
|
|
6
|
+
|
|
7
|
+
describe('Input', () => {
|
|
8
|
+
// Snapshot tests
|
|
9
|
+
|
|
10
|
+
test('snapshot: no props', () => {
|
|
11
|
+
const renderResult = render(
|
|
12
|
+
<ThemeContextProvider>
|
|
13
|
+
<FileInput>Upload File</FileInput>
|
|
14
|
+
</ThemeContextProvider>
|
|
15
|
+
);
|
|
16
|
+
expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('snapshot: value prop', () => {
|
|
20
|
+
const renderResult = render(
|
|
21
|
+
<ThemeContextProvider>
|
|
22
|
+
<FileInput testId='test123'>Upload File/Image</FileInput>
|
|
23
|
+
</ThemeContextProvider>
|
|
24
|
+
);
|
|
25
|
+
expect(renderResult.container.firstChild).toMatchSnapshot();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('test ID: default', () => {
|
|
29
|
+
render(
|
|
30
|
+
<ThemeContextProvider>
|
|
31
|
+
<FileInput>Upload File/Image</FileInput>
|
|
32
|
+
</ThemeContextProvider>
|
|
33
|
+
);
|
|
34
|
+
const fileInput = screen.getByTestId('ucl-uikit-fileinput');
|
|
35
|
+
expect(fileInput).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('test ID: default with mutliple attribute', () => {
|
|
39
|
+
render(
|
|
40
|
+
<ThemeContextProvider>
|
|
41
|
+
<FileInput multiple={true}>Upload File/Image</FileInput>
|
|
42
|
+
</ThemeContextProvider>
|
|
43
|
+
);
|
|
44
|
+
const fileInput = screen.getByTestId('ucl-uikit-fileinput');
|
|
45
|
+
expect(fileInput).toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('test ID: custom', () => {
|
|
49
|
+
render(
|
|
50
|
+
<ThemeContextProvider>
|
|
51
|
+
<FileInput testId='custom-test-id'>Upload File/Image</FileInput>
|
|
52
|
+
</ThemeContextProvider>
|
|
53
|
+
);
|
|
54
|
+
const fileInput = screen.getByTestId('custom-test-id');
|
|
55
|
+
expect(fileInput).toBeDefined();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('snapshot: id prop', () => {
|
|
59
|
+
render(
|
|
60
|
+
<ThemeContextProvider>
|
|
61
|
+
<FileInput id='custom-id'>Upload File/Image</FileInput>
|
|
62
|
+
</ThemeContextProvider>
|
|
63
|
+
);
|
|
64
|
+
const fileInput = screen.getByTestId('ucl-uikit-fileinput');
|
|
65
|
+
expect(fileInput.id).toBe('custom-id');
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('updates file list on file selection', async () => {
|
|
69
|
+
const user = userEvent.setup();
|
|
70
|
+
render(
|
|
71
|
+
<ThemeContextProvider>
|
|
72
|
+
<FileInput>Upload File</FileInput>
|
|
73
|
+
</ThemeContextProvider>
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const fileInput = screen.getByTestId(
|
|
77
|
+
'ucl-uikit-fileinput'
|
|
78
|
+
) as HTMLInputElement;
|
|
79
|
+
const file = new File(['file content'], 'example.txt', {
|
|
80
|
+
type: 'text/plain',
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
await user.upload(fileInput, file);
|
|
84
|
+
|
|
85
|
+
expect(fileInput.files).toHaveLength(1);
|
|
86
|
+
expect(fileInput.files?.[0].name).toBe('example.txt');
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('applies custom className', () => {
|
|
90
|
+
render(
|
|
91
|
+
<ThemeContextProvider>
|
|
92
|
+
<FileInput className='custom-class'>Upload File</FileInput>
|
|
93
|
+
</ThemeContextProvider>
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
const fileInput = screen.getByTestId('ucl-uikit-fileinput');
|
|
97
|
+
expect(fileInput).toHaveClass('custom-class');
|
|
98
|
+
});
|
|
99
|
+
});
|