@mw-kit/mw-ui 1.7.20 → 1.7.21

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.
@@ -1,19 +1,9 @@
1
- import React from 'react';
2
- import { CommonContext, CommonOption, CommonProps } from '../interfaces';
3
- export interface Option extends CommonOption {
4
- onClick?: (index: number, data: Option, event: React.MouseEvent) => void;
5
- }
6
- interface LoaderReturn {
7
- options: Option[];
8
- lastPage: boolean;
9
- }
10
- export declare type Loader = (search: string, page: number) => Promise<LoaderReturn | Option[]>;
1
+ import { CommonContext, Option, CommonProps } from '../interfaces';
11
2
  export interface SelectProps extends CommonProps {
12
3
  type: 'select';
13
4
  name?: string;
14
- setValue: (value: string, option: CommonOption) => void;
5
+ setValue: (value: string, option: Option) => void;
15
6
  value: string;
16
- loader: Loader;
17
7
  }
18
- export declare type ContextInterface = CommonContext<SelectProps, Option>;
19
- export {};
8
+ export declare type ContextInterface = CommonContext<SelectProps>;
9
+ export * from '../interfaces';
@@ -1,19 +1,12 @@
1
1
  /// <reference types="react" />
2
- import { CommonContext, CommonOption, CommonProps } from '../interfaces';
3
- export declare type Option = CommonOption;
4
- interface LoaderReturn {
5
- options: Option[];
6
- lastPage: boolean;
7
- }
8
- export declare type Loader = (search: string, page: number) => Promise<LoaderReturn | Option[]>;
2
+ import { CommonContext, Option, CommonProps } from '../interfaces';
9
3
  export interface SelectProps extends CommonProps {
10
4
  type: 'select-multiple';
11
5
  setValue: (value: string[], options: Option[]) => void;
12
6
  value: string[] | Option[];
13
7
  selectAll?: boolean;
14
- loader: Loader;
15
8
  }
