@adamjanicki/ui 1.5.3 → 1.5.5
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/Animated/Animated.d.ts +15 -12
- package/components/Animated/Animated.js +38 -19
- package/components/Button/Button.d.ts +1 -5
- package/components/Carousel/Carousel.d.ts +63 -0
- package/components/Carousel/Carousel.js +76 -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/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/Layer/Layer.d.ts +7 -2
- package/components/Layer/Layer.js +3 -3
- package/components/Select/Select.d.ts +1 -5
- package/functions/scrollToId.js +1 -1
- package/hooks/useFocusTrap.d.ts +1 -1
- package/index.d.ts +12 -9
- package/index.js +13 -9
- package/package.json +8 -28
- package/style.css +97 -22
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
type Props = {
|
|
3
3
|
/**
|
|
4
|
-
* Whether
|
|
4
|
+
* Whether to begin the animation.
|
|
5
|
+
* Set to true to start animation, false to start the exit animation.
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
|
+
animated: boolean;
|
|
7
8
|
/**
|
|
8
|
-
* Duration of the animation in
|
|
9
|
+
* Duration of the animation in seconds
|
|
10
|
+
* @default 0.25
|
|
9
11
|
*/
|
|
10
12
|
duration?: number;
|
|
11
13
|
/**
|
|
12
|
-
* Whether to keep the component mounted when it is not
|
|
14
|
+
* Whether to keep the component mounted when it is not animated
|
|
15
|
+
* @default false
|
|
13
16
|
*/
|
|
14
|
-
|
|
17
|
+
keepMounted?: boolean;
|
|
15
18
|
/**
|
|
16
19
|
* Animation configuration for the enter state
|
|
17
20
|
*/
|
|
18
|
-
|
|
21
|
+
animateTo?: {
|
|
19
22
|
/**
|
|
20
|
-
* Class name to apply to the component
|
|
23
|
+
* Class name to apply to the component while animated (after state)
|
|
21
24
|
*/
|
|
22
25
|
className?: string;
|
|
23
26
|
/**
|
|
24
|
-
* Inline styles to apply to the component
|
|
27
|
+
* Inline styles to apply to the component while animated
|
|
25
28
|
*/
|
|
26
29
|
style?: React.CSSProperties;
|
|
27
30
|
};
|
|
28
|
-
|
|
31
|
+
animateFrom?: {
|
|
29
32
|
/**
|
|
30
|
-
* Class name to apply to the component
|
|
33
|
+
* Class name to apply to the component when not animated (before state)
|
|
31
34
|
*/
|
|
32
35
|
className?: string;
|
|
33
36
|
/**
|
|
34
|
-
* Inline styles to apply to the component
|
|
37
|
+
* Inline styles to apply to the component when not animated
|
|
35
38
|
*/
|
|
36
39
|
style?: React.CSSProperties;
|
|
37
40
|
};
|
|
@@ -48,5 +51,5 @@ type Props = {
|
|
|
48
51
|
*/
|
|
49
52
|
style?: React.CSSProperties;
|
|
50
53
|
};
|
|
51
|
-
declare const Animated:
|
|
54
|
+
declare const Animated: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
52
55
|
export default Animated;
|
|
@@ -10,30 +10,49 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import { useState, useEffect } from "react";
|
|
13
|
+
import React, { useState, useEffect, useRef } from "react";
|
|
14
14
|
import classNames from "../../functions/classNames";
|
|
15
|
-
var Animated = function (
|
|
16
|
-
var
|
|
17
|
-
var
|
|
18
|
-
var
|
|
15
|
+
var Animated = React.forwardRef(function (props, ref) {
|
|
16
|
+
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;
|
|
17
|
+
var _c = useState(animated || keepMounted), shouldRender = _c[0], setShouldRender = _c[1];
|
|
18
|
+
var _d = useState(animated ? "forward" : "reverse"), animationState = _d[0], setAnimationState = _d[1];
|
|
19
|
+
var timeoutRef = useRef(null);
|
|
20
|
+
var animationFrameRef = useRef(null);
|
|
21
|
+
var clearRefs = function () {
|
|
22
|
+
if (timeoutRef.current) {
|
|
23
|
+
clearTimeout(timeoutRef.current);
|
|
24
|
+
timeoutRef.current = null;
|
|
25
|
+
}
|
|
26
|
+
if (animationFrameRef.current) {
|
|
27
|
+
cancelAnimationFrame(animationFrameRef.current);
|
|
28
|
+
animationFrameRef.current = null;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
19
31
|
useEffect(function () {
|
|
20
|
-
|
|
21
|
-
if (
|
|
22
|
-
// Start enter animation
|
|
32
|
+
clearRefs();
|
|
33
|
+
if (animated) {
|
|
23
34
|
setShouldRender(true);
|
|
24
|
-
|
|
35
|
+
// Use requestAnimationFrame so browser paints shouldRender first
|
|
36
|
+
animationFrameRef.current = requestAnimationFrame(function () {
|
|
37
|
+
setAnimationState("forward");
|
|
38
|
+
animationFrameRef.current = null;
|
|
39
|
+
});
|
|
25
40
|
}
|
|
26
|
-
else
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!keepMountedOnExit) {
|
|
41
|
+
else {
|
|
42
|
+
setAnimationState("reverse");
|
|
43
|
+
timeoutRef.current = window.setTimeout(function () {
|
|
44
|
+
if (!keepMounted) {
|
|
31
45
|
setShouldRender(false);
|
|
32
46
|
}
|
|
33
|
-
|
|
47
|
+
timeoutRef.current = null;
|
|
48
|
+
// convert to ms
|
|
49
|
+
}, duration * 1000);
|
|
34
50
|
}
|
|
35
|
-
return
|
|
36
|
-
}, [
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
return clearRefs;
|
|
52
|
+
}, [animated, duration, keepMounted, shouldRender]);
|
|
53
|
+
if (!shouldRender)
|
|
54
|
+
return null;
|
|
55
|
+
var currentAnimation = animationState === "forward" ? animateTo : animateFrom;
|
|
56
|
+
return (_jsx("div", { 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), ref: ref, children: children }));
|
|
57
|
+
});
|
|
39
58
|
export default Animated;
|
|
@@ -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
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type ButtonProps = {
|
|
3
|
+
/**
|
|
4
|
+
* Children to render inside the button
|
|
5
|
+
*/
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* Additional class name to apply to the button
|
|
9
|
+
*/
|
|
10
|
+
className?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Additional styles to apply to the button
|
|
13
|
+
*/
|
|
14
|
+
style?: React.CSSProperties;
|
|
15
|
+
};
|
|
16
|
+
type Props = {
|
|
17
|
+
/**
|
|
18
|
+
* The child elements/slides of the carousel
|
|
19
|
+
*/
|
|
20
|
+
children: React.ReactNode[];
|
|
21
|
+
/**
|
|
22
|
+
* How long the transition lasts (in seconds)
|
|
23
|
+
* @default 1
|
|
24
|
+
*/
|
|
25
|
+
duration?: number;
|
|
26
|
+
/**
|
|
27
|
+
* The interval at which autoplay runs (in seconds)
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
autoplayInterval?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to hide the arrow controls
|
|
33
|
+
* @default false
|
|
34
|
+
*/
|
|
35
|
+
hideArrows?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether to hide the dot controls
|
|
38
|
+
* @default false
|
|
39
|
+
*/
|
|
40
|
+
hideDots?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* [Optional] props to supply to the dot buttons
|
|
43
|
+
*/
|
|
44
|
+
dotProps?: Omit<ButtonProps, "children">;
|
|
45
|
+
/**
|
|
46
|
+
* [Optional] props to supply to the left arrow button
|
|
47
|
+
*/
|
|
48
|
+
leftArrowProps?: ButtonProps;
|
|
49
|
+
/**
|
|
50
|
+
* [Optional] props to supply to the right arrow button
|
|
51
|
+
*/
|
|
52
|
+
rightArrowProps?: ButtonProps;
|
|
53
|
+
/**
|
|
54
|
+
* [Optional] Additional class name to apply to the carousel.
|
|
55
|
+
*/
|
|
56
|
+
className?: string;
|
|
57
|
+
/**
|
|
58
|
+
* [Optional] Additional styles to apply to the carousel.
|
|
59
|
+
*/
|
|
60
|
+
style?: React.CSSProperties;
|
|
61
|
+
};
|
|
62
|
+
declare const Carousel: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
|
|
63
|
+
export default Carousel;
|
|
@@ -0,0 +1,76 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import React, { useState, useEffect, useRef, useCallback } from "react";
|
|
14
|
+
import { classNames } from "../../functions";
|
|
15
|
+
import Button from "../Button";
|
|
16
|
+
var DEFAULT_DURATION_S = 1;
|
|
17
|
+
var Carousel = React.forwardRef(function (props, ref) {
|
|
18
|
+
var _a, _b, _c;
|
|
19
|
+
var children = props.children, className = props.className, style = props.style, hideArrows = props.hideArrows, hideDots = props.hideDots, dotProps = props.dotProps, leftArrowProps = props.leftArrowProps, rightArrowProps = props.rightArrowProps;
|
|
20
|
+
// min duration
|
|
21
|
+
var duration = Math.max((_a = props.duration) !== null && _a !== void 0 ? _a : DEFAULT_DURATION_S, 0.1);
|
|
22
|
+
var autoplayInterval = props.autoplayInterval
|
|
23
|
+
? Math.max(duration, props.autoplayInterval)
|
|
24
|
+
: undefined;
|
|
25
|
+
var length = children.length;
|
|
26
|
+
var _d = useState({
|
|
27
|
+
cur: 0,
|
|
28
|
+
delta: 0,
|
|
29
|
+
animating: false,
|
|
30
|
+
}), state = _d[0], setState = _d[1];
|
|
31
|
+
var intervalRef = useRef(null);
|
|
32
|
+
var cur = state.cur, delta = state.delta, animating = state.animating;
|
|
33
|
+
var next = safeMod(cur + delta, length);
|
|
34
|
+
var startTransition = useCallback(function (delta) {
|
|
35
|
+
if (animating || delta === 0)
|
|
36
|
+
return;
|
|
37
|
+
setState(function (old) { return (__assign(__assign({}, old), { delta: delta, animating: true })); });
|
|
38
|
+
}, [animating]);
|
|
39
|
+
var onTransitionEnd = function () {
|
|
40
|
+
setState(function (_a) {
|
|
41
|
+
var delta = _a.delta, cur = _a.cur;
|
|
42
|
+
return ({
|
|
43
|
+
delta: delta,
|
|
44
|
+
animating: false,
|
|
45
|
+
cur: safeMod(cur + delta, length),
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
useEffect(function () {
|
|
50
|
+
if (autoplayInterval) {
|
|
51
|
+
intervalRef.current = window.setInterval(function () {
|
|
52
|
+
startTransition(1);
|
|
53
|
+
}, autoplayInterval * 1000);
|
|
54
|
+
}
|
|
55
|
+
return function () {
|
|
56
|
+
var interval = intervalRef.current;
|
|
57
|
+
intervalRef.current = null;
|
|
58
|
+
if (interval) {
|
|
59
|
+
clearInterval(interval);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, [autoplayInterval, startTransition]);
|
|
63
|
+
if (length <= 0)
|
|
64
|
+
return null;
|
|
65
|
+
var animatingStyles = animating
|
|
66
|
+
? {
|
|
67
|
+
transform: "translateX(".concat(-(delta / Math.abs(delta)) * 100, "%)"),
|
|
68
|
+
transition: "transform ".concat(duration, "s ease-in-out"),
|
|
69
|
+
}
|
|
70
|
+
: undefined;
|
|
71
|
+
return (_jsxs("div", { className: classNames("ajui-carousel", className), style: style, 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)); }) }))] }))] }));
|
|
72
|
+
});
|
|
73
|
+
function safeMod(n, m) {
|
|
74
|
+
return ((n % m) + m) % m;
|
|
75
|
+
}
|
|
76
|
+
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
|
};
|
|
@@ -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, props = __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({ 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
|
+
} }, props, { children: children })));
|
|
49
|
+
});
|
|
50
|
+
export default InlineCode;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
type
|
|
2
|
+
type Props = {
|
|
3
3
|
/**
|
|
4
4
|
* Callback that fires when the user clicks outside the layer
|
|
5
5
|
*/
|
|
@@ -27,6 +27,11 @@ type LayerProps = {
|
|
|
27
27
|
* @default false
|
|
28
28
|
*/
|
|
29
29
|
returnFocusOnEscape?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* [Optional] disable the scroll lock behavior of the layer
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
disableScrollLock?: boolean;
|
|
30
35
|
};
|
|
31
|
-
declare const Layer: ({ returnFocusOnEscape, ...props }:
|
|
36
|
+
declare const Layer: ({ returnFocusOnEscape, disableScrollLock, ...props }: Props) => React.JSX.Element;
|
|
32
37
|
export default Layer;
|
|
@@ -45,14 +45,14 @@ var BaseLayer = function (_a) {
|
|
|
45
45
|
onMouseDown: function (e) {
|
|
46
46
|
var _a, _b;
|
|
47
47
|
e.stopPropagation();
|
|
48
|
-
(_b = (_a = children.props).onMouseDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
48
|
+
(_b = (_a = children.props) === null || _a === void 0 ? void 0 : _a.onMouseDown) === null || _b === void 0 ? void 0 : _b.call(_a, e);
|
|
49
49
|
},
|
|
50
50
|
}) }));
|
|
51
51
|
};
|
|
52
52
|
var Layer = function (_a) {
|
|
53
|
-
var
|
|
53
|
+
var returnFocusOnEscape = _a.returnFocusOnEscape, disableScrollLock = _a.disableScrollLock, props = __rest(_a, ["returnFocusOnEscape", "disableScrollLock"]);
|
|
54
54
|
// Lock and unlock on mount and unmount
|
|
55
|
-
useScrollLock();
|
|
55
|
+
useScrollLock(!disableScrollLock);
|
|
56
56
|
useEffect(function () {
|
|
57
57
|
return function () {
|
|
58
58
|
var _a;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { CornerType } from "../../types";
|
|
3
|
-
type Props =
|
|
3
|
+
type Props = React.DetailedHTMLProps<React.SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement> & {
|
|
4
4
|
/**
|
|
5
5
|
* Array of options to display in the select
|
|
6
6
|
*/
|
|
@@ -24,10 +24,6 @@ type Props = Omit<React.DetailedHTMLProps<React.SelectHTMLAttributes<HTMLSelectE
|
|
|
24
24
|
* @default "rounded"
|
|
25
25
|
*/
|
|
26
26
|
corners?: CornerType;
|
|
27
|
-
/**
|
|
28
|
-
* Name of the select for accessibility purposes
|
|
29
|
-
*/
|
|
30
|
-
"aria-label": string;
|
|
31
27
|
};
|
|
32
28
|
declare const _default: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLSelectElement>>;
|
|
33
29
|
export default _default;
|
package/functions/scrollToId.js
CHANGED
package/hooks/useFocusTrap.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* `true` by default
|
|
6
6
|
* @returns ref object that must be passed to the element that should be trapped
|
|
7
7
|
*/
|
|
8
|
-
declare const useFocusTrap: <T extends HTMLElement>(isActive?: boolean) => import("react").
|
|
8
|
+
declare const useFocusTrap: <T extends HTMLElement>(isActive?: boolean) => import("react").RefObject<T | null>;
|
|
9
9
|
export default useFocusTrap;
|
package/index.d.ts
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
export * from "./components/Button";
|
|
2
|
-
export { default as Button } from "./components/Button";
|
|
3
|
-
export * from "./components/Link";
|
|
4
|
-
export { default as Link } from "./components/Link";
|
|
5
|
-
export * from "./components/Input";
|
|
6
|
-
export { default as Input } from "./components/Input";
|
|
7
1
|
export { default as Alert } from "./components/Alert";
|
|
8
2
|
export { default as Animated } from "./components/Animated";
|
|
9
3
|
export { default as Badge } from "./components/Badge";
|
|
10
4
|
export { default as Banner } from "./components/Banner";
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export { default as
|
|
5
|
+
export { default as Button } from "./components/Button";
|
|
6
|
+
export * from "./components/Button";
|
|
7
|
+
export { default as Carousel } from "./components/Carousel";
|
|
14
8
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
9
|
+
export { default as Hamburger } from "./components/Hamburger";
|
|
10
|
+
export * from "./components/Hamburger";
|
|
11
|
+
export { default as InlineCode } from "./components/InlineCode";
|
|
12
|
+
export { default as Input } from "./components/Input";
|
|
13
|
+
export * from "./components/Input";
|
|
15
14
|
export { default as Layer } from "./components/Layer";
|
|
15
|
+
export { default as Link } from "./components/Link";
|
|
16
|
+
export * from "./components/Link";
|
|
17
|
+
export { default as Select } from "./components/Select";
|
|
16
18
|
export { default as Spinner } from "./components/Spinner";
|
|
17
19
|
export * from "./hooks";
|
|
20
|
+
export * from "./functions";
|
package/index.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
// Components
|
|
2
|
-
export * from "./components/Button";
|
|
3
|
-
export { default as Button } from "./components/Button";
|
|
4
|
-
export * from "./components/Link";
|
|
5
|
-
export { default as Link } from "./components/Link";
|
|
6
|
-
export * from "./components/Input";
|
|
7
|
-
export { default as Input } from "./components/Input";
|
|
8
2
|
export { default as Alert } from "./components/Alert";
|
|
9
3
|
export { default as Animated } from "./components/Animated";
|
|
10
4
|
export { default as Badge } from "./components/Badge";
|
|
11
5
|
export { default as Banner } from "./components/Banner";
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export { default as
|
|
6
|
+
export { default as Button } from "./components/Button";
|
|
7
|
+
export * from "./components/Button";
|
|
8
|
+
export { default as Carousel } from "./components/Carousel";
|
|
15
9
|
export { default as ClickOutside } from "./components/ClickOutside";
|
|
10
|
+
export { default as Hamburger } from "./components/Hamburger";
|
|
11
|
+
export * from "./components/Hamburger";
|
|
12
|
+
export { default as InlineCode } from "./components/InlineCode";
|
|
13
|
+
export { default as Input } from "./components/Input";
|
|
14
|
+
export * from "./components/Input";
|
|
16
15
|
export { default as Layer } from "./components/Layer";
|
|
16
|
+
export { default as Link } from "./components/Link";
|
|
17
|
+
export * from "./components/Link";
|
|
18
|
+
export { default as Select } from "./components/Select";
|
|
17
19
|
export { default as Spinner } from "./components/Spinner";
|
|
18
20
|
// Hooks
|
|
19
21
|
export * from "./hooks";
|
|
22
|
+
// Functions
|
|
23
|
+
export * from "./functions";
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamjanicki/ui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "Basic UI components and hooks for React in TypeScript",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "./index.js",
|
|
6
7
|
"types": "./index.d.ts",
|
|
7
8
|
"author": "Adam Janicki",
|
|
@@ -11,39 +12,18 @@
|
|
|
11
12
|
"url": "git+https://github.com/adamjanicki2/ui.git"
|
|
12
13
|
},
|
|
13
14
|
"scripts": {
|
|
14
|
-
"build": "tsc; cp src/style.css ./style.css",
|
|
15
15
|
"clean": "./clean.sh",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"prepare": "npm run lint; npm test; npm run build"
|
|
16
|
+
"lint": "eslint src --max-warnings=0",
|
|
17
|
+
"build": "npm run clean && npm run lint && tsc; cp src/style.css ./style.css",
|
|
18
|
+
"prepare": "npm run build"
|
|
20
19
|
},
|
|
21
20
|
"peerDependencies": {
|
|
22
21
|
"react": ">=18",
|
|
23
22
|
"react-dom": ">=18"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
|
-
"@
|
|
27
|
-
"@
|
|
28
|
-
"
|
|
29
|
-
"@typescript-eslint/eslint-plugin": "^6.11.0",
|
|
30
|
-
"@typescript-eslint/parser": "^6.11.0",
|
|
31
|
-
"eslint": "^8.53.0",
|
|
32
|
-
"eslint-config-prettier": "^9.0.0",
|
|
33
|
-
"eslint-plugin-react": "^7.33.2",
|
|
34
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
35
|
-
"jest": "^29.7.0",
|
|
36
|
-
"jest-canvas-mock": "^2.5.2",
|
|
37
|
-
"jest-css-modules": "^2.1.0",
|
|
38
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
39
|
-
"nodemon": "^3.1.4",
|
|
40
|
-
"ts-jest": "^29.2.2",
|
|
41
|
-
"typescript": "^5.2.2"
|
|
42
|
-
},
|
|
43
|
-
"eslintConfig": {
|
|
44
|
-
"extends": [
|
|
45
|
-
"react-app",
|
|
46
|
-
"react-app/jest"
|
|
47
|
-
]
|
|
25
|
+
"@types/react": "^19.1.9",
|
|
26
|
+
"@types/react-dom": "^19.1.7",
|
|
27
|
+
"typescript": "^5.9.2"
|
|
48
28
|
}
|
|
49
29
|
}
|
package/style.css
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/* General styles */
|
|
2
2
|
:root {
|
|
3
3
|
/* General colors */
|
|
4
|
-
--ajui-light-gray: #eee;
|
|
5
4
|
--ajui-moon-gray: #ccc;
|
|
6
5
|
--ajui-dark-gray: #555;
|
|
7
6
|
--ajui-darkest-gray: #333;
|
|
@@ -16,7 +15,7 @@
|
|
|
16
15
|
--ajui-default-opacity-dim: 0.75;
|
|
17
16
|
/* Corners */
|
|
18
17
|
--ajui-sharp-radius: 0;
|
|
19
|
-
--ajui-rounded-radius:
|
|
18
|
+
--ajui-rounded-radius: 8px;
|
|
20
19
|
--ajui-pill-radius: 9999px;
|
|
21
20
|
--ajui-circle-radius: 50%;
|
|
22
21
|
/* Buttons */
|
|
@@ -162,7 +161,7 @@ button {
|
|
|
162
161
|
|
|
163
162
|
/* Alert */
|
|
164
163
|
.ajui-alert {
|
|
165
|
-
padding:
|
|
164
|
+
padding: 16px;
|
|
166
165
|
border-style: solid;
|
|
167
166
|
border-width: 1px;
|
|
168
167
|
font-weight: 400;
|
|
@@ -180,10 +179,10 @@ button {
|
|
|
180
179
|
|
|
181
180
|
/* Banner */
|
|
182
181
|
.ajui-banner {
|
|
183
|
-
padding:
|
|
182
|
+
padding: 24px 32px;
|
|
184
183
|
border: none;
|
|
185
184
|
font-weight: 400;
|
|
186
|
-
width:
|
|
185
|
+
width: 100%;
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
/* Link */
|
|
@@ -200,12 +199,12 @@ a {
|
|
|
200
199
|
border: none;
|
|
201
200
|
padding: 0;
|
|
202
201
|
cursor: pointer;
|
|
203
|
-
font-size:
|
|
202
|
+
font-size: 16px;
|
|
204
203
|
font-weight: 500;
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
.ajui-button-size--regular {
|
|
208
|
-
padding:
|
|
207
|
+
padding: 8px 16px;
|
|
209
208
|
}
|
|
210
209
|
|
|
211
210
|
.ajui-button-size--small {
|
|
@@ -219,11 +218,11 @@ a {
|
|
|
219
218
|
justify-content: center;
|
|
220
219
|
align-items: center;
|
|
221
220
|
transition: opacity var(--ajui-default-transition);
|
|
222
|
-
padding:
|
|
221
|
+
padding: 4px;
|
|
223
222
|
}
|
|
224
223
|
|
|
225
224
|
.ajui-button-base:disabled {
|
|
226
|
-
cursor:
|
|
225
|
+
cursor: default !important;
|
|
227
226
|
opacity: var(--ajui-disabled-opacity);
|
|
228
227
|
}
|
|
229
228
|
|
|
@@ -267,8 +266,8 @@ a {
|
|
|
267
266
|
border: none;
|
|
268
267
|
background-color: inherit;
|
|
269
268
|
color: inherit;
|
|
270
|
-
padding:
|
|
271
|
-
font-size:
|
|
269
|
+
padding: 12px 8px;
|
|
270
|
+
font-size: 16px;
|
|
272
271
|
font-weight: 400;
|
|
273
272
|
}
|
|
274
273
|
|
|
@@ -296,7 +295,7 @@ a {
|
|
|
296
295
|
|
|
297
296
|
.ajui-input-default:disabled {
|
|
298
297
|
opacity: var(--ajui-disabled-opacity);
|
|
299
|
-
cursor:
|
|
298
|
+
cursor: default;
|
|
300
299
|
}
|
|
301
300
|
|
|
302
301
|
/* Select */
|
|
@@ -310,11 +309,6 @@ a {
|
|
|
310
309
|
background-color: inherit;
|
|
311
310
|
}
|
|
312
311
|
|
|
313
|
-
.ajui-select-disabled {
|
|
314
|
-
opacity: var(--ajui-disabled-opacity);
|
|
315
|
-
cursor: not-allowed !important;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
312
|
.ajui-select-base {
|
|
319
313
|
width: 100%;
|
|
320
314
|
color: inherit;
|
|
@@ -323,22 +317,27 @@ a {
|
|
|
323
317
|
box-shadow: none;
|
|
324
318
|
cursor: pointer;
|
|
325
319
|
background-color: transparent;
|
|
326
|
-
padding:
|
|
327
|
-
font-size:
|
|
320
|
+
padding: 12px 28px 12px 8px;
|
|
321
|
+
font-size: 16px;
|
|
328
322
|
font-weight: 400;
|
|
329
323
|
appearance: none;
|
|
330
324
|
-webkit-appearance: none;
|
|
331
325
|
-moz-appearance: none;
|
|
332
326
|
}
|
|
333
327
|
|
|
328
|
+
.ajui-select-disabled * {
|
|
329
|
+
opacity: var(--ajui-disabled-opacity);
|
|
330
|
+
cursor: default;
|
|
331
|
+
}
|
|
332
|
+
|
|
334
333
|
.ajui-select-triangle {
|
|
335
|
-
--size:
|
|
334
|
+
--size: 12px;
|
|
336
335
|
width: var(--size);
|
|
337
336
|
height: var(--size);
|
|
338
337
|
position: absolute;
|
|
339
338
|
top: 50%;
|
|
340
339
|
transform: translateY(-50%);
|
|
341
|
-
right: calc(var(--size) -
|
|
340
|
+
right: calc(var(--size) - 4px);
|
|
342
341
|
pointer-events: none;
|
|
343
342
|
}
|
|
344
343
|
|
|
@@ -360,7 +359,7 @@ a {
|
|
|
360
359
|
.ajui-spinner {
|
|
361
360
|
animation: ajui-spinner-animation 1s linear infinite;
|
|
362
361
|
transform-origin: center;
|
|
363
|
-
height:
|
|
362
|
+
height: 24px;
|
|
364
363
|
}
|
|
365
364
|
|
|
366
365
|
@keyframes ajui-spinner-animation {
|
|
@@ -371,3 +370,79 @@ a {
|
|
|
371
370
|
transform: rotate(360deg);
|
|
372
371
|
}
|
|
373
372
|
}
|
|
373
|
+
|
|
374
|
+
/* Inline Code */
|
|
375
|
+
.ajui-inline-code {
|
|
376
|
+
background-color: var(--ajui-default-border);
|
|
377
|
+
color: var(--ajui-default-color);
|
|
378
|
+
border-radius: var(--ajui-rounded-radius);
|
|
379
|
+
transition: background-color var(--ajui-default-transition);
|
|
380
|
+
word-wrap: break-word;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
.ajui-copy-cursor {
|
|
384
|
+
cursor: copy;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
.ajui-inline-code-copied {
|
|
388
|
+
background-color: var(--ajui-success-background);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/* Carousel */
|
|
392
|
+
.ajui-carousel {
|
|
393
|
+
max-width: 100%;
|
|
394
|
+
position: relative;
|
|
395
|
+
overflow: hidden;
|
|
396
|
+
min-height: 64px;
|
|
397
|
+
min-width: 64px;
|
|
398
|
+
width: fit-content;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
.ajui-carousel-slider {
|
|
402
|
+
width: 100%;
|
|
403
|
+
height: 100%;
|
|
404
|
+
display: flex;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.ajui-carousel-item {
|
|
408
|
+
flex: 0 0 100%;
|
|
409
|
+
width: 100%;
|
|
410
|
+
height: 100%;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
.ajui-carousel-arrow-prev,
|
|
414
|
+
.ajui-carousel-arrow-next {
|
|
415
|
+
display: flex;
|
|
416
|
+
justify-content: center;
|
|
417
|
+
align-items: center;
|
|
418
|
+
position: absolute;
|
|
419
|
+
top: 50%;
|
|
420
|
+
transform: translateY(-50%);
|
|
421
|
+
width: 24px;
|
|
422
|
+
height: 24px;
|
|
423
|
+
padding: 0;
|
|
424
|
+
font-weight: 800;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
.ajui-carousel-arrow-prev {
|
|
428
|
+
left: 8px;
|
|
429
|
+
}
|
|
430
|
+
.ajui-carousel-arrow-next {
|
|
431
|
+
right: 8px;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.ajui-carousel-dots {
|
|
435
|
+
position: absolute;
|
|
436
|
+
display: flex;
|
|
437
|
+
align-items: center;
|
|
438
|
+
bottom: 8px;
|
|
439
|
+
transform: translateX(-50%);
|
|
440
|
+
left: 50%;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
.ajui-carousel-dot {
|
|
444
|
+
width: 16px;
|
|
445
|
+
height: 8px;
|
|
446
|
+
padding: 0;
|
|
447
|
+
margin: 0 2px;
|
|
448
|
+
}
|