@adamjanicki/ui 1.5.5 → 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.
@@ -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 }, rest)));
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,5 +1,6 @@
1
1
  import React from "react";
2
- type Props = {
2
+ import type { DivProps, Style } from "../../types";
3
+ type Props = DivProps & {
3
4
  /**
4
5
  * Whether to begin the animation.
5
6
  * Set to true to start animation, false to start the exit animation.
@@ -26,7 +27,7 @@ type Props = {
26
27
  /**
27
28
  * Inline styles to apply to the component while animated
28
29
  */
29
- style?: React.CSSProperties;
30
+ style?: Style;
30
31
  };
31
32
  animateFrom?: {
32
33
  /**
@@ -36,20 +37,8 @@ type Props = {
36
37
  /**
37
38
  * Inline styles to apply to the component when not animated
38
39
  */
39
- style?: React.CSSProperties;
40
+ style?: Style;
40
41
  };
41
- /**
42
- * Children to render
43
- */
44
- children: React.ReactNode | React.ReactNode[];
45
- /**
46
- * [Optional] className to apply to the component always
47
- */
48
- className?: string;
49
- /**
50
- * [Optional] Inline styles to apply to the component always
51
- */
52
- style?: React.CSSProperties;
53
42
  };
54
- declare const Animated: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
43
+ declare const Animated: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
55
44
  export default Animated;
@@ -9,13 +9,24 @@ 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
24
  import React, { useState, useEffect, useRef } from "react";
14
25
  import classNames from "../../functions/classNames";
15
26
  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;
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"]);
17
28
  var _c = useState(animated || keepMounted), shouldRender = _c[0], setShouldRender = _c[1];
18
- var _d = useState(animated ? "forward" : "reverse"), animationState = _d[0], setAnimationState = _d[1];
29
+ var _d = useState(false), isAnimatingForward = _d[0], setIsAnimatingForward = _d[1];
19
30
  var timeoutRef = useRef(null);
20
31
  var animationFrameRef = useRef(null);
21
32
  var clearRefs = function () {
@@ -29,30 +40,35 @@ var Animated = React.forwardRef(function (props, ref) {
29
40
  }
30
41
  };
31
42
  useEffect(function () {
32
- clearRefs();
33
- if (animated) {
34
- setShouldRender(true);
35
- // Use requestAnimationFrame so browser paints shouldRender first
43
+ // initiate forward animation
44
+ if (animated && shouldRender) {
45
+ clearRefs();
36
46
  animationFrameRef.current = requestAnimationFrame(function () {
37
- setAnimationState("forward");
38
- animationFrameRef.current = null;
47
+ return setIsAnimatingForward(true);
39
48
  });
40
49
  }
50
+ return clearRefs;
51
+ }, [animated, shouldRender]);
52
+ useEffect(function () {
53
+ // make container element appear on DOM
54
+ if (animated) {
55
+ setShouldRender(true);
56
+ }
57
+ // initiate reverse animation
41
58
  else {
42
- setAnimationState("reverse");
59
+ clearRefs();
60
+ setIsAnimatingForward(false);
43
61
  timeoutRef.current = window.setTimeout(function () {
44
62
  if (!keepMounted) {
45
63
  setShouldRender(false);
46
64
  }
47
- timeoutRef.current = null;
48
- // convert to ms
49
65
  }, duration * 1000);
50
66
  }
51
67
  return clearRefs;
52
- }, [animated, duration, keepMounted, shouldRender]);
68
+ }, [animated, duration, keepMounted]);
53
69
  if (!shouldRender)
54
70
  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 }));
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 })));
57
73
  });
