@companix/uikit 0.0.12 → 0.0.14

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.
@@ -2,7 +2,6 @@ import { FormProps } from '../Input';
2
2
  import { CalendarProps } from './Calendar';
3
3
  interface DatePickerProps extends Omit<CalendarProps, 'onChange'>, Omit<FormProps, 'value' | 'onChange' | 'rightElement'> {
4
4
  onChange?: (value: Date | null) => void;
5
- placeholder?: string;
6
5
  clearButton?: boolean;
7
6
  clearButtonIcon?: boolean;
8
7
  children?: React.ReactNode;
@@ -8,7 +8,7 @@ export interface FormProps extends React.HTMLAttributes<HTMLDivElement> {
8
8
  readOnly?: boolean;
9
9
  onValueChange?: (value: string, targetElement: HTMLInputElement) => void;
10
10
  onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;
11
- inputRef?: React.RefObject<HTMLInputElement>;
11
+ inputRef?: React.Ref<HTMLInputElement>;
12
12
  size?: 'sm' | 'md' | 'lg';
13
13
  fill?: boolean;
14
14
  mask?: string;
@@ -9,6 +9,7 @@ export interface SelectFormProps extends React.HTMLAttributes<HTMLDivElement> {
9
9
  fill?: boolean;
10
10
  clearButton?: boolean;
11
11
  clearButtonIcon?: boolean;
12
+ inputRef?: React.Ref<HTMLInputElement>;
12
13
  onClear?: (event: React.MouseEvent<HTMLButtonElement>) => void;
13
14
  }
14
15
  export declare const SelectInput: import('react').ForwardRefExoticComponent<SelectFormProps & import('react').RefAttributes<HTMLDivElement>>;
@@ -1,11 +1,8 @@
1
- import { FormProps } from '../Input';
2
1
  import { Option } from '../types';
3
- interface SelectProps<T> extends Omit<FormProps, 'value' | 'onChange' | 'rightElement'> {
2
+ import { SelectFormProps } from './SelectInput';
3
+ interface SelectProps<T> extends Omit<SelectFormProps, 'value' | 'onChange'> {
4
4
  options: Option<T>[];
5
5
  onChange: (event: T | null) => void;
6
- placeholder?: string;
7
- clearButton?: boolean;
8
- clearButtonIcon?: boolean;
9
6
  value: T | null;
10
7
  children?: React.ReactNode;
11
8
  minimalOptions?: boolean;
@@ -11,5 +11,6 @@ export interface SelectTagsProps<T> {
11
11
  emptyText?: string;
12
12
  size?: 'sm' | 'md' | 'lg';
13
13
  fill?: boolean;
14
+ inputRef?: React.Ref<HTMLInputElement>;
14
15
  }
15
16
  export declare const SelectTags: <T extends string | number>(props: SelectTagsProps<T>) => import("react/jsx-runtime").JSX.Element;
@@ -2,6 +2,7 @@ interface TextAreaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement
2
2
  grow?: boolean;
3
3
  onResize?: (el: HTMLTextAreaElement) => void;
4
4
  fill?: boolean;
5
+ textAreaRef?: React.Ref<HTMLTextAreaElement>;
5
6
  }
6
- export declare const TextArea: ({ onResize, grow, value, onChange, disabled, required, rows, fill, ...textAreaProps }: TextAreaProps) => import("react/jsx-runtime").JSX.Element;
7
+ export declare const TextArea: ({ onResize, grow, value, onChange, disabled, required, rows, fill, textAreaRef, ...textAreaProps }: TextAreaProps) => import("react/jsx-runtime").JSX.Element;
7
8
  export {};
@@ -1,8 +1,8 @@
1
1
  export interface UseLoadingProps<T = unknown> {
2
- onClick: (startLoad: () => void, param: T) => Promise<any>;
2
+ onClick: (startLoad: () => void, value: T) => Promise<any>;
3
3
  }
4
4
  export declare const useLoading: <T = unknown>({ onClick }: UseLoadingProps<T>) => {
5
- handleClick: (param: T) => void;
5
+ handleClick: (value: T) => void;
6
6
  isLoading: boolean;
7
7
  isError: boolean;
8
8
  };
@@ -1,36 +1,38 @@
1
1
  import { jsx as f } from "react/jsx-runtime";
2
- import { useResizeTextarea as p } from "./bundle.es38.js";
3
- import { attr as e, callMultiple as x } from "@companix/utils-browser";
4
- import { useEffect as u } from "react";
5
- const R = ({
6
- onResize: s,
2
+ import { useResizeTextarea as x } from "./bundle.es38.js";
3
+ import { attr as e, callMultiple as u } from "@companix/utils-browser";
4
+ import { useEffect as z } from "react";
5
+ import { mergeRefs as R } from "react-merge-refs";
6
+ const q = ({
7
+ onResize: m,
7
8
  grow: a = !1,
8
9
  value: t,
9
- onChange: i,
10
+ onChange: s,
10
11
  disabled: o,
11
- required: m,
12
+ required: i,
12
13
  rows: l = 2,
13
- fill: c = !1,
14
+ fill: p = !1,
15
+ textAreaRef: c,
14
16
  ...d
15
17
  }) => {
16
- const [n, r] = p(s, a);
17
- return u(r, [r, t]), /* @__PURE__ */ f(
18
+ const [n, r] = x(m, a);
19
+ return z(r, [r, t]), /* @__PURE__ */ f(
18
20
  "div",
19
21
  {
20
22
  className: "form form-textarea",
21
- "data-required": e(m),
23
+ "data-required": e(i),
22
24
  "data-disabled": e(o),
23
- "data-fill": e(c),
25
+ "data-fill": e(p),
24
26
  children: /* @__PURE__ */ f(
25
27
  "textarea",
26
28
  {
27
29
  className: "form-input",
28
30
  "data-grow": e(a),
29
31
  value: t,
30
- ref: n,
32
+ ref: R([c, n]),
31
33
  rows: l,
32
34
  disabled: o,
33
- onChange: x(i, r),
35
+ onChange: u(s, r),
34
36
  ...d
35
37
  }
36
38
  )
@@ -38,5 +40,5 @@ const R = ({
38
40
  );
39
41
  };
40
42
  export {
41
- R as TextArea
43
+ q as TextArea
42
44
  };
@@ -1,13 +1,14 @@
1
1
  import { jsx as o, jsxs as c } from "react/jsx-runtime";
2
2
  import { useFroozeClosing as F } from "./bundle.es31.js";
3
- import { Popover as I } from "./bundle.es6.js";
4
- import { OptionItem as L } from "./bundle.es10.js";
5
- import { OptionsList as M } from "./bundle.es12.js";
6
- import { useState as j, useRef as d, useMemo as h } from "react";
3
+ import { Popover as L } from "./bundle.es6.js";
4
+ import { OptionItem as M } from "./bundle.es10.js";
5
+ import { OptionsList as j } from "./bundle.es12.js";
6
+ import { useState as V, useRef as d, useMemo as h } from "react";
7
7
  import { Icon as g } from "./bundle.es35.js";
8
- import { faClose as V, faChevronDown as B } from "@fortawesome/free-solid-svg-icons";
9
- import { attr as H, getActiveElementByAnotherElement as Q, contains as q } from "@companix/utils-browser";
10
- const ee = (v) => {
8
+ import { faClose as B, faChevronDown as H } from "@fortawesome/free-solid-svg-icons";
9
+ import { attr as Q, getActiveElementByAnotherElement as q, contains as G } from "@companix/utils-browser";
10
+ import { mergeRefs as J } from "react-merge-refs";
11
+ const ne = (v) => {
11
12
  const {
12
13
  options: r,
13
14
  closeAfterSelect: x,
@@ -15,46 +16,47 @@ const ee = (v) => {
15
16
  onChange: l,
16
17
  emptyText: N = "Ничего не найдено",
17
18
  readOnly: m,
18
- size: z = "md",
19
+ size: R = "md",
19
20
  value: n,
21
+ inputRef: z,
20
22
  disabled: f
21
- } = v, [a, A] = j(""), i = d(null), y = d(null), { popoverRef: u, froozePopoverPosition: D, handleAnimationEnd: R } = F(), b = h(() => {
23
+ } = v, [i, A] = V(""), a = d(null), y = d(null), { popoverRef: u, froozePopoverPosition: D, handleAnimationEnd: b } = F(), w = h(() => {
22
24
  const e = {};
23
25
  return r.forEach((t) => {
24
26
  e[t.value] = t;
25
27
  }), e;
26
- }, [r]), w = (e) => n.includes(e) ? [...n] : [...n, e], E = (e) => n.filter((t) => e !== t), O = (e, t) => {
28
+ }, [r]), E = (e) => n.includes(e) ? [...n] : [...n, e], O = (e) => n.filter((t) => e !== t), P = (e, t) => {
27
29
  x ? (D(), l(e), t()) : l(e);
28
- }, p = h(() => a.trim() ? r.filter(({ title: e }) => {
29
- const t = e.toLowerCase(), s = a.trim().toLowerCase();
30
+ }, p = h(() => i.trim() ? r.filter(({ title: e }) => {
31
+ const t = e.toLowerCase(), s = i.trim().toLowerCase();
30
32
  return t.indexOf(s) >= 0;
31
- }) : r, [a, r]), P = (e) => {
33
+ }) : r, [i, r]), T = (e) => {
32
34
  if (f) return;
33
35
  u.current && u.current.getAttribute("data-state") === "open" && e.preventDefault();
34
- const t = Q(e.currentTarget);
35
- e.defaultPrevented || q(e.currentTarget, t) || i.current && i.current.focus();
36
- }, T = (e) => {
37
- e.target !== i.current && e.preventDefault();
38
- }, k = (e, t) => {
39
- e.stopPropagation(), l(E(t));
36
+ const t = q(e.currentTarget);
37
+ e.defaultPrevented || G(e.currentTarget, t) || a.current && a.current.focus();
38
+ }, k = (e) => {
39
+ e.target !== a.current && e.preventDefault();
40
+ }, I = (e, t) => {
41
+ e.stopPropagation(), l(O(t));
40
42
  };
41
43
  return /* @__PURE__ */ o(
42
- I,
44
+ L,
43
45
  {
44
46
  minimal: !0,
45
47
  ref: u,
46
48
  sideOffset: 0,
47
49
  matchTarget: "width",
48
- onAnimationEnd: R,
50
+ onAnimationEnd: b,
49
51
  onOpenAutoFocus: (e) => e.preventDefault(),
50
52
  onCloseAutoFocus: (e) => e.preventDefault(),
51
- content: ({ close: e }) => /* @__PURE__ */ c(M, { maxHeight: 300, children: [
53
+ content: ({ close: e }) => /* @__PURE__ */ c(j, { maxHeight: 300, children: [
52
54
  p.length === 0 && /* @__PURE__ */ o("div", { className: "select-tags-empty", children: N }),
53
55
  p.map(({ value: t, title: s, icon: S }, $) => /* @__PURE__ */ o(
54
- L,
56
+ M,
55
57
  {
56
58
  active: n.includes(t),
57
- onClick: () => O(w(t), e),
59
+ onClick: () => P(E(t), e),
58
60
  title: s,
59
61
  icon: S
60
62
  },
@@ -65,9 +67,9 @@ const ee = (v) => {
65
67
  "div",
66
68
  {
67
69
  className: "form",
68
- onClick: P,
69
- onMouseDown: T,
70
- "data-size": z,
70
+ onClick: T,
71
+ onMouseDown: k,
72
+ "data-size": R,
71
73
  children: /* @__PURE__ */ c("div", { className: "select-tags-container", children: [
72
74
  /* @__PURE__ */ c("div", { className: "select-tags", children: [
73
75
  n.length > 0 && /* @__PURE__ */ o(
@@ -76,24 +78,24 @@ const ee = (v) => {
76
78
  className: "tag-container",
77
79
  ref: y,
78
80
  role: "listbox",
79
- "data-readonly": H(m),
81
+ "data-readonly": Q(m),
80
82
  children: n.map((e, t) => /* @__PURE__ */ c("div", { className: "tag", children: [
81
- /* @__PURE__ */ o("span", { className: "tag-name", children: b[e].title }),
82
- /* @__PURE__ */ o("button", { className: "tag-close-button", onClick: (s) => k(s, e), children: /* @__PURE__ */ o(g, { className: "tag-close-icon", icon: V, size: "xxxs" }) })
83
+ /* @__PURE__ */ o("span", { className: "tag-name", children: w[e].title }),
84
+ /* @__PURE__ */ o("button", { className: "tag-close-button", onClick: (s) => I(s, e), children: /* @__PURE__ */ o(g, { className: "tag-close-icon", icon: B, size: "xxxs" }) })
83
85
  ] }, `tag-option-${e}-${t}`))
84
86
  }
85
87
  ),
86
88
  (!m || n.length === 0) && /* @__PURE__ */ o(
87
89
  "input",
88
90
  {
89
- ref: i,
91
+ ref: J([z, a]),
90
92
  type: "text",
91
93
  autoCapitalize: "none",
92
94
  autoComplete: "off",
93
95
  autoCorrect: "off",
94
96
  className: "form-input",
95
97
  spellCheck: !1,
96
- value: a,
98
+ value: i,
97
99
  disabled: f,
98
100
  readOnly: m,
99
101
  placeholder: C,
@@ -101,7 +103,7 @@ const ee = (v) => {
101
103
  }
102
104
  )
103
105
  ] }),
104
- /* @__PURE__ */ o(g, { className: "expand-icon", icon: B, size: "xxxs" })
106
+ /* @__PURE__ */ o(g, { className: "expand-icon", icon: H, size: "xxxs" })
105
107
  ] })
106
108
  }
107
109
  )
@@ -109,5 +111,5 @@ const ee = (v) => {
109
111
  );
110
112
  };
111
113
  export {
112
- ee as SelectTags
114
+ ne as SelectTags
113
115
  };
@@ -1,53 +1,55 @@
1
1
  import { jsxs as n, jsx as c } from "react/jsx-runtime";
2
- import b from "classnames";
2
+ import R from "classnames";
3
3
  import { attr as r } from "@companix/utils-browser";
4
- import { forwardRef as g, useRef as w, useCallback as y } from "react";
4
+ import { forwardRef as b, useRef as w, useCallback as y } from "react";
5
5
  import { Icon as a } from "./bundle.es35.js";
6
- import { faClose as D, faChevronDown as R } from "@fortawesome/free-solid-svg-icons";
7
- import { VisuallyHidden as T } from "@radix-ui/react-visually-hidden";
8
- const V = g(
6
+ import { faClose as D, faChevronDown as T } from "@fortawesome/free-solid-svg-icons";
7
+ import { VisuallyHidden as j } from "@radix-ui/react-visually-hidden";
8
+ import { mergeRefs as O } from "react-merge-refs";
9
+ const J = b(
9
10
  ({
10
11
  required: u,
11
12
  size: d,
12
13
  fill: m,
13
14
  leftElement: l,
14
- className: p,
15
+ className: f,
15
16
  value: o,
16
- clearButton: f,
17
+ clearButton: p,
17
18
  placeholder: C,
18
19
  clearButtonIcon: h,
19
20
  disabled: s,
20
21
  onClear: I,
22
+ inputRef: N,
21
23
  ...i
22
- }, N) => {
23
- const e = w(null), k = y(
24
+ }, k) => {
25
+ const e = w(null), x = y(
24
26
  (t) => {
25
27
  if (!e.current || !document)
26
28
  return;
27
29
  t.target !== e.current && (e.current.click(), document.activeElement !== e.current && e.current.focus());
28
30
  },
29
31
  [e]
30
- ), x = (t) => {
32
+ ), v = (t) => {
31
33
  document && document.activeElement === e.current && t.preventDefault();
32
- }, v = (t) => {
33
- s || k(t);
34
34
  }, F = (t) => {
35
- x(t);
35
+ s || x(t);
36
+ }, g = (t) => {
37
+ v(t);
36
38
  }, z = (t) => {
37
39
  e.current && e.current.focus(), I?.(t);
38
40
  };
39
41
  return /* @__PURE__ */ n(
40
42
  "div",
41
43
  {
42
- ref: N,
43
- className: b("form select", p),
44
+ ref: k,
45
+ className: R("form select", f),
44
46
  "data-size": d ?? "md",
45
47
  "data-fill": r(m),
46
48
  "data-required": r(u),
47
49
  "data-disabled": r(s),
48
- onMouseDown: F,
50
+ onMouseDown: g,
49
51
  ...i,
50
- onClick: v,
52
+ onClick: F,
51
53
  children: [
52
54
  /* @__PURE__ */ n("div", { className: "select-layout form-input", children: [
53
55
  l && /* @__PURE__ */ c("div", { className: "select-element", children: l }),
@@ -56,14 +58,14 @@ const V = g(
56
58
  o
57
59
  ] }) }),
58
60
  /* @__PURE__ */ n("div", { className: "select-element", children: [
59
- f && o && /* @__PURE__ */ c("button", { className: "select-close-button", onClick: z, children: h ?? /* @__PURE__ */ c(a, { className: "select-close-icon", icon: D, size: "xxxs" }) }),
60
- /* @__PURE__ */ c(a, { className: "expand-icon select-expand", icon: R, size: "xxxs" })
61
+ p && o && /* @__PURE__ */ c("button", { className: "select-close-button", onClick: z, children: h ?? /* @__PURE__ */ c(a, { className: "select-close-icon", icon: D, size: "xxxs" }) }),
62
+ /* @__PURE__ */ c(a, { className: "expand-icon select-expand", icon: T, size: "xxxs" })
61
63
  ] })
62
64
  ] }),
63
- /* @__PURE__ */ c(T, { asChild: !0, children: /* @__PURE__ */ c(
65
+ /* @__PURE__ */ c(j, { asChild: !0, children: /* @__PURE__ */ c(
64
66
  "input",
65
67
  {
66
- ref: e,
68
+ ref: O([N, e]),
67
69
  autoComplete: "off",
68
70
  autoCapitalize: "none",
69
71
  autoCorrect: "off",
@@ -79,5 +81,5 @@ const V = g(
79
81
  }
80
82
  );
81
83
  export {
82
- V as SelectInput
84
+ J as SelectInput
83
85
  };
@@ -1,23 +1,16 @@
1
- import { useState as a } from "react";
2
- const l = ({ onClick: i }) => {
3
- const [e, s] = a({ isLoading: !1, isError: !1 });
4
- return {
5
- ...e,
6
- handleClick: (o) => {
7
- e.isLoading || i(() => s({ isLoading: !0, isError: !1 }), o).then(() => {
8
- s({
9
- isLoading: !1,
10
- isError: !1
11
- });
12
- }).catch((r) => {
13
- console.log(r), s({
14
- isLoading: !1,
15
- isError: !0
16
- });
17
- });
18
- }
19
- };
1
+ import { useState as e } from "react";
2
+ const d = ({ onClick: t }) => {
3
+ const [a, s] = e({ isLoading: !1, isError: !1 });
4
+ return { ...a, handleClick: (r) => {
5
+ a.isLoading || t(() => {
6
+ s({ isLoading: !0, isError: !1 });
7
+ }, r).then(() => {
8
+ s({ isLoading: !1, isError: !1 });
9
+ }).catch(() => {
10
+ s({ isLoading: !1, isError: !0 });
11
+ });
12
+ } };
20
13
  };
21
14
  export {
22
- l as useLoading
15
+ d as useLoading
23
16
  };
@@ -1,7 +1,7 @@
1
1
  import { jsxs as D, jsx as t } from "react/jsx-runtime";
2
- import { dateToFormat as $, weeks as g, createVoids as p, getDayIndex as b, getFirstDay as u, getMonthMaxDay as k } from "./bundle.es44.js";
3
- import { CalendarHeader as F } from "./bundle.es45.js";
4
- import { useCalendar as j } from "./bundle.es46.js";
2
+ import { dateToFormat as $, weeks as g, createVoids as p, getDayIndex as b, getFirstDay as u, getMonthMaxDay as k } from "./bundle.es43.js";
3
+ import { CalendarHeader as F } from "./bundle.es44.js";
4
+ import { useCalendar as j } from "./bundle.es45.js";
5
5
  import { attr as m } from "@companix/utils-browser";
6
6
  import { isSameDate as f } from "./bundle.es40.js";
7
7
  import { useLayoutEffect as I } from "react";
@@ -2,7 +2,7 @@ import { jsxs as T, jsx as $ } from "react/jsx-runtime";
2
2
  import { forwardRef as b, useState as I, useMemo as P, useImperativeHandle as R, useCallback as j, createElement as k } from "react";
3
3
  import * as c from "@radix-ui/react-toast";
4
4
  import { varToStyle as w } from "@companix/utils-browser";
5
- import { Toast as C } from "./bundle.es43.js";
5
+ import { Toast as C } from "./bundle.es46.js";
6
6
  var g = /* @__PURE__ */ ((e) => (e["top-center"] = "up", e["top-left"] = "left", e["top-right"] = "right", e["bottom-center"] = "down", e["bottom-left"] = "left", e["bottom-right"] = "right", e))(g || {});
7
7
  const M = b((e, h) => {
8
8
  const { side: f = "top", align: i = "center", gap: m = 14, duration: u, swipeThreshold: v, closeIcon: x } = e, [l, p] = I([]), o = P(() => ({}), []);
@@ -1,45 +1,33 @@
1
- import { jsxs as n, jsx as e } from "react/jsx-runtime";
2
- import * as t from "@radix-ui/react-toast";
3
- import { attr as C } from "@companix/utils-browser";
4
- import { useState as h, useRef as v, useEffect as N, useLayoutEffect as x } from "react";
5
- import { RemoveListener as R } from "./bundle.es36.js";
6
- const E = (i) => {
7
- const [c, l] = h(!1), o = v(null), {
8
- appearance: d = "neutral",
9
- icon: r,
10
- title: a,
11
- description: s,
12
- duration: m,
13
- closeIcon: u,
14
- onRemoving: p,
15
- onRemoved: f,
16
- onInitialized: L
17
- } = i;
18
- return N(() => {
19
- l(!0);
20
- }, []), x(() => {
21
- o.current && L(o.current);
22
- }, []), /* @__PURE__ */ n(
23
- t.Root,
24
- {
25
- ref: o,
26
- "data-expanded": !0,
27
- "data-appearance": d,
28
- "data-mounted": C(c),
29
- className: "toaster",
30
- duration: m,
31
- children: [
32
- /* @__PURE__ */ e(R, { callback: f }),
33
- r && /* @__PURE__ */ e("div", { className: "toaster-icon", children: r }),
34
- /* @__PURE__ */ n("div", { className: "toaster-content", children: [
35
- a && /* @__PURE__ */ e(t.Title, { className: "toaster-title", children: a }),
36
- s && /* @__PURE__ */ e(t.Description, { className: "toaster-description", children: s })
37
- ] }),
38
- /* @__PURE__ */ e(t.Close, { className: "toaster-close", onClick: p, children: u ?? /* @__PURE__ */ e("svg", { viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M2.96967 2.96967C3.26256 2.67678 3.73744 2.67678 4.03033 2.96967L8 6.939L11.9697 2.96967C12.2626 2.67678 12.7374 2.67678 13.0303 2.96967C13.3232 3.26256 13.3232 3.73744 13.0303 4.03033L9.061 8L13.0303 11.9697C13.2966 12.2359 13.3208 12.6526 13.1029 12.9462L13.0303 13.0303C12.7374 13.3232 12.2626 13.3232 11.9697 13.0303L8 9.061L4.03033 13.0303C3.73744 13.3232 3.26256 13.3232 2.96967 13.0303C2.67678 12.7374 2.67678 12.2626 2.96967 11.9697L6.939 8L2.96967 4.03033C2.7034 3.76406 2.6792 3.3474 2.89705 3.05379L2.96967 2.96967Z" }) }) })
39
- ]
40
- }
41
- );
1
+ import { clamp as a } from "@companix/utils-browser";
2
+ const D = (t, e) => new Date(e, t, 0).getDate(), g = (t, e) => new Date(e, t - 1, 1).getDay(), i = (t) => t === 0 ? 6 : t - 1, u = (t) => new Array(t).fill(0), h = (t) => ({
3
+ day: t.getDate(),
4
+ month: t.getMonth() + 1,
5
+ year: t.getFullYear()
6
+ }), y = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"], s = 9999, c = 100, f = (t, e) => {
7
+ const o = [], n = a(t - e, c, s), l = a(t + e, c, s);
8
+ for (let r = n; r <= l; r++)
9
+ o.push({ title: String(r).padStart(4, "0"), value: r });
10
+ return o;
11
+ }, p = (t) => {
12
+ const e = [], o = new Intl.DateTimeFormat(t, {
13
+ month: "long"
14
+ });
15
+ for (let n = 0; n < 12; n++)
16
+ e.push({
17
+ title: o.format(new Date(2023, n, 15)),
18
+ value: n
19
+ });
20
+ return e;
42
21
  };
43
22
  export {
44
- E as Toast
23
+ s as DEFAULT_MAX_YEAR,
24
+ c as DEFAULT_MIN_YEAR,
25
+ u as createVoids,
26
+ h as dateToFormat,
27
+ i as getDayIndex,
28
+ g as getFirstDay,
29
+ D as getMonthMaxDay,
30
+ p as getMonths,
31
+ f as getYears,
32
+ y as weeks
45
33
  };
@@ -1,33 +1,77 @@
1
- import { clamp as a } from "@companix/utils-browser";
2
- const D = (t, e) => new Date(e, t, 0).getDate(), g = (t, e) => new Date(e, t - 1, 1).getDay(), i = (t) => t === 0 ? 6 : t - 1, u = (t) => new Array(t).fill(0), h = (t) => ({
3
- day: t.getDate(),
4
- month: t.getMonth() + 1,
5
- year: t.getFullYear()
6
- }), y = ["Пн", "Вт", "Ср", "Чт", "Пт", "Сб", "Вс"], s = 9999, c = 100, f = (t, e) => {
7
- const o = [], n = a(t - e, c, s), l = a(t + e, c, s);
8
- for (let r = n; r <= l; r++)
9
- o.push({ title: String(r).padStart(4, "0"), value: r });
10
- return o;
11
- }, p = (t) => {
12
- const e = [], o = new Intl.DateTimeFormat(t, {
13
- month: "long"
14
- });
15
- for (let n = 0; n < 12; n++)
16
- e.push({
17
- title: o.format(new Date(2023, n, 15)),
18
- value: n
19
- });
20
- return e;
1
+ import { jsxs as d, jsx as o } from "react/jsx-runtime";
2
+ import { useCallback as u, useMemo as h } from "react";
3
+ import { Select as p } from "./bundle.es8.js";
4
+ import { getMonths as k, getYears as z, DEFAULT_MAX_YEAR as f, DEFAULT_MIN_YEAR as g } from "./bundle.es43.js";
5
+ import { Icon as C } from "./bundle.es35.js";
6
+ import { faChevronLeft as E, faChevronRight as T } from "@fortawesome/free-solid-svg-icons";
7
+ import { setMonth as _, setYear as F } from "./bundle.es40.js";
8
+ const y = ({
9
+ viewDate: n,
10
+ onChange: c,
11
+ isMonthDisabled: a,
12
+ isYearDisabled: m,
13
+ onNextMonth: N,
14
+ onPrevMonth: v
15
+ }) => {
16
+ const e = n.getFullYear(), r = n.getMonth(), s = "ru", M = u(
17
+ (t) => {
18
+ c(_(n, t));
19
+ },
20
+ [c, n]
21
+ ), x = u(
22
+ (t) => {
23
+ c(F(n, t));
24
+ },
25
+ [c, n]
26
+ ), A = h(() => k(s).map((t) => ({
27
+ ...t,
28
+ className: "capitalize",
29
+ disabled: a && a(t.value)
30
+ })), [s, a]), Y = h(() => z(e, 100).map((t) => ({
31
+ ...t,
32
+ disabled: m && m(t.value)
33
+ })), [e, m]);
34
+ let l = r === 11 && e === f;
35
+ a && !l && (l = a(
36
+ r === 11 ? 0 : r + 1,
37
+ r === 11 ? Math.min(e + 1, f) : e
38
+ ));
39
+ let i = r === 0 && e === g;
40
+ return a && !i && (i = a(
41
+ r === 0 ? 11 : r - 1,
42
+ r === 0 ? Math.max(e - 1, g) : e
43
+ )), /* @__PURE__ */ d("div", { className: "calendar-header", children: [
44
+ !i && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "left", onClick: v, children: /* @__PURE__ */ o(C, { icon: E }) }),
45
+ /* @__PURE__ */ d("div", { className: "calendar-pickers", children: [
46
+ /* @__PURE__ */ o(
47
+ p,
48
+ {
49
+ fill: !0,
50
+ options: Y,
51
+ size: "sm",
52
+ value: e,
53
+ minimalOptions: !0,
54
+ matchTarget: "min-width",
55
+ onChange: (t) => x(t || 0)
56
+ }
57
+ ),
58
+ /* @__PURE__ */ o(
59
+ p,
60
+ {
61
+ fill: !0,
62
+ options: A,
63
+ size: "sm",
64
+ className: "capitalize",
65
+ value: r,
66
+ minimalOptions: !0,
67
+ matchTarget: "min-width",
68
+ onChange: (t) => M(t || 0)
69
+ }
70
+ )
71
+ ] }),
72
+ !l && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "right", onClick: N, children: /* @__PURE__ */ o(C, { icon: T }) })
73
+ ] });
21
74
  };
22
75
  export {
23
- s as DEFAULT_MAX_YEAR,
24
- c as DEFAULT_MIN_YEAR,
25
- u as createVoids,
26
- h as dateToFormat,
27
- i as getDayIndex,
28
- g as getFirstDay,
29
- D as getMonthMaxDay,
30
- p as getMonths,
31
- f as getYears,
32
- y as weeks
76
+ y as CalendarHeader
33
77
  };
@@ -1,77 +1,51 @@
1
- import { jsxs as d, jsx as o } from "react/jsx-runtime";
2
- import { useCallback as u, useMemo as h } from "react";
3
- import { Select as p } from "./bundle.es8.js";
4
- import { getMonths as k, getYears as z, DEFAULT_MAX_YEAR as f, DEFAULT_MIN_YEAR as g } from "./bundle.es44.js";
5
- import { Icon as C } from "./bundle.es35.js";
6
- import { faChevronLeft as E, faChevronRight as T } from "@fortawesome/free-solid-svg-icons";
7
- import { setMonth as _, setYear as F } from "./bundle.es40.js";
8
- const y = ({
9
- viewDate: n,
10
- onChange: c,
11
- isMonthDisabled: a,
12
- isYearDisabled: m,
13
- onNextMonth: N,
14
- onPrevMonth: v
1
+ import { subMonths as L, addMonths as N, useDayDisableCheker as R } from "./bundle.es40.js";
2
+ import { DEFAULT_MIN_YEAR as w, DEFAULT_MAX_YEAR as A } from "./bundle.es43.js";
3
+ import { useState as U, useCallback as M } from "react";
4
+ const X = ({
5
+ value: p,
6
+ disablePast: r,
7
+ disableFuture: c,
8
+ shouldDisableDate: E,
9
+ minDateTime: l,
10
+ maxDateTime: s
15
11
  }) => {
16
- const e = n.getFullYear(), r = n.getMonth(), s = "ru", M = u(
17
- (t) => {
18
- c(_(n, t));
12
+ const [e, u] = U(p || /* @__PURE__ */ new Date()), _ = M(() => {
13
+ u(L(e));
14
+ }, [e]), C = M(() => {
15
+ u(N(e, 1));
16
+ }, [e]), D = R({
17
+ disableFuture: c,
18
+ disablePast: r,
19
+ shouldDisableDate: E,
20
+ minDateTime: l,
21
+ maxDateTime: s
22
+ }), k = M(
23
+ (o, t) => {
24
+ const n = /* @__PURE__ */ new Date();
25
+ t = t || e.getFullYear();
26
+ const h = l ? l.getMonth() : 0, Y = s ? s.getMonth() : 11, F = l?.getFullYear() || w, f = s?.getFullYear() || A;
27
+ let g = t >= F && t <= f ? t === F && h > o || t === f && o > Y : !0;
28
+ return c && (g = g || (t === n.getFullYear() ? o > n.getMonth() : t > n.getFullYear())), r && (g = g || (t === n.getFullYear() ? o < n.getMonth() : t < n.getFullYear())), g;
19
29
  },
20
- [c, n]
21
- ), x = u(
22
- (t) => {
23
- c(F(n, t));
30
+ [c, r, e, l, s]
31
+ ), v = M(
32
+ (o) => {
33
+ const t = /* @__PURE__ */ new Date(), n = l?.getFullYear() || w, h = s?.getFullYear() || A;
34
+ let Y = n > o || o > h;
35
+ return c && (Y = Y || o > t.getFullYear()), r && (Y = Y || o < t.getFullYear()), Y;
24
36
  },
25
- [c, n]
26
- ), A = h(() => k(s).map((t) => ({
27
- ...t,
28
- className: "capitalize",
29
- disabled: a && a(t.value)
30
- })), [s, a]), Y = h(() => z(e, 100).map((t) => ({
31
- ...t,
32
- disabled: m && m(t.value)
33
- })), [e, m]);
34
- let l = r === 11 && e === f;
35
- a && !l && (l = a(
36
- r === 11 ? 0 : r + 1,
37
- r === 11 ? Math.min(e + 1, f) : e
38
- ));
39
- let i = r === 0 && e === g;
40
- return a && !i && (i = a(
41
- r === 0 ? 11 : r - 1,
42
- r === 0 ? Math.max(e - 1, g) : e
43
- )), /* @__PURE__ */ d("div", { className: "calendar-header", children: [
44
- !i && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "left", onClick: v, children: /* @__PURE__ */ o(C, { icon: E }) }),
45
- /* @__PURE__ */ d("div", { className: "calendar-pickers", children: [
46
- /* @__PURE__ */ o(
47
- p,
48
- {
49
- fill: !0,
50
- options: Y,
51
- size: "sm",
52
- value: e,
53
- minimalOptions: !0,
54
- matchTarget: "min-width",
55
- onChange: (t) => x(t || 0)
56
- }
57
- ),
58
- /* @__PURE__ */ o(
59
- p,
60
- {
61
- fill: !0,
62
- options: A,
63
- size: "sm",
64
- className: "capitalize",
65
- value: r,
66
- minimalOptions: !0,
67
- matchTarget: "min-width",
68
- onChange: (t) => M(t || 0)
69
- }
70
- )
71
- ] }),
72
- !l && /* @__PURE__ */ o("button", { className: "calendar-navigation", "data-side": "right", onClick: N, children: /* @__PURE__ */ o(C, { icon: T }) })
73
- ] });
37
+ [c, r, l, s]
38
+ );
39
+ return {
40
+ viewDate: e,
41
+ setViewDate: u,
42
+ setPrevMonth: _,
43
+ setNextMonth: C,
44
+ isDayDisabled: D,
45
+ isMonthDisabled: k,
46
+ isYearDisabled: v
47
+ };
74
48
  };
75
49
  export {
76
- y as CalendarHeader
50
+ X as useCalendar
77
51
  };
@@ -1,51 +1,45 @@
1
- import { subMonths as L, addMonths as N, useDayDisableCheker as R } from "./bundle.es40.js";
2
- import { DEFAULT_MIN_YEAR as w, DEFAULT_MAX_YEAR as A } from "./bundle.es44.js";
3
- import { useState as U, useCallback as M } from "react";
4
- const X = ({
5
- value: p,
6
- disablePast: r,
7
- disableFuture: c,
8
- shouldDisableDate: E,
9
- minDateTime: l,
10
- maxDateTime: s
11
- }) => {
12
- const [e, u] = U(p || /* @__PURE__ */ new Date()), _ = M(() => {
13
- u(L(e));
14
- }, [e]), C = M(() => {
15
- u(N(e, 1));
16
- }, [e]), D = R({
17
- disableFuture: c,
18
- disablePast: r,
19
- shouldDisableDate: E,
20
- minDateTime: l,
21
- maxDateTime: s
22
- }), k = M(
23
- (o, t) => {
24
- const n = /* @__PURE__ */ new Date();
25
- t = t || e.getFullYear();
26
- const h = l ? l.getMonth() : 0, Y = s ? s.getMonth() : 11, F = l?.getFullYear() || w, f = s?.getFullYear() || A;
27
- let g = t >= F && t <= f ? t === F && h > o || t === f && o > Y : !0;
28
- return c && (g = g || (t === n.getFullYear() ? o > n.getMonth() : t > n.getFullYear())), r && (g = g || (t === n.getFullYear() ? o < n.getMonth() : t < n.getFullYear())), g;
29
- },
30
- [c, r, e, l, s]
31
- ), v = M(
32
- (o) => {
33
- const t = /* @__PURE__ */ new Date(), n = l?.getFullYear() || w, h = s?.getFullYear() || A;
34
- let Y = n > o || o > h;
35
- return c && (Y = Y || o > t.getFullYear()), r && (Y = Y || o < t.getFullYear()), Y;
36
- },
37
- [c, r, l, s]
1
+ import { jsxs as n, jsx as e } from "react/jsx-runtime";
2
+ import * as t from "@radix-ui/react-toast";
3
+ import { attr as C } from "@companix/utils-browser";
4
+ import { useState as h, useRef as v, useEffect as N, useLayoutEffect as x } from "react";
5
+ import { RemoveListener as R } from "./bundle.es36.js";
6
+ const E = (i) => {
7
+ const [c, l] = h(!1), o = v(null), {
8
+ appearance: d = "neutral",
9
+ icon: r,
10
+ title: a,
11
+ description: s,
12
+ duration: m,
13
+ closeIcon: u,
14
+ onRemoving: p,
15
+ onRemoved: f,
16
+ onInitialized: L
17
+ } = i;
18
+ return N(() => {
19
+ l(!0);
20
+ }, []), x(() => {
21
+ o.current && L(o.current);
22
+ }, []), /* @__PURE__ */ n(
23
+ t.Root,
24
+ {
25
+ ref: o,
26
+ "data-expanded": !0,
27
+ "data-appearance": d,
28
+ "data-mounted": C(c),
29
+ className: "toaster",
30
+ duration: m,
31
+ children: [
32
+ /* @__PURE__ */ e(R, { callback: f }),
33
+ r && /* @__PURE__ */ e("div", { className: "toaster-icon", children: r }),
34
+ /* @__PURE__ */ n("div", { className: "toaster-content", children: [
35
+ a && /* @__PURE__ */ e(t.Title, { className: "toaster-title", children: a }),
36
+ s && /* @__PURE__ */ e(t.Description, { className: "toaster-description", children: s })
37
+ ] }),
38
+ /* @__PURE__ */ e(t.Close, { className: "toaster-close", onClick: p, children: u ?? /* @__PURE__ */ e("svg", { viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ e("path", { d: "M2.96967 2.96967C3.26256 2.67678 3.73744 2.67678 4.03033 2.96967L8 6.939L11.9697 2.96967C12.2626 2.67678 12.7374 2.67678 13.0303 2.96967C13.3232 3.26256 13.3232 3.73744 13.0303 4.03033L9.061 8L13.0303 11.9697C13.2966 12.2359 13.3208 12.6526 13.1029 12.9462L13.0303 13.0303C12.7374 13.3232 12.2626 13.3232 11.9697 13.0303L8 9.061L4.03033 13.0303C3.73744 13.3232 3.26256 13.3232 2.96967 13.0303C2.67678 12.7374 2.67678 12.2626 2.96967 11.9697L6.939 8L2.96967 4.03033C2.7034 3.76406 2.6792 3.3474 2.89705 3.05379L2.96967 2.96967Z" }) }) })
39
+ ]
40
+ }
38
41
  );
39
- return {
40
- viewDate: e,
41
- setViewDate: u,
42
- setPrevMonth: _,
43
- setNextMonth: C,
44
- isDayDisabled: D,
45
- isMonthDisabled: k,
46
- isYearDisabled: v
47
- };
48
42
  };
49
43
  export {
50
- X as useCalendar
44
+ E as Toast
51
45
  };
@@ -1,87 +1,83 @@
1
- import { jsx as r } from "react/jsx-runtime";
2
- import { useMemo as E, useEffect as I } from "react";
3
- import { OptionsList as b } from "./bundle.es12.js";
4
- import { OptionItem as B } from "./bundle.es10.js";
1
+ import { jsx as i } from "react/jsx-runtime";
2
+ import { useMemo as S, useEffect as A } from "react";
3
+ import { OptionsList as E } from "./bundle.es12.js";
4
+ import { OptionItem as b } from "./bundle.es10.js";
5
5
  import { Popover as F } from "./bundle.es6.js";
6
- import { useFroozeClosing as z } from "./bundle.es31.js";
7
- import { SelectInput as D } from "./bundle.es32.js";
8
- import { useScrollListController as L } from "./bundle.es33.js";
9
- const y = (c) => {
6
+ import { useFroozeClosing as I } from "./bundle.es31.js";
7
+ import { SelectInput as z } from "./bundle.es32.js";
8
+ import { useScrollListController as D } from "./bundle.es33.js";
9
+ const M = (c) => {
10
10
  const {
11
11
  options: e,
12
- onChange: i,
12
+ onChange: l,
13
+ value: s,
13
14
  minimalOptions: a,
14
- clearButton: m,
15
- clearButtonIcon: u,
16
- matchTarget: f = "width",
17
- value: l,
18
- children: n,
19
- disabled: s,
20
- ...d
21
- } = c, p = E(() => {
22
- const o = e.findIndex((t) => t.value === l);
15
+ matchTarget: m = "width",
16
+ children: u,
17
+ disabled: p,
18
+ ...n
19
+ } = c, t = S(() => {
20
+ const o = e.findIndex((r) => r.value === s);
23
21
  return {
24
22
  index: o,
25
23
  option: e[o]
26
24
  };
27
- }, [e, l]), v = p.option?.value ?? null, { popoverRef: h, froozePopoverPosition: x, handleAnimationEnd: O } = z(), { scrollToElement: C, optionsWrapperRef: g, scrollBoxRef: P } = L(), R = (o, t) => {
28
- x(), i(o), t();
29
- }, S = (o) => {
30
- o.stopPropagation(), i(null);
31
- }, A = () => {
32
- p.index !== -1 && C(p.index, !0);
25
+ }, [e, s]), f = t.option?.value ?? null, { popoverRef: d, froozePopoverPosition: v, handleAnimationEnd: h } = I(), { scrollToElement: x, optionsWrapperRef: O, scrollBoxRef: C } = D(), g = (o, r) => {
26
+ v(), l(o), r();
27
+ }, P = (o) => {
28
+ o.stopPropagation(), l(null);
29
+ }, R = () => {
30
+ t.index !== -1 && x(t.index, !0);
33
31
  };
34
- return /* @__PURE__ */ r(
32
+ return /* @__PURE__ */ i(
35
33
  F,
36
34
  {
37
35
  minimal: !0,
38
- ref: h,
36
+ ref: d,
39
37
  sideOffset: 0,
40
- matchTarget: f,
41
- onAnimationEnd: O,
38
+ matchTarget: m,
39
+ onAnimationEnd: h,
42
40
  onOpenAutoFocus: (o) => o.preventDefault(),
43
41
  onCloseAutoFocus: (o) => o.preventDefault(),
44
- disabled: s,
45
- content: ({ close: o }) => /* @__PURE__ */ r(
46
- T,
42
+ disabled: p,
43
+ content: ({ close: o }) => /* @__PURE__ */ i(
44
+ L,
47
45
  {
48
46
  options: e,
49
- active: v,
50
- scrollboxRef: P,
51
- optionsWrapperRef: g,
47
+ active: f,
48
+ scrollboxRef: C,
49
+ optionsWrapperRef: O,
52
50
  minimalOptions: a,
53
- onOpened: A,
54
- onSelect: (t) => R(t, o)
51
+ onOpened: R,
52
+ onSelect: (r) => g(r, o)
55
53
  }
56
54
  ),
57
- children: n ?? /* @__PURE__ */ r(
58
- D,
55
+ children: u ?? /* @__PURE__ */ i(
56
+ z,
59
57
  {
60
- ...d,
61
- disabled: s,
62
- value: p.option?.title ?? "",
63
- onClear: S,
64
- clearButton: m,
65
- clearButtonIcon: u
58
+ ...n,
59
+ disabled: p,
60
+ value: t.option?.title ?? "",
61
+ onClear: P
66
62
  }
67
63
  )
68
64
  }
69
65
  );
70
- }, T = (c) => {
71
- const { active: e, onOpened: i, scrollboxRef: a, optionsWrapperRef: m, options: u, onSelect: f, minimalOptions: l } = c;
72
- return I(() => {
73
- i?.();
74
- }, []), /* @__PURE__ */ r(b, { scrollboxRef: a, optionsWrapperRef: m, maxHeight: 300, children: u.map((n, s) => /* @__PURE__ */ r(
75
- B,
66
+ }, L = (c) => {
67
+ const { active: e, onOpened: l, scrollboxRef: s, optionsWrapperRef: a, options: m, onSelect: u, minimalOptions: p } = c;
68
+ return A(() => {
69
+ l?.();
70
+ }, []), /* @__PURE__ */ i(E, { scrollboxRef: s, optionsWrapperRef: a, maxHeight: 300, children: m.map((n, t) => /* @__PURE__ */ i(
71
+ b,
76
72
  {
77
73
  active: e === n.value,
78
- onClick: () => f?.(n.value),
79
- minimal: l,
74
+ onClick: () => u?.(n.value),
75
+ minimal: p,
80
76
  ...n
81
77
  },
82
- `option-item-${n.value}-${s}`
78
+ `option-item-${n.value}-${t}`
83
79
  )) });
84
80
  };
85
81
  export {
86
- y as Select
82
+ M as Select
87
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companix/uikit",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "module": "./dist/bundle.es.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "type": "module",
@@ -8,7 +8,7 @@
8
8
  "dist",
9
9
  "README.md"
10
10
  ],
11
- "author": "Pavel Victorov.",
11
+ "author": "Pavel Victorov",
12
12
  "scripts": {
13
13
  "echo": "echo \"uikit\"",
14
14
  "dev": "vite --config vite.config.ts",