compostrap 1.0.2 → 1.0.3
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/dist/css/compostrap.css +4 -4
- package/dist/css/sidebar-menu.css +4 -4
- package/dist/css/theme.css +5 -22
- package/docs/blog.md +85 -85
- package/docs/layout.md +143 -143
- package/package.json +1 -1
- package/readme.md +198 -198
- package/src/js/datepicker.js +154 -154
- package/src/scss/datagrid.scss +5 -5
- package/src/scss/datepicker/_index.scss +557 -557
- package/src/scss/sidebar/_index.scss +8 -8
- package/src/scss/sidebar-menu/_pills.scss +10 -8
package/src/js/datepicker.js
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Datepicker: a calendar of Vanilla Calendar Pro under an input with data-bs-toggle="datepicker", configured like the
|
|
3
|
-
* datepicker of Bootstrap 6 (the same data attributes). The value of the input is an ISO date (2026-11-07), which a
|
|
4
|
-
* server understands; data-bs-date-format="locale" writes it in the language of the page instead (for display only).
|
|
5
|
-
* A choice fires input and change on the input. An element with data-bs-inline="true" shows the calendar in the page,
|
|
6
|
-
* with an <input type="hidden"> inside for the value.
|
|
7
|
-
*
|
|
8
|
-
* Attributes: data-bs-date-min, data-bs-date-max (ISO dates or "today"), data-bs-selection-mode ("single", "multiple",
|
|
9
|
-
* "multiple-ranged"), data-bs-display-months-count, data-bs-first-weekday (1 = Monday), data-bs-locale (the lang of the
|
|
10
|
-
* page by default), data-bs-date-format ("iso" or "locale"), data-bs-inline, data-bs-selection-time-mode (24 or 12: a time
|
|
11
|
-
* under the calendar, the value is then "2026-11-07 14:30"; the calendar stays open after a click on a day).
|
|
12
|
-
*
|
|
13
|
-
* <input type="text" class="form-control" data-bs-toggle="datepicker" data-bs-date-min="today" autocomplete="off">
|
|
14
|
-
*/
|
|
15
|
-
import { Calendar, months, time as timeExtension } from 'vanilla-calendar-pro';
|
|
16
|
-
|
|
17
|
-
const SELECTOR = '[data-bs-toggle="datepicker"]';
|
|
18
|
-
|
|
19
|
-
export class Datepicker {
|
|
20
|
-
static options = {
|
|
21
|
-
firstWeekday: 1,
|
|
22
|
-
locale: null,
|
|
23
|
-
dateFormat: 'iso',
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
static _calendars = new WeakMap();
|
|
27
|
-
static _initialized = false;
|
|
28
|
-
|
|
29
|
-
/** Starts the datepickers; the options are defaults for all of them, the data attributes of an input win. */
|
|
30
|
-
static init(options = {}) {
|
|
31
|
-
this.options = { ...this.options, ...options };
|
|
32
|
-
document.querySelectorAll(`${SELECTOR}[data-bs-inline="true"]`).forEach((element) => this.get(element));
|
|
33
|
-
if (this._initialized) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this._initialized = true;
|
|
38
|
-
document.addEventListener('focusin', (event) => {
|
|
39
|
-
const input = event.target.closest?.(SELECTOR);
|
|
40
|
-
// the first focus creates the calendar and opens it, later ones are opened by the calendar itself (it
|
|
41
|
-
// knows when the focus only returns to the input after a choice)
|
|
42
|
-
if (input && input.tagName === 'INPUT' && !input.disabled && !input.readOnly && !this._calendars.has(input)) {
|
|
43
|
-
this.get(input).show();
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
// a focus or a press outside closes the calendar (Vanilla Calendar Pro closes it on a click only)
|
|
47
|
-
const outside = (event) => {
|
|
48
|
-
document.querySelectorAll('[data-vc="calendar"][data-vc-input]:not([data-vc-calendar-hidden])').forEach((element) => {
|
|
49
|
-
const input = element.__compostrapInput;
|
|
50
|
-
if (input && !input.contains(event.target) && !element.contains(event.target)) {
|
|
51
|
-
this._calendars.get(input)?.hide();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
document.addEventListener('focusin', outside);
|
|
56
|
-
document.addEventListener('pointerdown', outside);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/** The calendar of an input (or of an inline element), created on first use. */
|
|
60
|
-
static get(element) {
|
|
61
|
-
let calendar = this._calendars.get(element);
|
|
62
|
-
if (!calendar) {
|
|
63
|
-
calendar = this._create(element);
|
|
64
|
-
this._calendars.set(element, calendar);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return calendar;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static _create(element) {
|
|
71
|
-
const data = element.dataset;
|
|
72
|
-
const inline = data.bsInline === 'true';
|
|
73
|
-
const input = element.tagName === 'INPUT' ? element : element.querySelector('input');
|
|
74
|
-
const mode = data.bsSelectionMode || 'single';
|
|
75
|
-
const format = data.bsDateFormat || this.options.dateFormat;
|
|
76
|
-
const locale = data.bsLocale || this.options.locale || document.documentElement.lang || 'default';
|
|
77
|
-
const count = Number(data.bsDisplayMonthsCount) || 1;
|
|
78
|
-
const timeMode = [12, 24].includes(Number(data.bsSelectionTimeMode)) ? Number(data.bsSelectionTimeMode) : false;
|
|
79
|
-
const value = input?.dataset.bsValue || input?.value || '';
|
|
80
|
-
const selected = this._parse(value);
|
|
81
|
-
const time = timeMode ? value.match(/\d{1,2}:\d{2}(?:\s?[AP]M)?/i)?.[0] : null;
|
|
82
|
-
|
|
83
|
-
// writes the chosen dates (and the time) into the input
|
|
84
|
-
const write = (self) => {
|
|
85
|
-
const dates = [...self.context.selectedDates];
|
|
86
|
-
if (input) {
|
|
87
|
-
input.dataset.bsValue = dates.join(',');
|
|
88
|
-
input.value = this._format(dates, mode, format, locale) + (timeMode && dates.length ? ' ' + self.context.selectedTime : '');
|
|
89
|
-
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
90
|
-
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return dates;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const calendar = new Calendar(element, {
|
|
97
|
-
extensions: timeMode ? [months, timeExtension] : [months],
|
|
98
|
-
inputMode: !inline,
|
|
99
|
-
openOnFocus: true,
|
|
100
|
-
positionToInput: 'left',
|
|
101
|
-
firstWeekday: Number(data.bsFirstWeekday ?? this.options.firstWeekday),
|
|
102
|
-
locale,
|
|
103
|
-
selectionDatesMode: mode,
|
|
104
|
-
selectedDates: selected,
|
|
105
|
-
displayMonthsCount: count,
|
|
106
|
-
type: count > 1 ? 'multiple' : 'default',
|
|
107
|
-
themeAttrDetect: 'html[data-bs-theme]',
|
|
108
|
-
...(timeMode ? { selectionTimeMode: timeMode } : {}),
|
|
109
|
-
...(time ? { selectedTime: time } : {}),
|
|
110
|
-
...(selected[0] ? { selectedMonth: Number(selected[0].slice(5, 7)) - 1, selectedYear: Number(selected[0].slice(0, 4)) } : {}),
|
|
111
|
-
...(data.bsDateMin ? { dateMin: data.bsDateMin } : {}),
|
|
112
|
-
...(data.bsDateMax ? { dateMax: data.bsDateMax } : {}),
|
|
113
|
-
onInit: (self) => {
|
|
114
|
-
self.context.mainElement.__compostrapInput = element;
|
|
115
|
-
// the calendar stands at the end of the page; in a modal or an offcanvas Bootstrap keeps the focus
|
|
116
|
-
// inside the dialog and took it back from the calendar (which closed before a click reached it), so
|
|
117
|
-
// the focus in the calendar is kept from the focus trap
|
|
118
|
-
self.context.mainElement.addEventListener('focusin', (event) => {
|
|
119
|
-
if (element.closest('.modal, .offcanvas')) {
|
|
120
|
-
event.stopPropagation();
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
},
|
|
124
|
-
onClickDate: (self) => {
|
|
125
|
-
const dates = write(self);
|
|
126
|
-
// with a time the calendar stays open, so the time can be set after the day
|
|
127
|
-
if (!inline && !timeMode && ((mode === 'single' && dates.length) || (mode === 'multiple-ranged' && dates.length > 1))) {
|
|
128
|
-
setTimeout(() => self.hide(), 100);
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
onChangeTime: (self) => {
|
|
132
|
-
if (self.context.selectedDates.length) {
|
|
133
|
-
write(self);
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
calendar.init();
|
|
138
|
-
return calendar;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// ISO dates of a value: "2026-11-07", "2026-11-07,2026-11-09" or "2026-11-07 – 2026-11-09"
|
|
142
|
-
static _parse(value) {
|
|
143
|
-
return value.match(/\d{4}-\d{2}-\d{2}/g) || [];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
static _format(dates, mode, format, locale) {
|
|
147
|
-
const text = (date) => {
|
|
148
|
-
if (format !== 'locale') return date;
|
|
149
|
-
const [y, m, d] = date.split('-').map(Number);
|
|
150
|
-
return new Date(y, m - 1, d).toLocaleDateString(locale === 'default' ? undefined : locale);
|
|
151
|
-
};
|
|
152
|
-
return dates.map(text).join(mode === 'multiple-ranged' ? ' – ' : ', ');
|
|
153
|
-
}
|
|
154
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Datepicker: a calendar of Vanilla Calendar Pro under an input with data-bs-toggle="datepicker", configured like the
|
|
3
|
+
* datepicker of Bootstrap 6 (the same data attributes). The value of the input is an ISO date (2026-11-07), which a
|
|
4
|
+
* server understands; data-bs-date-format="locale" writes it in the language of the page instead (for display only).
|
|
5
|
+
* A choice fires input and change on the input. An element with data-bs-inline="true" shows the calendar in the page,
|
|
6
|
+
* with an <input type="hidden"> inside for the value.
|
|
7
|
+
*
|
|
8
|
+
* Attributes: data-bs-date-min, data-bs-date-max (ISO dates or "today"), data-bs-selection-mode ("single", "multiple",
|
|
9
|
+
* "multiple-ranged"), data-bs-display-months-count, data-bs-first-weekday (1 = Monday), data-bs-locale (the lang of the
|
|
10
|
+
* page by default), data-bs-date-format ("iso" or "locale"), data-bs-inline, data-bs-selection-time-mode (24 or 12: a time
|
|
11
|
+
* under the calendar, the value is then "2026-11-07 14:30"; the calendar stays open after a click on a day).
|
|
12
|
+
*
|
|
13
|
+
* <input type="text" class="form-control" data-bs-toggle="datepicker" data-bs-date-min="today" autocomplete="off">
|
|
14
|
+
*/
|
|
15
|
+
import { Calendar, months, time as timeExtension } from 'vanilla-calendar-pro';
|
|
16
|
+
|
|
17
|
+
const SELECTOR = '[data-bs-toggle="datepicker"]';
|
|
18
|
+
|
|
19
|
+
export class Datepicker {
|
|
20
|
+
static options = {
|
|
21
|
+
firstWeekday: 1,
|
|
22
|
+
locale: null,
|
|
23
|
+
dateFormat: 'iso',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
static _calendars = new WeakMap();
|
|
27
|
+
static _initialized = false;
|
|
28
|
+
|
|
29
|
+
/** Starts the datepickers; the options are defaults for all of them, the data attributes of an input win. */
|
|
30
|
+
static init(options = {}) {
|
|
31
|
+
this.options = { ...this.options, ...options };
|
|
32
|
+
document.querySelectorAll(`${SELECTOR}[data-bs-inline="true"]`).forEach((element) => this.get(element));
|
|
33
|
+
if (this._initialized) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
this._initialized = true;
|
|
38
|
+
document.addEventListener('focusin', (event) => {
|
|
39
|
+
const input = event.target.closest?.(SELECTOR);
|
|
40
|
+
// the first focus creates the calendar and opens it, later ones are opened by the calendar itself (it
|
|
41
|
+
// knows when the focus only returns to the input after a choice)
|
|
42
|
+
if (input && input.tagName === 'INPUT' && !input.disabled && !input.readOnly && !this._calendars.has(input)) {
|
|
43
|
+
this.get(input).show();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
// a focus or a press outside closes the calendar (Vanilla Calendar Pro closes it on a click only)
|
|
47
|
+
const outside = (event) => {
|
|
48
|
+
document.querySelectorAll('[data-vc="calendar"][data-vc-input]:not([data-vc-calendar-hidden])').forEach((element) => {
|
|
49
|
+
const input = element.__compostrapInput;
|
|
50
|
+
if (input && !input.contains(event.target) && !element.contains(event.target)) {
|
|
51
|
+
this._calendars.get(input)?.hide();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
document.addEventListener('focusin', outside);
|
|
56
|
+
document.addEventListener('pointerdown', outside);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The calendar of an input (or of an inline element), created on first use. */
|
|
60
|
+
static get(element) {
|
|
61
|
+
let calendar = this._calendars.get(element);
|
|
62
|
+
if (!calendar) {
|
|
63
|
+
calendar = this._create(element);
|
|
64
|
+
this._calendars.set(element, calendar);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return calendar;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static _create(element) {
|
|
71
|
+
const data = element.dataset;
|
|
72
|
+
const inline = data.bsInline === 'true';
|
|
73
|
+
const input = element.tagName === 'INPUT' ? element : element.querySelector('input');
|
|
74
|
+
const mode = data.bsSelectionMode || 'single';
|
|
75
|
+
const format = data.bsDateFormat || this.options.dateFormat;
|
|
76
|
+
const locale = data.bsLocale || this.options.locale || document.documentElement.lang || 'default';
|
|
77
|
+
const count = Number(data.bsDisplayMonthsCount) || 1;
|
|
78
|
+
const timeMode = [12, 24].includes(Number(data.bsSelectionTimeMode)) ? Number(data.bsSelectionTimeMode) : false;
|
|
79
|
+
const value = input?.dataset.bsValue || input?.value || '';
|
|
80
|
+
const selected = this._parse(value);
|
|
81
|
+
const time = timeMode ? value.match(/\d{1,2}:\d{2}(?:\s?[AP]M)?/i)?.[0] : null;
|
|
82
|
+
|
|
83
|
+
// writes the chosen dates (and the time) into the input
|
|
84
|
+
const write = (self) => {
|
|
85
|
+
const dates = [...self.context.selectedDates];
|
|
86
|
+
if (input) {
|
|
87
|
+
input.dataset.bsValue = dates.join(',');
|
|
88
|
+
input.value = this._format(dates, mode, format, locale) + (timeMode && dates.length ? ' ' + self.context.selectedTime : '');
|
|
89
|
+
input.dispatchEvent(new Event('input', { bubbles: true }));
|
|
90
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return dates;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const calendar = new Calendar(element, {
|
|
97
|
+
extensions: timeMode ? [months, timeExtension] : [months],
|
|
98
|
+
inputMode: !inline,
|
|
99
|
+
openOnFocus: true,
|
|
100
|
+
positionToInput: 'left',
|
|
101
|
+
firstWeekday: Number(data.bsFirstWeekday ?? this.options.firstWeekday),
|
|
102
|
+
locale,
|
|
103
|
+
selectionDatesMode: mode,
|
|
104
|
+
selectedDates: selected,
|
|
105
|
+
displayMonthsCount: count,
|
|
106
|
+
type: count > 1 ? 'multiple' : 'default',
|
|
107
|
+
themeAttrDetect: 'html[data-bs-theme]',
|
|
108
|
+
...(timeMode ? { selectionTimeMode: timeMode } : {}),
|
|
109
|
+
...(time ? { selectedTime: time } : {}),
|
|
110
|
+
...(selected[0] ? { selectedMonth: Number(selected[0].slice(5, 7)) - 1, selectedYear: Number(selected[0].slice(0, 4)) } : {}),
|
|
111
|
+
...(data.bsDateMin ? { dateMin: data.bsDateMin } : {}),
|
|
112
|
+
...(data.bsDateMax ? { dateMax: data.bsDateMax } : {}),
|
|
113
|
+
onInit: (self) => {
|
|
114
|
+
self.context.mainElement.__compostrapInput = element;
|
|
115
|
+
// the calendar stands at the end of the page; in a modal or an offcanvas Bootstrap keeps the focus
|
|
116
|
+
// inside the dialog and took it back from the calendar (which closed before a click reached it), so
|
|
117
|
+
// the focus in the calendar is kept from the focus trap
|
|
118
|
+
self.context.mainElement.addEventListener('focusin', (event) => {
|
|
119
|
+
if (element.closest('.modal, .offcanvas')) {
|
|
120
|
+
event.stopPropagation();
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
},
|
|
124
|
+
onClickDate: (self) => {
|
|
125
|
+
const dates = write(self);
|
|
126
|
+
// with a time the calendar stays open, so the time can be set after the day
|
|
127
|
+
if (!inline && !timeMode && ((mode === 'single' && dates.length) || (mode === 'multiple-ranged' && dates.length > 1))) {
|
|
128
|
+
setTimeout(() => self.hide(), 100);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
onChangeTime: (self) => {
|
|
132
|
+
if (self.context.selectedDates.length) {
|
|
133
|
+
write(self);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
calendar.init();
|
|
138
|
+
return calendar;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ISO dates of a value: "2026-11-07", "2026-11-07,2026-11-09" or "2026-11-07 – 2026-11-09"
|
|
142
|
+
static _parse(value) {
|
|
143
|
+
return value.match(/\d{4}-\d{2}-\d{2}/g) || [];
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
static _format(dates, mode, format, locale) {
|
|
147
|
+
const text = (date) => {
|
|
148
|
+
if (format !== 'locale') return date;
|
|
149
|
+
const [y, m, d] = date.split('-').map(Number);
|
|
150
|
+
return new Date(y, m - 1, d).toLocaleDateString(locale === 'default' ? undefined : locale);
|
|
151
|
+
};
|
|
152
|
+
return dates.map(text).join(mode === 'multiple-ranged' ? ' – ' : ', ');
|
|
153
|
+
}
|
|
154
|
+
}
|
package/src/scss/datagrid.scss
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
// datagrid module of compostrap
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
@use 'datagrid/index';
|
|
1
|
+
//
|
|
2
|
+
// datagrid module of compostrap
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
@use 'datagrid/index';
|