58
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 }, rest)));
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 }, rest)));
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
@@ -26,7 +26,7 @@ type ButtonProps = DefaultButtonProps & {
26
26
  * Type of button
27
27
  * @default "primary"
28
28
  */
29
- variant?: "primary" | "secondary" | "transparent";
29
+ variant?: "primary" | "secondary";
30
30
  /**
31
31
  * Type of corners on the button
32
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;
@@ -1,9 +1,10 @@
1
1
  import React from "react";
2
+ import type { DivProps, Style } from "../../types";
2
3
  type ButtonProps = {
3
4
  /**
4
5
  * Children to render inside the button
5
6
  */
6
- children?: React.ReactNode;
7
+ children?: React.ReactNode | React.ReactNode[];
7
8
  /**
8
9
  * Additional class name to apply to the button
9
10
  */
@@ -11,9 +12,9 @@ type ButtonProps = {
11
12
  /**
12
13
  * Additional styles to apply to the button
13
14
  */
14
- style?: React.CSSProperties;
15
+ style?: Style;
15
16
  };
16
- type Props = {
17
+ type Props = DivProps & {
17
18
  /**
18
19
  * The child elements/slides of the carousel
19
20
  */
@@ -50,14 +51,6 @@ type Props = {
50
51
  * [Optional] props to supply to the right arrow button
51
52
  */
52
53
  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
54
  };
62
- declare const Carousel: React.ForwardRefExoticComponent<Props & React.RefAttributes<HTMLDivElement>>;
55
+ declare const Carousel: React.ForwardRefExoticComponent<Omit<Props, "ref"> & React.RefAttributes<HTMLDivElement>>;
63
56
  export default Carousel;
@@ -9,6 +9,17 @@ 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, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
13
24
  import React, { useState, useEffect, useRef, useCallback } from "react";
14
25
  import { classNames } from "../../functions";
@@ -16,7 +27,7 @@ import Button from "../Button";
16
27
  var DEFAULT_DURATION_S = 1;
17
28
  var Carousel = React.forwardRef(function (props, ref) {
18
29
  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;
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"]);
20
31
  // min duration
21
32
  var duration = Math.max((_a = props.duration) !== null && _a !== void 0 ? _a : DEFAULT_DURATION_S, 0.1);
22
33
  var autoplayInterval = props.autoplayInterval
@@ -68,7 +79,7 @@ var Carousel = React.forwardRef(function (props, ref) {
68
79
  transition: "transform ".concat(duration, "s ease-in-out"),
69
80
  }
70
81
  : 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)); }) }))] }))] }));
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)); }) }))] }))] })));
72
83
  });
73
84
  function safeMod(n, m) {
74
85
  return ((n % m) + m) % m;
@@ -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?: React.CSSProperties;
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?: React.CSSProperties;
50
- top: React.CSSProperties;
51
- bottom: React.CSSProperties;
52
- middle?: React.CSSProperties;
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;
@@ -24,7 +24,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import React, { useState, useRef } from "react";
25
25
  import { classNames } from "../../functions";
26
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"]);
27
+ var className = _a.className, disableCopy = _a.disableCopy, onClick = _a.onClick, children = _a.children, rest = __rest(_a, ["className", "disableCopy", "onClick", "children"]);
28
28
  var _b = useState(false), copied = _b[0], setCopied = _b[1];
29
29
  var timeoutRef = useRef(null);
30
30
  var handleCopy = function () {
@@ -40,11 +40,11 @@ var InlineCode = React.forwardRef(function (_a, ref) {
40
40
  timeoutRef.current = null;
41
41
  }, 3000);
42
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) {
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
44
  if (!disableCopy) {
45
45
  handleCopy();
46
46
  }
47
47
  onClick === null || onClick === void 0 ? void 0 : onClick(e);
48
- } }, props, { children: children })));
48
+ }, children: children })));
49
49
  });
50
50
  export default InlineCode;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { InputProps } from "./Input";
3
- import { CornerType } from "../../types";
3
+ import type { CornerType, Style } from "../../types";
4
4
  type IconInputProps = {
5
5
  /**
6
6
  * [Optional] Icon to display at the start of the input
@@ -17,7 +17,7 @@ type IconInputProps = {
17
17
  /**
18
18
  * [Optional] Inline styles to add to the container
19
19
  */
20
- style?: React.CSSProperties;
20
+ style?: Style;
21
21
  /**
22
22
  * [Optional] Corner style for the input
23
23
  */
@@ -14,6 +14,6 @@ import { forwardRef } from "react";
14
14
  import classNames from "../../functions/classNames";
15
15
  var IconInput = forwardRef(function (_a, ref) {
16
16
  var startIcon = _a.startIcon, endIcon = _a.endIcon, className = _a.className, style = _a.style, _b = _a.corners, corners = _b === void 0 ? "rounded" : _b, inputProps = _a.inputProps;
17
- return (_jsxs("div", { className: classNames("ajui-input-default ajui-icon-input corners--".concat(corners), className), style: style, ref: ref, children: [startIcon || null, _jsx("input", __assign({}, inputProps, { className: classNames("ajui-input-base corners--".concat(corners), inputProps === null || inputProps === void 0 ? void 0 : inputProps.className) })), endIcon || null] }));
17
+ return (_jsxs("div", { className: classNames("ajui-input-default ajui-icon-input ajui-corners--".concat(corners), className), style: style, ref: ref, children: [startIcon || null, _jsx("input", __assign({}, inputProps, { className: classNames("ajui-input-base ajui-corners--".concat(corners), inputProps === null || inputProps === void 0 ? void 0 : inputProps.className) })), endIcon || null] }));
18
18
  });
19
19
  export default IconInput;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CornerType } from "../../types";
