diginet-core-ui 1.3.24
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/assets/avatar/default.svg +3 -0
- package/assets/images/menu/dhr/Default.svg +13 -0
- package/assets/images/menu/dhr/MHRM00N0001.svg +14 -0
- package/assets/images/menu/dhr/MHRM09N0001.svg +1 -0
- package/assets/images/menu/dhr/MHRM09N0002.svg +3 -0
- package/assets/images/menu/dhr/MHRM09N0003.svg +25 -0
- package/assets/images/menu/dhr/MHRM25N0001.svg +26 -0
- package/assets/images/menu/dhr/MHRM29N0001.svg +30 -0
- package/assets/images/menu/dhr/MHRM29N0015.svg +63 -0
- package/assets/images/menu/dhr/MHRM39N0012.svg +43 -0
- package/assets/images/menu/dhr/MHRM39N0013.svg +24 -0
- package/assets/images/menu/dhr/MHRM39N0014.svg +14 -0
- package/assets/images/menu/dhr/MHRM39N0015.svg +36 -0
- package/assets/images/menu/dhr/MHRM39N0016.svg +23 -0
- package/assets/images/menu/dhr/MHRM77N0001.svg +28 -0
- package/assets/images/menu/dhr/MHRM84N0001.svg +27 -0
- package/assets/images/menu/dhr/MHRM84N0002.svg +24 -0
- package/assets/images/menu/dhr/MHRM89N0001.svg +16 -0
- package/assets/images/menu/dhr/MHRP00N0001.svg +10 -0
- package/assets/images/menu/dhr/MHRP09N0001.svg +22 -0
- package/assets/images/menu/dhr/MHRP09N0002.svg +19 -0
- package/assets/images/menu/dhr/MHRP09N0003.svg +12 -0
- package/assets/images/menu/dhr/MHRP09N0004.svg +6 -0
- package/assets/images/menu/dhr/MHRP09N0005.svg +10 -0
- package/assets/images/menu/dhr/MHRP09N0006.svg +17 -0
- package/assets/images/menu/dhr/MHRP09N0007.svg +15 -0
- package/assets/images/menu/dhr/MHRP09N0008.svg +8 -0
- package/assets/images/menu/dhr/MHRP09N0009.svg +10 -0
- package/assets/images/menu/dhr/MHRP09N0010.svg +12 -0
- package/assets/images/menu/dhr/MHRP09N0011.svg +16 -0
- package/assets/images/menu/dhr/MHRP09N0012.svg +6 -0
- package/assets/images/menu/dhr/MHRP09N0013.svg +8 -0
- package/assets/images/menu/dhr/MHRP09N0014.svg +11 -0
- package/assets/images/menu/dhr/MHRP09N0015.svg +12 -0
- package/assets/images/menu/dhr/MHRP09N0016.svg +18 -0
- package/assets/images/menu/dhr/MHRP09N0017.svg +18 -0
- package/assets/images/menu/dhr/MHRP09N0018.svg +12 -0
- package/assets/images/menu/dhr/MHRP09N0019.svg +13 -0
- package/assets/images/menu/dhr/MHRP09N0020.svg +17 -0
- package/assets/images/menu/dhr/MHRP09N0021.svg +10 -0
- package/assets/images/menu/dhr/MHRP09N0022.svg +16 -0
- package/assets/images/menu/dhr/MHRP09N0023.svg +8 -0
- package/assets/images/menu/dhr/MHRP09N0024.svg +15 -0
- package/assets/images/menu/dhr/MHRP09N0025.svg +16 -0
- package/assets/images/menu/dhr/MHRP09N0026.svg +13 -0
- package/assets/images/menu/dhr/MHRP09N0027.svg +10 -0
- package/assets/images/menu/dhr/MHRP13N0001.svg +9 -0
- package/assets/images/menu/dhr/MHRP21N0001.svg +12 -0
- package/assets/images/menu/dhr/MHRP21N0002.svg +13 -0
- package/assets/images/menu/dhr/MHRP25N0001.svg +13 -0
- package/assets/images/menu/dhr/MHRP25N0002.svg +16 -0
- package/assets/images/menu/dhr/MHRP25N0003.svg +38 -0
- package/assets/images/menu/dhr/MHRP25N0004.svg +17 -0
- package/assets/images/menu/dhr/MHRP25N0005.svg +20 -0
- package/assets/images/menu/dhr/MHRP29N0001.svg +18 -0
- package/assets/images/menu/dhr/MHRP29N0002.svg +15 -0
- package/assets/images/menu/dhr/MHRP29N0003.svg +20 -0
- package/assets/images/menu/dhr/MHRP29N0004.svg +21 -0
- package/assets/images/menu/dhr/MHRP29N0005.svg +21 -0
- package/assets/images/menu/dhr/MHRP29N0006.svg +14 -0
- package/assets/images/menu/dhr/MHRP29N0007.svg +19 -0
- package/assets/images/menu/dhr/MHRP29N0008.svg +20 -0
- package/assets/images/menu/dhr/MHRP29N0009.svg +11 -0
- package/assets/images/menu/dhr/MHRP29N0010.svg +11 -0
- package/assets/images/menu/dhr/MHRP29N0011.svg +12 -0
- package/assets/images/menu/dhr/MHRP29N0013.svg +27 -0
- package/assets/images/menu/dhr/MHRP29N0014.svg +32 -0
- package/assets/images/menu/dhr/MHRP29N0016.svg +54 -0
- package/assets/images/menu/dhr/MHRP29N0017.svg +24 -0
- package/assets/images/menu/dhr/MHRP29N0018.svg +44 -0
- package/assets/images/menu/dhr/MHRP29N0019.svg +17 -0
- package/assets/images/menu/dhr/MHRP29N0020.svg +11 -0
- package/assets/images/menu/dhr/MHRP38N0001.svg +13 -0
- package/assets/images/menu/dhr/MHRP38N0002.svg +14 -0
- package/assets/images/menu/dhr/MHRP39N0001.svg +15 -0
- package/assets/images/menu/dhr/MHRP39N0002.svg +13 -0
- package/assets/images/menu/dhr/MHRP39N0003.svg +16 -0
- package/assets/images/menu/dhr/MHRP39N0004.svg +22 -0
- package/assets/images/menu/dhr/MHRP39N0005.svg +16 -0
- package/assets/images/menu/dhr/MHRP39N0006.svg +17 -0
- package/assets/images/menu/dhr/MHRP39N0007.svg +13 -0
- package/assets/images/menu/dhr/MHRP39N0008.svg +3 -0
- package/assets/images/menu/dhr/MHRP39N0009.svg +3 -0
- package/assets/images/menu/dhr/MHRP39N0010.svg +7 -0
- package/assets/images/menu/dhr/MHRP39N0011.svg +14 -0
- package/assets/images/menu/dhr/MHRP39N0013.svg +10 -0
- package/assets/images/menu/dhr/MHRP39N0014.svg +11 -0
- package/assets/images/menu/dhr/MHRP39N1222.svg +12 -0
- package/assets/images/menu/dhr/MHRP51N0001.svg +9 -0
- package/assets/images/menu/dhr/MHRP51N0002.svg +13 -0
- package/assets/images/menu/dhr/MHRP52N0001.svg +21 -0
- package/assets/images/menu/dhr/MHRP52N0002.svg +21 -0
- package/assets/images/menu/dhr/MHRP52N0003.svg +16 -0
- package/assets/images/menu/dhr/MHRP75N0001.svg +19 -0
- package/assets/images/menu/dhr/MHRP75N0002.svg +25 -0
- package/assets/images/menu/dhr/MHRP75N0003.svg +3 -0
- package/assets/images/menu/dhr/MHRP75N0006.svg +14 -0
- package/assets/images/menu/dhr/MHRP75N0007.svg +19 -0
- package/assets/images/menu/dhr/MHRP75N0008.svg +19 -0
- package/assets/images/menu/dhr/MHRP77N0007.svg +28 -0
- package/assets/images/menu/dhr/MHRP77N0008.svg +17 -0
- package/assets/images/menu/dhr/MHRP77N0009.svg +19 -0
- package/assets/images/menu/dhr/MHRP77N0010.svg +20 -0
- package/assets/images/menu/dhr/MHRP89N1000.svg +6 -0
- package/assets/images/menu/dhr/MHRP89N1001.svg +6 -0
- package/assets/images/menu/dhr/W00F0001.svg +3 -0
- package/assets/images/menu/dhr/W00F0002.svg +3 -0
- package/assets/images/menu/dhr/W00F0003.svg +3 -0
- package/assets/images/menu/dhr/W00F0004.svg +3 -0
- package/assets/images/menu/dhr/W00F0005.svg +1 -0
- package/assets/images/menu/dhr/W09F2000-WEB5.svg +17 -0
- package/assets/images/menu/dhr/W09F2000.svg +6 -0
- package/assets/images/menu/dhr/W09F2002-WEB5.svg +21 -0
- package/assets/images/menu/dhr/W09F2005-WEB5.svg +13 -0
- package/assets/images/menu/dhr/W09F2020-WEB5.svg +16 -0
- package/assets/images/menu/dhr/W09F2022-WEB5.svg +20 -0
- package/assets/images/menu/dhr/W09F2150-WEB5.svg +16 -0
- package/assets/images/menu/dhr/W09F2152-WEB5.svg +20 -0
- package/assets/images/menu/dhr/W09F2160-WEB5.svg +14 -0
- package/assets/images/menu/dhr/W09F2162-WEB5.svg +18 -0
- package/assets/images/menu/dhr/W29F4006-WEB5.svg +19 -0
- package/assets/images/menu/dhr/W75F2260-WEB5.svg +15 -0
- package/assets/images/menu/dhr/W75F2261-WEB5.svg +19 -0
- package/assets/images/menu/dhr/W75F3005-WEB5.svg +13 -0
- package/assets/images/menu/dhr/W75F4070-WEB5.svg +21 -0
- package/assets/images/menu/dhr/W75F4071-WEB5.svg +17 -0
- package/assets/images/menu/dhr/W75F4100-WEB5.svg +14 -0
- package/assets/images/menu/dhr/W77F1011.svg +19 -0
- package/assets/images/menu/dhr/W77F1013.svg +22 -0
- package/assets/images/menu/erp/W00F0001.svg +3 -0
- package/assets/images/menu/erp/W00F0002.svg +3 -0
- package/assets/images/menu/erp/W00F0003.svg +3 -0
- package/assets/images/menu/erp/W00F0004.svg +3 -0
- package/assets/images/menu/erp/W05F0001.svg +16 -0
- package/assets/images/menu/erp/W05F0001N0000.svg +16 -0
- package/assets/images/menu/erp/W05F0004N0000.svg +6 -0
- package/assets/images/menu/erp/W05F0006.svg +30 -0
- package/assets/images/menu/erp/W05F0007N0000.svg +6 -0
- package/assets/images/menu/erp/W05F0008.svg +14 -0
- package/assets/images/menu/erp/W05F4000.svg +9 -0
- package/assets/images/menu/erp/W06F0001.svg +17 -0
- package/assets/images/menu/erp/W06F0001N0000.svg +17 -0
- package/assets/images/menu/erp/W06F0004N0000.svg +22 -0
- package/assets/images/menu/erp/W06F0005.svg +22 -0
- package/assets/images/menu/erp/W06F0006.svg +55 -0
- package/assets/images/menu/erp/W06F0008.svg +17 -0
- package/assets/images/menu/erp/WA3F1025.svg +5 -0
- package/assets/images/menu/erp/WA3F2100.svg +10 -0
- package/components/accordion/context.js +6 -0
- package/components/accordion/css.js +159 -0
- package/components/accordion/details.js +60 -0
- package/components/accordion/group.js +122 -0
- package/components/accordion/index.js +117 -0
- package/components/accordion/summary.js +175 -0
- package/components/alert/index.js +264 -0
- package/components/alert/notify.js +192 -0
- package/components/avatar/index.js +556 -0
- package/components/badge/index.js +223 -0
- package/components/button/icon.js +493 -0
- package/components/button/index.js +653 -0
- package/components/button/more.js +135 -0
- package/components/button/ripple-effect.js +85 -0
- package/components/card/body-card.js +67 -0
- package/components/card/card.js +127 -0
- package/components/card/context.js +6 -0
- package/components/card/index.js +50 -0
- package/components/chart/Pie/Circle.js +50 -0
- package/components/chart/Pie/Sector.js +142 -0
- package/components/chart/Pie/Sectors.js +91 -0
- package/components/chart/Pie/index.js +311 -0
- package/components/chart/Pie-v2/Circle.js +50 -0
- package/components/chart/Pie-v2/Sector.js +128 -0
- package/components/chart/Pie-v2/Sectors.js +224 -0
- package/components/chart/Pie-v2/index.js +397 -0
- package/components/chart/bar/Axis.js +79 -0
- package/components/chart/bar/Bar.js +365 -0
- package/components/chart/bar/Grid.js +115 -0
- package/components/chart/bar/Labels.js +175 -0
- package/components/chart/bar/Points.js +111 -0
- package/components/chart/bar/index.js +172 -0
- package/components/chart/bar-v2/Axis.js +79 -0
- package/components/chart/bar-v2/Bar.js +374 -0
- package/components/chart/bar-v2/Grid.js +115 -0
- package/components/chart/bar-v2/Labels.js +175 -0
- package/components/chart/bar-v2/Points.js +111 -0
- package/components/chart/bar-v2/index.js +172 -0
- package/components/chart/line/Axis.js +79 -0
- package/components/chart/line/Grid.js +115 -0
- package/components/chart/line/Labels.js +172 -0
- package/components/chart/line/Path.js +163 -0
- package/components/chart/line/Point.js +348 -0
- package/components/chart/line/Title.js +56 -0
- package/components/chart/line/index.js +174 -0
- package/components/chart/line-v2/Axis.js +79 -0
- package/components/chart/line-v2/Grid.js +115 -0
- package/components/chart/line-v2/Labels.js +172 -0
- package/components/chart/line-v2/Path.js +163 -0
- package/components/chart/line-v2/Point.js +354 -0
- package/components/chart/line-v2/Title.js +56 -0
- package/components/chart/line-v2/index.js +174 -0
- package/components/check-text/index.js +157 -0
- package/components/check-text/interview-confirmation.js +172 -0
- package/components/check-text/interview-status.js +138 -0
- package/components/chip/attach.js +180 -0
- package/components/chip/index.js +340 -0
- package/components/collapse/index.js +67 -0
- package/components/dialogs/colors.js +11 -0
- package/components/divider/index.js +71 -0
- package/components/divider/style.js +12 -0
- package/components/form-control/attachment/index.js +1890 -0
- package/components/form-control/calendar/function.js +673 -0
- package/components/form-control/calendar/index.js +248 -0
- package/components/form-control/calendar/range.js +293 -0
- package/components/form-control/checkbox/index.js +306 -0
- package/components/form-control/control/index.js +92 -0
- package/components/form-control/date-picker/index-old.js +953 -0
- package/components/form-control/date-picker/index.js +676 -0
- package/components/form-control/date-range-picker/index.js +1305 -0
- package/components/form-control/dropdown/index.js +1865 -0
- package/components/form-control/dropdown-box/index.js +292 -0
- package/components/form-control/form/context.js +5 -0
- package/components/form-control/form/index.js +41 -0
- package/components/form-control/form-group/index.js +118 -0
- package/components/form-control/helper-text/index.js +71 -0
- package/components/form-control/input-base/index.js +733 -0
- package/components/form-control/label/index.js +73 -0
- package/components/form-control/money-input/index.js +491 -0
- package/components/form-control/number-input/index.js +633 -0
- package/components/form-control/phone-input/index.js +433 -0
- package/components/form-control/radio/index.js +263 -0
- package/components/form-control/text-input/index.js +523 -0
- package/components/form-control/time-picker/index.js +829 -0
- package/components/form-control/time-picker/swiper.js +590 -0
- package/components/form-control/toggle/index.js +250 -0
- package/components/form-view/helper-text.js +33 -0
- package/components/form-view/index.js +107 -0
- package/components/form-view/input.js +129 -0
- package/components/form-view/label.js +38 -0
- package/components/index.js +100 -0
- package/components/list/list-item-action.js +82 -0
- package/components/list/list-item-icon.js +76 -0
- package/components/list/list-item-text.js +57 -0
- package/components/list/list-item.js +114 -0
- package/components/list/list.js +155 -0
- package/components/list/sub-header.js +61 -0
- package/components/modal/body.js +71 -0
- package/components/modal/context.js +6 -0
- package/components/modal/footer.js +63 -0
- package/components/modal/header.js +108 -0
- package/components/modal/index.js +69 -0
- package/components/modal/modal.js +339 -0
- package/components/others/extra/index.js +124 -0
- package/components/others/scrollbar/index.js +95 -0
- package/components/paging/page-info.js +298 -0
- package/components/paging/page-selector.js +281 -0
- package/components/paper/index.js +119 -0
- package/components/popover/index.js +417 -0
- package/components/popup/danger_popup.js +215 -0
- package/components/popup/index.js +469 -0
- package/components/popup/proposals_popup.js +364 -0
- package/components/popup/v2/danger-popup.js +17 -0
- package/components/popup/v2/index.js +460 -0
- package/components/popup/v2/info-popup.js +17 -0
- package/components/popup/v2/success-popup.js +17 -0
- package/components/popup/v2/warning-popup.js +17 -0
- package/components/popup/v2/yes-no-popup.js +20 -0
- package/components/progress/circular.js +414 -0
- package/components/progress/linear.js +327 -0
- package/components/rating/index.js +392 -0
- package/components/slider/slider-container.js +356 -0
- package/components/slider/slider-item.js +183 -0
- package/components/status/index.js +123 -0
- package/components/tab/context.js +3 -0
- package/components/tab/tab-container.js +83 -0
- package/components/tab/tab-header.js +133 -0
- package/components/tab/tab-panel.js +51 -0
- package/components/tab/tab.js +206 -0
- package/components/tooltip/index.js +602 -0
- package/components/tooltip/portal.js +13 -0
- package/components/transfer/index.js +489 -0
- package/components/tree-view/css.js +94 -0
- package/components/tree-view/index.js +1009 -0
- package/components/typography/index.js +218 -0
- package/css/styles.css +1 -0
- package/css/styles.css.map +1 -0
- package/global/index.js +175 -0
- package/icons/basic.js +6326 -0
- package/icons/effect.js +171 -0
- package/icons/general/clock/clock.js +21 -0
- package/icons/general/color-handler/background.js +41 -0
- package/icons/general/color-handler/text.js +41 -0
- package/icons/general/emoji/emoji.js +35 -0
- package/icons/general/font-properties/bold.js +21 -0
- package/icons/general/font-properties/font-family.js +35 -0
- package/icons/general/font-properties/font-size.js +27 -0
- package/icons/general/font-properties/italic.js +21 -0
- package/icons/general/font-properties/underline.js +31 -0
- package/icons/general/hyperlink/hyperlink.js +38 -0
- package/icons/general/indent/decrease.js +55 -0
- package/icons/general/indent/increase.js +55 -0
- package/icons/general/index.js +21 -0
- package/icons/general/list/bullets.js +77 -0
- package/icons/general/list/numbering.js +71 -0
- package/icons/general/picture/picture.js +21 -0
- package/icons/general/steps/redo.js +21 -0
- package/icons/general/steps/undo.js +21 -0
- package/icons/general/text-align/center.js +21 -0
- package/icons/general/text-align/justify.js +21 -0
- package/icons/general/text-align/left.js +21 -0
- package/icons/general/text-align/right.js +21 -0
- package/icons/index.js +3 -0
- package/icons/menu/dhr.js +2440 -0
- package/icons/menu/erp.js +490 -0
- package/icons/menu/index.js +5 -0
- package/icons/menu/v2/index.js +52 -0
- package/locale/index.js +11 -0
- package/package.json +45 -0
- package/readme.md +517 -0
- package/styles/animation.js +890 -0
- package/styles/color-helper.js +504 -0
- package/styles/colors.js +306 -0
- package/styles/general.js +48 -0
- package/styles/media-queries.js +10 -0
- package/styles/typography.js +122 -0
- package/styles/utils.js +10 -0
- package/theme/index.js +5 -0
- package/theme/make-styles.js +95 -0
- package/theme/set-theme.js +39 -0
- package/theme/settings.js +230 -0
- package/theme/theme-provider.js +68 -0
- package/theme/theme.js +56 -0
- package/theme/with-styles.js +17 -0
- package/theme/with-theme.js +11 -0
- package/utils/array/array.js +186 -0
- package/utils/console.js +34 -0
- package/utils/date.js +471 -0
- package/utils/error/error.js +62 -0
- package/utils/error/errors.js +247 -0
- package/utils/getFileType.js +32 -0
- package/utils/index.js +23 -0
- package/utils/iterator.js +45 -0
- package/utils/map-parent.js +53 -0
- package/utils/number.js +64 -0
- package/utils/object/extend.js +57 -0
- package/utils/object/object.js +68 -0
- package/utils/parseHTML.js +8 -0
- package/utils/promisify.js +38 -0
- package/utils/randomString.js +33 -0
- package/utils/remove-unicode.js +6 -0
- package/utils/render-portal.js +90 -0
- package/utils/renderHTML.js +21 -0
- package/utils/renderIcon.js +57 -0
- package/utils/string/capitalize.js +3 -0
- package/utils/string/capitalizeSentenceCase.js +10 -0
- package/utils/string/string.js +81 -0
- package/utils/type.js +90 -0
- package/utils/updatePosition.js +36 -0
- package/utils/useOnClickOutside.js +23 -0
- package/utils/usePortal.js +56 -0
- package/utils/validate.js +149 -0
|
@@ -0,0 +1,829 @@
|
|
|
1
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
+
|
|
3
|
+
/** @jsxRuntime classic */
|
|
4
|
+
|
|
5
|
+
/** @jsx jsx */
|
|
6
|
+
import { jsx, css } from '@emotion/core';
|
|
7
|
+
import PropTypes from 'prop-types';
|
|
8
|
+
import React, { forwardRef, memo, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
9
|
+
import { Cancel as CancelIcon, Clock as ClockIcon } from '../../../icons';
|
|
10
|
+
import { randomString, useOnClickOutside } from '../../../utils';
|
|
11
|
+
import theme from '../../../theme/settings';
|
|
12
|
+
import Swiper from './swiper';
|
|
13
|
+
|
|
14
|
+
const formatDimension = x => {
|
|
15
|
+
const regexPercent = /^\d+%$/;
|
|
16
|
+
const regexPixel = /^\d+px$/;
|
|
17
|
+
|
|
18
|
+
if (isNaN(x)) {
|
|
19
|
+
if (regexPercent.test(x)) {
|
|
20
|
+
return x;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (regexPixel.test(x)) {
|
|
24
|
+
return +x.split('px')[0];
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
return x;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const addZero = i => {
|
|
32
|
+
if (isNaN(i) && +i < 10) {
|
|
33
|
+
return `0${parseInt(i, 10)}`;
|
|
34
|
+
} else if (!isNaN(i) && i < 10) {
|
|
35
|
+
return `0${i}`;
|
|
36
|
+
} else {
|
|
37
|
+
return i;
|
|
38
|
+
}
|
|
39
|
+
}; //array data
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const getHours = () => {
|
|
43
|
+
let hours = [],
|
|
44
|
+
i = 0;
|
|
45
|
+
|
|
46
|
+
for (i; i < 24; i++) {
|
|
47
|
+
hours.push({
|
|
48
|
+
value: i,
|
|
49
|
+
text: i
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return hours;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const getMinutes = () => {
|
|
57
|
+
let minutes = [],
|
|
58
|
+
i = 0;
|
|
59
|
+
|
|
60
|
+
for (i; i < 60; i++) {
|
|
61
|
+
minutes.push({
|
|
62
|
+
value: i,
|
|
63
|
+
text: i
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return minutes;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const checkValue = value => {
|
|
71
|
+
if (!isNaN(Date.parse(value))) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return false;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const getValue = value => {
|
|
79
|
+
if (typeof value === 'string') {
|
|
80
|
+
const date = new Date();
|
|
81
|
+
value = value.split(/\D+/);
|
|
82
|
+
value[2] = value[2] || 0;
|
|
83
|
+
date.setHours(...value);
|
|
84
|
+
value = date;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (checkValue(value)) {
|
|
88
|
+
return new Date(value);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new Date();
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const TimePicker = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(({
|
|
95
|
+
activeHeight,
|
|
96
|
+
activeWidth,
|
|
97
|
+
allowSeconds,
|
|
98
|
+
defaultValue,
|
|
99
|
+
disabled,
|
|
100
|
+
error,
|
|
101
|
+
label,
|
|
102
|
+
inputProps,
|
|
103
|
+
inputRef,
|
|
104
|
+
onChange,
|
|
105
|
+
required,
|
|
106
|
+
value,
|
|
107
|
+
viewType,
|
|
108
|
+
...props
|
|
109
|
+
}, ref) => {
|
|
110
|
+
const Id = randomString(7, {
|
|
111
|
+
allowSymbol: false,
|
|
112
|
+
allowNumber: false
|
|
113
|
+
});
|
|
114
|
+
const IDs = {
|
|
115
|
+
clock: 'DCUI-time-picker-clock' + Id,
|
|
116
|
+
container: 'DCUI-time-picker-container' + Id,
|
|
117
|
+
icon: 'DCUI-time-picker-icon' + Id,
|
|
118
|
+
inputTypeText: 'DCUI-time-picker-input-type-text' + Id,
|
|
119
|
+
inputWrapper: 'DCUI-time-picker-input-wrapper' + Id,
|
|
120
|
+
main: 'DCUI-time-picker-main' + Id,
|
|
121
|
+
label: 'DCUI-time-picker-label' + Id
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
if (!ref) {
|
|
125
|
+
ref = useRef(null);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (!inputRef) {
|
|
129
|
+
inputRef = useRef(null);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const mainRef = useRef(null);
|
|
133
|
+
const clockContainerRef = useRef(null);
|
|
134
|
+
const swiperWrapperHoursRef = useRef(null);
|
|
135
|
+
const swiperWrapperMinutesRef = useRef(null);
|
|
136
|
+
const swiperWrapperSecondsRef = useRef(null);
|
|
137
|
+
let values = [];
|
|
138
|
+
const styles = {
|
|
139
|
+
container: {
|
|
140
|
+
outlined: css`
|
|
141
|
+
* {
|
|
142
|
+
box-sizing: border-box;
|
|
143
|
+
font-family: ${theme.typography.fontFamily};
|
|
144
|
+
}
|
|
145
|
+
margin: 0;
|
|
146
|
+
padding: 0;
|
|
147
|
+
&.disabled {
|
|
148
|
+
.${IDs.label} {
|
|
149
|
+
color: ${theme.colors.disabled} !important;
|
|
150
|
+
pointer-events: none;
|
|
151
|
+
user-select: none;
|
|
152
|
+
}
|
|
153
|
+
#${IDs.inputTypeText} {
|
|
154
|
+
pointer-events: none;
|
|
155
|
+
user-select: none;
|
|
156
|
+
::placeholder {
|
|
157
|
+
color: ${theme.colors.input};
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
.${IDs.icon}.svg-default {
|
|
161
|
+
color: ${theme.colors.disabled} !important;
|
|
162
|
+
pointer-events: none;
|
|
163
|
+
user-select: none;
|
|
164
|
+
}
|
|
165
|
+
.${IDs.main} {
|
|
166
|
+
background-color: ${theme.colors.bgDisabled};
|
|
167
|
+
pointer-events: none;
|
|
168
|
+
::before {
|
|
169
|
+
border-color: ${theme.colors.disabled} !important;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
`,
|
|
174
|
+
underlined: css`
|
|
175
|
+
* {
|
|
176
|
+
box-sizing: border-box;
|
|
177
|
+
}
|
|
178
|
+
margin: 0;
|
|
179
|
+
padding: 0;
|
|
180
|
+
&.disabled {
|
|
181
|
+
.${IDs.label} {
|
|
182
|
+
color: ${theme.colors.disabled} !important;
|
|
183
|
+
pointer-events: none;
|
|
184
|
+
user-select: none;
|
|
185
|
+
}
|
|
186
|
+
#${IDs.inputTypeText} {
|
|
187
|
+
pointer-events: none;
|
|
188
|
+
user-select: none;
|
|
189
|
+
::placeholder {
|
|
190
|
+
color: ${theme.colors.input};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
.${IDs.icon}.svg-default {
|
|
194
|
+
color: ${theme.colors.disabled} !important;
|
|
195
|
+
pointer-events: none;
|
|
196
|
+
user-select: none;
|
|
197
|
+
}
|
|
198
|
+
.${IDs.main} {
|
|
199
|
+
pointer-events: none;
|
|
200
|
+
::after, ::before {
|
|
201
|
+
border-color: ${theme.colors.disabled} !important;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
`
|
|
206
|
+
},
|
|
207
|
+
label: {
|
|
208
|
+
container: css`
|
|
209
|
+
display: flex;
|
|
210
|
+
margin-bottom: 4px;
|
|
211
|
+
label {
|
|
212
|
+
color: ${theme.colors.label};
|
|
213
|
+
font-size: 12px;
|
|
214
|
+
font-weight: 700;
|
|
215
|
+
pointer-events: initial;
|
|
216
|
+
user-select: initial;
|
|
217
|
+
}
|
|
218
|
+
`,
|
|
219
|
+
required: css`
|
|
220
|
+
color: ${theme.colors.danger};
|
|
221
|
+
font-size: 12px;
|
|
222
|
+
font-weight: bold;
|
|
223
|
+
`
|
|
224
|
+
},
|
|
225
|
+
main: {
|
|
226
|
+
outlined: css`
|
|
227
|
+
background-color: white;
|
|
228
|
+
border-radius: 4px;
|
|
229
|
+
display: flex;
|
|
230
|
+
flex-direction: column;
|
|
231
|
+
height: 40px;
|
|
232
|
+
pointer-events: initial;
|
|
233
|
+
position: relative;
|
|
234
|
+
width: 100%;
|
|
235
|
+
::before {
|
|
236
|
+
background-color: transparent;
|
|
237
|
+
border-radius: 4px;
|
|
238
|
+
border: solid 1px ${theme.colors.border};
|
|
239
|
+
bottom: 0;
|
|
240
|
+
content: '\\00a0';
|
|
241
|
+
left: 0;
|
|
242
|
+
pointer-events: none;
|
|
243
|
+
position: absolute;
|
|
244
|
+
right: 0;
|
|
245
|
+
top: 0;
|
|
246
|
+
transition: border-color 0.2s ease;
|
|
247
|
+
user-select: none;
|
|
248
|
+
}
|
|
249
|
+
:hover:not(.focused):not(.error) {
|
|
250
|
+
background-color: ${theme.colors.hover};
|
|
251
|
+
::before {
|
|
252
|
+
border-color: ${theme.colors.primary};
|
|
253
|
+
}
|
|
254
|
+
input::placeholder,
|
|
255
|
+
.${IDs.icon}.svg-default {
|
|
256
|
+
color: ${theme.colors.primary};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
&.focused {
|
|
261
|
+
::before {
|
|
262
|
+
border: 2px solid ${theme.colors.info};
|
|
263
|
+
}
|
|
264
|
+
.${IDs.icon}.svg-default {
|
|
265
|
+
opacity: 0;
|
|
266
|
+
visibility: hidden;
|
|
267
|
+
}
|
|
268
|
+
.${IDs.icon}.svg-active {
|
|
269
|
+
opacity: 1;
|
|
270
|
+
visibility: visible;
|
|
271
|
+
}
|
|
272
|
+
~ .${IDs.clock} {
|
|
273
|
+
opacity: 1;
|
|
274
|
+
transform: scale(1);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
&.error {
|
|
278
|
+
::before {
|
|
279
|
+
border-color: ${theme.colors.danger};
|
|
280
|
+
}
|
|
281
|
+
.${IDs.icon}.svg-default {
|
|
282
|
+
color: ${theme.colors.danger};
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
`,
|
|
287
|
+
underlined: css`
|
|
288
|
+
display: flex;
|
|
289
|
+
flex-direction: column;
|
|
290
|
+
height: 40px;
|
|
291
|
+
pointer-events: initial;
|
|
292
|
+
position: relative;
|
|
293
|
+
width: 100%;
|
|
294
|
+
:after {
|
|
295
|
+
background-color: transparent;
|
|
296
|
+
border-bottom: 2px solid ${theme.colors.info};
|
|
297
|
+
bottom: 0;
|
|
298
|
+
content: '';
|
|
299
|
+
left: 0;
|
|
300
|
+
pointer-events: none;
|
|
301
|
+
position: absolute;
|
|
302
|
+
right: 0;
|
|
303
|
+
top: 0;
|
|
304
|
+
transform: scaleX(0);
|
|
305
|
+
transform-origin: left;
|
|
306
|
+
transition: transform 0.3s cubic-bezier(0.075, 0.82, 0.165, 1);
|
|
307
|
+
}
|
|
308
|
+
::before {
|
|
309
|
+
background-color: transparent;
|
|
310
|
+
border-bottom: solid 1px ${theme.colors.border};
|
|
311
|
+
bottom: 0;
|
|
312
|
+
content: '\\00a0';
|
|
313
|
+
left: 0;
|
|
314
|
+
pointer-events: none;
|
|
315
|
+
position: absolute;
|
|
316
|
+
right: 0;
|
|
317
|
+
top: 0;
|
|
318
|
+
transition: border-color 0.2s ease;
|
|
319
|
+
user-select: none;
|
|
320
|
+
}
|
|
321
|
+
:hover:not(.focused):not(.error) {
|
|
322
|
+
::before {
|
|
323
|
+
border-color: ${theme.colors.primary};
|
|
324
|
+
}
|
|
325
|
+
input::placeholder,
|
|
326
|
+
.${IDs.icon}.svg-default {
|
|
327
|
+
color: ${theme.colors.primary};
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
&.focused {
|
|
332
|
+
::after {
|
|
333
|
+
transform: scale(1);
|
|
334
|
+
}
|
|
335
|
+
.${IDs.icon}.svg-default {
|
|
336
|
+
opacity: 0;
|
|
337
|
+
visibility: hidden;
|
|
338
|
+
}
|
|
339
|
+
.${IDs.icon}.svg-active {
|
|
340
|
+
opacity: 1;
|
|
341
|
+
visibility: visible;
|
|
342
|
+
}
|
|
343
|
+
~ .${IDs.clock} {
|
|
344
|
+
opacity: 1;
|
|
345
|
+
transform: scale(1);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
&.error {
|
|
349
|
+
::after, ::before {
|
|
350
|
+
border-color: ${theme.colors.danger};
|
|
351
|
+
}
|
|
352
|
+
.${IDs.icon}.svg-default {
|
|
353
|
+
color: ${theme.colors.danger};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
}
|
|
357
|
+
`
|
|
358
|
+
},
|
|
359
|
+
input: {
|
|
360
|
+
outlined: css`
|
|
361
|
+
background-color: transparent;
|
|
362
|
+
border: 0;
|
|
363
|
+
font-size: 16px;
|
|
364
|
+
margin: 0;
|
|
365
|
+
outline: none;
|
|
366
|
+
padding: 10px 16px;
|
|
367
|
+
position: relative;
|
|
368
|
+
width: 100%;
|
|
369
|
+
&::placeholder {
|
|
370
|
+
color: ${theme.colors.placeholder};
|
|
371
|
+
letter-spacing: 0.0675em;
|
|
372
|
+
transition: color 0.2s cubic-bezier(0.075, 0.82, 0.165, 1) 0ms;
|
|
373
|
+
}
|
|
374
|
+
`,
|
|
375
|
+
underlined: css`
|
|
376
|
+
background-color: white;
|
|
377
|
+
border: 0;
|
|
378
|
+
font-size: 16px;
|
|
379
|
+
line-height: 20px;
|
|
380
|
+
margin: auto 0;
|
|
381
|
+
outline: none;
|
|
382
|
+
padding: 0;
|
|
383
|
+
position: relative;
|
|
384
|
+
width: 100%;
|
|
385
|
+
&::placeholder {
|
|
386
|
+
color: ${theme.colors.placeholder};
|
|
387
|
+
letter-spacing: 0.0675em;
|
|
388
|
+
transition: color 0.2s cubic-bezier(0.075, 0.82, 0.165, 1) 0ms;
|
|
389
|
+
}
|
|
390
|
+
`
|
|
391
|
+
},
|
|
392
|
+
icon: {
|
|
393
|
+
outlined: css`
|
|
394
|
+
align-items: center;
|
|
395
|
+
color: ${theme.colors.border};
|
|
396
|
+
cursor: pointer;
|
|
397
|
+
display: flex;
|
|
398
|
+
font-size: 20px;
|
|
399
|
+
height: 20px;
|
|
400
|
+
justify-content: center;
|
|
401
|
+
position: absolute;
|
|
402
|
+
top: 50%;
|
|
403
|
+
right: 20px;
|
|
404
|
+
transform: translateY(-50%);
|
|
405
|
+
transition: opacity 0.2s ease, color 0.2s ease;
|
|
406
|
+
width: 20px;
|
|
407
|
+
&.svg-active {
|
|
408
|
+
opacity: 0;
|
|
409
|
+
visibility: hidden;
|
|
410
|
+
:hover {
|
|
411
|
+
color: ${theme.colors.primary};
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
`,
|
|
415
|
+
underlined: css`
|
|
416
|
+
align-items: center;
|
|
417
|
+
color: ${theme.colors.border};
|
|
418
|
+
cursor: pointer;
|
|
419
|
+
display: flex;
|
|
420
|
+
font-size: 20px;
|
|
421
|
+
height: 20px;
|
|
422
|
+
justify-content: center;
|
|
423
|
+
position: absolute;
|
|
424
|
+
top: 50%;
|
|
425
|
+
right: 6px;
|
|
426
|
+
transform: translateY(-50%);
|
|
427
|
+
transition: opacity 0.2s ease, color 0.2s ease;
|
|
428
|
+
width: 20px;
|
|
429
|
+
&.svg-active {
|
|
430
|
+
opacity: 0;
|
|
431
|
+
visibility: hidden;
|
|
432
|
+
:hover {
|
|
433
|
+
color: ${theme.colors.primary};
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
`
|
|
437
|
+
},
|
|
438
|
+
error: {
|
|
439
|
+
outlined: css`
|
|
440
|
+
color: ${theme.colors.danger};
|
|
441
|
+
font-size: 12px;
|
|
442
|
+
font-weight: 400;
|
|
443
|
+
line-height: 12px;
|
|
444
|
+
margin-top: 8px;
|
|
445
|
+
pointer-events: none;
|
|
446
|
+
`,
|
|
447
|
+
underlined: css`
|
|
448
|
+
color: ${theme.colors.danger};
|
|
449
|
+
font-size: 12px;
|
|
450
|
+
font-weight: 400;
|
|
451
|
+
line-height: 12px;
|
|
452
|
+
bottom: -20px;
|
|
453
|
+
position: absolute;
|
|
454
|
+
pointer-events: none;
|
|
455
|
+
`
|
|
456
|
+
},
|
|
457
|
+
clock: {
|
|
458
|
+
container: css`
|
|
459
|
+
background-color: white;
|
|
460
|
+
border-radius: 4px;
|
|
461
|
+
box-shadow: 0px 4px 10px 0px rgba(0,0,0,0.25);
|
|
462
|
+
display: flex;
|
|
463
|
+
height: ${formatDimension(activeHeight)}px;
|
|
464
|
+
min-width: 120px;
|
|
465
|
+
opacity: 0;
|
|
466
|
+
position: fixed;
|
|
467
|
+
transform: scale(0);
|
|
468
|
+
transition: transform 0.2s ease-in-out, opacity 0.2s ease-out, top 0.1s linear, bottom 0.1s linear;
|
|
469
|
+
width: ${formatDimension(activeWidth)}px;
|
|
470
|
+
z-index: 9001;
|
|
471
|
+
`,
|
|
472
|
+
wrapper: css`
|
|
473
|
+
border-radius: 4px;
|
|
474
|
+
flex: 1;
|
|
475
|
+
`
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const updateValue = value => {
|
|
480
|
+
const time = getValue(value);
|
|
481
|
+
values = [addZero(time.getHours()), addZero(time.getMinutes()), addZero(time.getSeconds())];
|
|
482
|
+
setInputValue(values);
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
const getDefaultValue = () => {
|
|
486
|
+
if (value && checkValue(value)) {
|
|
487
|
+
return new Date(value);
|
|
488
|
+
} else if (defaultValue && checkValue(defaultValue)) {
|
|
489
|
+
return new Date(defaultValue);
|
|
490
|
+
} else {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
const escKeyFunc = ev => {
|
|
496
|
+
//call the useOnClickOutside when press esc key
|
|
497
|
+
if (ev.keyCode === 27) {
|
|
498
|
+
onBlur();
|
|
499
|
+
inputContainerRef.current.childNodes[0].blur();
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
const getScrollParent = element => {
|
|
504
|
+
const style = getComputedStyle(element);
|
|
505
|
+
let scrollParent = window;
|
|
506
|
+
|
|
507
|
+
if (style.position !== 'fixed') {
|
|
508
|
+
let parent = element.parentElement;
|
|
509
|
+
|
|
510
|
+
while (parent) {
|
|
511
|
+
const parentStyle = getComputedStyle(parent);
|
|
512
|
+
|
|
513
|
+
if (/(auto|scroll)/.test(parentStyle.overflow + parentStyle.overflowY + parentStyle.overflowX)) {
|
|
514
|
+
scrollParent = parent;
|
|
515
|
+
parent = undefined;
|
|
516
|
+
} else {
|
|
517
|
+
parent = parent.parentElement;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
return scrollParent;
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
const setPositionClock = () => {
|
|
526
|
+
const clock = clockContainerRef.current;
|
|
527
|
+
const container = ref.current;
|
|
528
|
+
|
|
529
|
+
if (!clock || !container) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const {
|
|
534
|
+
bottom,
|
|
535
|
+
left,
|
|
536
|
+
top
|
|
537
|
+
} = container.getBoundingClientRect();
|
|
538
|
+
|
|
539
|
+
if (top > window.innerHeight) {
|
|
540
|
+
clock.style.top = 'auto';
|
|
541
|
+
clock.style.bottom = '5px';
|
|
542
|
+
clock.style.transformOrigin = 'bottom left';
|
|
543
|
+
} else if (bottom < 0) {
|
|
544
|
+
clock.style.top = '5px';
|
|
545
|
+
clock.style.bottom = 'auto';
|
|
546
|
+
clock.style.transformOrigin = 'top left';
|
|
547
|
+
} else {
|
|
548
|
+
if (window.innerHeight - bottom < activeHeight + 10) {
|
|
549
|
+
if (top < activeHeight + 10) {
|
|
550
|
+
clock.style.top = (window.innerHeight - activeHeight) / 2 + 'px';
|
|
551
|
+
clock.style.bottom = 'auto';
|
|
552
|
+
clock.style.transformOrigin = 'center center';
|
|
553
|
+
} else {
|
|
554
|
+
clock.style.top = top - activeHeight - 10 + 'px';
|
|
555
|
+
clock.style.bottom = 'auto';
|
|
556
|
+
clock.style.transformOrigin = 'bottom left';
|
|
557
|
+
}
|
|
558
|
+
} else {
|
|
559
|
+
clock.style.bottom = 'auto';
|
|
560
|
+
clock.style.top = bottom + 5 + 'px';
|
|
561
|
+
clock.style.transformOrigin = 'top left';
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (left < 0) {
|
|
566
|
+
clock.style.left = '5px';
|
|
567
|
+
} else if (left + activeWidth > window.innerWidth) {
|
|
568
|
+
clock.style.left = (window.innerWidth - activeWidth) / 2 + 'px';
|
|
569
|
+
} else {
|
|
570
|
+
clock.style.left = left + 'px';
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
const setInputValue = values => {
|
|
575
|
+
if (!inputRef.current) return;
|
|
576
|
+
const input = inputRef.current;
|
|
577
|
+
|
|
578
|
+
if (allowSeconds) {
|
|
579
|
+
input.value = values[0] + ':' + values[1] + ':' + values[2];
|
|
580
|
+
} else {
|
|
581
|
+
input.value = values[0] + ':' + values[1] + ':00';
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
if (onChange) onChange(input);
|
|
585
|
+
};
|
|
586
|
+
|
|
587
|
+
const onFocus = () => {
|
|
588
|
+
document.body.style.overflow = 'hidden';
|
|
589
|
+
mainRef.current.classList.add('focused');
|
|
590
|
+
setPositionClock();
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
const onBlur = () => {
|
|
594
|
+
mainRef.current.classList.remove('focused');
|
|
595
|
+
inputRef.current.blur();
|
|
596
|
+
document.body.style.overflow = null;
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
const onOpen = () => {
|
|
600
|
+
inputRef.current.focus();
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
const onClose = () => onBlur();
|
|
604
|
+
|
|
605
|
+
useOnClickOutside(ref, onBlur); // const validateValue = (text) => {
|
|
606
|
+
// const timeRegex = /^(0?[0-9]|1[0-9]|2[0-3])(:(0?[0-9]|[1-5][0-9]))?(:(0?[0-9]|[1-5][0-9]))$/;
|
|
607
|
+
// if (timeRegex.test(text)) return true;
|
|
608
|
+
// return false;
|
|
609
|
+
// };
|
|
610
|
+
|
|
611
|
+
const validateKeyboard = e => {
|
|
612
|
+
if (!/[0-9:]/.test(e.key)) {
|
|
613
|
+
e.preventDefault();
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
|
|
617
|
+
const setInputHour = e => {
|
|
618
|
+
if (!inputRef.current) return;
|
|
619
|
+
values = inputRef.current.value.split(':');
|
|
620
|
+
values.splice(0, 1, addZero(e.text));
|
|
621
|
+
setInputValue(values);
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
const setInputMinute = e => {
|
|
625
|
+
if (!inputRef.current) return;
|
|
626
|
+
values = inputRef.current.value.split(':');
|
|
627
|
+
values.splice(1, 1, addZero(e.text));
|
|
628
|
+
setInputValue(values);
|
|
629
|
+
};
|
|
630
|
+
|
|
631
|
+
const setInputSecond = e => {
|
|
632
|
+
if (!inputRef.current) return;
|
|
633
|
+
values = inputRef.current.value.split(':');
|
|
634
|
+
values.splice(2, 1, addZero(e.text));
|
|
635
|
+
setInputValue(values);
|
|
636
|
+
};
|
|
637
|
+
|
|
638
|
+
useEffect(() => {
|
|
639
|
+
const parent = ref.current;
|
|
640
|
+
const scrollParent = getScrollParent(parent);
|
|
641
|
+
|
|
642
|
+
if (defaultValue) {
|
|
643
|
+
updateValue(defaultValue);
|
|
644
|
+
} else {
|
|
645
|
+
inputRef.current.value = '';
|
|
646
|
+
} // if (value) {
|
|
647
|
+
// updateValue(value);
|
|
648
|
+
// }
|
|
649
|
+
|
|
650
|
+
|
|
651
|
+
window.addEventListener('resize', setPositionClock);
|
|
652
|
+
document.addEventListener('keydown', e => escKeyFunc(e));
|
|
653
|
+
scrollParent.addEventListener('scroll', setPositionClock);
|
|
654
|
+
inputRef.current.addEventListener('keypress', e => validateKeyboard(e));
|
|
655
|
+
return () => {
|
|
656
|
+
window.removeEventListener('resize', setPositionClock);
|
|
657
|
+
document.removeEventListener('keydown', e => escKeyFunc(e));
|
|
658
|
+
scrollParent.removeEventListener('scroll', setPositionClock);
|
|
659
|
+
!!inputRef.current && inputRef.current.removeEventListener('keypress', e => validateKeyboard(e));
|
|
660
|
+
};
|
|
661
|
+
}, []);
|
|
662
|
+
useEffect(() => {
|
|
663
|
+
if (value) {
|
|
664
|
+
updateValue(value);
|
|
665
|
+
}
|
|
666
|
+
}, [value]);
|
|
667
|
+
useEffect(() => {
|
|
668
|
+
setPositionClock();
|
|
669
|
+
}, [activeHeight, activeWidth, allowSeconds]);
|
|
670
|
+
useEffect(() => {
|
|
671
|
+
if (disabled) {
|
|
672
|
+
ref.current.disabled = true;
|
|
673
|
+
ref.current.classList.add('disabled');
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
return () => {
|
|
677
|
+
if (ref.current) {
|
|
678
|
+
ref.current.disabled = false;
|
|
679
|
+
ref.current.classList.remove('disabled');
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
}, [disabled]);
|
|
683
|
+
useEffect(() => {
|
|
684
|
+
if (error && error !== '') {
|
|
685
|
+
mainRef.current.classList.add('error');
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
return () => {
|
|
689
|
+
!!mainRef.current && mainRef.current.classList.remove('error');
|
|
690
|
+
};
|
|
691
|
+
}, [error]);
|
|
692
|
+
const RequireMemo = useMemo(() => required && jsx("span", {
|
|
693
|
+
css: styles.label.required
|
|
694
|
+
}, "*"), [required]);
|
|
695
|
+
const LabelMemo = useMemo(() => jsx("div", {
|
|
696
|
+
css: styles.label.container
|
|
697
|
+
}, jsx("label", {
|
|
698
|
+
className: IDs.label,
|
|
699
|
+
id: IDs.label,
|
|
700
|
+
htmlFor: IDs.inputTypeText
|
|
701
|
+
}, label), RequireMemo), [label, required, error, disabled]);
|
|
702
|
+
const InputMemo = useMemo(() => jsx("input", _extends({}, inputProps, {
|
|
703
|
+
css: styles.input[viewType],
|
|
704
|
+
disabled: disabled,
|
|
705
|
+
id: IDs.inputTypeText,
|
|
706
|
+
onFocus: onFocus,
|
|
707
|
+
placeholder: 'hh:mm:ss',
|
|
708
|
+
readOnly: true,
|
|
709
|
+
ref: inputRef,
|
|
710
|
+
type: 'text'
|
|
711
|
+
})), [allowSeconds, disabled, viewType]);
|
|
712
|
+
const IconMemo = useMemo(() => jsx(React.Fragment, null, jsx("span", {
|
|
713
|
+
css: styles.icon[viewType],
|
|
714
|
+
className: `${IDs.icon} svg-default`,
|
|
715
|
+
onClick: onOpen
|
|
716
|
+
}, jsx(ClockIcon, {
|
|
717
|
+
color: 'currentColor'
|
|
718
|
+
})), jsx("span", {
|
|
719
|
+
css: styles.icon[viewType],
|
|
720
|
+
className: `${IDs.icon} svg-active`,
|
|
721
|
+
onClick: onClose
|
|
722
|
+
}, jsx(CancelIcon, {
|
|
723
|
+
color: 'currentColor',
|
|
724
|
+
width: '16',
|
|
725
|
+
height: '16'
|
|
726
|
+
}))), [allowSeconds, disabled, error, viewType]);
|
|
727
|
+
const ClockMemo = useMemo(() => jsx("div", {
|
|
728
|
+
css: styles.clock.container,
|
|
729
|
+
ref: clockContainerRef,
|
|
730
|
+
className: IDs.clock
|
|
731
|
+
}, jsx("div", {
|
|
732
|
+
css: styles.clock.wrapper,
|
|
733
|
+
ref: swiperWrapperHoursRef
|
|
734
|
+
}, jsx(Swiper, {
|
|
735
|
+
containerStyle: {
|
|
736
|
+
borderRadius: '4px'
|
|
737
|
+
},
|
|
738
|
+
data: getHours(),
|
|
739
|
+
defaultValue: getDefaultValue() && getDefaultValue().getHours(),
|
|
740
|
+
value: getDefaultValue() && getDefaultValue().getHours(),
|
|
741
|
+
height: formatDimension(activeHeight),
|
|
742
|
+
onChange: selected => setInputHour(selected),
|
|
743
|
+
parentNode: swiperWrapperHoursRef
|
|
744
|
+
})), jsx("div", {
|
|
745
|
+
css: styles.clock.wrapper,
|
|
746
|
+
ref: swiperWrapperMinutesRef
|
|
747
|
+
}, jsx(Swiper, {
|
|
748
|
+
containerStyle: {
|
|
749
|
+
borderRadius: '4px'
|
|
750
|
+
},
|
|
751
|
+
data: getMinutes(),
|
|
752
|
+
defaultValue: getDefaultValue() && getDefaultValue().getMinutes(),
|
|
753
|
+
value: getDefaultValue() && getDefaultValue().getMinutes(),
|
|
754
|
+
height: formatDimension(activeHeight),
|
|
755
|
+
onChange: selected => setInputMinute(selected),
|
|
756
|
+
parentNode: swiperWrapperMinutesRef
|
|
757
|
+
})), allowSeconds ? jsx("div", {
|
|
758
|
+
css: styles.clock.wrapper,
|
|
759
|
+
ref: swiperWrapperSecondsRef
|
|
760
|
+
}, jsx(Swiper, {
|
|
761
|
+
containerStyle: {
|
|
762
|
+
borderRadius: '4px'
|
|
763
|
+
},
|
|
764
|
+
data: getMinutes(),
|
|
765
|
+
defaultValue: getDefaultValue() && getDefaultValue().getSeconds(),
|
|
766
|
+
value: getDefaultValue() && getDefaultValue().getSeconds(),
|
|
767
|
+
height: formatDimension(activeHeight),
|
|
768
|
+
onChange: selected => setInputSecond(selected),
|
|
769
|
+
parentNode: swiperWrapperSecondsRef
|
|
770
|
+
})) : null), [activeHeight, activeWidth, allowSeconds, defaultValue, disabled, error, value, viewType]);
|
|
771
|
+
const ErrorMemo = useMemo(() => error && jsx("span", {
|
|
772
|
+
css: styles.error[viewType]
|
|
773
|
+
}, error), [error]);
|
|
774
|
+
const MainMemo = useMemo(() => jsx("div", {
|
|
775
|
+
className: IDs.main,
|
|
776
|
+
css: styles.main[viewType],
|
|
777
|
+
ref: mainRef
|
|
778
|
+
}, InputMemo, IconMemo, ErrorMemo), [activeHeight, activeWidth, allowSeconds, defaultValue, disabled, error, value, viewType]);
|
|
779
|
+
return jsx("div", _extends({}, props, {
|
|
780
|
+
css: styles.container[viewType],
|
|
781
|
+
ref: ref
|
|
782
|
+
}), LabelMemo, MainMemo, ClockMemo);
|
|
783
|
+
}));
|
|
784
|
+
TimePicker.defaultProps = {
|
|
785
|
+
activeHeight: 200,
|
|
786
|
+
activeWidth: 150,
|
|
787
|
+
allowSeconds: false,
|
|
788
|
+
disabled: false,
|
|
789
|
+
required: true,
|
|
790
|
+
viewType: 'outlined'
|
|
791
|
+
};
|
|
792
|
+
TimePicker.propTypes = {
|
|
793
|
+
/** height of the clock when display */
|
|
794
|
+
activeHeight: PropTypes.number,
|
|
795
|
+
|
|
796
|
+
/** width of the clock when display */
|
|
797
|
+
activeWidth: PropTypes.number,
|
|
798
|
+
|
|
799
|
+
/** allow second field on clock */
|
|
800
|
+
allowSeconds: PropTypes.bool,
|
|
801
|
+
|
|
802
|
+
/** the default value when the clock is open */
|
|
803
|
+
defaultValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]),
|
|
804
|
+
|
|
805
|
+
/** if 'true' the form control will be disabled */
|
|
806
|
+
disabled: PropTypes.bool,
|
|
807
|
+
|
|
808
|
+
/** error of the form control */
|
|
809
|
+
error: PropTypes.string,
|
|
810
|
+
|
|
811
|
+
/** label of the form control */
|
|
812
|
+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
|
|
813
|
+
|
|
814
|
+
/** properties of the input element */
|
|
815
|
+
inputProps: PropTypes.object,
|
|
816
|
+
|
|
817
|
+
/** a callback function when value input change */
|
|
818
|
+
onChange: PropTypes.func,
|
|
819
|
+
|
|
820
|
+
/** required state of the form control */
|
|
821
|
+
required: PropTypes.bool,
|
|
822
|
+
|
|
823
|
+
/** the default value when the clock is open */
|
|
824
|
+
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.string]),
|
|
825
|
+
|
|
826
|
+
/** view type of the form control */
|
|
827
|
+
viewType: PropTypes.oneOf(['outlined', 'underlined'])
|
|
828
|
+
};
|
|
829
|
+
export default TimePicker;
|