Skip to content

Commit

Permalink
feat: custom components for week grid (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomosterlund authored Dec 25, 2023
1 parent cf1cb95 commit 0edba78
Show file tree
Hide file tree
Showing 23 changed files with 1,662 additions and 69 deletions.
4 changes: 3 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
extends: ['@schedule-x/eslint-config', 'plugin:vue/vue3-recommended'],
rules: {},
rules: {
'vue/singleline-html-element-content-newline': 'off',
},
ignorePatterns: ['development/shims-vue.d.ts', 'dist/**'],
parserOptions: {
parser: '@typescript-eslint/parser',
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/001-smoke.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('Smoke Test', () => {
const weekView = createWeekViewPageObject()

beforeEach(() => {
cy.visit('/cypress/pages/001-smoke.html')
cy.visit('/cypress/pages/001-smoke/001-smoke.html')
})

it('should navigate between views', () => {
Expand Down
14 changes: 14 additions & 0 deletions cypress/e2e/002-custom-events.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
describe('Custom events test', () => {
beforeEach(() => {
cy.visit('/cypress/pages/002-custom-events/002-custom-events.html')
})

it('should render custom events', () => {
cy.contains('Event 1').should('exist')
cy.contains('Event 2').should('exist')
cy.contains('Event 3').should('exist')
cy.contains('Event 4').should('exist')
cy.contains('Title: Event 5').should('exist')
cy.contains('Id: 5').should('exist')
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { ScheduleXCalendar } from '../../'
import { ScheduleXCalendar } from '../../..'
import {
createCalendar,
viewDay,
Expand All @@ -12,6 +12,7 @@ import {
import '@schedule-x/theme-default/dist/index.css'
const calendarApp = createCalendar({
selectedDate: '2023-12-18',
views: [viewWeek, viewMonthGrid, viewDay, viewMonthAgenda],
events: [
{
Expand Down Expand Up @@ -52,15 +53,11 @@ const removeEvent = () => {
<div class="app">
<ScheduleXCalendar :calendar-app="calendarApp" />

<button @click="addEvent">
add event
</button>
<button @click="updateEvent">
update event
</button>
<button @click="removeEvent">
remove event
</button>
<button @click="addEvent">add event</button>

<button @click="updateEvent">update event</button>

<button @click="removeEvent">remove event</button>
</div>
</template>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import '@fontsource/open-sans/500-italic.css'
import '@fontsource/open-sans/700.css'
import '@fontsource/open-sans/700-italic.css'
import { createApp } from 'vue'
import './style.css'
import '../style.css'
import App from './001-smoke-App.vue'

createApp(App).mount('#root')
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="./001-smoke-main.ts"></script>
<script type="module" src="001-smoke-main.ts"></script>
</body>
</html>
66 changes: 66 additions & 0 deletions cypress/pages/002-custom-events/002-custom-events-App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<script setup lang="ts">
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { ScheduleXCalendar } from '../../..'
import { createCalendar, viewDay, viewWeek } from '@schedule-x/calendar'
import '@schedule-x/theme-default/dist/index.css'
import CustomDateGridEvent from '../../../development/components/CustomDateGridEvent.vue'
import CustomTimeGridEvent from '../../../development/components/CustomTimeGridEvent.vue'
const calendarApp = createCalendar({
views: [viewWeek, viewDay],
selectedDate: '2023-12-18',
events: [
{
id: 1,
title: 'Event 1',
start: '2023-12-18',
end: '2023-12-18',
},
{
id: 2,
title: 'Event 2',
start: '2023-12-17',
end: '2023-12-21',
},
{
id: 3,
title: 'Event 3',
start: '2023-12-22',
end: '2023-12-28',
},
{
id: 4,
title: 'Event 4',
start: '2023-12-22',
end: '2023-12-28',
},
{
id: 5,
title: 'Event 5',
start: '2023-12-18 04:15',
end: '2023-12-18 05:15',
},
],
})
const customComponents = {
dateGridEvent: CustomDateGridEvent,
timeGridEvent: CustomTimeGridEvent,
}
</script>

<template>
<div class="app">
<ScheduleXCalendar
:calendar-app="calendarApp"
:custom-components="customComponents"
/>
</div>
</template>

<style>
.app {
width: 100%;
}
</style>
21 changes: 21 additions & 0 deletions cypress/pages/002-custom-events/002-custom-events.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
/>
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Browser test | Vue Calendar | Custom events</title>
<style>
body {
margin: 0;
}
</style>
</head>
<body>
<div id="root"></div>
<script type="module" src="002-custom-events.ts"></script>
</body>
</html>
10 changes: 10 additions & 0 deletions cypress/pages/002-custom-events/002-custom-events.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import '@fontsource/open-sans'
import '@fontsource/open-sans/300.css'
import '@fontsource/open-sans/500-italic.css'
import '@fontsource/open-sans/700.css'
import '@fontsource/open-sans/700-italic.css'
import { createApp } from 'vue'
import '../style.css'
import App from './002-custom-events-App.vue'

createApp(App).mount('#root')
80 changes: 80 additions & 0 deletions cypress/pages/002-custom-events/components/CustomDateGridEvent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<template>
<div
class="custom-date-grid-event"
:style="{
width: '100%',
height: '100%',
border: '2px solid black',
borderRadius: '4px',
}"
>
<div class="left-arrow">&larr;</div>

{{ calendarEvent.title }}

<div class="right-arrow">&rarr;</div>
</div>
</template>

<script lang="ts" setup>
import { PropType } from 'vue'
defineProps({
calendarEvent: {
type: Object as PropType<{ title: string; id: number | string }>,
required: true,
},
})
</script>

<style lang="scss">
.custom-date-grid-event {
position: relative;
overflow: hidden;
padding: 0 4px;
font-size: 14px;
font-weight: bold;
text-overflow: ellipsis;
white-space: nowrap;
background-color: #fff;
color: #000;
border-radius: 4px;
border: 2px solid black;
box-sizing: border-box;
cursor: pointer;
user-select: none;
transition: background-color 0.2s ease;
&:hover {
background-color: #eee;
}
.sx__date-grid-event--overflow-left & {
padding-left: 24px;
}
}
.left-arrow {
position: absolute;
left: 8px;
top: 50%;
transform: translateY(-50%);
display: none;
.sx__date-grid-event--overflow-left & {
display: block;
}
}
.right-arrow {
position: absolute;
right: 8px;
top: 50%;
transform: translateY(-50%);
display: none;
.sx__date-grid-event--overflow-right & {
display: block;
}
}
</style>
31 changes: 31 additions & 0 deletions cypress/pages/002-custom-events/components/CustomTimeGridEvent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<template>
<div class="custom-time-grid-event">
<input type="checkbox" />
<div>Id: {{ calendarEvent.id }}</div>
<div>Title: {{ calendarEvent.title }}</div>
</div>
</template>

<script lang="ts" setup>
import { PropType } from 'vue'
defineProps({
calendarEvent: {
type: Object as PropType<{ title: string; id: number | string }>,
required: true,
},
})
</script>

<style>
.custom-time-grid-event {
border: 2px solid black;
border-radius: 4px;
background-color: #fff;
font-family: inherit;
line-height: 1.5;
padding: 0.125rem;
width: 100%;
height: 100%;
}
</style>
38 changes: 21 additions & 17 deletions development/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,50 @@ import {
} from '@schedule-x/calendar'
import '@schedule-x/theme-default/dist/index.css'
import { ref } from 'vue'
import { createEventModalPlugin } from '@schedule-x/event-modal'
import { createDragAndDropPlugin } from '@schedule-x/drag-and-drop'
import { seededEvents } from './data/seeded-events.ts'
import { CustomComponents } from '../src/types/custom-components.ts'
import CustomTimeGridEvent from './components/CustomTimeGridEvent.vue'
import CustomDateGridEvent from './components/CustomDateGridEvent.vue'
const counter = ref(0)
const incrementCounter = () => {
counter.value++
}
const sxCal = createCalendar({
const calendarApp = createCalendar({
views: [viewWeek, viewMonthGrid, viewDay, viewMonthAgenda],
events: [
{
id: 1,
title: 'Event 1',
start: '2023-12-18',
end: '2023-12-18',
},
],
events: seededEvents,
plugins: [createEventModalPlugin(), createDragAndDropPlugin()],
})
const addEvent = () => {
sxCal.events.add({
calendarApp.events.add({
id: 2,
title: 'Event 2',
start: '2023-12-19',
end: '2023-12-19',
})
}
const customComponents: CustomComponents = {
timeGridEvent: CustomTimeGridEvent,
dateGridEvent: CustomDateGridEvent,
}
</script>

<template>
<div class="app">
<Calendar :calendar-app="sxCal" />
<Calendar
:calendar-app="calendarApp"
:custom-components="customComponents"
/>

<button @click="addEvent">
add event
</button>
<button @click="addEvent">add event</button>

<button @click="incrementCounter">
increment counter
</button>
<button @click="incrementCounter">increment counter</button>

<div>{{ counter }}</div>
</div>
Expand Down
Loading

0 comments on commit 0edba78

Please sign in to comment.