armtek-uikit-react 1.0.96 → 1.0.97

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/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"armtek-uikit-react","version":"1.0.96","description":"Armtek UIKit for React","repository":{"type":"git","url":"ssh://git@gl.corp:10022/int/uikit/uikit_react.git"},"author":"","license":"ISC","dependencies":{"build":"^0.1.4","clsx":"^2.0.0","rc-slider":"^10.2.1","react":"*","react-datepicker":"^4.16.0","react-dom":"*","react-transition-group":"^4.4.5"},"peerDependencies":{"react":"*","react-dom":"*"},"scripts":{"pub":"npm version patch && npm publish"}}
1
+ {"name":"armtek-uikit-react","version":"1.0.97","description":"Armtek UIKit for React","repository":{"type":"git","url":"ssh://git@gl.corp:10022/int/uikit/uikit_react.git"},"author":"","license":"ISC","dependencies":{"build":"^0.1.4","clsx":"^2.0.0","rc-slider":"^10.2.1","react":"*","react-datepicker":"^4.16.0","react-dom":"*","react-transition-group":"^4.4.5"},"peerDependencies":{"react":"*","react-dom":"*"},"scripts":{"pub":"npm version patch && npm publish"}}
@@ -3,7 +3,9 @@ import { ChangeEvent } from 'react';
3
3
  export type DateFieldProps = {
4
4
  format?: string;
5
5
  onInput?: (e: ChangeEvent<HTMLInputElement>) => void;
6
- onChange?: (value: Date | null) => void;
6
+ onChange?: (e: ChangeEvent<HTMLInputElement> & {
7
+ value: Date | null;
8
+ }) => void;
7
9
  value?: Date | string | null;
8
10
  showTime?: boolean;
9
11
  showTimeOnly?: boolean;
@@ -11,7 +13,9 @@ export type DateFieldProps = {
11
13
  export declare const DateField: import("react").ForwardRefExoticComponent<{
12
14
  format?: string | undefined;
13
15
  onInput?: ((e: ChangeEvent<HTMLInputElement>) => void) | undefined;
14
- onChange?: ((value: Date | null) => void) | undefined;
16
+ onChange?: ((e: ChangeEvent<HTMLInputElement> & {
17
+ value: Date | null;
18
+ }) => void) | undefined;
15
19
  value?: string | Date | null | undefined;
16
20
  showTime?: boolean | undefined;
17
21
  showTimeOnly?: boolean | undefined;
@@ -27,7 +27,19 @@ export const DateField = /*#__PURE__*/forwardRef((props, ref) => {
27
27
  const handleChange = d => {
28
28
  setDate(d);
29
29
  setOpen(false);
30
- if (onChange) onChange(d);
30
+ if (onChange) {
31
+ const e = new Event('input', {
32
+ bubbles: true
33
+ });
34
+ Object.defineProperty(e, 'target', {
35
+ writable: false,
36
+ value: {
37
+ name: props.name,
38
+ value: d
39
+ }
40
+ });
41
+ onChange(e);
42
+ }
31
43
  };
32
44
  const handleClick = e => {
33
45
  setOpen(prev => !prev);
@@ -42,6 +54,7 @@ export const DateField = /*#__PURE__*/forwardRef((props, ref) => {
42
54
  ref: ref,
43
55
  ...restProps,
44
56
  value: (dateValue == null ? void 0 : dateValue.toLocaleDateString('ru-RU')) || '',
57
+ onChange: () => null,
45
58
  endAdornment: /*#__PURE__*/_jsx(ButtonIcon, {
46
59
  size: 'medium',
47
60
  variant: 'transparent',
@@ -1,7 +1,13 @@
1
1
  import { TextFieldProps } from '../TextField/TextField';
2
+ export type PeriodChangeEvent = (Event & {
3
+ target: {
4
+ value: [Date | null, Date | null];
5
+ name: string;
6
+ };
7
+ });
2
8
  declare const Period: import("react").ForwardRefExoticComponent<{
3
9
  format?: string | undefined;
4
- onChange?: ((value: [Date | null, Date | null]) => void) | undefined;
10
+ onChange?: ((e: PeriodChangeEvent) => void) | undefined;
5
11
  value?: [Date | null, Date | null] | undefined;
6
12
  } & Omit<TextFieldProps, "value" | "onChange"> & import("react").RefAttributes<unknown>>;
7
13
  export default Period;
@@ -29,7 +29,19 @@ const Period = /*#__PURE__*/forwardRef((props, ref) => {
29
29
  const handleChange = date => {
30
30
  setValue(date);
31
31
  if (date[0] && date[1]) setActive(false);
32
- if (onChange) onChange(date);
32
+ if (onChange) {
33
+ const e = new Event('input', {
34
+ bubbles: true
35
+ });
36
+ Object.defineProperty(e, 'target', {
37
+ writable: false,
38
+ value: {
39
+ name: props.name,
40
+ value: date
41
+ }
42
+ });
43
+ onChange(e);
44
+ }
33
45
  };
34
46
  let realValue = Array.isArray(props.value) ? props.value : value;
35
47
  let displayValue = '';
@@ -42,6 +54,7 @@ const Period = /*#__PURE__*/forwardRef((props, ref) => {
42
54
  placeholder: 'дд.мм.гггг - дд.мм.гггг',
43
55
  ...restProps,
44
56
  value: displayValue,
57
+ onChange: () => null,
45
58
  onFocus: handleClick,
46
59
  endAdornment: /*#__PURE__*/_jsx(ButtonIcon, {
47
60
  size: 'medium',
@@ -1,5 +1,6 @@
1
1
  import { OptionType } from '../../../types/theme';
2
2
  import { TextFieldProps } from '../TextField/TextField';
3
+ import { MouseEvent } from 'react';
3
4
  type SelectBaseProps = {
4
5
  options: OptionType[];
5
6
  inline?: boolean;
@@ -10,28 +11,27 @@ type SelectBaseProps = {
10
11
  onClearAll?: () => void;
11
12
  onSubmit?: () => void;
12
13
  };
13
- type SelectSingleProps = {
14
- multiple?: false;
15
- value?: string;
16
- defaultValue?: string;
17
- onChange?: (option: string) => void;
14
+ type MultipleType<M extends boolean = false> = {
15
+ multiple?: M;
16
+ value?: M extends false ? string : string[];
17
+ defaultValue?: M extends false ? string : string[];
18
+ onChange?: (e: SelectChangeEvent<M extends false ? string : string[]>) => void;
18
19
  };
19
- type SelectMultipleProps = {
20
- multiple?: true;
21
- value?: string[];
22
- defaultValue?: string[];
23
- onChange?: (option: string[]) => void;
24
- };
25
- type SelectPropsType = SelectMultipleProps | SelectSingleProps;
26
- export type SelectProps = SelectBaseProps & SelectPropsType & Omit<TextFieldProps, 'value' | 'defaultValue' | 'onChange'>;
20
+ export type SelectProps<M extends boolean = false> = SelectBaseProps & MultipleType<M> & Omit<TextFieldProps, keyof SelectBaseProps | keyof MultipleType<M>>;
27
21
  export declare const getOptionValue: (option: OptionType) => string;
28
- declare function Select(props: SelectProps): import("react/jsx-runtime").JSX.Element;
22
+ export type SelectChangeEvent<Value = string> = (Event & {
23
+ target: {
24
+ value: Value;
25
+ name: string;
26
+ };
27
+ });
28
+ declare function Select<M extends boolean = false>(props: SelectProps<M>): import("react/jsx-runtime").JSX.Element;
29
29
  type SelectOptionsType<T extends boolean> = {
30
30
  options: OptionType[];
31
31
  value?: T extends true ? string[] : string;
32
32
  inline?: boolean;
33
33
  multiple?: T;
34
- onClick: (option: OptionType) => void;
34
+ onClick: (e: MouseEvent, option: OptionType) => void;
35
35
  listStyle?: 'checkbox' | 'default';
36
36
  onSelectAll?: () => void;
37
37
  onClearAll?: () => void;
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  import TextField from "../TextField/TextField";
4
- import { forwardRef, useRef, useState } from 'react';
4
+ import { forwardRef, useState } from 'react';
5
5
  import clsx from 'clsx';
6
6
  import ListItem from "../../List/ListItem";
7
7
  import css from "./Select.module.scss";
@@ -17,6 +17,9 @@ const CssClasses = ['select', 'select__input_wrapper', 'select__input', 'options
17
17
  // const css = getCssPrefix(CssClasses)
18
18
 
19
19
  export const getOptionValue = option => option.value || option.text;
20
+
21
+ // let selectEl!: HTMLSelectElement
22
+
20
23
  function Select(props) {
21
24
  var _options$find;
22
25
  let {
@@ -40,44 +43,33 @@ function Select(props) {
40
43
  let [selected, setSelected] = useState(defaultValue || (multiple ? [] : ''));
41
44
  let [focused, setFocused] = useState(false);
42
45
  let [q, setQ] = useState('');
43
- let selectRef = useRef(null);
44
46
  const [anchorEl, setAnchorEl] = useState(null);
45
-
46
- // let selectEl!: HTMLSelectElement
47
- //
48
- // useEffect(() => {
49
- // selectEl = document.createElement('select')
50
- // selectEl.onchange = (e) => {
51
- // console.log(e)
52
- // }
53
- // return () => {
54
- // selectEl.remove()
55
- // }
56
- // }, [])
57
-
58
47
  const handleOpen = e => {
59
48
  if (!inputProps.disabled) {
60
49
  setActive(true);
61
50
  if (e.target instanceof HTMLDivElement) setAnchorEl(e.currentTarget);
62
51
  }
63
52
  };
64
- const handleSelect = option => {
65
- // selectEl.sele = option.value
66
- // selectEl?.dispatchEvent(new Event('change', { bubbles: true }))
67
-
53
+ const handleSelect = (e, option) => {
68
54
  let v = getOptionValue(option);
69
55
  let mSelected = Array.isArray(selected) ? selected : [selected];
70
56
  let newValueS = v;
71
57
  let newValueM = mSelected.includes(v) ? mSelected.filter(item => item !== v) : mSelected.concat(v);
72
58
  setSelected(multiple ? newValueM : newValueS);
73
- if (onChange) onChange(multiple ? newValueM : newValueS);
59
+ if (onChange) {
60
+ Object.defineProperty(e, 'target', {
61
+ writable: false,
62
+ value: {
63
+ name: props.name,
64
+ value: multiple ? newValueM : newValueS
65
+ }
66
+ });
67
+ onChange(e);
68
+ }
74
69
  if (search && !multiple) {
75
70
  setQ(options.find(item => getOptionValue(item) === newValueS).text);
76
71
  }
77
72
  if (!multiple) setActive(false);
78
-
79
- // if(selectRef.current)
80
- // selectRef.current.dispatchEvent(new Event('change', { bubbles: true }))
81
73
  };
82
74
  const handleSearch = e => {
83
75
  setQ(e.target.value);
@@ -88,18 +80,6 @@ function Select(props) {
88
80
  const handleBlur = !!search ? () => {
89
81
  setFocused(false);
90
82
  } : undefined;
91
-
92
- // const handleChange = (e: ChangeEvent<HTMLSelectElement>) => {
93
- // let option = options.find(item => getOptionValue(item) === e.target.value)
94
- // if( option )
95
- // {
96
- // let v = getOptionValue(option)
97
- // setSelected(!multiple ? v : prev => prev?.concat(v) || [v])
98
- // if( !multiple )
99
- // setActive(false)
100
- // }
101
- // }
102
-
103
83
  let selectEndAdornment = /*#__PURE__*/_jsxs(_Fragment, {
104
84
  children: [/*#__PURE__*/_jsx(Adornment, {
105
85
  children: endAdornment
@@ -113,13 +93,6 @@ function Select(props) {
113
93
  })
114
94
  })]
115
95
  });
116
- let selectProps = {};
117
- // if( value !== undefined )
118
- // {
119
- // selectProps.value = value
120
- // selectProps.onChange = handleChange
121
- // }
122
-
123
96
  const handleSelectAll = () => {
124
97
  let value = options.map(item => getOptionValue(item));
125
98
  setSelected(value);
@@ -143,20 +116,10 @@ function Select(props) {
143
116
  return /*#__PURE__*/_jsxs(_Fragment, {
144
117
  children: [/*#__PURE__*/_jsxs("div", {
145
118
  className: css.select,
146
- children: [/*#__PURE__*/_jsxs("div", {
119
+ children: [/*#__PURE__*/_jsx("div", {
147
120
  className: css.select__input_wrapper,
148
121
  onClick: handleOpen,
149
- children: [/*#__PURE__*/_jsx("select", {
150
- multiple: multiple,
151
- ref: selectRef,
152
- ...selectProps,
153
- style: {
154
- display: 'none'
155
- },
156
- children: options.map(item => /*#__PURE__*/_jsx("option", {
157
- children: item.text
158
- }, item.text))
159
- }), /*#__PURE__*/_jsx(TextField, {
122
+ children: /*#__PURE__*/_jsx(TextField, {
160
123
  ...inputProps,
161
124
  onChange: handleSearch,
162
125
  focused: focused,
@@ -169,7 +132,7 @@ function Select(props) {
169
132
  pointerEvents: 'none'
170
133
  },
171
134
  editable: !!search
172
- })]
135
+ })
173
136
  }), multiple && !realActive && /*#__PURE__*/_jsx(SelectSummaryChips, {
174
137
  options: selectedOptions,
175
138
  disabled: inputProps.disabled,
@@ -220,7 +183,7 @@ const SelectOptions = /*#__PURE__*/forwardRef((props, ref) => {
220
183
  disabled: disabled,
221
184
  checked: checked,
222
185
  active: active,
223
- onClick: () => onClick(item),
186
+ onClick: e => onClick(e, item),
224
187
  children: item.text
225
188
  }, index);
226
189
  }), listStyle === 'checkbox' && !!multiple && /*#__PURE__*/_jsx("div", {
@@ -1,9 +1,10 @@
1
+ import { MouseEvent } from 'react';
1
2
  import { OptionType } from '../../../types/theme';
2
3
  export type SelectSummaryProps = {
3
4
  label_check_all?: string;
4
5
  label_uncheck_all?: string;
5
6
  label_submit?: string;
6
- onClose: (option: OptionType) => void;
7
+ onClose: (e: MouseEvent, option: OptionType) => void;
7
8
  onSelectAll?: () => void;
8
9
  onClearAll?: () => void;
9
10
  onSubmit?: () => void;
@@ -15,7 +16,7 @@ export declare const SelectSummary: (props: SelectSummaryProps) => import("react
15
16
  type SelectSummaryChipsProps = {
16
17
  options: OptionType[];
17
18
  disabled?: boolean;
18
- onDelete: (option: OptionType) => void;
19
+ onDelete: (e: MouseEvent, option: OptionType) => void;
19
20
  };
20
21
  export declare const SelectSummaryChips: (props: SelectSummaryChipsProps) => import("react/jsx-runtime").JSX.Element;
21
22
  export {};
@@ -96,7 +96,7 @@ export const SelectSummaryChips = props => {
96
96
  disabled: disabled,
97
97
  className: css.selectSummary__option,
98
98
  text: option.text,
99
- onClose: () => onDelete(option)
99
+ onClose: e => onDelete(e, option)
100
100
  }, getOptionValue(option));
101
101
  })
102
102
  })