@mw-kit/mw-ui 1.7.17 → 1.7.19

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.
@@ -11,7 +11,7 @@ export interface CommonOption {
11
11
  value: string;
12
12
  data?: any;
13
13
  disabled?: boolean;
14
- disabledText?: string;
14
+ rules?: MenuOption['rules'];
15
15
  }
16
16
  export interface CommonProps extends Omit<InputProps, 'type' | 'mask' | 'icon' | 'setValue' | 'name' | 'value' | 'onChange'> {
17
17
  onScrollEnd?: () => Promise<void>;
@@ -1,12 +1,9 @@
1
1
  import React from 'react';
2
+ import { PopupProps } from 'semantic-ui-react';
2
3
  import { ElementOrString, SpacingOrZero, Spacings } from '../../interfaces';
3
4
  import { AbsoluteContainerProps } from '../AbsoluteContainer/interfaces';
4
- interface Rule {
5
- /** string de mensagem que sera exibida caso a validacao falhe */
6
- message?: ElementOrString;
7
- /** funcao que fara a validacao da regra, deve retornar true caso passe na validacao, e false caso contrario */
8
- rule: (index: number) => boolean;
9
- }
5
+ /** funcao que fara a validacao da regra, deve retornar true caso passe na validacao, e false ou o conteudo do popup caso contrario */
6
+ declare type Rule = (index: number, data: Option['data'], label: Exclude<Option['label'], string>) => boolean | Omit<PopupProps, 'trigger'>;
10
7
  export interface Option {
11
8
  label: string | {
12
9
  text: string;
@@ -18,6 +15,7 @@ export interface Option {
18
15
  onClick?: (index: number, option: Option, event: React.MouseEvent) => void;
19
16
  rules?: Rule[];
20
17
  data?: any;
18
+ disabled?: boolean;
21
19
  }
22
20
  export interface CommonProps extends Omit<AbsoluteContainerProps, 'children'> {
23
21
  bordered?: boolean;
package/dist/index.js CHANGED
@@ -12413,34 +12413,59 @@ var MenuComponent = function MenuComponent(props, ref) {
12413
12413
  } : option.label;
12414
12414
  var closeMenu = keepOpen ? function () {} : close;
12415
12415
  var onClick;
12416
- var disabled;
12417
- var rules = option.rules || [];
12418
- var rule = rules.find(function (rule) {
12419
- return !rule.rule(index);
12420
- });
12416
+ var disabled = option.disabled;
12421
12417
 
12422
- if (rule === undefined) {
12423
- var _onClick = option.onClick || function () {};
12418
+ var OptionContent = function OptionContent(_ref) {
12419
+ var children = _ref.children;
12420
+ return children;
12421
+ };
12424
12422
 
12425
- onClick = function onClick(e) {
12426
- _onClick(index, option, e);
12423
+ if (!disabled) {
12424
+ var rules = option.rules || [];
12425
+ var rule = rules.map(function (rule) {
12426
+ return rule(index, option.data, label);
12427
+ }).find(function (result) {
12428
+ return result !== true;
12429
+ });
12427
12430
 
12428
- closeMenu();
12429
- };
12430
- } else {
12431
- disabled = true;
12431
+ if (rule === true || rule === undefined) {
12432
+ var _onClick = option.onClick || function () {};
12433
+
12434
+ onClick = function onClick(e) {
12435
+ _onClick(index, option, e);
12436
+
12437
+ closeMenu();
12438
+ };
12439
+ } else {
12440
+ disabled = true;
12441
+
12442
+ if (rule !== false) {
12443
+ OptionContent = function OptionContent(_ref2) {
12444
+ var children = _ref2.children;
12445
+ return React__default.createElement(semanticUiReact.Popup, Object.assign({
12446
+ on: 'click',
12447
+ position: 'top left',
12448
+ inverted: true,
12449
+ wide: true
12450
+ }, rule, {
12451
+ trigger: React__default.createElement("div", null, children)
12452
+ }));
12453
+ };
12454
+ }
12455
+ }
12432
12456
  }
12433
12457
 
12458
+ OptionContent.displayName = 'OptionContent';
12434
12459
  return React__default.createElement(React__default.Fragment, {
12435
12460
  key: index
12436
- }, React__default.createElement(Option, {
12461
+ }, React__default.createElement(OptionContent, null, React__default.createElement(Option, {
12437
12462
  onClick: onClick,
12438
12463
  disabled: disabled
12439
12464
  }, isString(label.element) ? React__default.createElement(EllipsisContainer$1, null, label.element) : label.element, caret ? React__default.createElement(Icon, {
12440
12465
  type: 'semantic',
12441
12466
  icon: 'caret right',
12442
12467
  width: '14px'
12443
- }) : null), delimiter && React__default.createElement(Delimiter, null));
12468
+ }) : null)), delimiter && React__default.createElement(Delimiter, null));
12444
12469
  })), children));
