@uxf/core-react 11.54.0 → 11.58.1

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/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # UXF Core-React
2
2
 
3
+ ## String helpers
4
+
5
+ ```tsx
6
+ import { nl2br } from "@uxf/core-react/string/nl2br";
7
+
8
+ <div>{nl2br("Hello\nWorld")}</div>
9
+ ```
10
+
3
11
  ## Hooks
4
12
  ---
5
13
  ### useBodyScrollLock
@@ -151,7 +159,7 @@ useFocusReturn(active);
151
159
  ### useAnchorProps
152
160
  Returns props for anchor element.
153
161
  ```tsx
154
- import { useAnchorProps } from "@uxf/core-react/hooks/use-anchor-props";
162
+ import { useAnchorProps } from "@uxf/core-react/clickable/use-anchor-props";
155
163
  import { AnchorHTMLAttributes } from "react";
156
164
 
157
165
  // extends <a /> by `analyticsCallback`, `disabled`, `loading`, `submit` props
@@ -167,7 +175,7 @@ const anchorProps = useAnchorProps<AnchorHTMLAttributes<HTMLAnchorElement>>({
167
175
  <a {...anchorProps}>Click me</a>
168
176
 
169
177
  // example with generics
170
- import { UseAnchorProps, useAnchorProps } from "@uxf/core-react/hooks/use-anchor-props";
178
+ import { UseAnchorProps, useAnchorProps } from "@uxf/core-react/clickable/use-anchor-props";
171
179
  import { AnchorHTMLAttributes } from "react";
172
180
 
173
181
  interface Props extends UseAnchorProps, AnchorHTMLAttributes<HTMLAnchorElement> {
@@ -187,7 +195,7 @@ const anchorProps = useAnchorProps<Props>({
187
195
  ### useButtonProps
188
196
  Returns props for button element.
189
197
  ```tsx
190
- import { useButtonProps } from "@uxf/core-react/hooks/use-button-props";
198
+ import { useButtonProps } from "@uxf/core-react/clickable/use-button-props";
191
199
  import { ButtonHTMLAttributes } from "react";
192
200
 
193
201
  // extends <button /> by `analyticsCallback` and `loading` props
