celebration-flip
Version:
A beautiful animated flip text component for celebrating milestones with customizable text and hearts
64 lines (55 loc) • 3.43 kB
JavaScript
import { jsxs, jsx } from 'react/jsx-runtime';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var CelebrationFlip = function (_a) {
var mainText = _a.mainText, secondaryText = _a.secondaryText, _b = _a.primaryColor, primaryColor = _b === void 0 ? "dodgerblue" : _b, _c = _a.secondaryColor, secondaryColor = _c === void 0 ? "hotpink" : _c, _d = _a.duration, duration = _d === void 0 ? 3 : _d, _e = _a.className, className = _e === void 0 ? "" : _e;
// Split text into individual characters for animation
var splitText = function (text) {
return text
.split("")
.map(function (char, index) { return (jsx("span", { children: char === " " ? "" : char }, index)); });
};
// Create hearts and secondary text
var createSecondaryLine = function () {
var hearts = ["♥", "♥", "♥", "♥"];
var textChars = secondaryText.split("");
var endHearts = ["♥", "♥", "♥", "♥"];
return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], hearts.map(function (heart, index) { return (jsx("span", { children: heart }, "start-heart-".concat(index))); }), true), [
jsx("span", {}, "space-1")
], false), textChars.map(function (char, index) { return (jsx("span", { children: char === " " ? "" : char }, "text-".concat(index))); }), true), [
jsx("span", {}, "space-2")
], false), endHearts.map(function (heart, index) { return (jsx("span", { children: heart }, "end-heart-".concat(index))); }), true);
};
var style = {
"--clr-1": primaryColor,
"--clr-2": secondaryColor,
"--duration": "".concat(duration, "s"),
};
return (jsxs("section", { className: "celebration-flip ".concat(className), style: style, children: [jsx("div", { className: "flip-text", children: splitText(mainText) }), jsx("div", { className: "flip-text", children: createSecondaryLine() })] }));
};
export { CelebrationFlip };
//# sourceMappingURL=index.esm.js.map