16
- export interface ContextInterface extends CommonContext<SelectProps, Option> {
9
+ export interface ContextInterface extends CommonContext<SelectProps> {
17
10
  checked: [Option[], React.Dispatch<React.SetStateAction<Option[]>>];
18
11
  }
19
- export {};
12
+ export * from '../interfaces';
@@ -3,7 +3,7 @@ import { ElementOrString, SpacingOrZero, Spacings } from '../../../../../interfa
3
3
  import { Position } from '../../../../AbsoluteContainer/interfaces';
4
4
  import { Option as MenuOption } from '../../../../Menu/interfaces';
5
5
  import { InputProps } from '../../Input/interfaces';
6
- export interface CommonOption {
6
+ export interface Option {
7
7
  label: string | {
8
8
  text: string;
9
9
  element: ElementOrString;
@@ -12,7 +12,15 @@ export interface CommonOption {
12
12
  data?: any;
13
13
  disabled?: boolean;
14
14
  rules?: MenuOption['rules'];
15
+ onClick?: (index: number, option: Pick<Option, 'value' | 'data'> & {
16
+ label: Exclude<Option['label'], string>;
17
+ }, event: React.MouseEvent) => void;
15
18
  }
19
+ interface LoaderReturn {
20
+ options: Option[];
21
+ lastPage: boolean;
22
+ }
23
+ export declare type Loader = (search: string, page: number) => Promise<LoaderReturn | Option[]>;
16
24
  export interface CommonProps extends Omit<InputProps, 'type' | 'mask' | 'icon' | 'setValue' | 'name' | 'value' | 'onChange'> {
17
25
  onScrollEnd?: () => Promise<void>;
18
26
  position?: Position;
@@ -21,6 +29,7 @@ export interface CommonProps extends Omit<InputProps, 'type' | 'mask' | 'icon' |
21
29
  x: number;
22
30
  y: number;
23
31
  };
32
+ loader: Loader;
24
33
  }
25
34
  interface BaseContext {
26
35
  setOpen: React.Dispatch<React.SetStateAction<boolean>>;
@@ -30,7 +39,7 @@ interface BaseContext {
30
39
  onSearch: () => void;
31
40
  onClearSearch: () => void;
32
41
  }
33
- export interface CommonContext<SelectProps extends CommonProps, Option extends CommonOption> extends BaseContext {
42
+ export interface CommonContext<SelectProps extends CommonProps> extends BaseContext {
34
43
  props: SelectProps;
35
44
  options: Option[];
36
45
  }
@@ -42,7 +51,7 @@ export interface ParsedOption extends MenuOption {
42
51
  }
43
52
  export interface useSelectReturn {
44
53
  parsedOptions: ParsedOption[];
45
- options: [CommonOption[], React.Dispatch<React.SetStateAction<CommonOption[]>>];
54
+ options: [Option[], React.Dispatch<React.SetStateAction<Option[]>>];
46
55
  input: {
47
56
  value: string;
48
57
  };
@@ -1,2 +1 @@
1
- export type { Option as SelectOption, Loader as SelectLoader, } from './hooks/Select/interfaces';
2
- export type { Option as SelectMultipleOption, Loader as SelectMultipleLoader, } from './hooks/SelectMultiple/interfaces';
1
+ export type { Option as SelectOption, Loader as SelectLoader, } from './hooks/interfaces';
package/dist/index.js CHANGED
@@ -14419,15 +14419,20 @@ var getOptions = function getOptions(props, options) {
14419
14419
  element: option.label
14420
14420
  } : option.label;
14421
14421
  var value = option.value,
14422
- onClick = option.onClick;
14422
+ onClick = option.onClick,
14423
+ data = option.data;
14423
14424
  return {
14424
14425
  label: label,
14425
14426
  onClick: onClick ? function (index, _option, event) {
14426
- onClick(index, option, event);
14427
+ onClick(index, {
14428
+ label: label,
14429
+ value: value,
14430
+ data: data
14431
+ }, event);
14427
14432
  } : function () {
14428
14433
  props.setValue(value, option);
14429
14434
  },
14430
- data: option.data,
14435
+ data: data,
14431
14436
  disabled: option.disabled,
14432
14437
  rules: option.rules
14433
14438
  };
@@ -14570,6 +14575,9 @@ var getOptions$1 = function getOptions(options, checked, setChecked) {
14570
14575
  text: option.label,
14571
14576
  element: option.label
14572
14577
  } : option.label;
14578
+ var value = option.value,
14579
+ onClick = option.onClick,
14580
+ data = option.data;
14573
14581
  return {
14574
14582
  label: {
14575
14583
  text: label.text,
@@ -14598,7 +14606,14 @@ var getOptions$1 = function getOptions(options, checked, setChecked) {
14598
14606
  }
14599
14607
  })
14600
14608
  },
14601
- data: option.data,
14609
+ onClick: onClick ? function (index, _option, event) {
14610
+ onClick(index, {
14611
+ label: label,
14612
+ value: value,
14613
+ data: data
14614
+ }, event);
14615
+ } : undefined,
14616
+ data: data,
14602
14617
  disabled: option.disabled,
14603
14618
  rules: option.rules,
14604
14619
  keepOpen: true
@@ -14613,7 +14628,8 @@ var getInputValue$1 = function getInputValue(value) {
14613
14628
 
14614
14629
  var useSelectMultiple = function useSelectMultiple(props) {
14615
14630
  var init = function init() {
14616
- return props.value.length === 0 ? [] : typeof props.value[0] === 'string' ? [].concat(props.value).map(function (value) {
14631
+ if (props.value.length) return [];
14632
+ return typeof props.value[0] === 'string' ? [].concat(props.value).map(function (value) {
14617
14633
  return {
14618
14634
  value: value,
14619
14635
  label: value