@uxf/core-react 11.54.0 → 11.58.0

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
@@ -151,7 +151,7 @@ useFocusReturn(active);
151
151
  ### useAnchorProps
152
152
  Returns props for anchor element.
153
153
  ```tsx
154
- import { useAnchorProps } from "@uxf/core-react/hooks/use-anchor-props";
154
+ import { useAnchorProps } from "@uxf/core-react/clickable/use-anchor-props";
155
155
  import { AnchorHTMLAttributes } from "react";
156
156
 
157
157
  // extends <a /> by `analyticsCallback`, `disabled`, `loading`, `submit` props
@@ -167,7 +167,7 @@ const anchorProps = useAnchorProps<AnchorHTMLAttributes<HTMLAnchorElement>>({
167
167
  <a {...anchorProps}>Click me</a>
168
168
 
169
169
  // example with generics
170
- import { UseAnchorProps, useAnchorProps } from "@uxf/core-react/hooks/use-anchor-props";
170
+ import { UseAnchorProps, useAnchorProps } from "@uxf/core-react/clickable/use-anchor-props";
171
171
  import { AnchorHTMLAttributes } from "react";
172
172
 
173
173
  interface Props extends UseAnchorProps, AnchorHTMLAttributes<HTMLAnchorElement> {
@@ -187,7 +187,7 @@ const anchorProps = useAnchorProps<Props>({
187
187
  ### useButtonProps
188
188
  Returns props for button element.
189
189
  ```tsx
190
- import { useButtonProps } from "@uxf/core-react/hooks/use-button-props";
190
+ import { useButtonProps } from "@uxf/core-react/clickable/use-button-props";
191
191
  import { ButtonHTMLAttributes } from "react";
192
192
 
193
193
  // extends <button /> by `analyticsCallback` and `loading` props
@@ -202,7 +202,7 @@ const buttonProps = useButtonProps<ButtonHTMLAttributes<HTMLButtonElement>>({
202
202
  <button {...buttonProps}>Click me</button>
203
203
 
204
204
  // example with generics
205
- import { UseButtonProps, useButtonProps } from "@uxf/core-react/hooks/use-button-props";
205
+ import { UseButtonProps, useButtonProps } from "@uxf/core-react/clickable/use-button-props";
206
206
  import { ButtonHTMLAttributes } from "react";
207
207
 
208
208
  interface Props extends UseButtonProps, ButtonHTMLAttributes<HTMLButtonElement> {
@@ -221,7 +221,7 @@ const buttonProps = useButtonProps<Props>({
221
221
  ### useClickableProps
222
222
  Returns props for clickable element.
223
223
  ```tsx
224
- import { useClickableProps } from "@uxf/core-react/hooks/use-clickable-props";
224
+ import { useClickableProps } from "@uxf/core-react/clickable/use-clickable-props";
225
225
  import { HTMLAttributes } from "react";
226
226
 
227
227
  // extends any HTML element by `analyticsCallback`, `disabled`, `loading`, `submit` props
@@ -236,7 +236,7 @@ const clickableProps = useClickableProps<HTMLAttributes<HTMLDivElement>>({
236
236
  <div {...clickableProps}>Click me</div>
237
237
 
238
238
  // example with generics
239
- import { UseClickableProps, useClickableProps } from "@uxf/core-react/hooks/use-clickable-props";
239
+ import { UseClickableProps, useClickableProps } from "@uxf/core-react/clickable/use-clickable-props";
240
240
  import { HTMLAttributes } from "react";
241
241
 
242
242
  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.0",
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"
@@ -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;