UNPKG

@trail-ui/react

Version:
162 lines (156 loc) 6.54 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/card/index.ts var card_exports = {}; __export(card_exports, { Card: () => _Card, CardBody: () => _CardBody, CardContext: () => CardContext, CardFooter: () => _CardFooter, CardHeader: () => _CardHeader }); module.exports = __toCommonJS(card_exports); // src/card/card.tsx 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"); var import_jsx_runtime = require("react/jsx-runtime"); var CardContext = (0, import_react.createContext)({}); function Card(props, ref) { [props, ref] = (0, import_react_aria_components.useContextProps)(props, ref, CardContext); const ctx = props; const { elementType, children, autoFocus, className, classNames, onPress, ...cardProps } = props; const variantProps = (0, import_theme.filterVariantProps)(props, import_theme.card.variantKeys); const Component = elementType || (props.isPressable ? "button" : "div"); let componentProps = cardProps; if (typeof Component === "string") { componentProps = (0, import_utils.filterDOMProps)(cardProps); } const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className); const { buttonProps, isPressed } = (0, import_react_aria.useButton)( { elementType: Component, onPress, isDisabled: !props.isPressable, ...cardProps }, ref ); const { focusProps, isFocused, isFocusVisible } = (0, import_react_aria.useFocusRing)({ autoFocus }); const { hoverProps, isHovered } = (0, import_react_aria.useHover)({ isDisabled: !props.isHoverable, ...cardProps }); const slots = (0, import_react.useMemo)( () => (0, import_theme.card)({ ...variantProps }), [variantProps] ); const context = (0, import_react.useMemo)( () => ({ isPressable: ctx.isPressable, isDisabled: ctx.isDisabled, isFooterBlurred: ctx.isFooterBlurred, disableAnimation: ctx.disableAnimation, fullWidth: ctx.fullWidth, slots, classNames }), [ ctx.isPressable, ctx.isDisabled, ctx.isFooterBlurred, ctx.disableAnimation, ctx.fullWidth, slots, classNames ] ); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( Component, { ...(0, import_utils.mergeProps)( props.isPressable ? { ...buttonProps, ...focusProps, role: "button" } : {}, props.isHoverable ? hoverProps : {}, componentProps ), ref, className: slots.base({ class: baseStyles }), tabIndex: props.isPressable ? 0 : -1, "data-disabled": (0, import_shared_utils.dataAttr)(props.isDisabled), "data-pressed": (0, import_shared_utils.dataAttr)(isPressed), "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), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardContext.Provider, { value: context, children }) } ); } var _Card = (0, import_react.forwardRef)(Card); // src/card/card-body.tsx var import_shared_utils2 = require("@trail-ui/shared-utils"); var import_react2 = require("react"); var import_jsx_runtime2 = require("react/jsx-runtime"); function CardBody(props, ref) { var _a; const { elementType, className, ...otherProps } = props; const Component = elementType || "div"; const { slots, classNames } = (0, import_react2.useContext)(CardContext); const bodyStyles = (0, import_shared_utils2.clsx)(classNames == null ? void 0 : classNames.body, className); return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component, { ref, className: (_a = slots.body) == null ? void 0 : _a.call(slots, { class: bodyStyles }), ...otherProps }); } var _CardBody = (0, import_react2.forwardRef)(CardBody); // src/card/card-footer.tsx var import_shared_utils3 = require("@trail-ui/shared-utils"); var import_react3 = require("react"); var import_jsx_runtime3 = require("react/jsx-runtime"); function CardFooter(props, ref) { var _a; const { elementType, className, ...otherProps } = props; const Component = elementType || "div"; const { slots, classNames } = (0, import_react3.useContext)(CardContext); const footerStyles = (0, import_shared_utils3.clsx)(classNames == null ? void 0 : classNames.footer, className); return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Component, { ref, className: (_a = slots.footer) == null ? void 0 : _a.call(slots, { class: footerStyles }), ...otherProps }); } var _CardFooter = (0, import_react3.forwardRef)(CardFooter); // src/card/card-header.tsx var import_shared_utils4 = require("@trail-ui/shared-utils"); var import_react4 = require("react"); var import_jsx_runtime4 = require("react/jsx-runtime"); function CardHeader(props, ref) { var _a; const { elementType, className, ...otherProps } = props; const Component = elementType || "div"; const { slots, classNames } = (0, import_react4.useContext)(CardContext); const headerStyles = (0, import_shared_utils4.clsx)(classNames == null ? void 0 : classNames.header, className); return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component, { ref, className: (_a = slots.header) == null ? void 0 : _a.call(slots, { class: headerStyles }), ...otherProps }); } var _CardHeader = (0, import_react4.forwardRef)(CardHeader); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Card, CardBody, CardContext, CardFooter, CardHeader });