@codezee/sixtify-brahma 0.0.0
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/.github/workflows/check-build.yml +41 -0
- package/.github/workflows/deploy-on-npm.yml +43 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +6 -0
- package/.lintstagedrc +5 -0
- package/.prettierignore +12 -0
- package/.prettierrc +22 -0
- package/.vscode/extensions.json +22 -0
- package/.vscode/settings.json +17 -0
- package/README.md +90 -0
- package/apps/docs/.eslintrc.cjs +9 -0
- package/apps/docs/.storybook/main.ts +23 -0
- package/apps/docs/.storybook/manager.ts +6 -0
- package/apps/docs/.storybook/preview.tsx +27 -0
- package/apps/docs/.storybook/theme.ts +8 -0
- package/apps/docs/next-env.d.ts +5 -0
- package/apps/docs/next.config.mjs +4 -0
- package/apps/docs/package.json +43 -0
- package/apps/docs/public/globals.css +26 -0
- package/apps/docs/stories/Actions/Actions.stories.tsx +49 -0
- package/apps/docs/stories/AgGrid/AgGrid.stories.tsx +70 -0
- package/apps/docs/stories/AppBar/AppBar.stories.tsx +39 -0
- package/apps/docs/stories/Breadcrumbs/Breadcrumbs.stories.tsx +37 -0
- package/apps/docs/stories/Button/ButtonGroup.stories.tsx +120 -0
- package/apps/docs/stories/Button/button.stories.tsx +99 -0
- package/apps/docs/stories/Card/AttendanceCard.stories.tsx +36 -0
- package/apps/docs/stories/Card/Card.stories.tsx +39 -0
- package/apps/docs/stories/Charts/PieChart.stories.tsx +265 -0
- package/apps/docs/stories/Chips/Chip.stories.tsx +141 -0
- package/apps/docs/stories/Chips/ChipWithBorder.stories.tsx +18 -0
- package/apps/docs/stories/Chips/FilterPill.stories.tsx +24 -0
- package/apps/docs/stories/Color/Color.stories.tsx +14 -0
- package/apps/docs/stories/Dialog/ButtomDialog.stories.tsx +48 -0
- package/apps/docs/stories/Dialog/DeleteDialog.stories.tsx +32 -0
- package/apps/docs/stories/Dialog/Dialog.stories.tsx +48 -0
- package/apps/docs/stories/Drawer/Drawer.stories.tsx +94 -0
- package/apps/docs/stories/FilterList/FilterList.stories.tsx +88 -0
- package/apps/docs/stories/FilterList/FilterListV2.stories.tsx +92 -0
- package/apps/docs/stories/FormFields/AutoComplete.stories.tsx +90 -0
- package/apps/docs/stories/FormFields/CheckBox.stories.tsx +64 -0
- package/apps/docs/stories/FormFields/DatePicker.stories.tsx +100 -0
- package/apps/docs/stories/FormFields/DateRangePicker.stories.tsx +39 -0
- package/apps/docs/stories/FormFields/DateTimePicker.stories.tsx +39 -0
- package/apps/docs/stories/FormFields/FileUpload.stories.tsx +83 -0
- package/apps/docs/stories/FormFields/ImageUpload.stories.tsx +69 -0
- package/apps/docs/stories/FormFields/ListItemButton.stories.tsx +59 -0
- package/apps/docs/stories/FormFields/PhoneInputField.stories.tsx +84 -0
- package/apps/docs/stories/FormFields/RadioGroupField.stories.tsx +172 -0
- package/apps/docs/stories/FormFields/SearchField.stories.tsx +74 -0
- package/apps/docs/stories/FormFields/TextField.stories.tsx +141 -0
- package/apps/docs/stories/FormFields/TimeField.stories.tsx +84 -0
- package/apps/docs/stories/FormFields/TimePicker.stories.tsx +84 -0
- package/apps/docs/stories/Indicator/Indicator.stories.tsx +33 -0
- package/apps/docs/stories/Indicator/SeverityIndicator.stories.tsx +27 -0
- package/apps/docs/stories/Layouts/FormRow.stories.tsx +45 -0
- package/apps/docs/stories/PadBox/PadBox.stories.tsx +49 -0
- package/apps/docs/stories/Stepper/Stepper.stories.tsx +110 -0
- package/apps/docs/stories/Stepper/StepperV2.stories.tsx +44 -0
- package/apps/docs/stories/Timeline/AttendanceStatus.stories.tsx +29 -0
- package/apps/docs/stories/Timeline/Timeline.stories.tsx +38 -0
- package/apps/docs/stories/Tooltip/Tooltip.stories.tsx +28 -0
- package/apps/docs/stories/UserProfileMenu/UserProfileMenu.stories.tsx +112 -0
- package/apps/docs/tsconfig.json +19 -0
- package/commitlint.config.cjs +6 -0
- package/index.ts +1 -0
- package/package.json +85 -0
- package/packages/eslint-config/README.md +3 -0
- package/packages/eslint-config/library.js +88 -0
- package/packages/eslint-config/next.js +85 -0
- package/packages/eslint-config/package.json +19 -0
- package/packages/eslint-config/react-internal.js +89 -0
- package/packages/shared-components/.eslintrc.js +10 -0
- package/packages/shared-components/package.json +51 -0
- package/packages/shared-components/src/Actions/AddAction.tsx +16 -0
- package/packages/shared-components/src/Actions/CalendarAction.tsx +16 -0
- package/packages/shared-components/src/Actions/ConfigureAction.tsx +16 -0
- package/packages/shared-components/src/Actions/DeleteAction.tsx +16 -0
- package/packages/shared-components/src/Actions/DownloadAction.tsx +16 -0
- package/packages/shared-components/src/Actions/EditAction.tsx +16 -0
- package/packages/shared-components/src/Actions/ExportAction.tsx +16 -0
- package/packages/shared-components/src/Actions/FilterAction.tsx +16 -0
- package/packages/shared-components/src/Actions/HistoryAction.tsx +16 -0
- package/packages/shared-components/src/Actions/ImportAction.tsx +16 -0
- package/packages/shared-components/src/Actions/ViewAction.tsx +16 -0
- package/packages/shared-components/src/Actions/index.ts +11 -0
- package/packages/shared-components/src/AgGrid/ActionCell/ActionCell.tsx +57 -0
- package/packages/shared-components/src/AgGrid/ActionCell/Popover.tsx +32 -0
- package/packages/shared-components/src/AgGrid/AgGrid.tsx +93 -0
- package/packages/shared-components/src/AgGrid/LoadingCell.tsx +5 -0
- package/packages/shared-components/src/AgGrid/index.ts +3 -0
- package/packages/shared-components/src/AppBar/AppBar.styled.tsx +33 -0
- package/packages/shared-components/src/AppBar/AppBar.tsx +20 -0
- package/packages/shared-components/src/AppBar/index.ts +1 -0
- package/packages/shared-components/src/Breadcrumbs/Breadcrumbs.tsx +76 -0
- package/packages/shared-components/src/Breadcrumbs/index.ts +1 -0
- package/packages/shared-components/src/Button/ActionButton.tsx +38 -0
- package/packages/shared-components/src/Button/Button.tsx +19 -0
- package/packages/shared-components/src/Button/ButtonGroup.tsx +37 -0
- package/packages/shared-components/src/Button/index.ts +3 -0
- package/packages/shared-components/src/Card/AttendanceCard.tsx +51 -0
- package/packages/shared-components/src/Card/Card.tsx +34 -0
- package/packages/shared-components/src/Card/CardItem/CardItem.tsx +33 -0
- package/packages/shared-components/src/Card/CardItem/CardItemValue.tsx +98 -0
- package/packages/shared-components/src/Card/CardItem/index.ts +2 -0
- package/packages/shared-components/src/Card/ProfileCard/ProfileCard.tsx +40 -0
- package/packages/shared-components/src/Card/ProfileCard/ProfileCardItem/ProfileCardBody.tsx +53 -0
- package/packages/shared-components/src/Card/ProfileCard/ProfileCardItem/ProfileCardHeader.tsx +94 -0
- package/packages/shared-components/src/Card/index.ts +6 -0
- package/packages/shared-components/src/Charts/PieChart.tsx +81 -0
- package/packages/shared-components/src/Charts/Skeleton.tsx +36 -0
- package/packages/shared-components/src/Charts/index.ts +1 -0
- package/packages/shared-components/src/Chips/Chip.tsx +26 -0
- package/packages/shared-components/src/Chips/ChipWithBorder.tsx +39 -0
- package/packages/shared-components/src/Chips/FilterPill.tsx +47 -0
- package/packages/shared-components/src/Chips/index.ts +3 -0
- package/packages/shared-components/src/Dialog/BottomDialog.styled.tsx +28 -0
- package/packages/shared-components/src/Dialog/BottomDialog.tsx +37 -0
- package/packages/shared-components/src/Dialog/DeleteDialog.tsx +48 -0
- package/packages/shared-components/src/Dialog/Dialog.tsx +61 -0
- package/packages/shared-components/src/Dialog/index.ts +3 -0
- package/packages/shared-components/src/Drawer/Bullet.tsx +12 -0
- package/packages/shared-components/src/Drawer/CloseDrawer/CloseDrawerMenuItem.tsx +57 -0
- package/packages/shared-components/src/Drawer/CloseDrawer/CloseDrawerMenuItemList.tsx +109 -0
- package/packages/shared-components/src/Drawer/CloseDrawer/CloseDrawerSubMenuItemList.tsx +128 -0
- package/packages/shared-components/src/Drawer/CloseDrawer/Popover.tsx +45 -0
- package/packages/shared-components/src/Drawer/CloseDrawer/Popper.tsx +43 -0
- package/packages/shared-components/src/Drawer/Drawer.styled.tsx +63 -0
- package/packages/shared-components/src/Drawer/Drawer.tsx +56 -0
- package/packages/shared-components/src/Drawer/MenuItem.tsx +75 -0
- package/packages/shared-components/src/Drawer/OpenDrawer/OpenDrawerCollapse.tsx +13 -0
- package/packages/shared-components/src/Drawer/OpenDrawer/OpenDrawerMenuItem.tsx +48 -0
- package/packages/shared-components/src/Drawer/OpenDrawer/OpenDrawerMenuItemList.tsx +232 -0
- package/packages/shared-components/src/Drawer/index.ts +1 -0
- package/packages/shared-components/src/FilterList/DateRangePickerPopUp.tsx +123 -0
- package/packages/shared-components/src/FilterList/FilterList.tsx +180 -0
- package/packages/shared-components/src/FilterList/FilterListV2.tsx +661 -0
- package/packages/shared-components/src/FilterList/FilterPopup.tsx +165 -0
- package/packages/shared-components/src/FilterList/FilterPopupWrapper.tsx +110 -0
- package/packages/shared-components/src/FilterList/FilterTypeWrapper.tsx +60 -0
- package/packages/shared-components/src/FilterList/GetFilterPopupComponent.tsx +76 -0
- package/packages/shared-components/src/FilterList/getFormData.ts +29 -0
- package/packages/shared-components/src/FilterList/index.ts +6 -0
- package/packages/shared-components/src/FormFields/Autocomplete/Autocomplete.tsx +509 -0
- package/packages/shared-components/src/FormFields/Autocomplete/Skeleton.tsx +26 -0
- package/packages/shared-components/src/FormFields/Autocomplete/index.ts +1 -0
- package/packages/shared-components/src/FormFields/CheckBox/CheckBox.styled.tsx +76 -0
- package/packages/shared-components/src/FormFields/CheckBox/CheckBox.tsx +44 -0
- package/packages/shared-components/src/FormFields/CheckBox/Skeleton.tsx +12 -0
- package/packages/shared-components/src/FormFields/CheckBox/index.ts +1 -0
- package/packages/shared-components/src/FormFields/DatePicker/DatePicker.tsx +217 -0
- package/packages/shared-components/src/FormFields/DatePicker/Skeleton.tsx +28 -0
- package/packages/shared-components/src/FormFields/DatePicker/index.ts +1 -0
- package/packages/shared-components/src/FormFields/DateRangePicker/DateRangePicker.tsx +97 -0
- package/packages/shared-components/src/FormFields/DateRangePicker/Skeleton.tsx +38 -0
- package/packages/shared-components/src/FormFields/DateRangePicker/index.ts +1 -0
- package/packages/shared-components/src/FormFields/DateTimePicker/DateTimePicker.tsx +253 -0
- package/packages/shared-components/src/FormFields/DateTimePicker/Skeleton.tsx +24 -0
- package/packages/shared-components/src/FormFields/DateTimePicker/index.ts +1 -0
- package/packages/shared-components/src/FormFields/FileUpload/FileNames.tsx +32 -0
- package/packages/shared-components/src/FormFields/FileUpload/FileUpload.styled.tsx +31 -0
- package/packages/shared-components/src/FormFields/FileUpload/FileUpload.tsx +160 -0
- package/packages/shared-components/src/FormFields/FileUpload/Skeleton.tsx +21 -0
- package/packages/shared-components/src/FormFields/FileUpload/index.ts +2 -0
- package/packages/shared-components/src/FormFields/ImageUpload/ImageUpload.styled.tsx +20 -0
- package/packages/shared-components/src/FormFields/ImageUpload/ImageUpload.tsx +181 -0
- package/packages/shared-components/src/FormFields/ImageUpload/ImageUploadView.tsx +65 -0
- package/packages/shared-components/src/FormFields/ImageUpload/PhotoCaptureDialog.tsx +74 -0
- package/packages/shared-components/src/FormFields/ImageUpload/Skeleton.tsx +31 -0
- package/packages/shared-components/src/FormFields/ImageUpload/index.ts +2 -0
- package/packages/shared-components/src/FormFields/ListItemButton/ListItemButton.styled.tsx +25 -0
- package/packages/shared-components/src/FormFields/ListItemButton/ListItemButton.tsx +52 -0
- package/packages/shared-components/src/FormFields/ListItemButton/index.ts +1 -0
- package/packages/shared-components/src/FormFields/PasswordField/PasswordField.tsx +50 -0
- package/packages/shared-components/src/FormFields/PasswordField/index.ts +1 -0
- package/packages/shared-components/src/FormFields/PhoneInputField/PhoneInputField.tsx +108 -0
- package/packages/shared-components/src/FormFields/PhoneInputField/Skeleton.tsx +31 -0
- package/packages/shared-components/src/FormFields/PhoneInputField/index.ts +1 -0
- package/packages/shared-components/src/FormFields/RadioGroupField/RadioGroupField.tsx +105 -0
- package/packages/shared-components/src/FormFields/RadioGroupField/Skeleton.tsx +26 -0
- package/packages/shared-components/src/FormFields/RadioGroupField/index.ts +1 -0
- package/packages/shared-components/src/FormFields/SearchField/SearchField.tsx +21 -0
- package/packages/shared-components/src/FormFields/SearchField/index.ts +1 -0
- package/packages/shared-components/src/FormFields/Switch/Skeleton.tsx +12 -0
- package/packages/shared-components/src/FormFields/Switch/Switch.tsx +33 -0
- package/packages/shared-components/src/FormFields/Switch/index.ts +1 -0
- package/packages/shared-components/src/FormFields/TextField/Skeleton.tsx +31 -0
- package/packages/shared-components/src/FormFields/TextField/TextField.tsx +167 -0
- package/packages/shared-components/src/FormFields/TextField/index.ts +1 -0
- package/packages/shared-components/src/FormFields/TimeField/Skeleton.tsx +24 -0
- package/packages/shared-components/src/FormFields/TimeField/TimeField.tsx +120 -0
- package/packages/shared-components/src/FormFields/TimeField/index.ts +1 -0
- package/packages/shared-components/src/FormFields/TimePicker/Skeleton.tsx +24 -0
- package/packages/shared-components/src/FormFields/TimePicker/TimePicker.tsx +168 -0
- package/packages/shared-components/src/FormFields/TimePicker/index.ts +1 -0
- package/packages/shared-components/src/FormFields/index.ts +16 -0
- package/packages/shared-components/src/Indicator/Indicator.tsx +18 -0
- package/packages/shared-components/src/Indicator/SeverityIndicator.tsx +34 -0
- package/packages/shared-components/src/Indicator/index.ts +2 -0
- package/packages/shared-components/src/Layouts/FormContainer.tsx +6 -0
- package/packages/shared-components/src/Layouts/FormGridLayout.tsx +27 -0
- package/packages/shared-components/src/Layouts/FormRow/FormRow.styled.tsx +47 -0
- package/packages/shared-components/src/Layouts/FormRow/FormRow.tsx +20 -0
- package/packages/shared-components/src/Layouts/FormRow/index.ts +1 -0
- package/packages/shared-components/src/Layouts/FormSection.tsx +22 -0
- package/packages/shared-components/src/Layouts/index.ts +4 -0
- package/packages/shared-components/src/Loader/FacebookCircularProgress.tsx +41 -0
- package/packages/shared-components/src/Loader/index.ts +1 -0
- package/packages/shared-components/src/PadBox/PadBox.tsx +21 -0
- package/packages/shared-components/src/PadBox/index.ts +1 -0
- package/packages/shared-components/src/Pagination/Pagination.tsx +42 -0
- package/packages/shared-components/src/Pagination/index.ts +1 -0
- package/packages/shared-components/src/Stepper/Stepper.tsx +88 -0
- package/packages/shared-components/src/Stepper/StepperV2.tsx +115 -0
- package/packages/shared-components/src/Stepper/StepperV3.tsx +72 -0
- package/packages/shared-components/src/Stepper/index.ts +3 -0
- package/packages/shared-components/src/Svgs/AppLogo/AppLogoMedium.tsx +65 -0
- package/packages/shared-components/src/Svgs/AppLogo/AppLogoSmall.tsx +48 -0
- package/packages/shared-components/src/Svgs/ArrowUp.tsx +11 -0
- package/packages/shared-components/src/Svgs/Company/CompanyBanner.tsx +480 -0
- package/packages/shared-components/src/Svgs/Company/index.ts +1 -0
- package/packages/shared-components/src/Svgs/Drawer/SettingIcon.tsx +31 -0
- package/packages/shared-components/src/Svgs/Drawer/SvgBankConfig.tsx +36 -0
- package/packages/shared-components/src/Svgs/Drawer/SvgConfiguration.tsx +16 -0
- package/packages/shared-components/src/Svgs/Drawer/SvgPayroll.tsx +32 -0
- package/packages/shared-components/src/Svgs/Drawer/SvgsEmployees.tsx +25 -0
- package/packages/shared-components/src/Svgs/Drawer/SvgsOrganization.tsx +36 -0
- package/packages/shared-components/src/Svgs/Drawer/SvgsTransaction.tsx +81 -0
- package/packages/shared-components/src/Svgs/Drawer/index.ts +7 -0
- package/packages/shared-components/src/Svgs/FormAction.tsx +118 -0
- package/packages/shared-components/src/Svgs/ImportExcelSuccessIcon.tsx +54 -0
- package/packages/shared-components/src/Svgs/LogoIcon.tsx +74 -0
- package/packages/shared-components/src/Svgs/SvgAdd.tsx +28 -0
- package/packages/shared-components/src/Svgs/SvgCalendar.tsx +89 -0
- package/packages/shared-components/src/Svgs/SvgConfigure.tsx +51 -0
- package/packages/shared-components/src/Svgs/SvgDelete.tsx +55 -0
- package/packages/shared-components/src/Svgs/SvgDownload.tsx +20 -0
- package/packages/shared-components/src/Svgs/SvgEmail.tsx +27 -0
- package/packages/shared-components/src/Svgs/SvgExport.tsx +33 -0
- package/packages/shared-components/src/Svgs/SvgFilterList.tsx +22 -0
- package/packages/shared-components/src/Svgs/SvgImport.tsx +43 -0
- package/packages/shared-components/src/Svgs/SvgNoLogo.tsx +66 -0
- package/packages/shared-components/src/Svgs/SvgNoSign.tsx +28 -0
- package/packages/shared-components/src/Svgs/SvgPhone.tsx +19 -0
- package/packages/shared-components/src/Svgs/SvgProfile.tsx +33 -0
- package/packages/shared-components/src/Svgs/SvgView.tsx +16 -0
- package/packages/shared-components/src/Svgs/SvgsDrop.tsx +44 -0
- package/packages/shared-components/src/Svgs/SvgsEdit.tsx +42 -0
- package/packages/shared-components/src/Svgs/SvgsHistory.tsx +40 -0
- package/packages/shared-components/src/Svgs/SvgsHome.tsx +18 -0
- package/packages/shared-components/src/Svgs/SvgsIndicator.tsx +24 -0
- package/packages/shared-components/src/Svgs/index.ts +18 -0
- package/packages/shared-components/src/Tab/Skeleton.tsx +15 -0
- package/packages/shared-components/src/Tab/Tabs.tsx +64 -0
- package/packages/shared-components/src/Tab/index.ts +1 -0
- package/packages/shared-components/src/Timeline/AttendanceStatus.tsx +56 -0
- package/packages/shared-components/src/Timeline/Timeline.tsx +159 -0
- package/packages/shared-components/src/Timeline/TimelineTrackSegments.tsx +130 -0
- package/packages/shared-components/src/Timeline/index.ts +2 -0
- package/packages/shared-components/src/Toast/Toast.tsx +59 -0
- package/packages/shared-components/src/Toast/ToastBody.tsx +26 -0
- package/packages/shared-components/src/Toast/ToastFooterLink.tsx +19 -0
- package/packages/shared-components/src/Toast/Toaster.styled.tsx +80 -0
- package/packages/shared-components/src/Toast/Toaster.tsx +21 -0
- package/packages/shared-components/src/Toast/index.ts +3 -0
- package/packages/shared-components/src/Toast/toasts.tsx +28 -0
- package/packages/shared-components/src/Toast/types.ts +13 -0
- package/packages/shared-components/src/Tooltip/Tooltip.tsx +36 -0
- package/packages/shared-components/src/Tooltip/index.ts +1 -0
- package/packages/shared-components/src/UserProfileMenu/UserProfileMenu.styled.tsx +42 -0
- package/packages/shared-components/src/UserProfileMenu/UserProfileMenu.tsx +168 -0
- package/packages/shared-components/src/UserProfileMenu/index.ts +1 -0
- package/packages/shared-components/src/index.ts +25 -0
- package/packages/shared-components/src/utils/colorVariant.ts +162 -0
- package/packages/shared-components/src/utils/date.ts +25 -0
- package/packages/shared-components/src/utils/file.ts +22 -0
- package/packages/shared-components/src/utils/index.ts +11 -0
- package/packages/shared-components/src/utils/theme/colorPalette.ts +112 -0
- package/packages/shared-components/src/utils/theme/colorPaletteUI.tsx +44 -0
- package/packages/shared-components/src/utils/theme/paletteDark.ts +10 -0
- package/packages/shared-components/src/utils/theme/paletteLight.ts +31 -0
- package/packages/shared-components/src/utils/theme/theme.ts +297 -0
- package/packages/shared-components/src/utils/theme/types.ts +18 -0
- package/packages/shared-components/src/utils/theme/typography.ts +52 -0
- package/packages/shared-components/src/utils/urlToNestedObject.ts +9 -0
- package/packages/shared-components/tsconfig.json +8 -0
- package/packages/shared-components/tsconfig.lint.json +8 -0
- package/packages/shared-components/webpack/cjs.js +20 -0
- package/packages/shared-components/webpack/common.js +36 -0
- package/packages/typescript-config/base.json +20 -0
- package/packages/typescript-config/nextjs.json +13 -0
- package/packages/typescript-config/package.json +9 -0
- package/packages/typescript-config/react-library.json +8 -0
- package/pnpm-workspace.yaml +3 -0
- package/turbo.json +42 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import type { AutocompleteProps as MuiAutocompleteProps } from "@mui/material";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Avatar,
|
|
5
|
+
Box,
|
|
6
|
+
Checkbox,
|
|
7
|
+
Chip,
|
|
8
|
+
Divider,
|
|
9
|
+
IconButton,
|
|
10
|
+
InputLabel,
|
|
11
|
+
Autocomplete as MuiAutocomplete,
|
|
12
|
+
Paper,
|
|
13
|
+
Popper,
|
|
14
|
+
Stack,
|
|
15
|
+
TextField,
|
|
16
|
+
useTheme,
|
|
17
|
+
} from "@mui/material";
|
|
18
|
+
import { styled } from "@mui/material/styles";
|
|
19
|
+
import { useMemo, useRef, useState, type KeyboardEvent } from "react";
|
|
20
|
+
import {
|
|
21
|
+
useController,
|
|
22
|
+
type ControllerRenderProps,
|
|
23
|
+
type FieldValues,
|
|
24
|
+
type UseControllerProps,
|
|
25
|
+
} from "react-hook-form";
|
|
26
|
+
import { useTranslation } from "react-i18next";
|
|
27
|
+
import { EditAction } from "../../Actions";
|
|
28
|
+
import { toasts } from "../../Toast";
|
|
29
|
+
import { BoxStyled, CheckStyled } from "../CheckBox/CheckBox.styled";
|
|
30
|
+
import { Skeleton } from "./Skeleton";
|
|
31
|
+
|
|
32
|
+
export type Option = {
|
|
33
|
+
heading?: string;
|
|
34
|
+
label: string;
|
|
35
|
+
value: string | number;
|
|
36
|
+
disabled?: boolean;
|
|
37
|
+
employee_code?: string;
|
|
38
|
+
avatar?: string;
|
|
39
|
+
punch_code?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type AutocompleteProps<P extends FieldValues> = UseControllerProps<P> &
|
|
43
|
+
Omit<
|
|
44
|
+
Omit<
|
|
45
|
+
MuiAutocompleteProps<
|
|
46
|
+
{
|
|
47
|
+
heading?: string;
|
|
48
|
+
label: string;
|
|
49
|
+
value: string | number;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
avatar?: string;
|
|
52
|
+
employee_code?: string;
|
|
53
|
+
punch_code?: string;
|
|
54
|
+
},
|
|
55
|
+
boolean,
|
|
56
|
+
boolean,
|
|
57
|
+
boolean
|
|
58
|
+
>,
|
|
59
|
+
"renderInput"
|
|
60
|
+
>,
|
|
61
|
+
keyof ControllerRenderProps<P>
|
|
62
|
+
> & {
|
|
63
|
+
required?: boolean;
|
|
64
|
+
label?: string;
|
|
65
|
+
helperText?: string;
|
|
66
|
+
error?: boolean;
|
|
67
|
+
withLabel?: boolean;
|
|
68
|
+
placeholder?: string;
|
|
69
|
+
isShowAvatar?: boolean;
|
|
70
|
+
shouldCloseOnSelect?: boolean;
|
|
71
|
+
onAction?: () => void;
|
|
72
|
+
isShowSelectAll?: boolean;
|
|
73
|
+
isShowOptionsOnType?: boolean;
|
|
74
|
+
maxLimit?: number;
|
|
75
|
+
renderOption?: (
|
|
76
|
+
props: React.HTMLProps<HTMLLIElement>,
|
|
77
|
+
option: Option,
|
|
78
|
+
state: { selected: boolean }
|
|
79
|
+
) => JSX.Element;
|
|
80
|
+
getOptionLabel?: (option: string) => string;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export function Autocomplete<P extends FieldValues>({
|
|
84
|
+
control,
|
|
85
|
+
defaultValue,
|
|
86
|
+
name,
|
|
87
|
+
required = false,
|
|
88
|
+
label,
|
|
89
|
+
multiple = false,
|
|
90
|
+
disabled = false,
|
|
91
|
+
options = [],
|
|
92
|
+
rules,
|
|
93
|
+
loading = false,
|
|
94
|
+
helperText,
|
|
95
|
+
error,
|
|
96
|
+
withLabel = false,
|
|
97
|
+
placeholder = "",
|
|
98
|
+
freeSolo,
|
|
99
|
+
isShowOptionsOnType = false,
|
|
100
|
+
isShowSelectAll = true,
|
|
101
|
+
isShowAvatar = false,
|
|
102
|
+
shouldCloseOnSelect = false,
|
|
103
|
+
onAction,
|
|
104
|
+
renderOption,
|
|
105
|
+
getOptionLabel,
|
|
106
|
+
maxLimit,
|
|
107
|
+
...restProps
|
|
108
|
+
}: AutocompleteProps<P>) {
|
|
109
|
+
const {
|
|
110
|
+
field: { onChange, value, ...restField },
|
|
111
|
+
} = useController({ name, control, defaultValue, rules });
|
|
112
|
+
|
|
113
|
+
const { t } = useTranslation();
|
|
114
|
+
|
|
115
|
+
const [inputValue, setInputValue] = useState("");
|
|
116
|
+
|
|
117
|
+
const handleSelectAll = (isSelected: boolean) => {
|
|
118
|
+
if (isSelected) {
|
|
119
|
+
const allValues = options.map((option) => option.value);
|
|
120
|
+
|
|
121
|
+
onChange(allValues);
|
|
122
|
+
} else {
|
|
123
|
+
onChange([]);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const highlightedOptionRef = useRef<string | number>("");
|
|
128
|
+
|
|
129
|
+
const isAllSelected = useMemo(() => {
|
|
130
|
+
return (
|
|
131
|
+
multiple &&
|
|
132
|
+
isShowSelectAll &&
|
|
133
|
+
options.length > 0 &&
|
|
134
|
+
value?.length === options.filter((option) => !option.disabled).length
|
|
135
|
+
);
|
|
136
|
+
}, [multiple, isShowSelectAll, options, value]);
|
|
137
|
+
|
|
138
|
+
const memoizedOptions = useMemo(() => {
|
|
139
|
+
return [
|
|
140
|
+
...(multiple && isShowSelectAll && options.length
|
|
141
|
+
? [{ label: "Select All", value: "select-all" }]
|
|
142
|
+
: []),
|
|
143
|
+
...options,
|
|
144
|
+
];
|
|
145
|
+
}, [multiple, isShowSelectAll, options]);
|
|
146
|
+
|
|
147
|
+
const filteredOptions = useMemo(() => {
|
|
148
|
+
if (inputValue.length < 3) {
|
|
149
|
+
return [];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return options.filter((option) =>
|
|
153
|
+
option.label.toLowerCase().includes(inputValue.toLowerCase())
|
|
154
|
+
);
|
|
155
|
+
}, [inputValue]);
|
|
156
|
+
|
|
157
|
+
// eslint-disable-next-line sonarjs/function-return-type
|
|
158
|
+
const selectedValue = useMemo(() => {
|
|
159
|
+
if (multiple && freeSolo) {
|
|
160
|
+
return (
|
|
161
|
+
value?.map((val: string | number) => {
|
|
162
|
+
const selectedOption = options.find((option) => option.value === val);
|
|
163
|
+
|
|
164
|
+
return selectedOption ? selectedOption.label : val.toString();
|
|
165
|
+
}) || []
|
|
166
|
+
);
|
|
167
|
+
} else if (withLabel) {
|
|
168
|
+
return options.find((option) => option.value === value?.value) ?? null;
|
|
169
|
+
} else if (multiple) {
|
|
170
|
+
return options.filter((option) => value?.includes(option.value));
|
|
171
|
+
} else if (!options.find((option) => option.value === value) && freeSolo) {
|
|
172
|
+
return value;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return options.find((option) => option.value === value) || null;
|
|
176
|
+
}, [multiple, options, value]);
|
|
177
|
+
|
|
178
|
+
const {
|
|
179
|
+
palette: {
|
|
180
|
+
app: { color },
|
|
181
|
+
},
|
|
182
|
+
} = useTheme();
|
|
183
|
+
|
|
184
|
+
const StyledPaper = styled(Paper)(({ theme }) => ({
|
|
185
|
+
"& .MuiAutocomplete-listbox": {
|
|
186
|
+
maxHeight: 200,
|
|
187
|
+
overflowY: "auto",
|
|
188
|
+
marginTop: "10px",
|
|
189
|
+
"&::-webkit-scrollbar": {
|
|
190
|
+
width: "6px",
|
|
191
|
+
},
|
|
192
|
+
"&::-webkit-scrollbar-thumb": {
|
|
193
|
+
backgroundColor: theme.palette.secondary.main,
|
|
194
|
+
borderRadius: "4px",
|
|
195
|
+
},
|
|
196
|
+
"&::-webkit-scrollbar-track": {
|
|
197
|
+
backgroundColor: color.lightBlue[100],
|
|
198
|
+
},
|
|
199
|
+
"& .MuiAutocomplete-option": {
|
|
200
|
+
fontSize: "14px", // Change this to your desired font size
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}));
|
|
204
|
+
|
|
205
|
+
const GroupHeader = styled("div")(({ theme }) => ({
|
|
206
|
+
position: "sticky",
|
|
207
|
+
padding: "4px 10px",
|
|
208
|
+
fontSize: "16px",
|
|
209
|
+
fontWeight: 500,
|
|
210
|
+
color: theme.palette.app.color.butterflyBlue[900],
|
|
211
|
+
backgroundColor: theme.palette.app.color.butterflyBlue[500],
|
|
212
|
+
}));
|
|
213
|
+
|
|
214
|
+
const GroupItems = styled("ul")({
|
|
215
|
+
padding: 0,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
if (loading) {
|
|
219
|
+
return <Skeleton label={label} />;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
223
|
+
const handleKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
|
|
224
|
+
if (e.code === "Space" && highlightedOptionRef.current) {
|
|
225
|
+
e.preventDefault();
|
|
226
|
+
|
|
227
|
+
if (multiple) {
|
|
228
|
+
if (highlightedOptionRef.current == "select-all") {
|
|
229
|
+
handleSelectAll(!isAllSelected);
|
|
230
|
+
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (selectedValue && Array.isArray(selectedValue)) {
|
|
235
|
+
if (maxLimit && selectedValue.length >= maxLimit) {
|
|
236
|
+
toasts.error({
|
|
237
|
+
title: t("common.autocomplete.limitExceed", { maxLimit }),
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const valuesArray = selectedValue.map((item) => item.value);
|
|
244
|
+
|
|
245
|
+
if (valuesArray.includes(highlightedOptionRef.current)) {
|
|
246
|
+
onChange(
|
|
247
|
+
valuesArray.filter(
|
|
248
|
+
(value) => value !== highlightedOptionRef.current
|
|
249
|
+
)
|
|
250
|
+
);
|
|
251
|
+
} else {
|
|
252
|
+
onChange([...valuesArray, highlightedOptionRef.current]);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} else {
|
|
256
|
+
onChange(highlightedOptionRef.current);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
return (
|
|
262
|
+
<Stack gap="10px">
|
|
263
|
+
{label && <InputLabel required={required}>{label}</InputLabel>}
|
|
264
|
+
|
|
265
|
+
<Stack
|
|
266
|
+
direction="row"
|
|
267
|
+
justifyContent="space-between"
|
|
268
|
+
gap="10px"
|
|
269
|
+
alignItems="start"
|
|
270
|
+
>
|
|
271
|
+
<MuiAutocomplete
|
|
272
|
+
PopperComponent={Popper}
|
|
273
|
+
PaperComponent={StyledPaper}
|
|
274
|
+
sx={{
|
|
275
|
+
"& .MuiAutocomplete-tag": {
|
|
276
|
+
backgroundColor: color.slate[700],
|
|
277
|
+
color: "black",
|
|
278
|
+
},
|
|
279
|
+
width: "100%",
|
|
280
|
+
}}
|
|
281
|
+
onHighlightChange={(event, option) => {
|
|
282
|
+
if (option) {
|
|
283
|
+
if (highlightedOptionRef.current != option.value) {
|
|
284
|
+
highlightedOptionRef.current = option.value;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}}
|
|
288
|
+
disableCloseOnSelect={shouldCloseOnSelect}
|
|
289
|
+
disabled={disabled}
|
|
290
|
+
freeSolo={freeSolo}
|
|
291
|
+
{...restProps}
|
|
292
|
+
{...restField}
|
|
293
|
+
renderTags={(value: Option[], getTagProps) =>
|
|
294
|
+
value.map((option: Option, index: number) => {
|
|
295
|
+
const { key, ...tagProps } = getTagProps({ index });
|
|
296
|
+
|
|
297
|
+
const label = typeof option === "string" ? option : option.label;
|
|
298
|
+
|
|
299
|
+
let avatarContent = "";
|
|
300
|
+
|
|
301
|
+
let avatar = undefined;
|
|
302
|
+
|
|
303
|
+
if (isShowAvatar) {
|
|
304
|
+
if (!option.avatar) {
|
|
305
|
+
const initials = option.label
|
|
306
|
+
.split(" ")
|
|
307
|
+
.map((word) => word[0]?.toUpperCase())
|
|
308
|
+
.join("");
|
|
309
|
+
|
|
310
|
+
avatarContent = `${initials}`;
|
|
311
|
+
}
|
|
312
|
+
avatar = option.avatar ? (
|
|
313
|
+
<Avatar src={option.avatar} alt={option.label} />
|
|
314
|
+
) : (
|
|
315
|
+
<Avatar>{avatarContent}</Avatar>
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return (
|
|
320
|
+
<Chip avatar={avatar} label={label} key={key} {...tagProps} />
|
|
321
|
+
);
|
|
322
|
+
})
|
|
323
|
+
}
|
|
324
|
+
renderOption={(props, option, { selected }) => {
|
|
325
|
+
if (renderOption) {
|
|
326
|
+
return renderOption(props, option, { selected });
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const { key, ...optionProps } = props;
|
|
330
|
+
|
|
331
|
+
return (
|
|
332
|
+
<li key={key} {...optionProps}>
|
|
333
|
+
<Stack gap="5px">
|
|
334
|
+
<Stack direction="row" gap="10px">
|
|
335
|
+
{multiple && (
|
|
336
|
+
<Checkbox
|
|
337
|
+
icon={<BoxStyled size="small" />}
|
|
338
|
+
checkedIcon={<CheckStyled size="small" />}
|
|
339
|
+
indeterminate={
|
|
340
|
+
!isAllSelected &&
|
|
341
|
+
selectedValue?.length &&
|
|
342
|
+
option.value === "select-all"
|
|
343
|
+
? true
|
|
344
|
+
: false
|
|
345
|
+
}
|
|
346
|
+
checked={isAllSelected ? true : selected}
|
|
347
|
+
sx={{
|
|
348
|
+
marginRight: "8px",
|
|
349
|
+
".MuiCheckbox-indeterminate": {
|
|
350
|
+
borderColor: color.butterflyBlue[900],
|
|
351
|
+
},
|
|
352
|
+
}}
|
|
353
|
+
/>
|
|
354
|
+
)}
|
|
355
|
+
{option.label}
|
|
356
|
+
</Stack>
|
|
357
|
+
{option.value === "select-all" && (
|
|
358
|
+
<Divider sx={{ width: "280px" }} />
|
|
359
|
+
)}
|
|
360
|
+
</Stack>
|
|
361
|
+
</li>
|
|
362
|
+
);
|
|
363
|
+
}}
|
|
364
|
+
renderInput={(params) => {
|
|
365
|
+
let startAdornment = params.InputProps.startAdornment;
|
|
366
|
+
|
|
367
|
+
if (!multiple && selectedValue?.avatar && getOptionLabel) {
|
|
368
|
+
startAdornment = (
|
|
369
|
+
<Box width="20px" marginLeft="10px">
|
|
370
|
+
<Avatar
|
|
371
|
+
src={selectedValue.avatar}
|
|
372
|
+
alt={selectedValue.label}
|
|
373
|
+
sx={{ width: 24, height: 24 }}
|
|
374
|
+
/>
|
|
375
|
+
</Box>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
return (
|
|
380
|
+
<TextField
|
|
381
|
+
{...params}
|
|
382
|
+
placeholder={placeholder || `Select ${label}`}
|
|
383
|
+
error={error}
|
|
384
|
+
helperText={helperText}
|
|
385
|
+
InputProps={{
|
|
386
|
+
...params.InputProps,
|
|
387
|
+
startAdornment,
|
|
388
|
+
}}
|
|
389
|
+
onChange={(e) => {
|
|
390
|
+
if (isShowOptionsOnType) {
|
|
391
|
+
setInputValue(e.target.value);
|
|
392
|
+
}
|
|
393
|
+
}}
|
|
394
|
+
onKeyDown={(e) => handleKeyDown(e)}
|
|
395
|
+
/>
|
|
396
|
+
);
|
|
397
|
+
}}
|
|
398
|
+
multiple={multiple}
|
|
399
|
+
options={isShowOptionsOnType ? filteredOptions : memoizedOptions}
|
|
400
|
+
isOptionEqualToValue={(option, value) =>
|
|
401
|
+
freeSolo ? false : option.value === value.value
|
|
402
|
+
}
|
|
403
|
+
getOptionLabel={(option) => {
|
|
404
|
+
if (getOptionLabel) {
|
|
405
|
+
return getOptionLabel(option);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
if (typeof option === "string") {
|
|
409
|
+
return option;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return option.label;
|
|
413
|
+
}}
|
|
414
|
+
value={selectedValue}
|
|
415
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
416
|
+
onChange={(_, newValue) => {
|
|
417
|
+
if (!newValue) {
|
|
418
|
+
setInputValue("");
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
if (withLabel) {
|
|
422
|
+
return onChange(newValue);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (
|
|
426
|
+
multiple &&
|
|
427
|
+
Array.isArray(newValue) &&
|
|
428
|
+
maxLimit &&
|
|
429
|
+
newValue.length > maxLimit
|
|
430
|
+
) {
|
|
431
|
+
toasts.error({
|
|
432
|
+
title: t("common.autocomplete.limitExceed", { maxLimit }),
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (multiple && isShowSelectAll && Array.isArray(newValue)) {
|
|
439
|
+
const isSelectAllIncluded = newValue.some(
|
|
440
|
+
(option) =>
|
|
441
|
+
typeof option !== "string" && option?.value === "select-all"
|
|
442
|
+
);
|
|
443
|
+
|
|
444
|
+
if (isSelectAllIncluded) {
|
|
445
|
+
handleSelectAll(!isAllSelected);
|
|
446
|
+
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (multiple && freeSolo) {
|
|
452
|
+
if (Array.isArray(newValue)) {
|
|
453
|
+
// eslint-disable-next-line sonarjs/function-return-type
|
|
454
|
+
const values = newValue.map((option) => {
|
|
455
|
+
return typeof option === "string" ? option : option.value;
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
return onChange(values);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
return onChange(value || []);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (typeof newValue === "string") {
|
|
465
|
+
return onChange(newValue ?? null);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
if (Array.isArray(newValue)) {
|
|
469
|
+
// eslint-disable-next-line sonarjs/function-return-type
|
|
470
|
+
const values = newValue.map((option) => {
|
|
471
|
+
if (typeof option === "string") {
|
|
472
|
+
return newValue;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return option.value;
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
return onChange(values);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
onChange(newValue ? newValue.value : null);
|
|
482
|
+
}}
|
|
483
|
+
groupBy={(option) => option.heading ?? ""}
|
|
484
|
+
renderGroup={(params) => (
|
|
485
|
+
<li key={params.key}>
|
|
486
|
+
<GroupHeader>{params.group}</GroupHeader>
|
|
487
|
+
<GroupItems>{params.children}</GroupItems>
|
|
488
|
+
</li>
|
|
489
|
+
)}
|
|
490
|
+
getOptionDisabled={(option) => !!option.disabled}
|
|
491
|
+
/>
|
|
492
|
+
|
|
493
|
+
{onAction && (
|
|
494
|
+
<IconButton
|
|
495
|
+
disabled={disabled}
|
|
496
|
+
sx={{
|
|
497
|
+
border: `1px solid ${color.iron[800]}`,
|
|
498
|
+
padding: "0px",
|
|
499
|
+
borderRadius: "5px",
|
|
500
|
+
}}
|
|
501
|
+
onClick={onAction}
|
|
502
|
+
>
|
|
503
|
+
<EditAction />
|
|
504
|
+
</IconButton>
|
|
505
|
+
)}
|
|
506
|
+
</Stack>
|
|
507
|
+
</Stack>
|
|
508
|
+
);
|
|
509
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Skeleton as MuiSkeleton, Stack } from "@mui/material";
|
|
2
|
+
|
|
3
|
+
type SkeletonProps = {
|
|
4
|
+
label?: string;
|
|
5
|
+
};
|
|
6
|
+
export const Skeleton = ({ label }: SkeletonProps) => {
|
|
7
|
+
return (
|
|
8
|
+
<Stack gap="10px">
|
|
9
|
+
{label && (
|
|
10
|
+
<MuiSkeleton
|
|
11
|
+
width={120}
|
|
12
|
+
height="23px"
|
|
13
|
+
sx={{
|
|
14
|
+
transform: "scale(1)",
|
|
15
|
+
}}
|
|
16
|
+
/>
|
|
17
|
+
)}
|
|
18
|
+
<MuiSkeleton
|
|
19
|
+
height="40px"
|
|
20
|
+
sx={{
|
|
21
|
+
transform: "scale(1)",
|
|
22
|
+
}}
|
|
23
|
+
/>
|
|
24
|
+
</Stack>
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./Autocomplete";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Check } from "@mui/icons-material";
|
|
2
|
+
import type { BoxProps, CSSObject, CheckboxProps } from "@mui/material";
|
|
3
|
+
import { Box, styled } from "@mui/material";
|
|
4
|
+
import type { ComponentType } from "react";
|
|
5
|
+
type BoxStyledProps = {
|
|
6
|
+
size: CheckboxProps["size"];
|
|
7
|
+
} & BoxProps;
|
|
8
|
+
|
|
9
|
+
type CheckStyledProps = {
|
|
10
|
+
size: CheckboxProps["size"];
|
|
11
|
+
} & CheckboxProps;
|
|
12
|
+
|
|
13
|
+
export const BoxStyled: ComponentType<BoxStyledProps> = styled(Box)<{
|
|
14
|
+
size: CheckboxProps["size"];
|
|
15
|
+
}>(({ theme, size }) => {
|
|
16
|
+
const { color } = theme.palette.app;
|
|
17
|
+
|
|
18
|
+
const checkBoxSize =
|
|
19
|
+
size === "small"
|
|
20
|
+
? {
|
|
21
|
+
width: "14px",
|
|
22
|
+
height: "14px",
|
|
23
|
+
}
|
|
24
|
+
: {
|
|
25
|
+
width: "20px",
|
|
26
|
+
height: "20px",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const style: CSSObject = {
|
|
30
|
+
...checkBoxSize,
|
|
31
|
+
borderRadius: "4px",
|
|
32
|
+
border: `2px solid ${color.iron[900]}`,
|
|
33
|
+
"input:hover ~ &": {
|
|
34
|
+
borderColor: color.butterflyBlue[900],
|
|
35
|
+
},
|
|
36
|
+
"input:disabled ~ &": {
|
|
37
|
+
borderColor: color.iron[800],
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return style;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const CheckStyled: ComponentType<CheckStyledProps> = styled(
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
Check as any
|
|
47
|
+
)<{
|
|
48
|
+
size: CheckboxProps["size"];
|
|
49
|
+
}>(({ theme, size }) => {
|
|
50
|
+
const { color } = theme.palette.app;
|
|
51
|
+
|
|
52
|
+
const checkBoxSize =
|
|
53
|
+
size === "small"
|
|
54
|
+
? {
|
|
55
|
+
width: "14px",
|
|
56
|
+
height: "14px",
|
|
57
|
+
}
|
|
58
|
+
: {
|
|
59
|
+
width: "20px",
|
|
60
|
+
height: "20px",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const style: CSSObject = {
|
|
64
|
+
...checkBoxSize,
|
|
65
|
+
border: `2px solid ${color.butterflyBlue[900]}`,
|
|
66
|
+
borderRadius: "4px",
|
|
67
|
+
color: color.iron[600],
|
|
68
|
+
backgroundColor: color.butterflyBlue[900],
|
|
69
|
+
"input:disabled ~ &": {
|
|
70
|
+
borderColor: color.iron[800],
|
|
71
|
+
backgroundColor: color.iron[800],
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return style;
|
|
76
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Checkbox, {
|
|
2
|
+
type CheckboxProps as MuiCheckboxProps,
|
|
3
|
+
} from "@mui/material/Checkbox";
|
|
4
|
+
import {
|
|
5
|
+
useController,
|
|
6
|
+
type ControllerRenderProps,
|
|
7
|
+
type FieldValues,
|
|
8
|
+
type UseControllerProps,
|
|
9
|
+
} from "react-hook-form";
|
|
10
|
+
import { BoxStyled, CheckStyled } from "./CheckBox.styled";
|
|
11
|
+
import { Skeleton } from "./Skeleton";
|
|
12
|
+
|
|
13
|
+
export type CheckBoxProps<P extends FieldValues> = UseControllerProps<P> &
|
|
14
|
+
Omit<Omit<MuiCheckboxProps, "checked">, keyof ControllerRenderProps<P>> & {
|
|
15
|
+
loading?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function CheckBox<P extends FieldValues>({
|
|
19
|
+
name,
|
|
20
|
+
rules,
|
|
21
|
+
control,
|
|
22
|
+
defaultValue,
|
|
23
|
+
size,
|
|
24
|
+
loading = false,
|
|
25
|
+
...restCheckBoxProps
|
|
26
|
+
}: CheckBoxProps<P>) {
|
|
27
|
+
const {
|
|
28
|
+
field: { value = false, ...restField },
|
|
29
|
+
} = useController({ name, control, defaultValue, rules });
|
|
30
|
+
|
|
31
|
+
if (loading) {
|
|
32
|
+
return <Skeleton />;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<Checkbox
|
|
37
|
+
icon={<BoxStyled size={size} />}
|
|
38
|
+
checkedIcon={<CheckStyled size={size} />}
|
|
39
|
+
checked={value}
|
|
40
|
+
{...restField}
|
|
41
|
+
{...restCheckBoxProps}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./CheckBox";
|