digitinary-ui 1.0.252 → 1.0.255
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/dist/components/Accordion/Accordion.js +28 -0
- package/dist/components/Accordion/Accordion.test.js +53 -0
- package/dist/components/Accordion/index.js +1 -0
- package/dist/components/ActionDropdown/ActionDropdown.test.js +42 -0
- package/dist/components/ActionDropdown/index.js +117 -0
- package/dist/components/Alert/Alert.js +57 -0
- package/dist/components/Alert/Alert.test.js +59 -0
- package/dist/components/Alert/index.js +1 -0
- package/dist/components/ArenaDatePicker/ArenaDatePicker.js +227 -0
- package/dist/components/ArenaDatePicker/index.js +1 -0
- package/dist/components/ArenaDateRange/ArenaDateRange.js +90 -0
- package/dist/components/ArenaDateRange/index.js +1 -0
- package/dist/components/ArenaLabel/ArenaLabel.js +6 -0
- package/dist/components/ArenaLabel/ArenaLabel.test.js +42 -0
- package/dist/components/BarChart/BarChart.js +22 -0
- package/dist/components/Button/Button.js +16 -0
- package/dist/components/Button/Button.test.js +63 -0
- package/dist/components/Button/index.js +1 -0
- package/dist/components/Card/Card.js +6 -0
- package/dist/components/Card/Card.test.js +38 -0
- package/dist/components/Card/index.js +1 -0
- package/dist/components/Carousel/Carousel.js +134 -0
- package/dist/components/Checkbox/Checkbox.js +8 -0
- package/dist/components/Checkbox/Checkbox.test.js +18 -0
- package/dist/components/Checkbox/index.js +1 -0
- package/dist/components/Chip/Chip.js +14 -0
- package/dist/components/Chip/index.js +1 -0
- package/dist/components/Chips/Chips.js +31 -0
- package/dist/components/CounterComponent/CounterComponent.js +21 -0
- package/dist/components/Date/Date.js +423 -0
- package/dist/components/Date/index.js +1 -0
- package/dist/components/DateRange/DateRange.js +266 -0
- package/dist/components/DateRange/index.js +1 -0
- package/dist/components/Dialog/Dialog.js +36 -0
- package/dist/components/Dialog/index.js +1 -0
- package/dist/components/DonutChart/DonutChart.js +56 -0
- package/dist/components/DoubleBarChart/DoubleBarChart.js +46 -0
- package/dist/components/DropDown/DropDown.js +123 -0
- package/dist/components/EllipsisMenu/index.js +8 -0
- package/dist/components/EllipsisTextWithTooltip/EllipsisTextWithTooltip.js +6 -0
- package/dist/components/FieldArray/FieldArray.js +48 -0
- package/dist/components/FieldArray/FieldArrayHook.js +19 -0
- package/dist/components/FileUploader/index.js +26 -0
- package/dist/components/FileUploader/viewFiles.js +84 -0
- package/dist/components/FileUploaderV2/index.js +62 -0
- package/dist/components/FileUploaderV2/types.js +1 -0
- package/dist/components/FileUploaderV2/viewFiles.js +99 -0
- package/dist/components/GaugeChart/index.js +19 -0
- package/dist/components/GaugeChart/types.js +1 -0
- package/dist/components/GridSystem/Col.js +21 -0
- package/dist/components/GridSystem/Container.js +13 -0
- package/dist/components/GridSystem/helper.js +12 -0
- package/dist/components/HelperText/HelperText.js +6 -0
- package/dist/components/HelperText/index.js +1 -0
- package/dist/components/Input/Input.js +78 -0
- package/dist/components/Input/index.js +1 -0
- package/dist/components/Input/input.test.js +113 -0
- package/dist/components/InputRange/index.js +57 -0
- package/dist/components/JsonEditor/JsonEditor.js +13 -0
- package/dist/components/JsonField/JsonField.js +84 -0
- package/dist/components/Label/Label.js +6 -0
- package/dist/components/Label/index.js +1 -0
- package/dist/components/LineChart/LineChart.js +45 -0
- package/dist/components/Loader/Loader.js +11 -0
- package/dist/components/Loader/index.js +1 -0
- package/dist/components/MultiSelectWithChips/MultiSelectWithChips.js +16 -0
- package/dist/components/NewDate/ArenaDatePicker.js +368 -0
- package/dist/components/NewDate/types.js +84 -0
- package/dist/components/NoDataFallback/NoDataFallback.js +7 -0
- package/dist/components/Overlay/Overlay.js +8 -0
- package/dist/components/Overlay/index.js +1 -0
- package/dist/components/Pagination/Pagination.js +22 -0
- package/dist/components/Pagination/index.js +1 -0
- package/dist/components/PaginationV2/PaginationV2.js +38 -0
- package/dist/components/PaginationV2/index.js +1 -0
- package/dist/components/PaginationV2/types.js +1 -0
- package/dist/components/PhoneNumber/index.js +41 -0
- package/dist/components/PieChart/PieChart.js +17 -0
- package/dist/components/Radio/Radio.js +8 -0
- package/dist/components/Radio/index.js +1 -0
- package/dist/components/RadioGroup/RadioGroup.js +17 -0
- package/dist/components/RadioGroup/index.js +1 -0
- package/dist/components/SectionHead/SectionHead.js +8 -0
- package/dist/components/SelectGroup/SelectGroup.js +184 -0
- package/dist/components/SelectGroup/helper.js +90 -0
- package/dist/components/SelectGroup/index.js +1 -0
- package/dist/components/SelectGroupV2/SelectGroupV2.js +175 -0
- package/dist/components/SideDrawer/SideDrawer.js +54 -0
- package/dist/components/SideDrawer/SideDrawer.test.js +59 -0
- package/dist/components/SideDrawer/index.js +1 -0
- package/dist/components/SideDrawerV2/SideDrawerV2.js +18 -0
- package/dist/components/SideDrawerV2/index.js +1 -0
- package/dist/components/SimpleCollapseSection/SimpleCollapseSection.js +11 -0
- package/dist/components/SimpleLabelValue/SimpleLabelValue.js +7 -0
- package/dist/components/SimpleLabelValue/index.js +1 -0
- package/dist/components/StackedBarChart/StackedBarChart.js +16 -0
- package/dist/components/Status/Status.js +20 -0
- package/dist/components/Stepper/Step/Step.js +15 -0
- package/dist/components/Stepper/Stepper.js +26 -0
- package/dist/components/Switch/Switch.js +6 -0
- package/dist/components/Switch/index.js +1 -0
- package/dist/components/Table/Table.js +63 -0
- package/dist/components/Table/index.js +1 -0
- package/dist/components/TableV2/helper.d.ts +1 -2
- package/dist/components/TableV2/helper.js +180 -0
- package/dist/components/TableV2/index.js +33 -0
- package/dist/components/TableV2/types.js +1 -0
- package/dist/components/TextArea/TextArea.d.ts +1 -1
- package/dist/components/TextArea/TextArea.js +51 -0
- package/dist/components/TextArea/index.js +1 -0
- package/dist/components/TimeTracker/TimeTracker.js +26 -0
- package/dist/components/Toast/Toast.js +57 -0
- package/dist/components/Tooltip/Tooltip.js +7 -0
- package/dist/components/ViewDocuments/index.js +53 -0
- package/dist/components/index.js +59 -0
- package/dist/constants/index.js +2 -0
- package/dist/icons/AccessDeniedIcon.js +3 -0
- package/dist/icons/AccountActivation.js +3 -0
- package/dist/icons/AccountChartIcon.js +3 -0
- package/dist/icons/AccountDarkIcon.js +3 -0
- package/dist/icons/AccountIcon.js +3 -0
- package/dist/icons/AccountStatement.js +3 -0
- package/dist/icons/ActivateAccount.js +3 -0
- package/dist/icons/ActivateCard.js +3 -0
- package/dist/icons/ActivateCardIcon.js +3 -0
- package/dist/icons/ActiveIcon.js +3 -0
- package/dist/icons/Add.js +3 -0
- package/dist/icons/AddIcon.js +3 -0
- package/dist/icons/AlertErrorIcon.js +3 -0
- package/dist/icons/AlertInfoIcon.js +3 -0
- package/dist/icons/AlertSuccessIcon.js +3 -0
- package/dist/icons/AlertWarningIcon.js +3 -0
- package/dist/icons/ApproveIcon.js +3 -0
- package/dist/icons/ArenaLogo.js +3 -0
- package/dist/icons/ArrowBottom.js +3 -0
- package/dist/icons/ArrowIcon.js +3 -0
- package/dist/icons/ArrowLeft.js +3 -0
- package/dist/icons/ArrowRight.js +3 -0
- package/dist/icons/ArrowUp.js +3 -0
- package/dist/icons/ArrowUpIcon.js +3 -0
- package/dist/icons/Article.js +3 -0
- package/dist/icons/ArticleIcon.js +3 -0
- package/dist/icons/AssignIcon.js +3 -0
- package/dist/icons/BackArrow.js +3 -0
- package/dist/icons/BackArrowArabic.js +3 -0
- package/dist/icons/Buyer.js +4 -0
- package/dist/icons/Calendar.js +3 -0
- package/dist/icons/CardViewIcon.js +3 -0
- package/dist/icons/CardsIcon.js +3 -0
- package/dist/icons/Check.js +3 -0
- package/dist/icons/CheckMark.js +3 -0
- package/dist/icons/Circle.js +3 -0
- package/dist/icons/ClaimIcon.js +3 -0
- package/dist/icons/ClearField.js +3 -0
- package/dist/icons/ClipBoard.js +3 -0
- package/dist/icons/CloseAccount.js +3 -0
- package/dist/icons/CloseCircleIcon.js +3 -0
- package/dist/icons/CloseIcon.js +3 -0
- package/dist/icons/CloseSquarIcon.js +3 -0
- package/dist/icons/ConsentCharIcon.js +3 -0
- package/dist/icons/ContactIcon.js +3 -0
- package/dist/icons/CopyInput.js +3 -0
- package/dist/icons/CustomerApproved.js +3 -0
- package/dist/icons/CustomerRejected.js +3 -0
- package/dist/icons/DangerIcon.js +3 -0
- package/dist/icons/DefaultFileIcon.js +3 -0
- package/dist/icons/DefaultIcon.js +3 -0
- package/dist/icons/DeleteIcon.js +3 -0
- package/dist/icons/DeleteOutlinedIcon.js +3 -0
- package/dist/icons/DisabledIcon.js +3 -0
- package/dist/icons/Document.js +3 -0
- package/dist/icons/DoubleLeftArrow.js +3 -0
- package/dist/icons/DoubleRightArrow.js +3 -0
- package/dist/icons/DownloadIcon.js +3 -0
- package/dist/icons/EditIcon.js +3 -0
- package/dist/icons/Ellipse.js +3 -0
- package/dist/icons/EmptyAccount.js +3 -0
- package/dist/icons/EmptyActivityStatus.js +3 -0
- package/dist/icons/EmptyCard.js +3 -0
- package/dist/icons/EmptyCardIcon.js +3 -0
- package/dist/icons/EmptyChannelsIcon.js +3 -0
- package/dist/icons/EmptyDashboard.js +3 -0
- package/dist/icons/EmptyFinance.js +3 -0
- package/dist/icons/EmptyFinanceIcon.js +3 -0
- package/dist/icons/EmptyLiabilitiesIcon.js +3 -0
- package/dist/icons/EmptyRequest.js +3 -0
- package/dist/icons/EmptyResults.js +3 -0
- package/dist/icons/EmptySpendingIcon.js +3 -0
- package/dist/icons/ErrorIcon.js +3 -0
- package/dist/icons/ExcelIcon.js +3 -0
- package/dist/icons/ExpandIcon.js +3 -0
- package/dist/icons/EyeIcon.js +3 -0
- package/dist/icons/Fail.js +3 -0
- package/dist/icons/FilterIcon.js +3 -0
- package/dist/icons/Finance.js +3 -0
- package/dist/icons/GeneralIcon.js +3 -0
- package/dist/icons/GridView.js +3 -0
- package/dist/icons/HidePasswordIcon.js +3 -0
- package/dist/icons/HistoryIcon.js +3 -0
- package/dist/icons/HomeIcon.js +4 -0
- package/dist/icons/InactiveIcon.js +3 -0
- package/dist/icons/InfoCircle.js +3 -0
- package/dist/icons/InfoDialogIcon.js +3 -0
- package/dist/icons/InfoIcon.js +3 -0
- package/dist/icons/InfoIconOnboard.js +3 -0
- package/dist/icons/InfoSquare.js +3 -0
- package/dist/icons/InstallmentsPay.js +3 -0
- package/dist/icons/IntoUser.js +3 -0
- package/dist/icons/KebabIcon.js +3 -0
- package/dist/icons/Kwd.js +3 -0
- package/dist/icons/LaptopIcon.js +4 -0
- package/dist/icons/LeadActivities.js +3 -0
- package/dist/icons/LeadDocuments.js +3 -0
- package/dist/icons/LeadInterestIcon.js +3 -0
- package/dist/icons/LeadOwnerIcon.js +3 -0
- package/dist/icons/LeadSourceIcon.js +3 -0
- package/dist/icons/LeadStagesIcon.js +3 -0
- package/dist/icons/LeadStatus.js +3 -0
- package/dist/icons/LeftArrowIcon.js +3 -0
- package/dist/icons/LinkIcon.js +3 -0
- package/dist/icons/ListViewIcon.js +3 -0
- package/dist/icons/LoaderIcon.js +3 -0
- package/dist/icons/LogoutIcon.js +4 -0
- package/dist/icons/ManageCardIcon.js +3 -0
- package/dist/icons/ManageDebitCard.js +3 -0
- package/dist/icons/MasterCardDiamond.js +3 -0
- package/dist/icons/MessageExclamation.js +3 -0
- package/dist/icons/MessageSquareIcon.js +3 -0
- package/dist/icons/Minus.js +3 -0
- package/dist/icons/MoreSquare.js +3 -0
- package/dist/icons/MoreSquareIcon.js +3 -0
- package/dist/icons/MoveElementIcon.js +3 -0
- package/dist/icons/MurabahaCars.js +3 -0
- package/dist/icons/MurabahaRealEstate.js +3 -0
- package/dist/icons/NextIcon.js +3 -0
- package/dist/icons/NoAvatar.js +3 -0
- package/dist/icons/NoDataIcon.js +5 -0
- package/dist/icons/NoDocuments.js +3 -0
- package/dist/icons/Note.js +3 -0
- package/dist/icons/OnboardingError.js +3 -0
- package/dist/icons/OnboardingPending.js +3 -0
- package/dist/icons/OnboardingReject.js +3 -0
- package/dist/icons/OnboardingSuccess.js +3 -0
- package/dist/icons/OpenAccount.js +3 -0
- package/dist/icons/OpenDeposit.js +3 -0
- package/dist/icons/PayToCardIcon.js +3 -0
- package/dist/icons/PaymentCard.js +3 -0
- package/dist/icons/PaymentChartIcon.js +3 -0
- package/dist/icons/PaymentDarkIcon.js +3 -0
- package/dist/icons/PaymentIcon.js +3 -0
- package/dist/icons/PdfIcon.js +3 -0
- package/dist/icons/PenIcon.js +3 -0
- package/dist/icons/PlusIcon.js +3 -0
- package/dist/icons/PointIcon.js +3 -0
- package/dist/icons/PreviousIcon.js +3 -0
- package/dist/icons/Profile.js +3 -0
- package/dist/icons/ProfileIcon.js +3 -0
- package/dist/icons/ReassignIcon.js +3 -0
- package/dist/icons/Refresh.js +3 -0
- package/dist/icons/RefreshIcon.js +3 -0
- package/dist/icons/RejectIcon.js +3 -0
- package/dist/icons/Reload.js +3 -0
- package/dist/icons/ReportLost.js +3 -0
- package/dist/icons/ReportStolen.js +3 -0
- package/dist/icons/RequestCardIcon.js +3 -0
- package/dist/icons/ResetPasswordIcon.js +3 -0
- package/dist/icons/ResolvedIcon.js +3 -0
- package/dist/icons/ResubmitIcon.js +3 -0
- package/dist/icons/ReturnIcon.js +3 -0
- package/dist/icons/RightArrowIcon.js +3 -0
- package/dist/icons/RotatingCircle.js +3 -0
- package/dist/icons/SearchIcon.js +3 -0
- package/dist/icons/SectionIcon.js +3 -0
- package/dist/icons/SelectDownArrowIcon.js +3 -0
- package/dist/icons/SelectFieldDownArrow.js +3 -0
- package/dist/icons/SelectFieldUpArrow.js +3 -0
- package/dist/icons/SendCardPinIcon.js +3 -0
- package/dist/icons/ServerBlock.js +3 -0
- package/dist/icons/Settings.js +3 -0
- package/dist/icons/ShowPasswordIcon.js +3 -0
- package/dist/icons/SmallArrow.js +3 -0
- package/dist/icons/SmallArrowRight.js +3 -0
- package/dist/icons/SortIcon.js +3 -0
- package/dist/icons/Sound.js +3 -0
- package/dist/icons/StandingOrderIcon.js +3 -0
- package/dist/icons/SubSectionIcon.js +3 -0
- package/dist/icons/SubmitIcon.js +3 -0
- package/dist/icons/Success.js +3 -0
- package/dist/icons/SuccessIcon.js +3 -0
- package/dist/icons/Swap.js +3 -0
- package/dist/icons/TableView.js +3 -0
- package/dist/icons/Tawaroq.js +3 -0
- package/dist/icons/TimeCircle.js +3 -0
- package/dist/icons/ToggleRightIcon.js +3 -0
- package/dist/icons/TopOpenLeadsIcon.js +3 -0
- package/dist/icons/TrackingIcon.js +4 -0
- package/dist/icons/TransferBetweenOwnAccountIcon.js +3 -0
- package/dist/icons/TransferFromCardIcon.js +3 -0
- package/dist/icons/TransferIcon.js +3 -0
- package/dist/icons/TransferInternalIcon.js +3 -0
- package/dist/icons/TransferInternational.js +3 -0
- package/dist/icons/TransferInternationalIcon.js +3 -0
- package/dist/icons/TransferLocalIcon.js +3 -0
- package/dist/icons/UnLinkIcon.js +3 -0
- package/dist/icons/UploadIcon.js +3 -0
- package/dist/icons/VideoIcon.js +3 -0
- package/dist/icons/ViewAccount.js +3 -0
- package/dist/icons/ViewCreditCard.js +3 -0
- package/dist/icons/ViewDebitCard.js +3 -0
- package/dist/icons/ViewFinanceIcon.js +3 -0
- package/dist/icons/ViewIcon.js +3 -0
- package/dist/icons/VisaPlatinum.js +3 -0
- package/dist/icons/VisaSignature.js +3 -0
- package/dist/icons/WaitList.js +3 -0
- package/dist/icons/WarningIcon.js +3 -0
- package/dist/icons/WhiteArrowLeft.js +3 -0
- package/dist/icons/WhiteList.js +9 -0
- package/dist/icons/WordIcon.js +3 -0
- package/dist/icons/ZoomIn.js +3 -0
- package/dist/icons/ZoomInIcon.js +3 -0
- package/dist/icons/ZoomOut.js +3 -0
- package/dist/icons/ZoomOutIcon.js +3 -0
- package/dist/icons/index.js +201 -0
- package/dist/index.js +4 -2
- package/dist/localization/ar.json +40 -0
- package/dist/localization/en.json +40 -0
- package/dist/localization/index.js +9 -0
- package/dist/types/enums.js +25 -0
- package/dist/types/index.js +3 -0
- package/dist/types/interfaces.js +1 -0
- package/dist/types/types.js +1 -0
- package/dist/utils/index.js +8 -0
- package/package.json +6 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import SelectFieldDownArrow from '../../icons/SelectFieldDownArrow';
|
|
4
|
+
import './style.scss';
|
|
5
|
+
const Accordion = ({ defaultExpanded = false, expanded, disabled = false, onChange, summary, children, className, }) => {
|
|
6
|
+
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
|
|
7
|
+
const isControlled = expanded !== undefined;
|
|
8
|
+
const toggleAccordion = () => {
|
|
9
|
+
if (disabled)
|
|
10
|
+
return;
|
|
11
|
+
if (isControlled && onChange) {
|
|
12
|
+
onChange();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
setIsExpanded(!isExpanded);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const handleKeyDown = (event) => {
|
|
19
|
+
if (disabled)
|
|
20
|
+
return;
|
|
21
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
22
|
+
toggleAccordion();
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const shouldExpand = isControlled ? expanded && !disabled : isExpanded && !disabled;
|
|
26
|
+
return (_jsxs("div", { className: `accordion-container ${shouldExpand ? 'expanded' : 'collapsed'} ${disabled ? 'disabled' : ''} ${className}`, children: [_jsxs("div", { className: "accordion-header", onClick: toggleAccordion, onKeyDown: handleKeyDown, "aria-expanded": shouldExpand, role: "button", tabIndex: 0, children: [summary, _jsx("div", { className: "iconContainer", children: _jsx(SelectFieldDownArrow, { "data-id": "ACCORDION_DROPDOWN_ARROW_ICON", className: `dropdownIcon ${shouldExpand ? 'rotateFlip' : ''} ${disabled ? 'disabled' : ''}`, width: "1.5rem", height: "1.5rem" }) })] }), _jsx("div", { className: `accordion-details ${shouldExpand ? 'expanded' : ''}`, children: children })] }));
|
|
27
|
+
};
|
|
28
|
+
export default Accordion;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import Accordion from './Accordion';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
// Mock the SelectFieldDownArrow component
|
|
6
|
+
jest.mock('../../icons/SelectFieldDownArrow', () => () => (_jsx("svg", { "data-id": "ACCORDION_DROPDOWN_ARROW_ICON" })));
|
|
7
|
+
describe('Accordion Component', () => {
|
|
8
|
+
test('renders the accordion with the provided summary', () => {
|
|
9
|
+
render(_jsx(Accordion, { summary: "Test Summary", children: "Accordion Content" }));
|
|
10
|
+
expect(screen.getByText('Test Summary')).toBeInTheDocument();
|
|
11
|
+
});
|
|
12
|
+
test('expands and collapses when clicked', () => {
|
|
13
|
+
render(_jsx(Accordion, { summary: "Test Summary", children: "Accordion Content" }));
|
|
14
|
+
const header = screen.getByRole('button');
|
|
15
|
+
const content = screen.getByText('Accordion Content').parentElement;
|
|
16
|
+
expect(content).not.toHaveClass('expanded');
|
|
17
|
+
fireEvent.click(header);
|
|
18
|
+
expect(content).toHaveClass('expanded');
|
|
19
|
+
fireEvent.click(header);
|
|
20
|
+
expect(content).not.toHaveClass('expanded');
|
|
21
|
+
});
|
|
22
|
+
test('does not toggle when disabled', () => {
|
|
23
|
+
render(_jsx(Accordion, { summary: "Test Summary", disabled: true, children: "Accordion Content" }));
|
|
24
|
+
const header = screen.getByRole('button');
|
|
25
|
+
const content = screen.getByText('Accordion Content').parentElement;
|
|
26
|
+
fireEvent.click(header);
|
|
27
|
+
expect(content).not.toHaveClass('expanded');
|
|
28
|
+
});
|
|
29
|
+
test('supports controlled expansion via the `expanded` prop', () => {
|
|
30
|
+
const { rerender } = render(_jsx(Accordion, { summary: "Test Summary", expanded: true, children: "Accordion Content" }));
|
|
31
|
+
const content = screen.getByText('Accordion Content').parentElement;
|
|
32
|
+
expect(content).toHaveClass('expanded');
|
|
33
|
+
rerender(_jsx(Accordion, { summary: "Test Summary", expanded: false, children: "Accordion Content" }));
|
|
34
|
+
expect(content).not.toHaveClass('expanded');
|
|
35
|
+
});
|
|
36
|
+
test('calls onChange when controlled and clicked', () => {
|
|
37
|
+
const onChange = jest.fn();
|
|
38
|
+
render(_jsx(Accordion, { summary: "Test Summary", expanded: true, onChange: onChange, children: "Accordion Content" }));
|
|
39
|
+
const header = screen.getByRole('button');
|
|
40
|
+
fireEvent.click(header);
|
|
41
|
+
expect(onChange).toHaveBeenCalledTimes(1);
|
|
42
|
+
});
|
|
43
|
+
test('toggles when Enter or Space key is pressed', () => {
|
|
44
|
+
render(_jsx(Accordion, { summary: "Test Summary", children: "Accordion Content" }));
|
|
45
|
+
const header = screen.getByRole('button');
|
|
46
|
+
const content = screen.getByText('Accordion Content').parentElement;
|
|
47
|
+
expect(content).not.toHaveClass('expanded');
|
|
48
|
+
fireEvent.keyDown(header, { key: 'Enter' });
|
|
49
|
+
expect(content).toHaveClass('expanded');
|
|
50
|
+
fireEvent.keyDown(header, { key: ' ' });
|
|
51
|
+
expect(content).not.toHaveClass('expanded');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Accordion';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import ActionDropdown from './index';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
// Mock the MoreSquareIcon component
|
|
6
|
+
jest.mock('../../icons/MoreSquareIcon', () => () => _jsx("svg", { "data-id": "MoreSquareIcon" }));
|
|
7
|
+
describe('ActionDropdown Component', () => {
|
|
8
|
+
test('renders dropdown button', () => {
|
|
9
|
+
render(_jsx(ActionDropdown, { options: ['Option 1', 'Option 2'] }));
|
|
10
|
+
const button = screen.getByRole('button');
|
|
11
|
+
expect(button).toBeInTheDocument();
|
|
12
|
+
});
|
|
13
|
+
test('opens the actions menu when button is clicked', () => {
|
|
14
|
+
render(_jsx(ActionDropdown, { options: ['Option 1', 'Option 2'] }));
|
|
15
|
+
const button = screen.getByRole('button');
|
|
16
|
+
fireEvent.click(button);
|
|
17
|
+
expect(screen.getByText('Option 1')).toBeInTheDocument();
|
|
18
|
+
expect(screen.getByText('Option 2')).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
test('closes the actions menu when clicking outside', async () => {
|
|
21
|
+
render(_jsx(ActionDropdown, { options: ['Option 1', 'Option 2'] }));
|
|
22
|
+
const button = screen.getByRole('button');
|
|
23
|
+
fireEvent.click(button);
|
|
24
|
+
expect(screen.getByText('Option 1')).toBeInTheDocument();
|
|
25
|
+
fireEvent.mouseDown(document.body);
|
|
26
|
+
expect(screen.queryByText('Option 1')).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
test('calls setIsOpen when clicking the dropdown button', () => {
|
|
29
|
+
render(_jsx(ActionDropdown, { options: ['Option 1', 'Option 2'] }));
|
|
30
|
+
const button = screen.getByRole('button');
|
|
31
|
+
fireEvent.click(button);
|
|
32
|
+
expect(screen.getByText('Option 1')).toBeInTheDocument();
|
|
33
|
+
});
|
|
34
|
+
test('renders options correctly', () => {
|
|
35
|
+
render(_jsx(ActionDropdown, { options: ['Option A', 'Option B', 'Option C'] }));
|
|
36
|
+
const button = screen.getByRole('button');
|
|
37
|
+
fireEvent.click(button);
|
|
38
|
+
expect(screen.getByText('Option A')).toBeInTheDocument();
|
|
39
|
+
expect(screen.getByText('Option B')).toBeInTheDocument();
|
|
40
|
+
expect(screen.getByText('Option C')).toBeInTheDocument();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import MoreSquareIcon from '../../icons/MoreSquareIcon';
|
|
4
|
+
import ReactDOM from 'react-dom';
|
|
5
|
+
import './style.scss';
|
|
6
|
+
const main = document.getElementById('main-container');
|
|
7
|
+
const ActionsMenu = ({ options, isOpen, TargetElement, customContainer = main, setIsOpen, }) => {
|
|
8
|
+
const menuRef = useRef(null);
|
|
9
|
+
const actionsListRef = useRef(null);
|
|
10
|
+
const [isDisplayedAboveTarget, setIsDisplayedAboveTarget] = useState(false);
|
|
11
|
+
const [isPositioned, setIsPositioned] = useState(false);
|
|
12
|
+
const [invertedTrianglePosition, setInvertedTrianglePosition] = useState(-5.5);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!isOpen)
|
|
15
|
+
setIsPositioned(false);
|
|
16
|
+
}, [isOpen]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
getInvertedTrianglePosition();
|
|
19
|
+
}, [isDisplayedAboveTarget]);
|
|
20
|
+
const isRTL = () => {
|
|
21
|
+
return (document.documentElement.dir === 'rtl' ||
|
|
22
|
+
document.documentElement.getAttribute('lang') === 'ar');
|
|
23
|
+
};
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const updatePosition = () => {
|
|
26
|
+
setIsPositioned(true);
|
|
27
|
+
if (TargetElement && menuRef.current && actionsListRef.current) {
|
|
28
|
+
const rect = TargetElement.getBoundingClientRect();
|
|
29
|
+
const menu = menuRef.current;
|
|
30
|
+
const menuRect = actionsListRef.current.getBoundingClientRect();
|
|
31
|
+
const menuWidth = menuRect.width;
|
|
32
|
+
const menuHeight = menuRect.height;
|
|
33
|
+
const spaceBelow = window.innerHeight - rect.bottom;
|
|
34
|
+
const spaceAbove = rect.top;
|
|
35
|
+
if (spaceBelow >= menuHeight || spaceBelow >= spaceAbove) {
|
|
36
|
+
menu.style.top = `${rect.bottom + window.scrollY}px`;
|
|
37
|
+
setIsDisplayedAboveTarget(false);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
menu.style.top = `${rect.top + window.scrollY - menuHeight - 10}px`;
|
|
41
|
+
setIsDisplayedAboveTarget(true);
|
|
42
|
+
}
|
|
43
|
+
if (isRTL()) {
|
|
44
|
+
const rightPosition = window.innerWidth - rect.right;
|
|
45
|
+
const leftPosition = rect.left;
|
|
46
|
+
if (leftPosition - menuWidth < 30) {
|
|
47
|
+
menu.style.left = '30px';
|
|
48
|
+
menu.style.right = 'auto';
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
menu.style.right = `${rightPosition + rect.width}px`;
|
|
52
|
+
menu.style.left = 'auto';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const leftPosition = rect.left - 84;
|
|
57
|
+
if (leftPosition < 30) {
|
|
58
|
+
menu.style.left = '30px';
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
menu.style.left = `${leftPosition}px`;
|
|
62
|
+
}
|
|
63
|
+
menu.style.right = 'auto';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const handleClickOutside = (event) => {
|
|
68
|
+
if (menuRef.current && !menuRef.current.contains(event.target)) {
|
|
69
|
+
setIsOpen(false);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
if (isOpen) {
|
|
73
|
+
updatePosition();
|
|
74
|
+
if (main) {
|
|
75
|
+
document.addEventListener('click', handleClickOutside);
|
|
76
|
+
main.addEventListener('scroll', updatePosition);
|
|
77
|
+
customContainer?.addEventListener('scroll', updatePosition);
|
|
78
|
+
window.addEventListener('resize', updatePosition);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return () => {
|
|
82
|
+
if (main) {
|
|
83
|
+
document.removeEventListener('click', handleClickOutside);
|
|
84
|
+
main.removeEventListener('scroll', updatePosition);
|
|
85
|
+
customContainer?.removeEventListener('scroll', updatePosition);
|
|
86
|
+
window.removeEventListener('resize', updatePosition);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
}, [isOpen, TargetElement, isPositioned, isDisplayedAboveTarget]);
|
|
90
|
+
const getInvertedTrianglePosition = () => {
|
|
91
|
+
const actionsContainer = document.querySelector('.actions-list');
|
|
92
|
+
let actionsContainerHeight;
|
|
93
|
+
if (actionsContainer)
|
|
94
|
+
actionsContainerHeight = actionsContainer?.clientHeight;
|
|
95
|
+
if (isDisplayedAboveTarget && actionsContainerHeight) {
|
|
96
|
+
setInvertedTrianglePosition(actionsContainerHeight - 5.5);
|
|
97
|
+
}
|
|
98
|
+
else
|
|
99
|
+
setInvertedTrianglePosition(-5.5);
|
|
100
|
+
};
|
|
101
|
+
if (!isOpen || !isPositioned)
|
|
102
|
+
return _jsx(_Fragment, {});
|
|
103
|
+
return ReactDOM.createPortal(_jsxs("div", { className: "actions-menu-container", ref: menuRef, style: {
|
|
104
|
+
position: 'absolute',
|
|
105
|
+
zIndex: 1000,
|
|
106
|
+
}, children: [_jsx("div", { className: "triangle-container", children: _jsx("div", { className: `triangle`, style: {
|
|
107
|
+
top: invertedTrianglePosition,
|
|
108
|
+
right: isRTL() ? 'auto' : '30px',
|
|
109
|
+
left: isRTL() ? '30px' : 'auto',
|
|
110
|
+
} }) }), _jsx("div", { ref: actionsListRef, className: "actions-list", children: options?.map((option, index) => (_jsx("div", { className: "dropdown-item", children: option }, index))) })] }), document.body);
|
|
111
|
+
};
|
|
112
|
+
const ActionDropdown = ({ options, customContainer, menuIcon = _jsx(MoreSquareIcon, {}), }) => {
|
|
113
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
114
|
+
const anchorRef = useRef(null);
|
|
115
|
+
return (_jsxs("div", { className: "action-dropdown-container", children: [_jsx("button", { className: "more-square-button", ref: anchorRef, onClick: () => setIsOpen((prev) => !prev), children: menuIcon }), _jsx(ActionsMenu, { isOpen: isOpen, setIsOpen: setIsOpen, TargetElement: anchorRef.current, options: options, customContainer: customContainer })] }));
|
|
116
|
+
};
|
|
117
|
+
export default ActionDropdown;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import ErrorAlert from '../../icons/AlertErrorIcon';
|
|
4
|
+
import NaturalAlert from '../../icons/InfoIcon';
|
|
5
|
+
import SuccessAlert from '../../icons/AlertSuccessIcon';
|
|
6
|
+
import CloseIcon from '../../icons/CloseIcon';
|
|
7
|
+
import './style.scss';
|
|
8
|
+
const severityMap = {
|
|
9
|
+
info: NaturalAlert,
|
|
10
|
+
success: SuccessAlert,
|
|
11
|
+
error: ErrorAlert,
|
|
12
|
+
warning: ErrorAlert,
|
|
13
|
+
natural: NaturalAlert,
|
|
14
|
+
};
|
|
15
|
+
const Alert = ({ severity = 'info', color = severity, // Default: alert color matches its severity (e.g., error=red, warning=yellow)
|
|
16
|
+
variant = 'default', onClose, action, className, icon = true, // Default to true, showing the icon based on severity
|
|
17
|
+
customStyle, children, }) => {
|
|
18
|
+
const IconComponent = severityMap[severity];
|
|
19
|
+
const [visible, setVisible] = useState(true);
|
|
20
|
+
const [exitTransition, setExitTransition] = useState(false);
|
|
21
|
+
const actionBtnRef = useRef(null);
|
|
22
|
+
const alertContentRef = useRef(null);
|
|
23
|
+
const handleClose = () => {
|
|
24
|
+
setExitTransition(true);
|
|
25
|
+
if (typeof onClose === 'function')
|
|
26
|
+
onClose();
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
setVisible(false);
|
|
29
|
+
}, 500);
|
|
30
|
+
};
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
let offsetWidth = 0;
|
|
33
|
+
if (actionBtnRef.current) {
|
|
34
|
+
const actionBtnWidth = actionBtnRef.current.offsetWidth / 16;
|
|
35
|
+
offsetWidth += actionBtnWidth;
|
|
36
|
+
}
|
|
37
|
+
if (onClose) {
|
|
38
|
+
offsetWidth += 1.5;
|
|
39
|
+
}
|
|
40
|
+
if (actionBtnRef.current || onClose) {
|
|
41
|
+
offsetWidth += 1;
|
|
42
|
+
}
|
|
43
|
+
if (alertContentRef.current) {
|
|
44
|
+
alertContentRef.current.style.marginRight = `${offsetWidth}rem`;
|
|
45
|
+
}
|
|
46
|
+
}, []);
|
|
47
|
+
if (!visible)
|
|
48
|
+
return null;
|
|
49
|
+
return (_jsxs("div", { className: `${className} alertContainer ${color} ${variant} ${exitTransition ? 'exit' : ''}`, style: customStyle, role: "alert", "data-id": `ALERT${severity ? `_${severity?.toUpperCase()}_ID` : ''}`, children: [icon === true ? (
|
|
50
|
+
// Default icon based on severity
|
|
51
|
+
_jsx(IconComponent, { className: `alertIcon ${color} ${variant}`, width: "1.25rem", height: "1.25rem", "data-id": "ALERT-ICON" })) : icon ? ( // Render custom icon if icon is JSX.Element
|
|
52
|
+
icon) : null, _jsx("div", { className: "alertContent", ref: alertContentRef, children: children }), _jsxs("div", { className: "actionContainer", children: [action && (_jsx("div", { className: "actionButton", ref: actionBtnRef, children: action })), onClose && (_jsx(CloseIcon, { className: "closeIcon", width: "1.25rem", height: "1.25rem", "data-id": "CLOSE-ICON", tabIndex: 0, onKeyDown: (e) => {
|
|
53
|
+
if (e.key === 'Enter' || e.key === ' ')
|
|
54
|
+
handleClose();
|
|
55
|
+
}, onClick: handleClose, "aria-label": "Close alert" }))] })] }));
|
|
56
|
+
};
|
|
57
|
+
export default Alert;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, screen, fireEvent } from '@testing-library/react';
|
|
3
|
+
import Alert from './index';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
// Mock components
|
|
6
|
+
jest.mock('../../icons/AlertErrorIcon', () => () => _jsx("div", { children: "Error Icon" }));
|
|
7
|
+
jest.mock('../../icons/InfoIcon', () => () => _jsx("div", { children: "Info Icon" }));
|
|
8
|
+
jest.mock('../../icons/AlertSuccessIcon', () => () => _jsx("div", { children: "Success Icon" }));
|
|
9
|
+
jest.mock('../../icons/CloseIcon', () => () => _jsx("div", { children: "Close Icon" }));
|
|
10
|
+
describe('Alert Component', () => {
|
|
11
|
+
test('should render with default props', () => {
|
|
12
|
+
render(_jsx(Alert, { severity: "info", onClose: () => { }, children: 'Test alert' }));
|
|
13
|
+
expect(screen.getByText('Test alert')).toBeInTheDocument();
|
|
14
|
+
expect(screen.getByText('Info Icon')).toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
test('should render custom severity icon', () => {
|
|
17
|
+
render(_jsx(Alert, { severity: "success", onClose: () => { }, children: 'Success alert' }));
|
|
18
|
+
expect(screen.getByText('Success Icon')).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
test('should render error icon when severity is "error"', () => {
|
|
21
|
+
render(_jsx(Alert, { severity: "error", onClose: () => { }, children: 'Error alert' }));
|
|
22
|
+
expect(screen.getByText('Error Icon')).toBeInTheDocument();
|
|
23
|
+
});
|
|
24
|
+
test('should render close icon', () => {
|
|
25
|
+
render(_jsx(Alert, { severity: "info", onClose: () => { }, children: 'Test alert with close icon' }));
|
|
26
|
+
expect(screen.getByText('Close Icon')).toBeInTheDocument();
|
|
27
|
+
});
|
|
28
|
+
test('should call onClose when close icon is clicked', () => {
|
|
29
|
+
const onClose = jest.fn();
|
|
30
|
+
render(_jsx(Alert, { severity: "info", onClose: onClose, children: 'Test alert with close icon' }));
|
|
31
|
+
fireEvent.click(screen.getByText('Close Icon'));
|
|
32
|
+
expect(onClose).toHaveBeenCalledTimes(0);
|
|
33
|
+
});
|
|
34
|
+
test('should apply the correct variant class', () => {
|
|
35
|
+
render(_jsx(Alert, { severity: "info", variant: "outlined", onClose: () => { }, children: 'Test alert' }));
|
|
36
|
+
expect(screen.getByRole('alert')).toHaveClass('outlined');
|
|
37
|
+
});
|
|
38
|
+
test('should apply custom styles when provided', () => {
|
|
39
|
+
render(_jsx(Alert, { severity: "info", customStyle: { backgroundColor: 'red' }, onClose: () => { }, children: 'Styled alert' }));
|
|
40
|
+
expect(screen.getByRole('alert')).toHaveStyle('background-color: red');
|
|
41
|
+
});
|
|
42
|
+
test('should render custom icon if icon prop is provided as JSX', () => {
|
|
43
|
+
const CustomIcon = () => _jsx("div", { children: "Custom Icon" });
|
|
44
|
+
render(_jsx(Alert, { severity: "info", icon: _jsx(CustomIcon, {}), onClose: () => { }, children: 'Custom icon alert' }));
|
|
45
|
+
expect(screen.getByText('Custom Icon')).toBeInTheDocument();
|
|
46
|
+
});
|
|
47
|
+
test('should render the alert content properly', () => {
|
|
48
|
+
render(_jsx(Alert, { severity: "info", onClose: () => { }, children: 'Test alert content' }));
|
|
49
|
+
expect(screen.getByText('Test alert content')).toBeInTheDocument();
|
|
50
|
+
});
|
|
51
|
+
test('should not render icon if icon is false', () => {
|
|
52
|
+
render(_jsx(Alert, { severity: "info", icon: false, onClose: () => { }, children: 'Alert without icon' }));
|
|
53
|
+
expect(screen.queryByText('Info Icon')).toBeNull();
|
|
54
|
+
});
|
|
55
|
+
test('should render action button when action prop is passed', () => {
|
|
56
|
+
render(_jsx(Alert, { severity: "info", action: _jsx("button", { children: "Action" }), onClose: () => { }, children: 'Alert with action' }));
|
|
57
|
+
expect(screen.getByText('Action')).toBeInTheDocument();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './Alert';
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, useRef } from 'react';
|
|
3
|
+
import DatePicker from 'react-datepicker';
|
|
4
|
+
import 'react-datepicker/dist/react-datepicker.css';
|
|
5
|
+
import moment from 'moment';
|
|
6
|
+
import ClearField from '../../icons/ClearField';
|
|
7
|
+
import CalendarIcon from '../../icons/Calendar';
|
|
8
|
+
import LeftArrowIcon from '../../icons/LeftArrowIcon';
|
|
9
|
+
import RightArrowIcon from '../../icons/RightArrowIcon';
|
|
10
|
+
import ArrowBottomIcon from '../../icons/ArrowBottom';
|
|
11
|
+
import ArrowUpIcon from '../../icons/ArrowUpIcon';
|
|
12
|
+
import Button from '../Button';
|
|
13
|
+
import Label from '../Label';
|
|
14
|
+
import './style.scss';
|
|
15
|
+
const ArenaDatePicker = ({ id, label, helperText, errorMsg, value = undefined, onChange, disabled, size = 'medium', clearable = true, timePicker, isEndDay, showTimeInput = false, placeholder = !showTimeInput ? 'DD MMM YYYY' : 'DD MMM YYYY HH:mm:ss', defaultFormat = !showTimeInput ? 'DD MMM YYYY' : 'DD MMM YYYY HH:mm:ss', maxDate, minDate, className = '', timeUnit = 'daily', showMonthYearPicker = false, timeInputLabel = '', isRange = false, showYearPicker = false, onClear, required, }) => {
|
|
16
|
+
const [showMonthCalender, setShowMonthCalender] = useState(showMonthYearPicker);
|
|
17
|
+
const [showYearCalender, setShowYearCalender] = useState(showYearPicker);
|
|
18
|
+
const [time, setTime] = useState({
|
|
19
|
+
h: isEndDay && !value ? 23 : value ? Number(moment(value).format('H')) : 0,
|
|
20
|
+
mm: isEndDay && !value ? 59 : value ? Number(moment(value).format('m')) : 0,
|
|
21
|
+
ss: isEndDay && !value ? 59 : value ? Number(moment(value).format('s')) : 0,
|
|
22
|
+
});
|
|
23
|
+
const datePickerRef = useRef(null); // Initialize the ref with null
|
|
24
|
+
const [startDate, setStartDate] = useState();
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (value) {
|
|
27
|
+
setStartDate(moment(value).toDate());
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
setStartDate(undefined);
|
|
31
|
+
}
|
|
32
|
+
}, [value]);
|
|
33
|
+
const [endDate, setEndDate] = useState(isRange ? undefined : startDate);
|
|
34
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
35
|
+
const toggleDatePicker = () => !disabled && setIsOpen(!isOpen);
|
|
36
|
+
const handleDateChange = (dates) => {
|
|
37
|
+
if (isRange) {
|
|
38
|
+
const [start, end] = dates;
|
|
39
|
+
setStartDate(start ?? undefined);
|
|
40
|
+
setEndDate(end ?? undefined);
|
|
41
|
+
onChange &&
|
|
42
|
+
onChange(start && end
|
|
43
|
+
? `${moment(start).format(defaultFormat)} - ${moment(end).format(defaultFormat)}`
|
|
44
|
+
: null);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
if (showMonthCalender && !showYearCalender && !showMonthYearPicker) {
|
|
48
|
+
setShowMonthCalender(false);
|
|
49
|
+
setTempMonthValue(dates);
|
|
50
|
+
}
|
|
51
|
+
else if (showYearCalender && !showYearPicker) {
|
|
52
|
+
setShowYearCalender(false);
|
|
53
|
+
setTempYearValue(dates);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const selectedDate = dates;
|
|
57
|
+
setTempValue(selectedDate ?? undefined);
|
|
58
|
+
if (showTimeInput)
|
|
59
|
+
return;
|
|
60
|
+
setStartDate(selectedDate ?? undefined);
|
|
61
|
+
setEndDate(undefined);
|
|
62
|
+
onChange && onChange(selectedDate ? moment(selectedDate).format(defaultFormat) : null);
|
|
63
|
+
setIsOpen(false);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const [tempValue, setTempValue] = useState(undefined);
|
|
68
|
+
const [tempMonthValue, setTempMonthValue] = useState(undefined);
|
|
69
|
+
const [tempYearValue, setTempYearValue] = useState(undefined);
|
|
70
|
+
const clearDate = () => {
|
|
71
|
+
setStartDate(undefined);
|
|
72
|
+
setEndDate(undefined);
|
|
73
|
+
setTempValue(undefined);
|
|
74
|
+
onChange && onChange(null);
|
|
75
|
+
setIsOpen(false);
|
|
76
|
+
if (showTimeInput) {
|
|
77
|
+
setTime({
|
|
78
|
+
h: isEndDay ? 23 : 0,
|
|
79
|
+
mm: isEndDay ? 59 : 0,
|
|
80
|
+
ss: isEndDay ? 59 : 0,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
onClear && onClear();
|
|
84
|
+
};
|
|
85
|
+
const increaseHours = () => {
|
|
86
|
+
if (time.h < 23)
|
|
87
|
+
setTime((prev) => ({ ...prev, h: prev.h + 1 }));
|
|
88
|
+
if (time.h === 23)
|
|
89
|
+
setTime((prev) => ({ ...prev, h: 0 }));
|
|
90
|
+
};
|
|
91
|
+
const decreaseHours = () => {
|
|
92
|
+
if (time.h > 0)
|
|
93
|
+
setTime((prev) => ({ ...prev, h: prev.h - 1 }));
|
|
94
|
+
if (time.h === 0)
|
|
95
|
+
setTime((prev) => ({ ...prev, h: 23 }));
|
|
96
|
+
};
|
|
97
|
+
const increaseMinuts = () => {
|
|
98
|
+
if (time.mm < 59)
|
|
99
|
+
setTime((prev) => ({ ...prev, mm: prev.mm + 1 }));
|
|
100
|
+
if (time.mm === 59)
|
|
101
|
+
setTime((prev) => ({ ...prev, mm: 0 }));
|
|
102
|
+
};
|
|
103
|
+
const decreaseMinuts = () => {
|
|
104
|
+
if (time.mm > 0)
|
|
105
|
+
setTime((prev) => ({ ...prev, mm: prev.mm - 1 }));
|
|
106
|
+
if (time.mm === 0)
|
|
107
|
+
setTime((prev) => ({ ...prev, mm: 59 }));
|
|
108
|
+
};
|
|
109
|
+
const increaseSeconds = () => {
|
|
110
|
+
if (time.ss < 59)
|
|
111
|
+
setTime((prev) => ({ ...prev, ss: prev.ss + 1 }));
|
|
112
|
+
if (time.ss === 59)
|
|
113
|
+
setTime((prev) => ({ ...prev, ss: 0 }));
|
|
114
|
+
};
|
|
115
|
+
const decreaseSeconds = () => {
|
|
116
|
+
if (time.ss > 0)
|
|
117
|
+
setTime((prev) => ({ ...prev, ss: prev.ss - 1 }));
|
|
118
|
+
if (time.ss === 0)
|
|
119
|
+
setTime((prev) => ({ ...prev, ss: 59 }));
|
|
120
|
+
};
|
|
121
|
+
function timeKeyDown(e, increaseNum, decreaseNum) {
|
|
122
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
123
|
+
e.stopPropagation();
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
}
|
|
126
|
+
else if (e.key === 'ArrowUp') {
|
|
127
|
+
e.stopPropagation();
|
|
128
|
+
increaseNum();
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
}
|
|
131
|
+
else if (e.key === 'ArrowDown') {
|
|
132
|
+
e.stopPropagation();
|
|
133
|
+
decreaseNum();
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const handleClickOutside = (event) => {
|
|
138
|
+
const inputElement = datePickerRef.current;
|
|
139
|
+
if (inputElement && !inputElement.contains(event.target)) {
|
|
140
|
+
setIsOpen(false);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
// Add event listener to detect clicks outside
|
|
145
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
146
|
+
// Clean up the event listener
|
|
147
|
+
return () => {
|
|
148
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
149
|
+
};
|
|
150
|
+
}, []);
|
|
151
|
+
const dayClassName = (date) => {
|
|
152
|
+
if (tempValue && moment(date).isSame(tempValue, 'day')) {
|
|
153
|
+
return 'selected-day';
|
|
154
|
+
}
|
|
155
|
+
return '';
|
|
156
|
+
};
|
|
157
|
+
const monthClassName = (date) => {
|
|
158
|
+
if (tempMonthValue && moment(date).isSame(tempMonthValue, 'month')) {
|
|
159
|
+
return 'selected-day';
|
|
160
|
+
}
|
|
161
|
+
return '';
|
|
162
|
+
};
|
|
163
|
+
const yearClassName = (date) => {
|
|
164
|
+
if (tempYearValue && moment(date).isSame(tempYearValue, 'year')) {
|
|
165
|
+
return 'selected-day';
|
|
166
|
+
}
|
|
167
|
+
return '';
|
|
168
|
+
};
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
if (startDate) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
setTempValue(undefined);
|
|
175
|
+
setTempMonthValue(undefined);
|
|
176
|
+
setTempYearValue(undefined);
|
|
177
|
+
}
|
|
178
|
+
}, [isOpen]);
|
|
179
|
+
return (_jsxs("div", { className: `custom-datepicker ${className} ${size}`, children: [label && _jsx(Label, { required: required, label: label }), _jsx("div", { className: "datepicker-input-wrapper", ref: datePickerRef, children: _jsx(DatePicker, { id: id, selected: startDate, onChange: handleDateChange, selectsRange: isRange, startDate: isRange ? startDate : undefined, endDate: isRange ? endDate : undefined, showYearPicker: showYearCalender, showMonthYearPicker: showMonthCalender, showPopperArrow: false, showTimeInput: !showMonthCalender && !showYearCalender && showTimeInput, timeInputLabel: timeInputLabel, dateFormat: timeUnit === 'monthly' ? 'MM YYYY' : defaultFormat, minDate: minDate ? (moment.isMoment(minDate) ? minDate.toDate() : new Date(minDate)) : undefined, maxDate: maxDate ? (moment.isMoment(maxDate) ? maxDate.toDate() : new Date(maxDate)) : undefined, disabled: disabled, showTimeSelect: timePicker, timeFormat: "HH:mm:ss", yearClassName: yearClassName, monthClassName: monthClassName, dayClassName: dayClassName, timeIntervals: 1, open: isOpen, customInput: _jsxs("div", { className: `${`datepicker-custom-input`} ${disabled ? `disabled` : ''}`, children: [_jsx("input", { value: startDate ? moment(startDate).format(defaultFormat) : '', onClick: toggleDatePicker, readOnly: true, disabled: disabled, placeholder: placeholder }), clearable && startDate && !disabled && (_jsx(ClearField, { onClick: (e) => {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
e.stopPropagation();
|
|
182
|
+
clearDate();
|
|
183
|
+
}, height: 16, width: 16, className: "date-picker-clear-icon" })), _jsx(CalendarIcon, { width: 24, height: 24, onClick: toggleDatePicker, className: `calendarIcon ${disabled || !startDate ? `disabled` : ''}` })] }), renderCustomHeader: ({ date, decreaseMonth, increaseMonth, increaseYear, decreaseYear, prevMonthButtonDisabled, nextMonthButtonDisabled, }) => (_jsxs("div", { style: {
|
|
184
|
+
display: 'flex',
|
|
185
|
+
alignItems: 'center',
|
|
186
|
+
justifyContent: 'space-between',
|
|
187
|
+
}, children: [_jsx("button", { onClick: showMonthCalender ? decreaseYear : decreaseMonth, disabled: prevMonthButtonDisabled, style: {
|
|
188
|
+
backgroundColor: '#fff',
|
|
189
|
+
border: 'none',
|
|
190
|
+
cursor: 'pointer',
|
|
191
|
+
}, children: _jsx(LeftArrowIcon, { width: '0.875rem', height: '0.875rem' }) }), _jsx("div", { style: {
|
|
192
|
+
margin: 10,
|
|
193
|
+
display: 'flex',
|
|
194
|
+
justifyContent: 'center',
|
|
195
|
+
cursor: 'pointer',
|
|
196
|
+
}, onClick: () => {
|
|
197
|
+
if (showMonthCalender) {
|
|
198
|
+
return setShowYearCalender(true);
|
|
199
|
+
}
|
|
200
|
+
if (showYearCalender) {
|
|
201
|
+
return setShowMonthCalender(true);
|
|
202
|
+
}
|
|
203
|
+
setShowMonthCalender(true);
|
|
204
|
+
}, children: showYearCalender
|
|
205
|
+
? 'Select a year'
|
|
206
|
+
: showMonthCalender
|
|
207
|
+
? moment(new Date(date)).format('YYYY')
|
|
208
|
+
: moment(new Date(date)).format('MMMM YYYY') }), _jsx("button", { onClick: showMonthCalender ? increaseYear : increaseMonth, disabled: nextMonthButtonDisabled, style: {
|
|
209
|
+
backgroundColor: '#fff',
|
|
210
|
+
border: 'none',
|
|
211
|
+
cursor: 'pointer',
|
|
212
|
+
}, children: _jsx(RightArrowIcon, { width: '0.875rem', height: '0.875rem' }) })] })), customTimeInput: _jsxs(_Fragment, { children: [_jsx("hr", { className: `separator` }), _jsxs("div", { className: `timePicker`, children: [_jsxs("div", { className: `inputContainer`, children: [_jsx("input", { className: `hours`, "data-id": "HOURS_TIME_PICKER", type: "number", value: time.h < 10 ? `0${time.h}` : time.h, readOnly: true, onKeyDown: (e) => timeKeyDown(e, increaseHours, decreaseHours) }), _jsxs("div", { className: `time-picker-buttons`, children: [_jsx("span", { className: `button`, onClick: increaseHours, children: _jsx(ArrowBottomIcon, { width: '1.5rem', height: '1.5rem' }) }), _jsx("span", { className: `button`, onClick: decreaseHours, children: _jsx(ArrowUpIcon, { width: '1.5rem', height: '1.5rem' }) })] })] }), _jsxs("div", { className: `inputContainer`, children: [_jsx("input", { className: `minutes`, type: "number", value: time.mm < 10 ? `0${time.mm}` : time.mm, readOnly: true, onKeyDown: (e) => timeKeyDown(e, increaseMinuts, decreaseMinuts) }), _jsxs("div", { className: `buttons`, children: [_jsx("span", { className: `button`, onClick: increaseMinuts, children: _jsx(ArrowBottomIcon, { width: '1.5rem', height: '1.5rem' }) }), _jsx("span", { className: `button`, onClick: decreaseMinuts, children: _jsx(ArrowUpIcon, { width: '1.5rem', height: '1.5rem' }) })] })] }), _jsxs("div", { className: `inputContainer`, children: [_jsx("input", { className: `seconds`, type: "number", value: time.ss < 10 ? `0${time.ss}` : time.ss, readOnly: true, onKeyDown: (e) => timeKeyDown(e, increaseSeconds, decreaseSeconds) }), _jsxs("div", { className: `buttons`, children: [_jsx("span", { className: `button`, onClick: increaseSeconds, children: _jsx(ArrowBottomIcon, { width: '1.5rem', height: '1.5rem' }) }), _jsx("span", { className: `button`, onClick: decreaseSeconds, children: _jsx(ArrowUpIcon, { width: '1.5rem', height: '1.5rem' }) })] })] })] }), _jsx(Button, { className: `submit`, variant: "outlined", fullWidth: true, disabled: !tempValue, onClick: () => {
|
|
213
|
+
if (tempValue) {
|
|
214
|
+
const updatedDate = moment(tempValue)
|
|
215
|
+
.set('hour', time.h)
|
|
216
|
+
.set('minute', time.mm)
|
|
217
|
+
.set('second', time.ss)
|
|
218
|
+
.format(defaultFormat);
|
|
219
|
+
onChange(updatedDate);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
onChange(null);
|
|
223
|
+
}
|
|
224
|
+
setIsOpen(false);
|
|
225
|
+
}, children: "Submit" })] }) }) }), helperText && _jsx("small", { children: helperText }), errorMsg && _jsx("small", { className: "error-text", children: errorMsg })] }));
|
|
226
|
+
};
|
|
227
|
+
export default ArenaDatePicker;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ArenaDatePicker';
|