UNPKG

@trail-ui/react

Version:
137 lines (132 loc) 5.51 kB
"use strict"; 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/listbox/listbox-item.tsx var listbox_item_exports = {}; __export(listbox_item_exports, { ListBoxItem: () => ListBoxItem }); module.exports = __toCommonJS(listbox_item_exports); var import_shared_utils2 = require("@trail-ui/shared-utils"); var import_theme2 = require("@trail-ui/theme"); var import_react2 = require("react"); var import_react_aria_components2 = require("react-aria-components"); // src/listbox/listbox.tsx var import_shared_utils = require("@trail-ui/shared-utils"); var import_theme = require("@trail-ui/theme"); var import_react = require("react"); var import_react_aria_components = require("react-aria-components"); var import_jsx_runtime = require("react/jsx-runtime"); var InternalListBoxContext = (0, import_react.createContext)( {} ); // src/listbox/listbox-selected-icon.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); function ListBoxSelectedIcon(props) { const { isSelected, ...otherProps } = props; return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "svg", { "aria-hidden": "true", "data-selected": isSelected, role: "presentation", viewBox: "0 0 16 16", ...otherProps, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "polyline", { fill: "none", points: "1 9 7 14 15 4", stroke: "currentColor", strokeDasharray: 22, strokeDashoffset: isSelected ? 44 : 66, strokeWidth: 2, style: { transition: "stroke-dashoffset 200ms ease" } } ) } ); } // src/listbox/listbox-item.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); function ListBoxItem(props) { const context = (0, import_react2.useContext)(InternalListBoxContext); const { children, description, startContent, endContent, selectedIcon, className, classNames = context.itemClasses, ...otherProps } = props; const slots = (0, import_react2.useMemo)(() => (0, import_theme2.menuItem)(), []); const baseStyles = (0, import_shared_utils2.clsx)(classNames == null ? void 0 : classNames.base, className); return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( import_react_aria_components2.ListBoxItem, { ...otherProps, textValue: "ListBoxItem", className: slots.base({ class: baseStyles }), children: ({ isSelected, isDisabled, selectionMode, isFocused }) => { if (isFocused && props.textValue && props.onFocusChange) { props.onFocusChange(props.textValue); } const selectedContent = () => { const defaultIcon = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ListBoxSelectedIcon, { isSelected }); if (typeof selectedIcon === "function") { return selectedIcon({ icon: defaultIcon, isSelected, isDisabled }); } if (selectedIcon) return selectedIcon; return defaultIcon; }; return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [ startContent, description ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: [ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components2.Text, { slot: "label", className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children }) }), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( import_react_aria_components2.Text, { slot: "description", className: slots.description({ class: classNames == null ? void 0 : classNames.description }), children: description } ) ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components2.Text, { slot: "label", className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children }) }), isSelected && selectionMode !== "none" && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( "span", { "aria-hidden": "true", className: slots.selectedIcon({ class: classNames == null ? void 0 : classNames.selectedIcon }), children: selectedContent() } ), endContent ] }); } } ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ListBoxItem });