UNPKG

@yamada-ui/transitions

Version:

Yamada UI transitions components

96 lines (95 loc) 3.18 kB
"use client" "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/airy.tsx var airy_exports = {}; __export(airy_exports, { Airy: () => Airy }); module.exports = __toCommonJS(airy_exports); var import_core = require("@yamada-ui/core"); var import_motion = require("@yamada-ui/motion"); var import_use_controllable_state = require("@yamada-ui/use-controllable-state"); var import_utils = require("@yamada-ui/utils"); var import_react = require("react"); var import_jsx_runtime = require("react/jsx-runtime"); var Airy = (0, import_motion.motionForwardRef)((props, ref) => { const [styles, mergedProps] = (0, import_core.useComponentStyle)("Airy", props); const { className, defaultValue = "from", delay = 0, isDisabled, disabled = isDisabled, duration = 0.2, from, isReadOnly, readOnly = isReadOnly, to, value: valueProp, onChange: onChangeProp, ...rest } = (0, import_core.omitThemeProps)(mergedProps); const [vars, { opacity }] = (0, import_core.useCreateVars)( { opacity: 1, ...styles, ...rest }, ["opacity"], { transform: true } ); const animate = (0, import_motion.useMotionAnimation)(); const [value, setValue] = (0, import_use_controllable_state.useControllableState)({ defaultValue, value: valueProp, onChange: onChangeProp }); const css = { vars, ...styles }; const onClick = (0, import_react.useCallback)(async () => { if (readOnly) return; await animate.start({ opacity: 0, transition: { delay, duration } }); setValue((prev) => prev === "from" ? "to" : "from"); await animate.start({ opacity, transition: { duration } }); }, [animate, setValue, readOnly, opacity, duration, delay]); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_motion.motion.button, { ref, type: "button", className: (0, import_utils.cx)("ui-airy", `ui-airy--${value}`, className), "data-disabled": (0, import_utils.dataAttr)(disabled), "data-readonly": (0, import_utils.dataAttr)(readOnly), "data-value": value, animate, disabled, initial: { opacity }, onClick, __css: css, ...rest, children: value === "from" ? from : to } ); }); Airy.displayName = "Airy"; Airy.__ui__ = "Airy"; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Airy }); //# sourceMappingURL=airy.js.map