@helpwave/hightide
Version:
helpwave's component and theming library
337 lines (333 loc) • 10.5 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/components/Ring.tsx
var Ring_exports = {};
__export(Ring_exports, {
AnimatedRing: () => AnimatedRing,
RadialRings: () => RadialRings,
Ring: () => Ring,
RingWave: () => RingWave
});
module.exports = __toCommonJS(Ring_exports);
var import_react = require("react");
// src/util/noop.ts
var noop = () => void 0;
// src/components/Circle.tsx
var import_clsx = __toESM(require("clsx"));
var import_jsx_runtime = require("react/jsx-runtime");
var Circle = ({
radius = 20,
className = "bg-primary",
style,
...restProps
}) => {
const size = radius * 2;
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"div",
{
className: (0, import_clsx.default)(`rounded-full`, className),
style: {
width: `${size}px`,
height: `${size}px`,
...style
},
...restProps
}
);
};
// src/components/Ring.tsx
var import_clsx2 = __toESM(require("clsx"));
var import_jsx_runtime2 = require("react/jsx-runtime");
var Ring = ({
innerSize = 20,
width = 7,
className = "outline-primary"
}) => {
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
className: (0, import_clsx2.default)(`bg-transparent rounded-full outline`, className),
style: {
width: `${innerSize}px`,
height: `${innerSize}px`,
outlineWidth: `${width}px`
}
}
);
};
var AnimatedRing = ({
innerSize,
width,
className,
fillAnimationDuration = 3,
repeating = false,
onAnimationFinished = noop,
style
}) => {
const [currentWidth, setCurrentWidth] = (0, import_react.useState)(0);
const milliseconds = 1e3 * fillAnimationDuration;
const animate = (0, import_react.useCallback)((timestamp, startTime) => {
const progress = Math.min((timestamp - startTime) / milliseconds, 1);
const newWidth = Math.min(width * progress, width);
setCurrentWidth(newWidth);
if (progress < 1) {
requestAnimationFrame((newTimestamp) => animate(newTimestamp, startTime));
} else {
onAnimationFinished();
if (repeating) {
setCurrentWidth(0);
requestAnimationFrame((newTimestamp) => animate(newTimestamp, newTimestamp));
}
}
}, [milliseconds, onAnimationFinished, repeating, width]);
(0, import_react.useEffect)(() => {
if (currentWidth < width) {
requestAnimationFrame((timestamp) => animate(timestamp, timestamp));
}
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
className: "row items-center justify-center",
style: {
width: `${innerSize + 2 * width}px`,
height: `${innerSize + 2 * width}px`,
...style
},
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Ring,
{
innerSize,
width: currentWidth,
className
}
)
}
);
};
var RingWave = ({
startInnerSize = 20,
endInnerSize = 30,
width,
className,
fillAnimationDuration = 3,
repeating = false,
onAnimationFinished = noop,
style
}) => {
const [currentInnerSize, setCurrentInnerSize] = (0, import_react.useState)(startInnerSize);
const distance = endInnerSize - startInnerSize;
const milliseconds = 1e3 * fillAnimationDuration;
const animate = (0, import_react.useCallback)((timestamp, startTime) => {
const progress = Math.min((timestamp - startTime) / milliseconds, 1);
const newInnerSize = Math.min(
startInnerSize + distance * progress,
endInnerSize
);
setCurrentInnerSize(newInnerSize);
if (progress < 1) {
requestAnimationFrame((newTimestamp) => animate(newTimestamp, startTime));
} else {
onAnimationFinished();
if (repeating) {
setCurrentInnerSize(startInnerSize);
requestAnimationFrame((newTimestamp) => animate(newTimestamp, newTimestamp));
}
}
}, [distance, endInnerSize, milliseconds, onAnimationFinished, repeating, startInnerSize]);
(0, import_react.useEffect)(() => {
if (currentInnerSize < endInnerSize) {
requestAnimationFrame((timestamp) => animate(timestamp, timestamp));
}
}, []);
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
"div",
{
className: "row items-center justify-center",
style: {
width: `${endInnerSize + 2 * width}px`,
height: `${endInnerSize + 2 * width}px`,
...style
},
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Ring,
{
innerSize: currentInnerSize,
width,
className
}
)
}
);
};
var RadialRings = ({
circle1ClassName = "bg-primary/90 outline-primary/90",
circle2ClassName = "bg-primary/60 outline-primary/60",
circle3ClassName = "bg-primary/40 outline-primary/40",
waveWidth = 10,
waveBaseColor = "outline-white/20",
sizeCircle1 = 100,
sizeCircle2 = 200,
sizeCircle3 = 300
}) => {
const [currentRing, setCurrentRing] = (0, import_react.useState)(0);
const size = sizeCircle3;
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
"div",
{
className: "relative",
style: {
width: `${sizeCircle3}px`,
height: `${sizeCircle3}px`
},
children: [
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Circle,
{
radius: sizeCircle1 / 2,
className: (0, import_clsx2.default)(circle1ClassName, `absolute z-[10] -translate-y-1/2 -translate-x-1/2`),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`
}
}
),
currentRing === 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
AnimatedRing,
{
innerSize: sizeCircle1,
width: (sizeCircle2 - sizeCircle1) / 2,
onAnimationFinished: () => currentRing === 0 ? setCurrentRing(1) : null,
repeating: true,
className: (0, import_clsx2.default)(
circle2ClassName,
{ "opacity-5": currentRing !== 0 }
),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`,
position: "absolute",
translate: `-50% -50%`,
zIndex: 9
}
}
) : null,
currentRing === 2 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RingWave,
{
startInnerSize: sizeCircle1 - waveWidth,
endInnerSize: sizeCircle2,
width: waveWidth,
repeating: true,
className: (0, import_clsx2.default)(waveBaseColor, `opacity-5`),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`,
position: "absolute",
translate: `-50% -50%`,
zIndex: 9
}
}
) : null,
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Circle,
{
radius: sizeCircle2 / 2,
className: (0, import_clsx2.default)(
circle2ClassName,
{ "opacity-20": currentRing < 1 },
`absolute z-[8] -translate-y-1/2 -translate-x-1/2`
),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`
}
}
),
currentRing === 1 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
AnimatedRing,
{
innerSize: sizeCircle2 - 1,
width: (sizeCircle3 - sizeCircle2) / 2,
onAnimationFinished: () => currentRing === 1 ? setCurrentRing(2) : null,
repeating: true,
className: (0, import_clsx2.default)(circle3ClassName),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`,
position: "absolute",
translate: `-50% -50%`,
zIndex: 7
}
}
) : null,
currentRing === 2 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
RingWave,
{
startInnerSize: sizeCircle2,
endInnerSize: sizeCircle3 - waveWidth,
width: waveWidth,
repeating: true,
className: (0, import_clsx2.default)(waveBaseColor, `opacity-5`),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`,
position: "absolute",
translate: `-50% -50%`,
zIndex: 7
}
}
) : null,
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
Circle,
{
radius: sizeCircle3 / 2,
className: (0, import_clsx2.default)(
circle3ClassName,
{ "opacity-20": currentRing < 2 },
`absolute z-[6] -translate-y-1/2 -translate-x-1/2`
),
style: {
left: `${size / 2}px`,
top: `${size / 2}px`
}
}
)
]
}
);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AnimatedRing,
RadialRings,
Ring,
RingWave
});
//# sourceMappingURL=Ring.js.map