12445
12470
  };
12446
12471
 
@@ -13163,11 +13188,9 @@ var MonthPicker = function MonthPicker(props) {
13163
13188
  setValue(year, index);
13164
13189
  close();
13165
13190
  },
13166
- rules: [{
13167
- rule: function rule() {
13168
- var disabled = min !== undefined && (min.getFullYear() > year || min.getFullYear() === year && min.getMonth() > index) || max !== undefined && (max.getFullYear() < year || max.getFullYear() === year && max.getMonth() < index);
13169
- return !disabled;
13170
- }
13191
+ rules: [function () {
13192
+ var disabled = min !== undefined && (min.getFullYear() > year || min.getFullYear() === year && min.getMonth() > index) || max !== undefined && (max.getFullYear() < year || max.getFullYear() === year && max.getMonth() < index);
13193
+ return !disabled;
13171
13194
  }]
13172
13195
  };
13173
13196
  })
@@ -14388,16 +14411,17 @@ var getOptions = function getOptions(props, options) {
14388
14411
  element: option.label
14389
14412
  } : option.label;
14390
14413
  var value = option.value,
14391
- onClick = option.onClick,
14392
- data = option.data;
14414
+ onClick = option.onClick;
14393
14415
  return {
14394
14416
  label: label,
14395
- data: data,
14396
14417
  onClick: onClick ? function (index, _option, event) {
14397
14418
  onClick(index, option, event);
14398
14419
  } : function () {
14399
14420
  props.setValue(value, option);
14400
- }
14421
+ },
14422
+ data: option.data,
14423
+ disabled: option.disabled,
14424
+ rules: option.rules
14401
14425
  };
14402
14426
  });
14403
14427
  };
@@ -14546,14 +14570,7 @@ var getOptions$1 = function getOptions(options, checked, setChecked) {
14546
14570
  checked: checked.findIndex(function (e) {
14547
14571
  return e.value === option.value;
14548
14572
  }) !== -1,
14549
- label: option.disabled && option.disabledText ? React__default.createElement(semanticUiReact.Popup, {
14550
- on: 'click',
14551
- trigger: React__default.createElement("div", null, label.element),
14552
- content: option.disabledText,
14553
- position: 'left center',
14554
- inverted: true,
14555
- wide: true
14556
- }) : label.element,
14573
+ label: label.element,
14557
14574
  disabled: option.disabled,
14558
14575
  onChange: function onChange(event) {
14559
14576
  var isChecked = event.target.checked;
@@ -14573,6 +14590,9 @@ var getOptions$1 = function getOptions(options, checked, setChecked) {
14573
14590
  }
14574
14591
  })
14575
14592
  },
14593
+ data: option.data,
14594
+ disabled: option.disabled,
14595
+ rules: option.rules,
14576
14596
  keepOpen: true
14577
14597
  };
14578
14598
  });