@@ -202,7 +210,7 @@ const buttonProps = useButtonProps<ButtonHTMLAttributes<HTMLButtonElement>>({
202
210
  <button {...buttonProps}>Click me</button>
203
211
 
204
212
  // example with generics
205
- import { UseButtonProps, useButtonProps } from "@uxf/core-react/hooks/use-button-props";
213
+ import { UseButtonProps, useButtonProps } from "@uxf/core-react/clickable/use-button-props";
206
214
  import { ButtonHTMLAttributes } from "react";
207
215
 
208
216
  interface Props extends UseButtonProps, ButtonHTMLAttributes<HTMLButtonElement> {
@@ -221,7 +229,7 @@ const buttonProps = useButtonProps<Props>({
221
229
  ### useClickableProps
222
230
  Returns props for clickable element.
223
231
  ```tsx
224
- import { useClickableProps } from "@uxf/core-react/hooks/use-clickable-props";
232
+ import { useClickableProps } from "@uxf/core-react/clickable/use-clickable-props";
225
233
  import { HTMLAttributes } from "react";
226
234
 
227
235
  // extends any HTML element by `analyticsCallback`, `disabled`, `loading`, `submit` props
@@ -236,7 +244,7 @@ const clickableProps = useClickableProps<HTMLAttributes<HTMLDivElement>>({
236
244
  <div {...clickableProps}>Click me</div>
237
245
 
238
246
  // example with generics
239
- import { UseClickableProps, useClickableProps } from "@uxf/core-react/hooks/use-clickable-props";
247
+ import { UseClickableProps, useClickableProps } from "@uxf/core-react/clickable/use-clickable-props";
240
248
  import { HTMLAttributes } from "react";
241
249
 
242
250
  interface Props extends UseClickableProps, HTMLAttributes<HTMLDivElement> {
@@ -8,9 +8,10 @@ interface Props<T extends HTMLElement> {
8
8
  onKeyUp?: KeyboardEventHandler<T>;
9
9
  isSubmitType?: boolean;
10
10
  }
11
- export declare function _useSimulatedButton<T extends HTMLElement>({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, isSubmitType, }: Props<T>): {
11
+ export declare function _useSimulatedButton<T extends HTMLAnchorElement>({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, isSubmitType, }: Props<T>): {
12
12
  onClick: MouseEventHandler<T>;
13
13
  onKeyDown: KeyboardEventHandler<T>;
14
14
  onKeyUp: KeyboardEventHandler<T>;
15
+ isBusy: boolean | undefined;
15
16
  };
16
17
  export {};
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports._useSimulatedButton = _useSimulatedButton;
4
4
  const react_1 = require("react");
5
5
  function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onClick, onKeyDown, onKeyUp, isSubmitType, }) {
6
+ // eslint-disable-next-line react-hooks/rules-of-hooks
7
+ const [isBusy, setIsBusy] = (0, react_1.useState)(false);
6
8
  // eslint-disable-next-line react-hooks/rules-of-hooks
7
9
  const _onClick = (0, react_1.useCallback)((e) => {
8
10
  var _a;
@@ -16,8 +18,11 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
16
18
  closestForm.dispatchEvent(new Event("submit", { bubbles: true, cancelable: true }));
17
19
  }
18
20
  }
19
- if (onClick) {
20
- onClick(e);
21
+ // TODO @vejvis - jaktože tady je onclick který vrací void a ne Promise<void> ?
22
+ const clickResult = onClick === null || onClick === void 0 ? void 0 : onClick(e);
23
+ if (clickResult instanceof Promise) {
24
+ setIsBusy(true);
25
+ clickResult.finally(() => setIsBusy(false));
21
26
  }
22
27
  }
23
28
  else {
@@ -47,5 +52,10 @@ function _useSimulatedButton({ analyticsCallback, isClickable, isHyperlink, onCl
47
52
  }
48
53
  }
49
54
  }, [isClickable, onKeyDown]);
50
- return { onClick: _onClick, onKeyDown: _onKeyDown, onKeyUp: _onKeyUp };
55
+ return {
56
+ onClick: _onClick,
57
+ onKeyDown: _onKeyDown,
58
+ onKeyUp: _onKeyUp,
59
+ isBusy: isBusy ? true : undefined,
60
+ };
51
61
  }
@@ -0,0 +1,9 @@
1
+ import { Nullish } from "@uxf/core/types";
2
+ import { CxClassValue } from "@uxf/core/utils/cx";
3
+ import { Options } from "./types";
4
+ interface State {
5
+ isBusy: boolean | Nullish;
6
+ isDisabled: boolean | Nullish;
7
+ }
8
+ export declare function addBusyAndDisabledClassnames(className: string | Nullish, state: State, options: Options): CxClassValue[];
9
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addBusyAndDisabledClassnames = addBusyAndDisabledClassnames;
4
+ const classes_1 = require("@uxf/core/constants/classes");
5
+ function addBusyAndDisabledClassnames(className, state, options) {
6
+ return [
7
+ state.isBusy &&
8
+ (options.classNamePrefix
9
+ ? `${options.classNamePrefix}--${classes_1.CLASSES.IS_LOADING} ${classes_1.CLASSES.IS_LOADING}`
10
+ : classes_1.CLASSES.IS_LOADING),
11
+ state.isDisabled &&
12
+ (options.classNamePrefix
13
+ ? `${options.classNamePrefix}--${classes_1.CLASSES.IS_DISABLED} ${classes_1.CLASSES.IS_DISABLED}`
14
+ : classes_1.CLASSES.IS_DISABLED),
15
+ className,
16
+ ];
17
+ }
@@ -0,0 +1,3 @@
1
+ export type Options = {
2
+ classNamePrefix?: string;
3
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { AnchorHTMLAttributes } from "react";
2
+ import { Options } from "./types";
3
+ export interface UseAnchorProps {
4
+ analyticsCallback?: () => void;
5
+ isDisabled?: boolean;
6
+ isLoading?: boolean;
7
+ type?: "submit";
8
+ }
9
+ export declare function useAnchorProps<T extends AnchorHTMLAttributes<HTMLAnchorElement>>(props: UseAnchorProps & T, options?: Options): T;
@@ -5,14 +5,15 @@ const classes_1 = require("@uxf/core/constants/classes");
5
5
  const cx_1 = require("@uxf/core/utils/cx");
6
6
  const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
7
7
  const _use_simulated_button_1 = require("./_use-simulated-button");
8
- function useAnchorProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, isDisabled, download, href, hrefLang, isLoading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps }) {
8
+ const add_busy_and_disabled_classnames_1 = require("./add-busy-and-disabled-classnames");
9
+ function useAnchorProps(props, options = {}) {
10
+ const { ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, isDisabled, download, href, hrefLang, isLoading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps } = props;
9
11
  const isBusy = Boolean(isLoading || ariaBusy);
10
12
  const isDisabledOrAriaDisabled = Boolean(isDisabled || ariaDisabled);
11
13
  const isBusyOrDisabled = isBusy || isDisabledOrAriaDisabled;
12
14
  const isSubmitType = type === "submit";
13
15
  const isButton = isSubmitType || (0, is_not_nil_1.isNotNil)(onClick);
14
16
  const tabIndexInteractive = isBusyOrDisabled ? -1 : tabIndex;
15
- const _className = [isBusy && classes_1.CLASSES.IS_LOADING, isDisabledOrAriaDisabled && classes_1.CLASSES.IS_DISABLED, className];
16
17
  const simulatedButton = (0, _use_simulated_button_1._useSimulatedButton)({
17
18
  analyticsCallback,
18
19
  isClickable: !isBusyOrDisabled || isButton,
@@ -22,6 +23,7 @@ function useAnchorProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabl
22
23
  onKeyUp,
23
24
  isSubmitType,
24
25
  });
26
+ const _className = (0, add_busy_and_disabled_classnames_1.addBusyAndDisabledClassnames)(className, { isBusy: isBusy || simulatedButton.isBusy, isDisabled: isDisabledOrAriaDisabled }, options);
25
27
  if (href) {
26
28
  return {
27
29
  "aria-busy": isBusy,
@@ -0,0 +1,7 @@
1
+ import { ButtonHTMLAttributes } from "react";
2
+ import { Options } from "./types";
3
+ export interface UseButtonProps {
4
+ analyticsCallback?: () => void;
5
+ loading?: boolean;
6
+ }
7
+ export declare function useButtonProps<T extends ButtonHTMLAttributes<HTMLButtonElement>>(props: UseButtonProps & T, options?: Options): T;
@@ -4,11 +4,13 @@ exports.useButtonProps = useButtonProps;
4
4
  const classes_1 = require("@uxf/core/constants/classes");
5
5
  const cx_1 = require("@uxf/core/utils/cx");
6
6
  const react_1 = require("react");
7
- function useButtonProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps }) {
7
+ const add_busy_and_disabled_classnames_1 = require("./add-busy-and-disabled-classnames");
8
+ function useButtonProps(props, options = {}) {
9
+ const { ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps } = props;
8
10
  const isBusy = loading ? loading : Boolean(ariaBusy);
9
11
  const isDisabled = disabled ? disabled : Boolean(ariaDisabled);
10
12
  const isBusyOrDisabled = isBusy || isDisabled;
11
- const _className = [isBusy && classes_1.CLASSES.IS_LOADING, isDisabled && classes_1.CLASSES.IS_DISABLED, className];
13
+ const _className = (0, add_busy_and_disabled_classnames_1.addBusyAndDisabledClassnames)(className, { isBusy, isDisabled }, options);
12
14
  const _onClick = (0, react_1.useCallback)((e) => {
13
15
  if (isBusyOrDisabled) {
14
16
  e.preventDefault();
@@ -1,8 +1,9 @@
1
1
  import { HTMLAttributes } from "react";
2
+ import { Options } from "./types";
2
3
  export interface UseClickableProps {
3
4
  analyticsCallback?: () => void;
4
5
  isDisabled?: boolean;
5
6
  isLoading?: boolean;
6
7
  type?: "submit";
7
8
  }
8
- export declare function useClickableProps<T extends HTMLAttributes<HTMLElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, isDisabled, isLoading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps }: UseClickableProps & T): T;
9
+ export declare function useClickableProps<T extends HTMLAttributes<HTMLElement>>(props: UseClickableProps & T, options?: Options): T;
@@ -5,13 +5,14 @@ const classes_1 = require("@uxf/core/constants/classes");
5
5
  const cx_1 = require("@uxf/core/utils/cx");
6
6
  const is_not_nil_1 = require("@uxf/core/utils/is-not-nil");
7
7
  const _use_simulated_button_1 = require("./_use-simulated-button");
8
- function useClickableProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, isDisabled, isLoading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps }) {
8
+ const add_busy_and_disabled_classnames_1 = require("./add-busy-and-disabled-classnames");
9
+ function useClickableProps(props, options = {}) {
10
+ const { ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, isDisabled, isLoading, onClick, onKeyDown, onKeyUp, role, tabIndex, type, ...restProps } = props;
9
11
  const isBusy = Boolean(isLoading || ariaBusy);
10
12
  const isDisabledOrAriaDisabled = Boolean(isDisabled || ariaDisabled);
11
13
  const isBusyOrDisabled = isBusy || isDisabledOrAriaDisabled;
12
14
  const isSubmitType = type === "submit";
13
15
  const isButton = isSubmitType || (0, is_not_nil_1.isNotNil)(onClick);
14
- const _className = [isBusy && classes_1.CLASSES.IS_LOADING, isDisabledOrAriaDisabled && classes_1.CLASSES.IS_DISABLED, className];
15
16
  const simulatedButton = (0, _use_simulated_button_1._useSimulatedButton)({
16
17
  analyticsCallback,
17
18
  isClickable: !isBusyOrDisabled || isButton,
@@ -21,6 +22,7 @@ function useClickableProps({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDis
21
22
  onKeyUp,
22
23
  isSubmitType,
23
24
  });
25
+ const _className = (0, add_busy_and_disabled_classnames_1.addBusyAndDisabledClassnames)(className, { isBusy: isBusy || simulatedButton.isBusy, isDisabled: isDisabledOrAriaDisabled }, options);
24
26
  if (isButton) {
25
27
  return {
26
28
  "aria-busy": isBusy,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/core-react",
3
- "version": "11.54.0",
3
+ "version": "11.58.1",
4
4
  "description": "UXF Core",
5
5
  "author": "UX Fans s.r.o",
6
6
  "license": "MIT",
@@ -12,7 +12,7 @@
12
12
  "typecheck": "tsc --noEmit --skipLibCheck"
13
13
  },
14
14
  "dependencies": {
15
- "@uxf/core": "11.54.0"
15
+ "@uxf/core": "11.58.0"
16
16
  },
17
17
  "peerDependencies": {
18
18
  "react": ">=18.2.0"
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare function nl2br(str: string): (string | React.JSX.Element)[];
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.nl2br = nl2br;
27
+ const react_1 = __importStar(require("react"));
28
+ function nl2br(str) {
29
+ return str.split("\n").map(function (item, i) {
30
+ if (i === 0) {
31
+ return item;
32
+ }
33
+ return (react_1.default.createElement(react_1.Fragment, { key: i },
34
+ react_1.default.createElement("br", null),
35
+ item));
36
+ });
37
+ }
@@ -1,8 +0,0 @@
1
- import { AnchorHTMLAttributes } from "react";
2
- export interface UseAnchorProps {
3
- analyticsCallback?: () => void;
4
- isDisabled?: boolean;
5
- isLoading?: boolean;
6
- type?: "submit";
7
- }
8
- export declare function useAnchorProps<T extends AnchorHTMLAttributes<HTMLAnchorElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, analyticsCallback, className, isDisabled, download, href, hrefLang, isLoading, media, onClick, onKeyDown, onKeyUp, ping, referrerPolicy, rel, role, tabIndex, target, type, ...restProps }: UseAnchorProps & T): T;
@@ -1,6 +0,0 @@
1
- import { ButtonHTMLAttributes } from "react";
2
- export interface UseButtonProps {
3
- analyticsCallback?: () => void;
4
- loading?: boolean;
5
- }
6
- export declare function useButtonProps<T extends ButtonHTMLAttributes<HTMLButtonElement>>({ ["aria-busy"]: ariaBusy, ["aria-disabled"]: ariaDisabled, autoFocus, analyticsCallback, className, disabled, formAction, formEncType, formMethod, formNoValidate, formTarget, loading, name, onClick, role, tabIndex, type, value, ...restProps }: UseButtonProps & T): T;