@operato/event-view 1.2.5 → 1.2.22
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 +21 -0
- package/dist/src/calendar-monthly-styles.js +6 -1
- package/dist/src/calendar-monthly-styles.js.map +1 -1
- package/dist/src/calendar-monthly.d.ts +1 -10
- package/dist/src/calendar-monthly.js +5 -17
- package/dist/src/calendar-monthly.js.map +1 -1
- package/dist/src/calendar-weekly-styles.js +2 -2
- package/dist/src/calendar-weekly-styles.js.map +1 -1
- package/dist/src/calendar-weekly.d.ts +1 -10
- package/dist/src/calendar-weekly.js +3 -21
- package/dist/src/calendar-weekly.js.map +1 -1
- package/dist/src/common.d.ts +15 -0
- package/dist/src/common.js +13 -0
- package/dist/src/common.js.map +1 -0
- package/dist/src/event-provider.d.ts +2 -3
- package/dist/src/event-provider.js.map +1 -1
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/ox-event-view.d.ts +2 -0
- package/dist/src/ox-event-view.js +5 -3
- package/dist/src/ox-event-view.js.map +1 -1
- package/dist/src/sample-event-provider.d.ts +3 -2
- package/dist/src/sample-event-provider.js +100 -4
- package/dist/src/sample-event-provider.js.map +1 -1
- package/dist/src/types.d.ts +20 -0
- package/dist/src/types.js +13 -0
- package/dist/src/types.js.map +1 -0
- package/dist/stories/index.stories.js +54 -1
- package/dist/stories/index.stories.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -2
- package/src/calendar-monthly-styles.ts +6 -1
- package/src/calendar-monthly.ts +7 -33
- package/src/calendar-weekly-styles.ts +2 -2
- package/src/calendar-weekly.ts +5 -38
- package/src/index.ts +2 -1
- package/src/ox-event-view.ts +4 -3
- package/src/types.ts +38 -0
- package/stories/index.stories.ts +60 -2
- package/themes/calendar-theme.css +1 -2
- package/src/biz-event.ts +0 -6
- package/src/event-provider.ts +0 -6
- package/src/sample-event-provider.ts +0 -116
package/src/calendar-weekly.ts
CHANGED
|
@@ -1,33 +1,9 @@
|
|
|
1
1
|
import dayjs, { Dayjs } from 'dayjs/esm/index'
|
|
2
|
-
import weekday from 'dayjs/esm/plugin/weekday'
|
|
3
|
-
import weekOfYear from 'dayjs/esm/plugin/weekOfYear'
|
|
4
2
|
import { html, LitElement, PropertyValues } from 'lit'
|
|
5
3
|
import { customElement, property } from 'lit/decorators.js'
|
|
6
4
|
|
|
7
|
-
import { BizEvent } from './biz-event'
|
|
8
5
|
import { CalendarWeeklyStyles } from './calendar-weekly-styles'
|
|
9
|
-
import { EventProvider } from './
|
|
10
|
-
|
|
11
|
-
dayjs.extend(weekday)
|
|
12
|
-
dayjs.extend(weekOfYear)
|
|
13
|
-
|
|
14
|
-
const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
15
|
-
|
|
16
|
-
function isToday(date: Date) {
|
|
17
|
-
const today = new Date()
|
|
18
|
-
return (
|
|
19
|
-
date.getDate() == today.getDate() &&
|
|
20
|
-
date.getMonth() == today.getMonth() &&
|
|
21
|
-
date.getFullYear() == today.getFullYear()
|
|
22
|
-
)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
type CALENDAR = {
|
|
26
|
-
label: string
|
|
27
|
-
date: Date
|
|
28
|
-
thisWeek: boolean
|
|
29
|
-
today?: boolean
|
|
30
|
-
}[]
|
|
6
|
+
import { CALENDAR, WEEKDAYS, EventProvider, isToday } from './types'
|
|
31
7
|
|
|
32
8
|
@customElement('calendar-weekly')
|
|
33
9
|
export class CalendarWeekly extends LitElement {
|
|
@@ -41,6 +17,8 @@ export class CalendarWeekly extends LitElement {
|
|
|
41
17
|
render() {
|
|
42
18
|
const calendar = this.createDaysForCurrentWeek(this.year, this.week)
|
|
43
19
|
|
|
20
|
+
const eventMap = this.eventProvider?.fetchEventsForCalendar(calendar)
|
|
21
|
+
|
|
44
22
|
return html`
|
|
45
23
|
<div head>
|
|
46
24
|
<div this-week>
|
|
@@ -49,7 +27,6 @@ export class CalendarWeekly extends LitElement {
|
|
|
49
27
|
|
|
50
28
|
<div nav>
|
|
51
29
|
<mwc-button
|
|
52
|
-
outlined
|
|
53
30
|
@click=${() => {
|
|
54
31
|
const dayJs = this.getLastDateOfWeek(this.year, this.week)
|
|
55
32
|
const prevWeek = dayJs.subtract(1, 'week')
|
|
@@ -85,14 +62,8 @@ export class CalendarWeekly extends LitElement {
|
|
|
85
62
|
${calendar.map(date => {
|
|
86
63
|
return html`<li day-task>
|
|
87
64
|
<div>
|
|
88
|
-
${
|
|
89
|
-
event
|
|
90
|
-
html`<span
|
|
91
|
-
@click=${() => event.clickEvent(event.title, event.due)}
|
|
92
|
-
event
|
|
93
|
-
.style="border-color: ${event.color};"
|
|
94
|
-
>${event.title}</span
|
|
95
|
-
>`
|
|
65
|
+
${(eventMap?.get(date?.date) || []).map(({ title, color, template }) =>
|
|
66
|
+
template ? template : html`<span event .style="border-color: ${color};">${title}</span>`
|
|
96
67
|
)}
|
|
97
68
|
</div>
|
|
98
69
|
</li>`
|
|
@@ -103,10 +74,6 @@ export class CalendarWeekly extends LitElement {
|
|
|
103
74
|
|
|
104
75
|
updated(changes: PropertyValues<this>) {}
|
|
105
76
|
|
|
106
|
-
findEvents(date: Date): BizEvent[] {
|
|
107
|
-
return this.eventProvider?.fetchEventsForDate(date, {}) || []
|
|
108
|
-
}
|
|
109
|
-
|
|
110
77
|
moveTo(year: number, month: number, week: number) {
|
|
111
78
|
this.year = year
|
|
112
79
|
this.month = month
|
package/src/index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './types.js'
|
|
2
|
+
export * from './ox-event-view.js'
|
package/src/ox-event-view.ts
CHANGED
|
@@ -6,7 +6,7 @@ import './calendar-weekly'
|
|
|
6
6
|
import { css, html, LitElement } from 'lit'
|
|
7
7
|
import { customElement, property } from 'lit/decorators.js'
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { EventProvider } from './types'
|
|
10
10
|
|
|
11
11
|
@customElement('ox-event-view')
|
|
12
12
|
export class OxEventView extends LitElement {
|
|
@@ -25,16 +25,17 @@ export class OxEventView extends LitElement {
|
|
|
25
25
|
`
|
|
26
26
|
|
|
27
27
|
@property({ type: String }) mode: 'monthly' | 'weekly' = 'monthly'
|
|
28
|
+
@property({ type: Array }) eventProvider?: EventProvider
|
|
28
29
|
|
|
29
30
|
render() {
|
|
30
31
|
return this.mode == 'weekly'
|
|
31
32
|
? html`
|
|
32
|
-
<calendar-weekly .eventProvider=${
|
|
33
|
+
<calendar-weekly .eventProvider=${this.eventProvider}>
|
|
33
34
|
<mwc-icon @click=${(e: Event) => (this.mode = 'monthly')}>calendar_month</mwc-icon>
|
|
34
35
|
</calendar-weekly>
|
|
35
36
|
`
|
|
36
37
|
: html`
|
|
37
|
-
<calendar-monthly .eventProvider=${
|
|
38
|
+
<calendar-monthly .eventProvider=${this.eventProvider}>
|
|
38
39
|
<mwc-icon @click=${(e: Event) => (this.mode = 'weekly')}>calendar_view_week</mwc-icon>
|
|
39
40
|
</calendar-monthly>
|
|
40
41
|
`
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TemplateResult } from 'lit'
|
|
2
|
+
import dayjs from 'dayjs/esm/index'
|
|
3
|
+
import weekday from 'dayjs/esm/plugin/weekday'
|
|
4
|
+
import weekOfYear from 'dayjs/esm/plugin/weekOfYear'
|
|
5
|
+
|
|
6
|
+
dayjs.extend(weekday)
|
|
7
|
+
dayjs.extend(weekOfYear)
|
|
8
|
+
|
|
9
|
+
export type BizEvent = {
|
|
10
|
+
due?: string
|
|
11
|
+
title: string
|
|
12
|
+
color: string
|
|
13
|
+
clickEvent?: any
|
|
14
|
+
template?: TemplateResult
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type CALENDAR = {
|
|
18
|
+
label: string
|
|
19
|
+
date: Date
|
|
20
|
+
thisMonth?: boolean
|
|
21
|
+
thisWeek?: boolean
|
|
22
|
+
today?: boolean
|
|
23
|
+
}[]
|
|
24
|
+
|
|
25
|
+
export interface EventProvider {
|
|
26
|
+
fetchEventsForCalendar(calendar: CALENDAR): Map<Date, BizEvent[]>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const WEEKDAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
30
|
+
|
|
31
|
+
export function isToday(date: Date) {
|
|
32
|
+
const today = new Date()
|
|
33
|
+
return (
|
|
34
|
+
date.getDate() == today.getDate() &&
|
|
35
|
+
date.getMonth() == today.getMonth() &&
|
|
36
|
+
date.getFullYear() == today.getFullYear()
|
|
37
|
+
)
|
|
38
|
+
}
|
package/stories/index.stories.ts
CHANGED
|
@@ -1,6 +1,64 @@
|
|
|
1
1
|
import '../src/ox-event-view.js'
|
|
2
|
-
|
|
3
2
|
import { html, TemplateResult } from 'lit'
|
|
3
|
+
import { BizEvent, CALENDAR, EventProvider } from '../src/types.js'
|
|
4
|
+
|
|
5
|
+
class SampleEventProvider implements EventProvider {
|
|
6
|
+
fetchEventsForCalendar(calendar: CALENDAR) {
|
|
7
|
+
const map = new Map<Date, BizEvent[]>()
|
|
8
|
+
|
|
9
|
+
calendar.forEach(({ date }) =>
|
|
10
|
+
map.set(date, [
|
|
11
|
+
{
|
|
12
|
+
due: '2021-08-21',
|
|
13
|
+
title: 'HAHAHA',
|
|
14
|
+
color: 'yellow'
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
due: '2021-08-21',
|
|
18
|
+
title: 'HOHOHO',
|
|
19
|
+
color: 'lime'
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
due: '2021-08-21',
|
|
23
|
+
title: 'HIHIHI',
|
|
24
|
+
color: 'yellow'
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
due: '2021-08-21',
|
|
28
|
+
title: 'HEHEHE',
|
|
29
|
+
color: 'white'
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
due: '2021-08-21',
|
|
33
|
+
title: 'KEKEKE',
|
|
34
|
+
color: 'yellow'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
due: '2021-08-21',
|
|
38
|
+
title: 'MEMEME',
|
|
39
|
+
color: 'orange'
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
due: '2021-08-21',
|
|
43
|
+
title: 'MOMOMO',
|
|
44
|
+
color: 'lime'
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
due: '2021-08-21',
|
|
48
|
+
title: 'QUOQUO',
|
|
49
|
+
color: 'navy'
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
due: '2021-08-21',
|
|
53
|
+
title: 'ZZXXCC',
|
|
54
|
+
color: 'gray'
|
|
55
|
+
}
|
|
56
|
+
])
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
return map
|
|
60
|
+
}
|
|
61
|
+
}
|
|
4
62
|
|
|
5
63
|
export default {
|
|
6
64
|
title: 'EventView',
|
|
@@ -26,7 +84,7 @@ const Template: Story<ArgTypes> = ({ mode = 'monthly' }: ArgTypes) =>
|
|
|
26
84
|
<link rel="stylesheet" href="/themes/calendar-theme.css" />
|
|
27
85
|
<link href="https://fonts.googleapis.com/css?family=Material+Icons&display=block" rel="stylesheet" />
|
|
28
86
|
|
|
29
|
-
<ox-event-view mode=${mode}> </ox-event-view>
|
|
87
|
+
<ox-event-view mode=${mode} .eventProvider=${new SampleEventProvider()}> </ox-event-view>
|
|
30
88
|
`
|
|
31
89
|
|
|
32
90
|
export const Regular = Template.bind({})
|
|
@@ -36,7 +36,7 @@ body {
|
|
|
36
36
|
--calendar-weekly-opacity: 0.5;
|
|
37
37
|
--calendar-weekly-date-label-background-color: var(--status-danger-color);
|
|
38
38
|
--calendar-weekly-date-label-margin: var(--margin-narrow);
|
|
39
|
-
--calendar-weekly-date-label-padding:
|
|
39
|
+
--calendar-weekly-date-label-padding: 3px var(--padding-narrow);
|
|
40
40
|
--calendar-weekly-date-label-color: var(--theme-white-color);
|
|
41
41
|
|
|
42
42
|
--calendar-weekly-background-color: #f4f4f4;
|
|
@@ -45,7 +45,6 @@ body {
|
|
|
45
45
|
--calendar-weekly-event-padding: 2px var(--padding-default);
|
|
46
46
|
--calendar-weekly-event-border: 3px solid #ccc;
|
|
47
47
|
--calendar-weekly-event-border-width: 0 0 0 3px;
|
|
48
|
-
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
@media only screen and (max-width: 460px) {
|
package/src/biz-event.ts
DELETED
package/src/event-provider.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { EventProvider } from './event-provider'
|
|
2
|
-
|
|
3
|
-
export class SampleMonthlyEventProvider implements EventProvider {
|
|
4
|
-
fetchEventsForDate(date: Date, options: any) {
|
|
5
|
-
return [
|
|
6
|
-
{
|
|
7
|
-
due: '2021-08-21',
|
|
8
|
-
title: 'HAHAHA',
|
|
9
|
-
color: 'yellow'
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
due: '2021-08-21',
|
|
13
|
-
title: 'HOHOHO',
|
|
14
|
-
color: 'lime'
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
due: '2021-08-21',
|
|
18
|
-
title: 'HIHIHI',
|
|
19
|
-
color: 'yellow'
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
due: '2021-08-21',
|
|
23
|
-
title: 'HEHEHE',
|
|
24
|
-
color: 'white'
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
due: '2021-08-21',
|
|
28
|
-
title: 'KEKEKE',
|
|
29
|
-
color: 'yellow'
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
due: '2021-08-21',
|
|
33
|
-
title: 'MEMEME',
|
|
34
|
-
color: 'orange'
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
due: '2021-08-21',
|
|
38
|
-
title: 'MOMOMO',
|
|
39
|
-
color: 'lime'
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
due: '2021-08-21',
|
|
43
|
-
title: 'QUOQUO',
|
|
44
|
-
color: 'navy'
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
due: '2021-08-21',
|
|
48
|
-
title: 'ZZXXCC',
|
|
49
|
-
color: 'gray'
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
fetchEventsForDuration(from: Date, to: Date, options: any) {
|
|
55
|
-
return []
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export class SampleWeeklyEventProvider implements EventProvider {
|
|
60
|
-
fetchEventsForDate(date: Date, options: any) {
|
|
61
|
-
return [
|
|
62
|
-
{
|
|
63
|
-
due: '2021-08-21',
|
|
64
|
-
title: 'HAHAHA',
|
|
65
|
-
color: 'yellow',
|
|
66
|
-
clickEvent: function (title: string, due: string) {
|
|
67
|
-
console.log('clicked...', title, due)
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
due: '2021-08-21',
|
|
72
|
-
title: 'HOHOHO',
|
|
73
|
-
color: 'lime'
|
|
74
|
-
},
|
|
75
|
-
{
|
|
76
|
-
due: '2021-08-21',
|
|
77
|
-
title: 'HIHIHI',
|
|
78
|
-
color: 'yellow'
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
due: '2021-08-21',
|
|
82
|
-
title: 'HEHEHE',
|
|
83
|
-
color: 'white'
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
due: '2021-08-21',
|
|
87
|
-
title: 'KEKEKE',
|
|
88
|
-
color: 'yellow'
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
due: '2021-08-21',
|
|
92
|
-
title: 'MEMEME',
|
|
93
|
-
color: 'orange'
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
due: '2021-08-21',
|
|
97
|
-
title: 'MOMOMO',
|
|
98
|
-
color: 'lime'
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
due: '2021-08-21',
|
|
102
|
-
title: 'QUOQUO',
|
|
103
|
-
color: 'navy'
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
due: '2021-08-21',
|
|
107
|
-
title: 'ZZXXCC',
|
|
108
|
-
color: 'gray'
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
fetchEventsForDuration(from: Date, to: Date, options: any) {
|
|
114
|
-
return []
|
|
115
|
-
}
|
|
116
|
-
}
|