@schedule-x/react 0.4.0 → 0.6.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/.husky/pre-commit +5 -0
- package/LICENSE +7 -0
- package/cypress/e2e/001-smoke.cy.ts +1 -1
- package/cypress/e2e/002-custom-events.cy.ts +33 -0
- package/cypress/pages/{001-smoke.html → 001-smoke/001-smoke.html} +1 -1
- package/cypress/pages/{001-smoke.tsx → 001-smoke/001-smoke.tsx} +2 -2
- package/cypress/pages/002-custom-events/002-custom-events.html +21 -0
- package/cypress/pages/002-custom-events/002-custom-events.tsx +65 -0
- package/cypress/pages/002-custom-events/components/CustomDateGridEvent.tsx +26 -0
- package/cypress/pages/002-custom-events/components/CustomMonthAgendaEvent.tsx +26 -0
- package/cypress/pages/002-custom-events/components/CustomMonthGridEvent.tsx +26 -0
- package/cypress/pages/002-custom-events/components/CustomTimeGridEvent.tsx +30 -0
- package/development/App.tsx +36 -4
- package/development/components/CustomDateGridEvent.tsx +26 -0
- package/development/components/CustomTimeGridEvent.tsx +29 -0
- package/development/index.css +2 -2
- package/dist/index.cjs.js +30 -5
- package/dist/index.js +31 -7
- package/dist/types/index.d.ts +2 -1
- package/dist/types/schedule-x-calendar.d.ts +14 -0
- package/dist/types/types/custom-components.d.ts +6 -0
- package/package.json +9 -6
- package/src/index.tsx +4 -1
- package/src/schedule-x-calendar.tsx +79 -0
- package/src/types/custom-components.ts +8 -0
- package/dist/assets/index-I1yYmKKo.js +0 -40
- package/dist/assets/index-tSapxTsJ.css +0 -1
- package/dist/index.html +0 -14
- package/dist/types/calendar.d.ts +0 -6
- package/src/calendar.tsx +0 -20
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2023 Tom Österlund
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createCalendarHeaderPageObject } from '@schedule-x/e2e-testing'
|
|
2
|
+
|
|
3
|
+
const calendarHeader = createCalendarHeaderPageObject()
|
|
4
|
+
|
|
5
|
+
describe('Custom events', () => {
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
cy.visit('/cypress/pages/002-custom-events/002-custom-events.html')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('should render custom events in week view', () => {
|
|
11
|
+
cy.contains('Event 1')
|
|
12
|
+
cy.contains('ID: 1')
|
|
13
|
+
cy.contains('Event 2|ID2')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('should render custom events in month view', () => {
|
|
17
|
+
calendarHeader.openViewByLabel('Month')
|
|
18
|
+
cy.contains('Event 1|ID1').should('exist')
|
|
19
|
+
cy.contains('Event 2|ID2').should('exist')
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
describe('Custom events test on mobile', () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
cy.visit('/cypress/pages/002-custom-events/002-custom-events.html')
|
|
26
|
+
cy.viewport('iphone-6')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should render custom events in month agenda view', () => {
|
|
30
|
+
calendarHeader.openViewByLabel('Month')
|
|
31
|
+
cy.contains('Event 1|ID1').should('exist')
|
|
32
|
+
})
|
|
33
|
+
})
|
|
@@ -5,14 +5,14 @@ import '@fontsource/open-sans/700.css'
|
|
|
5
5
|
import '@fontsource/open-sans/700-italic.css'
|
|
6
6
|
import ReactDOM from 'react-dom/client'
|
|
7
7
|
import React from 'react'
|
|
8
|
-
import { Calendar, useCalendarApp } from '
|
|
8
|
+
import { Calendar, useCalendarApp } from '../../..'
|
|
9
9
|
import {
|
|
10
10
|
viewDay,
|
|
11
11
|
viewMonthAgenda,
|
|
12
12
|
viewMonthGrid,
|
|
13
13
|
viewWeek,
|
|
14
14
|
} from '@schedule-x/calendar'
|
|
15
|
-
import '
|
|
15
|
+
import '../index.css'
|
|
16
16
|
import '@schedule-x/theme-default/dist/index.css'
|
|
17
17
|
|
|
18
18
|
// eslint-disable-next-line react-refresh/only-export-components
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta
|
|
6
|
+
name="viewport"
|
|
7
|
+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"
|
|
8
|
+
/>
|
|
9
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
|
10
|
+
<title>Browser test | React Calendar | Custom events</title>
|
|
11
|
+
<style>
|
|
12
|
+
body {
|
|
13
|
+
margin: 0;
|
|
14
|
+
}
|
|
15
|
+
</style>
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
<div id="root"></div>
|
|
19
|
+
<script type="module" src="002-custom-events.tsx"></script>
|
|
20
|
+
</body>
|
|
21
|
+
</html>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import '@fontsource/open-sans'
|
|
2
|
+
import '@fontsource/open-sans/300.css'
|
|
3
|
+
import '@fontsource/open-sans/500-italic.css'
|
|
4
|
+
import '@fontsource/open-sans/700.css'
|
|
5
|
+
import '@fontsource/open-sans/700-italic.css'
|
|
6
|
+
import ReactDOM from 'react-dom/client'
|
|
7
|
+
import React from 'react'
|
|
8
|
+
import { ScheduleXCalendar, useCalendarApp } from '../../..'
|
|
9
|
+
import {
|
|
10
|
+
viewDay,
|
|
11
|
+
viewMonthAgenda,
|
|
12
|
+
viewMonthGrid,
|
|
13
|
+
viewWeek,
|
|
14
|
+
} from '@schedule-x/calendar'
|
|
15
|
+
import '../index.css'
|
|
16
|
+
import '@schedule-x/theme-default/dist/index.css'
|
|
17
|
+
import CustomTimeGridEvent from './components/CustomTimeGridEvent.tsx'
|
|
18
|
+
import CustomDateGridEvent from './components/CustomDateGridEvent.tsx'
|
|
19
|
+
import CustomMonthAgendaEvent from './components/CustomMonthAgendaEvent.tsx'
|
|
20
|
+
import CustomMonthGridEvent from './components/CustomMonthGridEvent.tsx'
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line react-refresh/only-export-components
|
|
23
|
+
function App() {
|
|
24
|
+
const calendarApp = useCalendarApp({
|
|
25
|
+
views: [viewWeek, viewMonthGrid, viewDay, viewMonthAgenda],
|
|
26
|
+
defaultView: viewWeek.name,
|
|
27
|
+
events: [
|
|
28
|
+
{
|
|
29
|
+
id: '1',
|
|
30
|
+
title: 'Event 1',
|
|
31
|
+
start: '2023-12-15 06:00',
|
|
32
|
+
end: '2023-12-15 08:00',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: '2',
|
|
36
|
+
title: 'Event 2',
|
|
37
|
+
start: '2023-12-14',
|
|
38
|
+
end: '2023-12-14',
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
selectedDate: '2023-12-15',
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
return (
|
|
45
|
+
<>
|
|
46
|
+
<div className="schedule-x-calendar">
|
|
47
|
+
<ScheduleXCalendar
|
|
48
|
+
calendarApp={calendarApp}
|
|
49
|
+
customComponents={{
|
|
50
|
+
timeGridEvent: CustomTimeGridEvent,
|
|
51
|
+
dateGridEvent: CustomDateGridEvent,
|
|
52
|
+
monthAgendaEvent: CustomMonthAgendaEvent,
|
|
53
|
+
monthGridEvent: CustomMonthGridEvent,
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
</div>
|
|
57
|
+
</>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
ReactDOM.createRoot(document.getElementById('root')!).render(
|
|
62
|
+
<React.StrictMode>
|
|
63
|
+
<App />
|
|
64
|
+
</React.StrictMode>
|
|
65
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type props = {
|
|
2
|
+
calendarEvent: {
|
|
3
|
+
id: string | number
|
|
4
|
+
title: string
|
|
5
|
+
start: string
|
|
6
|
+
end: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function CustomDateGridEvent({ calendarEvent }: props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
height: '100%',
|
|
15
|
+
width: '100%',
|
|
16
|
+
background: 'green',
|
|
17
|
+
color: 'white',
|
|
18
|
+
padding: '2px',
|
|
19
|
+
borderRadius: 5,
|
|
20
|
+
border: '1px solid white',
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
<span>{calendarEvent.title}</span>|<span>ID{calendarEvent.id}</span>
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type props = {
|
|
2
|
+
calendarEvent: {
|
|
3
|
+
id: string | number
|
|
4
|
+
title: string
|
|
5
|
+
start: string
|
|
6
|
+
end: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function CustomMonthAgendaEvent({ calendarEvent }: props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
height: '100%',
|
|
15
|
+
width: '100%',
|
|
16
|
+
background: 'green',
|
|
17
|
+
color: 'white',
|
|
18
|
+
padding: '2px',
|
|
19
|
+
borderRadius: 5,
|
|
20
|
+
border: '1px solid white',
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
<span>{calendarEvent.title}</span>|<span>ID{calendarEvent.id}</span>
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type props = {
|
|
2
|
+
calendarEvent: {
|
|
3
|
+
id: string | number
|
|
4
|
+
title: string
|
|
5
|
+
start: string
|
|
6
|
+
end: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function CustomMonthGridEvent({ calendarEvent }: props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
height: '100%',
|
|
15
|
+
width: '100%',
|
|
16
|
+
background: 'green',
|
|
17
|
+
color: 'white',
|
|
18
|
+
padding: '2px',
|
|
19
|
+
borderRadius: 5,
|
|
20
|
+
border: '1px solid white',
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
<span>{calendarEvent.title}</span>|<span>ID{calendarEvent.id}</span>
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type props = {
|
|
2
|
+
calendarEvent: {
|
|
3
|
+
id: string | number
|
|
4
|
+
title: string
|
|
5
|
+
start: string
|
|
6
|
+
end: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function CustomTimeGridEvent({ calendarEvent }: props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
top: 0,
|
|
16
|
+
left: 0,
|
|
17
|
+
right: 0,
|
|
18
|
+
height: '100%',
|
|
19
|
+
background: 'green',
|
|
20
|
+
color: 'white',
|
|
21
|
+
padding: 10,
|
|
22
|
+
borderRadius: 5,
|
|
23
|
+
border: '1px solid white',
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
<div>{calendarEvent.title}</div>
|
|
27
|
+
<div>ID: {calendarEvent.id}</div>
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
package/development/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import './App.css'
|
|
2
|
-
import {
|
|
2
|
+
import { ScheduleXCalendar, useCalendarApp } from '../src'
|
|
3
3
|
import {
|
|
4
4
|
viewDay,
|
|
5
5
|
viewMonthAgenda,
|
|
@@ -7,24 +7,56 @@ import {
|
|
|
7
7
|
viewWeek,
|
|
8
8
|
} from '@schedule-x/calendar'
|
|
9
9
|
import '@schedule-x/theme-default/dist/index.css'
|
|
10
|
+
import { createDragAndDropPlugin } from '@schedule-x/drag-and-drop'
|
|
11
|
+
import { createEventModalPlugin } from '@schedule-x/event-modal'
|
|
12
|
+
import CustomTimeGridEvent from './components/CustomTimeGridEvent.tsx'
|
|
13
|
+
import CustomDateGridEvent from './components/CustomDateGridEvent.tsx'
|
|
10
14
|
|
|
11
15
|
function App() {
|
|
12
16
|
const calendarApp = useCalendarApp({
|
|
13
17
|
views: [viewMonthGrid, viewDay, viewWeek, viewMonthAgenda],
|
|
18
|
+
selectedDate: '2023-12-22',
|
|
14
19
|
events: [
|
|
20
|
+
{
|
|
21
|
+
id: '0',
|
|
22
|
+
title: 'Event 0',
|
|
23
|
+
start: '2023-12-22',
|
|
24
|
+
end: '2023-12-22',
|
|
25
|
+
},
|
|
15
26
|
{
|
|
16
27
|
id: '1',
|
|
17
28
|
title: 'Event 1',
|
|
18
|
-
start: '2023-12-
|
|
19
|
-
end: '2023-12-
|
|
29
|
+
start: '2023-12-22 05:00',
|
|
30
|
+
end: '2023-12-22 07:00',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
id: '2',
|
|
34
|
+
title: 'Event 2',
|
|
35
|
+
start: '2023-12-22 05:00',
|
|
36
|
+
end: '2023-12-22 07:00',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id: '3',
|
|
40
|
+
title: 'Event 3',
|
|
41
|
+
start: '2023-12-23 05:00',
|
|
42
|
+
end: '2023-12-23 07:00',
|
|
20
43
|
},
|
|
21
44
|
],
|
|
45
|
+
plugins: [createDragAndDropPlugin(), createEventModalPlugin()],
|
|
22
46
|
})
|
|
23
47
|
|
|
24
48
|
return (
|
|
25
49
|
<>
|
|
26
50
|
<div>
|
|
27
|
-
<
|
|
51
|
+
<ScheduleXCalendar
|
|
52
|
+
calendarApp={calendarApp}
|
|
53
|
+
customComponents={{
|
|
54
|
+
timeGridEvent: CustomTimeGridEvent,
|
|
55
|
+
dateGridEvent: CustomDateGridEvent,
|
|
56
|
+
monthAgendaEvent: CustomDateGridEvent,
|
|
57
|
+
monthGridEvent: CustomDateGridEvent,
|
|
58
|
+
}}
|
|
59
|
+
/>
|
|
28
60
|
</div>
|
|
29
61
|
</>
|
|
30
62
|
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
type props = {
|
|
2
|
+
calendarEvent: {
|
|
3
|
+
id: string | number
|
|
4
|
+
title: string
|
|
5
|
+
start: string
|
|
6
|
+
end: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function CustomDateGridEvent({ calendarEvent }: props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
height: '100%',
|
|
15
|
+
width: '100%',
|
|
16
|
+
background: 'green',
|
|
17
|
+
color: 'white',
|
|
18
|
+
padding: '2px',
|
|
19
|
+
borderRadius: 5,
|
|
20
|
+
border: '1px solid white',
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
{calendarEvent.title}
|
|
24
|
+
</div>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
type props = {
|
|
2
|
+
calendarEvent: {
|
|
3
|
+
id: string | number
|
|
4
|
+
title: string
|
|
5
|
+
start: string
|
|
6
|
+
end: string
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default function CustomTimeGridEvent({ calendarEvent }: props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
style={{
|
|
14
|
+
position: 'absolute',
|
|
15
|
+
top: 0,
|
|
16
|
+
left: 0,
|
|
17
|
+
right: 0,
|
|
18
|
+
height: '100%',
|
|
19
|
+
background: 'green',
|
|
20
|
+
color: 'white',
|
|
21
|
+
padding: 10,
|
|
22
|
+
borderRadius: 5,
|
|
23
|
+
border: '1px solid white',
|
|
24
|
+
}}
|
|
25
|
+
>
|
|
26
|
+
{calendarEvent.title}
|
|
27
|
+
</div>
|
|
28
|
+
)
|
|
29
|
+
}
|
package/development/index.css
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -2,14 +2,38 @@
|
|
|
2
2
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var react = require('react');
|
|
5
|
+
var reactDom = require('react-dom');
|
|
5
6
|
var calendar = require('@schedule-x/calendar');
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
const createCustomComponentFn = (setCustomComponent, customComponent) => (wrapperElement, props) => {
|
|
9
|
+
setCustomComponent({
|
|
10
|
+
Component: react.createElement(customComponent, props),
|
|
11
|
+
wrapperElement,
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
function ScheduleXCalendar({ calendarApp, customComponents }) {
|
|
15
|
+
const randomId = 'sx' + Math.random().toString(36).substring(2, 11);
|
|
16
|
+
const [customComponentsMeta, setCustomComponentsMeta] = react.useState([]);
|
|
17
|
+
const setComponent = (component) => {
|
|
18
|
+
setCustomComponentsMeta((prev) => {
|
|
19
|
+
const newComponents = [...prev];
|
|
20
|
+
const ccid = component.wrapperElement.dataset.ccid;
|
|
21
|
+
const existingComponent = newComponents.find((c) => c.wrapperElement.dataset.ccid === ccid);
|
|
22
|
+
if (existingComponent) {
|
|
23
|
+
newComponents.splice(newComponents.indexOf(existingComponent), 1);
|
|
24
|
+
}
|
|
25
|
+
return [...newComponents, component];
|
|
26
|
+
});
|
|
27
|
+
};
|
|
9
28
|
react.useEffect(() => {
|
|
29
|
+
for (const [componentName, Component] of Object.entries(customComponents || {})) {
|
|
30
|
+
calendarApp._setCustomComponentFn(componentName, createCustomComponentFn(setComponent, Component));
|
|
31
|
+
}
|
|
10
32
|
calendarApp.render(document.getElementById(randomId));
|
|
11
|
-
}, [calendarApp, randomId]);
|
|
12
|
-
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx("div", { className: "sx-react-calendar-wrapper", id: randomId }) })
|
|
33
|
+
}, [calendarApp, randomId, customComponents]);
|
|
34
|
+
return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsxs(react.Fragment, { children: [jsxRuntime.jsx("div", { className: "sx-react-calendar-wrapper", id: randomId }), customComponentsMeta.map(({ Component, wrapperElement }) => {
|
|
35
|
+
return reactDom.createPortal(Component, wrapperElement);
|
|
36
|
+
})] }) }));
|
|
13
37
|
}
|
|
14
38
|
|
|
15
39
|
function useCalendarApp(config) {
|
|
@@ -17,5 +41,6 @@ function useCalendarApp(config) {
|
|
|
17
41
|
return calendarApp;
|
|
18
42
|
}
|
|
19
43
|
|
|
20
|
-
exports.Calendar =
|
|
44
|
+
exports.Calendar = ScheduleXCalendar;
|
|
45
|
+
exports.ScheduleXCalendar = ScheduleXCalendar;
|
|
21
46
|
exports.useCalendarApp = useCalendarApp;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
|
-
import { jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
-
import { useEffect,
|
|
1
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useEffect, Fragment as Fragment$1, createElement } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
import { createCalendar } from '@schedule-x/calendar';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
const createCustomComponentFn = (setCustomComponent, customComponent) => (wrapperElement, props) => {
|
|
7
|
+
setCustomComponent({
|
|
8
|
+
Component: createElement(customComponent, props),
|
|
9
|
+
wrapperElement,
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
function ScheduleXCalendar({ calendarApp, customComponents }) {
|
|
13
|
+
const randomId = 'sx' + Math.random().toString(36).substring(2, 11);
|
|
14
|
+
const [customComponentsMeta, setCustomComponentsMeta] = useState([]);
|
|
15
|
+
const setComponent = (component) => {
|
|
16
|
+
setCustomComponentsMeta((prev) => {
|
|
17
|
+
const newComponents = [...prev];
|
|
18
|
+
const ccid = component.wrapperElement.dataset.ccid;
|
|
19
|
+
const existingComponent = newComponents.find((c) => c.wrapperElement.dataset.ccid === ccid);
|
|
20
|
+
if (existingComponent) {
|
|
21
|
+
newComponents.splice(newComponents.indexOf(existingComponent), 1);
|
|
22
|
+
}
|
|
23
|
+
return [...newComponents, component];
|
|
24
|
+
});
|
|
25
|
+
};
|
|
7
26
|
useEffect(() => {
|
|
27
|
+
for (const [componentName, Component] of Object.entries(customComponents || {})) {
|
|
28
|
+
calendarApp._setCustomComponentFn(componentName, createCustomComponentFn(setComponent, Component));
|
|
29
|
+
}
|
|
8
30
|
calendarApp.render(document.getElementById(randomId));
|
|
9
|
-
}, [calendarApp, randomId]);
|
|
10
|
-
return (jsx(Fragment, { children: jsx("div", { className: "sx-react-calendar-wrapper", id: randomId }) })
|
|
31
|
+
}, [calendarApp, randomId, customComponents]);
|
|
32
|
+
return (jsx(Fragment, { children: jsxs(Fragment$1, { children: [jsx("div", { className: "sx-react-calendar-wrapper", id: randomId }), customComponentsMeta.map(({ Component, wrapperElement }) => {
|
|
33
|
+
return createPortal(Component, wrapperElement);
|
|
34
|
+
})] }) }));
|
|
11
35
|
}
|
|
12
36
|
|
|
13
37
|
function useCalendarApp(config) {
|
|
@@ -15,4 +39,4 @@ function useCalendarApp(config) {
|
|
|
15
39
|
return calendarApp;
|
|
16
40
|
}
|
|
17
41
|
|
|
18
|
-
export { Calendar, useCalendarApp };
|
|
42
|
+
export { ScheduleXCalendar as Calendar, ScheduleXCalendar, useCalendarApp };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { CalendarApp } from '@schedule-x/calendar';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
type ReactComponent = React.ComponentType<any>;
|
|
4
|
+
type props = {
|
|
5
|
+
calendarApp: CalendarApp;
|
|
6
|
+
customComponents?: {
|
|
7
|
+
timeGridEvent?: ReactComponent;
|
|
8
|
+
dateGridEvent?: ReactComponent;
|
|
9
|
+
monthGridEvent?: ReactComponent;
|
|
10
|
+
monthAgendaEvent?: ReactComponent;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare function ScheduleXCalendar({ calendarApp, customComponents }: props): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "dist/index.cjs.js",
|
|
15
15
|
"module": "dist/index.js",
|
|
16
16
|
"types": "dist/types/index.d.ts",
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.6.0",
|
|
18
18
|
"type": "module",
|
|
19
19
|
"scripts": {
|
|
20
20
|
"dev": "vite",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"build:publish": "npm run build && npm publish"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
|
-
"@schedule-x/calendar": "^0.
|
|
29
|
+
"@schedule-x/calendar": "^0.6.0",
|
|
30
30
|
"react": "^16.7.0 || ^17 || ^18",
|
|
31
31
|
"react-dom": "^16.7.0 || ^17 || ^18"
|
|
32
32
|
},
|
|
@@ -35,10 +35,12 @@
|
|
|
35
35
|
"@rollup/plugin-commonjs": "^25.0.7",
|
|
36
36
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
37
37
|
"@rollup/plugin-typescript": "^11.1.5",
|
|
38
|
-
"@schedule-x/
|
|
39
|
-
"@schedule-x/
|
|
40
|
-
"@schedule-x/
|
|
41
|
-
"@schedule-x/
|
|
38
|
+
"@schedule-x/drag-and-drop": "^0.6.0",
|
|
39
|
+
"@schedule-x/e2e-testing": "^0.6.0",
|
|
40
|
+
"@schedule-x/eslint-config": "^0.6.0",
|
|
41
|
+
"@schedule-x/event-modal": "^0.6.0",
|
|
42
|
+
"@schedule-x/prettier-config": "^0.6.0",
|
|
43
|
+
"@schedule-x/theme-default": "^0.6.0",
|
|
42
44
|
"@types/react": "^18.2.43",
|
|
43
45
|
"@types/react-dom": "^18.2.17",
|
|
44
46
|
"@typescript-eslint/eslint-plugin": "^6.14.0",
|
|
@@ -49,6 +51,7 @@
|
|
|
49
51
|
"eslint-config-prettier": "^9.1.0",
|
|
50
52
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
51
53
|
"eslint-plugin-react-refresh": "^0.4.5",
|
|
54
|
+
"husky": "^8.0.3",
|
|
52
55
|
"rollup": "^4.9.0",
|
|
53
56
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
54
57
|
"rollup-plugin-postcss": "^4.0.2",
|
package/src/index.tsx
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
// @deprecated. To be removed in v1.0.0
|
|
2
|
+
export { ScheduleXCalendar as Calendar } from './schedule-x-calendar.tsx'
|
|
3
|
+
|
|
4
|
+
export { ScheduleXCalendar } from './schedule-x-calendar.tsx'
|
|
2
5
|
export { useCalendarApp } from './use-calendar-app.tsx'
|