@povio/ui 0.0.10 → 0.1.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.
@@ -1,6 +1,7 @@
1
1
  import { FC, ReactElement, SVGProps } from 'react';
2
- import { ButtonProps as AriaButtonProps, LinkProps as AriaLinkProps, ToggleButtonProps as AriaToggleButtonProps } from 'react-aria-components';
2
+ import { ButtonProps as AriaButtonProps, ToggleButtonProps as AriaToggleButtonProps } from 'react-aria-components';
3
3
  import { ButtonContentVariantProps } from '../shared/buttonContent.cva';
4
+ import { LinkNavigationProps } from '../../text/Link/Link';
4
5
  import { ButtonVariantProps } from './button.cva';
5
6
  export type ButtonIconProps<IconOnly extends boolean = false> = {
6
7
  iconOnly?: IconOnly;
@@ -18,7 +19,7 @@ type ToggleButtonProps = {
18
19
  export type ButtonProps<IconOnly extends boolean = false> = ButtonVariantProps & ButtonContentVariantProps & AriaButtonProps & ButtonIconProps<IconOnly> & ToggleButtonProps & {
19
20
  children: string;
20
21
  isLoading?: boolean;
21
- link?: AriaLinkProps;
22
+ link?: LinkNavigationProps;
22
23
  noDisableWhenLoading?: boolean;
23
24
  iconClassName?: string;
24
25
  disableTooltip?: boolean;
@@ -3,6 +3,7 @@ import { clsx } from "clsx";
3
3
  import { Link, ToggleButton, Button as Button$1 } from "react-aria-components";
4
4
  import { ButtonContent } from "../shared/ButtonContent.js";
5
5
  import { TooltipEllipsis } from "../../overlays/Tooltip/TooltipEllipsis.js";
6
+ import { LinkContext } from "../../../config/link.context.js";
6
7
  import { UIStyle } from "../../../config/uiStyle.context.js";
7
8
  import { button, buttonSize, buttonContent, buttonIconSize, buttonTypography } from "./button.cva.js";
8
9
  const Button = ({
@@ -17,6 +18,7 @@ const Button = ({
17
18
  disableTooltip,
18
19
  ...props
19
20
  }) => {
21
+ const linkContext = LinkContext.useLinkContext();
20
22
  const uiStyle = UIStyle.useConfig();
21
23
  const buttonCva = uiStyle?.button?.cva ?? button;
22
24
  const buttonSizeCva = uiStyle?.button?.sizeCva ?? buttonSize;
@@ -25,13 +27,16 @@ const Button = ({
25
27
  const typographyMap = uiStyle?.button?.typography ?? buttonTypography;
26
28
  const Component = (() => {
27
29
  if (link) {
28
- return Link;
30
+ return linkContext?.LinkComponent ?? Link;
29
31
  }
30
32
  if (props.toggle != null) {
31
33
  return ToggleButton;
32
34
  }
33
35
  return Button$1;
34
36
  })();
37
+ if (link && !link.to && link.href) {
38
+ link.to = link.href;
39
+ }
35
40
  return /* @__PURE__ */ jsx(
36
41
  TooltipEllipsis,
37
42
  {
@@ -1,10 +1,11 @@
1
1
  import { FC, ReactElement, SVGProps } from 'react';
2
- import { ButtonProps as AriaButtonProps, LinkProps as AriaLinkProps } from 'react-aria-components';
2
+ import { ButtonProps as AriaButtonProps } from 'react-aria-components';
3
3
  import { ButtonVariantProps } from '../Button/button.cva';
4
+ import { LinkNavigationProps } from '../../text/Link/Link';
4
5
  export interface IconButtonProps extends ButtonVariantProps, Omit<AriaButtonProps, "children"> {
5
6
  label: string;
6
7
  icon: FC<SVGProps<SVGSVGElement>> | ReactElement;
7
- link?: AriaLinkProps;
8
+ link?: LinkNavigationProps;
8
9
  disableTooltip?: boolean;
9
10
  }
10
11
  export declare const IconButton: ({ label, ...props }: IconButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,11 @@
1
1
  import { FC, ReactElement, RefObject, SVGProps } from 'react';
2
- import { ButtonProps as AriaButtonProps, LinkProps as AriaLinkProps } from 'react-aria-components';
2
+ import { ButtonProps as AriaButtonProps } from 'react-aria-components';
3
3
  import { ButtonVariantProps } from '../Button/button.cva';
4
+ import { LinkNavigationProps } from '../../text/Link/Link';
4
5
  export interface InlineIconButtonProps extends Omit<AriaButtonProps, "children">, ButtonVariantProps {
5
6
  label: string;
6
7
  icon: FC<SVGProps<SVGSVGElement>> | ReactElement;
7
- link?: AriaLinkProps;
8
+ link?: LinkNavigationProps;
8
9
  ref?: RefObject<HTMLButtonElement | HTMLAnchorElement | null>;
9
10
  disableTooltip?: boolean;
10
11
  }
@@ -1,10 +1,11 @@
1
- import { ButtonProps as AriaButtonProps, LinkProps as AriaLinkProps } from 'react-aria-components';
1
+ import { ButtonProps as AriaButtonProps } from 'react-aria-components';
2
2
  import { ButtonVariantProps } from '../Button/button.cva';
3
3
  import { MenuItem } from '../../Menu/Menu';
4
+ import { LinkNavigationProps } from '../../text/Link/Link';
4
5
  export interface SplitButtonProps extends ButtonVariantProps, Omit<AriaButtonProps, "children"> {
5
6
  label: string;
6
7
  labelRight: string;
7
- link?: AriaLinkProps;
8
+ link?: LinkNavigationProps;
8
9
  items: MenuItem[];
9
10
  }
10
11
  export declare const SplitButton: ({ variant, color, width, size, label, labelRight, link, items, className, ...props }: SplitButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,11 +1,12 @@
1
- import { ButtonProps as AriaButtonProps, LinkProps as AriaLinkProps } from 'react-aria-components';
1
+ import { ButtonProps as AriaButtonProps } from 'react-aria-components';
2
2
  import { ButtonIconProps } from '../Button/Button';
3
3
  import { ButtonVariantProps } from '../Button/button.cva';
4
4
  import { ButtonContentVariantProps } from '../shared/buttonContent.cva';
5
+ import { LinkNavigationProps } from '../../text/Link/Link';
5
6
  export type TextButtonProps = Omit<ButtonVariantProps, "variant"> & ButtonContentVariantProps & AriaButtonProps & ButtonIconProps<true | false> & {
6
7
  children: string;
7
8
  isLoading?: boolean;
8
- link?: AriaLinkProps;
9
+ link?: LinkNavigationProps;
9
10
  disableTooltip?: boolean;
10
11
  };
11
12
  export declare const TextButton: ({ children, ...props }: TextButtonProps) => import("react/jsx-runtime").JSX.Element;
@@ -39,7 +39,15 @@ const Tooltip = ({
39
39
  closeDelay: closeDelay ?? 0,
40
40
  isDisabled,
41
41
  children: [
42
- /* @__PURE__ */ jsx(Trigger, { className: triggerClassName, children }),
42
+ /* @__PURE__ */ jsx(
43
+ Trigger,
44
+ {
45
+ ...isNonInteractiveTrigger && {
46
+ className: triggerClassName
47
+ },
48
+ children
49
+ }
50
+ ),
43
51
  /* @__PURE__ */ jsxs(
44
52
  Tooltip$1,
45
53
  {
@@ -1,7 +1,9 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { LinkProps as AriaLinkProps } from 'react-aria-components';
3
3
  import { LinkVariantProps } from './link.cva';
4
- export interface LinkProps extends PropsWithChildren<AriaLinkProps>, LinkVariantProps {
4
+ export interface LinkNavigationProps extends AriaLinkProps {
5
+ }
6
+ export interface LinkProps extends PropsWithChildren<LinkNavigationProps>, LinkVariantProps {
5
7
  className?: string;
6
8
  }
7
9
  export declare const Link: ({ variant, ...props }: LinkProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,12 +1,18 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { Link as Link$1 } from "react-aria-components";
3
3
  import { link } from "./link.cva.js";
4
+ import { LinkContext } from "../../../config/link.context.js";
4
5
  import { UIStyle } from "../../../config/uiStyle.context.js";
5
6
  const Link = ({ variant, ...props }) => {
7
+ const linkContext = LinkContext.useLinkContext();
6
8
  const uiStyle = UIStyle.useConfig();
7
9
  const linkCva = uiStyle?.link?.cva ?? link;
10
+ const LinkComponent = linkContext?.LinkComponent ?? Link$1;
11
+ if (!props.to && props.href) {
12
+ props.to = props.href;
13
+ }
8
14
  return /* @__PURE__ */ jsx(
9
- Link$1,
15
+ LinkComponent,
10
16
  {
11
17
  ...props,
12
18
  className: linkCva({ variant, className: props.className })
@@ -0,0 +1,10 @@
1
+ import { ComponentType, PropsWithChildren } from 'react';
2
+ import { LinkNavigationProps } from '../components/text/Link/Link';
3
+ interface LinkContextValue {
4
+ LinkComponent?: ComponentType<LinkNavigationProps>;
5
+ }
6
+ export declare namespace LinkContext {
7
+ const LinkContextProvider: ({ children, LinkComponent }: PropsWithChildren<LinkContextValue>) => import("react/jsx-runtime").JSX.Element;
8
+ const useLinkContext: () => LinkContextValue;
9
+ }
10
+ export {};
@@ -0,0 +1,19 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { createContext, use } from "react";
3
+ var LinkContext;
4
+ ((LinkContext2) => {
5
+ const LinkContextInternal = createContext(null);
6
+ LinkContext2.LinkContextProvider = ({ children, LinkComponent }) => {
7
+ const value = {
8
+ LinkComponent
9
+ };
10
+ return /* @__PURE__ */ jsx(LinkContextInternal.Provider, { value, children });
11
+ };
12
+ LinkContext2.useLinkContext = () => {
13
+ const context = use(LinkContextInternal);
14
+ return context;
15
+ };
16
+ })(LinkContext || (LinkContext = {}));
17
+ export {
18
+ LinkContext
19
+ };
package/dist/index.d.ts CHANGED
@@ -143,7 +143,7 @@ export { PaginatedTable } from './components/table/PaginatedTable';
143
143
  export type { TableProps, TableWrapperProps } from './components/table/Table';
144
144
  export { Table } from './components/table/Table';
145
145
  export type { TableRowVariantProps } from './components/table/table.cva';
146
- export type { LinkProps } from './components/text/Link/Link';
146
+ export type { LinkNavigationProps, LinkProps } from './components/text/Link/Link';
147
147
  export { Link } from './components/text/Link/Link';
148
148
  export type { LinkVariantProps } from './components/text/Link/link.cva';
149
149
  export type { TagProps } from './components/text/Tag/Tag';
@@ -154,6 +154,7 @@ export { Typography } from './components/text/Typography/Typography';
154
154
  export type { TypographyVariantProps } from './components/text/Typography/typography.cva';
155
155
  export { Confirmation } from './config/confirmation.context';
156
156
  export { ns, resources } from './config/i18n';
157
+ export { LinkContext } from './config/link.context';
157
158
  export { UIRouter } from './config/router.context';
158
159
  export { UIConfig } from './config/uiConfig.context';
159
160
  export { UIStyle } from './config/uiStyle.context';
@@ -200,11 +201,8 @@ export { createAclGuard } from './utils/vendor/acl/AclGuard';
200
201
  export { AbilityContext } from './utils/vendor/acl/ability.context';
201
202
  export type { AppAbilities, AppAbility } from './utils/vendor/acl/appAbility.types';
202
203
  export { Can } from './utils/vendor/acl/Can';
203
- export type { AuthGuardProps } from './utils/vendor/auth/AuthGuard';
204
204
  export { AuthGuard } from './utils/vendor/auth/AuthGuard';
205
205
  export { AuthContext } from './utils/vendor/auth/auth.context';
206
- export type { WithPrivateAuthGuardProps } from './utils/vendor/auth/withPrivateAuthGuard';
207
- export { withPrivateAuthGuard } from './utils/vendor/auth/withPrivateAuthGuard';
208
206
  export type { GeneralErrorCodes } from './utils/vendor/error-handling';
209
207
  export { ApplicationException, ErrorHandler, SharedErrorHandler } from './utils/vendor/error-handling';
210
208
  export type { RequestConfig, RequestInfo, Response, RestClient as IRestClient, } from './utils/vendor/rest-client.types';
package/dist/index.js CHANGED
@@ -93,6 +93,7 @@ import { Tag } from "./components/text/Tag/Tag.js";
93
93
  import { Typography } from "./components/text/Typography/Typography.js";
94
94
  import { Confirmation } from "./config/confirmation.context.js";
95
95
  import { ns, resources } from "./config/i18n.js";
96
+ import { LinkContext } from "./config/link.context.js";
96
97
  import { UIRouter } from "./config/router.context.js";
97
98
  import { UIConfig } from "./config/uiConfig.context.js";
98
99
  import { UIStyle } from "./config/uiStyle.context.js";
@@ -133,7 +134,6 @@ import { AbilityContext } from "./utils/vendor/acl/ability.context.js";
133
134
  import { Can } from "./utils/vendor/acl/Can.js";
134
135
  import { AuthGuard } from "./utils/vendor/auth/AuthGuard.js";
135
136
  import { AuthContext } from "./utils/vendor/auth/auth.context.js";
136
- import { withPrivateAuthGuard } from "./utils/vendor/auth/withPrivateAuthGuard.js";
137
137
  import { ApplicationException, ErrorHandler, SharedErrorHandler } from "./utils/vendor/error-handling.js";
138
138
  import { RestInterceptor } from "./utils/vendor/rest-interceptor.js";
139
139
  export {
@@ -199,6 +199,7 @@ export {
199
199
  Inputs,
200
200
  ItalicIcon,
201
201
  Link,
202
+ LinkContext,
202
203
  LinkIcon,
203
204
  Loader,
204
205
  Menu,
@@ -279,6 +280,5 @@ export {
279
280
  useTableColumnConfig,
280
281
  useTableNav,
281
282
  useToast,
282
- useTranslationMemo,
283
- withPrivateAuthGuard
283
+ useTranslationMemo
284
284
  };
@@ -1,8 +1,8 @@
1
- import { WithPrivateAuthGuardProps } from '../auth/withPrivateAuthGuard';
1
+ import { PropsWithChildren } from 'react';
2
2
  import { AppAbilities } from './appAbility.types';
3
- export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ privateAuthGuardProps, ...props }: {
3
+ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
4
4
  canUse: TAppAbilities;
5
5
  redirectTo?: string;
6
- } & {
7
- children?: import('react').ReactNode | undefined;
8
- } & WithPrivateAuthGuardProps) => import("react/jsx-runtime").JSX.Element;
6
+ }
7
+ export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import('react').ReactNode;
8
+ export {};
@@ -1,7 +1,6 @@
1
1
  import { UIRouter } from "../../../config/router.context.js";
2
2
  import { AbilityContext } from "./ability.context.js";
3
- import { withPrivateAuthGuard } from "../auth/withPrivateAuthGuard.js";
4
- const createAclGuard = () => withPrivateAuthGuard(({ canUse, redirectTo = "/", children }) => {
3
+ const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
5
4
  const ability = AbilityContext.useAbility();
6
5
  const { replace } = UIRouter.useUIRouter();
7
6
  if (!ability.can(canUse[0], canUse[1])) {
@@ -9,7 +8,7 @@ const createAclGuard = () => withPrivateAuthGuard(({ canUse, redirectTo = "/", c
9
8
  return null;
10
9
  }
11
10
  return children;
12
- });
11
+ };
13
12
  export {
14
13
  createAclGuard
15
14
  };
@@ -11,11 +11,12 @@ export declare namespace AuthContext {
11
11
  updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
12
12
  accessToken?: string | null;
13
13
  user?: TUser | null;
14
+ userPromise?: () => Promise<TUser | null>;
14
15
  routes?: Routes;
15
16
  loadingState?: ReactNode;
16
17
  }
17
18
  type ProviderProps<TUser = unknown> = Type<TUser>;
18
- export const Provider: <TUser = unknown>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, routes, loadingState, children, }: PropsWithChildren<ProviderProps<TUser>>) => import("react/jsx-runtime").JSX.Element;
19
+ export const Provider: <TUser = unknown>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children, }: PropsWithChildren<ProviderProps<TUser>>) => import("react/jsx-runtime").JSX.Element;
19
20
  export const useAuth: <TUser = unknown>() => Type<TUser>;
20
21
  export {};
21
22
  }
@@ -10,6 +10,7 @@ var AuthContext;
10
10
  updateTokens,
11
11
  accessToken,
12
12
  user,
13
+ userPromise,
13
14
  routes,
14
15
  loadingState,
15
16
  children
@@ -21,6 +22,7 @@ var AuthContext;
21
22
  updateTokens,
22
23
  accessToken,
23
24
  user,
25
+ userPromise,
24
26
  routes,
25
27
  loadingState
26
28
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@povio/ui",
3
- "version": "0.0.10",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,6 +0,0 @@
1
- import { ComponentType, PropsWithChildren } from 'react';
2
- import { AuthGuardProps } from './AuthGuard';
3
- export interface WithPrivateAuthGuardProps {
4
- privateAuthGuardProps?: Omit<AuthGuardProps, "type">;
5
- }
6
- export declare const withPrivateAuthGuard: <T extends PropsWithChildren & WithPrivateAuthGuardProps>(WrappedComponent: ComponentType<T & WithPrivateAuthGuardProps>) => ({ privateAuthGuardProps, ...props }: T & WithPrivateAuthGuardProps) => import("react/jsx-runtime").JSX.Element;
@@ -1,17 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { AuthGuard } from "./AuthGuard.js";
3
- const withPrivateAuthGuard = (WrappedComponent) => {
4
- return ({ privateAuthGuardProps, ...props }) => {
5
- return /* @__PURE__ */ jsx(
6
- AuthGuard,
7
- {
8
- type: "private",
9
- ...privateAuthGuardProps,
10
- children: /* @__PURE__ */ jsx(WrappedComponent, { ...props })
11
- }
12
- );
13
- };
14
- };
15
- export {
16
- withPrivateAuthGuard
17
- };