@adamjanicki/ui 1.3.3 → 1.3.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.
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ContentType, CornerType } from "../../utils/types";
2
+ import { ContentType, CornerType } from "../../types";
3
3
  type Props = {
4
4
  /**
5
5
  * The type of alert to display.
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import React from "react";
25
- import { classNames } from "../../utils/util";
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
28
  return (_jsx("div", __assign({ className: classNames("ajui-alert content--".concat(type, " corners--").concat(corners), className), ref: ref }, rest)));
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { useState, useEffect } from "react";
14
- import { classNames } from "../../utils/util";
14
+ import classNames from "../../functions/classNames";
15
15
  var Animated = function (_a) {
16
16
  var visible = _a.visible, _b = _a.duration, duration = _b === void 0 ? 250 : _b, _c = _a.keepMountedOnExit, keepMountedOnExit = _c === void 0 ? false : _c, enter = _a.enter, exit = _a.exit, children = _a.children, className = _a.className, style = _a.style;
17
17
  var _d = useState(visible), shouldRender = _d[0], setShouldRender = _d[1];
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ContentType, CornerType } from "../../utils/types";
2
+ import { ContentType, CornerType } from "../../types";
3
3
  type Props = {
4
4
  /**
5
5
  * The type of badge to display.
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import React from "react";
25
- import { classNames } from "../../utils/util";
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
28
  return (_jsx("div", __assign({ className: classNames("ajui-badge content--".concat(type, " corners--").concat(corners), className), ref: ref }, rest)));
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { ContentType } from "../../utils/types";
2
+ import { ContentType } from "../../types";
3
3
  type Props = {
4
4
  /**
5
5
  * The type of badge to display.
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import React from "react";
25
- import { classNames } from "../../utils/util";
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
28
  return (_jsx("div", __assign({ className: classNames("content--".concat(type, " ajui-banner"), className), ref: ref }, rest)));
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { CustomLinkElement } from "../Link/Link";
3
- import { CornerType } from "../../utils/types";
3
+ import { 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
@@ -23,7 +23,7 @@ var __rest = (this && this.__rest) || function (s, e) {
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import { forwardRef } from "react";
25
25
  import { UnstyledLink } from "../Link/Link";
26
- import { classNames } from "../../utils/util";
26
+ import classNames from "../../functions/classNames";
27
27
  export var UnstyledButton = forwardRef(function (_a, ref) {
28
28
  var to = _a.to, LinkElement = _a.LinkElement, className = _a.className, props = __rest(_a, ["to", "LinkElement", "className"]);
29
29
  className = classNames("ajui-button-base", className);
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { InputProps } from "./Input";
3
- import { CornerType } from "../../utils/types";
3
+ import { CornerType } from "../../types";
4
4
  type IconInputProps = {
5
5
  /**
6
6
  * [Optional] Icon to display at the start of the input
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { forwardRef } from "react";
14
- import { classNames } from "../../utils/util";
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
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] }));
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CornerType } from "../../utils/types";
2
+ import { CornerType } from "../../types";
3
3
  type Props = React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> & {
4
4
  /**
5
5
  * Type of corners on the input
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import { forwardRef } from "react";
25
- import { classNames } from "../../utils/util";
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
28
  return (_jsx("input", __assign({}, props, { ref: ref, className: classNames("ajui-input-base ajui-input-default corners--".concat(corners), className) })));
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CornerType } from "../../utils/types";
2
+ import { CornerType } from "../../types";
3
3
  type TextAreaProps = React.DetailedHTMLProps<React.TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement> & {
4
4
  /**
5
5
  * Type of corners on the text area
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import { forwardRef } from "react";
25
- import { classNames } from "../../utils/util";
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
28
  return (_jsx("textarea", __assign({}, props, { ref: ref, className: classNames("ajui-input-base ajui-input-default corners--".concat(corners), className), rows: rows })));
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import React, { useEffect } from "react";
14
14
  import { useFocusTrap, useScrollLock } from "../../hooks";
15
- import { classNames } from "../../utils/util";
15
+ import classNames from "../../functions/classNames";
16
16
  var BaseLayer = function (_a) {
17
17
  var onClose = _a.onClose, children = _a.children, style = _a.style, className = _a.className, _b = _a.disableEscape, disableEscape = _b === void 0 ? false : _b, visible = _a.visible;
18
18
  var focusRef = useFocusTrap(visible);
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
24
  import { forwardRef } from "react";
25
- import { classNames } from "../../utils/util";
25
+ import classNames from "../../functions/classNames";
26
26
  var DefaultLinkElement = forwardRef(function (_a, ref) {
27
27
  var to = _a.to, props = __rest(_a, ["to"]);
28
28
  return _jsx("a", __assign({}, props, { href: to, ref: ref }));
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { CornerType } from "../../utils/types";
2
+ import { CornerType } from "../../types";
3
3
  type Props = Omit<React.DetailedHTMLProps<React.SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement>, "aria-label"> & {
4
4
  /**
5
5
  * Array of options to display in the select
@@ -22,7 +22,7 @@ var __rest = (this && this.__rest) || function (s, e) {
22
22
  };
23
23
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
24
  import { forwardRef } from "react";
25
- import { classNames } from "../../utils/util";
25
+ import classNames from "../../functions/classNames";
26
26
  var identity = function (x) { return x; };
27
27
  var Select = function (_a, ref) {
28
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, innerStyle = _a.innerStyle, innerClassName = _a.innerClassName, disabled = _a.disabled, props = __rest(_a, ["className", "options", "getOptionValue", "getOptionLabel", "corners", "style", "innerStyle", "innerClassName", "disabled"]);
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  return t;
22
22
  };
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
- import { classNames } from "../../utils/util";
24
+ import classNames from "../../functions/classNames";
25
25
  var Spinner = function (_a) {
26
26
  var className = _a.className, props = __rest(_a, ["className"]);
27
27
  return (
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Reduce a list of classnames into one string
3
+ *
4
+ * @param classNames list of class names to concatenate
5
+ * @returns single aggregated string of classnames
6
+ */
7
+ export default function classNames(...classNames: Array<string | null | undefined>): string;
@@ -2,9 +2,9 @@
2
2
  * Reduce a list of classnames into one string
3
3
  *
4
4
  * @param classNames list of class names to concatenate
5
- * @returns concatenated class names
5
+ * @returns single aggregated string of classnames
6
6
  */
7
- export function classNames() {
7
+ export default function classNames() {
8
8
  var classNames = [];
9
9
  for (var _i = 0; _i < arguments.length; _i++) {
10
10
  classNames[_i] = arguments[_i];
@@ -0,0 +1,2 @@
1
+ import classNames from "./classNames";
2
+ export { classNames };
@@ -0,0 +1,2 @@
1
+ import classNames from "./classNames";
2
+ export { classNames };
@@ -1,5 +1,5 @@
1
- import { useEffect, useRef } from "react";
2
- var focusableElementsString = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
1
+ import { useEffect, useRef, useCallback } from "react";
2
+ var selector = 'a[href], area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), iframe, object, embed, [tabindex="0"], [contenteditable]';
3
3
  /**
4
4
  * A hook for trapping focus within an element.
5
5
  *
@@ -10,42 +10,48 @@ var focusableElementsString = 'a[href], area[href], input:not([disabled]), selec
10
10
  var useFocusTrap = function (isActive) {
11
11
  if (isActive === void 0) { isActive = true; }
12
12
  var trapRef = useRef(null);
13
+ var focusableElements = useRef(null);
14
+ var updateFocusableElements = useCallback(function () {
15
+ if (trapRef.current) {
16
+ focusableElements.current = trapRef.current.querySelectorAll(selector);
17
+ }
18
+ }, []);
13
19
  useEffect(function () {
14
20
  if (!isActive || !trapRef.current)
15
21
  return;
16
- var focusableElements = trapRef.current.querySelectorAll(focusableElementsString);
17
- var trapFocus = function (event) {
22
+ updateFocusableElements();
23
+ var handleKeyDown = function (event) {
18
24
  var _a;
19
25
  if (event.key !== "Tab")
20
26
  return;
21
- if (focusableElements.length === 0)
27
+ if (!focusableElements.current ||
28
+ focusableElements.current.length === 0) {
22
29
  return event.preventDefault();
23
- var activeEl = document.activeElement;
24
- var firstEl = focusableElements[0];
25
- var lastEl = focusableElements[focusableElements.length - 1];
26
- var focusFirst = function () {
27
- firstEl.focus();
28
- event.preventDefault();
29
- };
30
- var focusLast = function () {
30
+ }
31
+ var activeElement = document.activeElement;
32
+ var firstEl = focusableElements.current[0];
33
+ var lastEl = focusableElements.current[focusableElements.current.length - 1];
34
+ if (event.shiftKey && activeElement === firstEl) {
31
35
  lastEl.focus();
32
36
  event.preventDefault();
33
- };
34
- if (activeEl === firstEl && event.shiftKey) {
35
- focusLast();
36
37
  }
37
- else if (activeEl === lastEl && !event.shiftKey) {
38
- focusFirst();
38
+ else if (!event.shiftKey && activeElement === lastEl) {
39
+ firstEl.focus();
40
+ event.preventDefault();
39
41
  }
40
- else if (!activeEl || !((_a = trapRef.current) === null || _a === void 0 ? void 0 : _a.contains(activeEl))) {
41
- event.shiftKey ? focusLast() : focusFirst();
42
+ else if (!((_a = trapRef.current) === null || _a === void 0 ? void 0 : _a.contains(activeElement))) {
43
+ (event.shiftKey ? lastEl : firstEl).focus();
44
+ event.preventDefault();
42
45
  }
43
46
  };
44
- document.addEventListener("keydown", trapFocus);
47
+ var observer = new MutationObserver(updateFocusableElements);
48
+ observer.observe(trapRef.current, { childList: true, subtree: true });
49
+ document.addEventListener("keydown", handleKeyDown);
45
50
  return function () {
46
- document.removeEventListener("keydown", trapFocus);
51
+ document.removeEventListener("keydown", handleKeyDown);
52
+ observer.disconnect();
47
53
  };
48
- }, [isActive]);
54
+ }, [isActive, updateFocusableElements]);
49
55
  return trapRef;
50
56
  };
51
57
  export default useFocusTrap;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui",
3
- "version": "1.3.3",
3
+ "version": "1.3.5",
4
4
  "description": "Basic UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
package/style.css CHANGED
@@ -302,7 +302,7 @@ a {
302
302
 
303
303
  .ajui-select-disabled {
304
304
  opacity: var(--ajui-disabled-opacity);
305
- cursor: not-allowed;
305
+ cursor: not-allowed !important;
306
306
  }
307
307
 
308
308
  .ajui-select-base {
@@ -310,6 +310,7 @@ a {
310
310
  color: inherit;
311
311
  outline: 0px solid transparent;
312
312
  border: none;
313
+ cursor: pointer;
313
314
  background-color: inherit;
314
315
  padding: 0.75rem 1.75rem 0.75rem 0.5rem;
315
316
  font-size: 1rem;
package/utils/util.d.ts DELETED
@@ -1,7 +0,0 @@
1
- /**
2
- * Reduce a list of classnames into one string
3
- *
4
- * @param classNames list of class names to concatenate
5
- * @returns concatenated class names
6
- */
7
- export declare function classNames(...classNames: (string | undefined)[]): string;
File without changes
File without changes