UNPKG

@react-spectrum/s2

Version:
137 lines (127 loc) 6.57 kB
require("./ProgressCircle.css"); var $ac757a4c2bd72aee$exports = require("../icons/useSpectrumContextProps.cjs"); var $5RNes$reactjsxruntime = require("react/jsx-runtime"); var $5RNes$reactariacomponents = require("react-aria-components"); var $5RNes$react = require("react"); var $5RNes$reactspectrumutils = require("@react-spectrum/utils"); function $parcel$export(e, n, v, s) { Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true}); } $parcel$export(module.exports, "ProgressCircleContext", () => $1c116ea4b0d2d023$export$afffa1e5edf12209); $parcel$export(module.exports, "ProgressCircle", () => $1c116ea4b0d2d023$export$c79b9d6b4cc92af7); /* * Copyright 2024 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ const $1c116ea4b0d2d023$export$afffa1e5edf12209 = /*#__PURE__*/ (0, $5RNes$react.createContext)(null); // Double check the types passed to each style, may not need all for each const $1c116ea4b0d2d023$var$wrapper = function anonymous(props, overrides) { let rules = " "; let width = false; let height = false; let matches = (overrides || '').matchAll(/(?:^|\s)(J|G|I|H|_u|_v|_s|__A|_d|_J|z|y|B|A|_P|_9|W|_l|_A|_z|Z|N|L|F|M|K)[^\s]+/g); for (let p of matches){ if (p[1] === "Z") width = true; if (p[1] === "F") height = true; rules += p[0]; } if (props.staticColor === "white") rules += ' -Ovbhqd-gcwrnr91'; else if (props.staticColor === "black") rules += ' -Ovbhqd-g4hn3s91'; if (props.size === "L") { if (!width) rules += ' ZG91'; } else if (props.size === "S") { if (!width) rules += ' Zu91'; } else if (!width) rules += ' ZC91'; if (props.size === "L") { if (!height) rules += ' FA91'; } else if (props.size === "S") { if (!height) rules += ' Ft91'; } else if (!height) rules += ' Fx91'; rules += ' fa91'; return rules; }; const $1c116ea4b0d2d023$var$track = function anonymous(props) { let rules = " "; if (props.isStaticColor) rules += ' Vd91'; else rules += ' Vf91'; rules += ' Vla91'; return rules; }; const $1c116ea4b0d2d023$var$fill = function anonymous(props) { let rules = " "; if (props.isStaticColor) rules += ' Ve91'; else rules += ' Vh91'; rules += ' Vlc91'; rules += ' _Sa91'; rules += ' _0d91'; return rules; }; const $1c116ea4b0d2d023$var$rotationAnimation = "Z8Un9b"; // stroke-dashoffset represents `100 - percentage`. See below for how this works. const $1c116ea4b0d2d023$var$dashoffsetAnimation = "uw9JJd"; let $1c116ea4b0d2d023$var$pxToRem = (px)=>px / 16 + 'rem'; const $1c116ea4b0d2d023$export$c79b9d6b4cc92af7 = /*#__PURE__*/ (0, $5RNes$react.forwardRef)(function ProgressCircle(props, ref) { [props, ref] = (0, $ac757a4c2bd72aee$exports.useSpectrumContextProps)(props, ref, $1c116ea4b0d2d023$export$afffa1e5edf12209); let { size: size = 'M', staticColor: staticColor, UNSAFE_style: UNSAFE_style, UNSAFE_className: UNSAFE_className = '' } = props; let domRef = (0, $5RNes$reactspectrumutils.useDOMRef)(ref); let strokeWidth = 3; if (size === 'S') strokeWidth = 2; else if (size === 'L') strokeWidth = 4; // SVG strokes are centered, so subtract half the stroke width from the radius to create an inner stroke. let radius = `calc(50% - ${$1c116ea4b0d2d023$var$pxToRem(strokeWidth / 2)})`; let isStaticColor = !!staticColor; return /*#__PURE__*/ (0, $5RNes$reactjsxruntime.jsx)((0, $5RNes$reactariacomponents.ProgressBar), { ...props, ref: domRef, style: UNSAFE_style, className: (renderProps)=>UNSAFE_className + $1c116ea4b0d2d023$var$wrapper({ ...renderProps, size: size, staticColor: staticColor }, props.styles), children: ({ percentage: percentage, isIndeterminate: isIndeterminate })=>/*#__PURE__*/ (0, $5RNes$reactjsxruntime.jsxs)("svg", { fill: "none", width: "100%", height: "100%", children: [ /*#__PURE__*/ (0, $5RNes$reactjsxruntime.jsx)("circle", { cx: "50%", cy: "50%", r: radius, strokeWidth: $1c116ea4b0d2d023$var$pxToRem(strokeWidth), className: $1c116ea4b0d2d023$var$track({ isStaticColor: isStaticColor }) }), /*#__PURE__*/ (0, $5RNes$reactjsxruntime.jsx)("circle", { cx: "50%", cy: "50%", r: radius, strokeWidth: $1c116ea4b0d2d023$var$pxToRem(strokeWidth), className: $1c116ea4b0d2d023$var$fill({ isStaticColor: isStaticColor }), style: { // These cubic-bezier timing functions were derived from the previous animation keyframes // using a best fit algorithm, and then manually adjusted to approximate the original animation. animation: isIndeterminate ? `${$1c116ea4b0d2d023$var$rotationAnimation} 1s cubic-bezier(.6, .1, .3, .9) infinite, ${$1c116ea4b0d2d023$var$dashoffsetAnimation} 1s cubic-bezier(.25, .1, .25, 1.3) infinite` : undefined }, // Normalize the path length to 100 so we can easily set stroke-dashoffset to a percentage. pathLength: "100", // Add extra gap between dashes so 0% works in Chrome. strokeDasharray: "100 200", strokeDashoffset: isIndeterminate || percentage == null ? undefined : 100 - percentage, strokeLinecap: "round" }) ] }) }); }); //# sourceMappingURL=ProgressCircle.cjs.map