@xjur-ui/react 2.1.1 → 2.2.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/CHANGELOG.md +12 -0
- package/dist/components/steps/index.js +1 -1
- package/package.json +7 -4
- package/.turbo/turbo-build.log +0 -419
- package/eslint.config.js +0 -10
- package/postcss.config.js +0 -5
- package/prettier.config.js +0 -7
- package/src/components/avatar-group.tsx +0 -76
- package/src/components/avatar.tsx +0 -54
- package/src/components/badge.tsx +0 -40
- package/src/components/breadcrumb.tsx +0 -119
- package/src/components/chip.tsx +0 -117
- package/src/components/collapsible.tsx +0 -35
- package/src/components/controls/button.tsx +0 -107
- package/src/components/controls/calendar.tsx +0 -124
- package/src/components/controls/checkbox.tsx +0 -57
- package/src/components/controls/context/field.context.ts +0 -27
- package/src/components/controls/date-picker.tsx +0 -199
- package/src/components/controls/floating-label.tsx +0 -60
- package/src/components/controls/input.tsx +0 -237
- package/src/components/controls/otp-input.tsx +0 -45
- package/src/components/controls/radio.tsx +0 -74
- package/src/components/controls/rich-editor.tsx +0 -372
- package/src/components/controls/search-input.tsx +0 -154
- package/src/components/controls/search-selector.tsx +0 -98
- package/src/components/controls/select.tsx +0 -274
- package/src/components/controls/switch.tsx +0 -31
- package/src/components/custom/pessoa/index.ts +0 -9
- package/src/components/custom/pessoa/pessoa-add-button.tsx +0 -35
- package/src/components/custom/pessoa/pessoa-body.tsx +0 -22
- package/src/components/custom/pessoa/pessoa-close-button.tsx +0 -13
- package/src/components/custom/pessoa/pessoa-content.tsx +0 -25
- package/src/components/custom/pessoa/pessoa-footer.tsx +0 -15
- package/src/components/custom/pessoa/pessoa-header.tsx +0 -35
- package/src/components/custom/pessoa/pessoa-trigger.tsx +0 -25
- package/src/components/custom/pessoa/pessoa.context.tsx +0 -73
- package/src/components/custom/pessoa/pessoa.tsx +0 -35
- package/src/components/dialog.tsx +0 -242
- package/src/components/divider.tsx +0 -24
- package/src/components/drag-and-drop/drag-handle.tsx +0 -46
- package/src/components/drag-and-drop/drag-list-item.tsx +0 -91
- package/src/components/drag-and-drop/drag-list.tsx +0 -47
- package/src/components/drag-and-drop/drag-root.tsx +0 -30
- package/src/components/drag-and-drop/index.ts +0 -39
- package/src/components/drag-and-drop/types/drag-item.ts +0 -7
- package/src/components/dropdown-menu.tsx +0 -101
- package/src/components/full-calendar/calendar-add-event.tsx +0 -15
- package/src/components/full-calendar/calendar-body.tsx +0 -12
- package/src/components/full-calendar/calendar-cell.tsx +0 -120
- package/src/components/full-calendar/calendar-day-view.tsx +0 -76
- package/src/components/full-calendar/calendar-event.tsx +0 -178
- package/src/components/full-calendar/calendar-header.tsx +0 -14
- package/src/components/full-calendar/calendar-month-view.tsx +0 -69
- package/src/components/full-calendar/calendar-more-events-dropdown.tsx +0 -39
- package/src/components/full-calendar/calendar-navigator.tsx +0 -86
- package/src/components/full-calendar/calendar-root.tsx +0 -165
- package/src/components/full-calendar/calendar-today-button.tsx +0 -21
- package/src/components/full-calendar/calendar-toggle-view.tsx +0 -61
- package/src/components/full-calendar/calendar-view-renderer.tsx +0 -19
- package/src/components/full-calendar/calendar-week-day.tsx +0 -49
- package/src/components/full-calendar/calendar-week-view.tsx +0 -88
- package/src/components/full-calendar/helpers/calendar.ts +0 -158
- package/src/components/full-calendar/index.ts +0 -16
- package/src/components/full-calendar/types/calendar-cell.ts +0 -4
- package/src/components/full-calendar/types/calendar-event.ts +0 -7
- package/src/components/full-calendar/types/calendar-view.ts +0 -1
- package/src/components/full-calendar/types/calendar-week-hour.ts +0 -4
- package/src/components/horizontal-scroll.tsx +0 -159
- package/src/components/icon.tsx +0 -29
- package/src/components/list.tsx +0 -111
- package/src/components/logo.tsx +0 -44
- package/src/components/selection-bar.tsx +0 -273
- package/src/components/sheet.tsx +0 -150
- package/src/components/skeleton.tsx +0 -12
- package/src/components/status.tsx +0 -43
- package/src/components/steps/index.ts +0 -6
- package/src/components/steps/step.tsx +0 -23
- package/src/components/steps/steps-action.tsx +0 -65
- package/src/components/steps/steps-content.tsx +0 -12
- package/src/components/steps/steps-context.tsx +0 -121
- package/src/components/steps/steps-navigation.tsx +0 -80
- package/src/components/steps/steps-root.tsx +0 -9
- package/src/components/table/index.ts +0 -8
- package/src/components/table/table-body.tsx +0 -17
- package/src/components/table/table-cell.tsx +0 -14
- package/src/components/table/table-footer.tsx +0 -17
- package/src/components/table/table-head.tsx +0 -31
- package/src/components/table/table-header.tsx +0 -17
- package/src/components/table/table-row.tsx +0 -21
- package/src/components/table/table-sort.tsx +0 -34
- package/src/components/table/table.tsx +0 -16
- package/src/components/tabs.tsx +0 -72
- package/src/components/tag.tsx +0 -99
- package/src/components/tooltip.tsx +0 -63
- package/src/components/typography.tsx +0 -85
- package/src/components/upload.tsx +0 -647
- package/src/hooks/index.ts +0 -1
- package/src/hooks/use-os.ts +0 -32
- package/src/index.css +0 -5
- package/src/resources/icons.ts +0 -154
- package/src/resources/input-mask.ts +0 -91
- package/src/resources/logo/horizontal.tsx +0 -70
- package/src/resources/logo/icon.tsx +0 -54
- package/src/resources/logo/index.tsx +0 -33
- package/src/resources/logo/vertical.tsx +0 -70
- package/src/types.d.ts +0 -4
- package/tsconfig.json +0 -4
- package/tsup.config.ts +0 -30
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
createContext,
|
|
3
|
-
use,
|
|
4
|
-
useCallback,
|
|
5
|
-
useMemo,
|
|
6
|
-
useState
|
|
7
|
-
} from 'react'
|
|
8
|
-
import {
|
|
9
|
-
DndContext,
|
|
10
|
-
closestCenter,
|
|
11
|
-
useSensor,
|
|
12
|
-
useSensors,
|
|
13
|
-
PointerSensor,
|
|
14
|
-
KeyboardSensor,
|
|
15
|
-
type DragEndEvent,
|
|
16
|
-
type DragStartEvent,
|
|
17
|
-
MouseSensor
|
|
18
|
-
} from '@dnd-kit/core'
|
|
19
|
-
import { sortableKeyboardCoordinates } from '@dnd-kit/sortable'
|
|
20
|
-
import type { ICalendarEvent } from './types/calendar-event'
|
|
21
|
-
import type { CalendarView } from './types/calendar-view'
|
|
22
|
-
|
|
23
|
-
interface CalendarContextType {
|
|
24
|
-
events: ICalendarEvent[]
|
|
25
|
-
selectedDate: Date
|
|
26
|
-
calendarView?: CalendarView
|
|
27
|
-
activeEventId: string | null
|
|
28
|
-
disableEventCreationInPast?: boolean
|
|
29
|
-
renderEvent: (event: ICalendarEvent) => React.ReactNode
|
|
30
|
-
handleChangeView: (view: CalendarView) => void
|
|
31
|
-
setSelectedDate: React.Dispatch<React.SetStateAction<Date>>
|
|
32
|
-
onEventMove?: (eventId: string, newDate: Date) => void
|
|
33
|
-
onAddEvent?: (date: Date) => void
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const CalendarContext = createContext<CalendarContextType>({
|
|
37
|
-
events: [],
|
|
38
|
-
calendarView: 'month',
|
|
39
|
-
selectedDate: new Date(),
|
|
40
|
-
activeEventId: null,
|
|
41
|
-
disableEventCreationInPast: true,
|
|
42
|
-
renderEvent: () => null,
|
|
43
|
-
setSelectedDate: () => {},
|
|
44
|
-
handleChangeView: () => {},
|
|
45
|
-
onEventMove: () => {},
|
|
46
|
-
onAddEvent: () => {}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
export function CalendarRoot({
|
|
50
|
-
children,
|
|
51
|
-
events,
|
|
52
|
-
calendarView: calendarViewProp = 'month',
|
|
53
|
-
selectedDate: selectedDateProp = new Date(),
|
|
54
|
-
disableEventCreationInPast = true,
|
|
55
|
-
renderEvent,
|
|
56
|
-
onEventMove,
|
|
57
|
-
onAddEvent
|
|
58
|
-
}: {
|
|
59
|
-
children: React.ReactNode
|
|
60
|
-
events: ICalendarEvent[]
|
|
61
|
-
selectedDate?: Date
|
|
62
|
-
calendarView?: CalendarView
|
|
63
|
-
disableEventCreationInPast?: boolean
|
|
64
|
-
renderEvent: (event: ICalendarEvent) => React.ReactNode
|
|
65
|
-
onEventMove?: (eventId: string, newDate: Date) => void
|
|
66
|
-
onAddEvent?: (date: Date) => void
|
|
67
|
-
}) {
|
|
68
|
-
const [selectedDate, setSelectedDate] = useState(selectedDateProp)
|
|
69
|
-
const [calendarView, setCalendarView] = useState(calendarViewProp)
|
|
70
|
-
const [activeEventId, setActiveEventId] = useState<string | null>(null)
|
|
71
|
-
|
|
72
|
-
const handleChangeView = useCallback((view: CalendarView) => {
|
|
73
|
-
setSelectedDate(new Date())
|
|
74
|
-
setCalendarView(view)
|
|
75
|
-
}, [])
|
|
76
|
-
|
|
77
|
-
const sensors = useSensors(
|
|
78
|
-
useSensor(PointerSensor, {
|
|
79
|
-
activationConstraint: {
|
|
80
|
-
distance: 8
|
|
81
|
-
}
|
|
82
|
-
}),
|
|
83
|
-
useSensor(KeyboardSensor, {
|
|
84
|
-
coordinateGetter: sortableKeyboardCoordinates
|
|
85
|
-
}),
|
|
86
|
-
useSensor(MouseSensor, {
|
|
87
|
-
activationConstraint: {
|
|
88
|
-
distance: 5,
|
|
89
|
-
delay: 250
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
const handleDragStart = useCallback((event: DragStartEvent) => {
|
|
95
|
-
const eventId = event.active.id.toString()
|
|
96
|
-
setActiveEventId(eventId)
|
|
97
|
-
}, [])
|
|
98
|
-
|
|
99
|
-
const handleDragEnd = useCallback(
|
|
100
|
-
(event: DragEndEvent) => {
|
|
101
|
-
const { active, over } = event
|
|
102
|
-
setActiveEventId(null)
|
|
103
|
-
|
|
104
|
-
if (!active || !over || !onEventMove) return
|
|
105
|
-
|
|
106
|
-
const eventId = active.id.toString()
|
|
107
|
-
const cellDate = over.data.current?.date as Date
|
|
108
|
-
|
|
109
|
-
console.log(cellDate)
|
|
110
|
-
|
|
111
|
-
if (cellDate) {
|
|
112
|
-
onEventMove(eventId, cellDate)
|
|
113
|
-
}
|
|
114
|
-
},
|
|
115
|
-
[onEventMove]
|
|
116
|
-
)
|
|
117
|
-
|
|
118
|
-
const providerValue = useMemo(
|
|
119
|
-
() => ({
|
|
120
|
-
events,
|
|
121
|
-
renderEvent,
|
|
122
|
-
activeEventId,
|
|
123
|
-
disableEventCreationInPast,
|
|
124
|
-
selectedDate,
|
|
125
|
-
setSelectedDate,
|
|
126
|
-
|
|
127
|
-
calendarView,
|
|
128
|
-
handleChangeView,
|
|
129
|
-
onEventMove,
|
|
130
|
-
onAddEvent
|
|
131
|
-
}),
|
|
132
|
-
[
|
|
133
|
-
events,
|
|
134
|
-
renderEvent,
|
|
135
|
-
activeEventId,
|
|
136
|
-
disableEventCreationInPast,
|
|
137
|
-
selectedDate,
|
|
138
|
-
calendarView,
|
|
139
|
-
handleChangeView,
|
|
140
|
-
onEventMove,
|
|
141
|
-
onAddEvent
|
|
142
|
-
]
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
return (
|
|
146
|
-
<CalendarContext.Provider value={providerValue}>
|
|
147
|
-
<DndContext
|
|
148
|
-
collisionDetection={closestCenter}
|
|
149
|
-
sensors={sensors}
|
|
150
|
-
onDragEnd={handleDragEnd}
|
|
151
|
-
onDragStart={handleDragStart}
|
|
152
|
-
>
|
|
153
|
-
{children}
|
|
154
|
-
</DndContext>
|
|
155
|
-
</CalendarContext.Provider>
|
|
156
|
-
)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function useFullCalendar() {
|
|
160
|
-
const context = use(CalendarContext)
|
|
161
|
-
if (!context) {
|
|
162
|
-
throw new Error('useFullCalendar must be used within a CalendarRoot')
|
|
163
|
-
}
|
|
164
|
-
return context
|
|
165
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useCallback } from 'react'
|
|
2
|
-
import { Button, type ButtonProps } from '../controls/button'
|
|
3
|
-
import { useFullCalendar } from './calendar-root'
|
|
4
|
-
|
|
5
|
-
export function CalendarTodayButton({
|
|
6
|
-
children = 'Hoje',
|
|
7
|
-
variant = 'tertiary',
|
|
8
|
-
...props
|
|
9
|
-
}: ButtonProps) {
|
|
10
|
-
const { setSelectedDate } = useFullCalendar()
|
|
11
|
-
|
|
12
|
-
const handleToday = useCallback(() => {
|
|
13
|
-
setSelectedDate(new Date())
|
|
14
|
-
}, [setSelectedDate])
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<Button variant={variant} onClick={handleToday} {...props}>
|
|
18
|
-
{children}
|
|
19
|
-
</Button>
|
|
20
|
-
)
|
|
21
|
-
}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react'
|
|
2
|
-
import {
|
|
3
|
-
SelectContent,
|
|
4
|
-
SelectOption,
|
|
5
|
-
SelectRoot,
|
|
6
|
-
SelectTrigger,
|
|
7
|
-
SelectValue,
|
|
8
|
-
SelectOptions,
|
|
9
|
-
SelectOptionText,
|
|
10
|
-
SelectIcon
|
|
11
|
-
} from '../controls/select'
|
|
12
|
-
import type { CalendarView } from './types/calendar-view'
|
|
13
|
-
import { useFullCalendar } from './calendar-root'
|
|
14
|
-
|
|
15
|
-
const views: Array<{ name: string; value: CalendarView }> = [
|
|
16
|
-
{ name: 'Mês', value: 'month' },
|
|
17
|
-
{ name: 'Semana', value: 'week' },
|
|
18
|
-
{ name: 'Dia', value: 'day' }
|
|
19
|
-
]
|
|
20
|
-
|
|
21
|
-
export function CalendarToggleView() {
|
|
22
|
-
const { calendarView, handleChangeView } = useFullCalendar()
|
|
23
|
-
|
|
24
|
-
const displayValue = useMemo(
|
|
25
|
-
() => views.find(view => view.value === calendarView)?.name,
|
|
26
|
-
[calendarView]
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<div className="w-[94px]">
|
|
31
|
-
<SelectRoot>
|
|
32
|
-
<SelectTrigger>
|
|
33
|
-
<SelectValue
|
|
34
|
-
displayValue={displayValue}
|
|
35
|
-
name="calendar-toggle-view"
|
|
36
|
-
value={calendarView}
|
|
37
|
-
/>
|
|
38
|
-
<SelectIcon
|
|
39
|
-
className="text-icon-neutral-3"
|
|
40
|
-
name="keyboard_arrow_down"
|
|
41
|
-
/>
|
|
42
|
-
</SelectTrigger>
|
|
43
|
-
|
|
44
|
-
<SelectContent>
|
|
45
|
-
<SelectOptions>
|
|
46
|
-
{views.map(view => (
|
|
47
|
-
<SelectOption
|
|
48
|
-
isActive={calendarView === view.value}
|
|
49
|
-
key={view.value}
|
|
50
|
-
value={view.value}
|
|
51
|
-
onClick={() => handleChangeView(view.value)}
|
|
52
|
-
>
|
|
53
|
-
<SelectOptionText>{view.name}</SelectOptionText>
|
|
54
|
-
</SelectOption>
|
|
55
|
-
))}
|
|
56
|
-
</SelectOptions>
|
|
57
|
-
</SelectContent>
|
|
58
|
-
</SelectRoot>
|
|
59
|
-
</div>
|
|
60
|
-
)
|
|
61
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { useFullCalendar } from './calendar-root'
|
|
2
|
-
import { CalendarMonthView } from './calendar-month-view'
|
|
3
|
-
import { CalendarWeekView } from './calendar-week-view'
|
|
4
|
-
import { CalendarDayView } from './calendar-day-view'
|
|
5
|
-
|
|
6
|
-
export function CalendarViewRenderer() {
|
|
7
|
-
const { calendarView } = useFullCalendar()
|
|
8
|
-
|
|
9
|
-
switch (calendarView) {
|
|
10
|
-
case 'month':
|
|
11
|
-
return <CalendarMonthView />
|
|
12
|
-
case 'week':
|
|
13
|
-
return <CalendarWeekView />
|
|
14
|
-
case 'day':
|
|
15
|
-
return <CalendarDayView />
|
|
16
|
-
default:
|
|
17
|
-
return <CalendarMonthView />
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { cx } from '@xjur-ui/util'
|
|
2
|
-
import type { ComponentProps } from 'react'
|
|
3
|
-
import { Typography } from '../typography'
|
|
4
|
-
import { isToday, WEEKDAYS } from './helpers/calendar'
|
|
5
|
-
|
|
6
|
-
interface CalendarWeekDayProps extends ComponentProps<'div'> {
|
|
7
|
-
date: Date
|
|
8
|
-
className?: string
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function CalendarWeekDay({
|
|
12
|
-
date,
|
|
13
|
-
className,
|
|
14
|
-
...props
|
|
15
|
-
}: CalendarWeekDayProps) {
|
|
16
|
-
const isCurrentDay = isToday(date)
|
|
17
|
-
const dayNumber = date.getDate()
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<div
|
|
21
|
-
className={cx(
|
|
22
|
-
'p-small gap-small-1x flex w-full flex-1 flex-col items-center',
|
|
23
|
-
className
|
|
24
|
-
)}
|
|
25
|
-
data-slot="week-day"
|
|
26
|
-
key={date.toISOString()}
|
|
27
|
-
{...props}
|
|
28
|
-
>
|
|
29
|
-
<Typography size="sm" variant="label" weight="medium">
|
|
30
|
-
{WEEKDAYS[date.getDay()]}
|
|
31
|
-
</Typography>
|
|
32
|
-
<div
|
|
33
|
-
className={cx(
|
|
34
|
-
'size-large-2x rounded-circle flex items-center justify-center',
|
|
35
|
-
isCurrentDay && 'bg-primary-idle'
|
|
36
|
-
)}
|
|
37
|
-
>
|
|
38
|
-
<Typography
|
|
39
|
-
className={cx(isCurrentDay && 'text-neutral-label')}
|
|
40
|
-
size="sm-1x"
|
|
41
|
-
variant="label"
|
|
42
|
-
weight="medium"
|
|
43
|
-
>
|
|
44
|
-
{dayNumber}
|
|
45
|
-
</Typography>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
)
|
|
49
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { useCallback, useMemo } from 'react'
|
|
2
|
-
import { cx } from '@xjur-ui/util'
|
|
3
|
-
import { setHours } from 'date-fns'
|
|
4
|
-
import { Typography } from '../typography'
|
|
5
|
-
import {
|
|
6
|
-
WEEK_HOURS,
|
|
7
|
-
getWeekDaysInMonth,
|
|
8
|
-
getEventsForDayAndHour
|
|
9
|
-
} from './helpers/calendar'
|
|
10
|
-
import { useFullCalendar } from './calendar-root'
|
|
11
|
-
import { CalendarWeekDay } from './calendar-week-day'
|
|
12
|
-
import { CalendarCell } from './calendar-cell'
|
|
13
|
-
import type { ICalendarCell } from './types/calendar-cell'
|
|
14
|
-
|
|
15
|
-
export function CalendarWeekView() {
|
|
16
|
-
const { selectedDate, events } = useFullCalendar()
|
|
17
|
-
|
|
18
|
-
const monthWeekDaysCells = useMemo(
|
|
19
|
-
() => getWeekDaysInMonth(selectedDate),
|
|
20
|
-
[selectedDate]
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
const getEventsForDayAndHourCallback = useCallback(
|
|
24
|
-
(date: Date, hour: number) => {
|
|
25
|
-
return getEventsForDayAndHour(events, date, hour)
|
|
26
|
-
},
|
|
27
|
-
[events]
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
const cellsWithHour = useCallback((cell: ICalendarCell, hour: number) => {
|
|
31
|
-
return {
|
|
32
|
-
...cell,
|
|
33
|
-
date: setHours(cell.date, hour)
|
|
34
|
-
}
|
|
35
|
-
}, [])
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<div className="bg-layer-2-hover rounded-small-1x border-border-layer-2 scrollbar-hide h-full w-full border">
|
|
39
|
-
<div className="flex flex-1 flex-col">
|
|
40
|
-
<div
|
|
41
|
-
className={cx(
|
|
42
|
-
'bg-layer-2-hover sticky top-0 grid [grid-template-columns:64px_repeat(7,1fr)]',
|
|
43
|
-
'[&>*]:border-border-layer-2',
|
|
44
|
-
'[&>*]:border-l'
|
|
45
|
-
)}
|
|
46
|
-
data-slot="week-header"
|
|
47
|
-
>
|
|
48
|
-
{monthWeekDaysCells.map((cell, index) => (
|
|
49
|
-
<CalendarWeekDay
|
|
50
|
-
date={cell.date}
|
|
51
|
-
key={cell.date.getDay()}
|
|
52
|
-
style={{ gridColumnStart: index + 2 }}
|
|
53
|
-
/>
|
|
54
|
-
))}
|
|
55
|
-
</div>
|
|
56
|
-
|
|
57
|
-
<div className="overflow-hidden">
|
|
58
|
-
{WEEK_HOURS.map(({ hour, label }) => (
|
|
59
|
-
<div className="flex items-start" key={hour}>
|
|
60
|
-
<div className="px-small flex h-full w-[64px] items-start justify-end">
|
|
61
|
-
<Typography size="sm-1x" variant="label" weight="medium">
|
|
62
|
-
{label}
|
|
63
|
-
</Typography>
|
|
64
|
-
</div>
|
|
65
|
-
|
|
66
|
-
<div
|
|
67
|
-
className={cx(
|
|
68
|
-
'grid flex-1 grid-cols-7',
|
|
69
|
-
'[&>*]:border-border-layer-2',
|
|
70
|
-
'[&>*]:border-t',
|
|
71
|
-
'[&>*]:border-l'
|
|
72
|
-
)}
|
|
73
|
-
>
|
|
74
|
-
{monthWeekDaysCells.map(cell => (
|
|
75
|
-
<CalendarCell
|
|
76
|
-
cell={cellsWithHour(cell, hour)}
|
|
77
|
-
events={getEventsForDayAndHourCallback(cell.date, hour)}
|
|
78
|
-
key={cell.date.toISOString()}
|
|
79
|
-
/>
|
|
80
|
-
))}
|
|
81
|
-
</div>
|
|
82
|
-
</div>
|
|
83
|
-
))}
|
|
84
|
-
</div>
|
|
85
|
-
</div>
|
|
86
|
-
</div>
|
|
87
|
-
)
|
|
88
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
endOfMonth,
|
|
3
|
-
startOfMonth,
|
|
4
|
-
subMonths,
|
|
5
|
-
isToday as isTodayDateFns,
|
|
6
|
-
isSameDay,
|
|
7
|
-
endOfWeek,
|
|
8
|
-
startOfWeek,
|
|
9
|
-
eachDayOfInterval
|
|
10
|
-
} from 'date-fns'
|
|
11
|
-
import type { ICalendarEvent } from '../types/calendar-event'
|
|
12
|
-
import type { ICalendarCell } from '../types/calendar-cell'
|
|
13
|
-
import type { ICalendarWeekHour } from '../types/calendar-week-hour'
|
|
14
|
-
|
|
15
|
-
function arrayFromLength(length: number) {
|
|
16
|
-
return Array.from({ length }, (_, i) => i)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const WEEKDAYS = [
|
|
20
|
-
'Domingo',
|
|
21
|
-
'Segunda',
|
|
22
|
-
'Terça',
|
|
23
|
-
'Quarta',
|
|
24
|
-
'Quinta',
|
|
25
|
-
'Sexta',
|
|
26
|
-
'Sábado'
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
export const WEEK_HOURS: ICalendarWeekHour[] = Array.from(
|
|
30
|
-
{ length: 16 },
|
|
31
|
-
(_, i) => {
|
|
32
|
-
const hour = i + 8
|
|
33
|
-
return {
|
|
34
|
-
hour,
|
|
35
|
-
label: `${hour.toString().padStart(2, '0')}:00`
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
export function getDaysInMonth(date: Date): ICalendarCell[] {
|
|
41
|
-
const year = date.getFullYear()
|
|
42
|
-
const month = date.getMonth()
|
|
43
|
-
|
|
44
|
-
const firstWeekdayOfMonth = startOfMonth(date).getDay()
|
|
45
|
-
const daysInPrevMonth = endOfMonth(subMonths(date, 1)).getDate()
|
|
46
|
-
const daysInMonth = endOfMonth(date).getDate()
|
|
47
|
-
|
|
48
|
-
const prevMonthDays = arrayFromLength(firstWeekdayOfMonth).map<ICalendarCell>(
|
|
49
|
-
dayIndex => {
|
|
50
|
-
dayIndex += 1
|
|
51
|
-
const prevMonth = month - 1
|
|
52
|
-
const dayOfPrevMonth = daysInPrevMonth - firstWeekdayOfMonth
|
|
53
|
-
const day = dayOfPrevMonth + dayIndex
|
|
54
|
-
const date = new Date(year, prevMonth, day)
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
dayOfWeekNumber: date.getDay(),
|
|
58
|
-
date,
|
|
59
|
-
type: 'month'
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
const currentMonthDays = arrayFromLength(daysInMonth).map<ICalendarCell>(
|
|
65
|
-
dayIndex => {
|
|
66
|
-
const day = dayIndex + 1
|
|
67
|
-
const date = new Date(year, month, day)
|
|
68
|
-
return {
|
|
69
|
-
dayOfWeekNumber: date.getDay(),
|
|
70
|
-
date,
|
|
71
|
-
type: 'month'
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
const totalWeekdays = 7
|
|
77
|
-
const totalDays = firstWeekdayOfMonth + daysInMonth
|
|
78
|
-
const remainingDays =
|
|
79
|
-
totalWeekdays - ((totalDays % totalWeekdays) % totalWeekdays)
|
|
80
|
-
|
|
81
|
-
const nextMonthDays = arrayFromLength(remainingDays).map<ICalendarCell>(
|
|
82
|
-
dayIndex => {
|
|
83
|
-
const day = dayIndex + 1
|
|
84
|
-
const date = new Date(year, month + 1, day)
|
|
85
|
-
return {
|
|
86
|
-
dayOfWeekNumber: date.getDay(),
|
|
87
|
-
date,
|
|
88
|
-
type: 'month'
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
return [...prevMonthDays, ...currentMonthDays, ...nextMonthDays]
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export function getEventsForDay(events: ICalendarEvent[], date: Date) {
|
|
97
|
-
return events.filter(event => isSameDay(event.eventDate, date))
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function isToday(date: Date) {
|
|
101
|
-
return isTodayDateFns(date)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Week view helpers
|
|
106
|
-
*/
|
|
107
|
-
|
|
108
|
-
export function getWeekDaysInMonth(date: Date): ICalendarCell[] {
|
|
109
|
-
const weekStart = startOfWeek(date, { weekStartsOn: 0 }) // Domingo = 0
|
|
110
|
-
const weekEnd = endOfWeek(date, { weekStartsOn: 0 })
|
|
111
|
-
const weekDays = eachDayOfInterval({ start: weekStart, end: weekEnd })
|
|
112
|
-
|
|
113
|
-
const dayOfWeekNumber = weekStart.getDay()
|
|
114
|
-
const dayOfWeekName = WEEKDAYS[dayOfWeekNumber]
|
|
115
|
-
|
|
116
|
-
return weekDays.map(day => ({
|
|
117
|
-
date: day,
|
|
118
|
-
dayOfWeekNumber,
|
|
119
|
-
dayOfWeekName,
|
|
120
|
-
fullDate: day,
|
|
121
|
-
type: 'week'
|
|
122
|
-
}))
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function getEventsForDayAndHour(
|
|
126
|
-
events: ICalendarEvent[],
|
|
127
|
-
date: Date,
|
|
128
|
-
hour: number
|
|
129
|
-
): ICalendarEvent[] {
|
|
130
|
-
return events.filter(event => {
|
|
131
|
-
return (
|
|
132
|
-
isSameDay(event.eventDate, date) && event.eventDate.getHours() === hour
|
|
133
|
-
)
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export function isCurrentHour(date: Date, hour: number): boolean {
|
|
138
|
-
const now = new Date()
|
|
139
|
-
return isSameDay(now, date) && now.getHours() === hour
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function getStartAndEndDateOfWeek(date: Date): {
|
|
143
|
-
start: Date
|
|
144
|
-
end: Date
|
|
145
|
-
} {
|
|
146
|
-
const start = startOfWeek(date, { weekStartsOn: 0 })
|
|
147
|
-
const end = endOfWeek(date, { weekStartsOn: 0 })
|
|
148
|
-
return { start, end }
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Day view helpers
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
export function getDaysInDay(date: Date): ICalendarCell[] {
|
|
156
|
-
const days = eachDayOfInterval({ start: date, end: date })
|
|
157
|
-
return days.map(day => ({ date: day, type: 'day' }))
|
|
158
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export * from './calendar-month-view'
|
|
2
|
-
export * from './calendar-week-view'
|
|
3
|
-
export * from './calendar-view-renderer'
|
|
4
|
-
export * from './calendar-navigator'
|
|
5
|
-
export * from './calendar-root'
|
|
6
|
-
export * from './calendar-toggle-view'
|
|
7
|
-
export * from './calendar-header'
|
|
8
|
-
export * from './calendar-body'
|
|
9
|
-
export * from './calendar-event'
|
|
10
|
-
export * from './calendar-today-button'
|
|
11
|
-
|
|
12
|
-
export type {
|
|
13
|
-
ICalendarEvent,
|
|
14
|
-
ICalendarEventStatus
|
|
15
|
-
} from './types/calendar-event'
|
|
16
|
-
export type { CalendarView } from './types/calendar-view'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type CalendarView = 'month' | 'week' | 'day'
|