2
+ import type { CornerType } from "../../types";
3
3
  type Props = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
4
4
  /**
5
5
  * Type of corners on the input
@@ -25,6 +25,6 @@ import { forwardRef } from "react";
25
25
  import classNames from "../../functions/classNames";
26
26
  var Input = forwardRef(function (_a, ref) {
27
27
  var className = _a.className, _b = _a.corners, corners = _b === void 0 ? "rounded" : _b, props = __rest(_a, ["className", "corners"]);
28
- return (_jsx("input", __assign({}, props, { ref: ref, className: classNames("ajui-input-base ajui-input-default corners--".concat(corners), className) })));
28
+ return (_jsx("input", __assign({}, props, { ref: ref, className: classNames("ajui-input-base ajui-input-default ajui-corners--".concat(corners), className) })));
29
29
  });
30
30
  export default Input;
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CornerType } from "../../types";
2
+ import type { CornerType } from "../../types";
3
3
  type TextAreaProps = React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> & {
4
4
  /**
5
5
  * Type of corners on the text area
@@ -25,6 +25,6 @@ import { forwardRef } from "react";
25
25
  import classNames from "../../functions/classNames";
26
26
  var TextArea = forwardRef(function (_a, ref) {
27
27
  var className = _a.className, _b = _a.rows, rows = _b === void 0 ? 3 : _b, _c = _a.corners, corners = _c === void 0 ? "rounded" : _c, props = __rest(_a, ["className", "rows", "corners"]);
28
- return (_jsx("textarea", __assign({}, props, { ref: ref, className: classNames("ajui-input-base ajui-input-default corners--".concat(corners), className), rows: rows })));
28
+ return (_jsx("textarea", __assign({}, props, { ref: ref, className: classNames("ajui-input-base ajui-input-default ajui-corners--".concat(corners), className), rows: rows })));
29
29
  });
30
30
  export default TextArea;
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
- type Props = {
2
+ import type { DivProps } from "../../types";
3
+ type Props<T extends React.ElementType> = Omit<DivProps, "children"> & {
3
4
  /**
4
5
  * Callback that fires when the user clicks outside the layer
5
6
  */
@@ -8,15 +9,7 @@ type Props = {
8
9
  * The child of the layer.
9
10
  * IMPORTANT: the child must be able to accept a ref
10
11
  */
11
- children: React.ReactElement;
12
- /**
13
- * [Optional] Additional class name
14
- */
15
- className?: string;
16
- /**
17
- * [Optional] Additional styles
18
- */
19
- style?: React.CSSProperties;
12
+ children: React.ReactElement<React.ComponentPropsWithRef<T>>;
20
13
  /**
21
14
  * [Optional] Whether to disable the escape key to close the layer
22
15
  * @default false
@@ -33,5 +26,5 @@ type Props = {
33
26
  */
34
27
  disableScrollLock?: boolean;
35
28
  };
36
- declare const Layer: ({ returnFocusOnEscape, disableScrollLock, ...props }: Props) => React.JSX.Element;
29
+ declare const Layer: <T extends React.ElementType>({ returnFocusOnEscape, disableScrollLock, ...props }: Props<T>) => React.JSX.Element;
37
30
  export default Layer;
@@ -1,10 +1,8 @@
1
1
  import React from "react";
2
2
  type BuiltinLinkProps = Omit<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>, "href">;
