react-ui89 0.14.0 → 0.15.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.
@@ -0,0 +1,12 @@
1
+ import React, { ReactNode } from "react";
2
+ type RouterPush = (url: string) => void | Promise<void>;
3
+ interface Ui89OverrideContextType {
4
+ routerPush?: RouterPush;
5
+ }
6
+ export interface Ui89OverrideProviderProps {
7
+ children?: ReactNode;
8
+ routerPush?: RouterPush;
9
+ }
10
+ export declare const Ui89OverrideProvider: React.FC<Ui89OverrideProviderProps>;
11
+ export declare const useUi89Overrides: () => Ui89OverrideContextType;
12
+ export {};
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react";
2
2
  import { Ui89Breadcrumbs } from "./Ui89Breadcrumbs";
3
+ import { Ui89OverrideProviderProps } from "../Ui89Override";
3
4
  declare const meta: Meta<typeof Ui89Breadcrumbs>;
4
5
  export default meta;
5
6
  type Story = StoryObj<typeof meta>;
@@ -7,3 +8,4 @@ export declare const Empty: Story;
7
8
  export declare const OneCrumb: Story;
8
9
  export declare const TwoCrumbs: Story;
9
10
  export declare const FiveCrumbs: Story;
11
+ export declare const OverrideRouterPush: StoryObj<Ui89OverrideProviderProps>;
@@ -10,7 +10,6 @@ interface Ui89ButtonProps {
10
10
  autoDisableOnClick?: boolean;
11
11
  disabled?: boolean;
12
12
  activated?: boolean;
13
- routerPush?: (url: string) => void;
14
13
  }
15
- export declare function Ui89Button({ theme, size, block, onClick, href, children, autoDisableOnClick, disabled, activated, routerPush, }: Ui89ButtonProps): React.JSX.Element;
14
+ export declare function Ui89Button({ theme, size, block, onClick, href, children, autoDisableOnClick, disabled, activated, }: Ui89ButtonProps): React.JSX.Element;
16
15
  export {};
@@ -1,5 +1,6 @@
1
1
  import type { Meta, StoryObj } from "@storybook/react";
2
2
  import { Ui89Button } from "./Ui89Button";
3
+ import { Ui89OverrideProviderProps } from "../Ui89Override";
3
4
  declare const meta: Meta<typeof Ui89Button>;
4
5
  export default meta;
5
6
  type Story = StoryObj<typeof meta>;
@@ -9,3 +10,4 @@ export declare const ThemeSuccess: Story;
9
10
  export declare const ThemeDanger: Story;
10
11
  export declare const ThemeInfo: Story;
11
12
  export declare const ThemeWarning: Story;
13
+ export declare const OverrideRouterPush: StoryObj<Ui89OverrideProviderProps>;
@@ -10,6 +10,8 @@ export { Ui89InputTextNumber } from "./components/Ui89InputTextNumber";
10
10
  export type { Ui89MenuBarItem, Ui89MenuBarProps, } from "./components/Ui89MenuBar";
11
11
  export { Ui89MenuBar } from "./components/Ui89MenuBar";
12
12
  export { Ui89ModalDialog } from "./components/Ui89ModalDialog";
13
+ export type { Ui89OverrideProviderProps } from "./Ui89Override";
14
+ export { Ui89OverrideProvider } from "./Ui89Override";
13
15
  export { Ui89Scene } from "./components/Ui89Scene";
14
16
  export { Ui89Shortcut } from "./components/Ui89Shortcut";
15
17
  export { Ui89SpaceVertical } from "./components/Ui89SpaceVertical";
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import React__default, { useState, useRef, useMemo, useEffect, forwardRef } from 'react';
2
+ import React__default, { createContext, useContext, useState, useRef, useMemo, useEffect, forwardRef } from 'react';
3
3
  import Timeout from 'smart-timeout';
4
4
  import { VariableSizeGrid } from 'react-window';
5
5
  import AutoSizer from 'react-virtualized-auto-sizer';
@@ -27,9 +27,32 @@ var resetStyles = {"a":"reset-module_a__dpZ8C"};
27
27
 
28
28
  var chosenThemeStyles = {"primary":"chosen-theme-module_primary__GwEqU","secondary":"chosen-theme-module_secondary__DI5Gk","info":"chosen-theme-module_info__KYP2h","success":"chosen-theme-module_success__l3hFS","warning":"chosen-theme-module_warning__A7IOL","danger":"chosen-theme-module_danger__CZ3Iq"};
29
29
 
