@uxf/ui 1.0.0-beta.22 → 1.0.0-beta.23
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/button/button.d.ts +15 -0
- package/button/button.jsx +17 -0
- package/button/button.stories.d.ts +10 -0
- package/button/button.stories.jsx +59 -0
- package/button/index.d.ts +2 -0
- package/button/index.js +23 -0
- package/button/theme.d.ts +18 -0
- package/{avatar → button}/theme.js +0 -0
- package/dropdown/dropdown.d.ts +10 -0
- package/dropdown/dropdown.jsx +26 -0
- package/dropdown/index.d.ts +1 -0
- package/dropdown/index.js +5 -0
- package/error-message/error-message.d.ts +7 -0
- package/error-message/error-message.jsx +8 -0
- package/{avatar/avatar.stories.d.ts → error-message/error-message.stories.d.ts} +2 -2
- package/error-message/error-message.stories.jsx +14 -0
- package/error-message/index.d.ts +1 -0
- package/error-message/index.js +8 -0
- package/hooks/use-dropdown.d.ts +7 -0
- package/hooks/use-dropdown.js +37 -0
- package/image-gallery/components/close-button.d.ts +6 -0
- package/image-gallery/components/close-button.jsx +13 -0
- package/image-gallery/components/dot.d.ts +6 -0
- package/image-gallery/components/dot.jsx +12 -0
- package/image-gallery/components/gallery.d.ts +11 -0
- package/image-gallery/components/gallery.jsx +74 -0
- package/image-gallery/components/icon-chevron-left.d.ts +3 -0
- package/image-gallery/components/icon-chevron-left.jsx +12 -0
- package/image-gallery/components/icon-chevron-right.d.ts +3 -0
- package/image-gallery/components/icon-chevron-right.jsx +12 -0
- package/image-gallery/components/icon-close.d.ts +3 -0
- package/image-gallery/components/icon-close.jsx +12 -0
- package/image-gallery/components/next-button.d.ts +6 -0
- package/image-gallery/components/next-button.jsx +13 -0
- package/image-gallery/components/previous-button.d.ts +6 -0
- package/image-gallery/components/previous-button.jsx +13 -0
- package/image-gallery/context.d.ts +10 -0
- package/image-gallery/context.jsx +12 -0
- package/image-gallery/image-gallery.d.ts +6 -0
- package/image-gallery/image-gallery.jsx +58 -0
- package/image-gallery/image-gallery.stories.d.ts +13 -0
- package/image-gallery/image-gallery.stories.jsx +29 -0
- package/image-gallery/image.d.ts +4 -0
- package/image-gallery/image.jsx +12 -0
- package/image-gallery/index.d.ts +3 -0
- package/image-gallery/index.js +25 -0
- package/image-gallery/types.d.ts +6 -0
- package/image-gallery/types.js +2 -0
- package/image-gallery/use-image.d.ts +2 -0
- package/image-gallery/use-image.js +16 -0
- package/input/index.d.ts +13 -0
- package/input/index.js +19 -0
- package/input/input-element.d.ts +8 -0
- package/input/input-element.jsx +11 -0
- package/input/input-left-addon.d.ts +6 -0
- package/input/input-left-addon.jsx +10 -0
- package/input/input-left-element.d.ts +6 -0
- package/input/input-left-element.jsx +10 -0
- package/input/input-right-addon.d.ts +6 -0
- package/input/input-right-addon.jsx +10 -0
- package/input/input-right-element.d.ts +6 -0
- package/input/input-right-element.jsx +10 -0
- package/input/input.d.ts +9 -0
- package/input/input.jsx +65 -0
- package/input/input.stories.d.ts +14 -0
- package/input/input.stories.jsx +78 -0
- package/input/theme.d.ts +6 -0
- package/input/theme.js +2 -0
- package/label/index.d.ts +1 -0
- package/label/index.js +8 -0
- package/label/label.d.ts +9 -0
- package/label/label.jsx +9 -0
- package/label/label.stories.d.ts +7 -0
- package/label/label.stories.jsx +14 -0
- package/package.json +3 -4
- package/select/index.d.ts +1 -0
- package/select/index.js +8 -0
- package/select/select.d.ts +27 -0
- package/select/select.jsx +47 -0
- package/select/select.stories.d.ts +8 -0
- package/select/select.stories.jsx +22 -0
- package/text-input/index.d.ts +1 -0
- package/text-input/index.js +17 -0
- package/text-input/text-input.d.ts +22 -0
- package/text-input/text-input.jsx +32 -0
- package/text-input/text-input.stories.d.ts +9 -0
- package/text-input/text-input.stories.jsx +55 -0
- package/types/form-control-props.d.ts +24 -0
- package/types/form-control-props.js +2 -0
- package/types/index.d.ts +1 -0
- package/types/index.js +17 -0
- package/utils/action.d.ts +2 -0
- package/utils/action.js +11 -0
- package/utils/component-structure-analyzer.d.ts +6 -0
- package/utils/component-structure-analyzer.jsx +10 -0
- package/utils/cx.d.ts +3 -0
- package/utils/cx.js +54 -0
- package/utils/forwardRef.d.ts +12 -0
- package/utils/forwardRef.js +10 -0
- package/utils/storybook-config.d.ts +19 -0
- package/utils/storybook-config.jsx +47 -0
- package/avatar/avatar.d.ts +0 -14
- package/avatar/avatar.jsx +0 -10
- package/avatar/avatar.stories.jsx +0 -29
- package/avatar/theme.d.ts +0 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ButtonColors, ButtonSizes, ButtonVariants } from "@uxf/ui/button";
|
|
3
|
+
interface ButtonProps {
|
|
4
|
+
variant?: keyof ButtonVariants;
|
|
5
|
+
color?: keyof ButtonColors;
|
|
6
|
+
size?: keyof ButtonSizes;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
loading?: boolean;
|
|
9
|
+
startAdornment?: ReactNode;
|
|
10
|
+
endAdornment?: ReactNode;
|
|
11
|
+
type?: "button" | "submit" | "reset";
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
declare function Button(props: ButtonProps): JSX.Element;
|
|
15
|
+
export default Button;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const cx_1 = require("@uxf/core/utils/cx");
|
|
8
|
+
function Button(props) {
|
|
9
|
+
var _a, _b, _c;
|
|
10
|
+
const className = (0, cx_1.cx)("button", `button--color-${(_a = props.color) !== null && _a !== void 0 ? _a : "default"}`, `button--size-${(_b = props.size) !== null && _b !== void 0 ? _b : "default"}`, `button--variant-${(_c = props.variant) !== null && _c !== void 0 ? _c : "default"}`, props.disabled && `button--disabled`, props.loading && `button--loading`);
|
|
11
|
+
return (<button type={props.type} className={className}>
|
|
12
|
+
{props.startAdornment}
|
|
13
|
+
{props.children}
|
|
14
|
+
{props.endAdornment}
|
|
15
|
+
</button>);
|
|
16
|
+
}
|
|
17
|
+
exports.default = Button;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Button } from "@uxf/ui/button";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: typeof Button;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare function Default(): JSX.Element;
|
|
9
|
+
export declare function Disabled(): JSX.Element;
|
|
10
|
+
export declare function Loading(): JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Loading = exports.Disabled = exports.Default = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const button_1 = require("@uxf/ui/button");
|
|
9
|
+
const storybook_config_1 = require("@uxf/ui/utils/storybook-config");
|
|
10
|
+
const react_2 = require("react");
|
|
11
|
+
exports.default = {
|
|
12
|
+
title: "UI/Button",
|
|
13
|
+
component: button_1.Button,
|
|
14
|
+
};
|
|
15
|
+
function Default() {
|
|
16
|
+
const config = (0, storybook_config_1.useStorybookConfig)("Button");
|
|
17
|
+
return (<div className="space-y-2">
|
|
18
|
+
{config.variants.map((variant) => (<react_2.Fragment key={variant}>
|
|
19
|
+
{config.colors.map((color) => (<react_2.Fragment key={color}>
|
|
20
|
+
{config.sizes.map((size) => (<div>
|
|
21
|
+
<button_1.Button key={size} variant={variant} color={color} size={size}>
|
|
22
|
+
Button
|
|
23
|
+
</button_1.Button>
|
|
24
|
+
</div>))}
|
|
25
|
+
</react_2.Fragment>))}
|
|
26
|
+
</react_2.Fragment>))}
|
|
27
|
+
</div>);
|
|
28
|
+
}
|
|
29
|
+
exports.Default = Default;
|
|
30
|
+
function Disabled() {
|
|
31
|
+
const config = (0, storybook_config_1.useStorybookConfig)("Button");
|
|
32
|
+
return (<div className="space-y-2">
|
|
33
|
+
{config.variants.map((variant) => (<react_2.Fragment key={variant}>
|
|
34
|
+
{config.colors.map((color) => (<react_2.Fragment key={color}>
|
|
35
|
+
{config.sizes.map((size) => (<div>
|
|
36
|
+
<button_1.Button key={size} variant={variant} color={color} size={size} disabled>
|
|
37
|
+
Button
|
|
38
|
+
</button_1.Button>
|
|
39
|
+
</div>))}
|
|
40
|
+
</react_2.Fragment>))}
|
|
41
|
+
</react_2.Fragment>))}
|
|
42
|
+
</div>);
|
|
43
|
+
}
|
|
44
|
+
exports.Disabled = Disabled;
|
|
45
|
+
function Loading() {
|
|
46
|
+
const config = (0, storybook_config_1.useStorybookConfig)("Button");
|
|
47
|
+
return (<div className="space-y-2">
|
|
48
|
+
{config.variants.map((variant) => (<react_2.Fragment key={variant}>
|
|
49
|
+
{config.colors.map((color) => (<react_2.Fragment key={color}>
|
|
50
|
+
{config.sizes.map((size) => (<div>
|
|
51
|
+
<button_1.Button key={size} variant={variant} color={color} size={size} loading>
|
|
52
|
+
Button
|
|
53
|
+
</button_1.Button>
|
|
54
|
+
</div>))}
|
|
55
|
+
</react_2.Fragment>))}
|
|
56
|
+
</react_2.Fragment>))}
|
|
57
|
+
</div>);
|
|
58
|
+
}
|
|
59
|
+
exports.Loading = Loading;
|
package/button/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Button = void 0;
|
|
21
|
+
var button_1 = require("@uxf/ui/button/button");
|
|
22
|
+
Object.defineProperty(exports, "Button", { enumerable: true, get: function () { return __importDefault(button_1).default; } });
|
|
23
|
+
__exportStar(require("@uxf/ui/button/theme"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ButtonVariants {
|
|
2
|
+
outlined: true;
|
|
3
|
+
default: true;
|
|
4
|
+
}
|
|
5
|
+
export interface ButtonSizes {
|
|
6
|
+
xs: true;
|
|
7
|
+
sm: true;
|
|
8
|
+
default: true;
|
|
9
|
+
lg: true;
|
|
10
|
+
xl: true;
|
|
11
|
+
}
|
|
12
|
+
export interface ButtonColors {
|
|
13
|
+
default: true;
|
|
14
|
+
white: true;
|
|
15
|
+
success: true;
|
|
16
|
+
warning: true;
|
|
17
|
+
error: true;
|
|
18
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { UseAnchorProps } from "@uxf/core/hooks/useAnchorProps";
|
|
2
|
+
import { AnchorHTMLAttributes, HTMLAttributes } from "react";
|
|
3
|
+
interface ItemProps extends AnchorHTMLAttributes<HTMLAnchorElement>, UseAnchorProps {
|
|
4
|
+
}
|
|
5
|
+
declare type ItemsProps = HTMLAttributes<HTMLDivElement>;
|
|
6
|
+
export declare const Dropdown: {
|
|
7
|
+
Item: import("react").ForwardRefExoticComponent<ItemProps & import("react").RefAttributes<HTMLAnchorElement>>;
|
|
8
|
+
Items: import("react").ForwardRefExoticComponent<ItemsProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
|
+
};
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Dropdown = void 0;
|
|
4
|
+
const useAnchorProps_1 = require("@uxf/core/hooks/useAnchorProps");
|
|
5
|
+
const forwardRef_1 = require("@uxf/ui/utils/forwardRef");
|
|
6
|
+
function Item(props, ref) {
|
|
7
|
+
const { children, className, ...restProps } = props;
|
|
8
|
+
const anchorProps = (0, useAnchorProps_1.useAnchorProps)({
|
|
9
|
+
className: `uxf-dropdown-item ${className || ""}`,
|
|
10
|
+
role: "menuitem",
|
|
11
|
+
...restProps,
|
|
12
|
+
});
|
|
13
|
+
return (<a ref={ref} {...anchorProps}>
|
|
14
|
+
{children}
|
|
15
|
+
</a>);
|
|
16
|
+
}
|
|
17
|
+
function Items(props, ref) {
|
|
18
|
+
const { children, className, role = "menu", ...restProps } = props;
|
|
19
|
+
return (<div className={`uxf-dropdown-items`} ref={ref} role={role} {...restProps}>
|
|
20
|
+
{children}
|
|
21
|
+
</div>);
|
|
22
|
+
}
|
|
23
|
+
exports.Dropdown = {
|
|
24
|
+
Item: (0, forwardRef_1.forwardRef)("Item.", Item),
|
|
25
|
+
Items: (0, forwardRef_1.forwardRef)("Items", Items),
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Dropdown } from "./dropdown";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ErrorMessage } from "./index";
|
|
3
3
|
declare const _default: {
|
|
4
4
|
title: string;
|
|
5
|
-
component: typeof
|
|
5
|
+
component: typeof ErrorMessage;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
8
8
|
export declare function Default(): JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Default = void 0;
|
|
4
|
+
const index_1 = require("./index");
|
|
5
|
+
exports.default = {
|
|
6
|
+
title: "UI/ErrorMessage",
|
|
7
|
+
component: index_1.ErrorMessage,
|
|
8
|
+
};
|
|
9
|
+
function Default() {
|
|
10
|
+
return (<div className="space-y-2">
|
|
11
|
+
<index_1.ErrorMessage>This field is required.</index_1.ErrorMessage>
|
|
12
|
+
</div>);
|
|
13
|
+
}
|
|
14
|
+
exports.Default = Default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as ErrorMessage } from "./error-message";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ErrorMessage = void 0;
|
|
7
|
+
var error_message_1 = require("./error-message");
|
|
8
|
+
Object.defineProperty(exports, "ErrorMessage", { enumerable: true, get: function () { return __importDefault(error_message_1).default; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Placement } from "@floating-ui/react-dom";
|
|
2
|
+
import { CSSProperties } from "react";
|
|
3
|
+
export declare function useDropdown(placement: Placement, matchWidth?: boolean): {
|
|
4
|
+
floating: (node: HTMLElement | null) => void;
|
|
5
|
+
reference: (node: (Element | import("@floating-ui/core").VirtualElement) | null) => void;
|
|
6
|
+
style: Partial<CSSProperties>;
|
|
7
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useDropdown = void 0;
|
|
4
|
+
const react_dom_1 = require("@floating-ui/react-dom");
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
function useDropdown(placement, matchWidth = false) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const [sizeData, setSizeData] = (0, react_1.useState)(null);
|
|
9
|
+
const { floating, reference, refs, strategy, update, x, y } = (0, react_dom_1.useFloating)({
|
|
10
|
+
placement,
|
|
11
|
+
middleware: [
|
|
12
|
+
(0, react_dom_1.flip)(),
|
|
13
|
+
(0, react_dom_1.shift)(),
|
|
14
|
+
(0, react_dom_1.size)({
|
|
15
|
+
apply: setSizeData,
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
});
|
|
19
|
+
(0, react_1.useEffect)(() => {
|
|
20
|
+
if (!refs.reference.current || !refs.floating.current) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return (0, react_dom_1.autoUpdate)(refs.reference.current, refs.floating.current, update);
|
|
24
|
+
}, [refs.reference, refs.floating, update]);
|
|
25
|
+
return {
|
|
26
|
+
floating,
|
|
27
|
+
reference,
|
|
28
|
+
style: {
|
|
29
|
+
left: x !== null && x !== void 0 ? x : undefined,
|
|
30
|
+
maxHeight: (_a = sizeData === null || sizeData === void 0 ? void 0 : sizeData.height) !== null && _a !== void 0 ? _a : undefined,
|
|
31
|
+
maxWidth: matchWidth ? (_b = sizeData === null || sizeData === void 0 ? void 0 : sizeData.reference.width) !== null && _b !== void 0 ? _b : undefined : undefined,
|
|
32
|
+
position: strategy,
|
|
33
|
+
top: y !== null && y !== void 0 ? y : undefined,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.useDropdown = useDropdown;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const icon_close_1 = __importDefault(require("./icon-close"));
|
|
8
|
+
function CloseButton(props) {
|
|
9
|
+
return (<button className="bg-black bg-opacity-50 p-3" onClick={() => props.onClick()}>
|
|
10
|
+
<icon_close_1.default />
|
|
11
|
+
</button>);
|
|
12
|
+
}
|
|
13
|
+
exports.default = CloseButton;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const cx_1 = require("@uxf/core/utils/cx");
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
function Dot(props) {
|
|
9
|
+
const className = (0, cx_1.cx)("h-2 w-2 rounded-full", props.active ? "bg-gray-500" : "bg-white");
|
|
10
|
+
return <div className={className}/>;
|
|
11
|
+
}
|
|
12
|
+
exports.default = Dot;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ImageGalleryImageProps } from "../types";
|
|
3
|
+
interface GalleryProps {
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
onNext: () => void;
|
|
6
|
+
onPrevious: () => void;
|
|
7
|
+
imageIndex: number;
|
|
8
|
+
images: ImageGalleryImageProps[];
|
|
9
|
+
}
|
|
10
|
+
declare function Gallery(props: GalleryProps): JSX.Element;
|
|
11
|
+
export default Gallery;
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const close_button_1 = __importDefault(require("./close-button"));
|
|
30
|
+
const previous_button_1 = __importDefault(require("./previous-button"));
|
|
31
|
+
const next_button_1 = __importDefault(require("./next-button"));
|
|
32
|
+
const dot_1 = __importDefault(require("./dot"));
|
|
33
|
+
const react_1 = __importStar(require("react"));
|
|
34
|
+
function Gallery(props) {
|
|
35
|
+
(0, react_1.useEffect)(() => {
|
|
36
|
+
const onKeyDown = (event) => {
|
|
37
|
+
switch (event.key) {
|
|
38
|
+
case "ArrowRight":
|
|
39
|
+
props.onNext();
|
|
40
|
+
break;
|
|
41
|
+
case "ArrowLeft":
|
|
42
|
+
props.onPrevious();
|
|
43
|
+
break;
|
|
44
|
+
case "Escape":
|
|
45
|
+
props.onClose();
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
document.body.style.overflow = "hidden";
|
|
50
|
+
window.addEventListener("keydown", onKeyDown);
|
|
51
|
+
return () => {
|
|
52
|
+
document.body.style.overflow = "auto";
|
|
53
|
+
window.removeEventListener("keydown", onKeyDown);
|
|
54
|
+
};
|
|
55
|
+
}, []);
|
|
56
|
+
return (<div className="fixed inset-0 top-0 bottom-0 z-50 flex flex-col bg-black bg-opacity-75 transition-opacity">
|
|
57
|
+
<div className="flex justify-end">
|
|
58
|
+
<close_button_1.default onClick={props.onClose}/>
|
|
59
|
+
</div>
|
|
60
|
+
<div className="container mx-auto flex h-full flex-1 flex-col">
|
|
61
|
+
<div className="relative flex flex-1 items-center justify-center">
|
|
62
|
+
<img className="absolute left-0 right-0 top-0 h-full w-full object-contain" src={props.images[props.imageIndex].src}/>
|
|
63
|
+
<div className="pointer-events-none absolute inset-0 flex items-center justify-between p-2">
|
|
64
|
+
<previous_button_1.default onClick={props.onPrevious}/>
|
|
65
|
+
<next_button_1.default onClick={props.onNext}/>
|
|
66
|
+
</div>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
69
|
+
<div className="row mx-auto flex space-x-2 p-4">
|
|
70
|
+
{props.images.map((url, index) => (<dot_1.default key={url.src} active={index === props.imageIndex}/>))}
|
|
71
|
+
</div>
|
|
72
|
+
</div>);
|
|
73
|
+
}
|
|
74
|
+
exports.default = Gallery;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
function IconChevronLeft() {
|
|
8
|
+
return (<svg xmlns="http://www.w3.org/2000/svg" className="h-10 w-10 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
9
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7"/>
|
|
10
|
+
</svg>);
|
|
11
|
+
}
|
|
12
|
+
exports.default = IconChevronLeft;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
function IconChevronRight() {
|
|
8
|
+
return (<svg xmlns="http://www.w3.org/2000/svg" className="h-10 w-10 text-white" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
|
|
9
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7"/>
|
|
10
|
+
</svg>);
|
|
11
|
+
}
|
|
12
|
+
exports.default = IconChevronRight;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
function IconClose() {
|
|
8
|
+
return (<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2} className="h-10 w-10 text-white">
|
|
9
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18L18 6M6 6l12 12"/>
|
|
10
|
+
</svg>);
|
|
11
|
+
}
|
|
12
|
+
exports.default = IconClose;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const icon_chevron_right_1 = __importDefault(require("./icon-chevron-right"));
|
|
8
|
+
function NextButton(props) {
|
|
9
|
+
return (<button className="pointer-events-auto rounded-full bg-black bg-opacity-50 p-2" onClick={props.onClick}>
|
|
10
|
+
<icon_chevron_right_1.default />
|
|
11
|
+
</button>);
|
|
12
|
+
}
|
|
13
|
+
exports.default = NextButton;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_1 = __importDefault(require("react"));
|
|
7
|
+
const icon_chevron_left_1 = __importDefault(require("./icon-chevron-left"));
|
|
8
|
+
function PreviousButton(props) {
|
|
9
|
+
return (<button className="pointer-events-auto rounded-full bg-black bg-opacity-50 p-2" onClick={props.onClick}>
|
|
10
|
+
<icon_chevron_left_1.default />
|
|
11
|
+
</button>);
|
|
12
|
+
}
|
|
13
|
+
exports.default = PreviousButton;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ImageGalleryImageProps } from "./types";
|
|
3
|
+
declare type ContextType = {
|
|
4
|
+
registerImage: (props: ImageGalleryImageProps) => void;
|
|
5
|
+
unregisterImage: (props: ImageGalleryImageProps) => void;
|
|
6
|
+
openGallery: (props: ImageGalleryImageProps) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const ImageGalleryProvider: import("react").Provider<ContextType>;
|
|
9
|
+
export declare const useImageGalleryContext: () => ContextType;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useImageGalleryContext = exports.ImageGalleryProvider = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const ImageGalleryContext = (0, react_1.createContext)({
|
|
6
|
+
registerImage: () => null,
|
|
7
|
+
unregisterImage: () => null,
|
|
8
|
+
openGallery: () => null,
|
|
9
|
+
});
|
|
10
|
+
exports.ImageGalleryProvider = ImageGalleryContext.Provider;
|
|
11
|
+
const useImageGalleryContext = () => (0, react_1.useContext)(ImageGalleryContext);
|
|
12
|
+
exports.useImageGalleryContext = useImageGalleryContext;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const react_1 = __importStar(require("react"));
|
|
30
|
+
const context_1 = require("./context");
|
|
31
|
+
const gallery_1 = __importDefault(require("./components/gallery"));
|
|
32
|
+
function ImageGallery(props) {
|
|
33
|
+
const [images, setImages] = (0, react_1.useState)([]);
|
|
34
|
+
const [imageIndex, setImageIndex] = (0, react_1.useState)(null);
|
|
35
|
+
const registerImage = (image) => setImages((v) => [...v, image]);
|
|
36
|
+
const unregisterImage = (image) => setImages((v) => v.filter((u) => u.src !== image.src));
|
|
37
|
+
const openGallery = (image) => setImageIndex(images.findIndex((i) => i.src === image.src));
|
|
38
|
+
const onPrevious = (0, react_1.useCallback)(() => {
|
|
39
|
+
setImageIndex((v) => (v === null ? null : v - 1));
|
|
40
|
+
}, []);
|
|
41
|
+
const onNext = (0, react_1.useCallback)(() => {
|
|
42
|
+
setImageIndex((v) => (v === null ? null : v + 1));
|
|
43
|
+
}, []);
|
|
44
|
+
// modulo bug https://stackoverflow.com/a/4467559
|
|
45
|
+
const moduloImageIndex = imageIndex === null
|
|
46
|
+
? null
|
|
47
|
+
: imageIndex < 0
|
|
48
|
+
? ((imageIndex % images.length) + images.length) % images.length
|
|
49
|
+
: imageIndex % images.length;
|
|
50
|
+
const contextValue = { registerImage, unregisterImage, openGallery };
|
|
51
|
+
return (<>
|
|
52
|
+
<context_1.ImageGalleryProvider value={contextValue}>
|
|
53
|
+
{props.children}
|
|
54
|
+
</context_1.ImageGalleryProvider>
|
|
55
|
+
{typeof moduloImageIndex === "number" && (<gallery_1.default onClose={() => setImageIndex(null)} onNext={onNext} onPrevious={onPrevious} imageIndex={moduloImageIndex} images={images}/>)}
|
|
56
|
+
</>);
|
|
57
|
+
}
|
|
58
|
+
exports.default = ImageGallery;
|