@gfazioli/mantine-clock 1.0.4 → 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/dist/cjs/Clock.cjs +152 -3
- package/dist/cjs/Clock.cjs.map +1 -1
- package/dist/cjs/Clock.module.css.cjs +1 -1
- package/dist/esm/Clock.mjs +152 -3
- package/dist/esm/Clock.mjs.map +1 -1
- package/dist/esm/Clock.module.css.mjs +1 -1
- package/dist/styles.css +14 -2
- package/dist/styles.layer.css +14 -2
- package/dist/types/Clock.d.ts +35 -3
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/Clock.cjs
CHANGED
|
@@ -44,7 +44,10 @@ const varsResolver = core.createVarsResolver(
|
|
|
44
44
|
secondaryNumbersOpacity,
|
|
45
45
|
secondHandColor,
|
|
46
46
|
minuteHandColor,
|
|
47
|
-
hourHandColor
|
|
47
|
+
hourHandColor,
|
|
48
|
+
secondsArcColor,
|
|
49
|
+
minutesArcColor,
|
|
50
|
+
hoursArcColor
|
|
48
51
|
}) => {
|
|
49
52
|
const sizeValue = size || "md";
|
|
50
53
|
const clockSize = typeof sizeValue === "string" && sizeValue in defaultClockSizes ? defaultClockSizes[sizeValue] : sizeValue;
|
|
@@ -87,6 +90,18 @@ const varsResolver = core.createVarsResolver(
|
|
|
87
90
|
"--clock-hour-hand-color": core.parseThemeColor({
|
|
88
91
|
color: hourHandColor || "",
|
|
89
92
|
theme
|
|
93
|
+
}).value,
|
|
94
|
+
"--clock-seconds-arc-color": core.parseThemeColor({
|
|
95
|
+
color: secondsArcColor || secondHandColor || "",
|
|
96
|
+
theme
|
|
97
|
+
}).value,
|
|
98
|
+
"--clock-minutes-arc-color": core.parseThemeColor({
|
|
99
|
+
color: minutesArcColor || minuteHandColor || "",
|
|
100
|
+
theme
|
|
101
|
+
}).value,
|
|
102
|
+
"--clock-hours-arc-color": core.parseThemeColor({
|
|
103
|
+
color: hoursArcColor || hourHandColor || "",
|
|
104
|
+
theme
|
|
90
105
|
}).value
|
|
91
106
|
}
|
|
92
107
|
};
|
|
@@ -143,7 +158,19 @@ const RealClock = (props) => {
|
|
|
143
158
|
hourNumbersDistance = 0.75,
|
|
144
159
|
// Default distance for hour numbers
|
|
145
160
|
primaryNumbersProps,
|
|
146
|
-
secondaryNumbersProps
|
|
161
|
+
secondaryNumbersProps,
|
|
162
|
+
withSecondsArc,
|
|
163
|
+
secondsArcFrom,
|
|
164
|
+
secondsArcDirection = "clockwise",
|
|
165
|
+
withMinutesArc,
|
|
166
|
+
minutesArcFrom,
|
|
167
|
+
minutesArcDirection = "clockwise",
|
|
168
|
+
withHoursArc,
|
|
169
|
+
hoursArcFrom,
|
|
170
|
+
hoursArcDirection = "clockwise",
|
|
171
|
+
secondsArcOpacity,
|
|
172
|
+
minutesArcOpacity,
|
|
173
|
+
hoursArcOpacity
|
|
147
174
|
} = props;
|
|
148
175
|
const timezoneTime = timezone2 && timezone2 !== "" ? dayjs(time).tz(timezone2) : dayjs(time);
|
|
149
176
|
const hours = timezoneTime.hour() % 12;
|
|
@@ -182,7 +209,114 @@ const RealClock = (props) => {
|
|
|
182
209
|
);
|
|
183
210
|
const centerSize = Math.round(size * 0.034);
|
|
184
211
|
const tickOffset = Math.round(size * 0.028);
|
|
185
|
-
|
|
212
|
+
const toClockAngle = (deg) => (deg % 360 + 360) % 360;
|
|
213
|
+
const secAngleFromDate = (d) => {
|
|
214
|
+
if (!d) {
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
const dt = timezone2 && timezone2 !== "" ? dayjs(d).tz(timezone2) : dayjs(d);
|
|
218
|
+
const s = dt.second();
|
|
219
|
+
const ms = dt.millisecond();
|
|
220
|
+
return toClockAngle((s + ms / 1e3) * 6);
|
|
221
|
+
};
|
|
222
|
+
const minAngleFromDate = (d) => {
|
|
223
|
+
if (!d) {
|
|
224
|
+
return 0;
|
|
225
|
+
}
|
|
226
|
+
const dt = timezone2 && timezone2 !== "" ? dayjs(d).tz(timezone2) : dayjs(d);
|
|
227
|
+
const m = dt.minute();
|
|
228
|
+
return toClockAngle(m * 6);
|
|
229
|
+
};
|
|
230
|
+
const hourAngleFromDate = (d) => {
|
|
231
|
+
if (!d) {
|
|
232
|
+
return 0;
|
|
233
|
+
}
|
|
234
|
+
const dt = timezone2 && timezone2 !== "" ? dayjs(d).tz(timezone2) : dayjs(d);
|
|
235
|
+
const h = dt.hour() % 12;
|
|
236
|
+
const m = dt.minute();
|
|
237
|
+
return toClockAngle(h * 30 + m * 0.5);
|
|
238
|
+
};
|
|
239
|
+
const describeSector = (cx, cy, r, startDeg, endDeg, direction) => {
|
|
240
|
+
const start = toClockAngle(startDeg);
|
|
241
|
+
const end = toClockAngle(endDeg);
|
|
242
|
+
let delta = 0;
|
|
243
|
+
if (direction === "clockwise") {
|
|
244
|
+
delta = end - start;
|
|
245
|
+
if (delta < 0) {
|
|
246
|
+
delta += 360;
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
249
|
+
delta = start - end;
|
|
250
|
+
if (delta < 0) {
|
|
251
|
+
delta += 360;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const largeArc = delta >= 180 ? 1 : 0;
|
|
255
|
+
const sweep = direction === "clockwise" ? 1 : 0;
|
|
256
|
+
const aStart = start * Math.PI / 180;
|
|
257
|
+
const aEnd = end * Math.PI / 180;
|
|
258
|
+
const x1 = cx + r * Math.sin(aStart);
|
|
259
|
+
const y1 = cy - r * Math.cos(aStart);
|
|
260
|
+
const x2 = cx + r * Math.sin(aEnd);
|
|
261
|
+
const y2 = cy - r * Math.cos(aEnd);
|
|
262
|
+
const fmt = (n) => Number.isFinite(n) ? n.toFixed(3) : "0";
|
|
263
|
+
return `M ${fmt(cx)} ${fmt(cy)} L ${fmt(x1)} ${fmt(y1)} A ${fmt(r)} ${fmt(r)} 0 ${largeArc} ${sweep} ${fmt(x2)} ${fmt(y2)} Z`;
|
|
264
|
+
};
|
|
265
|
+
const showSecArc = withSecondsArc === true && (secondsArcOpacity ?? 1) !== 0;
|
|
266
|
+
const showMinArc = withMinutesArc === true && (minutesArcOpacity ?? 1) !== 0;
|
|
267
|
+
const showHrArc = withHoursArc === true && (hoursArcOpacity ?? 1) !== 0;
|
|
268
|
+
return /* @__PURE__ */ React.createElement(core.Box, { ...getStyles("clockContainer") }, /* @__PURE__ */ React.createElement(core.Box, { ...getStyles("glassWrapper") }, /* @__PURE__ */ React.createElement(core.Box, { ...getStyles("clockFace") }, (showSecArc || showMinArc || showHrArc) && /* @__PURE__ */ React.createElement(
|
|
269
|
+
"svg",
|
|
270
|
+
{
|
|
271
|
+
...getStyles("arcsLayer", { style: { width: size, height: size } }),
|
|
272
|
+
viewBox: `0 0 ${size} ${size}`
|
|
273
|
+
},
|
|
274
|
+
showHrArc && /* @__PURE__ */ React.createElement(
|
|
275
|
+
"path",
|
|
276
|
+
{
|
|
277
|
+
d: describeSector(
|
|
278
|
+
clockRadius,
|
|
279
|
+
clockRadius,
|
|
280
|
+
calculatedHourHandLength,
|
|
281
|
+
hourAngleFromDate(parseTimeValue(hoursArcFrom) ?? null),
|
|
282
|
+
hourAngle,
|
|
283
|
+
hoursArcDirection
|
|
284
|
+
),
|
|
285
|
+
fill: "var(--clock-hours-arc-color-resolved)",
|
|
286
|
+
fillOpacity: Math.round((hoursArcOpacity ?? 1) * 100) / 100
|
|
287
|
+
}
|
|
288
|
+
),
|
|
289
|
+
showMinArc && /* @__PURE__ */ React.createElement(
|
|
290
|
+
"path",
|
|
291
|
+
{
|
|
292
|
+
d: describeSector(
|
|
293
|
+
clockRadius,
|
|
294
|
+
clockRadius,
|
|
295
|
+
calculatedMinuteHandLength,
|
|
296
|
+
minAngleFromDate(parseTimeValue(minutesArcFrom) ?? null),
|
|
297
|
+
minuteAngle,
|
|
298
|
+
minutesArcDirection
|
|
299
|
+
),
|
|
300
|
+
fill: "var(--clock-minutes-arc-color-resolved)",
|
|
301
|
+
fillOpacity: Math.round((minutesArcOpacity ?? 1) * 100) / 100
|
|
302
|
+
}
|
|
303
|
+
),
|
|
304
|
+
showSecArc && /* @__PURE__ */ React.createElement(
|
|
305
|
+
"path",
|
|
306
|
+
{
|
|
307
|
+
d: describeSector(
|
|
308
|
+
clockRadius,
|
|
309
|
+
clockRadius,
|
|
310
|
+
calculatedSecondHandLength,
|
|
311
|
+
secAngleFromDate(parseTimeValue(secondsArcFrom) ?? null),
|
|
312
|
+
secondAngle,
|
|
313
|
+
secondsArcDirection
|
|
314
|
+
),
|
|
315
|
+
fill: "var(--clock-seconds-arc-color-resolved)",
|
|
316
|
+
fillOpacity: Math.round((secondsArcOpacity ?? 1) * 100) / 100
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
), /* @__PURE__ */ React.createElement(core.Box, { ...getStyles("hourMarks") }, hourTicksOpacity !== 0 && Array.from({ length: 12 }, (_, i) => /* @__PURE__ */ React.createElement(
|
|
186
320
|
core.Box,
|
|
187
321
|
{
|
|
188
322
|
key: `hour-tick-${i}`,
|
|
@@ -387,6 +521,21 @@ const Clock = core.factory((_props, ref) => {
|
|
|
387
521
|
timezone: timezone2,
|
|
388
522
|
running,
|
|
389
523
|
value,
|
|
524
|
+
withSecondsArc,
|
|
525
|
+
secondsArcFrom,
|
|
526
|
+
secondsArcDirection,
|
|
527
|
+
secondsArcColor,
|
|
528
|
+
secondsArcOpacity,
|
|
529
|
+
withMinutesArc,
|
|
530
|
+
minutesArcFrom,
|
|
531
|
+
minutesArcDirection,
|
|
532
|
+
minutesArcColor,
|
|
533
|
+
minutesArcOpacity,
|
|
534
|
+
withHoursArc,
|
|
535
|
+
hoursArcFrom,
|
|
536
|
+
hoursArcDirection,
|
|
537
|
+
hoursArcColor,
|
|
538
|
+
hoursArcOpacity,
|
|
390
539
|
// Styles API props
|
|
391
540
|
classNames,
|
|
392
541
|
style,
|