30
+ const Ui89OverrideContext = createContext({});
31
+ const Ui89OverrideProvider = ({ routerPush, children, }) => {
32
+ return (React__default.createElement(Ui89OverrideContext.Provider, { value: { routerPush } }, children));
33
+ };
34
+ const useUi89Overrides = () => {
35
+ const context = useContext(Ui89OverrideContext);
36
+ if (context === undefined) {
37
+ throw new Error("useUi89Overrides must be used within a Ui89OverrideProvider");
38
+ }
39
+ return context;
40
+ };
41
+
30
42
  function Ui89BreadcrumbsItem({ index, item, onSelect, }) {
31
43
  item.url !== undefined ? "a" : "div";
32
- return (React__default.createElement("a", { className: `${resetStyles.a} ${styles$f.breadcrumbsItem}`, href: item.url, style: { "--ui89-index": index } },
44
+ const overrides = useUi89Overrides();
45
+ const onClick = (e) => {
46
+ if (item.url !== undefined) {
47
+ if (item.url.startsWith("/")) {
48
+ if (overrides.routerPush !== undefined) {
49
+ e.preventDefault();
50
+ overrides.routerPush(item.url);
51
+ }
52
+ }
53
+ }
54
+ };
55
+ return (React__default.createElement("a", { className: `${resetStyles.a} ${styles$f.breadcrumbsItem}`, href: item.url, style: { "--ui89-index": index }, onClick: onClick },
33
56
  React__default.createElement("div", { className: styles$f.breadcrumbsItemBackground }),
34
57
  item.label));
35
58
  }
@@ -48,8 +71,8 @@ function HoverShadow({ children, }) {
48
71
  children));
49
72
  }
50
73
 
51
- function Ui89Button({ theme = Ui89Theme.primary, size = "normal", block, onClick, href, children, autoDisableOnClick = true, disabled, activated, routerPush, }) {
52
- //const router = useRouter()
74
+ function Ui89Button({ theme = Ui89Theme.primary, size = "normal", block, onClick, href, children, autoDisableOnClick = true, disabled, activated, }) {
75
+ const overrides = useUi89Overrides();
53
76
  const [clicking, setClicking] = useState(false);
54
77
  let localDisabled = disabled || (autoDisableOnClick && clicking);
55
78
  async function onAnchorClick(e) {
@@ -65,9 +88,9 @@ function Ui89Button({ theme = Ui89Theme.primary, size = "normal", block, onClick
65
88
  setClicking(true);
66
89
  if (href !== undefined) {
67
90
  if (href.startsWith("/")) {
68
- if (routerPush !== undefined) {
91
+ if (overrides.routerPush !== undefined) {
69
92
  e.preventDefault();
70
- routerPush(href);
93
+ overrides.routerPush(href);
71
94
  }
72
95
  }
73
96
  }
@@ -110,7 +133,7 @@ function Ui89Button({ theme = Ui89Theme.primary, size = "normal", block, onClick
110
133
  if (href) {
111
134
  return (React__default.createElement("span", { className: styles$e.container },
112
135
  React__default.createElement(HoverShadow, null,
113
- React__default.createElement("a", { className: buttonClass, href: href, onClick: onAnchorClick },
136
+ React__default.createElement("a", { className: buttonClass, role: "button", href: href, onClick: onAnchorClick },
114
137
  React__default.createElement("span", { className: styles$e.click }),
115
138
  children))));
116
139
  }
@@ -31447,5 +31470,5 @@ function Ui89VirtualTable(props) {
31447
31470
  React__default.createElement(Ui89TagBox, { theme: "warn" }, "Empty")))));
31448
31471
  }
31449
31472
 
31450
- export { Ui89Breadcrumbs, Ui89Button, Ui89Card, Ui89HighlightText, Ui89InputText, Ui89InputTextNumber, Ui89Look, Ui89MenuBar, Ui89ModalDialog, Ui89Scene, Ui89Shortcut, Ui89SpaceVertical, Ui89TabbedCard, Ui89Tabs, Ui89TagBox, Ui89Theme, Ui89ThemeBackground, Ui89TitleBox, Ui89TitleUnderline, Ui89VirtualTable };
31473
+ export { Ui89Breadcrumbs, Ui89Button, Ui89Card, Ui89HighlightText, Ui89InputText, Ui89InputTextNumber, Ui89Look, Ui89MenuBar, Ui89ModalDialog, Ui89OverrideProvider, Ui89Scene, Ui89Shortcut, Ui89SpaceVertical, Ui89TabbedCard, Ui89Tabs, Ui89TagBox, Ui89Theme, Ui89ThemeBackground, Ui89TitleBox, Ui89TitleUnderline, Ui89VirtualTable };
31451
31474
  //# sourceMappingURL=index.js.map