@mw-kit/mw-ui 1.7.3 → 1.7.4

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.
@@ -12353,8 +12353,8 @@ var MenuComponent = function MenuComponent(props, ref) {
12353
12353
  if (rule === undefined) {
12354
12354
  var _onClick = option.onClick || function () {};
12355
12355
 
12356
- onClick = function onClick() {
12357
- _onClick(index);
12356
+ onClick = function onClick(e) {
12357
+ _onClick(index, option, e);
12358
12358
 
12359
12359
  closeMenu();
12360
12360
  };
@@ -13635,22 +13635,21 @@ var Header$1 = function Header() {
13635
13635
  };
13636
13636
 
13637
13637
  var getOptions = function getOptions(props, options) {
13638
- return options.map(function (option, index) {
13638
+ return options.map(function (option) {
13639
13639
  var label = isString(option.label) ? {
13640
13640
  text: option.label,
13641
13641
  element: option.label
13642
13642
  } : option.label;
13643
13643
  var value = option.value,
13644
- onClick = option.onClick;
13644
+ onClick = option.onClick,
13645
+ data = option.data;
13645
13646
  return {
13646
13647
  label: label,
13647
- onClick: onClick ? function () {
13648
- onClick(index, {
13649
- label: label,
13650
- value: value
13651
- });
13648
+ data: data,
13649
+ onClick: onClick ? function (index, _option, event) {
13650
+ onClick(index, option, event);
13652
13651
  } : function () {
13653
- props.setValue(value);
13652
+ props.setValue(value, option);
13654
13653
  }
13655
13654
  };
13656
13655
  });
@@ -13710,7 +13709,9 @@ var Footer$1 = function Footer() {
13710
13709
  setOpen = context.setOpen;
13711
13710
 
13712
13711
  var onClick = function onClick() {
13713
- setValue([].concat(checked));
13712
+ setValue(checked.map(function (c) {
13713
+ return c.value;
13714
+ }), [].concat(checked));
13714
13715
  setOpen(false);
13715
13716
  };
13716
13717
 
@@ -13756,9 +13757,7 @@ var Header$2 = function Header() {
13756
13757
 
13757
13758
  var onClick = function onClick() {
13758
13759
  setChecked(function (prev) {
13759
- return prev.length === options.length ? [] : options.map(function (option) {
13760
- return option.value;
13761
- });
13760
+ return prev.length === options.length ? [] : [].concat(options);
13762
13761
  });
13763
13762
  };
13764
13763
 
@@ -13797,7 +13796,9 @@ var getOptions$1 = function getOptions(options, checked, setChecked) {
13797
13796
  text: label.text,
13798
13797
  element: React__default.createElement(Checkbox, {
13799
13798
  type: 'checkbox',
13800
- checked: checked.includes(option.value),
13799
+ checked: checked.findIndex(function (e) {
13800
+ return e.value === option.value;
13801
+ }) !== -1,
13801
13802
  label: option.disabled && option.disabledText ? React__default.createElement(Popup, {
13802
13803
  on: 'click',
13803
13804
  trigger: React__default.createElement("div", null, label.element),
@@ -13811,9 +13812,9 @@ var getOptions$1 = function getOptions(options, checked, setChecked) {
13811
13812
  var isChecked = event.target.checked;
13812
13813
  setChecked(function (prev) {
13813
13814
  var newState = prev.filter(function (v) {
13814
- return v !== option.value;
13815
+ return v.value !== option.value;
13815
13816
  });
13816
- if (isChecked) newState.push(option.value);
13817
+ if (isChecked) newState.push(_extends({}, option));
13817
13818
  return newState;
13818
13819
  });
13819
13820
  },
@@ -13836,19 +13837,61 @@ var getInputValue$1 = function getInputValue(value) {
13836
13837
  };
13837
13838
 
13838
13839
  var useSelectMultiple = function useSelectMultiple(props) {
13840
+ var init = function init() {
13841
+ return props.value.length === 0 ? [] : typeof props.value[0] === 'string' ? [].concat(props.value).map(function (value) {
13842
+ return {
13843
+ value: value,
13844
+ label: value
13845
+ };
13846
+ }) : [].concat(props.value);
13847
+ };
13848
+
13839
13849
  var _useState = useState([]),
13840
13850
  options = _useState[0],
13841
13851
  setOptions = _useState[1];
13842
13852
 
13843
- var _useState2 = useState([].concat(props.value)),
13844
- checked = _useState2[0],
13845
- setChecked = _useState2[1];
13853
+ var _useState2 = useState(init),
13854
+ inital = _useState2[0],
13855
+ setInitial = _useState2[1];
13856
+
13857
+ var _useState3 = useState(init),
13858
+ checked = _useState3[0],
13859
+ setChecked = _useState3[1];
13846
13860
 
13861
+ useEffect(function () {
13862
+ var getOption = function getOption(def, options, prev) {
13863
+ var index = options.findIndex(function (o) {
13864
+ return o.value === def.value;
13865
+ });
13866
+ if (index !== -1) return _extends({}, options[index]);else {
13867
+ var _index = prev.findIndex(function (o) {
13868
+ return o.value === def.value;
13869
+ });
13870
+
13871
+ if (_index !== -1) return _extends({}, prev[_index]);
13872
+ }
13873
+ return def;
13874
+ };
13875
+
13876
+ var mapper = function mapper(prev) {
13877
+ return props.value.length > 0 && typeof props.value[0] === 'string' ? props.value.map(function (value) {
13878
+ return getOption({
13879
+ value: value,
13880
+ label: value
13881
+ }, options, prev);
13882
+ }) : props.value.map(function (value) {
13883
+ return getOption(value, options, prev);
13884
+ });
13885
+ };
13886
+
13887
+ setInitial(mapper);
13888
+ setChecked(mapper);
13889
+ }, [props.value, options]);
13847
13890
  var parsedOptions = getOptions$1(options, checked, setChecked);
13848
13891
  var inputValue = getInputValue$1(props.value);
13849
13892
 
13850
13893
  var onReset = function onReset() {
13851
- setChecked([].concat(props.value));
13894
+ setChecked([].concat(inital));
13852
13895
  };
13853
13896
 
13854
13897
  var returnData = {
@@ -13992,6 +14035,12 @@ var Select = React__default.forwardRef(function (props, ref) {
13992
14035
  setSearch('');
13993
14036
  };
13994
14037
 
14038
+ var onClick = function onClick() {
14039
+ setOpen(function (prev) {
14040
+ return !prev;
14041
+ });
14042
+ };
14043
+
13995
14044
  return getContext({
13996
14045
  setOpen: setOpen,
13997
14046
  search: [search, setSearch],
@@ -14006,11 +14055,7 @@ var Select = React__default.forwardRef(function (props, ref) {
14006
14055
  }, React__default.createElement(Input$1, Object.assign({}, inputProps, {
14007
14056
  type: 'search',
14008
14057
  readOnly: true,
14009
- onClick: function onClick() {
14010
- setOpen(function (prev) {
14011
- return !prev;
14012
- });
14013
- },
14058
+ onClick: onClick,
14014
14059
  loading: loading,
14015
14060
  icon: {
14016
14061
  position: 'right',
@@ -14018,7 +14063,8 @@ var Select = React__default.forwardRef(function (props, ref) {
14018
14063
  type: 'semantic',
14019
14064
  icon: open ? 'caret up' : 'caret down',
14020
14065
  width: '14px'
14021
- }
14066
+ },
14067
+ onClick: onClick
14022
14068
  },
14023
14069
  ref: ref
14024
14070
  })), React__default.createElement(Menu, Object.assign({}, menuProps, {