@prokodo/ui 0.0.32 → 0.0.34

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,98 +1,26 @@
1
1
  "use client";
2
2
  var __defProp = Object.defineProperty;
3
3
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
4
- import { jsx, jsxs } from "react/jsx-runtime";
5
- import { useId, useRef, useMemo } from "react";
6
- import { create } from "../../helpers/bem.js";
7
- import { isString } from "../../helpers/validations.js";
8
- import styles from "./Button.module.scss.js";
4
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
9
5
  import { Link } from "../link/Link.js";
10
- import { Icon } from "../icon/Icon.js";
6
+ import { ButtonView } from "./Button.view.js";
11
7
  import { Loading } from "../loading/Loading.js";
12
- const bem = create(styles, "Button");
13
- const mockEvent = {};
14
- const mockKeyDownEvent = {};
15
8
  function ButtonClient(props) {
16
- const {
17
- id,
18
- fullWidth,
19
- color = "primary",
20
- iconProps = {},
21
- loading,
22
- variant = "contained",
23
- className,
24
- contentClassName,
25
- disabled,
26
- redirect,
27
- onClick,
28
- onKeyDown,
29
- ...rest
30
- } = props;
31
- const uniqueId = useId();
32
- const labelRef = useRef(null);
33
- const ariaLabelId = `Button-${uniqueId}`;
34
- const isOutlined = variant === "outlined";
35
- const iconName = iconProps == null ? void 0 : iconProps.name;
36
- const isIconOnly = iconName && !(props == null ? void 0 : props.title);
37
- const iconModifier = useMemo(
38
- () => ({
39
- "icon-only": Boolean(isIconOnly)
40
- }),
41
- [isIconOnly]
42
- );
43
- const renderInnerContent = /* @__PURE__ */ __name(() => /* @__PURE__ */ jsxs("span", { ref: labelRef, "aria-labelledby": ariaLabelId, className: bem("title"), children: [
44
- iconName && /* @__PURE__ */ jsx(Icon, { className: bem("icon", iconModifier), ...iconProps }),
45
- props == null ? void 0 : props.title
46
- ] }), "renderInnerContent");
47
- const renderContent = /* @__PURE__ */ __name(() => Boolean(loading) ? /* @__PURE__ */ jsx(Loading, { size: "xs" }) : renderInnerContent(), "renderContent");
48
- const renderVariant = /* @__PURE__ */ __name(() => isOutlined ? /* @__PURE__ */ jsx("div", { className: bem("content", iconModifier, contentClassName), children: renderContent() }) : renderContent(), "renderVariant");
49
- if (redirect) {
50
- return /* @__PURE__ */ jsx(
51
- Link,
9
+ const { loading, iconProps = {}, ...rest } = props;
10
+ const isIconOnly = typeof (iconProps == null ? void 0 : iconProps.name) === "string" && !props.title;
11
+ const finalIconProps = Boolean(loading) ? { name: void 0 } : iconProps;
12
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
13
+ Boolean(loading) && /* @__PURE__ */ jsx(Loading, { size: "xs" }),
14
+ /* @__PURE__ */ jsx(
15
+ ButtonView,
52
16
  {
53
- disabled,
54
- href: redirect.href,
55
- className: bem(
56
- void 0,
57
- {
58
- "has-fullWidth": Boolean(fullWidth),
59
- [`has-variant-${variant}`]: true,
60
- [`has-bg-${color}`]: variant === "contained",
61
- [`has-text-${color}`]: variant === "text",
62
- "is-disabled": Boolean(disabled),
63
- ...iconModifier
64
- },
65
- className
66
- ),
67
- onClick: /* @__PURE__ */ __name(() => onClick == null ? void 0 : onClick(mockEvent), "onClick"),
68
- onKeyDown: /* @__PURE__ */ __name(() => onKeyDown == null ? void 0 : onKeyDown(mockKeyDownEvent), "onKeyDown"),
69
- children: renderVariant()
17
+ ...rest,
18
+ iconProps: finalIconProps,
19
+ isIconOnly: Boolean(isIconOnly),
20
+ LinkComponent: Link
70
21
  }
71
- );
72
- }
73
- return /* @__PURE__ */ jsx(
74
- "button",
75
- {
76
- ...rest,
77
- color,
78
- disabled: Boolean(disabled) || Boolean(loading),
79
- id: `${ariaLabelId}${isString(id) ? ` ${id}` : ""}`,
80
- tabIndex: redirect !== void 0 || Boolean(disabled) ? -1 : rest.tabIndex,
81
- className: bem(
82
- void 0,
83
- {
84
- "has-fullWidth": Boolean(fullWidth),
85
- [`has-variant-${variant}`]: true,
86
- [`has-bg-${color}`]: variant === "contained",
87
- [`has-text-${color}`]: variant === "text",
88
- "is-disabled": Boolean(disabled),
89
- ...iconModifier
90
- },
91
- className
92
- ),
93
- children: renderVariant()
94
- }
95
- );
22
+ )
23
+ ] });
96
24
  }
97
25
  __name(ButtonClient, "ButtonClient");
