clayui-date-picker 3.165.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/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ Valid-License-Identifier: LicenseRef-BSD-3-Clause-Liferay
2
+ Valid-License-Identifier: BSD-3-Clause
3
+ License-Text:
4
+
5
+ Copyright (c) 2014, Liferay Inc. All rights reserved.
6
+
7
+ Redistribution and use in source and binary forms, with or without modification,
8
+ are permitted provided that the following conditions are met:
9
+
10
+ 1. Redistributions of source code must retain the above copyright notice,
11
+ this list of conditions and the following disclaimer.
12
+
13
+ 1. Redistributions in binary form must reproduce the above copyright notice,
14
+ this list of conditions and the following disclaimer in the documentation
15
+ and/or other materials provided with the distribution.
16
+
17
+ 1. Neither the name of the copyright holder nor the names of its contributors
18
+ may be used to endorse or promote products derived from this software without
19
+ specific prior written permission.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
30
+ USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # `@clayui/date-picker`
2
+
3
+ Date and Time pickers let users select a date and time for a form.
4
+
5
+ - [Documentation](https://clayui.com/docs/components/date-picker.html)
6
+ - [Changelog](./CHANGELOG.md)
7
+ - [Breaking change schedule](./BREAKING.md)
8
+
9
+ ## Install
10
+
11
+ Run `yarn`
12
+
13
+ ```shell
14
+ yarn add @clayui/date-picker
15
+ ```
16
+
17
+ ## Contribute
18
+
19
+ We'd love to get contributions from you! Please, check our [Contributing Guidelines](https://github.com/liferay/clay/blob/master/CONTRIBUTING.md) to see how you can help us improve.
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var DateNavigation_exports = {};
30
+ __export(DateNavigation_exports, {
31
+ default: () => DateNavigation_default
32
+ });
33
+ module.exports = __toCommonJS(DateNavigation_exports);
34
+ var import_button = __toESM(require("@clayui/button"));
35
+ var import_icon = __toESM(require("@clayui/icon"));
36
+ var import_react = __toESM(require("react"));
37
+ var import_Helpers = require("./Helpers");
38
+ var import_Select = __toESM(require("./Select"));
39
+ function ClayDatePickerDateNavigation({
40
+ ariaLabels,
41
+ currentMonth,
42
+ disabled,
43
+ months,
44
+ onDotClicked,
45
+ onMonthChange,
46
+ spritemap,
47
+ years
48
+ }) {
49
+ function handleChangeMonth(month) {
50
+ const date = (0, import_Helpers.setMonth)(years, month, currentMonth);
51
+ if (date) {
52
+ onMonthChange(date);
53
+ }
54
+ }
55
+ const handlePreviousMonthClicked = () => handleChangeMonth(-1);
56
+ const handleNextMonthClicked = () => handleChangeMonth(1);
57
+ return /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-calendar-header" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-nav" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-nav-item input-date-picker-month" }, /* @__PURE__ */ import_react.default.createElement(
58
+ import_Select.default,
59
+ {
60
+ "aria-label": ariaLabels.selectMonth,
61
+ disabled,
62
+ name: "month",
63
+ onChange: (event) => onMonthChange(
64
+ new Date(
65
+ currentMonth.getFullYear(),
66
+ Number(event.target.value)
67
+ )
68
+ ),
69
+ options: months,
70
+ testId: "month-select",
71
+ value: currentMonth.getMonth()
72
+ }
73
+ )), /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-nav-item input-date-picker-year" }, /* @__PURE__ */ import_react.default.createElement(
74
+ import_Select.default,
75
+ {
76
+ "aria-label": ariaLabels.selectYear,
77
+ disabled,
78
+ name: "year",
79
+ onChange: (event) => onMonthChange(
80
+ new Date(
81
+ Number(event.target.value),
82
+ currentMonth.getMonth()
83
+ )
84
+ ),
85
+ options: years,
86
+ testId: "year-select",
87
+ value: currentMonth.getFullYear()
88
+ }
89
+ )), /* @__PURE__ */ import_react.default.createElement("div", { className: "date-picker-nav-controls date-picker-nav-item date-picker-nav-item-expand" }, /* @__PURE__ */ import_react.default.createElement(
90
+ import_button.default,
91
+ {
92
+ "aria-label": ariaLabels.buttonPreviousMonth,
93
+ className: "nav-btn nav-btn-monospaced",
94
+ disabled,
95
+ displayType: null,
96
+ onClick: handlePreviousMonthClicked,
97
+ title: ariaLabels.buttonPreviousMonth
98
+ },
99
+ /* @__PURE__ */ import_react.default.createElement(import_icon.default, { spritemap, symbol: "angle-left" })
100
+ ), /* @__PURE__ */ import_react.default.createElement(
101
+ import_button.default,
102
+ {
103
+ "aria-label": ariaLabels.buttonDot,
104
+ className: "nav-btn nav-btn-monospaced",
105
+ disabled,
106
+ displayType: null,
107
+ onClick: onDotClicked,
108
+ title: ariaLabels.buttonDot
109
+ },
110
+ /* @__PURE__ */ import_react.default.createElement(import_icon.default, { spritemap, symbol: "simple-circle" })
111
+ ), /* @__PURE__ */ import_react.default.createElement(
112
+ import_button.default,
113
+ {
114
+ "aria-label": ariaLabels.buttonNextMonth,
115
+ className: "nav-btn nav-btn-monospaced",
116
+ disabled,
117
+ displayType: null,
118
+ onClick: handleNextMonthClicked,
119
+ title: ariaLabels.buttonNextMonth
120
+ },
121
+ /* @__PURE__ */ import_react.default.createElement(import_icon.default, { spritemap, symbol: "angle-right" })
122
+ ))));
123
+ }
124
+ var DateNavigation_default = ClayDatePickerDateNavigation;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var DayNumber_exports = {};
30
+ __export(DayNumber_exports, {
31
+ default: () => DayNumber_default
32
+ });
33
+ module.exports = __toCommonJS(DayNumber_exports);
34
+ var import_shared = require("@clayui/shared");
35
+ var import_classnames = __toESM(require("classnames"));
36
+ var import_react = __toESM(require("react"));
37
+ var import_Helpers = require("./Helpers");
38
+ function ClayDatePickerDayNumber({
39
+ day,
40
+ daysSelected,
41
+ disabled,
42
+ index,
43
+ isFocused,
44
+ onClick,
45
+ outOfRange,
46
+ range
47
+ }) {
48
+ const { date, nextMonth, previousMonth } = day;
49
+ const [startDate, endDate] = daysSelected;
50
+ const isStartAndEndDateRange = startDate.toDateString() !== endDate.toDateString() && isWithinInterval(date, daysSelected);
51
+ const hasEndDateSelected = date.toDateString() === endDate.toDateString();
52
+ const hasStartDateSelected = date.toDateString() === startDate.toDateString();
53
+ return /* @__PURE__ */ import_react.default.createElement(
54
+ "div",
55
+ {
56
+ "aria-selected": isStartAndEndDateRange || hasStartDateSelected ? true : void 0,
57
+ className: (0, import_classnames.default)(
58
+ "date-picker-col",
59
+ range && {
60
+ "c-selected": isStartAndEndDateRange,
61
+ "c-selected-end": hasEndDateSelected && !hasStartDateSelected,
62
+ "c-selected-start": hasStartDateSelected && !hasEndDateSelected
63
+ }
64
+ ),
65
+ role: "gridcell"
66
+ },
67
+ /* @__PURE__ */ import_react.default.createElement(
68
+ "button",
69
+ {
70
+ "aria-disabled": outOfRange ? true : void 0,
71
+ "aria-label": (0, import_Helpers.setDate)(date, {
72
+ hours: 12,
73
+ milliseconds: 0,
74
+ minutes: 0,
75
+ seconds: 0
76
+ }).toDateString(),
77
+ className: (0, import_classnames.default)(
78
+ "date-picker-date date-picker-calendar-item",
79
+ {
80
+ "active": hasStartDateSelected || range && hasEndDateSelected,
81
+ "disabled": disabled || outOfRange,
82
+ "next-month-date": nextMonth,
83
+ "previous-month-date": previousMonth
84
+ }
85
+ ),
86
+ "data-index": index,
87
+ disabled,
88
+ onClick: () => onClick(date),
89
+ onKeyDown: (event) => {
90
+ if (event.key === import_shared.Keys.Spacebar) {
91
+ event.preventDefault();
92
+ }
93
+ },
94
+ onKeyUp: (event) => {
95
+ if (event.key === import_shared.Keys.Spacebar) {
96
+ onClick(date);
97
+ }
98
+ },
99
+ tabIndex: isFocused ? void 0 : -1,
100
+ type: "button"
101
+ },
102
+ date.getDate()
103
+ )
104
+ );
105
+ }
106
+ function isWithinInterval(date, interval) {
107
+ const [start, end] = interval;
108
+ const time = date.getTime();
109
+ const startTime = start.getTime();
110
+ const endTime = end.getTime();
111
+ if (startTime > endTime) {
112
+ return false;
113
+ }
114
+ return time >= startTime && time <= endTime;
115
+ }
116
+ var DayNumber_default = ClayDatePickerDayNumber;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var DaysTable_exports = {};
30
+ __export(DaysTable_exports, {
31
+ default: () => DaysTable_default
32
+ });
33
+ module.exports = __toCommonJS(DaysTable_exports);
34
+ var import_react = __toESM(require("react"));
35
+ function ClayDatePickerDaysTable({ children, weeks }) {
36
+ return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, weeks.map((days, index) => /* @__PURE__ */ import_react.default.createElement(
37
+ "div",
38
+ {
39
+ className: "date-picker-date-row date-picker-row",
40
+ "data-index": index,
41
+ key: index,
42
+ role: "row"
43
+ },
44
+ days.map((day, index2) => {
45
+ return import_react.default.Children.only(children({ day, key: index2 }));
46
+ })
47
+ )));
48
+ }
49
+ var DaysTable_default = ClayDatePickerDaysTable;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var Helpers_exports = {};
30
+ __export(Helpers_exports, {
31
+ addMonths: () => addMonths,
32
+ clamp: () => clamp,
33
+ clone: () => clone,
34
+ formatDate: () => import_format.default,
35
+ isAfter: () => isAfter,
36
+ isBefore: () => isBefore,
37
+ isSameDay: () => isSameDay,
38
+ isValid: () => isValid,
39
+ parseDate: () => import_parse.default,
40
+ range: () => range,
41
+ setDate: () => setDate,
42
+ setMonth: () => setMonth
43
+ });
44
+ module.exports = __toCommonJS(Helpers_exports);
45
+ var import_format = __toESM(require("date-fns/format"));
46
+ var import_parse = __toESM(require("date-fns/parse"));
47
+ function addMonths(date, months) {
48
+ date = clone(date);
49
+ date.setMonth(date.getMonth() + months);
50
+ return date;
51
+ }
52
+ function clamp(date, min, max) {
53
+ if (min && isBefore(date, min)) {
54
+ return clone(min);
55
+ }
56
+ if (max && isAfter(date, max)) {
57
+ return clone(max);
58
+ }
59
+ return clone(date);
60
+ }
61
+ function clone(date) {
62
+ return new Date(date instanceof Date ? date.getTime() : date);
63
+ }
64
+ function isAfter(a, b) {
65
+ return a.getTime() > b.getTime();
66
+ }
67
+ function isBefore(a, b) {
68
+ return a.getTime() < b.getTime();
69
+ }
70
+ function isSameDay(a, b) {
71
+ return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
72
+ }
73
+ function isValid(date) {
74
+ return date instanceof Date && !isNaN(date.getTime());
75
+ }
76
+ function range({ end, start }) {
77
+ return Array.from(
78
+ {
79
+ length: end - start + 1
80
+ },
81
+ (_v, k) => k + start
82
+ );
83
+ }
84
+ function setDate(date, options) {
85
+ date = clone(date);
86
+ return Object.keys(options).reduce((acc, key) => {
87
+ const method = `set${key.charAt(0).toUpperCase() + key.slice(1)}`;
88
+ acc[method](options[key]);
89
+ return acc;
90
+ }, date);
91
+ }
92
+ function setMonth(range2, month, currentMonth) {
93
+ const date = addMonths(currentMonth, month);
94
+ const year = date.getFullYear();
95
+ if (range2.find((elem) => elem.value === year)) {
96
+ return date;
97
+ }
98
+ }