3
- export type CustomLinkElement = (props: Partial<BuiltinLinkProps> & {
3
+ export type CustomLinkElement = React.ForwardRefExoticComponent<BuiltinLinkProps & {
4
4
  to: string;
5
- } & {
6
- ref?: React.MutableRefObject<HTMLAnchorElement>;
7
- }) => React.ReactNode;
5
+ } & React.RefAttributes<HTMLAnchorElement>>;
8
6
  type DefaultLinkProps = BuiltinLinkProps & {
9
7
  /**
10
8
  * URL to navigate to
@@ -28,8 +28,8 @@ var DefaultLinkElement = forwardRef(function (_a, ref) {
28
28
  return _jsx("a", __assign({}, props, { href: to, ref: ref }));
29
29
  });
30
30
  export var UnstyledLink = forwardRef(function (_a, ref) {
31
- var _b = _a.LinkElement, LinkElement = _b === void 0 ? DefaultLinkElement : _b, props = __rest(_a, ["LinkElement"]);
32
- return (_jsx(LinkElement, __assign({}, props, { ref: ref })));
31
+ var _b = _a.LinkElement, LinkElement = _b === void 0 ? DefaultLinkElement : _b, className = _a.className, props = __rest(_a, ["LinkElement", "className"]);
32
+ return (_jsx(LinkElement, __assign({}, props, { className: classNames("ajui-action", className), ref: ref })));
33
33
  });
34
34
  var Link = forwardRef(function (_a, ref) {
35
35
  var className = _a.className, props = __rest(_a, ["className"]);
@@ -1,17 +1,10 @@
1
1
  import React from "react";
2
- import { CornerType } from "../../types";
2
+ import type { CornerType } from "../../types";
3
3
  type Props = React.DetailedHTMLProps<React.SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement> & {
4
4
  /**
5
5
  * Array of options to display in the select
6
6
  */
7
7
  options: string[];
8
- /**
9
- * Mapper function to get the value of the option
10
- *
11
- * @param option the option to get the value of
12
- * @returns the value of the option
13
- */
14
- getOptionValue?: (option: string) => string;
15
8
  /**
16
9
  * Mapper function to get the label of the option
17
10
  *
@@ -23,9 +23,8 @@ var __rest = (this && this.__rest) || function (s, e) {
23
23
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  import { forwardRef } from "react";
25
25
  import classNames from "../../functions/classNames";
26
- var identity = function (x) { return x; };
27
26
  var Select = function (_a, ref) {
28
- var className = _a.className, options = _a.options, _b = _a.getOptionValue, getOptionValue = _b === void 0 ? identity : _b, _c = _a.getOptionLabel, getOptionLabel = _c === void 0 ? identity : _c, _d = _a.corners, corners = _d === void 0 ? "rounded" : _d, style = _a.style, disabled = _a.disabled, props = __rest(_a, ["className", "options", "getOptionValue", "getOptionLabel", "corners", "style", "disabled"]);
29
- return (_jsxs("div", { className: classNames("ajui-select-container", "corners--".concat(corners), disabled ? "ajui-select-disabled" : undefined, className) || undefined, style: style, children: [_jsx("select", __assign({}, props, { ref: ref, className: "ajui-select-base corners--".concat(corners), disabled: disabled, children: options.map(function (option, index) { return (_jsx("option", { value: getOptionValue(option), children: getOptionLabel(option) }, index)); }) })), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 64 64", className: "ajui-select-triangle", "aria-hidden": "true", children: _jsx("path", { fill: "currentColor", d: "M 29.175781 50.824219 C 30.738281 52.386719 33.273438 52.386719 34.835938 50.824219 L 58.835938 26.824219 C 60.398438 25.261719 60.398438 22.726562 58.835938 21.164062 C 57.273438 19.601562 54.738281 19.601562 53.175781 21.164062 L 32 42.335938 L 10.824219 21.175781 C 9.261719 19.613281 6.726562 19.613281 5.164062 21.175781 C 3.601562 22.738281 3.601562 25.273438 5.164062 26.835938 L 29.164062 50.835938 Z M 29.175781 50.824219" }) })] }));
27
+ var className = _a.className, options = _a.options, getOptionLabel = _a.getOptionLabel, _b = _a.corners, corners = _b === void 0 ? "rounded" : _b, style = _a.style, disabled = _a.disabled, props = __rest(_a, ["className", "options", "getOptionLabel", "corners", "style", "disabled"]);
28
+ return (_jsxs("div", { className: classNames("ajui-select-container", "ajui-corners--".concat(corners), disabled ? "ajui-select-disabled" : undefined, className), style: style, children: [_jsx("select", __assign({}, props, { ref: ref, className: "ajui-select-base ajui-corners--".concat(corners), disabled: disabled, children: options.map(function (option, index) { return (_jsx("option", { value: option, children: (getOptionLabel === null || getOptionLabel === void 0 ? void 0 : getOptionLabel(option)) || option }, index)); }) })), _jsx("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 64 64", className: "ajui-select-triangle", "aria-hidden": "true", children: _jsx("path", { fill: "currentColor", d: "M 29.175781 50.824219 C 30.738281 52.386719 33.273438 52.386719 34.835938 50.824219 L 58.835938 26.824219 C 60.398438 25.261719 60.398438 22.726562 58.835938 21.164062 C 57.273438 19.601562 54.738281 19.601562 53.175781 21.164062 L 32 42.335938 L 10.824219 21.175781 C 9.261719 19.613281 6.726562 19.613281 5.164062 21.175781 C 3.601562 22.738281 3.601562 25.273438 5.164062 26.835938 L 29.164062 50.835938 Z M 29.175781 50.824219" }) })] }));
30
29
  };
31
30
  export default forwardRef(Select);
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import type { Style } from "../../types";
2
2
  type Props = {
3
3
  /**
4
4
  * [Optional] Additional class names to apply to the spinner.
@@ -7,7 +7,7 @@ type Props = {
7
7
  /**
8
8
  * [Optional] Additional styles to apply to the spinner.
9
9
  */
10
- style?: React.CSSProperties;
10
+ style?: Style;
11
11
  };
