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,504 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a number whose value is limited to the given range.
|
|
3
|
+
*
|
|
4
|
+
* @param {number} value The value to be clamped
|
|
5
|
+
* @param {number} min The lower boundary of the output range
|
|
6
|
+
* @param {number} max The upper boundary of the output range
|
|
7
|
+
* @returns {number} A number in the range [min, max]
|
|
8
|
+
*/
|
|
9
|
+
const clamp = (value, min = 0, max = 1) => {
|
|
10
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
11
|
+
if (value < min || value > max) {
|
|
12
|
+
console.error(`DigiNet-CORE-UI: The value provided ${value} is out of range [${min}, ${max}].`);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return Math.min(Math.max(min, value), max);
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Converts a color from CSS hex format to CSS rgb format.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} color - Hex color, i.e. #nnn or #nnnnnn
|
|
22
|
+
* @returns {string} A CSS rgb color string
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export const hexToRgb = color => {
|
|
27
|
+
color = color.substr(1);
|
|
28
|
+
const re = new RegExp(`.{1,${color.length >= 6 ? 2 : 1}}`, 'g');
|
|
29
|
+
let colors = color.match(re);
|
|
30
|
+
|
|
31
|
+
if (colors && colors[0].length === 1) {
|
|
32
|
+
colors = colors.map(n => n + n);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return colors ? `rgb${colors.length === 4 ? 'a' : ''}(${colors.map((n, index) => {
|
|
36
|
+
return index < 3 ? parseInt(n, 16) : Math.round(parseInt(n, 16) / 255 * 1000) / 1000;
|
|
37
|
+
}).join(', ')})` : '';
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const intToHex = int => {
|
|
41
|
+
const hex = int.toString(16);
|
|
42
|
+
return hex.length === 1 ? `0${hex}` : hex;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Converts a color from CSS rgb format to CSS hex format.
|
|
46
|
+
*
|
|
47
|
+
* @param {string} color - RGB color, i.e. rgb(n, n, n)
|
|
48
|
+
* @returns {string} A CSS rgb color string, i.e. #nnnnnn
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export const rgbToHex = color => {
|
|
53
|
+
if (color.indexOf('#') === 0) {
|
|
54
|
+
return color;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const {
|
|
58
|
+
values
|
|
59
|
+
} = decomposeColor(color);
|
|
60
|
+
return `#${values.map(n => intToHex(n)).join('')}`;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Converts a color from CSS rgb format to CSS hex format.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} color - RGBA color, i.e. rgba(n, n, n, f)
|
|
66
|
+
* @returns {string} A CSS rgb A color string, i.e. #nnnnnnnn
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export const rgbaToHexA = color => {
|
|
70
|
+
let sep = color.indexOf(',') > -1 ? ',' : ' ';
|
|
71
|
+
color = color.substr(5).split(')')[0].split(sep); // Strip the slash if using space-separated syntax
|
|
72
|
+
|
|
73
|
+
if (color.indexOf('/') > -1) color.splice(3, 1);
|
|
74
|
+
|
|
75
|
+
for (let R in color) {
|
|
76
|
+
let r = color[R];
|
|
77
|
+
|
|
78
|
+
if (r.indexOf('%') > -1) {
|
|
79
|
+
let p = r.substr(0, r.length - 1) / 100;
|
|
80
|
+
|
|
81
|
+
if (R < 3) {
|
|
82
|
+
color[R] = Math.round(p * 255);
|
|
83
|
+
} else {
|
|
84
|
+
color[R] = p;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
let r = (+color[0]).toString(16),
|
|
90
|
+
g = (+color[1]).toString(16),
|
|
91
|
+
b = (+color[2]).toString(16),
|
|
92
|
+
a = Math.round(+color[3] * 255).toString(16);
|
|
93
|
+
if (r.length == 1) r = '0' + r;
|
|
94
|
+
if (g.length == 1) g = '0' + g;
|
|
95
|
+
if (b.length == 1) b = '0' + b;
|
|
96
|
+
if (a.length == 1) a = '0' + a;
|
|
97
|
+
return '#' + r + g + b + a;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Converts a color from hsl format to rgb format.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} color - HSL color values
|
|
103
|
+
* @returns {string} rgb color values
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
export const hslToRgb = color => {
|
|
107
|
+
color = decomposeColor(color);
|
|
108
|
+
const {
|
|
109
|
+
values
|
|
110
|
+
} = color;
|
|
111
|
+
const h = values[0];
|
|
112
|
+
const s = values[1] / 100;
|
|
113
|
+
const l = values[2] / 100;
|
|
114
|
+
const a = s * Math.min(l, 1 - l);
|
|
115
|
+
|
|
116
|
+
const f = (n, k = (n + h / 30) % 12) => l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
|
|
117
|
+
|
|
118
|
+
let type = 'rgb';
|
|
119
|
+
const rgb = [Math.round(f(0) * 255), Math.round(f(8) * 255), Math.round(f(4) * 255)];
|
|
120
|
+
|
|
121
|
+
if (color.type === 'hsla') {
|
|
122
|
+
type += 'a';
|
|
123
|
+
rgb.push(values[3]);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return recomposeColor({
|
|
127
|
+
type,
|
|
128
|
+
values: rgb
|
|
129
|
+
});
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* Returns an object with the type and values of a color.
|
|
133
|
+
*
|
|
134
|
+
* Note: Does not support rgb % values.
|
|
135
|
+
*
|
|
136
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
137
|
+
* @returns {object} - A color object: {type: string, values: number[]}
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
export const decomposeColor = color => {
|
|
141
|
+
if (color.type) {
|
|
142
|
+
return color;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (color.charAt(0) === '#') {
|
|
146
|
+
return decomposeColor(hexToRgb(color));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const marker = color.indexOf('(');
|
|
150
|
+
const type = color.substring(0, marker);
|
|
151
|
+
|
|
152
|
+
if (['rgb', 'rgba', 'hsl', 'hsla'].indexOf(type) === -1) {
|
|
153
|
+
throw 'DigiNet-CORE-UI: Unsupported `%s` color.\n' + 'We support the following formats: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla().', color;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
let values = color.substring(marker + 1, color.length - 1).split(',');
|
|
157
|
+
values = values.map(value => parseFloat(value));
|
|
158
|
+
return {
|
|
159
|
+
type,
|
|
160
|
+
values
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* Converts a color object with type and values to a string.
|
|
165
|
+
*
|
|
166
|
+
* @param {object} color - Decomposed color
|
|
167
|
+
* @param {string} color.type - One of: 'rgb', 'rgba', 'hsl', 'hsla'
|
|
168
|
+
* @param {array} color.values - [n,n,n] or [n,n,n,n]
|
|
169
|
+
* @returns {string} A CSS color string
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
export const recomposeColor = color => {
|
|
173
|
+
const {
|
|
174
|
+
type
|
|
175
|
+
} = color;
|
|
176
|
+
let {
|
|
177
|
+
values
|
|
178
|
+
} = color;
|
|
179
|
+
|
|
180
|
+
if (type.indexOf('rgb') !== -1) {
|
|
181
|
+
// Only convert the first 3 values to int (i.e. not alpha)
|
|
182
|
+
values = values.map((n, i) => i < 3 ? parseInt(n, 10) : n);
|
|
183
|
+
} else if (type.indexOf('hsl') !== -1) {
|
|
184
|
+
values[1] = `${values[1]}%`;
|
|
185
|
+
values[2] = `${values[2]}%`;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return `${type}(${values.join(', ')})`;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Calculates the contrast ratio between two colors.
|
|
192
|
+
*
|
|
193
|
+
* Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
|
|
194
|
+
*
|
|
195
|
+
* @param {string} foreground - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
196
|
+
* @param {string} background - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
197
|
+
* @returns {number} A contrast ratio value in the range 0 - 21.
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
export const getContrastRatio = (foreground, background) => {
|
|
201
|
+
const lumA = getLuminance(foreground);
|
|
202
|
+
const lumB = getLuminance(background);
|
|
203
|
+
return (Math.max(lumA, lumB) + 0.05) / (Math.min(lumA, lumB) + 0.05);
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* The relative brightness of any point in a color space,
|
|
207
|
+
* normalized to 0 for darkest black and 1 for lightest white.
|
|
208
|
+
*
|
|
209
|
+
* Formula: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
|
|
210
|
+
*
|
|
211
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
212
|
+
* @returns {number} The relative brightness of the color in the range 0 - 1
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
export const getLuminance = color => {
|
|
216
|
+
color = decomposeColor(color);
|
|
217
|
+
let rgb = color.type === 'hsl' ? decomposeColor(hslToRgb(color)).values : color.values;
|
|
218
|
+
rgb = rgb.map(val => {
|
|
219
|
+
val /= 255; // normalized
|
|
220
|
+
|
|
221
|
+
return val <= 0.03928 ? val / 12.92 : ((val + 0.055) / 1.055) ** 2.4;
|
|
222
|
+
}); // Truncate at 3 digits
|
|
223
|
+
|
|
224
|
+
return Number((0.2126 * rgb[0] + 0.7152 * rgb[1] + 0.0722 * rgb[2]).toFixed(3));
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Darken or lighten a color, depending on its luminance.
|
|
228
|
+
* Light colors are darkened, dark colors are lightened.
|
|
229
|
+
*
|
|
230
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
231
|
+
* @param {number} coefficient=0.15 - multiplier in the range 0 - 1
|
|
232
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
233
|
+
*/
|
|
234
|
+
|
|
235
|
+
export const emphasize = (color, coefficient = 0.15) => {
|
|
236
|
+
return getLuminance(color) > 0.5 ? darken(color, coefficient) : lighten(color, coefficient);
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Set the absolute transparency of a color.
|
|
240
|
+
* Any existing alpha values are overwritten.
|
|
241
|
+
*
|
|
242
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
243
|
+
* @param {number} value - value to set the alpha channel to in the range 0 -1
|
|
244
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
export const fade = (color, value) => {
|
|
248
|
+
color = decomposeColor(color);
|
|
249
|
+
value = clamp(value);
|
|
250
|
+
|
|
251
|
+
if (color.type === 'rgb' || color.type === 'hsl') {
|
|
252
|
+
color.type += 'a';
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
color.values[3] = value;
|
|
256
|
+
return recomposeColor(color);
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Darkens a color.
|
|
260
|
+
*
|
|
261
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
262
|
+
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
263
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
264
|
+
*/
|
|
265
|
+
|
|
266
|
+
export const darken = (color, coefficient) => {
|
|
267
|
+
color = decomposeColor(color);
|
|
268
|
+
coefficient = clamp(coefficient);
|
|
269
|
+
|
|
270
|
+
if (color.type.indexOf('hsl') !== -1) {
|
|
271
|
+
color.values[2] *= 1 - coefficient;
|
|
272
|
+
} else if (color.type.indexOf('rgb') !== -1) {
|
|
273
|
+
for (let i = 0; i < 3; i += 1) {
|
|
274
|
+
color.values[i] *= 1 - coefficient;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return recomposeColor(color);
|
|
279
|
+
};
|
|
280
|
+
/**
|
|
281
|
+
* Lightens a color.
|
|
282
|
+
*
|
|
283
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
284
|
+
* @param {number} coefficient - multiplier in the range 0 - 1
|
|
285
|
+
* @returns {string} A CSS color string. Hex input values are returned as rgb
|
|
286
|
+
*/
|
|
287
|
+
|
|
288
|
+
export const lighten = (color, coefficient) => {
|
|
289
|
+
color = decomposeColor(color);
|
|
290
|
+
coefficient = clamp(coefficient);
|
|
291
|
+
|
|
292
|
+
if (color.type.indexOf('hsl') !== -1) {
|
|
293
|
+
color.values[2] += (100 - color.values[2]) * coefficient;
|
|
294
|
+
} else if (color.type.indexOf('rgb') !== -1) {
|
|
295
|
+
for (let i = 0; i < 3; i += 1) {
|
|
296
|
+
color.values[i] += (255 - color.values[i]) * coefficient;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return recomposeColor(color);
|
|
301
|
+
};
|
|
302
|
+
/**
|
|
303
|
+
* Validate a color string.
|
|
304
|
+
*
|
|
305
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
306
|
+
* @returns {boolean} is a color
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
export const isColor = color => {
|
|
310
|
+
const regex = /(^#([0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$|^(rgb|hsl)a\((\d{1,3}%?,\s?){3}(1|0|0?\.\d+)\)$|^(rgb|hsl)\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$)/igm;
|
|
311
|
+
return regex.test(color);
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Detect a color string type.
|
|
315
|
+
*
|
|
316
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
317
|
+
* @returns {string | false} color type, string or false
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
export const detectColor = color => {
|
|
321
|
+
if (color && isColor(color)) {
|
|
322
|
+
if (/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.test(color)) return 'hex';
|
|
323
|
+
if (/^#([0-9a-f]{4}|[0-9a-f]{8})$/i.test(color)) return 'hexa';
|
|
324
|
+
if (/^rgb\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$/i.test(color)) return 'rgb';
|
|
325
|
+
if (/^rgba\((\d{1,3}%?,\s?){3}(1|0|0?\.\d+)\)$/i.test(color)) return 'rgba';
|
|
326
|
+
if (/^hsl\(\d{1,3}%?(,\s?\d{1,3}%?){2}\)$/i.test(color)) return 'hsl';
|
|
327
|
+
if (/^hsla\((\d{1,3}%?,\s?){3}(1|0|0?\.\d+)\)$/i.test(color)) return 'hsla';
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return null;
|
|
331
|
+
};
|
|
332
|
+
export const colorNames = {
|
|
333
|
+
aliceblue: '#f0f8ff',
|
|
334
|
+
antiquewhite: '#faebd7',
|
|
335
|
+
aqua: '#00ffff',
|
|
336
|
+
aquamarine: '#7fffd4',
|
|
337
|
+
azure: '#f0ffff',
|
|
338
|
+
beige: '#f5f5dc',
|
|
339
|
+
bisque: '#ffe4c4',
|
|
340
|
+
black: '#000000',
|
|
341
|
+
blanchedalmond: '#ffebcd',
|
|
342
|
+
blue: '#0000ff',
|
|
343
|
+
blueviolet: '#8a2be2',
|
|
344
|
+
brown: '#a52a2a',
|
|
345
|
+
burlywood: '#deb887',
|
|
346
|
+
cadetblue: '#5f9ea0',
|
|
347
|
+
chartreuse: '#7fff00',
|
|
348
|
+
chocolate: '#d2691e',
|
|
349
|
+
coral: '#ff7f50',
|
|
350
|
+
cornflowerblue: '#6495ed',
|
|
351
|
+
cornsilk: '#fff8dc',
|
|
352
|
+
crimson: '#dc143c',
|
|
353
|
+
cyan: '#00ffff',
|
|
354
|
+
darkblue: '#00008b',
|
|
355
|
+
darkcyan: '#008b8b',
|
|
356
|
+
darkgoldenrod: '#b8860b',
|
|
357
|
+
darkgray: '#a9a9a9',
|
|
358
|
+
darkgreen: '#006400',
|
|
359
|
+
darkkhaki: '#bdb76b',
|
|
360
|
+
darkmagenta: '#8b008b',
|
|
361
|
+
darkolivegreen: '#556b2f',
|
|
362
|
+
darkorange: '#ff8c00',
|
|
363
|
+
darkorchid: '#9932cc',
|
|
364
|
+
darkred: '#8b0000',
|
|
365
|
+
darksalmon: '#e9967a',
|
|
366
|
+
darkseagreen: '#8fbc8f',
|
|
367
|
+
darkslateblue: '#483d8b',
|
|
368
|
+
darkslategray: '#2f4f4f',
|
|
369
|
+
darkturquoise: '#00ced1',
|
|
370
|
+
darkviolet: '#9400d3',
|
|
371
|
+
deeppink: '#ff1493',
|
|
372
|
+
deepskyblue: '#00bfff',
|
|
373
|
+
dimgray: '#696969',
|
|
374
|
+
dodgerblue: '#1e90ff',
|
|
375
|
+
firebrick: '#b22222',
|
|
376
|
+
floralwhite: '#fffaf0',
|
|
377
|
+
forestgreen: '#228b22',
|
|
378
|
+
fuchsia: '#ff00ff',
|
|
379
|
+
gainsboro: '#dcdcdc',
|
|
380
|
+
ghostwhite: '#f8f8ff',
|
|
381
|
+
gold: '#ffd700',
|
|
382
|
+
goldenrod: '#daa520',
|
|
383
|
+
gray: '#808080',
|
|
384
|
+
green: '#008000',
|
|
385
|
+
greenyellow: '#adff2f',
|
|
386
|
+
honeydew: '#f0fff0',
|
|
387
|
+
hotpink: '#ff69b4',
|
|
388
|
+
indianred: '#cd5c5c',
|
|
389
|
+
indigo: '#4b0082',
|
|
390
|
+
ivory: '#fffff0',
|
|
391
|
+
khaki: '#f0e68c',
|
|
392
|
+
lavender: '#e6e6fa',
|
|
393
|
+
lavenderblush: '#fff0f5',
|
|
394
|
+
lawngreen: '#7cfc00',
|
|
395
|
+
lemonchiffon: '#fffacd',
|
|
396
|
+
lightblue: '#add8e6',
|
|
397
|
+
lightcoral: '#f08080',
|
|
398
|
+
lightcyan: '#e0ffff',
|
|
399
|
+
lightgoldenrodyellow: '#fafad2',
|
|
400
|
+
lightgreen: '#90ee90',
|
|
401
|
+
lightgrey: '#d3d3d3',
|
|
402
|
+
lightpink: '#ffb6c1',
|
|
403
|
+
lightsalmon: '#ffa07a',
|
|
404
|
+
lightseagreen: '#20b2aa',
|
|
405
|
+
lightskyblue: '#87cefa',
|
|
406
|
+
lightslategray: '#778899',
|
|
407
|
+
lightsteelblue: '#b0c4de',
|
|
408
|
+
lightyellow: '#ffffe0',
|
|
409
|
+
lime: '#00ff00',
|
|
410
|
+
limegreen: '#32cd32',
|
|
411
|
+
linen: '#faf0e6',
|
|
412
|
+
magenta: '#ff00ff',
|
|
413
|
+
maroon: '#800000',
|
|
414
|
+
mediumaquamarine: '#66cdaa',
|
|
415
|
+
mediumblue: '#0000cd',
|
|
416
|
+
mediumorchid: '#ba55d3',
|
|
417
|
+
mediumpurple: '#9370d8',
|
|
418
|
+
mediumseagreen: '#3cb371',
|
|
419
|
+
mediumslateblue: '#7b68ee',
|
|
420
|
+
mediumspringgreen: '#00fa9a',
|
|
421
|
+
mediumturquoise: '#48d1cc',
|
|
422
|
+
mediumvioletred: '#c71585',
|
|
423
|
+
midnightblue: '#191970',
|
|
424
|
+
mintcream: '#f5fffa',
|
|
425
|
+
mistyrose: '#ffe4e1',
|
|
426
|
+
moccasin: '#ffe4b5',
|
|
427
|
+
navajowhite: '#ffdead',
|
|
428
|
+
navy: '#000080',
|
|
429
|
+
oldlace: '#fdf5e6',
|
|
430
|
+
olive: '#808000',
|
|
431
|
+
olivedrab: '#6b8e23',
|
|
432
|
+
orange: '#ffa500',
|
|
433
|
+
orangered: '#ff4500',
|
|
434
|
+
orchid: '#da70d6',
|
|
435
|
+
palegoldenrod: '#eee8aa',
|
|
436
|
+
palegreen: '#98fb98',
|
|
437
|
+
paleturquoise: '#afeeee',
|
|
438
|
+
palevioletred: '#d87093',
|
|
439
|
+
papayawhip: '#ffefd5',
|
|
440
|
+
peachpuff: '#ffdab9',
|
|
441
|
+
peru: '#cd853f',
|
|
442
|
+
pink: '#ffc0cb',
|
|
443
|
+
plum: '#dda0dd',
|
|
444
|
+
powderblue: '#b0e0e6',
|
|
445
|
+
purple: '#800080',
|
|
446
|
+
rebeccapurple: '#663399',
|
|
447
|
+
red: '#ff0000',
|
|
448
|
+
rosybrown: '#bc8f8f',
|
|
449
|
+
royalblue: '#4169e1',
|
|
450
|
+
saddlebrown: '#8b4513',
|
|
451
|
+
salmon: '#fa8072',
|
|
452
|
+
sandybrown: '#f4a460',
|
|
453
|
+
seagreen: '#2e8b57',
|
|
454
|
+
seashell: '#fff5ee',
|
|
455
|
+
sienna: '#a0522d',
|
|
456
|
+
silver: '#c0c0c0',
|
|
457
|
+
skyblue: '#87ceeb',
|
|
458
|
+
slateblue: '#6a5acd',
|
|
459
|
+
slategray: '#708090',
|
|
460
|
+
snow: '#fffafa',
|
|
461
|
+
springgreen: '#00ff7f',
|
|
462
|
+
steelblue: '#4682b4',
|
|
463
|
+
tan: '#d2b48c',
|
|
464
|
+
teal: '#008080',
|
|
465
|
+
thistle: '#d8bfd8',
|
|
466
|
+
tomato: '#ff6347',
|
|
467
|
+
turquoise: '#40e0d0',
|
|
468
|
+
violet: '#ee82ee',
|
|
469
|
+
wheat: '#f5deb3',
|
|
470
|
+
white: '#ffffff',
|
|
471
|
+
whitesmoke: '#f5f5f5',
|
|
472
|
+
yellow: '#ffff00',
|
|
473
|
+
yellowgreen: '#9acd32'
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Validate a color name.
|
|
477
|
+
*
|
|
478
|
+
* @param {string} color - CSS color, i.e. one of: #nnn, #nnnnnn, rgb(), rgba(), hsl(), hsla()
|
|
479
|
+
* @returns {boolean} is a color
|
|
480
|
+
*/
|
|
481
|
+
|
|
482
|
+
export const isColorName = color => {
|
|
483
|
+
const plaintColor = color.replace(/\s+/g, '').trim().toLowerCase();
|
|
484
|
+
if (typeof colorNames[plaintColor] !== 'undefined') return colorNames[plaintColor];
|
|
485
|
+
return false;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* Convert from #ffffff to rgba()
|
|
489
|
+
* @param hex color - #ffffff
|
|
490
|
+
* @param {number} alpha - 0.5
|
|
491
|
+
* @returns {string} color - rgba()
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
export const hexToRGBA = (hex, alpha) => {
|
|
495
|
+
var r = parseInt(hex.slice(1, 3), 16),
|
|
496
|
+
g = parseInt(hex.slice(3, 5), 16),
|
|
497
|
+
b = parseInt(hex.slice(5, 7), 16);
|
|
498
|
+
|
|
499
|
+
if (alpha) {
|
|
500
|
+
return "rgba(" + r + ", " + g + ", " + b + ", " + alpha + ")";
|
|
501
|
+
} else {
|
|
502
|
+
return "rgb(" + r + ", " + g + ", " + b + ")";
|
|
503
|
+
}
|
|
504
|
+
};
|