98
26
  export {
@@ -1,16 +1,16 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { jsx } from "react/jsx-runtime";
3
+ import { jsx, Fragment } from "react/jsx-runtime";
4
4
  import { Suspense, lazy } from "react";
5
5
  import ButtonServer from "./Button.server.js";
6
6
  const loader = /* @__PURE__ */ __name(() => import("./Button.lazy.js"), "loader");
7
7
  if (typeof window !== "undefined") void loader();
8
8
  const LazyWrapper = typeof window !== "undefined" ? lazy(loader) : null;
9
- function Button({ priority, ...props }) {
9
+ function Button({ priority = false, ...props }) {
10
10
  const interactive = !!props.onClick || !!props.onKeyDown || !!props.redirect;
11
11
  if (!interactive) return /* @__PURE__ */ jsx(ButtonServer, { ...props });
12
- const Child = LazyWrapper ?? ((p) => /* @__PURE__ */ jsx(ButtonServer, { ...p }));
13
- return /* @__PURE__ */ jsx(Suspense, { fallback: /* @__PURE__ */ jsx(ButtonServer, { ...props }), children: /* @__PURE__ */ jsx(Child, { ...props, priority }) });
12
+ const Fallback = /* @__PURE__ */ jsx("div", { "data-island": "button", children: /* @__PURE__ */ jsx(ButtonServer, { ...props }) });
13
+ return /* @__PURE__ */ jsx(Suspense, { fallback: Fallback, children: LazyWrapper ? /* @__PURE__ */ jsx(LazyWrapper, { ...props, priority }) : /* @__PURE__ */ jsx(Fragment, {}) });
14
14
  }
15
15
  __name(Button, "Button");
16
16
  export {
@@ -5,17 +5,18 @@ import { jsx } from "react/jsx-runtime";
5
5
  import { useHydrationReady } from "../../hooks/useHydrationReady.js";
6
6
  import ButtonClient from "./Button.client.js";
7
7
  import ButtonServer from "./Button.server.js";
8
- function ButtonWrapper(props) {
8
+ function ButtonWrapper({
9
+ priority = false,
10
+ ...props
11
+ }) {
9
12
  const hasInteraction = !!props.onClick || !!props.onKeyDown || !!props.redirect;
10
- const lazy = Boolean(props == null ? void 0 : props.priority) ? false : true;
11
13
  const [visible, ref] = useHydrationReady({
12
- enabled: hasInteraction && lazy,
13
- priority: props.priority
14
+ enabled: hasInteraction && !priority
14
15
  });
15
- if (hasInteraction && (visible || !lazy)) {
16
+ if (hasInteraction && (priority || visible)) {
16
17
  return /* @__PURE__ */ jsx(ButtonClient, { ...props });
17
18
  }
18
- return /* @__PURE__ */ jsx("div", { ref, children: /* @__PURE__ */ jsx(ButtonServer, { ...props }) });
19
+ return /* @__PURE__ */ jsx("div", { ref, "data-island": "button", children: /* @__PURE__ */ jsx(ButtonServer, { ...props }) });
19
20
  }
20
21
  __name(ButtonWrapper, "ButtonWrapper");
21
22
  export {
@@ -1,73 +1,17 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- import { jsx, jsxs } from "react/jsx-runtime";
4
- import { create } from "../../helpers/bem.js";
5
- import styles from "./Button.module.scss.js";
3
+ import { jsx } from "react/jsx-runtime";
6
4
  import { Link } from "../link/Link.js";
7
- import { Icon } from "../icon/Icon.js";
8
- const bem = create(styles, "Button");
9
- function ButtonServer(props) {
10
- const {
11
- fullWidth,
12
- color = "primary",
13
- iconProps = {},
14
- variant = "contained",
15
- className,
16
- contentClassName,
17
- disabled,
18
- redirect
19
- } = props;
20
- const isOutlined = variant === "outlined";
21
- const iconName = iconProps == null ? void 0 : iconProps.name;
22
- const isIconOnly = iconName && !(props == null ? void 0 : props.title);
23
- const iconModifier = {
24
- "icon-only": Boolean(isIconOnly)
25
- };
26
- const renderInnerContent = /* @__PURE__ */ __name(() => /* @__PURE__ */ jsxs("span", { className: bem("title"), children: [
27
- iconName && /* @__PURE__ */ jsx(Icon, { className: bem("icon", iconModifier), ...iconProps }),
28
- props == null ? void 0 : props.title
29
- ] }), "renderInnerContent");
30
- const renderVariant = /* @__PURE__ */ __name(() => isOutlined ? /* @__PURE__ */ jsx("div", { className: bem("content", iconModifier, contentClassName), children: renderInnerContent() }) : renderInnerContent(), "renderVariant");
31
- if (redirect) {
32
- return /* @__PURE__ */ jsx(
33
- Link,
34
- {
35
- disabled,
36
- href: redirect.href,
37
- className: bem(
38
- void 0,
39
- {
40
- "has-fullWidth": Boolean(fullWidth),
41
- [`has-variant-${variant}`]: true,
42
- [`has-bg-${color}`]: variant === "contained",
43
- [`has-text-${color}`]: variant === "text",
44
- "is-disabled": Boolean(disabled),
45
- ...iconModifier
46
- },
47
- className
48
- ),
49
- children: renderVariant()
50
- }
51
- );
52
- }
5
+ import { ButtonView } from "./Button.view.js";
6
+ function ButtonServer(p) {
7
+ var _a;
8
+ const isIconOnly = ((_a = p.iconProps) == null ? void 0 : _a.name) && !("title" in p && p.title);
53
9
  return /* @__PURE__ */ jsx(
54
- "button",
10
+ ButtonView,
55
11
  {
56
- disabled: Boolean(disabled),
57
- type: "button",
58
- className: bem(
59
- void 0,
60
- {
61
- "has-fullWidth": Boolean(fullWidth),
62
- [`has-variant-${variant}`]: true,
63
- [`has-bg-${color}`]: variant === "contained",
64
- [`has-text-${color}`]: variant === "text",
65
- "is-disabled": Boolean(disabled),
66
- ...iconModifier
67
- },
68
- className
69
- ),
70
- children: renderVariant()
12
+ ...p,
13
+ isIconOnly: Boolean(isIconOnly),
14
+ LinkComponent: Link
71
15
  }
72
16
  );
73
17
  }
@@ -0,0 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
4
+ import { create } from "../../helpers/bem.js";
5
+ import styles from "./Button.module.scss.js";
6
+ import { Icon } from "../icon/Icon.js";
7
+ const bem = create(styles, "Button");
8
+ function ButtonView({
9
+ fullWidth,
10
+ color,
11
+ variant,
12
+ className,
13
+ contentClassName,
14
+ disabled,
15
+ redirect,
16
+ iconProps = {},
17
+ isIconOnly,
18
+ LinkComponent,
19
+ ...rest
20
+ }) {
21
+ const isOutlined = variant === "outlined";
22
+ const iconName = iconProps == null ? void 0 : iconProps.name;
23
+ const iconMod = { "icon-only": isIconOnly };
24
+ const { title } = rest;
25
+ const inner = /* @__PURE__ */ jsxs(Fragment, { children: [
26
+ iconName && /* @__PURE__ */ jsx(Icon, { className: bem("icon", iconMod), ...iconProps }),
27
+ title
28
+ ] });
29
+ const variantNode = isOutlined ? /* @__PURE__ */ jsx("div", { className: bem("content", iconMod, contentClassName), children: inner }) : inner;
30
+ const common = {
31
+ id: rest.id,
32
+ "aria-label": title ?? void 0,
33
+ className: bem(
34
+ void 0,
35
+ {
36
+ "has-fullWidth": Boolean(fullWidth),
37
+ [`has-variant-${variant}`]: true,
38
+ [`has-bg-${color}`]: variant === "contained",
39
+ [`has-text-${color}`]: variant === "text",
40
+ "is-disabled": Boolean(disabled),
41
+ ...iconMod
42
+ },
43
+ className
44
+ )
45
+ };
46
+ return redirect ? /* @__PURE__ */ jsx(LinkComponent, { ...common, disabled, href: redirect.href, children: variantNode }) : /* @__PURE__ */ jsx(
47
+ "button",
48
+ {
49
+ ...common,
50
+ disabled: Boolean(disabled),
51
+ tabIndex: redirect !== void 0 || Boolean(disabled) ? -1 : rest.tabIndex,
52
+ type: "button",
53
+ ...rest,
54
+ children: variantNode
55
+ }
56
+ );
57
+ }
58
+ __name(ButtonView, "ButtonView");
59
+ export {
60
+ ButtonView
61
+ };
@@ -1,4 +1,4 @@
1
- const PROKODO_UI_VERSION = "0.0.32";
1
+ const PROKODO_UI_VERSION = "0.0.34";
2
2
  export {
3
3
  PROKODO_UI_VERSION
4
4
  };
@@ -2,11 +2,11 @@ var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
  import { useRef, useState, useLayoutEffect } from "react";
4
4
  function useHydrationReady(opts = {}) {
5
- const { enabled = true, threshold = 0.1, priority = false } = opts;
5
+ const { enabled = true, threshold = 0.1 } = opts;
6
6
  const ref = useRef(null);
7
- const [visible, setVisible] = useState(() => {
7
+ const [visible, set] = useState(() => {
8
8
  var _a;
9
- if (!enabled || !!priority || typeof window === "undefined") return !enabled;
9
+ if (!enabled || typeof window === "undefined") return !enabled;
10
10
  const box = (_a = ref.current) == null ? void 0 : _a.getBoundingClientRect();
11
11
  return !!box && box.top < window.innerHeight;
12
12
  });
@@ -15,7 +15,7 @@ function useHydrationReady(opts = {}) {
15
15
  const io = new IntersectionObserver(
16
16
  ([e]) => {
17
17
  if ((e == null ? void 0 : e.isIntersecting) === true) {
18
- setVisible(true);
18
+ set(true);
19
19
  io.disconnect();
20
20
  }
21
21
  },