react-pop-cards 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +155 -27
- package/dist/index.d.mts +24 -0
- package/dist/index.d.ts +20 -12
- package/dist/index.js +2 -43
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +54 -53
- package/dist/index.css +0 -2568
- package/dist/lib/components/Card.js +0 -203
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/es.weak-map.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
require("core-js/modules/es.symbol.description.js");
|
|
9
|
-
require("core-js/modules/es.array.reduce.js");
|
|
10
|
-
require("core-js/modules/es.regexp.to-string.js");
|
|
11
|
-
require("core-js/modules/web.dom-collections.iterator.js");
|
|
12
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
var _web = require("@react-spring/web");
|
|
14
|
-
var _reactResponsive = require("react-responsive");
|
|
15
|
-
require("../../index.css");
|
|
16
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
-
var _chromaJs = _interopRequireDefault(require("chroma-js"));
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
25
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable react-hooks/rules-of-hooks */
|
|
26
|
-
const Card = _ref => {
|
|
27
|
-
let {
|
|
28
|
-
data,
|
|
29
|
-
bgColor,
|
|
30
|
-
disposition,
|
|
31
|
-
isRounded,
|
|
32
|
-
tension,
|
|
33
|
-
friction
|
|
34
|
-
} = _ref;
|
|
35
|
-
const isMobile = (0, _reactResponsive.useMediaQuery)({
|
|
36
|
-
query: "(max-width: 640px)"
|
|
37
|
-
});
|
|
38
|
-
const activeCardRef = (0, _react.useRef)(null);
|
|
39
|
-
const parentCard = (0, _react.useRef)(null);
|
|
40
|
-
|
|
41
|
-
// NOTE: default content div classes
|
|
42
|
-
const cardDivClass = "col-span-3 flex justify-center items-center duration-100";
|
|
43
|
-
const miniCardDivClass = "col-span-2 gap-4 flex justify-center items-center duration-100";
|
|
44
|
-
const miniCardClass = "hover:scale-125 duration-200 cursor-pointer flex justify-center items-center max-sm:w-[4rem] max-sm:h-[4rem] w-[5rem] h-[5rem] shadow-lg";
|
|
45
|
-
|
|
46
|
-
// Define card data
|
|
47
|
-
const initialCardDimensions = {
|
|
48
|
-
width: "6rem",
|
|
49
|
-
height: "6rem"
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// NOTE: assign the data to the cards
|
|
53
|
-
|
|
54
|
-
const newArray = data.map(item => _objectSpread(_objectSpread({}, initialCardDimensions), item));
|
|
55
|
-
const [cards, setCards] = (0, _react.useState)(newArray);
|
|
56
|
-
|
|
57
|
-
// active card
|
|
58
|
-
const [activeCard, setActiveCard] = (0, _react.useState)(data[0].title);
|
|
59
|
-
(0, _react.useEffect)(() => {
|
|
60
|
-
handleCardClick(activeCard);
|
|
61
|
-
const handleLocalStorageUpdate = () => {
|
|
62
|
-
try {
|
|
63
|
-
const updatedArray = JSON.parse(localStorage.getItem("data")).map(item => _objectSpread(_objectSpread({}, initialCardDimensions), item));
|
|
64
|
-
setCards(updatedArray);
|
|
65
|
-
setActiveCard(updatedArray[0].title);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.error("Error parsing local storage data:", error);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
window.addEventListener("DataChange", handleLocalStorageUpdate);
|
|
71
|
-
return () => {
|
|
72
|
-
window.removeEventListener("DataChange", handleLocalStorageUpdate);
|
|
73
|
-
};
|
|
74
|
-
}, [data, activeCard, isMobile]);
|
|
75
|
-
|
|
76
|
-
// Handle card click and update dimensions
|
|
77
|
-
const handleCardClick = cardKey => {
|
|
78
|
-
const updatedCards = cards.map(card => {
|
|
79
|
-
return _objectSpread(_objectSpread({}, card), {}, {
|
|
80
|
-
width: cardKey === card.title ? isMobile ? "11rem" : "20rem" : initialCardDimensions.width,
|
|
81
|
-
height: cardKey === card.title ? isMobile ? "11rem" : "20rem" : initialCardDimensions.height
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
setCards(updatedCards);
|
|
85
|
-
setActiveCard(cardKey);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
// NOTE: Animated styles for each card
|
|
89
|
-
const animatedStyles = Object.keys(cards).reduce((acc, cardKey) => {
|
|
90
|
-
acc[cardKey] = (0, _web.useSpring)({
|
|
91
|
-
to: {
|
|
92
|
-
width: cards[cardKey[0]].width.toString(),
|
|
93
|
-
height: cards[cardKey[0]].height.toString(),
|
|
94
|
-
backgroundColor: bgColor
|
|
95
|
-
},
|
|
96
|
-
config: {
|
|
97
|
-
tension: tension,
|
|
98
|
-
friction: friction
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
return acc;
|
|
102
|
-
}, {});
|
|
103
|
-
|
|
104
|
-
// NOTE: parent classNames of the animated cards
|
|
105
|
-
const getCardClasses = key => {
|
|
106
|
-
key = Number(key);
|
|
107
|
-
switch (key) {
|
|
108
|
-
case 0:
|
|
109
|
-
return "flex justify-end items-end";
|
|
110
|
-
case 1:
|
|
111
|
-
return "flex items-end";
|
|
112
|
-
case 2:
|
|
113
|
-
return "flex justify-end";
|
|
114
|
-
case 3:
|
|
115
|
-
return "flex";
|
|
116
|
-
default:
|
|
117
|
-
return "lol";
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
// NOTE: classNames for the disposition
|
|
122
|
-
const getDisposition = disposition => {
|
|
123
|
-
switch (disposition) {
|
|
124
|
-
case "LeftRight":
|
|
125
|
-
return "".concat(isMobile ? "flex flex-col justify-center items-center gap-8 h-full" : "grid grid-cols-5 h-full");
|
|
126
|
-
case "RightLeft":
|
|
127
|
-
return "".concat(isMobile ? "flex flex-col-reverse justify-center items-center gap-8 h-full" : "grid grid-cols-5 h-full");
|
|
128
|
-
case "TopBottom":
|
|
129
|
-
return "flex flex-col justify-center items-center gap-8 h-full";
|
|
130
|
-
case "BottomTop":
|
|
131
|
-
return "flex flex-col-reverse justify-center items-center gap-8 h-full";
|
|
132
|
-
default:
|
|
133
|
-
return "grid grid-cols-5 h-full";
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// NOTE: text color according to bg color
|
|
138
|
-
const [textColor, setTextColor] = (0, _react.useState)();
|
|
139
|
-
(0, _react.useEffect)(() => {
|
|
140
|
-
const luminance = (0, _chromaJs.default)(bgColor).luminance();
|
|
141
|
-
luminance < 0.5 ? setTextColor("#e5e5e5") : setTextColor("#1c2531");
|
|
142
|
-
}, [bgColor]);
|
|
143
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
144
|
-
className: getDisposition(disposition)
|
|
145
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
146
|
-
className: (disposition === "LeftRight" ? "order-1" : "order-2") + " ".concat(cardDivClass)
|
|
147
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
148
|
-
className: "grid grid-cols-2 gap-2"
|
|
149
|
-
}, Object.entries(cards).map(_ref2 => {
|
|
150
|
-
let [key, value] = _ref2;
|
|
151
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
152
|
-
key: key,
|
|
153
|
-
className: getCardClasses(key),
|
|
154
|
-
ref: parentCard
|
|
155
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
156
|
-
style: {
|
|
157
|
-
color: textColor
|
|
158
|
-
}
|
|
159
|
-
}, /*#__PURE__*/_react.default.createElement(_web.animated.div, {
|
|
160
|
-
ref: activeCard === value.title ? activeCardRef : null,
|
|
161
|
-
style: animatedStyles[key],
|
|
162
|
-
onClick: () => handleCardClick(value.title),
|
|
163
|
-
className: "".concat(activeCard === value.title ? "px-6 py-4" : "flex justify-center items-center", " cursor-pointer duration-100 ").concat(isRounded ? " rounded-2xl" : " rounded-none")
|
|
164
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
165
|
-
className: "".concat(activeCard === value.title ? "min-h-full" : "max-sm:space-y-1 space-y-3")
|
|
166
|
-
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
167
|
-
className: "flex max-sm:flex-col-reverse justify-between items-center"
|
|
168
|
-
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
169
|
-
className: (activeCard === value.title ? "max-sm:text-xl text-4xl" : "max-sm:text-xs text-base") + " capitalize font-bold duration-100"
|
|
170
|
-
}, value.title), activeCard === value.title && value.image != null && /*#__PURE__*/_react.default.createElement("img", {
|
|
171
|
-
className: "max-sm:w-12 max-sm:h-12 w-20 h-20",
|
|
172
|
-
src: value.image,
|
|
173
|
-
alt: "imageCard"
|
|
174
|
-
})), activeCard === value.title && /*#__PURE__*/_react.default.createElement("p", {
|
|
175
|
-
className: "line-clamp-[8] text-justify max-sm:text-xs"
|
|
176
|
-
}, value.description)))));
|
|
177
|
-
}))), /*#__PURE__*/_react.default.createElement("div", {
|
|
178
|
-
className: (disposition === "RightLeft" ? "order-1" : "order-2") + " ".concat(miniCardDivClass),
|
|
179
|
-
style: {
|
|
180
|
-
color: textColor
|
|
181
|
-
}
|
|
182
|
-
}, Object.entries(cards).map(_ref3 => {
|
|
183
|
-
let [key, value] = _ref3;
|
|
184
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
185
|
-
key: key,
|
|
186
|
-
onClick: () => handleCardClick(value.title),
|
|
187
|
-
className: "bg-base-100 ".concat(activeCard === value.title ? "scale-105 shadow-xl" : "scale-90", " ").concat(miniCardClass, " ").concat(isRounded ? "rounded-2xl" : "rounded-none")
|
|
188
|
-
}, /*#__PURE__*/_react.default.createElement("label", {
|
|
189
|
-
className: "text-center text-xs capitalize"
|
|
190
|
-
}, value.title));
|
|
191
|
-
})));
|
|
192
|
-
};
|
|
193
|
-
Card.propTypes = {
|
|
194
|
-
data: _propTypes.default.array.isRequired
|
|
195
|
-
};
|
|
196
|
-
Card.defaultProps = {
|
|
197
|
-
disposition: "LeftRight",
|
|
198
|
-
bgColor: "#e5e7eb",
|
|
199
|
-
isRounded: false,
|
|
200
|
-
tension: 120,
|
|
201
|
-
friction: 10
|
|
202
|
-
};
|
|
203
|
-
var _default = exports.default = Card;
|