-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
775 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
.bear-calendar { | ||
font-family: Arial, sans-serif; | ||
height: 100%; | ||
|
||
* { | ||
--primary: #3788d8; | ||
--primary-container: #2f71b3; | ||
--secondary: rgb(216, 146, 16); | ||
--secondary-container: rgb(173, 117, 13); | ||
--surface: #fff; | ||
--text: rgb(61, 61, 61); | ||
--surface-2: #e0e0e0; | ||
--text: rgb(3, 0, 0); | ||
--text-hover: #141414; | ||
--border-color: rgba(0, 0, 0, 0.125); | ||
--disable-day-color: #f0f0f0; | ||
--past-date-dots: #f5ffd0; | ||
--space-sm: 2px; | ||
--space-md: 5px; | ||
--space-lg: 10px; | ||
--space-tn: 2px; | ||
--space-sm: 4px; | ||
--space-md: 8px; | ||
--space-lg: 16px; | ||
--secondary-color: #818181; | ||
--corner: 5px; | ||
--hover: rgba(0, 0, 0, 0.125); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/core/src/components/bear-calendar/view/footer/footer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import classes from "./style.module.scss"; | ||
import { | ||
joinClass, | ||
PluginName, | ||
useCalendarProps, | ||
View, | ||
} from "@bear-calendar/utility"; | ||
import React, {useMemo, useState} from "react"; | ||
|
||
interface IProps { | ||
children: React.ReactNode; | ||
activePlugin: keyof typeof PluginName; | ||
changeView: (name: keyof typeof PluginName) => void; | ||
} | ||
|
||
export const Footer: React.FC<IProps> = ({ | ||
children, | ||
changeView, | ||
activePlugin, | ||
}) => { | ||
const props = useCalendarProps(); | ||
|
||
return ( | ||
<View className={classes.footer} horizontal spaceBetween center> | ||
{props.plugin.length > 1 && ( | ||
<View space="tiny" horizontal> | ||
{props.plugin.map((item) => ( | ||
<View | ||
center | ||
className={joinClass(classes.plugin, [ | ||
activePlugin === item.name, | ||
classes.active, | ||
])} | ||
onClick={changeView.bind(window, item.name)} | ||
> | ||
{item.name.split("")[0]} | ||
</View> | ||
))} | ||
</View> | ||
)} | ||
{children} | ||
</View> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/core/src/components/bear-calendar/view/footer/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./footer"; |
16 changes: 16 additions & 0 deletions
16
packages/core/src/components/bear-calendar/view/footer/style.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.footer { | ||
background: var(--primary); | ||
padding: var(--space-tn); | ||
color: var(--surface); | ||
|
||
.plugin { | ||
width: 20px; | ||
height: 20px; | ||
&.active { | ||
} | ||
} | ||
|
||
&:empty { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.view { | ||
height: 100%; | ||
.body { | ||
height: 100%; | ||
border: 1px solid var(--border-color); | ||
border-bottom: unset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
packages/plugin-timeline/src/components/card/group-card/event-handler/eventHandler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import React, {useMemo} from "react"; | ||
import {IEventModel, useCalendarProps, View} from "@bear-calendar/utility"; | ||
import {useTimelineProps} from "../../../timeline/useTimelineProps"; | ||
import dayjs from "dayjs"; | ||
import classes from "./style.module.scss"; | ||
import {EventHolder} from "./eventHolder"; | ||
|
||
type IWithPriority = { | ||
priority: number; | ||
event: IEventModel; | ||
}; | ||
interface IProps { | ||
events: IEventModel[]; | ||
} | ||
export const EventHandler: React.FC<IProps> = (props) => { | ||
const timelineProps = useTimelineProps(); | ||
const [maxPriority, withPriority] = useMemo(() => { | ||
const maxPriority = 0; | ||
const withPriority: IWithPriority[] = []; | ||
|
||
const isThereConflict = ( | ||
current: dayjs.Dayjs, | ||
start: string, | ||
end: string | ||
) => { | ||
return current.isAfter(start) && current.isBefore(end); | ||
}; | ||
|
||
const startFrom = | ||
(timelineProps.maxEventPerGroup || 0) > props.events.length | ||
? props.events.length | ||
: timelineProps.maxEventPerGroup; | ||
|
||
for (let i = startFrom === undefined ? 5 : startFrom; i >= 0; --i) { | ||
const event = props.events[i]; | ||
|
||
let priority = 0; | ||
if (event) { | ||
for (let j = withPriority.length; j >= 0; j--) { | ||
const prevEvent = withPriority[j]; | ||
if (prevEvent) { | ||
if ( | ||
isThereConflict( | ||
dayjs(event.date.start), | ||
prevEvent.event.date.start, | ||
prevEvent.event.date.end | ||
) || | ||
isThereConflict( | ||
dayjs(event.date.start), | ||
prevEvent.event.date.start, | ||
prevEvent.event.date.end | ||
) | ||
) { | ||
priority = | ||
priority < prevEvent.priority | ||
? prevEvent.priority + 1 | ||
: priority; | ||
} | ||
} | ||
} | ||
withPriority.push({ | ||
priority, | ||
event, | ||
}); | ||
} | ||
} | ||
return [maxPriority, withPriority]; | ||
}, [props.events]); | ||
|
||
const [differentIn] = useMemo(() => { | ||
let format: Parameters<typeof EventHolder>["0"]["differentIn"]; | ||
switch (timelineProps.zoomLevel) { | ||
case "month": | ||
format = "days"; | ||
break; | ||
case "day": | ||
format = "hours"; | ||
break; | ||
case "week": | ||
format = "days"; | ||
break; | ||
} | ||
|
||
return [format]; | ||
}, [timelineProps.zoomLevel]); | ||
|
||
const render = () => { | ||
const events = []; | ||
for (let i = maxPriority; i >= 0; i--) { | ||
events.push( | ||
<View className={classes.line} space="tiny"> | ||
{withPriority | ||
.filter((e) => e.priority === i) | ||
.map((event) => ( | ||
<EventHolder | ||
differentIn={differentIn} | ||
event={event.event} | ||
/> | ||
))} | ||
</View> | ||
); | ||
} | ||
|
||
return events; | ||
}; | ||
|
||
return <View>{render().map((i) => i)}</View>; | ||
}; |
28 changes: 28 additions & 0 deletions
28
packages/plugin-timeline/src/components/card/group-card/event-handler/eventHolder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {EventCard, IEventModel, View} from "@bear-calendar/utility"; | ||
import dayjs from "dayjs"; | ||
import React from "react"; | ||
import classes from "./style.module.scss"; | ||
import {useTimelineProps} from "../../../timeline/useTimelineProps"; | ||
import {useEventHolder} from "./useEventHolder"; | ||
|
||
export interface IEventHolderProps { | ||
differentIn: Parameters<dayjs.Dayjs["diff"]>["1"]; | ||
event: IEventModel; | ||
} | ||
export const EventHolder: React.FC<IEventHolderProps> = (props) => { | ||
const propsTimeline = useTimelineProps(); | ||
const {left, width} = useEventHolder(props); | ||
|
||
return ( | ||
<View | ||
className={classes.event} | ||
style={{left: `${left}px`, width: `${width}px`}} | ||
> | ||
{propsTimeline.renderEvent ? ( | ||
propsTimeline.renderEvent(props.event) | ||
) : ( | ||
<EventCard event={props.event} /> | ||
)} | ||
</View> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
packages/plugin-timeline/src/components/card/group-card/event-handler/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./eventHandler"; |
12 changes: 12 additions & 0 deletions
12
packages/plugin-timeline/src/components/card/group-card/event-handler/style.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.line { | ||
.title { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
|
||
} | ||
|
||
.event { | ||
position: relative; | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/plugin-timeline/src/components/card/group-card/event-handler/useEventHolder.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {IEventModel, useStore} from "@bear-calendar/utility"; | ||
import {useMemo} from "react"; | ||
import {IEventHolderProps} from "./eventHolder"; | ||
import dayjs from "dayjs"; | ||
import {useTimelineProps} from "../../../timeline/useTimelineProps"; | ||
|
||
export const useEventHolder = (props: IEventHolderProps) => { | ||
const propsTimeline = useTimelineProps(); | ||
const {current} = useStore(); | ||
const [left, width] = useMemo(() => { | ||
let left = 0; | ||
let width; | ||
const cellWidth = 80; // TODO :: should be sync width header items | ||
|
||
const diff = dayjs(props.event.date.end).diff( | ||
props.event.date.start, | ||
props.differentIn | ||
); | ||
width = (diff || 1) * cellWidth; | ||
|
||
left = Math.abs( | ||
current | ||
.startOf(propsTimeline.zoomLevel) | ||
.diff(props.event.date.start, props.differentIn) * cellWidth | ||
); | ||
|
||
return [left, width]; | ||
}, []); | ||
|
||
return {left, width}; | ||
}; |
Oops, something went wrong.