mimir-ui-kit 1.15.1 → 1.15.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  export { SelectSearch } from './SelectSearch';
2
- export type { TSelectSearchProps } from './types';
2
+ export type { TSelectSearchProps, TSelectOption } from './types';
3
3
  export { ESelectSearchSize } from './constants';
@@ -1,15 +1,21 @@
1
+ import { ReactNode } from 'react';
1
2
  import { ESelectSearchSize } from './constants';
2
- import { VirtualizedFixedSizeListProps } from './SelectSearch';
3
3
 
4
+ export type TSelectOption = {
5
+ name: string;
6
+ id: number | string;
7
+ bottom?: ReactNode;
8
+ [index: string]: unknown;
9
+ };
4
10
  export type TSelectSearchProps = {
5
11
  /**
6
12
  * Текущее выбранное значение.
7
13
  */
8
- value?: Record<string, unknown> | null;
14
+ value?: TSelectOption | null;
9
15
  /**
10
16
  * Функция обратного вызова при изменении выбранного значения.
11
17
  */
12
- onChange?: (value: Record<string, unknown>) => void;
18
+ onChange?: (value: TSelectOption) => void;
13
19
  /**
14
20
  * Текст-подсказка для поля ввода.
15
21
  */
@@ -22,19 +28,18 @@ export type TSelectSearchProps = {
22
28
  * Флаг для растягивания компонента на всю ширину контейнера.
23
29
  */
24
30
  full?: boolean;
25
- /**
26
- * Дочерние элементы компонента.
27
- */
28
- children?: React.ReactNode;
29
- /**
30
- * Свойства для виртуализированного списка фиксированного размера.
31
- */
32
- virtualizedFixedSizeList?: VirtualizedFixedSizeListProps;
33
31
  /**
34
32
  * Значение, отображаемое в поле выбора.
35
33
  */
36
34
  displayValue?: string;
35
+ /** Показывать ли иконку стрелки выпадающего списка */
37
36
  showArrow?: boolean;
37
+ /** Функция обратного вызова, срабатывающая при изменении поискового запроса */
38
38
  onSearch?: (value: string) => void;
39
+ /** Фильтровать ли варианты на основе поискового запроса */
39
40
  filterOnSearch?: boolean;
41
+ /** Значения, передаваемые в SelectSearch */
42
+ items: TSelectOption[];
43
+ /** Класснейм для значения */
44
+ classNameOption?: string;
40
45
  };
@@ -1,3 +1,4 @@
1
+ import { default as React } from 'react';
1
2
  import { imageTypesArr } from './constants';
2
3
 
3
4
  export type TUploader = {
@@ -18,6 +19,14 @@ export type TUploader = {
18
19
  * Максимальный размер файлов.
19
20
  */
20
21
  maxSize: number;
22
+ /**
23
+ * Максимальное количество файлов.
24
+ */
25
+ maxFiles: number;
26
+ /**
27
+ * Выключен ли Uploader или нет
28
+ */
29
+ isDisabled?: boolean;
21
30
  };
22
31
  export type TUploadValue = {
23
32
  value: TFileItem[];
@@ -27,4 +36,4 @@ export type TFileItem = {
27
36
  id: number;
28
37
  file: File;
29
38
  };
30
- export declare function Uploader({ filesType, onChangeValue, arrayName, maxSize }: TUploader): import("react/jsx-runtime").JSX.Element;
39
+ export declare const Uploader: React.ForwardRefExoticComponent<TUploader & React.RefAttributes<HTMLDivElement>>;
@@ -1,5 +1,5 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { useId, useRef } from "react";
2
+ import { forwardRef, useRef, useId } from "react";
3
3
  import { Icon } from "../../icons/Icon.js";
4
4
  import { Button } from "../Button/Button.js";
5
5
  import '../../assets/Uploader.css';const cls = {
@@ -25,67 +25,73 @@ const filesTyps = ["jpeg", "jpg", "png", "tiff", "gif"];
25
25
  const generateId = (min, max) => {
26
26
  return Math.random() * (max - min) + min;
27
27
  };
28
- function Uploader({
29
- filesType = filesTyps,
30
- onChangeValue,
31
- arrayName,
32
- maxSize = 15
33
- }) {
34
- const idImg = useId();
35
- const ref = useRef(null);
36
- const onChange = (e) => {
37
- if (e.target.files && e.target.files[0]) {
38
- const list = [];
39
- Array.from(e.target.files).forEach((el) => {
40
- if (filesType.map((name) => MIME[name]).includes(el.type) && el.size / 1024 ** 2 <= maxSize) {
41
- list.push({ file: el, id: generateId(1, 100) });
42
- }
43
- });
44
- onChangeValue({ arrayName, value: list });
45
- }
46
- };
47
- const onOpen = () => {
48
- var _a;
49
- (_a = ref.current) == null ? void 0 : _a.click();
50
- };
51
- return /* @__PURE__ */ jsxs("div", { className: cls["upload-file__wrapper"], children: [
52
- /* @__PURE__ */ jsx(
53
- "input",
54
- {
55
- type: "file",
56
- className: cls["upload-file-input"],
57
- "aria-label": "Upload",
58
- name: "image[]",
59
- multiple: true,
60
- onChange,
61
- title: "",
62
- id: idImg,
63
- accept: filesType.map((i) => MIME[i]).join()
28
+ const Uploader = forwardRef(
29
+ (props, ref) => {
30
+ const {
31
+ filesType = filesTyps,
32
+ onChangeValue,
33
+ arrayName,
34
+ maxSize = 15,
35
+ isDisabled
36
+ } = props;
37
+ const uploaderRef = useRef(null);
38
+ const idImg = useId();
39
+ const onChange = (e) => {
40
+ if (e.target.files && e.target.files[0]) {
41
+ const list = [];
42
+ Array.from(e.target.files).forEach((el) => {
43
+ if (filesType.map((name) => MIME[name]).includes(el.type) && el.size / 1024 ** 2 <= maxSize) {
44
+ list.push({ file: el, id: generateId(1, 100) });
45
+ }
46
+ });
47
+ onChangeValue({ arrayName, value: list });
64
48
  }
65
- ),
66
- /* @__PURE__ */ jsxs("label", { htmlFor: idImg, ref, children: [
49
+ };
50
+ const onOpen = () => {
51
+ var _a;
52
+ (_a = uploaderRef.current) == null ? void 0 : _a.click();
53
+ };
54
+ return /* @__PURE__ */ jsxs("div", { className: cls["upload-file__wrapper"], ref, children: [
67
55
  /* @__PURE__ */ jsx(
68
- Button,
56
+ "input",
69
57
  {
70
- size: "m",
71
- variant: "secondary-asphalt",
72
- leftIcon: /* @__PURE__ */ jsx(Icon, { iconName: "UnionIcon16px" }),
73
- onClick: onOpen,
74
- children: "Выберите файлы"
58
+ type: "file",
59
+ className: cls["upload-file-input"],
60
+ "aria-label": "Upload",
61
+ name: "image[]",
62
+ multiple: true,
63
+ onChange,
64
+ title: "",
65
+ id: idImg,
66
+ accept: filesType.map((i) => MIME[i]).join(),
67
+ disabled: isDisabled
75
68
  }
76
69
  ),
77
- /* @__PURE__ */ jsx("b", { children: "Или перетащие сюда" }),
78
- /* @__PURE__ */ jsxs("span", { className: cls["upload-text"], children: [
79
- "Максимальный размер одного файла – ",
80
- maxSize,
81
- " Мб",
82
- /* @__PURE__ */ jsx("br", {}),
83
- "Загрузить можно файлы следующих форматов: ",
84
- filesType.join(", ")
70
+ /* @__PURE__ */ jsxs("label", { htmlFor: idImg, ref: uploaderRef, children: [
71
+ /* @__PURE__ */ jsx(
72
+ Button,
73
+ {
74
+ size: "m",
75
+ variant: "secondary-asphalt",
76
+ leftIcon: /* @__PURE__ */ jsx(Icon, { iconName: "UnionIcon16px" }),
77
+ onClick: onOpen,
78
+ disabled: isDisabled,
79
+ children: "Выберите файлы"
80
+ }
81
+ ),
82
+ /* @__PURE__ */ jsx("b", { children: "Или перетащите сюда" }),
83
+ /* @__PURE__ */ jsxs("span", { className: cls["upload-text"], children: [
84
+ "Максимальный размер одного файла – ",
85
+ maxSize,
86
+ " Мб",
87
+ /* @__PURE__ */ jsx("br", {}),
88
+ "Загрузить можно файлы следующих форматов: ",
89
+ filesType.join(", ")
90
+ ] })
85
91
  ] })
86
- ] })
87
- ] });
88
- }
92
+ ] });
93
+ }
94
+ );
89
95
  export {
90
96
  Uploader
91
97
  };
@@ -1,3 +1,4 @@
1
+ import { TPhotosDetail } from '../ListPhotos/ListPhotos';
1
2
  import { imageTypesArr } from '../Uploader/constants';
2
3
  import { TFileItem } from '../Uploader/Uploader';
3
4
 
@@ -21,9 +22,17 @@ export type TUploaderPhotos = {
21
22
  * type:'delete' в data передает id удаленного файла
22
23
  */
23
24
  onChange: (j: TOnChangePhotosUpdate) => void;
25
+ /**
26
+ * Передаваемые файлы.
27
+ */
28
+ value?: TPhotosDetail[];
29
+ /**
30
+ * Максимальное количество файлов.
31
+ */
32
+ maxFiles: number;
24
33
  };
25
34
  export type TOnChangePhotosUpdate = {
26
35
  type: string;
27
36
  data: TFileItem[] | number;
28
37
  };
29
- export declare function UploaderPhotos({ filesType, arrayName, maxSize, onChange }: TUploaderPhotos): import("react/jsx-runtime").JSX.Element;
38
+ export declare const UploaderPhotos: import('react').ForwardRefExoticComponent<TUploaderPhotos & import('react').RefAttributes<HTMLDivElement>>;
@@ -1,46 +1,62 @@
1
1
  import { jsxs, jsx } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { c as classNames } from "../../index-CweZ_OcN.js";
3
+ import { forwardRef, useState, useEffect } from "react";
3
4
  import { ListPhotos } from "../ListPhotos/ListPhotos.js";
4
5
  import { Uploader } from "../Uploader/Uploader.js";
5
6
  import '../../assets/UploaderPhotos.css';const cls = {
6
- "upload-file__wrapper": "_upload-file__wrapper_udscq_2"
7
+ "upload-file__wrapper": "_upload-file__wrapper_17bcu_2"
7
8
  };
8
- function UploaderPhotos({
9
- filesType,
10
- arrayName,
11
- maxSize,
12
- onChange
13
- }) {
14
- const [photos, setPhotos] = useState([]);
15
- const onChangeValue = (e) => {
16
- setPhotos([
17
- ...photos,
18
- ...e.value.map((el) => {
19
- return {
9
+ const UploaderPhotos = forwardRef(
10
+ (props, ref) => {
11
+ const { filesType, arrayName, maxSize, onChange, value, maxFiles } = props;
12
+ const [photos, setPhotos] = useState(value || []);
13
+ const isMaxFilesReached = photos.length >= maxFiles;
14
+ useEffect(() => {
15
+ if (value) {
16
+ setPhotos(value);
17
+ }
18
+ }, [value]);
19
+ const onChangeValue = (e) => {
20
+ const newPhotos = [
21
+ ...photos,
22
+ ...e.value.map((el) => ({
20
23
  url: URL.createObjectURL(el.file),
21
24
  id: el.id
22
- };
23
- })
24
- ]);
25
- onChange == null ? void 0 : onChange({ type: "add", data: e.value });
26
- };
27
- const onDelete = (j) => {
28
- setPhotos(j.list);
29
- if (j.deleteId) onChange == null ? void 0 : onChange({ type: "delete", data: j.deleteId });
30
- };
31
- return /* @__PURE__ */ jsxs("div", { className: cls["upload-file__wrapper"], children: [
32
- /* @__PURE__ */ jsx(
33
- Uploader,
25
+ }))
26
+ ];
27
+ setPhotos(newPhotos);
28
+ onChange == null ? void 0 : onChange({ type: "add", data: e.value });
29
+ };
30
+ const onDelete = (j) => {
31
+ setPhotos(j.list);
32
+ if (j.deleteId) onChange == null ? void 0 : onChange({ type: "delete", data: j.deleteId });
33
+ };
34
+ return /* @__PURE__ */ jsxs(
35
+ "div",
34
36
  {
35
- filesType,
36
- arrayName,
37
- maxSize,
38
- onChangeValue
37
+ className: classNames(
38
+ cls["upload-file__wrapper"],
39
+ isMaxFilesReached && cls.disabled
40
+ ),
41
+ children: [
42
+ /* @__PURE__ */ jsx(
43
+ Uploader,
44
+ {
45
+ filesType,
46
+ arrayName,
47
+ maxSize,
48
+ onChangeValue,
49
+ ref,
50
+ maxFiles,
51
+ isDisabled: isMaxFilesReached
52
+ }
53
+ ),
54
+ /* @__PURE__ */ jsx(ListPhotos, { value: photos, onChange: onDelete })
55
+ ]
39
56
  }
40
- ),
41
- /* @__PURE__ */ jsx(ListPhotos, { value: photos, onChange: onDelete })
42
- ] });
43
- }
57
+ );
58
+ }
59
+ );
44
60
  export {
45
61
  UploaderPhotos
46
62
  };
@@ -20,9 +20,7 @@ export { EDrawerPosition } from './Drawer';
20
20
  export { Steps, EStepsPrimaryColor, EStepsSecondaryColor, EStepsSize, type TCommonStepsProps } from './Steps';
21
21
  export { Vote, EVoteSize, type TCommonVoteProps } from './Vote';
22
22
  export { SelectSearch, ESelectSearchSize } from './SelectSearch';
23
- export type { TSelectSearchProps } from './SelectSearch';
24
- export { SelectSearchOption } from './SelectSearchOption';
25
- export type { SelectSearchOptionProps } from './SelectSearchOption';
23
+ export type { TSelectSearchProps, TSelectOption } from './SelectSearch';
26
24
  export { Switch } from './Switch';
27
25
  export type { TSwitchProps } from './Switch';
28
26
  export { Tag, ETagSize, ETagType } from './Tag';
@@ -21,7 +21,6 @@ import { Vote } from "./Vote/Vote.js";
21
21
  import { EVoteSize } from "./Vote/constants.js";
22
22
  import { SelectSearch } from "./SelectSearch/SelectSearch.js";
23
23
  import { ESelectSearchSize } from "./SelectSearch/constants.js";
24
- import { S } from "../SelectSearchOption-snHM9uZX.js";
25
24
  import { Switch } from "./Switch/Switch.js";
26
25
  import { Tag } from "./Tag/Tag.js";
27
26
  import { ETagSize, ETagType } from "./Tag/constants.js";
@@ -73,7 +72,6 @@ export {
73
72
  Pagination,
74
73
  RadioGroup,
75
74
  SelectSearch,
76
- S as SelectSearchOption,
77
75
  Slider,
78
76
  Steps,
79
77
  Switch,
package/dist/index.js CHANGED
@@ -21,7 +21,6 @@ import { Vote } from "./components/Vote/Vote.js";
21
21
  import { EVoteSize } from "./components/Vote/constants.js";
22
22
  import { SelectSearch } from "./components/SelectSearch/SelectSearch.js";
23
23
  import { ESelectSearchSize } from "./components/SelectSearch/constants.js";
24
- import { S } from "./SelectSearchOption-snHM9uZX.js";
25
24
  import { Switch } from "./components/Switch/Switch.js";
26
25
  import { Tag } from "./components/Tag/Tag.js";
27
26
  import { ETagSize, ETagType } from "./components/Tag/constants.js";
@@ -84,7 +83,6 @@ import './assets/index.css';export {
84
83
  Pagination,
85
84
  RadioGroup,
86
85
  SelectSearch,
87
- S as SelectSearchOption,
88
86
  Slider,
89
87
  Steps,
90
88
  Switch,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mimir-ui-kit",
3
3
  "private": false,
4
- "version": "1.15.1",
4
+ "version": "1.15.2",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {