@para-ui/core 3.0.86 → 4.0.0-alpha
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/AutoBox/index.js +18 -19
- package/AutoTips/index.js +5 -4
- package/Breadcrumbs/index.js +5 -4
- package/Button/SplitButton.d.ts +13 -0
- package/Button/index.d.ts +1 -1
- package/Button/index.js +54 -12
- package/ButtonGroup/index.js +6 -5
- package/Carousel/index.d.ts +5 -5
- package/Carousel/index.js +21 -9
- package/Cascader/Cascader.d.ts +99 -0
- package/Cascader/OptionList/CacheContent.d.ts +7 -0
- package/Cascader/OptionList/Column.d.ts +21 -0
- package/Cascader/OptionList/index.d.ts +4 -0
- package/Cascader/OptionList/useActive.d.ts +6 -0
- package/Cascader/context.d.ts +23 -0
- package/Cascader/hooks/useDisplayValues.d.ts +10 -0
- package/Cascader/hooks/useEntities.d.ts +10 -0
- package/Cascader/hooks/useMissingValues.d.ts +3 -0
- package/Cascader/index.d.ts +3 -58
- package/Cascader/index.js +28 -177
- package/Cascader/utils/commonUtil.d.ts +18 -0
- package/Cascader/utils/treeUtil.d.ts +55 -0
- package/Checkbox/index.d.ts +7 -0
- package/Checkbox/index.js +50 -29
- package/CheckboxGroup/index.d.ts +3 -1
- package/CheckboxGroup/index.js +48 -18
- package/Collapse/index.js +2 -2
- package/Collapse/motion.d.ts +0 -2
- package/CollapseBox/index.js +3 -3
- package/CollapseLayout/index.d.ts +5 -0
- package/CollapseLayout/index.js +144 -22
- package/ColorPicker/chromePicker/index.d.ts +9 -0
- package/ColorPicker/compactPicker/index.d.ts +9 -0
- package/ColorPicker/config.d.ts +5 -0
- package/ColorPicker/index.d.ts +4 -1
- package/ColorPicker/index.js +7 -3
- package/ColorPicker/sketchPicker/index.d.ts +11 -0
- package/ColorPicker/swatchesPicker/index.d.ts +9 -0
- package/ComboSelect/index.js +14 -12
- package/Container/index.js +2 -2
- package/CopyText/index.d.ts +33 -0
- package/CopyText/index.js +180 -0
- package/DatePicker/generatePicker/generateRangePicker.d.ts +9 -2
- package/DatePicker/generatePicker/generateSinglePicker.d.ts +8 -8
- package/DatePicker/generatePicker/index.d.ts +32 -26
- package/DatePicker/generatePicker/interface.d.ts +12 -0
- package/DatePicker/index.d.ts +12 -8
- package/DatePicker/index.js +367 -454
- package/DatePicker/util.d.ts +40 -4
- package/Desktop/index.d.ts +16 -3
- package/Desktop/index.js +177 -68
- package/Desktop/lang/en_US.d.ts +6 -0
- package/Desktop/lang/index.d.ts +13 -0
- package/Desktop/lang/zh_CN.d.ts +6 -0
- package/DragVerify/index.js +9 -100
- package/Drawer/index.js +8 -8
- package/Drawer/interface.d.ts +2 -2
- package/Dropdown/index.js +2 -2
- package/DynamicMultiBox/index.js +57 -41
- package/DynamicMultiBox/interface.d.ts +4 -4
- package/Empty/index.js +2 -2
- package/Form/index.d.ts +20 -26
- package/Form/index.js +48 -69
- package/FormItem/index.js +15 -15
- package/FunctionModal/index.js +11 -9
- package/GlobalContext/constant.d.ts +1 -1
- package/GlobalContext/index.js +2 -2
- package/Help/index.js +4 -3
- package/HelperText/index.js +2 -2
- package/InputLang/index.d.ts +5 -0
- package/InputLang/index.js +35 -29
- package/InputNumber/index.d.ts +5 -0
- package/InputNumber/index.js +95 -80
- package/Label/index.js +4 -3
- package/Loading/index.js +2 -2
- package/Menu/index.js +114 -39
- package/Menu/interface.d.ts +8 -0
- package/Message/index.d.ts +4 -4
- package/Message/index.js +13 -11
- package/Modal/index.js +29 -15
- package/MultiBox/index.js +9 -8
- package/Notification/index.d.ts +9 -1
- package/Notification/index.js +29 -15
- package/OperateBtn/index.js +28 -11
- package/PageHeader/index.js +270 -74
- package/PageHeader/interface.d.ts +17 -0
- package/Pagination/index.d.ts +4 -3
- package/Pagination/index.js +117 -95
- package/Pagination/lang/en_US.d.ts +3 -2
- package/Pagination/lang/index.d.ts +6 -4
- package/Pagination/lang/zh_CN.d.ts +3 -2
- package/ParauiProvider/index.js +4 -4
- package/PasswordRules/index.js +5 -5
- package/PopConfirm/index.d.ts +15 -5
- package/PopConfirm/index.js +62 -16
- package/Popover/index.js +4 -3
- package/Progress/index.js +10 -9
- package/Querying/index.js +7 -7
- package/README.md +40 -1120
- package/Radio/index.d.ts +7 -0
- package/Radio/index.js +49 -27
- package/RadioGroup/index.d.ts +3 -1
- package/RadioGroup/index.js +48 -21
- package/Search/index.d.ts +3 -15
- package/Search/index.js +21 -83
- package/Select/index.d.ts +7 -2
- package/Select/index.js +114 -91
- package/Select/lang/en_US.d.ts +1 -1
- package/Select/lang/index.d.ts +2 -2
- package/Select/lang/zh_CN.d.ts +1 -1
- package/SelectInput/index.js +8 -7
- package/Selector/index.js +30 -22
- package/SelectorPicker/index.d.ts +5 -0
- package/SelectorPicker/index.js +47 -32
- package/SelectorPicker/lang/en_US.d.ts +1 -0
- package/SelectorPicker/lang/index.d.ts +2 -0
- package/SelectorPicker/lang/zh_CN.d.ts +1 -0
- package/SingleBox/index.js +8 -7
- package/Slider/index.js +5 -5
- package/Status/index.d.ts +6 -5
- package/Status/index.js +27 -4
- package/Stepper/index.d.ts +9 -10
- package/Stepper/index.js +69 -29
- package/Styles/index.scss +4 -0
- package/Styles/scrollbar.scss +24 -24
- package/Styles/theme.scss +104 -57
- package/Switch/index.d.ts +34 -14
- package/Switch/index.js +97 -30
- package/Table/index.js +33 -27
- package/Table/interface.d.ts +3 -1
- package/Table/tableHeadInterface.d.ts +1 -1
- package/Table/tablePaginationInterface.d.ts +5 -5
- package/Tabs/index.d.ts +11 -1
- package/Tabs/index.js +49 -16
- package/Tag/TagGroup.d.ts +11 -7
- package/Tag/index.d.ts +22 -7
- package/Tag/index.js +1382 -53
- package/TextEditor/index.js +4 -3
- package/TextField/index.d.ts +5 -0
- package/TextField/index.js +50 -32
- package/TimePicker/index.d.ts +5 -0
- package/TimePicker/index.js +39 -23
- package/Timeline/TimelineItem.d.ts +1 -1
- package/Timeline/index.d.ts +5 -5
- package/Timeline/index.js +21 -18
- package/Title/index.d.ts +15 -3
- package/Title/index.js +95 -29
- package/ToggleButton/ToggleButtonGroup.d.ts +1 -0
- package/ToggleButton/index.d.ts +4 -0
- package/ToggleButton/index.js +14 -52
- package/Tooltip/index.js +28 -34
- package/Tooltip/interface.d.ts +4 -10
- package/Tooltip/utils.d.ts +1 -3
- package/Transfer/index.d.ts +3 -3
- package/Transfer/index.js +72 -68
- package/Tree/Tree.d.ts +2 -2
- package/Tree/index.js +10 -9
- package/Tree/utils/treeUtil.d.ts +0 -7
- package/Upload/index.js +16 -14
- package/_verture/{constant-66aa48a1.js → constant-0d9802f7.js} +1 -1
- package/_verture/{defineProperty-62acccfc.js → defineProperty-1d116156.js} +1 -1
- package/_verture/index-5c77417d.js +150 -0
- package/_verture/index-68db2bc3.js +10530 -0
- package/_verture/{index-9738004e.js → index-7ec72724.js} +44 -38
- package/_verture/index-d63bd287.js +327 -0
- package/_verture/{index-fa8a0124.js → index-e6f85fd5.js} +7 -8
- package/_verture/{index-77f9e0fb.js → index-e9007d6a.js} +6 -6
- package/_verture/{intl-4a9f1b44.js → intl-5c1ec055.js} +1 -1
- package/_verture/{modalContext-20780c9a.js → modalContext-c12ca3e8.js} +3 -3
- package/_verture/slicedToArray-a8206399.js +43 -0
- package/_verture/{toConsumableArray-81040c9e.js → toConsumableArray-8f4c9589.js} +1 -1
- package/_verture/typeof-adeedc13.js +11 -0
- package/_verture/typeof-b240b062.js +16 -0
- package/_verture/{utils-c9b9a157.js → utils-f0e81540.js} +8 -8
- package/index.d.ts +2 -2
- package/index.js +32 -27
- package/locale/en-US.d.ts +10 -6
- package/locale/index.d.ts +20 -12
- package/locale/index.js +33 -25
- package/locale/zh-CN.d.ts +10 -6
- package/package.json +25 -11
- package/umd/AutoBox.js +20 -21
- package/umd/AutoTips.js +31 -4
- package/umd/Breadcrumbs.js +7 -7
- package/umd/Button.js +7 -8
- package/umd/ButtonGroup.js +7 -8
- package/umd/Carousel.js +29 -1
- package/umd/Cascader.js +20 -21
- package/umd/Checkbox.js +7 -7
- package/umd/CheckboxGroup.js +7 -7
- package/umd/Collapse.js +19 -21
- package/umd/CollapseBox.js +1 -1
- package/umd/CollapseLayout.js +4 -4
- package/umd/ColorPicker.js +1 -1
- package/umd/ComboSelect.js +7 -7
- package/umd/Container.js +1 -1
- package/umd/CopyText.js +42 -0
- package/umd/DatePicker.js +7 -7
- package/umd/Desktop.js +7 -7
- package/umd/DragVerify.js +4 -4
- package/umd/Drawer.js +7 -8
- package/umd/Dropdown.js +3 -3
- package/umd/DynamicMultiBox.js +7 -7
- package/umd/Empty.js +1 -1
- package/umd/Form.js +6 -6
- package/umd/FormItem.js +6 -6
- package/umd/FunctionModal.js +7 -7
- package/umd/Help.js +7 -7
- package/umd/HelperText.js +1 -1
- package/umd/InputLang.js +7 -7
- package/umd/InputNumber.js +7 -7
- package/umd/Label.js +7 -7
- package/umd/Loading.js +4 -5
- package/umd/Menu.js +4 -4
- package/umd/Message.js +3 -4
- package/umd/Modal.js +7 -7
- package/umd/MultiBox.js +7 -7
- package/umd/Notification.js +5 -6
- package/umd/OperateBtn.js +7 -7
- package/umd/PageHeader.js +7 -7
- package/umd/Pagination.js +7 -7
- package/umd/ParauiProvider.js +1 -1
- package/umd/PasswordRules.js +3 -4
- package/umd/PopConfirm.js +7 -7
- package/umd/Popover.js +31 -4
- package/umd/Progress.js +4 -5
- package/umd/Querying.js +1 -1
- package/umd/Radio.js +7 -7
- package/umd/RadioGroup.js +7 -7
- package/umd/Search.js +7 -7
- package/umd/Select.js +7 -7
- package/umd/SelectInput.js +7 -7
- package/umd/Selector.js +7 -7
- package/umd/SelectorPicker.js +7 -7
- package/umd/SingleBox.js +7 -7
- package/umd/Slider.js +3 -3
- package/umd/Status.js +29 -1
- package/umd/Stepper.js +20 -20
- package/umd/Switch.js +7 -7
- package/umd/Table.js +7 -7
- package/umd/Tabs.js +7 -7
- package/umd/Tag.js +7 -8
- package/umd/TextEditor.js +19 -19
- package/umd/TextField.js +7 -7
- package/umd/TimePicker.js +7 -7
- package/umd/Timeline.js +1 -1
- package/umd/Title.js +42 -1
- package/umd/ToggleButton.js +7 -8
- package/umd/Tooltip.js +31 -4
- package/umd/Transfer.js +8 -8
- package/umd/Tree.js +7 -7
- package/umd/Upload.js +8 -8
- package/umd/locale.js +1 -1
- package/Cascader/lang/en_US.d.ts +0 -4
- package/Cascader/lang/index.d.ts +0 -9
- package/Cascader/lang/zh_CN.d.ts +0 -4
- package/Split/index.d.ts +0 -7
- package/Split/index.js +0 -123
- package/_verture/index-a369ca3f.js +0 -4
- package/_verture/index-beef914f.js +0 -340
- package/_verture/slicedToArray-76060636.js +0 -43
- package/_verture/typeof-498dd2b1.js +0 -11
- package/umd/Split.js +0 -1
package/Tag/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { _ as _defineProperty } from '../_verture/defineProperty-
|
|
2
|
-
import { _ as _slicedToArray } from '../_verture/slicedToArray-
|
|
1
|
+
import { _ as _defineProperty } from '../_verture/defineProperty-1d116156.js';
|
|
2
|
+
import { _ as _slicedToArray } from '../_verture/slicedToArray-a8206399.js';
|
|
3
3
|
import { _ as __rest } from '../_verture/tslib.es6-55ed4bd2.js';
|
|
4
4
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { useState, useRef, useEffect } from 'react';
|
|
6
6
|
import CloseIcon from '@para-ui/icons/Close';
|
|
7
|
+
import EditIcon from '@para-ui/icons/EditOutline';
|
|
7
8
|
import clsx from 'clsx';
|
|
8
|
-
import { _ as _toConsumableArray } from '../_verture/toConsumableArray-
|
|
9
|
-
import { _ as _typeof } from '../_verture/typeof-
|
|
10
|
-
import { $ as $prefixCls } from '../_verture/constant-
|
|
9
|
+
import { _ as _toConsumableArray } from '../_verture/toConsumableArray-8f4c9589.js';
|
|
10
|
+
import { _ as _typeof$1 } from '../_verture/typeof-adeedc13.js';
|
|
11
|
+
import { $ as $prefixCls } from '../_verture/constant-0d9802f7.js';
|
|
11
12
|
import AutoTips from '../AutoTips/index.js';
|
|
12
13
|
import { s as styleInject } from '../_verture/style-inject.es-300983ab.js';
|
|
13
14
|
import Plus from '@para-ui/icons/Plus';
|
|
@@ -15,29 +16,30 @@ import '../_verture/unsupportedIterableToArray-cb478f24.js';
|
|
|
15
16
|
import '../Tooltip/index.js';
|
|
16
17
|
import 'rc-tooltip';
|
|
17
18
|
import 'rc-tooltip/lib/placements';
|
|
19
|
+
import '@para-ui/icons/Forbid';
|
|
18
20
|
import '@paraview/lib';
|
|
19
21
|
|
|
20
|
-
var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/1/12 上午9:43\n* @description\n*/\n/**\n* @author
|
|
22
|
+
var css_248z = "@charset \"UTF-8\";\n/**\n* @author Hanz\n* @date 2022/1/12 上午9:43\n* @description\n*/\n/**\n* @author linhd\n* @date 2023/4/11 14:16\n* @description 最新色卡\n*/\n.paraui-v4-tag-outline.paraui-v4-tag {\n border: 0.5px solid rgb(92, 101, 115);\n}\n.paraui-v4-tag-outline.paraui-v4-tag-blue {\n border: 0.5px solid rgb(46, 101, 230);\n}\n.paraui-v4-tag-outline.paraui-v4-tag-green {\n border: 0.5px solid rgb(19, 191, 76);\n}\n.paraui-v4-tag-outline.paraui-v4-tag-yellow {\n border: 0.5px solid rgb(255, 147, 38);\n}\n.paraui-v4-tag-outline.paraui-v4-tag-red {\n border: 0.5px solid rgb(244, 66, 66);\n}\n\n.paraui-v4-tag-edit-input {\n height: 24px;\n align-self: flex-start;\n margin: 0 8px 8px 0;\n font-size: 14px;\n color: rgb(29, 33, 38);\n text-indent: 8px;\n border: 1px solid rgb(46, 101, 230);\n border-radius: 4px;\n}\n\n.paraui-v4-tag {\n display: inline-flex;\n justify-content: center;\n align-items: center;\n max-width: 100%;\n height: 24px;\n margin: 0 8px 8px 0;\n padding: 0 10px;\n font-size: 14px;\n color: rgb(29, 33, 38);\n white-space: nowrap;\n background: rgb(234, 236, 241);\n border-radius: 4px;\n line-height: 18px;\n}\n.paraui-v4-tag .tag-close-icon:hover {\n background-color: rgb(212, 218, 227);\n}\n.paraui-v4-tag .tag-edit-icon {\n display: flex;\n}\n.paraui-v4-tag.paraui-v4-tag-small {\n height: 20px;\n font-size: 12px;\n padding: 0 6px;\n}\n.paraui-v4-tag.paraui-v4-tag-small > svg {\n font-size: 12px;\n}\n.paraui-v4-tag.paraui-v4-tag-small > svg + .paraui-v4-auto-tips {\n margin-left: 2px;\n}\n.paraui-v4-tag.paraui-v4-tag-small .tag-close-icon {\n margin-left: 2px;\n}\n.paraui-v4-tag.paraui-v4-tag-small .tag-edit-icon {\n font-size: 12px;\n}\n.paraui-v4-tag > svg {\n color: inherit;\n font-size: 500;\n}\n.paraui-v4-tag .tag-edit-icon {\n color: inherit;\n font-size: 500;\n cursor: pointer;\n}\n.paraui-v4-tag .tag-edit-icon > svg {\n color: rgb(29, 33, 38);\n}\n.paraui-v4-tag .tag-close-icon {\n margin-left: 4px;\n color: inherit;\n font-size: 500;\n cursor: pointer;\n}\n.paraui-v4-tag .tag-close-icon:hover {\n color: inherit;\n}\n.paraui-v4-tag > svg + .paraui-v4-auto-tips {\n margin-left: 4px;\n}\n.paraui-v4-tag.paraui-v4-tag-has-color, .paraui-v4-tag.paraui-v4-tag-has-color svg, .paraui-v4-tag.paraui-v4-tag-has-color svg:hover {\n color: inherit;\n}\n.paraui-v4-tag.paraui-v4-tag-blue {\n color: rgb(46, 101, 230);\n background-color: rgba(46, 101, 230, 0.1);\n}\n.paraui-v4-tag.paraui-v4-tag-green {\n color: rgb(19, 191, 76);\n background-color: rgba(19, 191, 76, 0.1);\n}\n.paraui-v4-tag.paraui-v4-tag-yellow {\n color: rgb(255, 147, 38);\n background-color: rgba(255, 147, 38, 0.1);\n}\n.paraui-v4-tag.paraui-v4-tag-red {\n color: rgb(244, 66, 66);\n background-color: rgba(244, 66, 66, 0.1);\n}\n.paraui-v4-tag.paraui-v4-tag-hidden {\n display: none;\n}\n\n.paraui-v4-tag-group {\n display: flex;\n align-items: center;\n flex-flow: row wrap;\n}\n.paraui-v4-tag-group .tag-group-input {\n height: 24px;\n align-self: flex-start;\n font-size: 14px;\n color: rgb(29, 33, 38);\n text-indent: 8px;\n border: 1px solid rgb(46, 101, 230);\n border-radius: 4px;\n}\n.paraui-v4-tag-group .tag-group-input .tag-group-input-large {\n height: 28px;\n}\n.paraui-v4-tag-group .tag-group-new .tag-group-new-icon {\n padding: 0 5px;\n}\n.paraui-v4-tag-group .tag-group-add-btn {\n border: 1px dashed rgb(212, 218, 227);\n}\n.paraui-v4-tag-group .tag-group-add-btn .tag-edit-icon {\n background: none !important;\n}\n.paraui-v4-tag-group .tag-group-add-btn:hover {\n cursor: pointer;\n}\n.paraui-v4-tag-group .tag-group-add-btn:hover svg {\n color: rgb(46, 101, 230);\n}\n.paraui-v4-tag-group .tag-group-add-btn:hover .tag-text {\n color: rgb(46, 101, 230);\n}";
|
|
21
23
|
styleInject(css_248z);
|
|
22
24
|
|
|
23
25
|
//tag group
|
|
24
26
|
var TagGroup = function TagGroup(props) {
|
|
25
27
|
var className = props.className,
|
|
26
28
|
_props$size = props.size,
|
|
27
|
-
size = _props$size === void 0 ?
|
|
29
|
+
size = _props$size === void 0 ? "large" : _props$size,
|
|
28
30
|
style = props.style,
|
|
29
|
-
_props$bordered = props.bordered,
|
|
30
|
-
bordered = _props$bordered === void 0 ? false : _props$bordered,
|
|
31
31
|
defaultInputValue = props.defaultInputValue,
|
|
32
32
|
_props$increased = props.increased,
|
|
33
33
|
increased = _props$increased === void 0 ? false : _props$increased,
|
|
34
34
|
increasedTag = props.increasedTag,
|
|
35
|
+
inputClassName = props.inputClassName,
|
|
36
|
+
inputWidth = props.inputWidth,
|
|
35
37
|
onChange = props.onChange;
|
|
36
38
|
var _useState = useState([]),
|
|
37
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
38
40
|
inData = _useState2[0],
|
|
39
41
|
setInData = _useState2[1]; //数据源
|
|
40
|
-
var _useState3 = useState(defaultInputValue !== null && defaultInputValue !== void 0 ? defaultInputValue :
|
|
42
|
+
var _useState3 = useState(defaultInputValue !== null && defaultInputValue !== void 0 ? defaultInputValue : ""),
|
|
41
43
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
42
44
|
inputValue = _useState4[0],
|
|
43
45
|
setInputValue = _useState4[1]; //input value
|
|
@@ -46,12 +48,16 @@ var TagGroup = function TagGroup(props) {
|
|
|
46
48
|
inputVisible = _useState6[0],
|
|
47
49
|
setInputVisible = _useState6[1]; //input visible
|
|
48
50
|
var inputRef = useRef(); //input ref
|
|
51
|
+
var _useState7 = useState(),
|
|
52
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
53
|
+
increasedInputWidth = _useState8[0],
|
|
54
|
+
setIncreasedInputWidth = _useState8[1]; //添加标签的最小宽
|
|
49
55
|
useEffect(function () {
|
|
50
56
|
if (props.data) {
|
|
51
57
|
var tArr = props.data;
|
|
52
58
|
//Item[]
|
|
53
59
|
var unObjType = tArr.some(function (v) {
|
|
54
|
-
return [
|
|
60
|
+
return ["string", "number"].includes(_typeof$1(v));
|
|
55
61
|
});
|
|
56
62
|
if (unObjType) {
|
|
57
63
|
tArr = tArr.map(function (_) {
|
|
@@ -78,6 +84,11 @@ var TagGroup = function TagGroup(props) {
|
|
|
78
84
|
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
79
85
|
});
|
|
80
86
|
};
|
|
87
|
+
var handleTagEdit = function handleTagEdit(value, idx) {
|
|
88
|
+
inData[idx].value = value;
|
|
89
|
+
setInData(_toConsumableArray(inData));
|
|
90
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(inData, getTagGroupVal(inData));
|
|
91
|
+
};
|
|
81
92
|
//input change
|
|
82
93
|
var handleInputChange = function handleInputChange(e) {
|
|
83
94
|
setInputValue(e.target.value);
|
|
@@ -85,7 +96,7 @@ var TagGroup = function TagGroup(props) {
|
|
|
85
96
|
//input confirm
|
|
86
97
|
var handleInputConfirm = function handleInputConfirm() {
|
|
87
98
|
var val = inputValue.trim();
|
|
88
|
-
if (val !==
|
|
99
|
+
if (val !== "") {
|
|
89
100
|
inData.push({
|
|
90
101
|
value: val,
|
|
91
102
|
label: val,
|
|
@@ -94,7 +105,7 @@ var TagGroup = function TagGroup(props) {
|
|
|
94
105
|
setInData(_toConsumableArray(inData));
|
|
95
106
|
onChange === null || onChange === void 0 ? void 0 : onChange(inData, getTagGroupVal(inData));
|
|
96
107
|
}
|
|
97
|
-
setInputValue(defaultInputValue !== null && defaultInputValue !== void 0 ? defaultInputValue :
|
|
108
|
+
setInputValue(defaultInputValue !== null && defaultInputValue !== void 0 ? defaultInputValue : "");
|
|
98
109
|
setInputVisible(false);
|
|
99
110
|
};
|
|
100
111
|
//input enter
|
|
@@ -123,8 +134,10 @@ var TagGroup = function TagGroup(props) {
|
|
|
123
134
|
return inData.map(function (item, idx) {
|
|
124
135
|
return jsx(Tag, Object.assign({}, item, {
|
|
125
136
|
size: size,
|
|
126
|
-
bordered: bordered,
|
|
127
137
|
visible: true,
|
|
138
|
+
tagChange: function tagChange(value) {
|
|
139
|
+
return handleTagEdit(value, idx);
|
|
140
|
+
},
|
|
128
141
|
onClose: handleClose(item)
|
|
129
142
|
}, {
|
|
130
143
|
children: item.label
|
|
@@ -135,10 +148,14 @@ var TagGroup = function TagGroup(props) {
|
|
|
135
148
|
var renderNewInput = function renderNewInput() {
|
|
136
149
|
var _a;
|
|
137
150
|
if (inputVisible) {
|
|
138
|
-
var inputCls = clsx(
|
|
139
|
-
|
|
140
|
-
});
|
|
151
|
+
var inputCls = clsx("tag-group-input", {
|
|
152
|
+
"tag-group-input-large": size === "large"
|
|
153
|
+
}, inputClassName);
|
|
141
154
|
return jsx("input", {
|
|
155
|
+
style: {
|
|
156
|
+
width: inputWidth || increasedInputWidth,
|
|
157
|
+
minWidth: increasedInputWidth
|
|
158
|
+
},
|
|
142
159
|
type: "text",
|
|
143
160
|
ref: inputRef,
|
|
144
161
|
className: inputCls,
|
|
@@ -149,18 +166,20 @@ var TagGroup = function TagGroup(props) {
|
|
|
149
166
|
});
|
|
150
167
|
}
|
|
151
168
|
var icon = jsx(Plus, {});
|
|
152
|
-
var text =
|
|
169
|
+
var text = "New Tag";
|
|
153
170
|
if (increasedTag) {
|
|
154
171
|
icon = increasedTag.icon || jsx(Plus, {});
|
|
155
|
-
text = (_a = increasedTag.text) !== null && _a !== void 0 ? _a :
|
|
172
|
+
text = (_a = increasedTag.text) !== null && _a !== void 0 ? _a : "New Tag";
|
|
156
173
|
}
|
|
157
|
-
var newCls = clsx(
|
|
158
|
-
|
|
159
|
-
});
|
|
174
|
+
var newCls = clsx("tag-group-new", {
|
|
175
|
+
"tag-group-new-icon": !text
|
|
176
|
+
}, "tag-group-add-btn");
|
|
160
177
|
return jsx(Tag, Object.assign({
|
|
178
|
+
getWidth: function getWidth(width) {
|
|
179
|
+
return setIncreasedInputWidth(width);
|
|
180
|
+
},
|
|
161
181
|
className: newCls,
|
|
162
182
|
size: size,
|
|
163
|
-
bordered: bordered,
|
|
164
183
|
icon: icon,
|
|
165
184
|
onClick: showInput
|
|
166
185
|
}, {
|
|
@@ -175,36 +194,1257 @@ var TagGroup = function TagGroup(props) {
|
|
|
175
194
|
}));
|
|
176
195
|
};
|
|
177
196
|
|
|
197
|
+
// This file is autogenerated. It's used to publish ESM to npm.
|
|
198
|
+
function _typeof(obj) {
|
|
199
|
+
"@babel/helpers - typeof";
|
|
200
|
+
|
|
201
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
202
|
+
return typeof obj;
|
|
203
|
+
} : function (obj) {
|
|
204
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
205
|
+
}, _typeof(obj);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// https://github.com/bgrins/TinyColor
|
|
209
|
+
// Brian Grinstead, MIT License
|
|
210
|
+
|
|
211
|
+
var trimLeft = /^\s+/;
|
|
212
|
+
var trimRight = /\s+$/;
|
|
213
|
+
function tinycolor(color, opts) {
|
|
214
|
+
color = color ? color : "";
|
|
215
|
+
opts = opts || {};
|
|
216
|
+
|
|
217
|
+
// If input is already a tinycolor, return itself
|
|
218
|
+
if (color instanceof tinycolor) {
|
|
219
|
+
return color;
|
|
220
|
+
}
|
|
221
|
+
// If we are called as a function, call using new instead
|
|
222
|
+
if (!(this instanceof tinycolor)) {
|
|
223
|
+
return new tinycolor(color, opts);
|
|
224
|
+
}
|
|
225
|
+
var rgb = inputToRGB(color);
|
|
226
|
+
this._originalInput = color, this._r = rgb.r, this._g = rgb.g, this._b = rgb.b, this._a = rgb.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb.format;
|
|
227
|
+
this._gradientType = opts.gradientType;
|
|
228
|
+
|
|
229
|
+
// Don't let the range of [0,255] come back in [0,1].
|
|
230
|
+
// Potentially lose a little bit of precision here, but will fix issues where
|
|
231
|
+
// .5 gets interpreted as half of the total, instead of half of 1
|
|
232
|
+
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
|
|
233
|
+
if (this._r < 1) this._r = Math.round(this._r);
|
|
234
|
+
if (this._g < 1) this._g = Math.round(this._g);
|
|
235
|
+
if (this._b < 1) this._b = Math.round(this._b);
|
|
236
|
+
this._ok = rgb.ok;
|
|
237
|
+
}
|
|
238
|
+
tinycolor.prototype = {
|
|
239
|
+
isDark: function isDark() {
|
|
240
|
+
return this.getBrightness() < 128;
|
|
241
|
+
},
|
|
242
|
+
isLight: function isLight() {
|
|
243
|
+
return !this.isDark();
|
|
244
|
+
},
|
|
245
|
+
isValid: function isValid() {
|
|
246
|
+
return this._ok;
|
|
247
|
+
},
|
|
248
|
+
getOriginalInput: function getOriginalInput() {
|
|
249
|
+
return this._originalInput;
|
|
250
|
+
},
|
|
251
|
+
getFormat: function getFormat() {
|
|
252
|
+
return this._format;
|
|
253
|
+
},
|
|
254
|
+
getAlpha: function getAlpha() {
|
|
255
|
+
return this._a;
|
|
256
|
+
},
|
|
257
|
+
getBrightness: function getBrightness() {
|
|
258
|
+
//http://www.w3.org/TR/AERT#color-contrast
|
|
259
|
+
var rgb = this.toRgb();
|
|
260
|
+
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
|
|
261
|
+
},
|
|
262
|
+
getLuminance: function getLuminance() {
|
|
263
|
+
//http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
|
264
|
+
var rgb = this.toRgb();
|
|
265
|
+
var RsRGB, GsRGB, BsRGB, R, G, B;
|
|
266
|
+
RsRGB = rgb.r / 255;
|
|
267
|
+
GsRGB = rgb.g / 255;
|
|
268
|
+
BsRGB = rgb.b / 255;
|
|
269
|
+
if (RsRGB <= 0.03928) R = RsRGB / 12.92;else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
270
|
+
if (GsRGB <= 0.03928) G = GsRGB / 12.92;else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
271
|
+
if (BsRGB <= 0.03928) B = BsRGB / 12.92;else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
272
|
+
return 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
273
|
+
},
|
|
274
|
+
setAlpha: function setAlpha(value) {
|
|
275
|
+
this._a = boundAlpha(value);
|
|
276
|
+
this._roundA = Math.round(100 * this._a) / 100;
|
|
277
|
+
return this;
|
|
278
|
+
},
|
|
279
|
+
toHsv: function toHsv() {
|
|
280
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
281
|
+
return {
|
|
282
|
+
h: hsv.h * 360,
|
|
283
|
+
s: hsv.s,
|
|
284
|
+
v: hsv.v,
|
|
285
|
+
a: this._a
|
|
286
|
+
};
|
|
287
|
+
},
|
|
288
|
+
toHsvString: function toHsvString() {
|
|
289
|
+
var hsv = rgbToHsv(this._r, this._g, this._b);
|
|
290
|
+
var h = Math.round(hsv.h * 360),
|
|
291
|
+
s = Math.round(hsv.s * 100),
|
|
292
|
+
v = Math.round(hsv.v * 100);
|
|
293
|
+
return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")";
|
|
294
|
+
},
|
|
295
|
+
toHsl: function toHsl() {
|
|
296
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
297
|
+
return {
|
|
298
|
+
h: hsl.h * 360,
|
|
299
|
+
s: hsl.s,
|
|
300
|
+
l: hsl.l,
|
|
301
|
+
a: this._a
|
|
302
|
+
};
|
|
303
|
+
},
|
|
304
|
+
toHslString: function toHslString() {
|
|
305
|
+
var hsl = rgbToHsl(this._r, this._g, this._b);
|
|
306
|
+
var h = Math.round(hsl.h * 360),
|
|
307
|
+
s = Math.round(hsl.s * 100),
|
|
308
|
+
l = Math.round(hsl.l * 100);
|
|
309
|
+
return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")";
|
|
310
|
+
},
|
|
311
|
+
toHex: function toHex(allow3Char) {
|
|
312
|
+
return rgbToHex(this._r, this._g, this._b, allow3Char);
|
|
313
|
+
},
|
|
314
|
+
toHexString: function toHexString(allow3Char) {
|
|
315
|
+
return "#" + this.toHex(allow3Char);
|
|
316
|
+
},
|
|
317
|
+
toHex8: function toHex8(allow4Char) {
|
|
318
|
+
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
|
|
319
|
+
},
|
|
320
|
+
toHex8String: function toHex8String(allow4Char) {
|
|
321
|
+
return "#" + this.toHex8(allow4Char);
|
|
322
|
+
},
|
|
323
|
+
toRgb: function toRgb() {
|
|
324
|
+
return {
|
|
325
|
+
r: Math.round(this._r),
|
|
326
|
+
g: Math.round(this._g),
|
|
327
|
+
b: Math.round(this._b),
|
|
328
|
+
a: this._a
|
|
329
|
+
};
|
|
330
|
+
},
|
|
331
|
+
toRgbString: function toRgbString() {
|
|
332
|
+
return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")";
|
|
333
|
+
},
|
|
334
|
+
toPercentageRgb: function toPercentageRgb() {
|
|
335
|
+
return {
|
|
336
|
+
r: Math.round(bound01(this._r, 255) * 100) + "%",
|
|
337
|
+
g: Math.round(bound01(this._g, 255) * 100) + "%",
|
|
338
|
+
b: Math.round(bound01(this._b, 255) * 100) + "%",
|
|
339
|
+
a: this._a
|
|
340
|
+
};
|
|
341
|
+
},
|
|
342
|
+
toPercentageRgbString: function toPercentageRgbString() {
|
|
343
|
+
return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
|
|
344
|
+
},
|
|
345
|
+
toName: function toName() {
|
|
346
|
+
if (this._a === 0) {
|
|
347
|
+
return "transparent";
|
|
348
|
+
}
|
|
349
|
+
if (this._a < 1) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
|
|
353
|
+
},
|
|
354
|
+
toFilter: function toFilter(secondColor) {
|
|
355
|
+
var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a);
|
|
356
|
+
var secondHex8String = hex8String;
|
|
357
|
+
var gradientType = this._gradientType ? "GradientType = 1, " : "";
|
|
358
|
+
if (secondColor) {
|
|
359
|
+
var s = tinycolor(secondColor);
|
|
360
|
+
secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a);
|
|
361
|
+
}
|
|
362
|
+
return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")";
|
|
363
|
+
},
|
|
364
|
+
toString: function toString(format) {
|
|
365
|
+
var formatSet = !!format;
|
|
366
|
+
format = format || this._format;
|
|
367
|
+
var formattedString = false;
|
|
368
|
+
var hasAlpha = this._a < 1 && this._a >= 0;
|
|
369
|
+
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
|
|
370
|
+
if (needsAlphaFormat) {
|
|
371
|
+
// Special case for "transparent", all other non-alpha formats
|
|
372
|
+
// will return rgba when there is transparency.
|
|
373
|
+
if (format === "name" && this._a === 0) {
|
|
374
|
+
return this.toName();
|
|
375
|
+
}
|
|
376
|
+
return this.toRgbString();
|
|
377
|
+
}
|
|
378
|
+
if (format === "rgb") {
|
|
379
|
+
formattedString = this.toRgbString();
|
|
380
|
+
}
|
|
381
|
+
if (format === "prgb") {
|
|
382
|
+
formattedString = this.toPercentageRgbString();
|
|
383
|
+
}
|
|
384
|
+
if (format === "hex" || format === "hex6") {
|
|
385
|
+
formattedString = this.toHexString();
|
|
386
|
+
}
|
|
387
|
+
if (format === "hex3") {
|
|
388
|
+
formattedString = this.toHexString(true);
|
|
389
|
+
}
|
|
390
|
+
if (format === "hex4") {
|
|
391
|
+
formattedString = this.toHex8String(true);
|
|
392
|
+
}
|
|
393
|
+
if (format === "hex8") {
|
|
394
|
+
formattedString = this.toHex8String();
|
|
395
|
+
}
|
|
396
|
+
if (format === "name") {
|
|
397
|
+
formattedString = this.toName();
|
|
398
|
+
}
|
|
399
|
+
if (format === "hsl") {
|
|
400
|
+
formattedString = this.toHslString();
|
|
401
|
+
}
|
|
402
|
+
if (format === "hsv") {
|
|
403
|
+
formattedString = this.toHsvString();
|
|
404
|
+
}
|
|
405
|
+
return formattedString || this.toHexString();
|
|
406
|
+
},
|
|
407
|
+
clone: function clone() {
|
|
408
|
+
return tinycolor(this.toString());
|
|
409
|
+
},
|
|
410
|
+
_applyModification: function _applyModification(fn, args) {
|
|
411
|
+
var color = fn.apply(null, [this].concat([].slice.call(args)));
|
|
412
|
+
this._r = color._r;
|
|
413
|
+
this._g = color._g;
|
|
414
|
+
this._b = color._b;
|
|
415
|
+
this.setAlpha(color._a);
|
|
416
|
+
return this;
|
|
417
|
+
},
|
|
418
|
+
lighten: function lighten() {
|
|
419
|
+
return this._applyModification(_lighten, arguments);
|
|
420
|
+
},
|
|
421
|
+
brighten: function brighten() {
|
|
422
|
+
return this._applyModification(_brighten, arguments);
|
|
423
|
+
},
|
|
424
|
+
darken: function darken() {
|
|
425
|
+
return this._applyModification(_darken, arguments);
|
|
426
|
+
},
|
|
427
|
+
desaturate: function desaturate() {
|
|
428
|
+
return this._applyModification(_desaturate, arguments);
|
|
429
|
+
},
|
|
430
|
+
saturate: function saturate() {
|
|
431
|
+
return this._applyModification(_saturate, arguments);
|
|
432
|
+
},
|
|
433
|
+
greyscale: function greyscale() {
|
|
434
|
+
return this._applyModification(_greyscale, arguments);
|
|
435
|
+
},
|
|
436
|
+
spin: function spin() {
|
|
437
|
+
return this._applyModification(_spin, arguments);
|
|
438
|
+
},
|
|
439
|
+
_applyCombination: function _applyCombination(fn, args) {
|
|
440
|
+
return fn.apply(null, [this].concat([].slice.call(args)));
|
|
441
|
+
},
|
|
442
|
+
analogous: function analogous() {
|
|
443
|
+
return this._applyCombination(_analogous, arguments);
|
|
444
|
+
},
|
|
445
|
+
complement: function complement() {
|
|
446
|
+
return this._applyCombination(_complement, arguments);
|
|
447
|
+
},
|
|
448
|
+
monochromatic: function monochromatic() {
|
|
449
|
+
return this._applyCombination(_monochromatic, arguments);
|
|
450
|
+
},
|
|
451
|
+
splitcomplement: function splitcomplement() {
|
|
452
|
+
return this._applyCombination(_splitcomplement, arguments);
|
|
453
|
+
},
|
|
454
|
+
// Disabled until https://github.com/bgrins/TinyColor/issues/254
|
|
455
|
+
// polyad: function (number) {
|
|
456
|
+
// return this._applyCombination(polyad, [number]);
|
|
457
|
+
// },
|
|
458
|
+
triad: function triad() {
|
|
459
|
+
return this._applyCombination(polyad, [3]);
|
|
460
|
+
},
|
|
461
|
+
tetrad: function tetrad() {
|
|
462
|
+
return this._applyCombination(polyad, [4]);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
// If input is an object, force 1 into "1.0" to handle ratios properly
|
|
467
|
+
// String input requires "1.0" as input, so 1 will be treated as 1
|
|
468
|
+
tinycolor.fromRatio = function (color, opts) {
|
|
469
|
+
if (_typeof(color) == "object") {
|
|
470
|
+
var newColor = {};
|
|
471
|
+
for (var i in color) {
|
|
472
|
+
if (color.hasOwnProperty(i)) {
|
|
473
|
+
if (i === "a") {
|
|
474
|
+
newColor[i] = color[i];
|
|
475
|
+
} else {
|
|
476
|
+
newColor[i] = convertToPercentage(color[i]);
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
color = newColor;
|
|
481
|
+
}
|
|
482
|
+
return tinycolor(color, opts);
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// Given a string or object, convert that input to RGB
|
|
486
|
+
// Possible string inputs:
|
|
487
|
+
//
|
|
488
|
+
// "red"
|
|
489
|
+
// "#f00" or "f00"
|
|
490
|
+
// "#ff0000" or "ff0000"
|
|
491
|
+
// "#ff000000" or "ff000000"
|
|
492
|
+
// "rgb 255 0 0" or "rgb (255, 0, 0)"
|
|
493
|
+
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
|
|
494
|
+
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
|
|
495
|
+
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
|
|
496
|
+
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
|
|
497
|
+
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
|
|
498
|
+
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
|
|
499
|
+
//
|
|
500
|
+
function inputToRGB(color) {
|
|
501
|
+
var rgb = {
|
|
502
|
+
r: 0,
|
|
503
|
+
g: 0,
|
|
504
|
+
b: 0
|
|
505
|
+
};
|
|
506
|
+
var a = 1;
|
|
507
|
+
var s = null;
|
|
508
|
+
var v = null;
|
|
509
|
+
var l = null;
|
|
510
|
+
var ok = false;
|
|
511
|
+
var format = false;
|
|
512
|
+
if (typeof color == "string") {
|
|
513
|
+
color = stringInputToObject(color);
|
|
514
|
+
}
|
|
515
|
+
if (_typeof(color) == "object") {
|
|
516
|
+
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
|
|
517
|
+
rgb = rgbToRgb(color.r, color.g, color.b);
|
|
518
|
+
ok = true;
|
|
519
|
+
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
|
|
520
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
|
|
521
|
+
s = convertToPercentage(color.s);
|
|
522
|
+
v = convertToPercentage(color.v);
|
|
523
|
+
rgb = hsvToRgb(color.h, s, v);
|
|
524
|
+
ok = true;
|
|
525
|
+
format = "hsv";
|
|
526
|
+
} else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
|
|
527
|
+
s = convertToPercentage(color.s);
|
|
528
|
+
l = convertToPercentage(color.l);
|
|
529
|
+
rgb = hslToRgb(color.h, s, l);
|
|
530
|
+
ok = true;
|
|
531
|
+
format = "hsl";
|
|
532
|
+
}
|
|
533
|
+
if (color.hasOwnProperty("a")) {
|
|
534
|
+
a = color.a;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
a = boundAlpha(a);
|
|
538
|
+
return {
|
|
539
|
+
ok: ok,
|
|
540
|
+
format: color.format || format,
|
|
541
|
+
r: Math.min(255, Math.max(rgb.r, 0)),
|
|
542
|
+
g: Math.min(255, Math.max(rgb.g, 0)),
|
|
543
|
+
b: Math.min(255, Math.max(rgb.b, 0)),
|
|
544
|
+
a: a
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
// Conversion Functions
|
|
549
|
+
// --------------------
|
|
550
|
+
|
|
551
|
+
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
|
|
552
|
+
// <http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript>
|
|
553
|
+
|
|
554
|
+
// `rgbToRgb`
|
|
555
|
+
// Handle bounds / percentage checking to conform to CSS color spec
|
|
556
|
+
// <http://www.w3.org/TR/css3-color/>
|
|
557
|
+
// *Assumes:* r, g, b in [0, 255] or [0, 1]
|
|
558
|
+
// *Returns:* { r, g, b } in [0, 255]
|
|
559
|
+
function rgbToRgb(r, g, b) {
|
|
560
|
+
return {
|
|
561
|
+
r: bound01(r, 255) * 255,
|
|
562
|
+
g: bound01(g, 255) * 255,
|
|
563
|
+
b: bound01(b, 255) * 255
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
// `rgbToHsl`
|
|
568
|
+
// Converts an RGB color value to HSL.
|
|
569
|
+
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
|
|
570
|
+
// *Returns:* { h, s, l } in [0,1]
|
|
571
|
+
function rgbToHsl(r, g, b) {
|
|
572
|
+
r = bound01(r, 255);
|
|
573
|
+
g = bound01(g, 255);
|
|
574
|
+
b = bound01(b, 255);
|
|
575
|
+
var max = Math.max(r, g, b),
|
|
576
|
+
min = Math.min(r, g, b);
|
|
577
|
+
var h,
|
|
578
|
+
s,
|
|
579
|
+
l = (max + min) / 2;
|
|
580
|
+
if (max == min) {
|
|
581
|
+
h = s = 0; // achromatic
|
|
582
|
+
} else {
|
|
583
|
+
var d = max - min;
|
|
584
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
585
|
+
switch (max) {
|
|
586
|
+
case r:
|
|
587
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
588
|
+
break;
|
|
589
|
+
case g:
|
|
590
|
+
h = (b - r) / d + 2;
|
|
591
|
+
break;
|
|
592
|
+
case b:
|
|
593
|
+
h = (r - g) / d + 4;
|
|
594
|
+
break;
|
|
595
|
+
}
|
|
596
|
+
h /= 6;
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
h: h,
|
|
600
|
+
s: s,
|
|
601
|
+
l: l
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
// `hslToRgb`
|
|
606
|
+
// Converts an HSL color value to RGB.
|
|
607
|
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
|
|
608
|
+
// *Returns:* { r, g, b } in the set [0, 255]
|
|
609
|
+
function hslToRgb(h, s, l) {
|
|
610
|
+
var r, g, b;
|
|
611
|
+
h = bound01(h, 360);
|
|
612
|
+
s = bound01(s, 100);
|
|
613
|
+
l = bound01(l, 100);
|
|
614
|
+
function hue2rgb(p, q, t) {
|
|
615
|
+
if (t < 0) t += 1;
|
|
616
|
+
if (t > 1) t -= 1;
|
|
617
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
618
|
+
if (t < 1 / 2) return q;
|
|
619
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
620
|
+
return p;
|
|
621
|
+
}
|
|
622
|
+
if (s === 0) {
|
|
623
|
+
r = g = b = l; // achromatic
|
|
624
|
+
} else {
|
|
625
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
626
|
+
var p = 2 * l - q;
|
|
627
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
628
|
+
g = hue2rgb(p, q, h);
|
|
629
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
r: r * 255,
|
|
633
|
+
g: g * 255,
|
|
634
|
+
b: b * 255
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// `rgbToHsv`
|
|
639
|
+
// Converts an RGB color value to HSV
|
|
640
|
+
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
|
|
641
|
+
// *Returns:* { h, s, v } in [0,1]
|
|
642
|
+
function rgbToHsv(r, g, b) {
|
|
643
|
+
r = bound01(r, 255);
|
|
644
|
+
g = bound01(g, 255);
|
|
645
|
+
b = bound01(b, 255);
|
|
646
|
+
var max = Math.max(r, g, b),
|
|
647
|
+
min = Math.min(r, g, b);
|
|
648
|
+
var h,
|
|
649
|
+
s,
|
|
650
|
+
v = max;
|
|
651
|
+
var d = max - min;
|
|
652
|
+
s = max === 0 ? 0 : d / max;
|
|
653
|
+
if (max == min) {
|
|
654
|
+
h = 0; // achromatic
|
|
655
|
+
} else {
|
|
656
|
+
switch (max) {
|
|
657
|
+
case r:
|
|
658
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
659
|
+
break;
|
|
660
|
+
case g:
|
|
661
|
+
h = (b - r) / d + 2;
|
|
662
|
+
break;
|
|
663
|
+
case b:
|
|
664
|
+
h = (r - g) / d + 4;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
h /= 6;
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
h: h,
|
|
671
|
+
s: s,
|
|
672
|
+
v: v
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
// `hsvToRgb`
|
|
677
|
+
// Converts an HSV color value to RGB.
|
|
678
|
+
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
|
|
679
|
+
// *Returns:* { r, g, b } in the set [0, 255]
|
|
680
|
+
function hsvToRgb(h, s, v) {
|
|
681
|
+
h = bound01(h, 360) * 6;
|
|
682
|
+
s = bound01(s, 100);
|
|
683
|
+
v = bound01(v, 100);
|
|
684
|
+
var i = Math.floor(h),
|
|
685
|
+
f = h - i,
|
|
686
|
+
p = v * (1 - s),
|
|
687
|
+
q = v * (1 - f * s),
|
|
688
|
+
t = v * (1 - (1 - f) * s),
|
|
689
|
+
mod = i % 6,
|
|
690
|
+
r = [v, q, p, p, t, v][mod],
|
|
691
|
+
g = [t, v, v, q, p, p][mod],
|
|
692
|
+
b = [p, p, t, v, v, q][mod];
|
|
693
|
+
return {
|
|
694
|
+
r: r * 255,
|
|
695
|
+
g: g * 255,
|
|
696
|
+
b: b * 255
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// `rgbToHex`
|
|
701
|
+
// Converts an RGB color to hex
|
|
702
|
+
// Assumes r, g, and b are contained in the set [0, 255]
|
|
703
|
+
// Returns a 3 or 6 character hex
|
|
704
|
+
function rgbToHex(r, g, b, allow3Char) {
|
|
705
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
706
|
+
|
|
707
|
+
// Return a 3 character hex if possible
|
|
708
|
+
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
|
|
709
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
|
|
710
|
+
}
|
|
711
|
+
return hex.join("");
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
// `rgbaToHex`
|
|
715
|
+
// Converts an RGBA color plus alpha transparency to hex
|
|
716
|
+
// Assumes r, g, b are contained in the set [0, 255] and
|
|
717
|
+
// a in [0, 1]. Returns a 4 or 8 character rgba hex
|
|
718
|
+
function rgbaToHex(r, g, b, a, allow4Char) {
|
|
719
|
+
var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a))];
|
|
720
|
+
|
|
721
|
+
// Return a 4 character hex if possible
|
|
722
|
+
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
|
|
723
|
+
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
|
|
724
|
+
}
|
|
725
|
+
return hex.join("");
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
// `rgbaToArgbHex`
|
|
729
|
+
// Converts an RGBA color to an ARGB Hex8 string
|
|
730
|
+
// Rarely used, but required for "toFilter()"
|
|
731
|
+
function rgbaToArgbHex(r, g, b, a) {
|
|
732
|
+
var hex = [pad2(convertDecimalToHex(a)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))];
|
|
733
|
+
return hex.join("");
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
// `equals`
|
|
737
|
+
// Can be called with any tinycolor input
|
|
738
|
+
tinycolor.equals = function (color1, color2) {
|
|
739
|
+
if (!color1 || !color2) return false;
|
|
740
|
+
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
|
|
741
|
+
};
|
|
742
|
+
tinycolor.random = function () {
|
|
743
|
+
return tinycolor.fromRatio({
|
|
744
|
+
r: Math.random(),
|
|
745
|
+
g: Math.random(),
|
|
746
|
+
b: Math.random()
|
|
747
|
+
});
|
|
748
|
+
};
|
|
749
|
+
|
|
750
|
+
// Modification Functions
|
|
751
|
+
// ----------------------
|
|
752
|
+
// Thanks to less.js for some of the basics here
|
|
753
|
+
// <https://github.com/cloudhead/less.js/blob/master/lib/less/functions.js>
|
|
754
|
+
|
|
755
|
+
function _desaturate(color, amount) {
|
|
756
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
757
|
+
var hsl = tinycolor(color).toHsl();
|
|
758
|
+
hsl.s -= amount / 100;
|
|
759
|
+
hsl.s = clamp01(hsl.s);
|
|
760
|
+
return tinycolor(hsl);
|
|
761
|
+
}
|
|
762
|
+
function _saturate(color, amount) {
|
|
763
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
764
|
+
var hsl = tinycolor(color).toHsl();
|
|
765
|
+
hsl.s += amount / 100;
|
|
766
|
+
hsl.s = clamp01(hsl.s);
|
|
767
|
+
return tinycolor(hsl);
|
|
768
|
+
}
|
|
769
|
+
function _greyscale(color) {
|
|
770
|
+
return tinycolor(color).desaturate(100);
|
|
771
|
+
}
|
|
772
|
+
function _lighten(color, amount) {
|
|
773
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
774
|
+
var hsl = tinycolor(color).toHsl();
|
|
775
|
+
hsl.l += amount / 100;
|
|
776
|
+
hsl.l = clamp01(hsl.l);
|
|
777
|
+
return tinycolor(hsl);
|
|
778
|
+
}
|
|
779
|
+
function _brighten(color, amount) {
|
|
780
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
781
|
+
var rgb = tinycolor(color).toRgb();
|
|
782
|
+
rgb.r = Math.max(0, Math.min(255, rgb.r - Math.round(255 * -(amount / 100))));
|
|
783
|
+
rgb.g = Math.max(0, Math.min(255, rgb.g - Math.round(255 * -(amount / 100))));
|
|
784
|
+
rgb.b = Math.max(0, Math.min(255, rgb.b - Math.round(255 * -(amount / 100))));
|
|
785
|
+
return tinycolor(rgb);
|
|
786
|
+
}
|
|
787
|
+
function _darken(color, amount) {
|
|
788
|
+
amount = amount === 0 ? 0 : amount || 10;
|
|
789
|
+
var hsl = tinycolor(color).toHsl();
|
|
790
|
+
hsl.l -= amount / 100;
|
|
791
|
+
hsl.l = clamp01(hsl.l);
|
|
792
|
+
return tinycolor(hsl);
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
|
|
796
|
+
// Values outside of this range will be wrapped into this range.
|
|
797
|
+
function _spin(color, amount) {
|
|
798
|
+
var hsl = tinycolor(color).toHsl();
|
|
799
|
+
var hue = (hsl.h + amount) % 360;
|
|
800
|
+
hsl.h = hue < 0 ? 360 + hue : hue;
|
|
801
|
+
return tinycolor(hsl);
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
// Combination Functions
|
|
805
|
+
// ---------------------
|
|
806
|
+
// Thanks to jQuery xColor for some of the ideas behind these
|
|
807
|
+
// <https://github.com/infusion/jQuery-xcolor/blob/master/jquery.xcolor.js>
|
|
808
|
+
|
|
809
|
+
function _complement(color) {
|
|
810
|
+
var hsl = tinycolor(color).toHsl();
|
|
811
|
+
hsl.h = (hsl.h + 180) % 360;
|
|
812
|
+
return tinycolor(hsl);
|
|
813
|
+
}
|
|
814
|
+
function polyad(color, number) {
|
|
815
|
+
if (isNaN(number) || number <= 0) {
|
|
816
|
+
throw new Error("Argument to polyad must be a positive number");
|
|
817
|
+
}
|
|
818
|
+
var hsl = tinycolor(color).toHsl();
|
|
819
|
+
var result = [tinycolor(color)];
|
|
820
|
+
var step = 360 / number;
|
|
821
|
+
for (var i = 1; i < number; i++) {
|
|
822
|
+
result.push(tinycolor({
|
|
823
|
+
h: (hsl.h + i * step) % 360,
|
|
824
|
+
s: hsl.s,
|
|
825
|
+
l: hsl.l
|
|
826
|
+
}));
|
|
827
|
+
}
|
|
828
|
+
return result;
|
|
829
|
+
}
|
|
830
|
+
function _splitcomplement(color) {
|
|
831
|
+
var hsl = tinycolor(color).toHsl();
|
|
832
|
+
var h = hsl.h;
|
|
833
|
+
return [tinycolor(color), tinycolor({
|
|
834
|
+
h: (h + 72) % 360,
|
|
835
|
+
s: hsl.s,
|
|
836
|
+
l: hsl.l
|
|
837
|
+
}), tinycolor({
|
|
838
|
+
h: (h + 216) % 360,
|
|
839
|
+
s: hsl.s,
|
|
840
|
+
l: hsl.l
|
|
841
|
+
})];
|
|
842
|
+
}
|
|
843
|
+
function _analogous(color, results, slices) {
|
|
844
|
+
results = results || 6;
|
|
845
|
+
slices = slices || 30;
|
|
846
|
+
var hsl = tinycolor(color).toHsl();
|
|
847
|
+
var part = 360 / slices;
|
|
848
|
+
var ret = [tinycolor(color)];
|
|
849
|
+
for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results;) {
|
|
850
|
+
hsl.h = (hsl.h + part) % 360;
|
|
851
|
+
ret.push(tinycolor(hsl));
|
|
852
|
+
}
|
|
853
|
+
return ret;
|
|
854
|
+
}
|
|
855
|
+
function _monochromatic(color, results) {
|
|
856
|
+
results = results || 6;
|
|
857
|
+
var hsv = tinycolor(color).toHsv();
|
|
858
|
+
var h = hsv.h,
|
|
859
|
+
s = hsv.s,
|
|
860
|
+
v = hsv.v;
|
|
861
|
+
var ret = [];
|
|
862
|
+
var modification = 1 / results;
|
|
863
|
+
while (results--) {
|
|
864
|
+
ret.push(tinycolor({
|
|
865
|
+
h: h,
|
|
866
|
+
s: s,
|
|
867
|
+
v: v
|
|
868
|
+
}));
|
|
869
|
+
v = (v + modification) % 1;
|
|
870
|
+
}
|
|
871
|
+
return ret;
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// Utility Functions
|
|
875
|
+
// ---------------------
|
|
876
|
+
|
|
877
|
+
tinycolor.mix = function (color1, color2, amount) {
|
|
878
|
+
amount = amount === 0 ? 0 : amount || 50;
|
|
879
|
+
var rgb1 = tinycolor(color1).toRgb();
|
|
880
|
+
var rgb2 = tinycolor(color2).toRgb();
|
|
881
|
+
var p = amount / 100;
|
|
882
|
+
var rgba = {
|
|
883
|
+
r: (rgb2.r - rgb1.r) * p + rgb1.r,
|
|
884
|
+
g: (rgb2.g - rgb1.g) * p + rgb1.g,
|
|
885
|
+
b: (rgb2.b - rgb1.b) * p + rgb1.b,
|
|
886
|
+
a: (rgb2.a - rgb1.a) * p + rgb1.a
|
|
887
|
+
};
|
|
888
|
+
return tinycolor(rgba);
|
|
889
|
+
};
|
|
890
|
+
|
|
891
|
+
// Readability Functions
|
|
892
|
+
// ---------------------
|
|
893
|
+
// <http://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef (WCAG Version 2)
|
|
894
|
+
|
|
895
|
+
// `contrast`
|
|
896
|
+
// Analyze the 2 colors and returns the color contrast defined by (WCAG Version 2)
|
|
897
|
+
tinycolor.readability = function (color1, color2) {
|
|
898
|
+
var c1 = tinycolor(color1);
|
|
899
|
+
var c2 = tinycolor(color2);
|
|
900
|
+
return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05);
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
// `isReadable`
|
|
904
|
+
// Ensure that foreground and background color combinations meet WCAG2 guidelines.
|
|
905
|
+
// The third argument is an optional Object.
|
|
906
|
+
// the 'level' property states 'AA' or 'AAA' - if missing or invalid, it defaults to 'AA';
|
|
907
|
+
// the 'size' property states 'large' or 'small' - if missing or invalid, it defaults to 'small'.
|
|
908
|
+
// If the entire object is absent, isReadable defaults to {level:"AA",size:"small"}.
|
|
909
|
+
|
|
910
|
+
// *Example*
|
|
911
|
+
// tinycolor.isReadable("#000", "#111") => false
|
|
912
|
+
// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
|
|
913
|
+
tinycolor.isReadable = function (color1, color2, wcag2) {
|
|
914
|
+
var readability = tinycolor.readability(color1, color2);
|
|
915
|
+
var wcag2Parms, out;
|
|
916
|
+
out = false;
|
|
917
|
+
wcag2Parms = validateWCAG2Parms(wcag2);
|
|
918
|
+
switch (wcag2Parms.level + wcag2Parms.size) {
|
|
919
|
+
case "AAsmall":
|
|
920
|
+
case "AAAlarge":
|
|
921
|
+
out = readability >= 4.5;
|
|
922
|
+
break;
|
|
923
|
+
case "AAlarge":
|
|
924
|
+
out = readability >= 3;
|
|
925
|
+
break;
|
|
926
|
+
case "AAAsmall":
|
|
927
|
+
out = readability >= 7;
|
|
928
|
+
break;
|
|
929
|
+
}
|
|
930
|
+
return out;
|
|
931
|
+
};
|
|
932
|
+
|
|
933
|
+
// `mostReadable`
|
|
934
|
+
// Given a base color and a list of possible foreground or background
|
|
935
|
+
// colors for that base, returns the most readable color.
|
|
936
|
+
// Optionally returns Black or White if the most readable color is unreadable.
|
|
937
|
+
// *Example*
|
|
938
|
+
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
|
|
939
|
+
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
|
|
940
|
+
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
|
|
941
|
+
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
|
|
942
|
+
tinycolor.mostReadable = function (baseColor, colorList, args) {
|
|
943
|
+
var bestColor = null;
|
|
944
|
+
var bestScore = 0;
|
|
945
|
+
var readability;
|
|
946
|
+
var includeFallbackColors, level, size;
|
|
947
|
+
args = args || {};
|
|
948
|
+
includeFallbackColors = args.includeFallbackColors;
|
|
949
|
+
level = args.level;
|
|
950
|
+
size = args.size;
|
|
951
|
+
for (var i = 0; i < colorList.length; i++) {
|
|
952
|
+
readability = tinycolor.readability(baseColor, colorList[i]);
|
|
953
|
+
if (readability > bestScore) {
|
|
954
|
+
bestScore = readability;
|
|
955
|
+
bestColor = tinycolor(colorList[i]);
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
if (tinycolor.isReadable(baseColor, bestColor, {
|
|
959
|
+
level: level,
|
|
960
|
+
size: size
|
|
961
|
+
}) || !includeFallbackColors) {
|
|
962
|
+
return bestColor;
|
|
963
|
+
} else {
|
|
964
|
+
args.includeFallbackColors = false;
|
|
965
|
+
return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
// Big List of Colors
|
|
970
|
+
// ------------------
|
|
971
|
+
// <https://www.w3.org/TR/css-color-4/#named-colors>
|
|
972
|
+
var names = tinycolor.names = {
|
|
973
|
+
aliceblue: "f0f8ff",
|
|
974
|
+
antiquewhite: "faebd7",
|
|
975
|
+
aqua: "0ff",
|
|
976
|
+
aquamarine: "7fffd4",
|
|
977
|
+
azure: "f0ffff",
|
|
978
|
+
beige: "f5f5dc",
|
|
979
|
+
bisque: "ffe4c4",
|
|
980
|
+
black: "000",
|
|
981
|
+
blanchedalmond: "ffebcd",
|
|
982
|
+
blue: "00f",
|
|
983
|
+
blueviolet: "8a2be2",
|
|
984
|
+
brown: "a52a2a",
|
|
985
|
+
burlywood: "deb887",
|
|
986
|
+
burntsienna: "ea7e5d",
|
|
987
|
+
cadetblue: "5f9ea0",
|
|
988
|
+
chartreuse: "7fff00",
|
|
989
|
+
chocolate: "d2691e",
|
|
990
|
+
coral: "ff7f50",
|
|
991
|
+
cornflowerblue: "6495ed",
|
|
992
|
+
cornsilk: "fff8dc",
|
|
993
|
+
crimson: "dc143c",
|
|
994
|
+
cyan: "0ff",
|
|
995
|
+
darkblue: "00008b",
|
|
996
|
+
darkcyan: "008b8b",
|
|
997
|
+
darkgoldenrod: "b8860b",
|
|
998
|
+
darkgray: "a9a9a9",
|
|
999
|
+
darkgreen: "006400",
|
|
1000
|
+
darkgrey: "a9a9a9",
|
|
1001
|
+
darkkhaki: "bdb76b",
|
|
1002
|
+
darkmagenta: "8b008b",
|
|
1003
|
+
darkolivegreen: "556b2f",
|
|
1004
|
+
darkorange: "ff8c00",
|
|
1005
|
+
darkorchid: "9932cc",
|
|
1006
|
+
darkred: "8b0000",
|
|
1007
|
+
darksalmon: "e9967a",
|
|
1008
|
+
darkseagreen: "8fbc8f",
|
|
1009
|
+
darkslateblue: "483d8b",
|
|
1010
|
+
darkslategray: "2f4f4f",
|
|
1011
|
+
darkslategrey: "2f4f4f",
|
|
1012
|
+
darkturquoise: "00ced1",
|
|
1013
|
+
darkviolet: "9400d3",
|
|
1014
|
+
deeppink: "ff1493",
|
|
1015
|
+
deepskyblue: "00bfff",
|
|
1016
|
+
dimgray: "696969",
|
|
1017
|
+
dimgrey: "696969",
|
|
1018
|
+
dodgerblue: "1e90ff",
|
|
1019
|
+
firebrick: "b22222",
|
|
1020
|
+
floralwhite: "fffaf0",
|
|
1021
|
+
forestgreen: "228b22",
|
|
1022
|
+
fuchsia: "f0f",
|
|
1023
|
+
gainsboro: "dcdcdc",
|
|
1024
|
+
ghostwhite: "f8f8ff",
|
|
1025
|
+
gold: "ffd700",
|
|
1026
|
+
goldenrod: "daa520",
|
|
1027
|
+
gray: "808080",
|
|
1028
|
+
green: "008000",
|
|
1029
|
+
greenyellow: "adff2f",
|
|
1030
|
+
grey: "808080",
|
|
1031
|
+
honeydew: "f0fff0",
|
|
1032
|
+
hotpink: "ff69b4",
|
|
1033
|
+
indianred: "cd5c5c",
|
|
1034
|
+
indigo: "4b0082",
|
|
1035
|
+
ivory: "fffff0",
|
|
1036
|
+
khaki: "f0e68c",
|
|
1037
|
+
lavender: "e6e6fa",
|
|
1038
|
+
lavenderblush: "fff0f5",
|
|
1039
|
+
lawngreen: "7cfc00",
|
|
1040
|
+
lemonchiffon: "fffacd",
|
|
1041
|
+
lightblue: "add8e6",
|
|
1042
|
+
lightcoral: "f08080",
|
|
1043
|
+
lightcyan: "e0ffff",
|
|
1044
|
+
lightgoldenrodyellow: "fafad2",
|
|
1045
|
+
lightgray: "d3d3d3",
|
|
1046
|
+
lightgreen: "90ee90",
|
|
1047
|
+
lightgrey: "d3d3d3",
|
|
1048
|
+
lightpink: "ffb6c1",
|
|
1049
|
+
lightsalmon: "ffa07a",
|
|
1050
|
+
lightseagreen: "20b2aa",
|
|
1051
|
+
lightskyblue: "87cefa",
|
|
1052
|
+
lightslategray: "789",
|
|
1053
|
+
lightslategrey: "789",
|
|
1054
|
+
lightsteelblue: "b0c4de",
|
|
1055
|
+
lightyellow: "ffffe0",
|
|
1056
|
+
lime: "0f0",
|
|
1057
|
+
limegreen: "32cd32",
|
|
1058
|
+
linen: "faf0e6",
|
|
1059
|
+
magenta: "f0f",
|
|
1060
|
+
maroon: "800000",
|
|
1061
|
+
mediumaquamarine: "66cdaa",
|
|
1062
|
+
mediumblue: "0000cd",
|
|
1063
|
+
mediumorchid: "ba55d3",
|
|
1064
|
+
mediumpurple: "9370db",
|
|
1065
|
+
mediumseagreen: "3cb371",
|
|
1066
|
+
mediumslateblue: "7b68ee",
|
|
1067
|
+
mediumspringgreen: "00fa9a",
|
|
1068
|
+
mediumturquoise: "48d1cc",
|
|
1069
|
+
mediumvioletred: "c71585",
|
|
1070
|
+
midnightblue: "191970",
|
|
1071
|
+
mintcream: "f5fffa",
|
|
1072
|
+
mistyrose: "ffe4e1",
|
|
1073
|
+
moccasin: "ffe4b5",
|
|
1074
|
+
navajowhite: "ffdead",
|
|
1075
|
+
navy: "000080",
|
|
1076
|
+
oldlace: "fdf5e6",
|
|
1077
|
+
olive: "808000",
|
|
1078
|
+
olivedrab: "6b8e23",
|
|
1079
|
+
orange: "ffa500",
|
|
1080
|
+
orangered: "ff4500",
|
|
1081
|
+
orchid: "da70d6",
|
|
1082
|
+
palegoldenrod: "eee8aa",
|
|
1083
|
+
palegreen: "98fb98",
|
|
1084
|
+
paleturquoise: "afeeee",
|
|
1085
|
+
palevioletred: "db7093",
|
|
1086
|
+
papayawhip: "ffefd5",
|
|
1087
|
+
peachpuff: "ffdab9",
|
|
1088
|
+
peru: "cd853f",
|
|
1089
|
+
pink: "ffc0cb",
|
|
1090
|
+
plum: "dda0dd",
|
|
1091
|
+
powderblue: "b0e0e6",
|
|
1092
|
+
purple: "800080",
|
|
1093
|
+
rebeccapurple: "663399",
|
|
1094
|
+
red: "f00",
|
|
1095
|
+
rosybrown: "bc8f8f",
|
|
1096
|
+
royalblue: "4169e1",
|
|
1097
|
+
saddlebrown: "8b4513",
|
|
1098
|
+
salmon: "fa8072",
|
|
1099
|
+
sandybrown: "f4a460",
|
|
1100
|
+
seagreen: "2e8b57",
|
|
1101
|
+
seashell: "fff5ee",
|
|
1102
|
+
sienna: "a0522d",
|
|
1103
|
+
silver: "c0c0c0",
|
|
1104
|
+
skyblue: "87ceeb",
|
|
1105
|
+
slateblue: "6a5acd",
|
|
1106
|
+
slategray: "708090",
|
|
1107
|
+
slategrey: "708090",
|
|
1108
|
+
snow: "fffafa",
|
|
1109
|
+
springgreen: "00ff7f",
|
|
1110
|
+
steelblue: "4682b4",
|
|
1111
|
+
tan: "d2b48c",
|
|
1112
|
+
teal: "008080",
|
|
1113
|
+
thistle: "d8bfd8",
|
|
1114
|
+
tomato: "ff6347",
|
|
1115
|
+
turquoise: "40e0d0",
|
|
1116
|
+
violet: "ee82ee",
|
|
1117
|
+
wheat: "f5deb3",
|
|
1118
|
+
white: "fff",
|
|
1119
|
+
whitesmoke: "f5f5f5",
|
|
1120
|
+
yellow: "ff0",
|
|
1121
|
+
yellowgreen: "9acd32"
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1124
|
+
// Make it easy to access colors via `hexNames[hex]`
|
|
1125
|
+
var hexNames = tinycolor.hexNames = flip(names);
|
|
1126
|
+
|
|
1127
|
+
// Utilities
|
|
1128
|
+
// ---------
|
|
1129
|
+
|
|
1130
|
+
// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
|
|
1131
|
+
function flip(o) {
|
|
1132
|
+
var flipped = {};
|
|
1133
|
+
for (var i in o) {
|
|
1134
|
+
if (o.hasOwnProperty(i)) {
|
|
1135
|
+
flipped[o[i]] = i;
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
return flipped;
|
|
1139
|
+
}
|
|
1140
|
+
|
|
1141
|
+
// Return a valid alpha value [0,1] with all invalid values being set to 1
|
|
1142
|
+
function boundAlpha(a) {
|
|
1143
|
+
a = parseFloat(a);
|
|
1144
|
+
if (isNaN(a) || a < 0 || a > 1) {
|
|
1145
|
+
a = 1;
|
|
1146
|
+
}
|
|
1147
|
+
return a;
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// Take input from [0, n] and return it as [0, 1]
|
|
1151
|
+
function bound01(n, max) {
|
|
1152
|
+
if (isOnePointZero(n)) n = "100%";
|
|
1153
|
+
var processPercent = isPercentage(n);
|
|
1154
|
+
n = Math.min(max, Math.max(0, parseFloat(n)));
|
|
1155
|
+
|
|
1156
|
+
// Automatically convert percentage into number
|
|
1157
|
+
if (processPercent) {
|
|
1158
|
+
n = parseInt(n * max, 10) / 100;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
// Handle floating point rounding errors
|
|
1162
|
+
if (Math.abs(n - max) < 0.000001) {
|
|
1163
|
+
return 1;
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
// Convert into [0, 1] range if it isn't already
|
|
1167
|
+
return n % max / parseFloat(max);
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// Force a number between 0 and 1
|
|
1171
|
+
function clamp01(val) {
|
|
1172
|
+
return Math.min(1, Math.max(0, val));
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
// Parse a base-16 hex value into a base-10 integer
|
|
1176
|
+
function parseIntFromHex(val) {
|
|
1177
|
+
return parseInt(val, 16);
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
|
|
1181
|
+
// <http://stackoverflow.com/questions/7422072/javascript-how-to-detect-number-as-a-decimal-including-1-0>
|
|
1182
|
+
function isOnePointZero(n) {
|
|
1183
|
+
return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1;
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
// Check to see if string passed in is a percentage
|
|
1187
|
+
function isPercentage(n) {
|
|
1188
|
+
return typeof n === "string" && n.indexOf("%") != -1;
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
// Force a hex value to have 2 characters
|
|
1192
|
+
function pad2(c) {
|
|
1193
|
+
return c.length == 1 ? "0" + c : "" + c;
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// Replace a decimal with it's percentage value
|
|
1197
|
+
function convertToPercentage(n) {
|
|
1198
|
+
if (n <= 1) {
|
|
1199
|
+
n = n * 100 + "%";
|
|
1200
|
+
}
|
|
1201
|
+
return n;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
// Converts a decimal to a hex value
|
|
1205
|
+
function convertDecimalToHex(d) {
|
|
1206
|
+
return Math.round(parseFloat(d) * 255).toString(16);
|
|
1207
|
+
}
|
|
1208
|
+
// Converts a hex value to a decimal
|
|
1209
|
+
function convertHexToDecimal(h) {
|
|
1210
|
+
return parseIntFromHex(h) / 255;
|
|
1211
|
+
}
|
|
1212
|
+
var matchers = function () {
|
|
1213
|
+
// <http://www.w3.org/TR/css3-values/#integers>
|
|
1214
|
+
var CSS_INTEGER = "[-\\+]?\\d+%?";
|
|
1215
|
+
|
|
1216
|
+
// <http://www.w3.org/TR/css3-values/#number-value>
|
|
1217
|
+
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
|
|
1218
|
+
|
|
1219
|
+
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
|
|
1220
|
+
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
|
|
1221
|
+
|
|
1222
|
+
// Actual matching.
|
|
1223
|
+
// Parentheses and commas are optional, but not required.
|
|
1224
|
+
// Whitespace can take the place of commas or opening paren
|
|
1225
|
+
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1226
|
+
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
|
|
1227
|
+
return {
|
|
1228
|
+
CSS_UNIT: new RegExp(CSS_UNIT),
|
|
1229
|
+
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
|
|
1230
|
+
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
|
|
1231
|
+
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
|
|
1232
|
+
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
|
|
1233
|
+
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
|
|
1234
|
+
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
|
|
1235
|
+
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1236
|
+
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
|
|
1237
|
+
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
|
|
1238
|
+
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
|
|
1239
|
+
};
|
|
1240
|
+
}();
|
|
1241
|
+
|
|
1242
|
+
// `isValidCSSUnit`
|
|
1243
|
+
// Take in a single string / number and check to see if it looks like a CSS unit
|
|
1244
|
+
// (see `matchers` above for definition).
|
|
1245
|
+
function isValidCSSUnit(color) {
|
|
1246
|
+
return !!matchers.CSS_UNIT.exec(color);
|
|
1247
|
+
}
|
|
1248
|
+
|
|
1249
|
+
// `stringInputToObject`
|
|
1250
|
+
// Permissive string parsing. Take in a number of formats, and output an object
|
|
1251
|
+
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
|
|
1252
|
+
function stringInputToObject(color) {
|
|
1253
|
+
color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase();
|
|
1254
|
+
var named = false;
|
|
1255
|
+
if (names[color]) {
|
|
1256
|
+
color = names[color];
|
|
1257
|
+
named = true;
|
|
1258
|
+
} else if (color == "transparent") {
|
|
1259
|
+
return {
|
|
1260
|
+
r: 0,
|
|
1261
|
+
g: 0,
|
|
1262
|
+
b: 0,
|
|
1263
|
+
a: 0,
|
|
1264
|
+
format: "name"
|
|
1265
|
+
};
|
|
1266
|
+
}
|
|
1267
|
+
|
|
1268
|
+
// Try to match string input using regular expressions.
|
|
1269
|
+
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
|
|
1270
|
+
// Just return an object and let the conversion functions handle that.
|
|
1271
|
+
// This way the result will be the same whether the tinycolor is initialized with string or object.
|
|
1272
|
+
var match;
|
|
1273
|
+
if (match = matchers.rgb.exec(color)) {
|
|
1274
|
+
return {
|
|
1275
|
+
r: match[1],
|
|
1276
|
+
g: match[2],
|
|
1277
|
+
b: match[3]
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
if (match = matchers.rgba.exec(color)) {
|
|
1281
|
+
return {
|
|
1282
|
+
r: match[1],
|
|
1283
|
+
g: match[2],
|
|
1284
|
+
b: match[3],
|
|
1285
|
+
a: match[4]
|
|
1286
|
+
};
|
|
1287
|
+
}
|
|
1288
|
+
if (match = matchers.hsl.exec(color)) {
|
|
1289
|
+
return {
|
|
1290
|
+
h: match[1],
|
|
1291
|
+
s: match[2],
|
|
1292
|
+
l: match[3]
|
|
1293
|
+
};
|
|
1294
|
+
}
|
|
1295
|
+
if (match = matchers.hsla.exec(color)) {
|
|
1296
|
+
return {
|
|
1297
|
+
h: match[1],
|
|
1298
|
+
s: match[2],
|
|
1299
|
+
l: match[3],
|
|
1300
|
+
a: match[4]
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
if (match = matchers.hsv.exec(color)) {
|
|
1304
|
+
return {
|
|
1305
|
+
h: match[1],
|
|
1306
|
+
s: match[2],
|
|
1307
|
+
v: match[3]
|
|
1308
|
+
};
|
|
1309
|
+
}
|
|
1310
|
+
if (match = matchers.hsva.exec(color)) {
|
|
1311
|
+
return {
|
|
1312
|
+
h: match[1],
|
|
1313
|
+
s: match[2],
|
|
1314
|
+
v: match[3],
|
|
1315
|
+
a: match[4]
|
|
1316
|
+
};
|
|
1317
|
+
}
|
|
1318
|
+
if (match = matchers.hex8.exec(color)) {
|
|
1319
|
+
return {
|
|
1320
|
+
r: parseIntFromHex(match[1]),
|
|
1321
|
+
g: parseIntFromHex(match[2]),
|
|
1322
|
+
b: parseIntFromHex(match[3]),
|
|
1323
|
+
a: convertHexToDecimal(match[4]),
|
|
1324
|
+
format: named ? "name" : "hex8"
|
|
1325
|
+
};
|
|
1326
|
+
}
|
|
1327
|
+
if (match = matchers.hex6.exec(color)) {
|
|
1328
|
+
return {
|
|
1329
|
+
r: parseIntFromHex(match[1]),
|
|
1330
|
+
g: parseIntFromHex(match[2]),
|
|
1331
|
+
b: parseIntFromHex(match[3]),
|
|
1332
|
+
format: named ? "name" : "hex"
|
|
1333
|
+
};
|
|
1334
|
+
}
|
|
1335
|
+
if (match = matchers.hex4.exec(color)) {
|
|
1336
|
+
return {
|
|
1337
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1338
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1339
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1340
|
+
a: convertHexToDecimal(match[4] + "" + match[4]),
|
|
1341
|
+
format: named ? "name" : "hex8"
|
|
1342
|
+
};
|
|
1343
|
+
}
|
|
1344
|
+
if (match = matchers.hex3.exec(color)) {
|
|
1345
|
+
return {
|
|
1346
|
+
r: parseIntFromHex(match[1] + "" + match[1]),
|
|
1347
|
+
g: parseIntFromHex(match[2] + "" + match[2]),
|
|
1348
|
+
b: parseIntFromHex(match[3] + "" + match[3]),
|
|
1349
|
+
format: named ? "name" : "hex"
|
|
1350
|
+
};
|
|
1351
|
+
}
|
|
1352
|
+
return false;
|
|
1353
|
+
}
|
|
1354
|
+
function validateWCAG2Parms(parms) {
|
|
1355
|
+
// return valid WCAG2 parms for isReadable.
|
|
1356
|
+
// If input parms are invalid, return {"level":"AA", "size":"small"}
|
|
1357
|
+
var level, size;
|
|
1358
|
+
parms = parms || {
|
|
1359
|
+
level: "AA",
|
|
1360
|
+
size: "small"
|
|
1361
|
+
};
|
|
1362
|
+
level = (parms.level || "AA").toUpperCase();
|
|
1363
|
+
size = (parms.size || "small").toLowerCase();
|
|
1364
|
+
if (level !== "AA" && level !== "AAA") {
|
|
1365
|
+
level = "AA";
|
|
1366
|
+
}
|
|
1367
|
+
if (size !== "small" && size !== "large") {
|
|
1368
|
+
size = "small";
|
|
1369
|
+
}
|
|
1370
|
+
return {
|
|
1371
|
+
level: level,
|
|
1372
|
+
size: size
|
|
1373
|
+
};
|
|
1374
|
+
}
|
|
1375
|
+
|
|
178
1376
|
//预设颜色列表
|
|
179
|
-
var PresetColors = [
|
|
1377
|
+
var PresetColors = ["blue", "green", "yellow", "red"];
|
|
180
1378
|
//tag
|
|
181
1379
|
var InternalTag = function InternalTag(props) {
|
|
182
1380
|
var _clsx;
|
|
183
|
-
var
|
|
1381
|
+
var _props$type = props.type,
|
|
1382
|
+
type = _props$type === void 0 ? "normal" : _props$type,
|
|
1383
|
+
className = props.className,
|
|
184
1384
|
children = props.children,
|
|
185
1385
|
icon = props.icon,
|
|
186
1386
|
color = props.color,
|
|
187
1387
|
onClose = props.onClose,
|
|
1388
|
+
onEdit = props.onEdit,
|
|
1389
|
+
getWidth = props.getWidth,
|
|
1390
|
+
tagChange = props.tagChange,
|
|
1391
|
+
editInputClassName = props.editInputClassName,
|
|
188
1392
|
closeIcon = props.closeIcon,
|
|
189
1393
|
_props$closable = props.closable,
|
|
190
1394
|
closable = _props$closable === void 0 ? false : _props$closable,
|
|
191
|
-
_props$
|
|
192
|
-
|
|
1395
|
+
_props$editable = props.editable,
|
|
1396
|
+
editable = _props$editable === void 0 ? false : _props$editable,
|
|
193
1397
|
_props$size = props.size,
|
|
194
|
-
size = _props$size === void 0 ?
|
|
1398
|
+
size = _props$size === void 0 ? "larage" : _props$size,
|
|
1399
|
+
_props$maxWidth = props.maxWidth,
|
|
1400
|
+
maxWidth = _props$maxWidth === void 0 ? 300 : _props$maxWidth,
|
|
195
1401
|
style = props.style,
|
|
196
1402
|
visibleTag = props.visible,
|
|
1403
|
+
editInputWidth = props.editInputWidth,
|
|
197
1404
|
tipMaxWidth = props.tipMaxWidth,
|
|
198
|
-
restProps = __rest(props, ["className", "children", "icon", "color", "onClose", "closeIcon", "closable", "
|
|
1405
|
+
restProps = __rest(props, ["type", "className", "children", "icon", "color", "onClose", "onEdit", "getWidth", "tagChange", "editInputClassName", "closeIcon", "closable", "editable", "size", "maxWidth", "style", "visible", "editInputWidth", "tipMaxWidth"]);
|
|
199
1406
|
var _useState = useState(true),
|
|
200
1407
|
_useState2 = _slicedToArray(_useState, 2),
|
|
201
1408
|
visible = _useState2[0],
|
|
202
1409
|
setVisible = _useState2[1]; //显示tag
|
|
1410
|
+
var _useState3 = useState(false),
|
|
1411
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
1412
|
+
inputVisible = _useState4[0],
|
|
1413
|
+
setInputVisible = _useState4[1]; //显示输入框
|
|
1414
|
+
var _useState5 = useState(""),
|
|
1415
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
1416
|
+
inputValue = _useState6[0],
|
|
1417
|
+
setInputValue = _useState6[1]; // 编辑输入框的值
|
|
1418
|
+
var _useState7 = useState(""),
|
|
1419
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
1420
|
+
inputWidth = _useState8[0],
|
|
1421
|
+
setInputWidth = _useState8[1]; // 编辑输入框的值
|
|
1422
|
+
var _useState9 = useState(false),
|
|
1423
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
1424
|
+
closeIconEnter = _useState10[0],
|
|
1425
|
+
setCloseIconEnter = _useState10[1]; // 鼠标是否进入closeIcon
|
|
1426
|
+
var _useState11 = useState(false),
|
|
1427
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
1428
|
+
editIconEnter = _useState12[0],
|
|
1429
|
+
setEditIconEnter = _useState12[1]; // 鼠标是否进入closeIcon
|
|
1430
|
+
var inputRef = useRef(); //input ref
|
|
1431
|
+
var tagRef = useRef(); //tagRef ref
|
|
203
1432
|
useEffect(function () {
|
|
204
|
-
if (
|
|
1433
|
+
if ("visible" in props) {
|
|
205
1434
|
setVisible(!!visibleTag);
|
|
206
1435
|
}
|
|
207
1436
|
}, [visibleTag]);
|
|
1437
|
+
useEffect(function () {
|
|
1438
|
+
if (!tagRef.current) return;
|
|
1439
|
+
var offsetWidth = tagRef.current.offsetWidth;
|
|
1440
|
+
setInputWidth(offsetWidth);
|
|
1441
|
+
getWidth && getWidth(offsetWidth);
|
|
1442
|
+
}, [tagRef, inputVisible]);
|
|
1443
|
+
useEffect(function () {
|
|
1444
|
+
if (typeof children === "string") {
|
|
1445
|
+
setInputValue(children);
|
|
1446
|
+
}
|
|
1447
|
+
}, [children]);
|
|
208
1448
|
//是否预设颜色
|
|
209
1449
|
var isPresetColor = function isPresetColor() {
|
|
210
1450
|
if (!color) return false;
|
|
@@ -212,10 +1452,22 @@ var InternalTag = function InternalTag(props) {
|
|
|
212
1452
|
};
|
|
213
1453
|
//tag style
|
|
214
1454
|
var tagStyle = Object.assign({
|
|
215
|
-
color: color && !isPresetColor() ? color : undefined
|
|
1455
|
+
color: color && !isPresetColor() ? color : undefined,
|
|
1456
|
+
backgroundColor: color && !isPresetColor() ? tinycolor(color).setAlpha(0.1).toRgbString() : undefined,
|
|
1457
|
+
borderColor: color && !isPresetColor() && type === "outline" ? color : undefined,
|
|
1458
|
+
maxWidth: maxWidth
|
|
216
1459
|
}, style);
|
|
1460
|
+
//tag closeIcon style
|
|
1461
|
+
var closeIconStyle = {
|
|
1462
|
+
backgroundColor: closeIconEnter ? tinycolor(color).setAlpha(0.1).toRgbString() : undefined
|
|
1463
|
+
};
|
|
1464
|
+
//tag editIcon style
|
|
1465
|
+
var editIconStyle = {
|
|
1466
|
+
backgroundColor: editIconEnter ? tinycolor(color).setAlpha(0.1).toRgbString() : undefined,
|
|
1467
|
+
marginRight: children ? "4px" : undefined
|
|
1468
|
+
};
|
|
217
1469
|
//tag cls
|
|
218
|
-
var tagClassName = clsx("".concat($prefixCls, "-tag"),
|
|
1470
|
+
var tagClassName = clsx("".concat($prefixCls, "-tag"), "".concat($prefixCls, "-tag-").concat(type), "".concat($prefixCls, "-tag-").concat(size), className, (_clsx = {}, _defineProperty(_clsx, "".concat($prefixCls, "-tag-has-color"), color), _defineProperty(_clsx, "".concat($prefixCls, "-tag-hidden"), !visible), _defineProperty(_clsx, "".concat($prefixCls, "-tag-").concat(color), isPresetColor()), _clsx));
|
|
219
1471
|
//tag close click
|
|
220
1472
|
var handleCloseClick = function handleCloseClick(e) {
|
|
221
1473
|
e.stopPropagation();
|
|
@@ -223,41 +1475,118 @@ var InternalTag = function InternalTag(props) {
|
|
|
223
1475
|
if (e.defaultPrevented) {
|
|
224
1476
|
return;
|
|
225
1477
|
}
|
|
226
|
-
if (!(
|
|
1478
|
+
if (!("visible" in props)) {
|
|
227
1479
|
setVisible(false);
|
|
228
1480
|
}
|
|
229
1481
|
};
|
|
1482
|
+
var handleCloseEnter = function handleCloseEnter() {
|
|
1483
|
+
setCloseIconEnter(true);
|
|
1484
|
+
};
|
|
1485
|
+
var handleCloseLeave = function handleCloseLeave() {
|
|
1486
|
+
setCloseIconEnter(false);
|
|
1487
|
+
};
|
|
1488
|
+
var handleEditEnter = function handleEditEnter() {
|
|
1489
|
+
setEditIconEnter(true);
|
|
1490
|
+
};
|
|
1491
|
+
var handleEditLeave = function handleEditLeave() {
|
|
1492
|
+
setEditIconEnter(false);
|
|
1493
|
+
};
|
|
1494
|
+
var handleEditClick = function handleEditClick(e) {
|
|
1495
|
+
e.stopPropagation();
|
|
1496
|
+
onEdit && onEdit(e);
|
|
1497
|
+
if (e.defaultPrevented) {
|
|
1498
|
+
return;
|
|
1499
|
+
}
|
|
1500
|
+
// 显示输入框
|
|
1501
|
+
setInputVisible(true);
|
|
1502
|
+
};
|
|
230
1503
|
//渲染close icon
|
|
231
1504
|
var renderCloseIcon = function renderCloseIcon() {
|
|
232
1505
|
if (!closable) return null;
|
|
233
1506
|
return closeIcon ? jsx("span", Object.assign({
|
|
234
|
-
className:
|
|
235
|
-
|
|
1507
|
+
className: "tag-close-icon",
|
|
1508
|
+
style: closeIconStyle,
|
|
1509
|
+
onClick: handleCloseClick,
|
|
1510
|
+
onMouseEnter: handleCloseEnter,
|
|
1511
|
+
onMouseLeave: handleCloseLeave
|
|
236
1512
|
}, {
|
|
237
1513
|
children: closeIcon
|
|
238
1514
|
})) : jsx(CloseIcon, {
|
|
239
|
-
className:
|
|
240
|
-
|
|
1515
|
+
className: "tag-close-icon",
|
|
1516
|
+
style: closeIconStyle,
|
|
1517
|
+
onClick: handleCloseClick,
|
|
1518
|
+
onMouseEnter: handleCloseEnter,
|
|
1519
|
+
onMouseLeave: handleCloseLeave
|
|
241
1520
|
});
|
|
242
1521
|
};
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
1522
|
+
// 渲染前缀icon
|
|
1523
|
+
var renderPrefixIcon = function renderPrefixIcon() {
|
|
1524
|
+
return (editable || icon) && jsx("span", Object.assign({
|
|
1525
|
+
className: "tag-edit-icon",
|
|
1526
|
+
style: editIconStyle,
|
|
1527
|
+
onMouseEnter: handleEditEnter,
|
|
1528
|
+
onMouseLeave: handleEditLeave
|
|
1529
|
+
}, {
|
|
1530
|
+
children: editable ? jsx(EditIcon, {
|
|
1531
|
+
onMouseEnter: handleEditEnter,
|
|
1532
|
+
onMouseLeave: handleEditLeave,
|
|
1533
|
+
className: "tag-edit-icon",
|
|
1534
|
+
onClick: handleEditClick
|
|
1535
|
+
}) : jsx(Fragment, {
|
|
1536
|
+
children: icon
|
|
1537
|
+
})
|
|
1538
|
+
}));
|
|
1539
|
+
};
|
|
1540
|
+
//input change
|
|
1541
|
+
var handleInputChange = function handleInputChange(e) {
|
|
1542
|
+
setInputValue(e.target.value);
|
|
1543
|
+
tagChange && tagChange(e.target.value);
|
|
1544
|
+
};
|
|
1545
|
+
//input confirm
|
|
1546
|
+
var handleInputConfirm = function handleInputConfirm() {
|
|
1547
|
+
setInputVisible(false);
|
|
1548
|
+
};
|
|
1549
|
+
//input enter
|
|
1550
|
+
var handleInputEnter = function handleInputEnter(e) {
|
|
1551
|
+
if (e.keyCode === 13 || e.which === 13) {
|
|
1552
|
+
handleInputConfirm();
|
|
1553
|
+
}
|
|
1554
|
+
};
|
|
1555
|
+
//
|
|
1556
|
+
var renderNewInput = function renderNewInput() {
|
|
1557
|
+
var inputCls = clsx("".concat($prefixCls, "-tag-edit-input"), editInputClassName);
|
|
1558
|
+
return jsx("input", {
|
|
1559
|
+
style: {
|
|
1560
|
+
width: editInputWidth || inputWidth,
|
|
1561
|
+
minWidth: inputWidth
|
|
1562
|
+
},
|
|
1563
|
+
type: "text",
|
|
1564
|
+
autoFocus: true,
|
|
1565
|
+
ref: inputRef,
|
|
1566
|
+
className: inputCls,
|
|
1567
|
+
value: inputValue,
|
|
1568
|
+
onChange: handleInputChange,
|
|
1569
|
+
onBlur: handleInputConfirm,
|
|
1570
|
+
onKeyDown: handleInputEnter
|
|
1571
|
+
});
|
|
1572
|
+
};
|
|
1573
|
+
return jsx(Fragment, {
|
|
1574
|
+
children: inputVisible ? renderNewInput() : jsxs("span", Object.assign({}, restProps, {
|
|
1575
|
+
className: tagClassName,
|
|
1576
|
+
style: tagStyle,
|
|
1577
|
+
ref: tagRef
|
|
1578
|
+
}, {
|
|
1579
|
+
children: [renderPrefixIcon(), children && jsx(AutoTips, Object.assign({
|
|
249
1580
|
tipMaxWidth: tipMaxWidth
|
|
250
1581
|
}, {
|
|
251
|
-
children: jsx("span", {
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
})) : null, renderCloseIcon()]
|
|
260
|
-
}));
|
|
1582
|
+
children: jsx("span", Object.assign({
|
|
1583
|
+
className: "tag-text"
|
|
1584
|
+
}, {
|
|
1585
|
+
children: inputValue || children
|
|
1586
|
+
}))
|
|
1587
|
+
})), renderCloseIcon()]
|
|
1588
|
+
}))
|
|
1589
|
+
});
|
|
261
1590
|
};
|
|
262
1591
|
var Tag = InternalTag;
|
|
263
1592
|
|