@axzydev/axzy_ui_system 1.8.14 → 1.8.16

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/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "packageManager": "pnpm@10.34.0",
5
5
  "private": false,
6
6
  "license": "MIT",
7
- "version": "1.8.14",
7
+ "version": "1.8.16",
8
8
  "type": "module",
9
9
  "sideEffects": [
10
10
  "*.css"
@@ -1,3 +1,4 @@
1
+ import type React from "react";
1
2
  import { ColorsTypes } from "@/types/colors.types";
2
3
 
3
4
  export interface CalendarEvent {
@@ -13,6 +14,23 @@ export interface CalendarEvent {
13
14
  color?: string;
14
15
  /** Arbitrary extra data passed through to event callbacks. */
15
16
  data?: any;
17
+ /** Column the event belongs to when `resources` are shown (day mode). */
18
+ resourceId?: string;
19
+ /** Second line under the title. Defaults to the "HH:mm - HH:mm" range. */
20
+ subtitle?: string;
21
+ /** Extra classes for the event block (e.g. a status tone). Replaces the default color styling when set without `color`. */
22
+ className?: string;
23
+ }
24
+
25
+ export interface CalendarResource {
26
+ /** Unique identifier, matched against `CalendarEvent.resourceId`. */
27
+ id: string;
28
+ /** Column title (e.g. a person's name). */
29
+ title: string;
30
+ /** Small line under the title. */
31
+ subtitle?: string;
32
+ /** Leading element in the column header (avatar, initials, icon). */
33
+ avatar?: React.ReactNode;
16
34
  }
17
35
 
18
36
  export interface ITCalendarProps {
@@ -22,12 +40,24 @@ export interface ITCalendarProps {
22
40
  mode?: 'week' | 'day' | 'month';
23
41
  /** Callback fired when an event is clicked. */
24
42
  onEventClick?: (event: CalendarEvent) => void;
25
- /** Callback fired when an empty time slot is clicked. */
26
- onSlotClick?: (date: Date) => void;
43
+ /** Callback fired when an empty time slot is clicked. In resource columns it also receives the resource id. */
44
+ onSlotClick?: (date: Date, resourceId?: string) => void;
27
45
  /** Callback fired when the mouse enters a time slot. */
28
46
  onSlotHover?: (date: Date) => void;
29
47
  /** Callback fired when a time range is selected via drag. */
30
48
  onSelectRange?: (start: Date, end: Date) => void;
49
+ /** Day mode only: one column per resource (e.g. per staff member) instead of one per day. */
50
+ resources?: CalendarResource[];
51
+ /** First hour shown in week/day views. @default 6 */
52
+ startHour?: number;
53
+ /** Last hour shown (exclusive) in week/day views. @default 22 */
54
+ endHour?: number;
55
+ /** Height in px of one hour row in week/day views. @default 80 */
56
+ hourHeight?: number;
57
+ /** Hides the top navigation bar (month/year, arrows, "today"), for when the page drives the date through `value`. @default false */
58
+ hideToolbar?: boolean;
59
+ /** Shows the current time as a badge on the "now" line. @default false */
60
+ showNowTime?: boolean;
31
61
 
32
62
  /** Currently selected date (date picker mode). */
33
63
  value?: Date;
@@ -33,12 +33,8 @@ function cn(...inputs: ClassValue[]) {
33
33
  // Constants
34
34
  // ----------------------------------------------------------------------
35
35
 
36
- const START_HOUR = 6; // 6 AM
37
- const END_HOUR = 22; // 10 PM
38
- const HOURS_COUNT = END_HOUR - START_HOUR;
39
-
40
- // Generate time slots
41
- const TIME_SLOTS = Array.from({ length: HOURS_COUNT + 1 }, (_, i) => START_HOUR + i);
36
+ const DEFAULT_START_HOUR = 6; // 6 AM
37
+ const DEFAULT_END_HOUR = 22; // 10 PM
42
38
 
43
39
  // ----------------------------------------------------------------------
44
40
  // Component
@@ -73,7 +69,17 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
73
69
  maxDate,
74
70
  className,
75
71
  variant = 'primary',
72
+ resources,
73
+ startHour = DEFAULT_START_HOUR,
74
+ endHour = DEFAULT_END_HOUR,
75
+ hourHeight = 80,
76
+ hideToolbar = false,
77
+ showNowTime = false,
76
78
  }) => {
79
+ const START_HOUR = startHour;
80
+ const END_HOUR = endHour;
81
+ const TIME_SLOTS = Array.from({ length: END_HOUR - START_HOUR + 1 }, (_, i) => START_HOUR + i);
82
+ const toPx = (minutes: number) => (minutes / 60) * hourHeight;
77
83
  const { t, dateLocale } = useITTranslation();
78
84
  // Determine mode: if onChange provided, assume picker (month) unless specialized
79
85
  const mode = modeProp || (onChange ? 'month' : 'week');
@@ -181,8 +187,8 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
181
187
  const duration = differenceInMinutes(end, start);
182
188
 
183
189
  return {
184
- top: `${((startMinutes - dayStartMinutes) / 60) * 80}px`,
185
- height: `${(duration / 60) * 80}px`,
190
+ top: `${toPx(startMinutes - dayStartMinutes)}px`,
191
+ height: `${toPx(duration)}px`,
186
192
  };
187
193
  };
188
194
 
@@ -295,7 +301,7 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
295
301
  >
296
302
 
297
303
  {/* Header */}
298
- <div
304
+ {!hideToolbar && <div
299
305
  className="flex items-center justify-between px-2 py-2 border-b"
300
306
  style={{
301
307
  backgroundColor: 'var(--it-calendar-bg, #ffffff)',
@@ -378,7 +384,7 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
378
384
  <FaChevronRight size={14} />
379
385
  </button>
380
386
  </div>
381
- </div>
387
+ </div>}
382
388
 
383
389
  {/* Content */}
384
390
  <div
@@ -512,19 +518,35 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
512
518
  </div>
513
519
  ) : (
514
520
  /* Week/Day View (Scheduler) */
515
- <div className={cn("flex h-full", mode === 'week' ? "min-w-[800px]" : "w-full")}>
521
+ (() => {
522
+ const byResource = mode === 'day' && !!resources?.length;
523
+ const headerHeight = byResource ? 64 : 40;
524
+ const columns = byResource
525
+ ? resources!.map((r) => ({ key: r.id, day: viewDays[0], resource: r }))
526
+ : viewDays.map((d) => ({ key: d.toISOString(), day: d, resource: undefined as undefined }));
527
+ const now = new Date();
528
+ const nowMinutes = now.getHours() * 60 + now.getMinutes();
529
+ const nowVisible = nowMinutes >= START_HOUR * 60 && nowMinutes <= END_HOUR * 60;
530
+ const slotDate = (day: Date, hour: number, minute: number) => {
531
+ const d = new Date(day);
532
+ d.setHours(hour, minute, 0, 0);
533
+ return d;
534
+ };
535
+ return (
536
+ <div className={cn("flex", mode === 'week' ? "min-w-[800px]" : byResource ? "w-full" : "w-full")} style={byResource ? { minWidth: `${64 + columns.length * 160}px` } : undefined}>
516
537
  {/* Time Sidebar */}
517
538
  <div
518
- className="flex-none w-16 pt-10 select-none"
539
+ className="flex-none w-16 select-none"
519
540
  style={{
541
+ paddingTop: `${headerHeight}px`,
520
542
  backgroundColor: 'var(--it-calendar-header-hover, #f1f5f9)',
521
543
  borderRight: '1px solid var(--it-calendar-border, #e2e8f0)',
522
544
  }}
523
545
  >
524
546
  {TIME_SLOTS.map((hour) => (
525
547
  hour < END_HOUR && (
526
- <div key={hour} className="h-20 relative text-right pr-2">
527
- <ITText as="span" className="text-xs text-slate-400 dark:text-slate-500 -mt-2 inline-block transform -translate-y-1/2">
548
+ <div key={hour} className="relative text-right pr-2" style={{ height: `${hourHeight}px` }}>
549
+ <ITText as="span" className="text-xs text-slate-400 dark:text-slate-500 inline-block pt-1">
528
550
  {format(new Date().setHours(hour, 0), 'HH:mm')}
529
551
  </ITText>
530
552
  </div>
@@ -532,19 +554,42 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
532
554
  ))}
533
555
  </div>
534
556
 
535
- {/* Days Columns */}
557
+ {/* Columns: one per day, or one per resource */}
536
558
  <div className="flex flex-1">
537
- {viewDays.map((day) => (
559
+ {columns.map(({ key, day, resource }, colIndex) => (
538
560
  <div
539
- key={day.toISOString()}
540
- className="flex-1 min-w-[120px] relative"
541
- style={{ borderRight: '1px solid var(--it-calendar-border, #e2e8f0)' }}
561
+ key={key}
562
+ className={cn("flex-1 relative", byResource ? "min-w-[160px]" : "min-w-[120px]")}
563
+ style={{ borderRight: colIndex < columns.length - 1 || !byResource ? '1px solid var(--it-calendar-border, #e2e8f0)' : undefined }}
542
564
  >
543
565
 
544
- {/* Day Header */}
566
+ {/* Column Header */}
567
+ {resource ? (
568
+ <div
569
+ className="flex items-center gap-3 px-3 sticky top-0 z-10"
570
+ style={{
571
+ height: `${headerHeight}px`,
572
+ backgroundColor: 'var(--it-calendar-bg, #ffffff)',
573
+ borderBottom: '1px solid var(--it-calendar-border, #e2e8f0)',
574
+ }}
575
+ >
576
+ {resource.avatar}
577
+ <div className="min-w-0">
578
+ <ITText as="div" className="text-sm font-semibold truncate" style={{ color: 'var(--it-calendar-header-text, #1e293b)' }}>
579
+ {resource.title}
580
+ </ITText>
581
+ {resource.subtitle && (
582
+ <ITText as="div" className="text-xs truncate" style={{ color: 'var(--it-calendar-days-text, #334155)', opacity: 0.7 }}>
583
+ {resource.subtitle}
584
+ </ITText>
585
+ )}
586
+ </div>
587
+ </div>
588
+ ) : (
545
589
  <div
546
- className="h-10 flex flex-col items-center justify-center sticky top-0 z-10"
590
+ className="flex flex-col items-center justify-center sticky top-0 z-10"
547
591
  style={{
592
+ height: `${headerHeight}px`,
548
593
  backgroundColor: isToday(day) ? 'var(--it-calendar-today-bg, #eff6ff)' : 'var(--it-calendar-bg, #ffffff)',
549
594
  borderBottom: '1px solid var(--it-calendar-border, #e2e8f0)',
550
595
  }}
@@ -570,6 +615,7 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
570
615
  {format(day, 'd')}
571
616
  </ITText>
572
617
  </div>
618
+ )}
573
619
 
574
620
  {/* Slots Grid */}
575
621
  <div className="relative">
@@ -577,51 +623,30 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
577
623
  hour < END_HOUR && (
578
624
  <div
579
625
  key={hour}
580
- className="h-20 relative group"
581
- style={{ borderBottom: '1px dashed var(--it-calendar-border, #e2e8f0)' }}
626
+ className="relative group"
627
+ style={{ height: `${hourHeight}px`, borderBottom: '1px dashed var(--it-calendar-border, #e2e8f0)' }}
582
628
  >
583
- {/* Slot 00 */}
629
+ {[0, 30].map((minute) => (
584
630
  <div
585
- className="absolute inset-x-0 top-0 h-10 border-b border-transparent hover:border-[var(--it-calendar-today-bg)] hover:bg-[var(--it-calendar-today-bg)] transition-colors cursor-pointer z-0"
586
- onMouseDown={(e) => {
587
- const d = new Date(day); d.setHours(hour, 0, 0, 0);
588
- handleMouseDown(d, e);
589
- }}
590
- onMouseEnter={() => {
591
- const d = new Date(day); d.setHours(hour, 0, 0, 0);
592
- handleMouseEnter(d);
593
- }}
631
+ key={minute}
632
+ className={cn(
633
+ "absolute inset-x-0 border-b border-transparent hover:border-[var(--it-calendar-today-bg)] hover:bg-[var(--it-calendar-today-bg)] transition-colors cursor-pointer z-0",
634
+ minute === 0 ? "top-0" : "bottom-0"
635
+ )}
636
+ style={{ height: `${hourHeight / 2}px` }}
637
+ onMouseDown={(e) => handleMouseDown(slotDate(day, hour, minute), e)}
638
+ onMouseEnter={() => handleMouseEnter(slotDate(day, hour, minute))}
594
639
  onClick={() => {
595
- if (!isDraggingRef.current) {
596
- const d = new Date(day); d.setHours(hour, 0, 0, 0);
597
- if (onSlotClick) onSlotClick(d);
598
- }
599
- }}
600
- />
601
- {/* Slot 30 */}
602
- <div
603
- className="absolute inset-x-0 bottom-0 h-10 hover:border-[var(--it-calendar-today-bg)] hover:bg-[var(--it-calendar-today-bg)] transition-colors cursor-pointer z-0"
604
- onMouseDown={(e) => {
605
- const d = new Date(day); d.setHours(hour, 30, 0, 0);
606
- handleMouseDown(d, e);
607
- }}
608
- onMouseEnter={() => {
609
- const d = new Date(day); d.setHours(hour, 30, 0, 0);
610
- handleMouseEnter(d);
611
- }}
612
- onClick={() => {
613
- if (!isDraggingRef.current) {
614
- const d = new Date(day); d.setHours(hour, 30, 0, 0);
615
- if (onSlotClick) onSlotClick(d);
616
- }
640
+ if (!isDraggingRef.current && onSlotClick) onSlotClick(slotDate(day, hour, minute), resource?.id);
617
641
  }}
618
642
  />
643
+ ))}
619
644
  </div>
620
645
  )
621
646
  ))}
622
647
 
623
648
  {/* Selection Overlay */}
624
- {dragStart && dragCurrent && isSameDay(dragStart, day) && (
649
+ {!byResource && dragStart && dragCurrent && isSameDay(dragStart, day) && (
625
650
  (() => {
626
651
  let start = dragStart;
627
652
  let end = dragCurrent;
@@ -629,10 +654,8 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
629
654
  const finalEnd = addMinutes(end, 30); // Visual end is end of slot
630
655
 
631
656
  const startMinutes = start.getHours() * 60 + start.getMinutes();
632
- const dayStartMinutes = START_HOUR * 60;
633
- const duration = differenceInMinutes(finalEnd, start);
634
- const top = ((startMinutes - dayStartMinutes) / 60) * 80;
635
- const height = (duration / 60) * 80;
657
+ const top = toPx(startMinutes - START_HOUR * 60);
658
+ const height = toPx(differenceInMinutes(finalEnd, start));
636
659
 
637
660
  return (
638
661
  <div
@@ -646,14 +669,18 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
646
669
  {/* Events */}
647
670
  {weekEvents
648
671
  .filter((event) => isSameDay(typeof event.start === 'string' ? parseISO(event.start) : event.start, day))
672
+ .filter((event) => !resource || event.resourceId === resource.id)
649
673
  .map((event) => {
650
674
  const style = getEventStyle(event);
675
+ const custom = !!event.className && !event.color;
651
676
  return (
652
677
  <div
653
678
  key={event.id}
654
679
  className={cn(
655
- "absolute left-1 right-1 rounded px-2 py-1 text-xs cursor-pointer hover:brightness-95 transition-all shadow-sm overflow-hidden z-20 border-l-4",
656
- !event.color && "bg-[var(--it-calendar-today-bg)] text-[var(--it-calendar-today-text)] border-[var(--it-calendar-selected-bg)]"
680
+ "absolute left-1 right-1 rounded px-2 py-1 text-xs cursor-pointer hover:brightness-110 transition-all shadow-sm overflow-hidden z-20",
681
+ !custom && "border-l-4",
682
+ !event.color && !custom && "bg-[var(--it-calendar-today-bg)] text-[var(--it-calendar-today-text)] border-[var(--it-calendar-selected-bg)]",
683
+ event.className
657
684
  )}
658
685
  style={{
659
686
  top: style.top,
@@ -669,30 +696,34 @@ export const ITCalendar: React.FC<ITCalendarProps> = ({
669
696
  >
670
697
  <ITText as="div" className="font-semibold truncate">{event.title}</ITText>
671
698
  <ITText as="div" className="opacity-80 truncate">
672
- {format(typeof event.start === 'string' ? parseISO(event.start) : event.start, 'HH:mm')} -
673
- {format(typeof event.end === 'string' ? parseISO(event.end) : event.end, 'HH:mm')}
699
+ {event.subtitle ?? `${format(typeof event.start === 'string' ? parseISO(event.start) : event.start, 'HH:mm')} - ${format(typeof event.end === 'string' ? parseISO(event.end) : event.end, 'HH:mm')}`}
674
700
  </ITText>
675
701
  </div>
676
702
  );
677
703
  })}
704
+
705
+ {/* Current Time Line */}
706
+ {isToday(day) && nowVisible && (
707
+ <div
708
+ className="absolute left-0 right-0 border-t-2 border-danger-500 z-30 pointer-events-none"
709
+ style={{ top: `${toPx(nowMinutes - START_HOUR * 60)}px` }}
710
+ >
711
+ {(!byResource || colIndex === 0) && <div className="absolute -left-1.5 -top-1.5 w-3 h-3 bg-danger-500 rounded-full" />}
712
+ {showNowTime && (!byResource || colIndex === columns.length - 1) && (
713
+ <ITText as="span" className="absolute right-1 -top-2.5 rounded-full bg-danger-500 px-1.5 text-[10px] font-bold text-white leading-4">
714
+ {format(now, 'HH:mm')}
715
+ </ITText>
716
+ )}
717
+ </div>
718
+ )}
678
719
  </div>
679
-
680
- {/* Current Time Line */}
681
- {isToday(day) && (
682
- <div
683
- className="absolute left-0 right-0 border-t-2 border-danger-500 z-30 pointer-events-none"
684
- style={{
685
- top: `${((new Date().getHours() * 60 + new Date().getMinutes() - (START_HOUR * 60)) / 60) * 80}px`
686
- }}
687
- >
688
- <div className="absolute -left-1.5 -top-1.5 w-3 h-3 bg-danger-500 rounded-full" />
689
- </div>
690
- )}
691
720
 
692
721
  </div>
693
722
  ))}
694
723
  </div>
695
724
  </div>
725
+ );
726
+ })()
696
727
  )}
697
728
  </div>
698
729
  </div>
@@ -486,7 +486,7 @@ export default function ITSidebar({
486
486
  />
487
487
  )}
488
488
 
489
- <div className="flex items-center gap-2.5 relative z-10 w-full">
489
+ <div className={`flex items-center gap-2.5 relative z-10 w-full ${isSidebarCollapsed ? "justify-center" : ""}`}>
490
490
  {item.icon && (
491
491
  <div
492
492
  className={`transition-all duration-300 flex-shrink-0 flex items-center justify-center`}
package/src/index.ts CHANGED
@@ -186,7 +186,7 @@ import type { ITAvatarProps } from "./components/atoms/avatar/avatar.props";
186
186
  import type { ITBadgetProps } from "./components/atoms/badget/badget.props";
187
187
  import type { ITBreadcrumbsProps, ITBreadcrumbItem } from "./components/molecules/breadcrumbs/breadcrumbs.props";
188
188
  import type { ITButtonProps } from "./components/atoms/button/button.props";
189
- import type { ITCalendarProps } from "./components/molecules/calendar/calendar.props";
189
+ import type { ITCalendarProps, CalendarEvent, CalendarResource } from "./components/molecules/calendar/calendar.props";
190
190
  import type { ITCardProps, ITCardTone } from "./components/molecules/card/card.props";
191
191
  import type { ITCheckboxProps } from "./components/atoms/checkbox/checkbox.props";
192
192
  import type { ITChipProps } from "./components/atoms/chip/chip.props";
@@ -306,6 +306,8 @@ export {
306
306
  ITAlertProps, ITAvatarProps, ITBadgetProps,
307
307
  ITBreadcrumbItem, ITBreadcrumbsProps, ITButtonProps,
308
308
  ITCalendarProps,
309
+ CalendarEvent,
310
+ CalendarResource,
309
311
  ITCardProps, ITCardTone, ITCheckboxProps, ITChipProps, ITChipInputProps, ITConfirmDialogProps,
310
312
  ITDropdownMenuItem, ITDropdownMenuProps, ITFieldProps, ITMaskedInputProps, ITMultiSelectOption, ITMultiSelectProps,
311
313
  ITDataTableFetchParams, ITDataTableProps, ITDataTableResponse, ITDatePickerProps,