12
12
  declare const Spinner: ({ className, ...props }: Props) => import("react/jsx-runtime").JSX.Element;
13
13
  export default Spinner;
package/index.d.ts CHANGED
@@ -18,3 +18,4 @@ export { default as Select } from "./components/Select";
18
18
  export { default as Spinner } from "./components/Spinner";
19
19
  export * from "./hooks";
20
20
  export * from "./functions";
21
+ export * from "./types";
package/index.js CHANGED
@@ -21,3 +21,5 @@ export { default as Spinner } from "./components/Spinner";
21
21
  export * from "./hooks";
22
22
  // Functions
23
23
  export * from "./functions";
24
+ // Types
25
+ export * from "./types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.5.5",
3
+ "version": "1.5.6",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "type": "module",
6
6
  "main": "./index.js",
package/style.css CHANGED
@@ -6,7 +6,7 @@
6
6
  --ajui-darkest-gray: #333;
7
7
  --ajui-obsidian: #121212;
8
8
  --ajui-focus-ring-color: #b2dbfa;
9
- --ajui-default-color: #111;
9
+ --ajui-default-text-color: #111;
10
10
  --ajui-default-background: white;
11
11
  --ajui-default-border: var(--ajui-moon-gray);
12
12
  /* General values */
@@ -17,20 +17,10 @@
17
17
  --ajui-sharp-radius: 0;
18
18
  --ajui-rounded-radius: 8px;
19
19
  --ajui-pill-radius: 9999px;
20
- --ajui-circle-radius: 50%;
21
20
  /* Buttons */
22
21
  --ajui-button-primary-background: black;
23
22
  --ajui-button-primary-color: white;
24
- --ajui-button-secondary-background: white;
25
- --ajui-button-secondary-color: #111;
26
- --ajui-button-secondary-border: var(--ajui-moon-gray);
27
- --ajui-button-transparent-background: transparent;
28
23
  --ajui-button-secondary-border-hover: var(--ajui-darkest-gray);
29
- /* Input */
30
- --ajui-input-selection-color: var(--ajui-focus-ring-color);
31
- --ajui-input-border: var(--ajui-default-border);
32
- /* Select */
33
- --ajui-select-border: var(--ajui-moon-gray);
34
24
  /* Content types */
35
25
  --ajui-success-background: #dff2e1;
36
26
  --ajui-success-color: #1b5e20;
@@ -49,8 +39,6 @@
49
39
  --ajui-info-border: #90caf9;
50
40
 
51
41
  --ajui-static-background: #e8e8e8;
52
- --ajui-static-color: var(--ajui-default-color);
53
- --ajui-static-border: var(--ajui-default-border);
54
42
  /* Layer */
55
43
  --ajui-layer-backdrop-background: rgba(200, 200, 200, 0.7);
56
44
  /* Link */
