Skip to content

Commit 60febef

Browse files
committed
replace calendar library
1 parent dfda22f commit 60febef

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

app/assets/stylesheets/application.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// links to stylesheets inside node_modules
2-
@use "add2calendar/css/add2calendar";
32
@use "bootstrap/scss/bootstrap.scss" with (
43
$primary: #00447c
54
);

app/javascript/src/add_to_calendar_button.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
/* global $ */
22

3-
const Add2Calendar = require('add2calendar')
3+
import 'add-to-calendar-button'
44

55
function createCalendarEvents () {
66
const calendarButtons = document.querySelectorAll('div.cal-btn')
77

88
for (const calendarButton of calendarButtons) {
9-
const calendarEvent = new Add2Calendar({
10-
title: calendarButton.dataset.title,
11-
start: calendarButton.dataset.start,
12-
end: calendarButton.dataset.end,
13-
description: calendarButton.dataset.title,
14-
isAllDay: true
15-
})
9+
// Create the add-to-calendar-button web component
10+
const button = document.createElement('add-to-calendar-button')
1611

17-
calendarEvent.createWidget(`#${calendarButton.id}`)
18-
calendarButton.title = calendarButton.dataset.tooltip
12+
// Set attributes from data attributes
13+
button.setAttribute('name', calendarButton.dataset.title)
14+
button.setAttribute('startDate', calendarButton.dataset.start)
15+
button.setAttribute('endDate', calendarButton.dataset.end)
16+
button.setAttribute('description', calendarButton.dataset.title)
17+
button.setAttribute('options', "'Apple','Google','iCal','Microsoft365','Outlook.com','Yahoo'")
18+
button.setAttribute('timeZone', 'currentBrowser')
19+
button.setAttribute('lightMode', 'bodyScheme')
20+
21+
// Set tooltip
22+
button.title = calendarButton.dataset.tooltip
23+
24+
// Replace the div content with the button
25+
calendarButton.innerHTML = ''
26+
calendarButton.appendChild(button)
1927
}
2028
}
2129

package-lock.json

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@rails/activestorage": "^8.1.0",
2323
"@rails/ujs": "^7.1.502",
2424
"@stimulus-components/rails-nested-form": "^5.0.0",
25-
"add2calendar": "^1.1.8",
25+
"add-to-calendar-button": "^2.12.12",
2626
"bootstrap": "5.3.6",
2727
"bootstrap-datepicker": "^1.10.1",
2828
"bootstrap-scss": "^5.3.4",

0 commit comments

Comments
 (0)