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
package/theme/theme.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as colors from '../styles/colors';
|
|
2
|
+
export const theme = {
|
|
3
|
+
palette: {
|
|
4
|
+
primary: {
|
|
5
|
+
light: colors.brand7,
|
|
6
|
+
main: colors.dark
|
|
7
|
+
},
|
|
8
|
+
success: {
|
|
9
|
+
main: colors.success5
|
|
10
|
+
},
|
|
11
|
+
warning: {
|
|
12
|
+
main: colors.warning5
|
|
13
|
+
},
|
|
14
|
+
danger: {
|
|
15
|
+
main: colors.danger5
|
|
16
|
+
},
|
|
17
|
+
info: {
|
|
18
|
+
main: colors.info5
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
typography: {
|
|
22
|
+
fontFamily: 'sans-serif',
|
|
23
|
+
body1: {
|
|
24
|
+
fontSize: 12
|
|
25
|
+
},
|
|
26
|
+
body2: {
|
|
27
|
+
fontSize: 14
|
|
28
|
+
},
|
|
29
|
+
body3: {
|
|
30
|
+
fontSize: 16
|
|
31
|
+
},
|
|
32
|
+
body4: {
|
|
33
|
+
fontSize: 20
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
shape: {
|
|
37
|
+
borderRadius: 4
|
|
38
|
+
},
|
|
39
|
+
border: {
|
|
40
|
+
type1: {
|
|
41
|
+
type: 'outline',
|
|
42
|
+
size: '1px',
|
|
43
|
+
defaultColor: colors.brand
|
|
44
|
+
},
|
|
45
|
+
type2: {
|
|
46
|
+
type: 'info',
|
|
47
|
+
size: '2px',
|
|
48
|
+
defaultColor: colors.info5
|
|
49
|
+
},
|
|
50
|
+
type3: {
|
|
51
|
+
type: 'danger',
|
|
52
|
+
size: '1px',
|
|
53
|
+
defaultColor: colors.danger5
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
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 } from '@emotion/core';
|
|
7
|
+
import makeStyles from './make-styles';
|
|
8
|
+
|
|
9
|
+
const WithStyles = styles => Component => props => {
|
|
10
|
+
const useStyle = makeStyles(styles);
|
|
11
|
+
const classes = useStyle();
|
|
12
|
+
return jsx(Component, _extends({}, props, {
|
|
13
|
+
classes: classes
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default WithStyles;
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
import settings from './settings';
|
|
4
|
+
|
|
5
|
+
const withTheme = Component => props => {
|
|
6
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
|
7
|
+
theme: settings
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export default withTheme;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { isDefined } from '../type';
|
|
2
|
+
import { each } from '../iterator';
|
|
3
|
+
import { orderEach } from '../object/object';
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {Array} entity
|
|
7
|
+
* @returns {Boolean}
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const isEmpty = entity => Array.isArray(entity) && !entity.length;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param {any} entity
|
|
14
|
+
* @returns {Array} [entity]
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export const wrapToArray = entity => Array.isArray(entity) ? entity : [entity];
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {*} value in object
|
|
21
|
+
* @param {ArrayLike} object is a array-like object
|
|
22
|
+
* @returns {Number} index of value, -1 if not found
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export const inArray = (value, object) => {
|
|
26
|
+
if (!object) return -1;
|
|
27
|
+
const array = Array.isArray(object) ? object : Array.from(object);
|
|
28
|
+
return array.indexOf(value);
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {Array} a
|
|
33
|
+
* @param {Array} b
|
|
34
|
+
* @returns {Array} intersection array of a and b
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
export const intersection = (a, b) => {
|
|
38
|
+
if (!Array.isArray(a) || a.length === 0 || !Array.isArray(b) || b.length === 0) return [];
|
|
39
|
+
const result = [];
|
|
40
|
+
each(a, (_, value) => {
|
|
41
|
+
const index = inArray(value, b);
|
|
42
|
+
|
|
43
|
+
if (index !== -1) {
|
|
44
|
+
result.push(value);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return result;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {Array} data
|
|
52
|
+
* @returns {Array} array with unique values
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
export const uniqueValues = data => data.filter((item, position) => data.indexOf(item) === position);
|
|
56
|
+
/**
|
|
57
|
+
*
|
|
58
|
+
* @param {Array} from
|
|
59
|
+
* @param {Array} what
|
|
60
|
+
* @returns {Array} without duplicate
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export const removeDuplicates = function (from, what) {
|
|
64
|
+
if (!Array.isArray(from) || from.length === 0) {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (!Array.isArray(what) || what.length === 0) {
|
|
69
|
+
return from.slice();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const result = [];
|
|
73
|
+
each(from, (_, value) => {
|
|
74
|
+
const index = inArray(value, what);
|
|
75
|
+
|
|
76
|
+
if (index === -1) {
|
|
77
|
+
result.push(value);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return result;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @param {Array} items
|
|
85
|
+
* @param {*} indexParameterName
|
|
86
|
+
* @param {*} currentItem
|
|
87
|
+
* @param {Function} needIndexCallback
|
|
88
|
+
* @returns
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
export const normalizeIndexes = function (items, indexParameterName, currentItem, needIndexCallback) {
|
|
92
|
+
const indexedItems = {};
|
|
93
|
+
let parameterIndex = 0;
|
|
94
|
+
/**
|
|
95
|
+
* useLegacyVisibleIndex will be process in future
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
const useLegacyVisibleIndex = false;
|
|
99
|
+
each(items, (index, item) => {
|
|
100
|
+
index = item[indexParameterName];
|
|
101
|
+
|
|
102
|
+
if (index >= 0) {
|
|
103
|
+
indexedItems[index] = indexedItems[index] || [];
|
|
104
|
+
|
|
105
|
+
if (item === currentItem) {
|
|
106
|
+
indexedItems[index].unshift(item);
|
|
107
|
+
} else {
|
|
108
|
+
indexedItems[index].push(item);
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
item[indexParameterName] = undefined;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (!useLegacyVisibleIndex) {
|
|
116
|
+
each(items, function () {
|
|
117
|
+
if (!isDefined(this[indexParameterName]) && !!needIndexCallback && needIndexCallback(this)) {
|
|
118
|
+
while (indexedItems[parameterIndex]) {
|
|
119
|
+
parameterIndex++;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
indexedItems[parameterIndex] = [this];
|
|
123
|
+
parameterIndex++;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
parameterIndex = 0;
|
|
129
|
+
orderEach(indexedItems, function (index, items) {
|
|
130
|
+
each(items, function () {
|
|
131
|
+
if (index >= 0) {
|
|
132
|
+
this[indexParameterName] = parameterIndex++;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}); // if (useLegacyVisibleIndex) {
|
|
136
|
+
// each(items, function () {
|
|
137
|
+
// if (
|
|
138
|
+
// !isDefined(this[indexParameterName]) &&
|
|
139
|
+
// (!needIndexCallback || needIndexCallback(this))
|
|
140
|
+
// ) {
|
|
141
|
+
// this[indexParameterName] = parameterIndex++;
|
|
142
|
+
// }
|
|
143
|
+
// });
|
|
144
|
+
// }
|
|
145
|
+
|
|
146
|
+
return parameterIndex;
|
|
147
|
+
};
|
|
148
|
+
export const merge = function (array1, array2) {
|
|
149
|
+
for (let i = 0; i < array2.length; i++) {
|
|
150
|
+
array1[array1.length] = array2[i];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return array1;
|
|
154
|
+
};
|
|
155
|
+
export const find = function (array, condition) {
|
|
156
|
+
for (let i = 0; i < array.length; i++) {
|
|
157
|
+
if (condition(array[i])) {
|
|
158
|
+
return array[i];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
export const groupByFunc = (array, cb) => array.reduce((result, item) => ({ ...result,
|
|
163
|
+
[cb(item)]: [...(result[cb(item)] || []), item]
|
|
164
|
+
}), {});
|
|
165
|
+
export const groupByKey = (array, key) => array.reduce((result, item) => {
|
|
166
|
+
(result[item[key]] = result[item[key]] || []).push(item);
|
|
167
|
+
return result;
|
|
168
|
+
}, {});
|
|
169
|
+
export const isEqual = (currentArray, compareArray) => {
|
|
170
|
+
if (!currentArray || !compareArray) return false;
|
|
171
|
+
if (currentArray.length !== compareArray.length) return false;
|
|
172
|
+
|
|
173
|
+
for (let i = 0, j = currentArray.length; i < j; i++) {
|
|
174
|
+
if (currentArray[i] instanceof Array && compareArray[i] instanceof Array) {
|
|
175
|
+
if (!isEqual(currentArray[i], compareArray[i])) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
} else if (currentArray[i] !== compareArray[i]) {
|
|
179
|
+
return false;
|
|
180
|
+
} // in future will update for object case
|
|
181
|
+
// else if (typeof currentArray[i] === 'object' && typeof compareArray[i] === 'object') {}
|
|
182
|
+
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return true;
|
|
186
|
+
};
|
package/utils/console.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/* global console */
|
|
2
|
+
import { isFunction } from './type';
|
|
3
|
+
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
|
|
6
|
+
const getConsoleMethod = function (method) {
|
|
7
|
+
if (typeof console === 'undefined' || !isFunction(console[method])) {
|
|
8
|
+
return noop;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return console[method].bind(console);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const logger = {
|
|
15
|
+
info: getConsoleMethod('info'),
|
|
16
|
+
warn: getConsoleMethod('warn'),
|
|
17
|
+
error: getConsoleMethod('error')
|
|
18
|
+
};
|
|
19
|
+
export const debug = (() => {
|
|
20
|
+
const assert = (condition, message) => {
|
|
21
|
+
if (!condition) {
|
|
22
|
+
throw new Error(message);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const assertParam = (parameter, message) => {
|
|
27
|
+
assert(parameter !== null && parameter !== undefined, message);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
assert: assert,
|
|
32
|
+
assertParam: assertParam
|
|
33
|
+
};
|
|
34
|
+
})();
|
package/utils/date.js
ADDED
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { getGlobal } from '../global';
|
|
2
|
+
import locale from '../locale';
|
|
3
|
+
const language = locale.get();
|
|
4
|
+
const localeName = language === 'en' ? 'en-US' : 'vi-VN';
|
|
5
|
+
const units = ['year', 'month', 'day', 'hour', 'minute', 'second', 'millisecond'];
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {Date|String|Array} value is a date time
|
|
9
|
+
* @param {String} format the input date format
|
|
10
|
+
* @param {Boolean} setNow return current time if true
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const getDate = (value, format = 'MM/DD/YYYY', setNow = true) => {
|
|
14
|
+
if (value) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
value = value.join('/');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (typeof value === 'string') {
|
|
20
|
+
if (format.replace(/\W/g, '/') === 'DD/MM/YYYY') {
|
|
21
|
+
value = value.replace(/^(\d{1,2}\/)(\d{1,2}\/)/, '$2$1');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return new Date(value);
|
|
26
|
+
} else if (setNow) {
|
|
27
|
+
return new Date();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const getMethodOfUnit = unit => {
|
|
32
|
+
switch (unit.toLowerCase()) {
|
|
33
|
+
case 'years':
|
|
34
|
+
case 'year':
|
|
35
|
+
return 'FullYear';
|
|
36
|
+
|
|
37
|
+
case 'months':
|
|
38
|
+
case 'month':
|
|
39
|
+
return 'Month';
|
|
40
|
+
|
|
41
|
+
case 'days':
|
|
42
|
+
case 'day':
|
|
43
|
+
return 'Date';
|
|
44
|
+
|
|
45
|
+
case 'hours':
|
|
46
|
+
case 'hour':
|
|
47
|
+
return 'Hours';
|
|
48
|
+
|
|
49
|
+
case 'minutes':
|
|
50
|
+
case 'minute':
|
|
51
|
+
return 'Minutes';
|
|
52
|
+
|
|
53
|
+
case 'seconds':
|
|
54
|
+
case 'second':
|
|
55
|
+
return 'Seconds';
|
|
56
|
+
|
|
57
|
+
case 'millisecond':
|
|
58
|
+
return 'Milliseconds';
|
|
59
|
+
|
|
60
|
+
default:
|
|
61
|
+
return 'Date';
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* check 1 value is a date
|
|
66
|
+
* @param {Date|String|Array|Number} value the value to check
|
|
67
|
+
* @param {String} formatInput the format date to check valid date
|
|
68
|
+
* @returns {Boolean} valid date
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
export const isValidDate = (value, formatInput) => {
|
|
73
|
+
if (typeof value === 'string' || Array.isArray(value)) {
|
|
74
|
+
if (String(getDate(value, formatInput)) !== 'Invalid Date') {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
} else if (Object.prototype.toString.call(value) === '[object Date]' && String(value) !== 'Invalid Date') {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* get the end of month from month and year or from a date
|
|
85
|
+
* @param {Number|String|Date|Array} month the month of year (can also be validated as year) or a value with date type
|
|
86
|
+
* @param {Number} year the year (can also be validated as month if arg 1 is year)
|
|
87
|
+
* @returns {Number} end day
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export const getEndDayOfMonth = (month, year) => {
|
|
91
|
+
if (!year) {
|
|
92
|
+
if (/number|string/.test(typeof month) || Array.isArray(month)) {
|
|
93
|
+
month = getDate(getDate, undefined, false);
|
|
94
|
+
|
|
95
|
+
if (String(month) !== 'Invalid Date') {
|
|
96
|
+
return new Date(month.getFullYear(), month.getMonth(), 0).getDate();
|
|
97
|
+
}
|
|
98
|
+
} else if (isValidDate(month)) {
|
|
99
|
+
return new Date(month.getFullYear(), month.getMonth(), 0).getDate();
|
|
100
|
+
}
|
|
101
|
+
} else if (!isNaN(month) && !isNaN(year)) {
|
|
102
|
+
var _Date, _Date$getDate;
|
|
103
|
+
|
|
104
|
+
return (_Date = new Date(year > 12 ? year : year - 1, month > 12 ? month : month - 1, 0)) === null || _Date === void 0 ? void 0 : (_Date$getDate = _Date.getDate) === null || _Date$getDate === void 0 ? void 0 : _Date$getDate.call(_Date);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return 'Invalid Date';
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* return a date time follow the concrete format
|
|
111
|
+
* @param {Date|String|Array} value is a date time
|
|
112
|
+
* @param {String} formatOutput format of date
|
|
113
|
+
* @param {Boolean} utc is utc time
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
export const formatDate = (value, formatOutput = 'DD/MM/YYYY', utc = false) => {
|
|
117
|
+
if (!value) return formatOutput;
|
|
118
|
+
formatOutput = formatOutput.trim();
|
|
119
|
+
|
|
120
|
+
if (typeof value === 'string') {
|
|
121
|
+
value = new Date(value);
|
|
122
|
+
|
|
123
|
+
if (String(value) === 'Invalid Date') {
|
|
124
|
+
return 'Invalid Date';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const dateTime = (() => {
|
|
129
|
+
var _value$toTimeString$m;
|
|
130
|
+
|
|
131
|
+
const UTC = utc ? 'UTC' : '';
|
|
132
|
+
const year = value['get' + UTC + 'FullYear']();
|
|
133
|
+
const month = value['get' + UTC + 'Month']();
|
|
134
|
+
const day = value['get' + UTC + 'Day']();
|
|
135
|
+
const dayOfYear = Math.ceil(value.valueOf() - new Date(year).valueOf() / 86400000);
|
|
136
|
+
const hours = value['get' + UTC + 'Hours']();
|
|
137
|
+
const timeZone = (_value$toTimeString$m = value.toTimeString().match(/\+[0-9]{4}/)) === null || _value$toTimeString$m === void 0 ? void 0 : _value$toTimeString$m[0].replace(/\+(\d{2})/, '+$1:');
|
|
138
|
+
return {
|
|
139
|
+
// Date - Month - Year
|
|
140
|
+
YY: year.toString().slice(-2),
|
|
141
|
+
// 21
|
|
142
|
+
YYYY: year,
|
|
143
|
+
// 2021
|
|
144
|
+
M: month + 1,
|
|
145
|
+
// 1
|
|
146
|
+
MM: ('0' + (month + 1).toString()).slice(-2),
|
|
147
|
+
// 01
|
|
148
|
+
MMM: getGlobal(['months', 'notFull', month]),
|
|
149
|
+
// Jan
|
|
150
|
+
MMMM: getGlobal(['months', 'full', month]),
|
|
151
|
+
// January
|
|
152
|
+
D: value['get' + UTC + 'Date'](),
|
|
153
|
+
// 26
|
|
154
|
+
DD: ('0' + value['get' + UTC + 'Date']().toString()).slice(-2),
|
|
155
|
+
// 26
|
|
156
|
+
DDD: dayOfYear,
|
|
157
|
+
// 26 - day of year
|
|
158
|
+
DDDD: dayOfYear.toString().replace(/^(\d)$/, '0$1'),
|
|
159
|
+
// 26 - 2 digit
|
|
160
|
+
dddd: getGlobal(['days', 'full', day]),
|
|
161
|
+
ddd: getGlobal(['days', 'notFull', day]),
|
|
162
|
+
e: day,
|
|
163
|
+
// 2 - day of week
|
|
164
|
+
E: day + 1,
|
|
165
|
+
// 3
|
|
166
|
+
Q: Math.ceil((month + 1) / 3),
|
|
167
|
+
// 1
|
|
168
|
+
// Hour + Minute + second
|
|
169
|
+
H: hours,
|
|
170
|
+
HH: ('0' + hours.toString()).slice(-2),
|
|
171
|
+
h: hours > 12 ? hours % 12 : hours,
|
|
172
|
+
hh: ('0' + hours > 12 ? hours % 12 : hours).toString().slice(-2),
|
|
173
|
+
K: hours + 1,
|
|
174
|
+
KK: ('0' + (hours + 1).toString()).slice(-2),
|
|
175
|
+
m: value['get' + UTC + 'Minutes'](),
|
|
176
|
+
mm: ('0' + value['get' + UTC + 'Minutes']().toString()).slice(-2),
|
|
177
|
+
s: value['get' + UTC + 'Seconds'](),
|
|
178
|
+
ss: ('0' + value['get' + UTC + 'Seconds']().toString()).slice(-2),
|
|
179
|
+
a: hours > 11 ? 'PM' : 'AM',
|
|
180
|
+
A: hours > 11 ? 'PM' : 'AM',
|
|
181
|
+
x: value.valueOf().toString(),
|
|
182
|
+
X: (value.valueOf() / 1000).toString(),
|
|
183
|
+
Z: timeZone,
|
|
184
|
+
ZZ: timeZone
|
|
185
|
+
};
|
|
186
|
+
})();
|
|
187
|
+
|
|
188
|
+
const dateTimeFormat = (options = {}) => {
|
|
189
|
+
return new Intl.DateTimeFormat(localeName, options).format(value);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const getFullTime = unit => {
|
|
193
|
+
const fullDate = value.toLocaleDateString(localeName); // "1/26/2020"
|
|
194
|
+
|
|
195
|
+
const lll = dateTimeFormat({
|
|
196
|
+
dateStyle: 'medium',
|
|
197
|
+
timeStyle: 'short'
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
switch (unit) {
|
|
201
|
+
case 'L':
|
|
202
|
+
return fullDate.split('/').map(v => v.length > 1 ? v : '0' + v).join('/');
|
|
203
|
+
|
|
204
|
+
case 'l':
|
|
205
|
+
return fullDate;
|
|
206
|
+
|
|
207
|
+
case 'LL':
|
|
208
|
+
return dateTimeFormat({
|
|
209
|
+
dateStyle: 'long'
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
case 'll':
|
|
213
|
+
return dateTimeFormat({
|
|
214
|
+
dateStyle: 'medium'
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
case 'LLL':
|
|
218
|
+
return dateTimeFormat({
|
|
219
|
+
dateStyle: 'long',
|
|
220
|
+
timeStyle: 'short'
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
case 'lll':
|
|
224
|
+
return lll;
|
|
225
|
+
|
|
226
|
+
case 'LLLL':
|
|
227
|
+
return dateTimeFormat({
|
|
228
|
+
dateStyle: 'full',
|
|
229
|
+
timeStyle: 'short'
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
case 'llll':
|
|
233
|
+
return dateTime.ddd + ', ' + lll;
|
|
234
|
+
|
|
235
|
+
case 'LT':
|
|
236
|
+
return dateTimeFormat({
|
|
237
|
+
date: 'none',
|
|
238
|
+
timeStyle: 'short'
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
case 'LTS':
|
|
242
|
+
return dateTimeFormat({
|
|
243
|
+
date: 'none',
|
|
244
|
+
timeStyle: 'medium'
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
default:
|
|
248
|
+
return 'Invalid format';
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const getUnitFormat = unit => {
|
|
253
|
+
if (/l/i.test(unit)) {
|
|
254
|
+
return getFullTime(unit);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
{
|
|
258
|
+
return dateTime[unit];
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const arrFormat = formatOutput.split(/\W+/g);
|
|
263
|
+
|
|
264
|
+
if (arrFormat.length) {
|
|
265
|
+
arrFormat.forEach(unit => {
|
|
266
|
+
formatOutput = formatOutput.replace(unit, getUnitFormat(unit));
|
|
267
|
+
});
|
|
268
|
+
return formatOutput;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* return a date like moment
|
|
273
|
+
* @param {Date|String|Array} value is date time
|
|
274
|
+
* @param {String} formatInput format of input date value
|
|
275
|
+
* @returns {Object} date
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
const date = (value, formatInput = 'MM/DD/YYYY') => {
|
|
279
|
+
const originDate = getDate(value, formatInput);
|
|
280
|
+
/**
|
|
281
|
+
* compare two date time and return a period
|
|
282
|
+
* @param {Date|String|Array} date is a date time
|
|
283
|
+
* @param {String} unit one of milliseconds|seconds|minutes|hours|days|months|years
|
|
284
|
+
* @param {Boolean|Number} floating allow odd numbers
|
|
285
|
+
* @returns {Number} distance
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
const diff = (compareDate, unit = 'days', floating = false) => {
|
|
289
|
+
compareDate = getDate(compareDate);
|
|
290
|
+
|
|
291
|
+
if (String(compareDate) === 'Invalid Date' || !isValidDate(originDate, formatInput)) {
|
|
292
|
+
return 'Invalid Date';
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
let result = [];
|
|
296
|
+
|
|
297
|
+
if (/months|years/.test(unit.toLowerCase())) {
|
|
298
|
+
const originDateArr = formatDate(originDate, 'YYYY/MM/DD HH:mm:ss').split(/\W+/);
|
|
299
|
+
const compareDateArr = formatDate(compareDate, 'YYYY/MM/DD HH:mm:ss').split(/\W+/);
|
|
300
|
+
const endDayOfMonth = getEndDayOfMonth(originDate);
|
|
301
|
+
const similarMaxTimeArr = [1, 12, endDayOfMonth, 24, 60, 60, 1000];
|
|
302
|
+
let decimalTotal = 0,
|
|
303
|
+
currentValueOfUnit = 1;
|
|
304
|
+
|
|
305
|
+
for (let i = originDateArr.length - 1; i >= 0; i--) {
|
|
306
|
+
result[i] = originDateArr[i] - compareDateArr[i];
|
|
307
|
+
|
|
308
|
+
if (i > 1) {
|
|
309
|
+
currentValueOfUnit *= similarMaxTimeArr[i + 1];
|
|
310
|
+
decimalTotal += result[i] * currentValueOfUnit;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const decimalOfMonth = decimalTotal / (endDayOfMonth * 86400000);
|
|
315
|
+
result = result[0] * 12 + result[1] + decimalOfMonth;
|
|
316
|
+
|
|
317
|
+
if (unit.toLowerCase() === 'years') {
|
|
318
|
+
result = result / 12;
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
const getValueOfUnit = (week = 1) => {
|
|
322
|
+
switch (unit.toLowerCase()) {
|
|
323
|
+
case 'days':
|
|
324
|
+
return 86400000;
|
|
325
|
+
|
|
326
|
+
case 'hours':
|
|
327
|
+
return 3600000;
|
|
328
|
+
|
|
329
|
+
case 'minutes':
|
|
330
|
+
return 60000;
|
|
331
|
+
|
|
332
|
+
case 'seconds':
|
|
333
|
+
return 1000;
|
|
334
|
+
|
|
335
|
+
case 'milliseconds':
|
|
336
|
+
return 1;
|
|
337
|
+
|
|
338
|
+
default:
|
|
339
|
+
return 86400000 * week;
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
result = (originDate.valueOf() - compareDate.valueOf()) / getValueOfUnit(unit === 'weeks' ? 1 : 7);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return result.toFixed(floating ? typeof floating === 'number' ? floating : 2 : 0);
|
|
347
|
+
};
|
|
348
|
+
/**
|
|
349
|
+
* add or subtract date time
|
|
350
|
+
* @param {Number} num the quantity to cal for unit
|
|
351
|
+
* @param {String} unit the unit of date/time
|
|
352
|
+
* @param {String} operator operator to cal (add/subtract)
|
|
353
|
+
* @returns {Object} date
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
const calculation = (num, unit, operator) => {
|
|
358
|
+
if (isNaN(num)) {
|
|
359
|
+
return NaN;
|
|
360
|
+
} // Example: unit === 'days' -> originDate.setDate(originDate.getDate() +/- num)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
originDate['set' + getMethodOfUnit(unit)](originDate['get' + getMethodOfUnit(unit)]() + (operator === 'add' ? +num : -num));
|
|
364
|
+
return date(originDate, formatInput);
|
|
365
|
+
};
|
|
366
|
+
/**
|
|
367
|
+
* get the moment of time follow unit time
|
|
368
|
+
* @param {String} unit the unit of time
|
|
369
|
+
* @param {String} moment start|end to get start|end of the moment
|
|
370
|
+
* @returns {Object} date
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
const timeOf = (unit, moment) => {
|
|
375
|
+
let temp = 1;
|
|
376
|
+
|
|
377
|
+
if (!units.includes(unit)) {
|
|
378
|
+
unit = 'day';
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
units.forEach(u => {
|
|
382
|
+
const method = getMethodOfUnit(u);
|
|
383
|
+
const valueUnitTime = originDate['get' + method]();
|
|
384
|
+
|
|
385
|
+
if (u === unit) {
|
|
386
|
+
const addTime = moment === 'start' ? 0 : 1;
|
|
387
|
+
originDate['set' + method](valueUnitTime + addTime);
|
|
388
|
+
temp = 0;
|
|
389
|
+
} else {
|
|
390
|
+
const time = u === 'millisecond' ? moment === 'start' ? 0 : -1 : u === 'day' ? Math.max(1, valueUnitTime * temp) : valueUnitTime * temp;
|
|
391
|
+
originDate['set' + method](time);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
return date(originDate, formatInput);
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
*
|
|
398
|
+
* @param {Date|String|Number|Array} compareDate date to calculate moment, undefined will compare with now
|
|
399
|
+
* @param {String|Array} unit year|month|day|hour|minute|second|millisecond, allow undefined
|
|
400
|
+
* @param {Boolean|Number} floating allow odd numbers
|
|
401
|
+
* @returns {String} moments
|
|
402
|
+
*/
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
const relative = (compareDate, unit, floating) => {
|
|
406
|
+
compareDate = getDate(compareDate);
|
|
407
|
+
|
|
408
|
+
if (String(compareDate) === 'Invalid Date' || !isValidDate(originDate, formatInput)) {
|
|
409
|
+
return 'Invalid Date';
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
if (typeof unit === 'string' && /s$/.test(unit)) {
|
|
413
|
+
unit = unit.replace(/s$/, '');
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (!unit || typeof unit === 'string' && !units.includes(unit)) {
|
|
417
|
+
unit = units;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
let num;
|
|
421
|
+
|
|
422
|
+
if (Array.isArray(unit)) {
|
|
423
|
+
for (let i = 0; i < unit.length; i++) {
|
|
424
|
+
num = diff(compareDate, unit[i] + 's', floating ? typeof floating === 'number' ? floating : 2 : 1);
|
|
425
|
+
|
|
426
|
+
if (Math.abs(num) >= 1) {
|
|
427
|
+
unit = unit[i];
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
} else {
|
|
432
|
+
num = diff(compareDate, unit + 's', floating ? typeof floating === 'number' ? floating : 2 : 1);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
num = (+num).toFixed(floating ? typeof floating === 'number' ? floating : 2 : 0);
|
|
436
|
+
|
|
437
|
+
try {
|
|
438
|
+
return new Intl.RelativeTimeFormat(language, {
|
|
439
|
+
numeric: "auto"
|
|
440
|
+
}).format(-num, unit);
|
|
441
|
+
} catch (e) {
|
|
442
|
+
return e.message;
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
return {
|
|
447
|
+
value: originDate,
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* return a date time follow the concrete format
|
|
451
|
+
* @param {String} formatOutput format of date
|
|
452
|
+
* @param {Boolean} utc is utc time
|
|
453
|
+
*/
|
|
454
|
+
format: (formatOutput, utc) => formatDate(originDate, formatOutput, utc),
|
|
455
|
+
diff,
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* check 1 value is a date
|
|
459
|
+
* @param {String} formatInput the format date to check valid date
|
|
460
|
+
* @returns {Boolean} valid date
|
|
461
|
+
*/
|
|
462
|
+
isValid: () => isValidDate(originDate, formatInput),
|
|
463
|
+
add: (num, unit) => calculation(num, unit, 'add'),
|
|
464
|
+
subtract: (num, unit) => calculation(num, unit, 'subtract'),
|
|
465
|
+
startOf: unit => timeOf(unit, 'start'),
|
|
466
|
+
endOf: unit => timeOf(unit, 'end'),
|
|
467
|
+
relative
|
|
468
|
+
};
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
export default date;
|