@@ -60,22 +48,13 @@
60
48
  [data-theme="dark"] {
61
49
  /* General colors */
62
50
  --ajui-focus-ring-color: #6699cc;
63
- --ajui-default-color: white;
51
+ --ajui-default-text-color: white;
64
52
  --ajui-default-background: var(--ajui-obsidian);
65
53
  --ajui-default-border: var(--ajui-dark-gray);
66
54
  /* Buttons */
67
55
  --ajui-button-primary-background: white;
68
56
  --ajui-button-primary-color: var(--ajui-obsidian);
69
- --ajui-button-secondary-background: var(--ajui-obsidian);
70
- --ajui-button-secondary-color: white;
71
- --ajui-button-secondary-border: var(--ajui-dark-gray);
72
- --ajui-button-transparent-background: transparent;
73
57
  --ajui-button-secondary-border-hover: var(--ajui-moon-gray);
74
- /* Input */
75
- --ajui-input-selection-color: var(--ajui-focus-ring-color);
76
- --ajui-input-border: var(--ajui-dark-gray);
77
- /* Select */
78
- --ajui-select-border: var(--ajui-dark-gray);
79
58
  /* Content types */
80
59
  --ajui-success-background: #2a5733;
81
60
  --ajui-success-color: #d9efd8;
@@ -94,69 +73,58 @@
94
73
  --ajui-info-border: #1d8ea4;
95
74
 
96
75
  --ajui-static-background: var(--ajui-darkest-gray);
97
- --ajui-static-color: var(--ajui-default-color);
98
- --ajui-static-border: var(--ajui-default-border);
99
76
  /* Layer */
100
77
  --ajui-layer-backdrop-background: rgba(55, 55, 55, 0.7);
101
78
  /* Link */
102
79
  --ajui-link-color: #009ef3;
103
80
  }
104
81
 
105
- a:focus:not(:focus-visible) {
106
- outline: none;
107
- }
108
-
109
- a,
110
- button {
111
- outline-color: var(--ajui-link-color);
112
- }
113
-
114
82
  .ajui-input-default:not([disabled]):focus-within,
115
83
  .ajui-select-container:not([disabled]):focus-within {
116
84
  outline: 3px solid var(--ajui-focus-ring-color);
117
85
  outline-offset: 0;
118
86
  }
119
87
 
