UNPKG

@yamada-ui/progress

Version:

Yamada UI progress components

311 lines (308 loc) • 9.56 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/index.ts var index_exports = {}; __export(index_exports, { CircleProgress: () => CircleProgress, CircleProgressLabel: () => CircleProgressLabel, Progress: () => Progress }); module.exports = __toCommonJS(index_exports); // src/circle-progress.tsx var import_core = require("@yamada-ui/core"); var import_use_animation = require("@yamada-ui/use-animation"); var import_utils = require("@yamada-ui/utils"); var import_jsx_runtime = require("react/jsx-runtime"); var CircleProgress = (0, import_core.forwardRef)( (props, ref) => { const [styles, { size = "6rem", ...mergedProps }] = (0, import_core.useComponentStyle)( "CircleProgress", props ); const { className, boxSize = size, children, color = "primary", isRounded, fullRounded = isRounded, isAnimation = false, max = 100, min = 0, speed = ["1.4s", "2s"], thickness = "0.625rem", trackColor = "border", value = 0, ...rest } = (0, import_core.omitThemeProps)(mergedProps); const isTransparent = value === 0 && !isAnimation; const percent = (0, import_utils.valueToPercent)(value, min, max); const interval = !isAnimation ? percent * 2.64 : void 0; const animation = (0, import_use_animation.useAnimation)({ duration: typeof speed[0] === "string" ? speed[0] : `${speed[0]}s`, iterationCount: "infinite", keyframes: { "0%": { strokeDasharray: "1, 400", strokeDashoffset: "0" }, "50%": { strokeDasharray: "400, 400", strokeDashoffset: "-100" }, "100%": { strokeDasharray: "400, 400", strokeDashoffset: "-260" } }, timingFunction: "linear" }); const css = { ...styles, fontSize: "$boxSize", vars: [ { name: "boxSize", token: "sizes", value: boxSize }, { name: "thickness", token: "sizes", value: thickness } ] }; const circleProps = isAnimation ? { animation } : { strokeDasharray: interval == null ? void 0 : `${interval} ${264 - interval}`, strokeDashoffset: 66, transitionDuration: "0.6s", transitionProperty: "stroke-dasharray, stroke", transitionTimingFunction: "ease" }; const ariaProps = !isAnimation ? { "aria-valuemax": max, "aria-valuemin": min, "aria-valuenow": value, role: "meter" } : {}; return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_core.ui.div, { ref, className: (0, import_utils.cx)("ui-circle-progress", className), __css: css, ...ariaProps, ...rest, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( CircleProgressShape, { boxSize, isAnimation, speed, children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CircleProgressCircle, { stroke: trackColor, strokeWidth: "$thickness" }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( CircleProgressCircle, { opacity: isTransparent ? 0 : void 0, stroke: color, strokeLinecap: fullRounded ? "round" : void 0, strokeWidth: "$thickness", ...circleProps } ) ] } ), children ] } ); } ); CircleProgress.displayName = "CircleProgress"; CircleProgress.__ui__ = "CircleProgress"; var CircleProgressCircle = ({ ...rest }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.circle, { cx: 50, cy: 50, fill: "transparent", r: 42, ...rest }); CircleProgressCircle.displayName = "CircleProgressCircle"; CircleProgressCircle.__ui__ = "CircleProgressCircle"; var CircleProgressShape = ({ boxSize, isAnimation, speed, ...rest }) => { const animation = (0, import_use_animation.useAnimation)({ duration: typeof speed[1] === "string" ? speed[1] : `${speed[1]}s`, iterationCount: "infinite", keyframes: { "0%": { transform: "rotate(0deg)" }, "100%": { transform: "rotate(360deg)" } }, timingFunction: "linear" }); const css = { boxSize, display: "block", ...isAnimation ? { animation } : {} }; return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.svg, { "aria-hidden": true, viewBox: "0 0 100 100", __css: css, ...rest }); }; CircleProgressShape.displayName = "CircleProgressShape"; CircleProgressShape.__ui__ = "CircleProgressShape"; var CircleProgressLabel = (0, import_core.ui)("span", { baseStyle: { fontSize: "0.25em", left: "50%", position: "absolute", textAlign: "center", top: "50%", transform: "translate(-50%, -50%)", width: "100%" } }); CircleProgressLabel.displayName = "CircleProgressLabel"; CircleProgressLabel.__ui__ = "CircleProgressLabel"; // src/progress.tsx var import_core2 = require("@yamada-ui/core"); var import_use_animation2 = require("@yamada-ui/use-animation"); var import_utils2 = require("@yamada-ui/utils"); var import_jsx_runtime2 = require("react/jsx-runtime"); var [ProgressProvider, useProgress] = (0, import_utils2.createContext)({ name: `ProgressStylesContext`, errorMessage: `useProgress returned is 'undefined'. Seems you forgot to wrap the components in "<Progress />" ` }); var Progress = (0, import_core2.forwardRef)((props, ref) => { var _a, _b; const [styles, mergedProps] = (0, import_core2.useComponentMultiStyle)("Progress", props); const { className, borderRadius: _borderRadius, children, hasStripe, isAnimation, isStripeAnimation, max = 100, min = 0, rounded, speed, value, ...rest } = (0, import_core2.omitThemeProps)(mergedProps, ["filledTrackColor"]); const borderRadius = (_b = _borderRadius != null ? _borderRadius : rounded) != null ? _b : (_a = styles.track) == null ? void 0 : _a.borderRadius; const css = { overflow: "hidden", pos: "relative", w: "100%", ...styles.track }; const ariaProps = !isAnimation ? { "aria-valuemax": max, "aria-valuemin": min, "aria-valuenow": value, role: "meter" } : {}; return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ProgressProvider, { value: styles, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)( import_core2.ui.div, { ref, className: (0, import_utils2.cx)("ui-progress", className), borderRadius, __css: css, ...ariaProps, ...rest, children: [ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( ProgressFilledTrack, { borderRadius, hasStripe, isAnimation, isStripeAnimation, max, min, speed, value } ), children ] } ) }); }); Progress.displayName = "Progress"; Progress.__ui__ = "Progress"; var ProgressFilledTrack = ({ hasStripe, isAnimation, isStripeAnimation, max = 100, min = 0, speed = "1.4s", value = 0, ...rest }) => { const percent = (0, import_utils2.valueToPercent)(value, min, max); const styles = useProgress(); const stripeAnimation = (0, import_use_animation2.useAnimation)({ duration: typeof speed === "string" ? speed : `${speed}s`, iterationCount: "infinite", keyframes: { "0%": { bgPosition: "1rem 0" }, "100%": { bgPosition: "0 0" } }, timingFunction: "linear" }); const interpolationAnimation = (0, import_use_animation2.useAnimation)({ duration: typeof speed === "string" ? speed : `${speed}s`, iterationCount: "infinite", keyframes: { "0%": { left: "-40%" }, "100%": { left: "100%" } }, timingFunction: "ease" }); isStripeAnimation = !isAnimation && hasStripe && isStripeAnimation; const css = { ...isStripeAnimation ? { animation: stripeAnimation } : {}, ...isAnimation ? { animation: interpolationAnimation, minWidth: "50%", position: "absolute", willChange: "left" } : {} }; const __css = { h: "100%", w: `${percent}%`, ...styles.filledTrack }; return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.div, { css, "aria-hidden": true, __css, ...rest }); }; ProgressFilledTrack.displayName = "ProgressFilledTrack"; ProgressFilledTrack.__ui__ = "ProgressFilledTrack"; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { CircleProgress, CircleProgressLabel, Progress }); //# sourceMappingURL=index.js.map