@trail-ui/react
Version:
1,183 lines (1,162 loc) • 47.3 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/tanstackGroupTable/tanstackGroupTable.tsx
var tanstackGroupTable_exports = {};
__export(tanstackGroupTable_exports, {
default: () => TanstackGroupTable
});
module.exports = __toCommonJS(tanstackGroupTable_exports);
var import_react_table = require("@tanstack/react-table");
var import_icons2 = require("@trail-ui/icons");
// src/avatar/avatar.tsx
var import_hooks = require("@trail-ui/hooks");
var import_shared_utils = require("@trail-ui/shared-utils");
var import_theme = require("@trail-ui/theme");
var import_utils = require("@react-aria/utils");
var import_react = require("react");
var import_react_aria = require("react-aria");
var import_react_aria_components = require("react-aria-components");
// src/avatar/avatar-icon.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var AvatarIcon = () => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
"svg",
{
"aria-hidden": "true",
fill: "none",
height: "80%",
role: "presentation",
viewBox: "0 0 24 24",
width: "80%",
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"path",
{
d: "M12 2C9.38 2 7.25 4.13 7.25 6.75C7.25 9.32 9.26 11.4 11.88 11.49C11.96 11.48 12.04 11.48 12.1 11.49C12.12 11.49 12.13 11.49 12.15 11.49C12.16 11.49 12.16 11.49 12.17 11.49C14.73 11.4 16.74 9.32 16.75 6.75C16.75 4.13 14.62 2 12 2Z",
fill: "currentColor"
}
),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"path",
{
d: "M17.0809 14.1489C14.2909 12.2889 9.74094 12.2889 6.93094 14.1489C5.66094 14.9989 4.96094 16.1489 4.96094 17.3789C4.96094 18.6089 5.66094 19.7489 6.92094 20.5889C8.32094 21.5289 10.1609 21.9989 12.0009 21.9989C13.8409 21.9989 15.6809 21.5289 17.0809 20.5889C18.3409 19.7389 19.0409 18.5989 19.0409 17.3589C19.0309 16.1289 18.3409 14.9889 17.0809 14.1489Z",
fill: "currentColor"
}
)
]
}
);
// src/avatar/avatar.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
var safeText = (name) => {
const parts = name.trim().split(" ");
if (parts.length === 1) {
return parts[0].slice(0, 2).toUpperCase();
} else {
return (parts[0][0] + parts[1][0]).toUpperCase();
}
};
var AvatarContext = (0, import_react.createContext)({});
function Avatar(props, ref) {
[props, ref] = (0, import_react_aria_components.useContextProps)(props, ref, AvatarContext);
const ctx = props;
const {
elementType,
src,
name,
icon = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AvatarIcon, {}),
className,
classNames,
fallback: fallbackComponent,
alt = name || "avatar",
color = "red",
radius = "full",
size = "md",
isBordered = false,
isDisabled = false,
ignoreFallback = false,
showFallback: showFallbackProp = false,
getInitials = safeText,
ImgComponent = "img",
imgProps,
onError,
onClick,
...avatarProps
} = props;
const Component = elementType || "span";
const { isFocusVisible, isFocused, focusProps } = (0, import_react_aria.useFocusRing)();
const { isHovered, hoverProps } = (0, import_react_aria.useHover)({ isDisabled });
const imageStatus = (0, import_hooks.useImage)({ src, onError, ignoreFallback });
const isImgLoaded = imageStatus === "loaded";
const showFallback = (!src || !isImgLoaded) && showFallbackProp;
const slots = (0, import_react.useMemo)(
() => {
var _a;
return (0, import_theme.avatar)({
color,
radius,
size,
isBordered,
isDisabled,
isInGroup: ctx == null ? void 0 : ctx.isInGroup,
isInGridGroup: (_a = ctx == null ? void 0 : ctx.isGrid) != null ? _a : false
});
},
[color, radius, size, isBordered, isDisabled, ctx == null ? void 0 : ctx.isInGroup, ctx == null ? void 0 : ctx.isGrid]
);
const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className);
const fallback = (0, import_react.useMemo)(() => {
if (!showFallback && src)
return null;
if (fallbackComponent) {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
"aria-label": alt,
className: slots.fallback({ class: classNames == null ? void 0 : classNames.fallback }),
role: "img",
children: fallbackComponent
}
);
}
return name ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-label": alt, className: slots.name({ class: classNames == null ? void 0 : classNames.name }), role: "img", children: getInitials(name) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "aria-label": alt, className: slots.icon({ class: classNames == null ? void 0 : classNames.icon }), role: "img", children: icon });
}, [showFallback, src, fallbackComponent, classNames, name, icon, alt, slots, getInitials]);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_aria_components.TooltipTrigger, { delay: 200, closeDelay: 200, children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_react_aria_components.Button,
{
isDisabled,
className: `${isDisabled ? "pointer-events-none cursor-default" : ""} focus-visible:rounded-full focus-visible:outline focus-visible:outline-2 focus-visible:outline-purple-600`,
onPress: onClick,
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
Component,
{
...(0, import_react_aria.mergeProps)((0, import_utils.filterDOMProps)(avatarProps), focusProps, hoverProps),
ref,
"data-hovered": (0, import_shared_utils.dataAttr)(isHovered),
"data-focused": (0, import_shared_utils.dataAttr)(isFocused),
"data-focus-visible": (0, import_shared_utils.dataAttr)(isFocusVisible),
className: slots.base({ class: baseStyles }),
children: [
src && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
ImgComponent,
{
src,
alt,
"data-loaded": (0, import_shared_utils.dataAttr)(isImgLoaded),
className: slots.img({ class: classNames == null ? void 0 : classNames.img }),
...imgProps
}
),
fallback
]
}
)
}
),
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
import_react_aria_components.Tooltip,
{
className: "shadow-medium pointer-events-none mt-1 rounded bg-neutral-900 text-neutral-50 dark:bg-neutral-900 dark:text-neutral-50",
placement: "bottom",
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "px-2 py-1 text-[10px]", children: alt })
}
)
] });
}
var _Avatar = (0, import_react.forwardRef)(Avatar);
// src/avatar/avatar-group.tsx
var import_react_utils = require("@trail-ui/react-utils");
var import_shared_utils2 = require("@trail-ui/shared-utils");
var import_theme2 = require("@trail-ui/theme");
var import_react2 = require("react");
var import_jsx_runtime3 = require("react/jsx-runtime");
function AvatarGroup(props, ref) {
const {
elementType,
max = 5,
total,
size,
color,
radius,
isBordered,
isDisabled,
isGrid,
renderCount = (count) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(_Avatar, { className: "hover:-translate-x-0", name: `+${count}` }),
className,
children,
...otherProps
} = props;
const Component = elementType || "span";
const context = (0, import_react2.useMemo)(
() => ({
isInGroup: true,
size,
color,
radius,
isGrid,
isBordered,
isDisabled
}),
[size, color, radius, isGrid, isBordered, isDisabled]
);
const classNames = (0, import_react2.useMemo)(() => (0, import_theme2.avatarGroup)({ className, isGrid }), [className, isGrid]);
const validChildren = (0, import_react_utils.getValidChildren)(children);
const childrenWithinMax = max ? validChildren.slice(0, max) : validChildren;
const remainingCount = total ? total : max != null ? validChildren.length - max : -1;
const clones = childrenWithinMax.map((child, index) => {
const isFirstAvatar = index === 0;
const isLastAvatar = index === childrenWithinMax.length - 1;
const childProps = {
className: (0, import_shared_utils2.clsx)(
isFirstAvatar ? "ms-0" : !isGrid ? "-ms-2" : "",
isLastAvatar && remainingCount < 1 ? "hover:-translate-x-0" : ""
)
};
return (0, import_react2.cloneElement)(child, (0, import_shared_utils2.compact)(childProps));
});
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Component, { ref, className: classNames, role: "group", ...otherProps, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(AvatarContext.Provider, { value: context, children: [
clones,
remainingCount > 0 && renderCount(remainingCount)
] }) });
}
var _AvatarGroup = (0, import_react2.forwardRef)(AvatarGroup);
// src/checkbox/checkbox.tsx
var import_shared_utils4 = require("@trail-ui/shared-utils");
var import_theme4 = require("@trail-ui/theme");
var import_react4 = require("react");
var import_react_aria_components3 = require("react-aria-components");
// src/checkbox/checkbox-group.tsx
var import_shared_utils3 = require("@trail-ui/shared-utils");
var import_theme3 = require("@trail-ui/theme");
var import_react3 = require("react");
var import_react_aria_components2 = require("react-aria-components");
var import_icons = require("@trail-ui/icons");
var import_jsx_runtime4 = require("react/jsx-runtime");
var CheckboxGroupThemeContext = (0, import_react3.createContext)({});
function CheckboxGroup(props, ref) {
const {
lineThrough,
orientation = "vertical",
label,
className,
classNames,
isInvalid,
children,
...otherProps
} = props;
const slots = (0, import_react3.useMemo)(() => (0, import_theme3.checkboxGroup)(), []);
const baseStyles = (0, import_shared_utils3.clsx)(classNames == null ? void 0 : classNames.base, className);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_aria_components2.CheckboxGroup, { ref, className: slots.base({ class: baseStyles }), ...otherProps, children: (renderProps) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
label && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_aria_components2.Label, { className: slots.label({ class: classNames == null ? void 0 : classNames.label }), children: label }),
children && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"div",
{
"data-orientation": orientation,
className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }),
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CheckboxGroupThemeContext.Provider, { value: { isInvalid, lineThrough }, children: typeof children === "function" ? children(renderProps) : children })
}
),
props.errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
import_react_aria_components2.Text,
{
slot: "errorMessage",
className: `${slots.errorMessage({ class: classNames == null ? void 0 : classNames.errorMessage })} flex flex-row items-center gap-0.5`,
children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_icons.ErrorIcon,
{
role: "img",
"aria-label": "Error",
"aria-hidden": "false",
className: "h-4 w-4 text-red-600"
}
),
props.errorMessage
]
}
) : props.description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components2.Text,
{
slot: "description",
className: slots.description({ class: classNames == null ? void 0 : classNames.description }),
children: props.description
}
) : null
] }) });
}
var _CheckboxGroup = (0, import_react3.forwardRef)(CheckboxGroup);
// src/checkbox/checkbox-icon.tsx
var import_jsx_runtime5 = require("react/jsx-runtime");
function CheckIcon(props) {
const { isSelected } = props;
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { "aria-hidden": "true", role: "presentation", viewBox: "0 0 17 18", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
"polyline",
{
fill: "none",
points: "1 9 7 14 15 4",
stroke: "currentColor",
strokeDasharray: 22,
strokeDashoffset: isSelected ? 44 : 66,
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: 2,
style: isSelected ? {
transition: "stroke-dashoffset 250ms linear 0s"
} : {}
}
) });
}
function IndeterminateIcon() {
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { stroke: "white", strokeWidth: 3, viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("line", { x1: "21", x2: "3", y1: "12", y2: "12" }) });
}
function CheckboxIcon(props) {
const { isIndeterminate, ...otherProps } = props;
const BaseIcon = isIndeterminate ? IndeterminateIcon : CheckIcon;
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BaseIcon, { ...otherProps });
}
// src/checkbox/checkbox.tsx
var import_jsx_runtime6 = require("react/jsx-runtime");
function Checkbox(props, ref) {
var _a, _b;
const groupThemeContext = (0, import_react4.useContext)(CheckboxGroupThemeContext);
const {
icon = /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckboxIcon, {}),
lineThrough = (_a = groupThemeContext == null ? void 0 : groupThemeContext.lineThrough) != null ? _a : false,
isInvalid = (_b = groupThemeContext == null ? void 0 : groupThemeContext.isInvalid) != null ? _b : false,
className,
classNames,
children,
...otherProps
} = props;
const slots = (0, import_react4.useMemo)(
() => (0, import_theme4.checkbox)({
lineThrough,
isInvalid
}),
[isInvalid, lineThrough]
);
const baseStyles = (0, import_shared_utils4.clsx)(classNames == null ? void 0 : classNames.base, className);
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_aria_components3.Checkbox, { ref, className: slots.base({ class: baseStyles }), ...otherProps, children: (renderProps) => {
const iconProps = {
"data-checked": String(renderProps.isSelected),
isSelected: renderProps.isSelected,
isIndeterminate: renderProps.isIndeterminate,
isInvalid: renderProps.isInvalid,
className: slots.icon({ class: classNames == null ? void 0 : classNames.icon })
};
const clonedIcon = typeof icon === "function" ? icon(iconProps) : (0, import_react4.cloneElement)(icon, iconProps);
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
"span",
{
"aria-hidden": "true",
className: slots.control({ class: classNames == null ? void 0 : classNames.control }),
"data-indeterminate": props.isIndeterminate,
children: clonedIcon
}
),
children && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: slots.label({ class: classNames == null ? void 0 : classNames.label }), children: typeof children === "function" ? children(renderProps) : children })
] });
} });
}
var _Checkbox = (0, import_react4.forwardRef)(Checkbox);
// src/checkbox/index.tsx
var import_react_aria_components4 = require("react-aria-components");
// src/lozenge/lozenge.tsx
var import_react5 = require("react");
var import_theme5 = require("@trail-ui/theme");
var import_jsx_runtime7 = require("react/jsx-runtime");
function Lozenge(props) {
const { color, size, value, className } = props;
const variantProps = (0, import_theme5.filterVariantProps)(props, import_theme5.lozenge.variantKeys);
const styles = (0, import_react5.useMemo)(
() => (0, import_theme5.lozenge)({
...variantProps,
color,
size
}),
[variantProps, color, size]
);
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: `${className} ${styles}`, children: value }) });
}
// src/button/button.tsx
var import_react7 = require("react");
var import_react_aria_components5 = require("react-aria-components");
var import_theme7 = require("@trail-ui/theme");
// src/spinner/spinner.tsx
var import_theme6 = require("@trail-ui/theme");
var import_react6 = require("react");
// src/spinner/spinners/bars.tsx
var import_jsx_runtime8 = require("react/jsx-runtime");
var Bars = (props) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("svg", { viewBox: "0 0 135 140", xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", ...props, children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("rect", { y: "10", width: "15", height: "120", rx: "6", children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "height",
begin: "0.5s",
dur: "1s",
values: "120;110;100;90;80;70;60;50;40;140;120",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "y",
begin: "0.5s",
dur: "1s",
values: "10;15;20;25;30;35;40;45;50;0;10",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("rect", { x: "30", y: "10", width: "15", height: "120", rx: "6", children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "height",
begin: "0.25s",
dur: "1s",
values: "120;110;100;90;80;70;60;50;40;140;120",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "y",
begin: "0.25s",
dur: "1s",
values: "10;15;20;25;30;35;40;45;50;0;10",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("rect", { x: "60", width: "15", height: "140", rx: "6", children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "height",
begin: "0s",
dur: "1s",
values: "120;110;100;90;80;70;60;50;40;140;120",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "y",
begin: "0s",
dur: "1s",
values: "10;15;20;25;30;35;40;45;50;0;10",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("rect", { x: "90", y: "10", width: "15", height: "120", rx: "6", children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "height",
begin: "0.25s",
dur: "1s",
values: "120;110;100;90;80;70;60;50;40;140;120",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "y",
begin: "0.25s",
dur: "1s",
values: "10;15;20;25;30;35;40;45;50;0;10",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("rect", { x: "120", y: "10", width: "15", height: "120", rx: "6", children: [
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "height",
begin: "0.5s",
dur: "1s",
values: "120;110;100;90;80;70;60;50;40;140;120",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
"animate",
{
attributeName: "y",
begin: "0.5s",
dur: "1s",
values: "10;15;20;25;30;35;40;45;50;0;10",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] })
] });
// src/spinner/spinners/dots.tsx
var import_jsx_runtime9 = require("react/jsx-runtime");
var Dots = (props) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("svg", { viewBox: "0 0 120 30", xmlns: "http://www.w3.org/2000/svg", fill: "currentColor", ...props, children: [
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("circle", { cx: "15", cy: "15", r: "15", children: [
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"animate",
{
attributeName: "r",
from: "15",
to: "15",
begin: "0s",
dur: "0.8s",
values: "15;9;15",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"animate",
{
attributeName: "fill-opacity",
from: "1",
to: "1",
begin: "0s",
dur: "0.8s",
values: "1;.5;1",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("circle", { cx: "60", cy: "15", r: "9", fillOpacity: "0.3", children: [
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"animate",
{
attributeName: "r",
from: "9",
to: "9",
begin: "0s",
dur: "0.8s",
values: "9;15;9",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"animate",
{
attributeName: "fill-opacity",
from: "0.5",
to: "0.5",
begin: "0s",
dur: "0.8s",
values: ".5;1;.5",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("circle", { cx: "105", cy: "15", r: "15", children: [
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"animate",
{
attributeName: "r",
from: "15",
to: "15",
begin: "0s",
dur: "0.8s",
values: "15;9;15",
calcMode: "linear",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
"animate",
{
attributeName: "fill-opacity",
from: "1",
to: "1",
begin: "0s",
dur: "0.8s",
values: "1;.5;1",
calcMode: "linear",
repeatCount: "indefinite"
}
)
] })
] });
// src/spinner/spinners/ring.tsx
var import_jsx_runtime10 = require("react/jsx-runtime");
var Ring = (props) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
"svg",
{
fill: "none",
stroke: "currentColor",
viewBox: "0 0 38 38",
xmlns: "http://www.w3.org/2000/svg",
...props,
children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("g", { fill: "none", fillRule: "evenodd", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("g", { transform: "translate(2.5 2.5)", strokeWidth: "5", children: [
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("circle", { strokeOpacity: ".5", cx: "16", cy: "16", r: "16" }),
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("path", { d: "M32 16c0-9.94-8.06-16-16-16", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
"animateTransform",
{
attributeName: "transform",
type: "rotate",
from: "0 16 16",
to: "360 16 16",
dur: "1s",
repeatCount: "indefinite"
}
) })
] }) })
}
);
// src/spinner/spinners/spin.tsx
var import_jsx_runtime11 = require("react/jsx-runtime");
var Spin = (props) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("svg", { stroke: "currentColor", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("g", { children: [
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("circle", { cx: "12", cy: "12", r: "9.5", fill: "none", strokeWidth: "3", strokeLinecap: "round", children: [
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
"animate",
{
attributeName: "stroke-dasharray",
dur: "1.5s",
calcMode: "spline",
values: "0 150;42 150;42 150;42 150",
keyTimes: "0;0.475;0.95;1",
keySplines: "0.42,0,0.58,1;0.42,0,0.58,1;0.42,0,0.58,1",
repeatCount: "indefinite"
}
),
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
"animate",
{
attributeName: "stroke-dashoffset",
dur: "1.5s",
calcMode: "spline",
values: "0;-16;-59;-59",
keyTimes: "0;0.475;0.95;1",
keySplines: "0.42,0,0.58,1;0.42,0,0.58,1;0.42,0,0.58,1",
repeatCount: "indefinite"
}
)
] }),
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
"animateTransform",
{
attributeName: "transform",
type: "rotate",
dur: "2s",
values: "0 12 12;360 12 12",
repeatCount: "indefinite"
}
)
] }) });
// src/spinner/spinner.tsx
var import_jsx_runtime12 = require("react/jsx-runtime");
var SPINNERS = {
bars: Bars,
dots: Dots,
ring: Ring,
spin: Spin
};
var DEFAULT_SPINNER = "spin";
function Spinner(props, ref) {
const { className, variant = DEFAULT_SPINNER, color, size, ...spinnerProps } = props;
const defaultSpinner = variant in SPINNERS ? variant : DEFAULT_SPINNER;
const SpinnerComponent = SPINNERS[defaultSpinner];
const styles = (0, import_react6.useMemo)(
() => (0, import_theme6.spinner)({
color,
size,
className
}),
[className, color, size]
);
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SpinnerComponent, { "aria-hidden": true, className: styles, ref, ...spinnerProps });
}
var _Spinner = (0, import_react6.forwardRef)(Spinner);
// src/button/button.tsx
var import_jsx_runtime13 = require("react/jsx-runtime");
function Button2(props, ref) {
const {
appearance,
// size = 'md',
spacing = "default",
fullWidth,
isLoading,
spinner: spinner2 = /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(_Spinner, { color: "current", size: "sm", ...props.spinnerProps }),
spinnerPlacement = "start",
startContent: startContentProp,
endContent: endContentProp,
disableAnimation,
className,
children,
...otherProps
} = props;
const styles = (0, import_react7.useMemo)(
() => (0, import_theme7.button)({
// size,
isLoading,
spinnerPlacement,
startContentProp: !!startContentProp,
endContentProp: !!endContentProp,
appearance,
spacing,
fullWidth,
disableAnimation,
className
}),
[
isLoading,
spinnerPlacement,
startContentProp,
endContentProp,
appearance,
spacing,
fullWidth,
disableAnimation,
className
]
);
const getIconClone = (icon) => (0, import_react7.isValidElement)(icon) ? (0, import_react7.cloneElement)(icon, {
"aria-hidden": true,
focusable: false,
tabIndex: -1
}) : null;
const startContent = getIconClone(startContentProp);
const endContent = getIconClone(endContentProp);
return (
// @ts-ignore
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_aria_components5.Button, { ref, className: styles, ...otherProps, children: () => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
!isLoading && startContent,
isLoading && spinnerPlacement === "start" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shrink-0", children: [
spinner2,
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { "aria-atomic": "true", "aria-live": "polite", className: "sr-only", children: [
"Loading",
" "
] })
] }),
children,
isLoading && spinnerPlacement === "end" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "shrink-0", children: [
/* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { "aria-atomic": "true", "aria-live": "polite", className: "sr-only", children: [
"Loading",
" "
] }),
spinner2
] }),
!isLoading && endContent
] }) })
);
}
var _Button = (0, import_react7.forwardRef)(Button2);
// src/tanstackGroupTable/tanstackGroupTable.tsx
var import_shared_utils5 = require("@trail-ui/shared-utils");
var import_react8 = require("react");
var import_theme8 = require("@trail-ui/theme");
var import_jsx_runtime14 = require("react/jsx-runtime");
function TanstackGroupTable({
columns,
data,
tableData,
checkBoxSelectedName,
tableName
}) {
const tableColumns = columns.map((column) => {
return {
id: column.id,
size: column.width,
header: () => {
switch (column.type) {
case "id":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"div",
{
className: "text-center",
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Checkbox,
{
"aria-label": `Select All ${tableName}`,
classNames: { control: "mr-0 text-center" },
...{
isSelected: Object.keys(rowSelection).length === data.length,
isIndeterminate: Object.keys(rowSelection).length > 0 && Object.keys(rowSelection).length < data.length,
checked: Object.keys(rowSelection).length === data.length,
onChange: () => {
const allSelected = Object.keys(rowSelection).length === data.length;
const newSelection = allSelected ? {} : data.reduce((acc, row) => {
acc[row.id] = true;
return acc;
}, {});
setRowSelection(newSelection);
}
}
}
)
}
);
default:
return column.name;
}
},
accessorKey: column.accessor,
cell: ({ cell }) => {
switch (column.type) {
case "id":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Checkbox,
{
"aria-labelledby": `Select ${cell.row.original[checkBoxSelectedName != null ? checkBoxSelectedName : ""]}`,
classNames: { control: "mr-0 text-center" },
...{
isSelected: cell.row.getIsSelected(),
onChange: () => cell.row.toggleSelected()
}
}
) });
case "text":
return cell.getValue();
case "date":
return new Date(cell.getValue()).toLocaleDateString();
case "number":
return cell.getValue();
case "status":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
Lozenge,
{
size: "sm",
variant: "light",
value: cell.getValue(),
color: cell.getValue() === "Active" ? "green" : cell.getValue() === "Inactive" ? "red" : "yellow"
}
);
case "percentage":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
Lozenge,
{
size: "sm",
variant: "light",
value: `${cell.getValue()}`,
color: cell.getValue() > 0 ? "green" : cell.getValue() < 0 ? "red" : "yellow"
}
);
case "image":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("figure", { className: "min-w-36", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"img",
{
className: "h-10",
src: cell.getValue(),
style: {
objectFit: column.objectFit ? column.objectFit : "cover",
width: column.objectFit === "contain" ? "max-content" : "100%"
},
alt: ""
}
) });
case "username":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { className: "flex items-center gap-1 text-sm text-neutral-900", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Avatar,
{
id: cell.getValue(),
size: "md",
is: "span",
name: cell.getValue(),
getInitials: (name) => name.toUpperCase().slice(0, 2),
showFallback: true,
color: ["green", "red", "yellow", "default", "purple", "blue"][Math.floor(Math.random() * 6)]
}
) });
case "usersList":
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(_AvatarGroup, { size: "md", max: 2, children: (cell.getValue() || []).map((user) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Avatar,
{
size: "md",
is: "span",
src: user.avatar,
name: user.name,
getInitials: (name) => name.toUpperCase().slice(0, 2),
showFallback: true,
color: ["green", "red", "yellow", "default", "purple", "blue"][Math.floor(Math.random() * 6)]
},
user.id
)) });
default:
return cell.getValue();
}
}
};
});
const [sorting, setSorting] = (0, import_react8.useState)([]);
const [rowSelection, setRowSelection] = (0, import_react8.useState)({});
const [expanded, setExpanded] = (0, import_react8.useState)({});
const table = (0, import_react_table.useReactTable)({
enableRowSelection: true,
columns: tableColumns,
data,
// sortDescFirst: true,
// enableSortingRemoval: false,
defaultColumn: {
size: 100
},
getCoreRowModel: (0, import_react_table.getCoreRowModel)(),
getSortedRowModel: (0, import_react_table.getSortedRowModel)(),
getExpandedRowModel: (0, import_react_table.getExpandedRowModel)(),
onRowSelectionChange: setRowSelection,
onSortingChange: setSorting,
onExpandedChange: setExpanded,
getPaginationRowModel: (0, import_react_table.getPaginationRowModel)(),
state: {
sorting,
rowSelection,
expanded
},
initialState: {
pagination: {
pageSize: tableData ? tableData : 10,
pageIndex: 0
}
}
});
const currentPage = table.getState().pagination.pageIndex + 1;
const pageCount = table.getPageCount();
const pageNumbers = [];
const maxButtonsToShow = 5;
if (pageCount <= maxButtonsToShow) {
for (let i = 1; i <= pageCount; i++) {
pageNumbers.push(i);
}
} else {
let startPage, endPage;
const middleButtonsToShow = maxButtonsToShow - 2;
const halfMiddleButtonsToShow = Math.floor(middleButtonsToShow / 2);
if (currentPage <= halfMiddleButtonsToShow + 1) {
startPage = 2;
endPage = middleButtonsToShow + 1;
} else if (currentPage + halfMiddleButtonsToShow >= pageCount) {
startPage = pageCount - middleButtonsToShow;
endPage = pageCount - 1;
} else {
startPage = currentPage - halfMiddleButtonsToShow;
endPage = currentPage + halfMiddleButtonsToShow;
}
pageNumbers.push(1);
if (startPage > 2) {
pageNumbers.push("...");
}
for (let i = startPage; i <= endPage; i++) {
pageNumbers.push(i);
}
if (endPage < pageCount - 1) {
pageNumbers.push("...");
}
pageNumbers.push(pageCount);
}
function toggleSort(header) {
const sortingHandler = header.column.getToggleSortingHandler();
if (sortingHandler) {
sortingHandler({ persist: () => {
} });
}
}
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_jsx_runtime14.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "rounded", children: [
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "h-full overflow-auto rounded border border-neutral-200", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: "grid-container", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("table", { className: "w-full table-auto overflow-x-auto bg-white", children: [
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("thead", { className: "border-b border-b-neutral-200 text-neutral-600", children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("tr", { children: headerGroup.headers.map((header) => {
var _a;
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"th",
{
scope: "col",
colSpan: header.colSpan,
className: `h-10 min-h-10 border-r border-r-neutral-200 bg-neutral-100 p-2 text-sm font-semibold text-neutral-900 first:w-10 first:text-center last:border-r-0`,
children: header.isPlaceholder && header.column.getIndex() === 0 ? null : header.id == "id" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: (0, import_react_table.flexRender)(header.column.columnDef.header, header.getContext()) }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Button,
{
appearance: "transparent",
className: (0, import_shared_utils5.clsx)(
header.column.getCanSort() ? "cursor-pointer select-none" : "",
`'justify-start' w-full items-center px-0 text-sm font-semibold text-neutral-900`
),
onPress: () => toggleSort(header),
onKeyDown: (event) => {
if (event.key === "Enter" || event.key === " ") {
header.column.getToggleSortingHandler();
}
},
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("span", { className: `'justify-between' flex w-full items-center gap-4`, children: [
(0, import_react_table.flexRender)(header.column.columnDef.header, header.getContext()),
header.column.getCanSort() && header.id !== "id" ? (
// currentSort === header.id
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "sort-icon", children: (_a = {
asc: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
import_icons2.ArrowUpIcon,
{
color: import_theme8.commonColors.neutral[800],
width: 16,
height: 16
}
),
desc: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
import_icons2.ArrowDownIcon,
{
color: import_theme8.commonColors.neutral[800],
width: 16,
height: 16
}
)
}[header.column.getIsSorted()]) != null ? _a : null })
) : null
] })
}
)
},
header.id
);
}) }, headerGroup.id)) }),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("tbody", { className: "text-neutral-900", children: table.getRowModel().rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
!row.getIsExpanded() && /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("tr", { className: "border-b border-b-neutral-200", children: [
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("td", { className: "h-10 border-b border-l border-b-neutral-200 border-l-neutral-200 px-2 py-2 text-sm font-normal text-neutral-900 first:w-10 first:border-l-0 first:text-center", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Checkbox,
{
"aria-label": "Select textual description issue",
classNames: { control: "m-0" },
...{
isSelected: row.getIsSelected(),
onChange: () => row.toggleSelected()
}
}
) }),
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
"td",
{
className: "border-b border-l border-b-neutral-200 border-l-neutral-200 p-2 px-2 py-2 text-sm font-normal text-neutral-900 first:w-10 first:border-l-0 first:text-center",
colSpan: tableColumns.length,
children: [
" ",
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: "text-sm font-medium text-neutral-900", children: '1. An incomplete textual description "PF Harris" is provided for the logo image link instead of "PF Harris logo" in the header section (4 instances)' })
]
}
)
] }, `${row.id}-expanded`),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("tr", { children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"td",
{
className: "border-b border-l border-b-neutral-200 border-l-neutral-200 px-2 py-2 text-sm font-normal text-neutral-900 first:w-10 first:border-l-0 first:text-center",
children: (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext())
},
cell.id
)) }, row.id),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("tr", { children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"td",
{
className: "first:text-centerpy-2 border-b border-l border-b-neutral-200 border-l-neutral-200 px-2 py-2 text-sm font-normal text-neutral-900 first:w-10 first:border-l-0 first:text-center",
children: (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext())
},
cell.id + 1
)) }, row.id + 1),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("tr", { children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"td",
{
className: "border-b border-l border-b-neutral-200 border-l-neutral-200 px-2 py-2 text-sm font-normal text-neutral-900 first:w-10 first:border-l-0 first:text-center",
children: (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext())
},
cell.id + 2
)) }, row.id + 2),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("tr", { children: row.getVisibleCells().map((cell) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"td",
{
className: "first:text-centerpy-2 border-b border-l border-b-neutral-200 border-l-neutral-200 px-2 py-2 text-sm font-normal text-neutral-900 first:w-10 first:border-l-0 first:text-center",
children: (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext())
},
cell.id + 3
)) }, row.id + 3)
] })) })
] }) }) }),
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { className: "mt-2 flex items-center justify-between space-x-2 p-2", children: [
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("p", { className: "text-sm text-neutral-600", children: [
"Showing ",
table.getRowModel().rows.length,
" out of ",
data.length,
" results"
] }) }),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("nav", { "aria-label": "Pagination", className: "flex justify-end", children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("ul", { className: "justtify-end flex", children: [
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Button,
{
"aria-label": "Previous page",
appearance: "transparent",
isDisabled: !table.getCanPreviousPage(),
onPress: () => table.previousPage(),
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
import_icons2.ChevronLeftIcon,
{
color: `${currentPage === 1 ? "#B0ACBB" : "#302E38"}`,
width: 24,
height: 24
}
)
}
) }),
pageNumbers.map((pageNumber, index) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("li", { children: pageNumber === "..." ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: "..." }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
"button",
{
...pageNumber === currentPage ? { "aria-current": "page" } : {},
"aria-current": pageNumber === currentPage ? "page" : void 0,
onClick: () => {
if (pageNumber !== "...") {
table.setPageIndex(pageNumber - 1);
}
},
className: `px-3 py-1 text-sm font-normal text-neutral-800 ${pageNumber === currentPage ? "rounded-sm bg-purple-100" : "bg-white"} ${pageNumber !== "..." ? "underline" : ""}`,
children: pageNumber
}
) }, index)),
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
_Button,
{
appearance: "transparent",
isDisabled: !table.getCanNextPage(),
onPress: () => table.nextPage(),
"aria-label": "Next page",
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
import_icons2.ChevronRightIcon,
{
color: !table.getCanNextPage() ? "#B0ACBB" : "#302E38",
width: 24,
height: 24
}
)
}
) })
] }) })
] })
] }) });
}