@primer/components 0.0.0-202110322927 → 0.0.0-2021103235619
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/CHANGELOG.md +1 -29
- package/dist/browser.esm.js +50 -53
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +80 -83
- package/dist/browser.umd.js.map +1 -1
- package/lib/ActionList/Header.js +1 -1
- package/lib/ActionList/Item.d.ts +0 -6
- package/lib/ActionList/Item.js +1 -5
- package/lib/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib/Autocomplete/Autocomplete.d.ts +8 -6
- package/lib/Autocomplete/AutocompleteInput.d.ts +8 -6
- package/lib/Button/Button.d.ts +5 -5
- package/lib/Button/ButtonBase.d.ts +1 -1
- package/lib/Button/ButtonClose.d.ts +3 -3
- package/lib/Button/ButtonDanger.d.ts +5 -5
- package/lib/Button/ButtonInvisible.d.ts +5 -5
- package/lib/Button/ButtonOutline.d.ts +5 -5
- package/lib/Button/ButtonPrimary.d.ts +5 -5
- package/lib/CircleBadge.d.ts +2 -2
- package/lib/CircleOcticon.d.ts +4 -4
- package/lib/DatePicker/DatePicker.d.ts +52 -0
- package/lib/DatePicker/DatePicker.js +109 -0
- package/lib/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib/DatePicker/DatePickerAnchor.js +202 -0
- package/lib/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib/DatePicker/DatePickerOverlay.js +55 -0
- package/lib/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib/DatePicker/DatePickerPanel.js +363 -0
- package/lib/DatePicker/Day.d.ts +15 -0
- package/lib/DatePicker/Day.js +206 -0
- package/lib/DatePicker/Month.d.ts +8 -0
- package/lib/DatePicker/Month.js +122 -0
- package/lib/DatePicker/dateParser.d.ts +12 -0
- package/lib/DatePicker/dateParser.js +192 -0
- package/lib/DatePicker/index.d.ts +2 -0
- package/lib/DatePicker/index.js +13 -0
- package/lib/DatePicker/useDatePicker.d.ts +107 -0
- package/lib/DatePicker/useDatePicker.js +558 -0
- package/lib/Dialog.d.ts +4 -4
- package/lib/Dropdown.d.ts +16 -16
- package/lib/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib/FilterList.d.ts +3 -3
- package/lib/Flash.d.ts +1 -1
- package/lib/Label.d.ts +1 -1
- package/lib/Position.d.ts +4 -4
- package/lib/ProgressBar.d.ts +1 -1
- package/lib/SelectMenu/SelectMenu.d.ts +28 -26
- package/lib/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib/SideNav.d.ts +8 -10
- package/lib/SideNav.js +15 -6
- package/lib/TextInputWithTokens.d.ts +8 -10
- package/lib/TextInputWithTokens.js +29 -102
- package/lib/Timeline.d.ts +4 -4
- package/lib/Token/AvatarToken.d.ts +1 -1
- package/lib/Token/IssueLabelToken.d.ts +1 -1
- package/lib/Token/Token.d.ts +1 -1
- package/lib/Token/Token.js +2 -13
- package/lib/Token/TokenBase.js +4 -0
- package/lib/Token/_RemoveTokenButton.js +2 -15
- package/lib/_TextInputWrapper.d.ts +1 -1
- package/lib/_TextInputWrapper.js +1 -1
- package/lib/hooks/useDebounce.d.ts +2 -0
- package/lib/hooks/useDebounce.js +24 -0
- package/lib/hooks/useResizeObserver.d.ts +1 -1
- package/lib/hooks/useResizeObserver.js +1 -1
- package/lib/sx.d.ts +2 -8
- package/lib/theme-preval.js +2 -2
- package/lib/theme.d.ts +0 -78
- package/lib/theme.js +1 -3
- package/lib/utils/testing.d.ts +1 -1
- package/lib-esm/ActionList/Header.js +1 -1
- package/lib-esm/ActionList/Item.d.ts +0 -6
- package/lib-esm/ActionList/Item.js +1 -5
- package/lib-esm/AnchoredOverlay/AnchoredOverlay.d.ts +4 -2
- package/lib-esm/Autocomplete/Autocomplete.d.ts +8 -6
- package/lib-esm/Autocomplete/AutocompleteInput.d.ts +8 -6
- package/lib-esm/Button/Button.d.ts +5 -5
- package/lib-esm/Button/ButtonBase.d.ts +1 -1
- package/lib-esm/Button/ButtonClose.d.ts +3 -3
- package/lib-esm/Button/ButtonDanger.d.ts +5 -5
- package/lib-esm/Button/ButtonInvisible.d.ts +5 -5
- package/lib-esm/Button/ButtonOutline.d.ts +5 -5
- package/lib-esm/Button/ButtonPrimary.d.ts +5 -5
- package/lib-esm/CircleBadge.d.ts +2 -2
- package/lib-esm/CircleOcticon.d.ts +4 -4
- package/lib-esm/DatePicker/DatePicker.d.ts +52 -0
- package/lib-esm/DatePicker/DatePicker.js +92 -0
- package/lib-esm/DatePicker/DatePickerAnchor.d.ts +5 -0
- package/lib-esm/DatePicker/DatePickerAnchor.js +174 -0
- package/lib-esm/DatePicker/DatePickerOverlay.d.ts +3 -0
- package/lib-esm/DatePicker/DatePickerOverlay.js +40 -0
- package/lib-esm/DatePicker/DatePickerPanel.d.ts +2 -0
- package/lib-esm/DatePicker/DatePickerPanel.js +332 -0
- package/lib-esm/DatePicker/Day.d.ts +15 -0
- package/lib-esm/DatePicker/Day.js +182 -0
- package/lib-esm/DatePicker/Month.d.ts +8 -0
- package/lib-esm/DatePicker/Month.js +98 -0
- package/lib-esm/DatePicker/dateParser.d.ts +12 -0
- package/lib-esm/DatePicker/dateParser.js +178 -0
- package/lib-esm/DatePicker/index.d.ts +2 -0
- package/lib-esm/DatePicker/index.js +1 -0
- package/lib-esm/DatePicker/useDatePicker.d.ts +107 -0
- package/lib-esm/DatePicker/useDatePicker.js +523 -0
- package/lib-esm/Dialog.d.ts +4 -4
- package/lib-esm/Dropdown.d.ts +16 -16
- package/lib-esm/DropdownMenu/DropdownButton.d.ts +6 -6
- package/lib-esm/FilterList.d.ts +3 -3
- package/lib-esm/Flash.d.ts +1 -1
- package/lib-esm/Label.d.ts +1 -1
- package/lib-esm/Position.d.ts +4 -4
- package/lib-esm/ProgressBar.d.ts +1 -1
- package/lib-esm/SelectMenu/SelectMenu.d.ts +28 -26
- package/lib-esm/SelectMenu/SelectMenuItem.d.ts +1 -1
- package/lib-esm/SideNav.d.ts +8 -10
- package/lib-esm/SideNav.js +16 -6
- package/lib-esm/TextInputWithTokens.d.ts +8 -10
- package/lib-esm/TextInputWithTokens.js +30 -101
- package/lib-esm/Timeline.d.ts +4 -4
- package/lib-esm/Token/AvatarToken.d.ts +1 -1
- package/lib-esm/Token/IssueLabelToken.d.ts +1 -1
- package/lib-esm/Token/Token.d.ts +1 -1
- package/lib-esm/Token/Token.js +2 -13
- package/lib-esm/Token/TokenBase.js +4 -0
- package/lib-esm/Token/_RemoveTokenButton.js +2 -11
- package/lib-esm/_TextInputWrapper.d.ts +1 -1
- package/lib-esm/_TextInputWrapper.js +1 -1
- package/lib-esm/hooks/useDebounce.d.ts +2 -0
- package/lib-esm/hooks/useDebounce.js +16 -0
- package/lib-esm/hooks/useResizeObserver.d.ts +1 -1
- package/lib-esm/hooks/useResizeObserver.js +1 -1
- package/lib-esm/sx.d.ts +2 -8
- package/lib-esm/theme-preval.js +2 -2
- package/lib-esm/theme.d.ts +0 -78
- package/lib-esm/theme.js +1 -2
- package/lib-esm/utils/testing.d.ts +1 -1
- package/package.json +9 -10
- package/lib/utils/types/KeyPaths.d.ts +0 -3
- package/lib/utils/types/KeyPaths.js +0 -1
- package/lib-esm/utils/types/KeyPaths.d.ts +0 -3
- package/lib-esm/utils/types/KeyPaths.js +0 -1
@@ -0,0 +1,122 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.Month = void 0;
|
7
|
+
|
8
|
+
var _dateFns = require("date-fns");
|
9
|
+
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
11
|
+
|
12
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
13
|
+
|
14
|
+
var _Box = _interopRequireDefault(require("../Box"));
|
15
|
+
|
16
|
+
var _Text = _interopRequireDefault(require("../Text"));
|
17
|
+
|
18
|
+
var _constants = require("../constants");
|
19
|
+
|
20
|
+
var _Day = require("./Day");
|
21
|
+
|
22
|
+
var _useDatePicker = _interopRequireDefault(require("./useDatePicker"));
|
23
|
+
|
24
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
25
|
+
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
27
|
+
|
28
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
29
|
+
|
30
|
+
const weekdayEnum = {
|
31
|
+
Sunday: 0,
|
32
|
+
Monday: 1,
|
33
|
+
Tuesday: 2,
|
34
|
+
Wednesday: 3,
|
35
|
+
Thursday: 4,
|
36
|
+
Friday: 5,
|
37
|
+
Saturday: 6
|
38
|
+
};
|
39
|
+
const MonthComponent = (0, _styledComponents.default)(_Box.default).withConfig({
|
40
|
+
displayName: "Month__MonthComponent",
|
41
|
+
componentId: "l6j7o0-0"
|
42
|
+
})(["display:grid;grid-auto-rows:min-content;grid-template-columns:repeat(1fr,7);grid-template-rows:1fr;gap:0px 0px;grid-template-areas:'month month month month month month month' 'sunday monday tuesday wednesday thursday friday saturday';justify-items:stretch;align-items:stretch;"]);
|
43
|
+
const MonthTitle = (0, _styledComponents.default)(_Text.default).withConfig({
|
44
|
+
displayName: "Month__MonthTitle",
|
45
|
+
componentId: "l6j7o0-1"
|
46
|
+
})(["font-size:", ";font-weight:", ";grid-area:month;height:", ";justify-self:center;"], (0, _constants.get)('fontSizes.1'), (0, _constants.get)('fontWeights.bold'), (0, _constants.get)('space.4'));
|
47
|
+
const WeekdayHeader = (0, _styledComponents.default)(_Text.default).withConfig({
|
48
|
+
displayName: "Month__WeekdayHeader",
|
49
|
+
componentId: "l6j7o0-2"
|
50
|
+
})(["color:", ";font-family:", ";font-size:", ";justify-self:center;padding:", " 0 ", ";"], (0, _constants.get)('colors.fg.subtle'), (0, _constants.get)('fonts.mono'), (0, _constants.get)('fontSizes.0'), (0, _constants.get)('space.3'), (0, _constants.get)('space.2'));
|
51
|
+
|
52
|
+
const Month = ({
|
53
|
+
date
|
54
|
+
}) => {
|
55
|
+
const {
|
56
|
+
configuration
|
57
|
+
} = (0, _useDatePicker.default)();
|
58
|
+
const [selectedDay, setSelectedDay] = (0, _react.useState)(null);
|
59
|
+
const getTitle = (0, _react.useMemo)(() => `${(0, _dateFns.format)(new Date(date), 'MMMM yyyy')}`, [date]);
|
60
|
+
const weekdayHeaders = (0, _react.useMemo)(() => {
|
61
|
+
var _configuration$weekSt;
|
62
|
+
|
63
|
+
const now = new Date(date);
|
64
|
+
const weekOptions = {
|
65
|
+
weekStartsOn: weekdayEnum[(_configuration$weekSt = configuration.weekStartsOn) !== null && _configuration$weekSt !== void 0 ? _configuration$weekSt : 'Sunday']
|
66
|
+
};
|
67
|
+
return (0, _dateFns.eachDayOfInterval)({
|
68
|
+
start: (0, _dateFns.startOfWeek)(now, weekOptions),
|
69
|
+
end: (0, _dateFns.endOfWeek)(now, weekOptions)
|
70
|
+
}).map(d => /*#__PURE__*/_react.default.createElement(WeekdayHeader, {
|
71
|
+
key: `weekday-${d}-header`
|
72
|
+
}, (0, _dateFns.format)(d, 'EEEEEE')));
|
73
|
+
}, [configuration.weekStartsOn, date]);
|
74
|
+
|
75
|
+
const dayAction = day => {
|
76
|
+
setSelectedDay(day);
|
77
|
+
};
|
78
|
+
|
79
|
+
const dayComponents = (0, _react.useMemo)(() => {
|
80
|
+
var _configuration$weekSt2, _configuration$weekSt3;
|
81
|
+
|
82
|
+
const components = [];
|
83
|
+
const firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
|
84
|
+
const preBlanks = (firstDay.getDay() + (7 - weekdayEnum[(_configuration$weekSt2 = configuration.weekStartsOn) !== null && _configuration$weekSt2 !== void 0 ? _configuration$weekSt2 : 'Sunday'])) % 7;
|
85
|
+
|
86
|
+
for (let i = 0; i < preBlanks; i++) {
|
87
|
+
components.push( /*#__PURE__*/_react.default.createElement(_Day.BlankDay, {
|
88
|
+
key: `month-pre-blank-${i}`
|
89
|
+
}));
|
90
|
+
}
|
91
|
+
|
92
|
+
for (let i = 1; i <= (0, _dateFns.getDaysInMonth)(firstDay); i++) {
|
93
|
+
const day = new Date(date.getFullYear(), date.getMonth(), i);
|
94
|
+
components.push( /*#__PURE__*/_react.default.createElement(_Day.Day, {
|
95
|
+
key: `day-component-${day.toString()}`,
|
96
|
+
date: day,
|
97
|
+
selected: selectedDay ? (0, _dateFns.isEqual)(day, selectedDay) : false,
|
98
|
+
onAction: dayAction
|
99
|
+
}));
|
100
|
+
}
|
101
|
+
|
102
|
+
const lastDay = (0, _dateFns.lastDayOfMonth)(firstDay);
|
103
|
+
const postBlanks = (lastDay.getDay() + (7 - weekdayEnum[(_configuration$weekSt3 = configuration.weekStartsOn) !== null && _configuration$weekSt3 !== void 0 ? _configuration$weekSt3 : 'Sunday'])) % 7;
|
104
|
+
|
105
|
+
for (let i = 6; i > postBlanks; i--) {
|
106
|
+
components.push( /*#__PURE__*/_react.default.createElement(_Day.BlankDay, {
|
107
|
+
key: `month-post-blank-${i}`
|
108
|
+
}));
|
109
|
+
}
|
110
|
+
|
111
|
+
return components;
|
112
|
+
}, [configuration.weekStartsOn, date, selectedDay]);
|
113
|
+
return /*#__PURE__*/_react.default.createElement(MonthComponent, {
|
114
|
+
role: "grid",
|
115
|
+
"aria-labelledby": `${date.getMonth()} ${date.getFullYear()}`
|
116
|
+
}, /*#__PURE__*/_react.default.createElement(MonthTitle, {
|
117
|
+
"aria-live": "polite"
|
118
|
+
}, !configuration.compressedHeader ? getTitle : ''), weekdayHeaders, dayComponents);
|
119
|
+
};
|
120
|
+
|
121
|
+
exports.Month = Month;
|
122
|
+
Month.displayName = "Month";
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { AnchorVariant, Selection, SelectionVariant } from './useDatePicker';
|
2
|
+
export declare const parseDate: (dateString: string, variant?: SelectionVariant) => Selection;
|
3
|
+
declare type FormatDateOptions = {
|
4
|
+
selection?: Selection;
|
5
|
+
anchorVariant?: AnchorVariant;
|
6
|
+
dateFormat?: string;
|
7
|
+
placeholder?: string;
|
8
|
+
rawFormat?: boolean;
|
9
|
+
variant?: SelectionVariant;
|
10
|
+
};
|
11
|
+
export declare const formatDate: ({ selection, dateFormat, placeholder, rawFormat, variant }: FormatDateOptions) => string;
|
12
|
+
export {};
|
@@ -0,0 +1,192 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.formatDate = exports.parseDate = void 0;
|
7
|
+
|
8
|
+
var _dateFns = require("date-fns");
|
9
|
+
|
10
|
+
var _useDatePicker = require("./useDatePicker");
|
11
|
+
|
12
|
+
const INVALID_DATE = 'Invalid Date';
|
13
|
+
const DATE_REGEX = new RegExp(/(\d{1,2}[-/.]\d{1,2}[-/.](?:\d{2}){1,2})(?:\s?-\s?)?(\d{1,2}[-/.]\d{1,2}[-/.](?:\d{2}){1,2})?/g);
|
14
|
+
|
15
|
+
const sanitizeDate = dateString => {
|
16
|
+
return dateString.replaceAll('.', '/').replaceAll('-', '/');
|
17
|
+
};
|
18
|
+
|
19
|
+
const parseDate = (dateString, variant = 'single') => {
|
20
|
+
const dateItems = dateString.matchAll(DATE_REGEX);
|
21
|
+
const parsedDateItems = []; // Determine Format
|
22
|
+
|
23
|
+
for (const d of dateItems) {
|
24
|
+
const tempD1 = new Date(sanitizeDate(d[1]));
|
25
|
+
const tempD2 = d[2] ? new Date(sanitizeDate(d[2])) : null;
|
26
|
+
|
27
|
+
if (tempD2) {
|
28
|
+
// Range
|
29
|
+
if (tempD1.toString() !== INVALID_DATE && tempD2.toString() !== INVALID_DATE) {
|
30
|
+
parsedDateItems.push((0, _dateFns.isBefore)(tempD1, tempD2) ? {
|
31
|
+
from: tempD1,
|
32
|
+
to: tempD2
|
33
|
+
} : {
|
34
|
+
from: tempD2,
|
35
|
+
to: tempD1
|
36
|
+
});
|
37
|
+
} else if (tempD1.toString() !== INVALID_DATE) {
|
38
|
+
parsedDateItems.push(tempD1);
|
39
|
+
} else if (tempD2.toString() !== INVALID_DATE) {
|
40
|
+
parsedDateItems.push(tempD2);
|
41
|
+
}
|
42
|
+
} else {
|
43
|
+
if (tempD1.toString() !== INVALID_DATE) {
|
44
|
+
parsedDateItems.push(tempD1);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
if (parsedDateItems.length === 0) {
|
50
|
+
// No Valid Dates
|
51
|
+
return null;
|
52
|
+
} // Cast Format based on variant
|
53
|
+
|
54
|
+
|
55
|
+
switch (variant) {
|
56
|
+
case 'single':
|
57
|
+
{
|
58
|
+
return parsedDateItems[0];
|
59
|
+
}
|
60
|
+
|
61
|
+
case 'multi':
|
62
|
+
{
|
63
|
+
const expandedParsedItems = [];
|
64
|
+
|
65
|
+
for (const item of parsedDateItems) {
|
66
|
+
if ((0, _useDatePicker.isRangeSelection)(item)) {
|
67
|
+
if (item.to) {
|
68
|
+
(0, _dateFns.eachDayOfInterval)({
|
69
|
+
start: item.from,
|
70
|
+
end: item.to
|
71
|
+
}).map(d => expandedParsedItems.push(d));
|
72
|
+
} else {
|
73
|
+
expandedParsedItems.push(item.from);
|
74
|
+
}
|
75
|
+
} else {
|
76
|
+
if (item) {
|
77
|
+
if (Array.isArray(item)) {
|
78
|
+
item.map(d => expandedParsedItems.push(d));
|
79
|
+
} else {
|
80
|
+
expandedParsedItems.push(item);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
return expandedParsedItems;
|
87
|
+
}
|
88
|
+
|
89
|
+
case 'range':
|
90
|
+
{
|
91
|
+
return parsedDateItems.filter(d => (0, _useDatePicker.isRangeSelection)(d))[0];
|
92
|
+
}
|
93
|
+
|
94
|
+
default:
|
95
|
+
{
|
96
|
+
return parsedDateItems[0];
|
97
|
+
}
|
98
|
+
}
|
99
|
+
};
|
100
|
+
|
101
|
+
exports.parseDate = parseDate;
|
102
|
+
|
103
|
+
const formatDate = ({
|
104
|
+
selection,
|
105
|
+
dateFormat = 'short',
|
106
|
+
placeholder = 'Choose Date',
|
107
|
+
rawFormat = false,
|
108
|
+
variant = 'single'
|
109
|
+
}) => {
|
110
|
+
if (!selection) {
|
111
|
+
if (rawFormat) return '';
|
112
|
+
return placeholder;
|
113
|
+
}
|
114
|
+
|
115
|
+
let template = 'MMM d';
|
116
|
+
|
117
|
+
if (!rawFormat && dateFormat) {
|
118
|
+
switch (dateFormat) {
|
119
|
+
case 'short':
|
120
|
+
template = 'MMM d';
|
121
|
+
break;
|
122
|
+
|
123
|
+
case 'long':
|
124
|
+
template = 'MMM d, yyyy';
|
125
|
+
break;
|
126
|
+
|
127
|
+
default:
|
128
|
+
template = dateFormat;
|
129
|
+
break;
|
130
|
+
}
|
131
|
+
} else {
|
132
|
+
template = 'MM/dd/yyyy';
|
133
|
+
}
|
134
|
+
|
135
|
+
switch (variant) {
|
136
|
+
case 'single':
|
137
|
+
{
|
138
|
+
if (selection instanceof Date) {
|
139
|
+
return (0, _dateFns.format)(selection, template);
|
140
|
+
} else if (Array.isArray(selection)) {
|
141
|
+
return (0, _dateFns.format)(selection[0], template);
|
142
|
+
} else if ((0, _useDatePicker.isRangeSelection)(selection)) {
|
143
|
+
return (0, _dateFns.format)(selection.from, template);
|
144
|
+
} else {
|
145
|
+
return 'Invalid Selection';
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
case 'multi':
|
150
|
+
{
|
151
|
+
if (Array.isArray(selection)) {
|
152
|
+
if (selection.length > 3 && !rawFormat) return `${selection.length} Selected`;
|
153
|
+
const formatted = selection.map(d => (0, _dateFns.format)(d, template)).join(', ');
|
154
|
+
return formatted;
|
155
|
+
} else if (selection instanceof Date) {
|
156
|
+
return [selection].map(d => (0, _dateFns.format)(d, template)).join(', ');
|
157
|
+
} else if ((0, _useDatePicker.isRangeSelection)(selection)) {
|
158
|
+
return [selection.to, selection.from].map(d => d ? (0, _dateFns.format)(d, template) : '').join(', ');
|
159
|
+
} else {
|
160
|
+
return 'Invalid Selection';
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
case 'range':
|
165
|
+
{
|
166
|
+
if ((0, _useDatePicker.isRangeSelection)(selection)) {
|
167
|
+
return Object.entries(selection).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
168
|
+
} else if (selection instanceof Date) {
|
169
|
+
return Object.entries({
|
170
|
+
from: selection,
|
171
|
+
to: null
|
172
|
+
}).map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
173
|
+
} else if (Array.isArray(selection)) {
|
174
|
+
return Object.entries({
|
175
|
+
from: selection[0],
|
176
|
+
to: selection[1]
|
177
|
+
}) // to date can still be null
|
178
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
179
|
+
.map(([_, date]) => date ? (0, _dateFns.format)(date, template) : '').join(' - ');
|
180
|
+
} else {
|
181
|
+
return 'Invalid Selection';
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
default:
|
186
|
+
{
|
187
|
+
return 'Invalid Configuration';
|
188
|
+
}
|
189
|
+
}
|
190
|
+
};
|
191
|
+
|
192
|
+
exports.formatDate = formatDate;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "DatePicker", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _DatePicker.DatePicker;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
|
13
|
+
var _DatePicker = require("./DatePicker");
|
@@ -0,0 +1,107 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
export declare type AnchorVariant = 'input' | 'button' | 'icon-only';
|
3
|
+
export declare type DateFormat = 'short' | 'long' | string;
|
4
|
+
export declare type SelectionVariant = 'single' | 'multi' | 'range';
|
5
|
+
export interface DatePickerConfiguration {
|
6
|
+
anchorVariant?: AnchorVariant;
|
7
|
+
blockedDates?: Array<Date>;
|
8
|
+
confirmation?: boolean;
|
9
|
+
confirmUnsavedClose?: boolean;
|
10
|
+
compressedHeader?: boolean;
|
11
|
+
dateFormat?: DateFormat;
|
12
|
+
disableWeekends?: boolean;
|
13
|
+
iconPlacement?: 'start' | 'end' | 'none';
|
14
|
+
maxDate?: Date | null;
|
15
|
+
maxSelections?: number;
|
16
|
+
maxRangeSize?: number;
|
17
|
+
minDate?: Date | null;
|
18
|
+
placeholder?: string;
|
19
|
+
rangeIncrement?: number;
|
20
|
+
showInputPrompt?: boolean;
|
21
|
+
variant?: SelectionVariant;
|
22
|
+
view?: '1-month' | '2-month';
|
23
|
+
weekStartsOn?: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
24
|
+
}
|
25
|
+
export declare type RangeSelection = {
|
26
|
+
from: Date;
|
27
|
+
to: Date | null;
|
28
|
+
};
|
29
|
+
export declare type StringRangeSelection = {
|
30
|
+
from: string;
|
31
|
+
to: string;
|
32
|
+
};
|
33
|
+
export interface DatePickerContext {
|
34
|
+
disabled?: boolean;
|
35
|
+
configuration: DatePickerConfiguration;
|
36
|
+
currentViewingDate: Date;
|
37
|
+
dialogOpen: boolean;
|
38
|
+
focusDate: Date;
|
39
|
+
formattedDate: string;
|
40
|
+
goToMonth: (date: Date) => void;
|
41
|
+
inputDate: string;
|
42
|
+
hoverRange?: RangeSelection | null;
|
43
|
+
nextMonth: () => void;
|
44
|
+
onClose: () => void;
|
45
|
+
onDateInput: (updatedSelection: Selection) => void;
|
46
|
+
onDayFocus: (date: Date) => void;
|
47
|
+
onSelection: (date: Date) => void;
|
48
|
+
previousMonth: () => void;
|
49
|
+
revertValue: () => void;
|
50
|
+
saveValue: (selection?: Selection) => void;
|
51
|
+
selection?: Selection;
|
52
|
+
selectionActive?: boolean;
|
53
|
+
setFocusDate: React.Dispatch<React.SetStateAction<Date>>;
|
54
|
+
setHoverRange: React.Dispatch<React.SetStateAction<RangeSelection | null>>;
|
55
|
+
softSelection?: Partial<RangeSelection> | null;
|
56
|
+
setDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
57
|
+
viewMode: '1-month' | '2-month';
|
58
|
+
}
|
59
|
+
export declare type Selection = Date | Array<Date> | RangeSelection | null;
|
60
|
+
export declare type StringSelection = string | Array<string> | {
|
61
|
+
to: string;
|
62
|
+
from: string;
|
63
|
+
} | null;
|
64
|
+
export declare type DaySelection = boolean | 'start' | 'middle' | 'end';
|
65
|
+
declare const useDatePicker: (date?: Date | undefined) => {
|
66
|
+
blocked: boolean | undefined;
|
67
|
+
disabled: boolean;
|
68
|
+
focused: boolean;
|
69
|
+
selected: DaySelection;
|
70
|
+
today: boolean;
|
71
|
+
configuration: DatePickerConfiguration;
|
72
|
+
currentViewingDate: Date;
|
73
|
+
dialogOpen: boolean;
|
74
|
+
focusDate: Date;
|
75
|
+
formattedDate: string;
|
76
|
+
goToMonth: (date: Date) => void;
|
77
|
+
inputDate: string;
|
78
|
+
hoverRange?: RangeSelection | null | undefined;
|
79
|
+
nextMonth: () => void;
|
80
|
+
onClose: () => void;
|
81
|
+
onDateInput: (updatedSelection: Selection) => void;
|
82
|
+
onDayFocus: (date: Date) => void;
|
83
|
+
onSelection: (date: Date) => void;
|
84
|
+
previousMonth: () => void;
|
85
|
+
revertValue: () => void;
|
86
|
+
saveValue: (selection?: Selection | undefined) => void;
|
87
|
+
selection?: Selection | undefined;
|
88
|
+
selectionActive?: boolean | undefined;
|
89
|
+
setFocusDate: React.Dispatch<React.SetStateAction<Date>>;
|
90
|
+
setHoverRange: React.Dispatch<React.SetStateAction<RangeSelection | null>>;
|
91
|
+
softSelection?: Partial<RangeSelection> | null | undefined;
|
92
|
+
setDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
93
|
+
viewMode: '1-month' | '2-month';
|
94
|
+
};
|
95
|
+
export default useDatePicker;
|
96
|
+
export interface DatePickerProviderProps {
|
97
|
+
closePicker?: () => void;
|
98
|
+
configuration?: DatePickerConfiguration;
|
99
|
+
isOpen?: boolean;
|
100
|
+
value?: Selection | StringSelection;
|
101
|
+
}
|
102
|
+
export declare function isSingleSelection(selection: Selection): selection is Date;
|
103
|
+
export declare function isMultiSelection(selection: Selection | StringSelection): selection is Array<Date> | Array<string>;
|
104
|
+
export declare function isRangeSelection(selection: Selection | StringSelection): selection is RangeSelection | StringRangeSelection;
|
105
|
+
export declare function isStringRangeSelection(selection: StringSelection): selection is StringRangeSelection;
|
106
|
+
export declare const normalizeDate: (date: Date | string) => Date;
|
107
|
+
export declare const DatePickerProvider: React.FC<DatePickerProviderProps>;
|