120
- .corners--rounded {
88
+ .ajui-corners--rounded {
121
89
  border-radius: var(--ajui-rounded-radius);
122
90
  }
123
91
 
124
- .corners--pill {
92
+ .ajui-corners--pill {
125
93
  border-radius: var(--ajui-pill-radius);
126
94
  }
127
95
 
128
- .corners--sharp {
96
+ .ajui-corners--sharp {
129
97
  border-radius: var(--ajui-sharp-radius);
130
98
  }
131
99
 
132
- .content--success {
100
+ .ajui-content--success {
133
101
  background-color: var(--ajui-success-background);
134
102
  color: var(--ajui-success-color);
135
103
  border-color: var(--ajui-success-border);
136
104
  }
137
105
 
138
- .content--warning {
106
+ .ajui-content--warning {
139
107
  background-color: var(--ajui-warning-background);
140
108
  color: var(--ajui-warning-color);
141
109
  border-color: var(--ajui-warning-border);
142
110
  }
143
111
 
144
- .content--error {
112
+ .ajui-content--error {
145
113
  background-color: var(--ajui-error-background);
146
114
  color: var(--ajui-error-color);
147
115
  border-color: var(--ajui-error-border);
148
116
  }
149
117
 
150
- .content--info {
118
+ .ajui-content--info {
151
119
  background-color: var(--ajui-info-background);
152
120
  color: var(--ajui-info-color);
153
121
  border-color: var(--ajui-info-border);
154
122
  }
155
123
 
156
- .content--static {
124
+ .ajui-content--static {
157
125
  background-color: var(--ajui-static-background);
158
- color: var(--ajui-static-color);
159
- border-color: var(--ajui-static-border);
126
+ color: var(--ajui-default-text-color);
127
+ border-color: var(--ajui-default-border);
160
128
  }
161
129
 
162
130
  /* Alert */
@@ -185,11 +153,16 @@ button {
185
153
  width: 100%;
186
154
  }
187
155
 
188
- /* Link */
189
- a {
156
+ /* Action (link/button) */
157
+ .ajui-action {
190
158
  color: inherit;
191
159
  text-decoration: none;
192
160
  cursor: pointer;
161
+ outline-color: var(--ajui-link-color);
162
+ }
163
+
164
+ .ajui-action:focus:not(:focus-visible) {
165
+ outline: none;
193
166
  }
194
167
 
195
168
  /* Button */
@@ -198,13 +171,12 @@ a {
198
171
  color: inherit;
199
172
  border: none;
200
173
  padding: 0;
201
- cursor: pointer;
202
174
  font-size: 16px;
203
- font-weight: 500;
204
175
  }
205
176
 
206
177
  .ajui-button-size--regular {
207
178
  padding: 8px 16px;
179
+ font-weight: 600;
208
180
  }
209
181
 
210
182
  .ajui-button-size--small {
@@ -232,17 +204,17 @@ a {
232
204
  transition: opacity var(--ajui-default-transition);
233
205
  }
234
206
 
235
- .ajui-button--transparent,
236
207
  .ajui-button--secondary {
237
- box-shadow: inset 0 0 0 1px var(--ajui-button-secondary-border);
208
+ box-shadow: inset 0 0 0 1px var(--ajui-default-border);
238
209
  transition: box-shadow var(--ajui-default-transition);
239
210
  }
240
211
 
241
212
  .ajui-button--secondary {
242
- background-color: var(--ajui-button-secondary-background);
213
+ background-color: var(--ajui-default-background);
243
214
  }
244
215
 
245
216
  .ajui-link-default {
217
+ font-weight: 600;
246
218
  color: var(--ajui-link-color);
247
219
  transition: opacity var(--ajui-default-transition);
248
220
  }
@@ -254,7 +226,6 @@ a {
254
226
  opacity: var(--ajui-default-opacity-dim);
255
227
  }
256
228
 
257
- .ajui-button--transparent:not([disabled]):hover,
258
229
  .ajui-button--secondary:not([disabled]):hover {
259
230
  box-shadow: inset 0 0 0 1px var(--ajui-button-secondary-border-hover);
260
231
  }
@@ -272,7 +243,7 @@ a {
272
243
  }
273
244
 
274
245
  .ajui-input-base::selection {
275
- background-color: var(--ajui-input-selection-color);
246
+ background-color: var(--ajui-focus-ring-color);
276
247
  }
277
248
 
278
249
  .ajui-icon-input {
@@ -291,6 +262,7 @@ a {
291
262
  transition: outline var(--ajui-default-transition);
292
263
  outline: 0px solid transparent;
293
264
  box-shadow: inset 0 0 0 1px var(--ajui-default-border);
265
+ background-color: var(--ajui-default-background);
294
266
  }
295
267
 
296
268
  .ajui-input-default:disabled {
@@ -305,8 +277,8 @@ a {
305
277
  width: fit-content;
306
278
  transition: outline var(--ajui-default-transition);
307
279
  outline: 0px solid transparent;
308
- box-shadow: inset 0 0 0 1px var(--ajui-select-border);
309
- background-color: inherit;
280
+ box-shadow: inset 0 0 0 1px var(--ajui-default-border);
281
+ background-color: var(--ajui-default-background);
310
282
  }
311
283
 
312
284
  .ajui-select-base {
@@ -374,7 +346,7 @@ a {
374
346
  /* Inline Code */
375
347
  .ajui-inline-code {
376
348
  background-color: var(--ajui-default-border);
377
- color: var(--ajui-default-color);
349
+ color: var(--ajui-default-text-color);
378
350
  border-radius: var(--ajui-rounded-radius);
379
351
  transition: background-color var(--ajui-default-transition);
380
352
  word-wrap: break-word;
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import React from "react";
1
2
  /**
2
3
  * The type of corner to display, controlling the border radius property.
3
4
  */
@@ -6,3 +7,11 @@ export type CornerType = "pill" | "rounded" | "sharp";
6
7
  * The type of message associated with a piece of content.
7
8
  */
8
9
  export type ContentType = "success" | "warning" | "error" | "info" | "static";
10
+ /**
11
+ * Standard style object to apply inline styling to components.
12
+ */
13
+ export type Style = React.CSSProperties;
14
+ /**
15
+ * Default props for a div element
16
+ */
17
+ export type DivProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>;