@adamjanicki/ui 1.5.4 → 1.5.6
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/components/Alert/Alert.d.ts +3 -15
- package/components/Alert/Alert.js +1 -1
- package/components/Animated/Animated.d.ts +19 -27
- package/components/Animated/Animated.js +54 -19
- package/components/Badge/Badge.d.ts +3 -16
- package/components/Badge/Badge.js +1 -1
- package/components/Banner/Banner.d.ts +3 -15
- package/components/Banner/Banner.js +1 -1
- package/components/Button/Button.d.ts +4 -8
- package/components/Button/Button.js +2 -2
- package/components/Carousel/Carousel.d.ts +56 -0
- package/components/Carousel/Carousel.js +87 -0
- package/components/Carousel/index.d.ts +2 -0
- package/components/Carousel/index.js +2 -0
- package/components/ClickOutside/ClickOutside.d.ts +4 -4
- package/components/ClickOutside/ClickOutside.js +14 -13
- package/components/Hamburger/Hamburger.d.ts +6 -5
- package/components/InlineCode/InlineCode.d.ts +13 -0
- package/components/InlineCode/InlineCode.js +50 -0
- package/components/InlineCode/index.d.ts +2 -0
- package/components/InlineCode/index.js +2 -0
- package/components/Input/IconInput.d.ts +2 -2
- package/components/Input/IconInput.js +1 -1
- package/components/Input/Input.d.ts +1 -1
- package/components/Input/Input.js +1 -1
- package/components/Input/TextArea.d.ts +1 -1
- package/components/Input/TextArea.js +1 -1
- package/components/Layer/Layer.d.ts +4 -11
- package/components/Layer/Layer.js +1 -1
- package/components/Link/Link.d.ts +2 -4
- package/components/Link/Link.js +2 -2
- package/components/Select/Select.d.ts +2 -13
- package/components/Select/Select.js +2 -3
- package/components/Spinner/Spinner.d.ts +2 -2
- package/functions/scrollToId.js +1 -1
- package/hooks/useFocusTrap.d.ts +1 -1
- package/index.d.ts +13 -9
- package/index.js +15 -9
- package/package.json +8 -28
- package/style.css +124 -77
- package/types/index.d.ts +9 -0
|
@@ -1,27 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ContentType, CornerType } from "../../types";
|
|
3
|
-
type Props = {
|
|
2
|
+
import type { ContentType, CornerType, DivProps } from "../../types";
|
|
3
|
+
type Props = DivProps & {
|
|
4
4
|
/**
|
|
5
5
|
* The type of alert to display.
|
|
6
6
|
*/
|
|
7
7
|
type: ContentType;
|
|
8
|
-
/**
|
|
9
|
-
* The content to display in the alert.
|
|
10
|
-
*/
|
|
11
|
-
children: React.ReactNode | React.ReactNode[];
|
|
12
|
-
/**
|
|
13
|
-
* [Optional] Additional class names to apply to the alert.
|
|
14
|
-
*/
|
|
15
|
-
className?: string;
|
|
16
|
-
/**
|
|
17
|
-
* [Optional] Additional styles to apply to the alert.
|
|
18
|
-
*/
|
|
19
|
-
style?: React.CSSProperties;
|
|
20
8
|
/**
|
|
21
9
|
* [Optional] The corner style of the alert.
|
|
22
10
|
* @default "rounded"
|
|
23
11
|
*/
|
|
24
12
|
corners?: CornerType;
|
|
25
13
|
};
|
|
26
|
-
declare const Alert: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
declare const Alert: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
27
15
|
export default Alert;
|
|
@@ -25,6 +25,6 @@ import React from "react";
|
|
|
25
25
|
import classNames from "../../functions/classNames";
|
|
26
26
|
var Alert = React.forwardRef(function (_a, ref) {
|
|
27
27
|
var type = _a.type, className = _a.className, _b = _a.corners, corners = _b === void 0 ? "rounded" : _b, rest = __rest(_a, ["type", "className", "corners"]);
|
|
28
|
-
return (_jsx("div", __assign({ className: classNames("ajui-alert content--".concat(type, " corners--").concat(corners), className), ref: ref }
|
|
28
|
+
return (_jsx("div", __assign({}, rest, { className: classNames("ajui-alert ajui-content--".concat(type, " ajui-corners--").concat(corners), className), ref: ref })));
|
|
29
29
|
});
|
|
30
30
|
export default Alert;
|
|
@@ -1,52 +1,44 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
type
|
|
2
|
+
import type { DivProps, Style } from "../../types";
|
|
3
|
+
type Props = DivProps & {
|
|
3
4
|
/**
|
|
4
|
-
* Whether
|
|
5
|
+
* Whether to begin the animation.
|
|
6
|
+
* Set to true to start animation, false to start the exit animation.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
animated: boolean;
|
|
7
9
|
/**
|
|
8
|
-
* Duration of the animation in
|
|
10
|
+
* Duration of the animation in seconds
|
|
11
|
+
* @default 0.25
|
|
9
12
|
*/
|
|
10
13
|
duration?: number;
|
|
11
14
|
/**
|
|
12
|
-
* Whether to keep the component mounted when it is not
|
|
15
|
+
* Whether to keep the component mounted when it is not animated
|
|
16
|
+
* @default false
|
|
13
17
|
*/
|
|
14
|
-
|
|
18
|
+
keepMounted?: boolean;
|
|
15
19
|
/**
|
|
16
20
|
* Animation configuration for the enter state
|
|
17
21
|
*/
|
|
18
|
-
|
|
22
|
+
animateTo?: {
|
|
19
23
|
/**
|
|
20
|
-
* Class name to apply to the component
|
|
24
|
+
* Class name to apply to the component while animated (after state)
|
|
21
25
|
*/
|
|
22
26
|
className?: string;
|
|
23
27
|
/**
|
|
24
|
-
* Inline styles to apply to the component
|
|
28
|
+
* Inline styles to apply to the component while animated
|
|
25
29
|
*/
|
|
26
|
-
style?:
|
|
30
|
+
style?: Style;
|
|
27
31
|
};
|
|
28
|
-
|
|
32
|
+
animateFrom?: {
|
|
29
33
|
/**
|
|
30
|
-
* Class name to apply to the component
|
|
34
|
+
* Class name to apply to the component when not animated (before state)
|
|
31
35
|
*/
|
|
32
36
|
className?: string;
|
|
33
37
|
/**
|
|
34
|
-
* Inline styles to apply to the component
|
|
38
|
+
* Inline styles to apply to the component when not animated
|
|
35
39
|
*/
|
|
36
|
-
style?:
|
|
40
|
+
style?: Style;
|
|
37
41
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Children to render
|
|
40
|
-
*/
|
|
41
|
-
children: React.ReactNode | React.ReactNode[];
|
|
42
|
-
/**
|
|
43
|
-
* [Optional] className to apply to the component always
|
|
44
|
-
*/
|
|
45
|
-
className?: string;
|
|
46
|
-
/**
|
|
47
|
-
* [Optional] Inline styles to apply to the component always
|
|
48
|
-
*/
|
|
49
|
-
style?: React.CSSProperties;
|
|
50
42
|
};
|
|
51
|
-
declare const Animated:
|
|
43
|
+
declare const Animated: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
52
44
|
export default Animated;
|
|
@@ -9,31 +9,66 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
12
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { useState, useEffect } from "react";
|
|
24
|
+
import React, { useState, useEffect, useRef } from "react";
|
|
14
25
|
import classNames from "../../functions/classNames";
|
|
15
|
-
var Animated = function (
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
26
|
+
var Animated = React.forwardRef(function (props, ref) {
|
|
27
|
+
var animated = props.animated, _a = props.duration, duration = _a === void 0 ? 0.25 : _a, _b = props.keepMounted, keepMounted = _b === void 0 ? false : _b, animateTo = props.animateTo, animateFrom = props.animateFrom, children = props.children, className = props.className, style = props.style, rest = __rest(props, ["animated", "duration", "keepMounted", "animateTo", "animateFrom", "children", "className", "style"]);
|
|
28
|
+
var _c = useState(animated || keepMounted), shouldRender = _c[0], setShouldRender = _c[1];
|
|
29
|
+
var _d = useState(false), isAnimatingForward = _d[0], setIsAnimatingForward = _d[1];
|
|
30
|
+
var timeoutRef = useRef(null);
|
|
31
|
+
var animationFrameRef = useRef(null);
|
|
32
|
+
var clearRefs = function () {
|
|
33
|
+
if (timeoutRef.current) {
|
|
34
|
+
clearTimeout(timeoutRef.current);
|
|
35
|
+
timeoutRef.current = null;
|
|
36
|
+
}
|
|
37
|
+
if (animationFrameRef.current) {
|
|
38
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
39
|
+
animationFrameRef.current = null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
useEffect(function () {
|
|
43
|
+
// initiate forward animation
|
|
44
|
+
if (animated && shouldRender) {
|
|
45
|
+
clearRefs();
|
|
46
|
+
animationFrameRef.current = requestAnimationFrame(function () {
|
|
47
|
+
return setIsAnimatingForward(true);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return clearRefs;
|
|
51
|
+
}, [animated, shouldRender]);
|
|
19
52
|
useEffect(function () {
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
// Start enter animation
|
|
53
|
+
// make container element appear on DOM
|
|
54
|
+
if (animated) {
|
|
23
55
|
setShouldRender(true);
|
|
24
|
-
setAnimationState("entering");
|
|
25
56
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
57
|
+
// initiate reverse animation
|
|
58
|
+
else {
|
|
59
|
+
clearRefs();
|
|
60
|
+
setIsAnimatingForward(false);
|
|
61
|
+
timeoutRef.current = window.setTimeout(function () {
|
|
62
|
+
if (!keepMounted) {
|
|
31
63
|
setShouldRender(false);
|
|
32
64
|
}
|
|
33
|
-
}, duration);
|
|
65
|
+
}, duration * 1000);
|
|
34
66
|
}
|
|
35
|
-
return
|
|
36
|
-
}, [
|
|
37
|
-
|
|
38
|
-
|
|
67
|
+
return clearRefs;
|
|
68
|
+
}, [animated, duration, keepMounted]);
|
|
69
|
+
if (!shouldRender)
|
|
70
|
+
return null;
|
|
71
|
+
var currentAnimation = isAnimatingForward ? animateTo : animateFrom;
|
|
72
|
+
return (_jsx("div", __assign({ className: classNames(className, currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.className), style: __assign(__assign({ transition: "all ".concat(duration, "s ease-in-out") }, style), currentAnimation === null || currentAnimation === void 0 ? void 0 : currentAnimation.style) }, rest, { ref: ref, children: children })));
|
|
73
|
+
});
|
|
39
74
|
export default Animated;
|
|
@@ -1,28 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ContentType, CornerType } from "../../types";
|
|
3
|
-
type Props = {
|
|
2
|
+
import type { ContentType, CornerType, DivProps } from "../../types";
|
|
3
|
+
type Props = DivProps & {
|
|
4
4
|
/**
|
|
5
5
|
* The type of badge to display.
|
|
6
6
|
*/
|
|
7
7
|
type: ContentType;
|
|
8
|
-
/**
|
|
9
|
-
* The content to display in the badge.
|
|
10
|
-
* Should be short.
|
|
11
|
-
*/
|
|
12
|
-
children: React.ReactNode | React.ReactNode[];
|
|
13
|
-
/**
|
|
14
|
-
* [Optional] Additional class names to apply to the badge.
|
|
15
|
-
*/
|
|
16
|
-
className?: string;
|
|
17
|
-
/**
|
|
18
|
-
* [Optional] Additional styles to apply to the badge.
|
|
19
|
-
*/
|
|
20
|
-
style?: React.CSSProperties;
|
|
21
8
|
/**
|
|
22
9
|
* [Optional] The corner style of the badge.
|
|
23
10
|
* @default "rounded"
|
|
24
11
|
*/
|
|
25
12
|
corners?: CornerType;
|
|
26
13
|
};
|
|
27
|
-
declare const Badge: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
14
|
+
declare const Badge: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
28
15
|
export default Badge;
|
|
@@ -25,6 +25,6 @@ import React from "react";
|
|
|
25
25
|
import classNames from "../../functions/classNames";
|
|
26
26
|
var Badge = React.forwardRef(function (_a, ref) {
|
|
27
27
|
var type = _a.type, className = _a.className, _b = _a.corners, corners = _b === void 0 ? "rounded" : _b, rest = __rest(_a, ["type", "className", "corners"]);
|
|
28
|
-
return (_jsx("div", __assign({ className: classNames("ajui-badge content--".concat(type, " corners--").concat(corners), className), ref: ref }
|
|
28
|
+
return (_jsx("div", __assign({}, rest, { className: classNames("ajui-badge ajui-content--".concat(type, " ajui-corners--").concat(corners), className), ref: ref })));
|
|
29
29
|
});
|
|
30
30
|
export default Badge;
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { ContentType } from "../../types";
|
|
3
|
-
type Props = {
|
|
2
|
+
import type { ContentType, DivProps } from "../../types";
|
|
3
|
+
type Props = DivProps & {
|
|
4
4
|
/**
|
|
5
5
|
* The type of badge to display.
|
|
6
6
|
*/
|
|
7
7
|
type: ContentType;
|
|
8
|
-
/**
|
|
9
|
-
* The content to display in the banner.
|
|
10
|
-
*/
|
|
11
|
-
children: React.ReactNode | React.ReactNode[];
|
|
12
|
-
/**
|
|
13
|
-
* [Optional] Additional class names to apply to the banner.
|
|
14
|
-
*/
|
|
15
|
-
className?: string;
|
|
16
|
-
/**
|
|
17
|
-
* [Optional] Additional styles to apply to the banner.
|
|
18
|
-
*/
|
|
19
|
-
style?: React.CSSProperties;
|
|
20
8
|
};
|
|
21
|
-
declare const Banner: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
declare const Banner: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
22
10
|
export default Banner;
|
|
@@ -25,6 +25,6 @@ import React from "react";
|
|
|
25
25
|
import classNames from "../../functions/classNames";
|
|
26
26
|
var Banner = React.forwardRef(function (_a, ref) {
|
|
27
27
|
var type = _a.type, className = _a.className, rest = __rest(_a, ["type", "className"]);
|
|
28
|
-
return (_jsx("div", __assign({ className: classNames("content--".concat(type, " ajui-banner"), className), ref: ref }
|
|
28
|
+
return (_jsx("div", __assign({}, rest, { className: classNames("ajui-content--".concat(type, " ajui-banner"), className), ref: ref })));
|
|
29
29
|
});
|
|
30
30
|
export default Banner;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { CustomLinkElement } from "../Link/Link";
|
|
3
|
-
import { CornerType } from "../../types";
|
|
2
|
+
import { type CustomLinkElement } from "../Link/Link";
|
|
3
|
+
import type { CornerType } from "../../types";
|
|
4
4
|
type DefaultButtonProps = React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> & {
|
|
5
5
|
/**
|
|
6
6
|
* [Optional] This can be used as a link if the `to` prop is provided
|
|
@@ -14,11 +14,7 @@ type DefaultButtonProps = React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTM
|
|
|
14
14
|
*/
|
|
15
15
|
LinkElement?: CustomLinkElement;
|
|
16
16
|
};
|
|
17
|
-
type IconButtonProps = Omit<DefaultButtonProps, "children"
|
|
18
|
-
/**
|
|
19
|
-
* Name of the button for accessibility purposes
|
|
20
|
-
*/
|
|
21
|
-
"aria-label": string;
|
|
17
|
+
type IconButtonProps = Omit<DefaultButtonProps, "children"> & {
|
|
22
18
|
/**
|
|
23
19
|
* Icon to display inside the button
|
|
24
20
|
* I would usually use FontAwesome, but for added flexibility, it's any node
|
|
@@ -30,7 +26,7 @@ type ButtonProps = DefaultButtonProps & {
|
|
|
30
26
|
* Type of button
|
|
31
27
|
* @default "primary"
|
|
32
28
|
*/
|
|
33
|
-
variant?: "primary" | "secondary"
|
|
29
|
+
variant?: "primary" | "secondary";
|
|
34
30
|
/**
|
|
35
31
|
* Type of corners on the button
|
|
36
32
|
* @default "rounded"
|
|
@@ -30,7 +30,7 @@ export var UnstyledButton = forwardRef(function (_a, ref) {
|
|
|
30
30
|
if (to) {
|
|
31
31
|
return (_jsx(UnstyledLink, { to: to, className: className, style: props.style, role: "button", LinkElement: LinkElement, "aria-label": props["aria-label"], children: props.children }));
|
|
32
32
|
}
|
|
33
|
-
return _jsx("button", __assign({}, props, { className: className, ref: ref }));
|
|
33
|
+
return (_jsx("button", __assign({}, props, { className: classNames("ajui-action", className), ref: ref })));
|
|
34
34
|
});
|
|
35
35
|
export var IconButton = forwardRef(function (_a, ref) {
|
|
36
36
|
var icon = _a.icon, className = _a.className, props = __rest(_a, ["icon", "className"]);
|
|
@@ -38,6 +38,6 @@ export var IconButton = forwardRef(function (_a, ref) {
|
|
|
38
38
|
});
|
|
39
39
|
var Button = forwardRef(function (_a, ref) {
|
|
40
40
|
var _b = _a.variant, variant = _b === void 0 ? "primary" : _b, _c = _a.corners, corners = _c === void 0 ? "rounded" : _c, className = _a.className, _d = _a.size, size = _d === void 0 ? "regular" : _d, rest = __rest(_a, ["variant", "corners", "className", "size"]);
|
|
41
|
-
return (_jsx(UnstyledButton, __assign({}, rest, { className: classNames("ajui-button--".concat(variant, " ajui-button-size--").concat(size, " corners--").concat(corners), className), ref: ref })));
|
|
41
|
+
return (_jsx(UnstyledButton, __assign({}, rest, { className: classNames("ajui-button--".concat(variant, " ajui-button-size--").concat(size, " ajui-corners--").concat(corners), className), ref: ref })));
|
|
42
42
|
});
|
|
43
43
|
export default Button;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { DivProps, Style } from "../../types";
|
|
3
|
+
type ButtonProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Children to render inside the button
|
|
6
|
+
*/
|
|
7
|
+
children?: React.ReactNode | React.ReactNode[];
|
|
8
|
+
/**
|
|
9
|
+
* Additional class name to apply to the button
|
|
10
|
+
*/
|
|
11
|
+
className?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Additional styles to apply to the button
|
|
14
|
+
*/
|
|
15
|
+
style?: Style;
|
|
16
|
+
};
|
|
17
|
+
type Props = DivProps & {
|
|
18
|
+
/**
|
|
19
|
+
* The child elements/slides of the carousel
|
|
20
|
+
*/
|
|
21
|
+
children: React.ReactNode[];
|
|
22
|
+
/**
|
|
23
|
+
* How long the transition lasts (in seconds)
|
|
24
|
+
* @default 1
|
|
25
|
+
*/
|
|
26
|
+
duration?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The interval at which autoplay runs (in seconds)
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
autoplayInterval?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to hide the arrow controls
|
|
34
|
+
* @default false
|
|
35
|
+
*/
|
|
36
|
+
hideArrows?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to hide the dot controls
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
hideDots?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* [Optional] props to supply to the dot buttons
|
|
44
|
+
*/
|
|
45
|
+
dotProps?: Omit<ButtonProps, "children">;
|
|
46
|
+
/**
|
|
47
|
+
* [Optional] props to supply to the left arrow button
|
|
48
|
+
*/
|
|
49
|
+
leftArrowProps?: ButtonProps;
|
|
50
|
+
/**
|
|
51
|
+
* [Optional] props to supply to the right arrow button
|
|
52
|
+
*/
|
|
53
|
+
rightArrowProps?: ButtonProps;
|
|
54
|
+
};
|
|
55
|
+
declare const Carousel: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
56
|
+
export default Carousel;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
|
+
import React, { useState, useEffect, useRef, useCallback } from "react";
|
|
25
|
+
import { classNames } from "../../functions";
|
|
26
|
+
import Button from "../Button";
|
|
27
|
+
var DEFAULT_DURATION_S = 1;
|
|
28
|
+
var Carousel = React.forwardRef(function (props, ref) {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
var children = props.children, className = props.className, hideArrows = props.hideArrows, hideDots = props.hideDots, dotProps = props.dotProps, leftArrowProps = props.leftArrowProps, rightArrowProps = props.rightArrowProps, rest = __rest(props, ["children", "className", "hideArrows", "hideDots", "dotProps", "leftArrowProps", "rightArrowProps"]);
|
|
31
|
+
// min duration
|
|
32
|
+
var duration = Math.max((_a = props.duration) !== null && _a !== void 0 ? _a : DEFAULT_DURATION_S, 0.1);
|
|
33
|
+
var autoplayInterval = props.autoplayInterval
|
|
34
|
+
? Math.max(duration, props.autoplayInterval)
|
|
35
|
+
: undefined;
|
|
36
|
+
var length = children.length;
|
|
37
|
+
var _d = useState({
|
|
38
|
+
cur: 0,
|
|
39
|
+
delta: 0,
|
|
40
|
+
animating: false,
|
|
41
|
+
}), state = _d[0], setState = _d[1];
|
|
42
|
+
var intervalRef = useRef(null);
|
|
43
|
+
var cur = state.cur, delta = state.delta, animating = state.animating;
|
|
44
|
+
var next = safeMod(cur + delta, length);
|
|
45
|
+
var startTransition = useCallback(function (delta) {
|
|
46
|
+
if (animating || delta === 0)
|
|
47
|
+
return;
|
|
48
|
+
setState(function (old) { return (__assign(__assign({}, old), { delta: delta, animating: true })); });
|
|
49
|
+
}, [animating]);
|
|
50
|
+
var onTransitionEnd = function () {
|
|
51
|
+
setState(function (_a) {
|
|
52
|
+
var delta = _a.delta, cur = _a.cur;
|
|
53
|
+
return ({
|
|
54
|
+
delta: delta,
|
|
55
|
+
animating: false,
|
|
56
|
+
cur: safeMod(cur + delta, length),
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
if (autoplayInterval) {
|
|
62
|
+
intervalRef.current = window.setInterval(function () {
|
|
63
|
+
startTransition(1);
|
|
64
|
+
}, autoplayInterval * 1000);
|
|
65
|
+
}
|
|
66
|
+
return function () {
|
|
67
|
+
var interval = intervalRef.current;
|
|
68
|
+
intervalRef.current = null;
|
|
69
|
+
if (interval) {
|
|
70
|
+
clearInterval(interval);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}, [autoplayInterval, startTransition]);
|
|
74
|
+
if (length <= 0)
|
|
75
|
+
return null;
|
|
76
|
+
var animatingStyles = animating
|
|
77
|
+
? {
|
|
78
|
+
transform: "translateX(".concat(-(delta / Math.abs(delta)) * 100, "%)"),
|
|
79
|
+
transition: "transform ".concat(duration, "s ease-in-out"),
|
|
80
|
+
}
|
|
81
|
+
: undefined;
|
|
82
|
+
return (_jsxs("div", __assign({}, rest, { className: classNames("ajui-carousel", className), ref: ref, children: [_jsxs("div", { className: "ajui-carousel-slider", style: __assign(__assign({}, animatingStyles), { flexDirection: delta >= 0 ? "row" : "row-reverse" }), onTransitionEnd: onTransitionEnd, children: [_jsx("div", { className: "ajui-carousel-item", children: children[cur] }), _jsx("div", { className: "ajui-carousel-item", "aria-hidden": true, children: children[next] })] }), length > 1 && (_jsxs(_Fragment, { children: [!hideArrows && (_jsxs(_Fragment, { children: [_jsx(Button, { className: classNames("ajui-carousel-arrow-prev", leftArrowProps === null || leftArrowProps === void 0 ? void 0 : leftArrowProps.className), style: leftArrowProps === null || leftArrowProps === void 0 ? void 0 : leftArrowProps.style, corners: "pill", "aria-label": "previous", onClick: function () { return startTransition(-1); }, children: (_b = leftArrowProps === null || leftArrowProps === void 0 ? void 0 : leftArrowProps.children) !== null && _b !== void 0 ? _b : "←" }), _jsx(Button, { className: classNames("ajui-carousel-arrow-next", rightArrowProps === null || rightArrowProps === void 0 ? void 0 : rightArrowProps.className), style: rightArrowProps === null || rightArrowProps === void 0 ? void 0 : rightArrowProps.style, corners: "pill", "aria-label": "next", onClick: function () { return startTransition(1); }, children: (_c = rightArrowProps === null || rightArrowProps === void 0 ? void 0 : rightArrowProps.children) !== null && _c !== void 0 ? _c : "→" })] })), !hideDots && (_jsx("div", { className: "ajui-carousel-dots", children: children.map(function (_, i) { return (_jsx(Button, { className: classNames("ajui-carousel-dot", dotProps === null || dotProps === void 0 ? void 0 : dotProps.className), corners: "pill", disabled: cur === i || animating, onClick: function () { return startTransition(i - cur); }, style: dotProps === null || dotProps === void 0 ? void 0 : dotProps.style }, i)); }) }))] }))] })));
|
|
83
|
+
});
|
|
84
|
+
function safeMod(n, m) {
|
|
85
|
+
return ((n % m) + m) % m;
|
|
86
|
+
}
|
|
87
|
+
export default Carousel;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
type Props = {
|
|
1
|
+
import React from "react";
|
|
2
|
+
type Props<T extends React.ElementType> = {
|
|
3
3
|
/**
|
|
4
4
|
* The children to render.
|
|
5
5
|
* IMPORTANT: The child must be a single element which can hold a ref.
|
|
6
6
|
*/
|
|
7
|
-
children: ReactElement
|
|
7
|
+
children: React.ReactElement<React.ComponentPropsWithRef<T>>;
|
|
8
8
|
/**
|
|
9
9
|
* The function to call when a click occurs outside the child element.
|
|
10
10
|
*
|
|
@@ -12,5 +12,5 @@ type Props = {
|
|
|
12
12
|
*/
|
|
13
13
|
onClickOutside: (event: MouseEvent) => void;
|
|
14
14
|
};
|
|
15
|
-
declare const ClickOutside: ({ children, onClickOutside }: Props) => JSX.Element;
|
|
15
|
+
declare const ClickOutside: <T extends React.ElementType>({ children, onClickOutside, }: Props<T>) => React.JSX.Element;
|
|
16
16
|
export default ClickOutside;
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
import { cloneElement, useCallback, useEffect, useRef } from "react";
|
|
2
2
|
var ClickOutside = function (_a) {
|
|
3
3
|
var children = _a.children, onClickOutside = _a.onClickOutside;
|
|
4
|
-
var ref = useRef();
|
|
5
|
-
var
|
|
4
|
+
var ref = useRef(null);
|
|
5
|
+
var clickWithinChildRef = useRef(false);
|
|
6
6
|
var startedRef = useRef(false);
|
|
7
7
|
useEffect(function () {
|
|
8
|
-
setTimeout(function () {
|
|
8
|
+
var timeout = window.setTimeout(function () {
|
|
9
9
|
startedRef.current = true;
|
|
10
10
|
}, 0);
|
|
11
11
|
return function () {
|
|
12
|
+
clearTimeout(timeout);
|
|
12
13
|
startedRef.current = false;
|
|
13
14
|
};
|
|
14
15
|
}, []);
|
|
15
16
|
var handleClickOutside = useCallback(function (event) {
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
if (!startedRef.current || !ref.current ||
|
|
17
|
+
var clickedWithinChild = clickWithinChildRef.current;
|
|
18
|
+
clickWithinChildRef.current = false;
|
|
19
|
+
if (!startedRef.current || !ref.current || clickedWithinChild)
|
|
19
20
|
return;
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (!event.composedPath().includes(ref.current)) {
|
|
22
|
+
onClickOutside(event);
|
|
23
|
+
}
|
|
22
24
|
}, [onClickOutside]);
|
|
23
25
|
useEffect(function () {
|
|
24
26
|
document.addEventListener("click", handleClickOutside);
|
|
@@ -28,11 +30,10 @@ var ClickOutside = function (_a) {
|
|
|
28
30
|
ref: ref,
|
|
29
31
|
onClick: function (event) {
|
|
30
32
|
var _a, _b;
|
|
31
|
-
// point of this is to let us know that click
|
|
32
|
-
// from the child element, so we can ignore it if
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
(_b = (_a = children.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
33
|
+
// point of this is to let us know that click originated
|
|
34
|
+
// from the child element, so we can ignore it if the click ends outside
|
|
35
|
+
clickWithinChildRef.current = true;
|
|
36
|
+
(_b = (_a = children.props) === null || _a === void 0 ? void 0 : _a.onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
|
|
36
37
|
},
|
|
37
38
|
});
|
|
38
39
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Style } from "../../types";
|
|
1
2
|
export type Props = {
|
|
2
3
|
/**
|
|
3
4
|
* Size of the button in pixels
|
|
@@ -39,17 +40,17 @@ export type Props = {
|
|
|
39
40
|
/**
|
|
40
41
|
* [Optional] additional styles to apply to the button
|
|
41
42
|
*/
|
|
42
|
-
style?:
|
|
43
|
+
style?: Style;
|
|
43
44
|
/**
|
|
44
45
|
* [Optional] round corners of the bars
|
|
45
46
|
*/
|
|
46
47
|
rounded?: boolean;
|
|
47
48
|
};
|
|
48
49
|
type OpenStyle = {
|
|
49
|
-
outer?:
|
|
50
|
-
top:
|
|
51
|
-
bottom:
|
|
52
|
-
middle?:
|
|
50
|
+
outer?: Style;
|
|
51
|
+
top: Style;
|
|
52
|
+
bottom: Style;
|
|
53
|
+
middle?: Style;
|
|
53
54
|
};
|
|
54
55
|
type InnerProps = Omit<Props, "variant" | "direction"> & {
|
|
55
56
|
double?: boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type Props = Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>, "children"> & {
|
|
3
|
+
/**
|
|
4
|
+
* Code string to render
|
|
5
|
+
*/
|
|
6
|
+
children: string;
|
|
7
|
+
/**
|
|
8
|
+
* Whether to disable click to copy
|
|
9
|
+
*/
|
|
10
|
+
disableCopy?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare const InlineCode: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLElement>>;
|
|
13
|
+
export default InlineCode;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
24
|
+
import React, { useState, useRef } from "react";
|
|
25
|
+
import { classNames } from "../../functions";
|
|
26
|
+
var InlineCode = React.forwardRef(function (_a, ref) {
|
|
27
|
+
var className = _a.className, disableCopy = _a.disableCopy, onClick = _a.onClick, children = _a.children, rest = __rest(_a, ["className", "disableCopy", "onClick", "children"]);
|
|
28
|
+
var _b = useState(false), copied = _b[0], setCopied = _b[1];
|
|
29
|
+
var timeoutRef = useRef(null);
|
|
30
|
+
var handleCopy = function () {
|
|
31
|
+
var timeout = timeoutRef.current;
|
|
32
|
+
if (timeout) {
|
|
33
|
+
clearTimeout(timeout);
|
|
34
|
+
timeoutRef.current = null;
|
|
35
|
+
}
|
|
36
|
+
navigator.clipboard.writeText(children);
|
|
37
|
+
setCopied(true);
|
|
38
|
+
timeoutRef.current = window.setTimeout(function () {
|
|
39
|
+
setCopied(false);
|
|
40
|
+
timeoutRef.current = null;
|
|
41
|
+
}, 3000);
|
|
42
|
+
};
|
|
43
|
+
return (_jsx("code", __assign({}, rest, { ref: ref, role: "button", className: classNames("ajui-inline-code", disableCopy ? undefined : "ajui-copy-cursor", copied ? "ajui-inline-code-copied" : undefined, className), onClick: function (e) {
|
|
44
|
+
if (!disableCopy) {
|
|
45
|
+
handleCopy();
|
|
46
|
+
}
|
|
47
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(e);
|
|
48
|
+
}, children: children })));
|
|
49
|
+
});
|
|
50
|
+
export default InlineCode;
|