@cloudscape-design/components 3.0.11 → 3.0.14
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/date-picker/calendar/index.d.ts +1 -1
- package/date-picker/calendar/index.d.ts.map +1 -1
- package/date-picker/calendar/index.js +16 -29
- package/date-picker/calendar/index.js.map +1 -1
- package/date-picker/embedded.d.ts +3 -0
- package/date-picker/embedded.d.ts.map +1 -0
- package/date-picker/embedded.js +15 -0
- package/date-picker/embedded.js.map +1 -0
- package/date-picker/index.d.ts.map +1 -1
- package/date-picker/index.js +15 -40
- package/date-picker/index.js.map +1 -1
- package/date-picker/interfaces.d.ts +12 -10
- package/date-picker/interfaces.d.ts.map +1 -1
- package/date-picker/interfaces.js.map +1 -1
- package/date-picker/use-date-picker.d.ts +17 -0
- package/date-picker/use-date-picker.d.ts.map +1 -0
- package/date-picker/use-date-picker.js +48 -0
- package/date-picker/use-date-picker.js.map +1 -0
- package/internal/components/focus-lock/index.d.ts +2 -1
- package/internal/components/focus-lock/index.d.ts.map +1 -1
- package/internal/components/focus-lock/index.js +7 -2
- package/internal/components/focus-lock/index.js.map +1 -1
- package/internal/components/focus-lock/utils.d.ts +3 -3
- package/internal/components/focus-lock/utils.d.ts.map +1 -1
- package/internal/components/focus-lock/utils.js +3 -1
- package/internal/components/focus-lock/utils.js.map +1 -1
- package/internal/environment.js +1 -1
- package/link/internal.d.ts.map +1 -1
- package/link/internal.js +2 -7
- package/link/internal.js.map +1 -1
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ export interface MonthChangeHandler {
|
|
|
10
10
|
export declare type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
11
11
|
interface CalendarProps extends BaseComponentProps {
|
|
12
12
|
locale: string;
|
|
13
|
-
startOfWeek:
|
|
13
|
+
startOfWeek: number | undefined;
|
|
14
14
|
selectedDate: Date | null;
|
|
15
15
|
displayedDate: Date;
|
|
16
16
|
isDateEnabled: DatePickerProps.IsDateEnabledFunction;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/date-picker/calendar/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/date-picker/calendar/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAS9C,MAAM,WAAW,iBAAiB;IAChC,CAAC,MAAM,EAAE,aAAa,CAAC,UAAU,GAAG,IAAI,CAAC;CAC1C;AAED,MAAM,WAAW,kBAAkB;IACjC,CAAC,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;CACxB;AAED,oBAAY,QAAQ,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAMjD,UAAU,aAAc,SAAQ,kBAAkB;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,YAAY,EAAE,IAAI,GAAG,IAAI,CAAC;IAC1B,aAAa,EAAE,IAAI,CAAC;IACpB,aAAa,EAAE,eAAe,CAAC,qBAAqB,CAAC;IACrD,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,cAAc,EAAE,MAAM,CAAC;IAEvB,aAAa,EAAE,kBAAkB,CAAC;IAClC,YAAY,EAAE,iBAAiB,CAAC;CACjC;AAED,QAAA,MAAM,QAAQ,0JAWX,aAAa,gBA4Gf,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { __assign } from "tslib";
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import React, {
|
|
4
|
+
import React, { useRef, useState } from 'react';
|
|
5
5
|
import { addDays, addMonths, isSameMonth, startOfMonth } from 'date-fns';
|
|
6
6
|
import styles from '../styles.css.js';
|
|
7
7
|
import useFocusVisible from '../../internal/hooks/focus-visible/index.js';
|
|
@@ -10,15 +10,16 @@ import Grid from './grid';
|
|
|
10
10
|
import moveFocusHandler from './utils/move-focus-handler';
|
|
11
11
|
import { useUniqueId } from '../../internal/hooks/use-unique-id/index.js';
|
|
12
12
|
import { formatDate, memoizedDate } from './utils/date.js';
|
|
13
|
+
import { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';
|
|
14
|
+
import { getWeekStartByLocale } from 'weekstart';
|
|
13
15
|
var Calendar = function (_a) {
|
|
14
16
|
var locale = _a.locale, startOfWeek = _a.startOfWeek, displayedDate = _a.displayedDate, todayAriaLabel = _a.todayAriaLabel, selectedDate = _a.selectedDate, isDateEnabled = _a.isDateEnabled, onChangeMonth = _a.onChangeMonth, onSelectDate = _a.onSelectDate, previousMonthLabel = _a.previousMonthLabel, nextMonthLabel = _a.nextMonthLabel;
|
|
17
|
+
var normalizedStartOfWeek = (typeof startOfWeek === 'number' ? startOfWeek : getWeekStartByLocale(locale));
|
|
15
18
|
var focusVisible = useFocusVisible();
|
|
16
19
|
var headerId = useUniqueId('calendar-dialog-title-');
|
|
17
20
|
var elementRef = useRef(null);
|
|
18
21
|
var gridWrapperRef = useRef(null);
|
|
19
|
-
var _b = useState(
|
|
20
|
-
var _c = useState(null), focusedDate = _c[0], setFocusedDate = _c[1];
|
|
21
|
-
var focusedDateMemoized = memoizedDate('focused', focusedDate);
|
|
22
|
+
var _b = useState(null), focusedDate = _b[0], setFocusedDate = _b[1];
|
|
22
23
|
var selectFocusedDate = function (selected, baseDate) {
|
|
23
24
|
if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {
|
|
24
25
|
return selected;
|
|
@@ -40,7 +41,7 @@ var Calendar = function (_a) {
|
|
|
40
41
|
return moveFocusHandler(startDate, isDateEnabled, function (date) { return addDays(date, 1); });
|
|
41
42
|
};
|
|
42
43
|
var baseDate = getBaseDate(displayedDate);
|
|
43
|
-
var
|
|
44
|
+
var focusedOrSelectedDate = focusedDate || selectFocusedDate(selectedDate, baseDate);
|
|
44
45
|
var onHeaderChangeMonthHandler = function (isPrevious) {
|
|
45
46
|
onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));
|
|
46
47
|
setFocusedDate(null);
|
|
@@ -52,7 +53,7 @@ var Calendar = function (_a) {
|
|
|
52
53
|
var onGridFocusDateHandler = function (_a) {
|
|
53
54
|
var date = _a.date;
|
|
54
55
|
if (date) {
|
|
55
|
-
var value = formatDate(date);
|
|
56
|
+
var value = memoizedDate('focused', formatDate(date));
|
|
56
57
|
setFocusedDate(value);
|
|
57
58
|
}
|
|
58
59
|
};
|
|
@@ -60,40 +61,26 @@ var Calendar = function (_a) {
|
|
|
60
61
|
onSelectDate(detail);
|
|
61
62
|
setFocusedDate(null);
|
|
62
63
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
focusCurrentDate();
|
|
67
|
-
}
|
|
68
|
-
}, [baseDate, focusedDateMemoized, gridHasFocus]);
|
|
69
|
-
useEffect(function () {
|
|
64
|
+
// The focused date changes as a feedback to keyboard navigation in the grid.
|
|
65
|
+
// Once changed, the corresponding day button needs to receive the actual focus.
|
|
66
|
+
useEffectOnUpdate(function () {
|
|
70
67
|
var _a, _b;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
(_b = elementRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
68
|
+
if (focusedDate) {
|
|
69
|
+
(_b = (_a = elementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector(".".concat(styles['calendar-day-focusable']))) === null || _b === void 0 ? void 0 : _b.focus();
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
}, [baseDate, isDateEnabled]);
|
|
77
|
-
if (!focusedDate) {
|
|
78
|
-
focusedDateMemoized = selectFocusedDate(selectedDate, baseDate);
|
|
79
|
-
}
|
|
71
|
+
}, [focusedDate]);
|
|
80
72
|
var onGridBlur = function (event) {
|
|
81
73
|
var _a;
|
|
82
74
|
var newFocusTargetIsInGrid = event.relatedTarget && ((_a = gridWrapperRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.relatedTarget));
|
|
83
75
|
if (!newFocusTargetIsInGrid) {
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
};
|
|
87
|
-
var onGridFocus = function () {
|
|
88
|
-
if (!gridHasFocus) {
|
|
89
|
-
setGridHasFocus(true);
|
|
76
|
+
setFocusedDate(null);
|
|
90
77
|
}
|
|
91
78
|
};
|
|
92
79
|
return (React.createElement("div", __assign({}, focusVisible, { className: styles.calendar, tabIndex: 0, role: "application", "aria-describedby": headerId, ref: elementRef }),
|
|
93
80
|
React.createElement("div", { className: styles['calendar-inner'] },
|
|
94
81
|
React.createElement(CalendarHeader, { headerId: headerId, baseDate: baseDate, locale: locale, onChangeMonth: onHeaderChangeMonthHandler, previousMonthLabel: previousMonthLabel, nextMonthLabel: nextMonthLabel }),
|
|
95
|
-
React.createElement("div", { onBlur: onGridBlur,
|
|
96
|
-
React.createElement(Grid, { locale: locale, baseDate: baseDate, isDateEnabled: isDateEnabled, focusedDate:
|
|
82
|
+
React.createElement("div", { onBlur: onGridBlur, ref: gridWrapperRef },
|
|
83
|
+
React.createElement(Grid, { locale: locale, baseDate: baseDate, isDateEnabled: isDateEnabled, focusedDate: focusedOrSelectedDate, onSelectDate: onGridSelectDateHandler, onFocusDate: onGridFocusDateHandler, onChangeMonth: onGridChangeMonthHandler, startOfWeek: normalizedStartOfWeek, todayAriaLabel: todayAriaLabel, selectedDate: selectedDate, handleFocusMove: moveFocusHandler })))));
|
|
97
84
|
};
|
|
98
85
|
export default Calendar;
|
|
99
86
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
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AAc,CAAC,OAAO,0CAAE,QAAQ,CAAC,KAAK,CAAC,aAAqB,CAAC,CAAA,CAAC;QACpH,IAAI,CAAC,sBAAsB,EAAE;YAC3B,eAAe,CAAC,KAAK,CAAC,CAAC;SACxB;IACH,CAAC,CAAC;IAEF,IAAM,WAAW,GAAG;QAClB,IAAI,CAAC,YAAY,EAAE;YACjB,eAAe,CAAC,IAAI,CAAC,CAAC;SACvB;IACH,CAAC,CAAC;IAEF,OAAO,CACL,wCACM,YAAY,IAChB,SAAS,EAAE,MAAM,CAAC,QAAQ,EAC1B,QAAQ,EAAE,CAAC,EACX,IAAI,EAAC,aAAa,sBACA,QAAQ,EAC1B,GAAG,EAAE,UAAU;QAEf,6BAAK,SAAS,EAAE,MAAM,CAAC,gBAAgB,CAAC;YACtC,oBAAC,cAAc,IACb,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,0BAA0B,EACzC,kBAAkB,EAAE,kBAAkB,EACtC,cAAc,EAAE,cAAc,GAC9B;YACF,6BAAK,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,cAAc;gBAChE,oBAAC,IAAI,IACH,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,mBAAmB,EAChC,YAAY,EAAE,uBAAuB,EACrC,WAAW,EAAE,sBAAsB,EACnC,aAAa,EAAE,wBAAwB,EACvC,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,YAAY,EAC1B,eAAe,EAAE,gBAAgB,GACjC,CACE,CACF,CACF,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,QAAQ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef, useState } from 'react';\nimport { addDays, addMonths, isSameMonth, startOfMonth } from 'date-fns';\nimport styles from '../styles.css.js';\nimport { FocusNextElement } from '../../internal/components/tab-trap';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport useFocusVisible from '../../internal/hooks/focus-visible/index.js';\nimport { DatePickerProps } from '../interfaces';\nimport { CalendarTypes } from './definitions';\nimport CalendarHeader from './header';\nimport Grid, { DateChangeHandlerNullable } from './grid';\nimport moveFocusHandler from './utils/move-focus-handler';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id/index.js';\nimport { formatDate, memoizedDate } from './utils/date.js';\n\nexport interface DateChangeHandler {\n (detail: CalendarTypes.DateDetail): void;\n}\n\nexport interface MonthChangeHandler {\n (newMonth: Date): void;\n}\n\nexport type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface HeaderChangeMonthHandler {\n (isPreviousButtonClick?: boolean): void;\n}\n\ninterface CalendarProps extends BaseComponentProps {\n locale: string;\n startOfWeek: DayIndex;\n selectedDate: Date | null;\n displayedDate: Date;\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n nextMonthLabel: string;\n previousMonthLabel: string;\n todayAriaLabel: string;\n\n onChangeMonth: MonthChangeHandler;\n onSelectDate: DateChangeHandler;\n}\n\nconst Calendar = ({\n locale,\n startOfWeek,\n displayedDate,\n todayAriaLabel,\n selectedDate,\n isDateEnabled,\n onChangeMonth,\n onSelectDate,\n previousMonthLabel,\n nextMonthLabel,\n}: CalendarProps) => {\n const focusVisible = useFocusVisible();\n const headerId = useUniqueId('calendar-dialog-title-');\n const elementRef = useRef<HTMLDivElement>(null);\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [gridHasFocus, setGridHasFocus] = useState(false);\n const [focusedDate, setFocusedDate] = useState<string | null>(null);\n let focusedDateMemoized: null | Date = memoizedDate('focused', focusedDate);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateEnabled(today) && isSameMonth(today, baseDate)) {\n return today;\n }\n if (isDateEnabled(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const getBaseDate = (date: Date) => {\n const startDate = startOfMonth(date);\n if (isDateEnabled(startDate)) {\n return startDate;\n }\n return moveFocusHandler(startDate, isDateEnabled, (date: Date) => addDays(date, 1));\n };\n\n const baseDate: Date = getBaseDate(displayedDate);\n\n const focusCurrentDate: FocusNextElement = () =>\n (elementRef.current?.querySelector(`.${styles['calendar-day-focusable']}`) as HTMLDivElement)?.focus();\n\n const onHeaderChangeMonthHandler: HeaderChangeMonthHandler = isPrevious => {\n onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));\n setFocusedDate(null);\n };\n\n const onGridChangeMonthHandler: MonthChangeHandler = newMonth => {\n onChangeMonth(newMonth);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler: DateChangeHandlerNullable = ({ date }) => {\n if (date) {\n const value = formatDate(date);\n setFocusedDate(value);\n }\n };\n\n const onGridSelectDateHandler: DateChangeHandler = detail => {\n onSelectDate(detail);\n setFocusedDate(null);\n };\n\n useEffect(() => {\n // focus current date if the focus is already inside the calendar grid\n if (focusedDateMemoized instanceof Date && isSameMonth(focusedDateMemoized, baseDate) && gridHasFocus) {\n focusCurrentDate();\n }\n }, [baseDate, focusedDateMemoized, gridHasFocus]);\n\n useEffect(() => {\n const calendarHasFocus = elementRef.current?.contains(document.activeElement);\n\n if (!calendarHasFocus) {\n elementRef.current?.focus();\n }\n\n // When the baseDate or isDateEnabled changes, there might not be a focusable date in the grid anymore\n }, [baseDate, isDateEnabled]);\n\n if (!focusedDate) {\n focusedDateMemoized = selectFocusedDate(selectedDate, baseDate);\n }\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setGridHasFocus(false);\n }\n };\n\n const onGridFocus = () => {\n if (!gridHasFocus) {\n setGridHasFocus(true);\n }\n };\n\n return (\n <div\n {...focusVisible}\n className={styles.calendar}\n tabIndex={0}\n role=\"application\"\n aria-describedby={headerId}\n ref={elementRef}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n headerId={headerId}\n baseDate={baseDate}\n locale={locale}\n onChangeMonth={onHeaderChangeMonthHandler}\n previousMonthLabel={previousMonthLabel}\n nextMonthLabel={nextMonthLabel}\n />\n <div onBlur={onGridBlur} onFocus={onGridFocus} ref={gridWrapperRef}>\n <Grid\n locale={locale}\n baseDate={baseDate}\n isDateEnabled={isDateEnabled}\n focusedDate={focusedDateMemoized}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangeMonth={onGridChangeMonthHandler}\n startOfWeek={startOfWeek}\n todayAriaLabel={todayAriaLabel}\n selectedDate={selectedDate}\n handleFocusMove={moveFocusHandler}\n />\n </div>\n </div>\n </div>\n );\n};\n\nexport default Calendar;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/date-picker/calendar/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACzE,OAAO,MAAM,MAAM,kBAAkB,CAAC;AAEtC,OAAO,eAAe,MAAM,6CAA6C,CAAC;AAG1E,OAAO,cAAc,MAAM,UAAU,CAAC;AACtC,OAAO,IAAmC,MAAM,QAAQ,CAAC;AACzD,OAAO,gBAAgB,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,6CAA6C,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,M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C","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useRef, useState } from 'react';\nimport { addDays, addMonths, isSameMonth, startOfMonth } from 'date-fns';\nimport styles from '../styles.css.js';\nimport { BaseComponentProps } from '../../internal/base-component';\nimport useFocusVisible from '../../internal/hooks/focus-visible/index.js';\nimport { DatePickerProps } from '../interfaces';\nimport { CalendarTypes } from './definitions';\nimport CalendarHeader from './header';\nimport Grid, { DateChangeHandlerNullable } from './grid';\nimport moveFocusHandler from './utils/move-focus-handler';\nimport { useUniqueId } from '../../internal/hooks/use-unique-id/index.js';\nimport { formatDate, memoizedDate } from './utils/date.js';\nimport { useEffectOnUpdate } from '../../internal/hooks/use-effect-on-update.js';\nimport { getWeekStartByLocale } from 'weekstart';\n\nexport interface DateChangeHandler {\n (detail: CalendarTypes.DateDetail): void;\n}\n\nexport interface MonthChangeHandler {\n (newMonth: Date): void;\n}\n\nexport type DayIndex = 0 | 1 | 2 | 3 | 4 | 5 | 6;\n\ninterface HeaderChangeMonthHandler {\n (isPreviousButtonClick?: boolean): void;\n}\n\ninterface CalendarProps extends BaseComponentProps {\n locale: string;\n startOfWeek: number | undefined;\n selectedDate: Date | null;\n displayedDate: Date;\n isDateEnabled: DatePickerProps.IsDateEnabledFunction;\n nextMonthLabel: string;\n previousMonthLabel: string;\n todayAriaLabel: string;\n\n onChangeMonth: MonthChangeHandler;\n onSelectDate: DateChangeHandler;\n}\n\nconst Calendar = ({\n locale,\n startOfWeek,\n displayedDate,\n todayAriaLabel,\n selectedDate,\n isDateEnabled,\n onChangeMonth,\n onSelectDate,\n previousMonthLabel,\n nextMonthLabel,\n}: CalendarProps) => {\n const normalizedStartOfWeek = (\n typeof startOfWeek === 'number' ? startOfWeek : getWeekStartByLocale(locale)\n ) as DayIndex;\n const focusVisible = useFocusVisible();\n const headerId = useUniqueId('calendar-dialog-title-');\n const elementRef = useRef<HTMLDivElement>(null);\n const gridWrapperRef = useRef<HTMLDivElement>(null);\n const [focusedDate, setFocusedDate] = useState<Date | null>(null);\n\n const selectFocusedDate = (selected: Date | null, baseDate: Date): Date | null => {\n if (selected && isDateEnabled(selected) && isSameMonth(selected, baseDate)) {\n return selected;\n }\n const today = new Date();\n if (isDateEnabled(today) && isSameMonth(today, baseDate)) {\n return today;\n }\n if (isDateEnabled(baseDate)) {\n return baseDate;\n }\n return null;\n };\n\n const getBaseDate = (date: Date) => {\n const startDate = startOfMonth(date);\n if (isDateEnabled(startDate)) {\n return startDate;\n }\n return moveFocusHandler(startDate, isDateEnabled, (date: Date) => addDays(date, 1));\n };\n\n const baseDate: Date = getBaseDate(displayedDate);\n const focusedOrSelectedDate = focusedDate || selectFocusedDate(selectedDate, baseDate);\n\n const onHeaderChangeMonthHandler: HeaderChangeMonthHandler = isPrevious => {\n onChangeMonth(addMonths(baseDate, isPrevious ? -1 : 1));\n setFocusedDate(null);\n };\n\n const onGridChangeMonthHandler: MonthChangeHandler = newMonth => {\n onChangeMonth(newMonth);\n setFocusedDate(null);\n };\n\n const onGridFocusDateHandler: DateChangeHandlerNullable = ({ date }) => {\n if (date) {\n const value = memoizedDate('focused', formatDate(date));\n setFocusedDate(value);\n }\n };\n\n const onGridSelectDateHandler: DateChangeHandler = detail => {\n onSelectDate(detail);\n setFocusedDate(null);\n };\n\n // The focused date changes as a feedback to keyboard navigation in the grid.\n // Once changed, the corresponding day button needs to receive the actual focus.\n useEffectOnUpdate(() => {\n if (focusedDate) {\n (elementRef.current?.querySelector(`.${styles['calendar-day-focusable']}`) as HTMLDivElement)?.focus();\n }\n }, [focusedDate]);\n\n const onGridBlur = (event: React.FocusEvent) => {\n const newFocusTargetIsInGrid = event.relatedTarget && gridWrapperRef.current?.contains(event.relatedTarget as Node);\n if (!newFocusTargetIsInGrid) {\n setFocusedDate(null);\n }\n };\n\n return (\n <div\n {...focusVisible}\n className={styles.calendar}\n tabIndex={0}\n role=\"application\"\n aria-describedby={headerId}\n ref={elementRef}\n >\n <div className={styles['calendar-inner']}>\n <CalendarHeader\n headerId={headerId}\n baseDate={baseDate}\n locale={locale}\n onChangeMonth={onHeaderChangeMonthHandler}\n previousMonthLabel={previousMonthLabel}\n nextMonthLabel={nextMonthLabel}\n />\n <div onBlur={onGridBlur} ref={gridWrapperRef}>\n <Grid\n locale={locale}\n baseDate={baseDate}\n isDateEnabled={isDateEnabled}\n focusedDate={focusedOrSelectedDate}\n onSelectDate={onGridSelectDateHandler}\n onFocusDate={onGridFocusDateHandler}\n onChangeMonth={onGridChangeMonthHandler}\n startOfWeek={normalizedStartOfWeek}\n todayAriaLabel={todayAriaLabel}\n selectedDate={selectedDate}\n handleFocusMove={moveFocusHandler}\n />\n </div>\n </div>\n </div>\n );\n};\n\nexport default Calendar;\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { DatePickerBaseProps } from './interfaces';
|
|
2
|
+
export declare const DatePickerEmbedded: ({ value, locale, startOfWeek, isDateEnabled, nextMonthAriaLabel, previousMonthAriaLabel, todayAriaLabel, onChange, }: DatePickerBaseProps) => JSX.Element;
|
|
3
|
+
//# sourceMappingURL=embedded.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded.d.ts","sourceRoot":"","sources":["../../../src/date-picker/embedded.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAKnD,eAAO,MAAM,kBAAkB,yHAS5B,mBAAmB,gBAoBrB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import Calendar from './calendar';
|
|
5
|
+
import { memoizedDate } from './calendar/utils/date';
|
|
6
|
+
import { useDatePicker } from './use-date-picker';
|
|
7
|
+
export var DatePickerEmbedded = function (_a) {
|
|
8
|
+
var value = _a.value, _b = _a.locale, locale = _b === void 0 ? '' : _b, startOfWeek = _a.startOfWeek, isDateEnabled = _a.isDateEnabled, nextMonthAriaLabel = _a.nextMonthAriaLabel, previousMonthAriaLabel = _a.previousMonthAriaLabel, todayAriaLabel = _a.todayAriaLabel, onChange = _a.onChange;
|
|
9
|
+
var _c = useDatePicker({
|
|
10
|
+
value: value,
|
|
11
|
+
onChange: onChange
|
|
12
|
+
}), displayedDate = _c.displayedDate, selectedDate = _c.selectedDate, onChangeMonthHandler = _c.onChangeMonthHandler, onSelectDateHandler = _c.onSelectDateHandler;
|
|
13
|
+
return (React.createElement(Calendar, { selectedDate: memoizedDate('value', selectedDate), displayedDate: memoizedDate('displayed', displayedDate), locale: locale, startOfWeek: startOfWeek, isDateEnabled: isDateEnabled ? isDateEnabled : function () { return true; }, nextMonthLabel: nextMonthAriaLabel, previousMonthLabel: previousMonthAriaLabel, todayAriaLabel: todayAriaLabel, onChangeMonth: onChangeMonthHandler, onSelectDate: onSelectDateHandler }));
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=embedded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded.js","sourceRoot":"","sources":["../../../src/date-picker/embedded.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,CAAC,IAAM,kBAAkB,GAAG,UAAC,EASb;QARpB,KAAK,WAAA,EACL,cAAW,EAAX,MAAM,mBAAG,EAAE,KAAA,EACX,WAAW,iBAAA,EACX,aAAa,mBAAA,EACb,kBAAkB,wBAAA,EAClB,sBAAsB,4BAAA,EACtB,cAAc,oBAAA,EACd,QAAQ,cAAA;IAEF,IAAA,KAA6E,aAAa,CAAC;QAC/F,KAAK,OAAA;QACL,QAAQ,UAAA;KACT,CAAC,EAHM,aAAa,mBAAA,EAAE,YAAY,kBAAA,EAAE,oBAAoB,0BAAA,EAAE,mBAAmB,yBAG5E,CAAC;IAEH,OAAO,CACL,oBAAC,QAAQ,IACP,YAAY,EAAE,YAAY,CAAC,OAAO,EAAE,YAAY,CAAC,EACjD,aAAa,EAAE,YAAY,CAAC,WAAW,EAAE,aAAa,CAAC,EACvD,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,EACzD,cAAc,EAAE,kBAAkB,EAClC,kBAAkB,EAAE,sBAAsB,EAC1C,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,mBAAmB,GACjC,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React from 'react';\nimport { DatePickerBaseProps } from './interfaces';\nimport Calendar from './calendar';\nimport { memoizedDate } from './calendar/utils/date';\nimport { useDatePicker } from './use-date-picker';\n\nexport const DatePickerEmbedded = ({\n value,\n locale = '',\n startOfWeek,\n isDateEnabled,\n nextMonthAriaLabel,\n previousMonthAriaLabel,\n todayAriaLabel,\n onChange,\n}: DatePickerBaseProps) => {\n const { displayedDate, selectedDate, onChangeMonthHandler, onSelectDateHandler } = useDatePicker({\n value,\n onChange,\n });\n\n return (\n <Calendar\n selectedDate={memoizedDate('value', selectedDate)}\n displayedDate={memoizedDate('displayed', displayedDate)}\n locale={locale}\n startOfWeek={startOfWeek}\n isDateEnabled={isDateEnabled ? isDateEnabled : () => true}\n nextMonthLabel={nextMonthAriaLabel}\n previousMonthLabel={previousMonthAriaLabel}\n todayAriaLabel={todayAriaLabel}\n onChangeMonth={onChangeMonthHandler}\n onSelectDate={onSelectDateHandler}\n />\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-picker/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA6C,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/date-picker/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA6C,MAAM,OAAO,CAAC;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAuB/C,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,QAAA,MAAM,UAAU,6FAqLf,CAAC;AAGF,eAAe,UAAU,CAAC"}
|
package/date-picker/index.js
CHANGED
|
@@ -3,12 +3,11 @@ import { __assign, __rest } from "tslib";
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import clsx from 'clsx';
|
|
5
5
|
import React, { useCallback, useRef, useState } from 'react';
|
|
6
|
-
import { getWeekStartByLocale } from 'weekstart';
|
|
7
6
|
import styles from './styles.css.js';
|
|
8
7
|
import Calendar from './calendar';
|
|
9
8
|
import { normalizeLocale } from './calendar/utils/locales';
|
|
10
9
|
import { getDateLabel } from './calendar/utils/intl';
|
|
11
|
-
import { displayToIso,
|
|
10
|
+
import { displayToIso, isoToDisplay, memoizedDate } from './calendar/utils/date';
|
|
12
11
|
import { KeyCode } from '../internal/keycode';
|
|
13
12
|
import { fireNonCancelableEvent } from '../internal/events';
|
|
14
13
|
import Dropdown from '../internal/components/dropdown';
|
|
@@ -18,23 +17,22 @@ import { applyDisplayName } from '../internal/utils/apply-display-name.js';
|
|
|
18
17
|
import checkControlled from '../internal/hooks/check-controlled';
|
|
19
18
|
import { useFocusTracker } from '../internal/hooks/use-focus-tracker.js';
|
|
20
19
|
import useForwardFocus from '../internal/hooks/forward-focus';
|
|
21
|
-
import { usePrevious } from '../internal/hooks/use-previous';
|
|
22
20
|
import { InternalButton } from '../button/internal';
|
|
23
21
|
import useBaseComponent from '../internal/hooks/use-base-component';
|
|
24
22
|
import { useUniqueId } from '../internal/hooks/use-unique-id';
|
|
25
23
|
import { useMergeRefs } from '../internal/hooks/use-merge-refs';
|
|
26
24
|
import FocusLock from '../internal/components/focus-lock';
|
|
25
|
+
import { useDatePicker } from './use-date-picker.js';
|
|
27
26
|
var DatePicker = React.forwardRef(function (_a, ref) {
|
|
28
27
|
var _b = _a.locale, locale = _b === void 0 ? '' : _b, startOfWeek = _a.startOfWeek, isDateEnabled = _a.isDateEnabled, nextMonthAriaLabel = _a.nextMonthAriaLabel, previousMonthAriaLabel = _a.previousMonthAriaLabel, todayAriaLabel = _a.todayAriaLabel, _c = _a.placeholder, placeholder = _c === void 0 ? '' : _c, _d = _a.value, value = _d === void 0 ? '' : _d, _e = _a.readOnly, readOnly = _e === void 0 ? false : _e, _f = _a.disabled, disabled = _f === void 0 ? false : _f, onBlur = _a.onBlur, _g = _a.autoFocus, autoFocus = _g === void 0 ? false : _g, onChange = _a.onChange, onFocus = _a.onFocus, name = _a.name, ariaLabel = _a.ariaLabel, ariaRequired = _a.ariaRequired, ariaLabelledby = _a.ariaLabelledby, ariaDescribedby = _a.ariaDescribedby, controlId = _a.controlId, invalid = _a.invalid, openCalendarAriaLabel = _a.openCalendarAriaLabel, expandToViewport = _a.expandToViewport, rest = __rest(_a, ["locale", "startOfWeek", "isDateEnabled", "nextMonthAriaLabel", "previousMonthAriaLabel", "todayAriaLabel", "placeholder", "value", "readOnly", "disabled", "onBlur", "autoFocus", "onChange", "onFocus", "name", "ariaLabel", "ariaRequired", "ariaLabelledby", "ariaDescribedby", "controlId", "invalid", "openCalendarAriaLabel", "expandToViewport"]);
|
|
29
28
|
var __internalRootRef = useBaseComponent('DatePicker').__internalRootRef;
|
|
29
|
+
var _h = useDatePicker({
|
|
30
|
+
value: value,
|
|
31
|
+
onChange: onChange
|
|
32
|
+
}), defaultDisplayedDate = _h.defaultDisplayedDate, displayedDate = _h.displayedDate, setDisplayedDate = _h.setDisplayedDate, selectedDate = _h.selectedDate, onChangeMonthHandler = _h.onChangeMonthHandler, onSelectDateHandler = _h.onSelectDateHandler;
|
|
30
33
|
var baseProps = getBaseProps(rest);
|
|
31
|
-
var
|
|
34
|
+
var _j = useState(false), isDropDownOpen = _j[0], setIsDropDownOpen = _j[1];
|
|
32
35
|
var normalizedLocale = normalizeLocale('DatePicker', locale !== null && locale !== void 0 ? locale : '');
|
|
33
|
-
var normalizedStartOfWeek = (typeof startOfWeek === 'number' ? startOfWeek : getWeekStartByLocale(normalizedLocale));
|
|
34
|
-
var defaultSelectedDate = value.length >= 10 ? value : null;
|
|
35
|
-
var _j = useState(defaultSelectedDate), selectedDate = _j[0], setSelectedDate = _j[1];
|
|
36
|
-
var defaultDisplayedDate = value.length >= 10 ? value : formatDate(new Date());
|
|
37
|
-
var _k = useState(defaultDisplayedDate), displayedDate = _k[0], setDisplayedDate = _k[1];
|
|
38
36
|
var internalInputRef = useRef(null);
|
|
39
37
|
var buttonRef = useRef(null);
|
|
40
38
|
useForwardFocus(ref, internalInputRef);
|
|
@@ -42,23 +40,10 @@ var DatePicker = React.forwardRef(function (_a, ref) {
|
|
|
42
40
|
var dropdownId = useUniqueId('calender');
|
|
43
41
|
var mergedRef = useMergeRefs(rootRef, __internalRootRef);
|
|
44
42
|
useFocusTracker({ rootRef: rootRef, onBlur: onBlur, onFocus: onFocus, viewportId: expandToViewport ? dropdownId : '' });
|
|
45
|
-
var onChangeMonthHandler = function (newMonth) {
|
|
46
|
-
setDisplayedDate(formatDate(newMonth));
|
|
47
|
-
};
|
|
48
|
-
var onSelectDateHandler = function (_a) {
|
|
49
|
-
var _b;
|
|
50
|
-
var date = _a.date;
|
|
51
|
-
var formattedDate = formatDate(date);
|
|
52
|
-
(_b = buttonRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
53
|
-
setIsDropDownOpen(false);
|
|
54
|
-
setSelectedDate(formattedDate);
|
|
55
|
-
setDisplayedDate(formattedDate);
|
|
56
|
-
fireNonCancelableEvent(onChange, { value: formattedDate });
|
|
57
|
-
};
|
|
58
43
|
var onDropdownCloseHandler = useCallback(function () {
|
|
59
44
|
setDisplayedDate(defaultDisplayedDate);
|
|
60
45
|
setIsDropDownOpen(false);
|
|
61
|
-
}, [defaultDisplayedDate]);
|
|
46
|
+
}, [defaultDisplayedDate, setDisplayedDate, setIsDropDownOpen]);
|
|
62
47
|
var onButtonClickHandler = function () {
|
|
63
48
|
if (!isDropDownOpen) {
|
|
64
49
|
setIsDropDownOpen(true);
|
|
@@ -81,21 +66,6 @@ var DatePicker = React.forwardRef(function (_a, ref) {
|
|
|
81
66
|
setIsDropDownOpen(false);
|
|
82
67
|
}
|
|
83
68
|
};
|
|
84
|
-
var prevValue = usePrevious(value);
|
|
85
|
-
if (prevValue !== value) {
|
|
86
|
-
if (value === '' && selectedDate !== value) {
|
|
87
|
-
setSelectedDate(value);
|
|
88
|
-
}
|
|
89
|
-
// update the displayedDate when inputValue changes in order to
|
|
90
|
-
// display the correct month when the date picker gets open again.
|
|
91
|
-
if (value.length >= 4 && displayedDate !== value) {
|
|
92
|
-
setDisplayedDate(value);
|
|
93
|
-
}
|
|
94
|
-
// set the selected date only when a full date (yyyy-mm-dd) is entered
|
|
95
|
-
if (value.length >= 10 && selectedDate !== value) {
|
|
96
|
-
setSelectedDate(value);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
69
|
var DateInputElement = (React.createElement("div", { className: styles['date-picker-trigger'] },
|
|
100
70
|
React.createElement("div", { className: styles['date-picker-input'] },
|
|
101
71
|
React.createElement(DateInput, { name: name, invalid: invalid, controlId: controlId, ariaLabelledby: ariaLabelledby, ariaDescribedby: ariaDescribedby, ariaLabel: ariaLabel, ariaRequired: ariaRequired, value: isoToDisplay(value), autoComplete: false, disableBrowserAutocorrect: true, disableAutocompleteOnBlur: isDropDownOpen, disabled: disabled, readOnly: readOnly, onChange: onInputChangeHandler, onBlur: onInputBlurHandler, placeholder: placeholder, ref: internalInputRef, autoFocus: autoFocus })),
|
|
@@ -112,8 +82,13 @@ var DatePicker = React.forwardRef(function (_a, ref) {
|
|
|
112
82
|
event.preventDefault();
|
|
113
83
|
};
|
|
114
84
|
return (React.createElement("div", __assign({}, baseProps, { ref: mergedRef, onKeyDown: onWrapperKeyDownHandler }),
|
|
115
|
-
React.createElement(Dropdown, { stretchWidth: true, stretchHeight: true, open: isDropDownOpen, onDropdownClose: onDropdownCloseHandler, onMouseDown: handleMouseDown, trigger: DateInputElement, expandToViewport: expandToViewport, scrollable: false, dropdownId: dropdownId }, isDropDownOpen && (React.createElement(FocusLock,
|
|
116
|
-
React.createElement(Calendar, { selectedDate: memoizedDate('value', selectedDate), displayedDate: memoizedDate('displayed', displayedDate), locale: normalizedLocale, startOfWeek:
|
|
85
|
+
React.createElement(Dropdown, { stretchWidth: true, stretchHeight: true, open: isDropDownOpen, onDropdownClose: onDropdownCloseHandler, onMouseDown: handleMouseDown, trigger: DateInputElement, expandToViewport: expandToViewport, scrollable: false, dropdownId: dropdownId }, isDropDownOpen && (React.createElement(FocusLock, { autoFocus: true },
|
|
86
|
+
React.createElement(Calendar, { selectedDate: memoizedDate('value', selectedDate), displayedDate: memoizedDate('displayed', displayedDate), locale: normalizedLocale, startOfWeek: startOfWeek, isDateEnabled: isDateEnabled ? isDateEnabled : function () { return true; }, nextMonthLabel: nextMonthAriaLabel, previousMonthLabel: previousMonthAriaLabel, todayAriaLabel: todayAriaLabel, onChangeMonth: onChangeMonthHandler, onSelectDate: function (e) {
|
|
87
|
+
var _a;
|
|
88
|
+
onSelectDateHandler(e);
|
|
89
|
+
(_a = buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
90
|
+
setIsDropDownOpen(false);
|
|
91
|
+
} }))))));
|
|
117
92
|
});
|
|
118
93
|
applyDisplayName(DatePicker, 'DatePicker');
|
|
119
94
|
export default DatePicker;
|
package/date-picker/index.js.map
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cAAc,EAAE,kBAAkB,EAClC,kBAAkB,EAAE,sBAAsB,EAC1C,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,oBAAoB,EACnC,YAAY,EAAE,mBAAmB,GACjC,CACQ,CACb,CACQ,CACP,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,gBAAgB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AAC3C,eAAe,UAAU,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport clsx from 'clsx';\nimport React, { Ref, useCallback, useRef, useState } from 'react';\nimport { getWeekStartByLocale } from 'weekstart';\nimport styles from './styles.css.js';\nimport { DatePickerProps } from './interfaces';\nimport Calendar, { DayIndex } from './calendar';\nimport { normalizeLocale } from './calendar/utils/locales';\nimport { getDateLabel } from './calendar/utils/intl';\nimport { CalendarTypes } from './calendar/definitions';\nimport { displayToIso, formatDate, isoToDisplay, memoizedDate } from './calendar/utils/date';\nimport { InputProps } from '../input/interfaces';\nimport { KeyCode } from '../internal/keycode';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport Dropdown from '../internal/components/dropdown';\nimport DateInput from '../internal/components/date-input';\nimport { getBaseProps } from '../internal/base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name.js';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport { useFocusTracker } from '../internal/hooks/use-focus-tracker.js';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { usePrevious } from '../internal/hooks/use-previous';\nimport { ButtonProps } from '../button/interfaces';\nimport { InternalButton } from '../button/internal';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport FocusLock from '../internal/components/focus-lock';\n\nexport { DatePickerProps };\n\nconst DatePicker = React.forwardRef(\n (\n {\n locale = '',\n startOfWeek,\n isDateEnabled,\n nextMonthAriaLabel,\n previousMonthAriaLabel,\n todayAriaLabel,\n placeholder = '',\n value = '',\n readOnly = false,\n disabled = false,\n onBlur,\n autoFocus = false,\n onChange,\n onFocus,\n name,\n ariaLabel,\n ariaRequired,\n ariaLabelledby,\n ariaDescribedby,\n controlId,\n invalid,\n openCalendarAriaLabel,\n expandToViewport,\n ...rest\n }: DatePickerProps,\n ref: Ref<DatePickerProps.Ref>\n ) => {\n const { __internalRootRef } = useBaseComponent('DatePicker');\n\n const baseProps = getBaseProps(rest);\n const [isDropDownOpen, setIsDropDownOpen] = useState<boolean>(false);\n const normalizedLocale = normalizeLocale('DatePicker', locale ?? '');\n const normalizedStartOfWeek = (\n typeof startOfWeek === 'number' ? startOfWeek : getWeekStartByLocale(normalizedLocale)\n ) as DayIndex;\n\n const defaultSelectedDate = value.length >= 10 ? value : null;\n const [selectedDate, setSelectedDate] = useState<string | null>(defaultSelectedDate);\n\n const defaultDisplayedDate = value.length >= 10 ? value : formatDate(new Date());\n const [displayedDate, setDisplayedDate] = useState<string>(defaultDisplayedDate);\n\n const internalInputRef = useRef<HTMLInputElement>(null);\n const buttonRef = useRef<ButtonProps.Ref>(null);\n useForwardFocus(ref, internalInputRef);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const dropdownId = useUniqueId('calender');\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n useFocusTracker({ rootRef, onBlur, onFocus, viewportId: expandToViewport ? dropdownId : '' });\n\n const onChangeMonthHandler = (newMonth: Date) => {\n setDisplayedDate(formatDate(newMonth));\n };\n\n const onSelectDateHandler = ({ date }: CalendarTypes.DateDetail) => {\n const formattedDate = formatDate(date);\n buttonRef.current?.focus();\n setIsDropDownOpen(false);\n setSelectedDate(formattedDate);\n setDisplayedDate(formattedDate);\n fireNonCancelableEvent(onChange, { value: formattedDate });\n };\n\n const onDropdownCloseHandler = useCallback(() => {\n setDisplayedDate(defaultDisplayedDate);\n setIsDropDownOpen(false);\n }, [defaultDisplayedDate]);\n\n const onButtonClickHandler = () => {\n if (!isDropDownOpen) {\n setIsDropDownOpen(true);\n }\n };\n\n const onWrapperKeyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.keyCode === KeyCode.escape && isDropDownOpen) {\n buttonRef.current?.focus();\n setIsDropDownOpen(false);\n }\n };\n\n const onInputChangeHandler: InputProps['onChange'] = event => {\n const isoDateString = displayToIso(event.detail.value);\n fireNonCancelableEvent(onChange, { value: isoDateString });\n };\n\n const onInputBlurHandler: InputProps['onBlur'] = () => {\n if (!isDropDownOpen) {\n setDisplayedDate(defaultDisplayedDate);\n setIsDropDownOpen(false);\n }\n };\n\n const prevValue = usePrevious(value);\n if (prevValue !== value) {\n if (value === '' && selectedDate !== value) {\n setSelectedDate(value);\n }\n // update the displayedDate when inputValue changes in order to\n // display the correct month when the date picker gets open again.\n if (value.length >= 4 && displayedDate !== value) {\n setDisplayedDate(value);\n }\n // set the selected date only when a full date (yyyy-mm-dd) is entered\n if (value.length >= 10 && selectedDate !== value) {\n setSelectedDate(value);\n }\n }\n\n const DateInputElement = (\n <div className={styles['date-picker-trigger']}>\n <div className={styles['date-picker-input']}>\n <DateInput\n name={name}\n invalid={invalid}\n controlId={controlId}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n ariaLabel={ariaLabel}\n ariaRequired={ariaRequired}\n value={isoToDisplay(value)}\n autoComplete={false}\n disableBrowserAutocorrect={true}\n disableAutocompleteOnBlur={isDropDownOpen}\n disabled={disabled}\n readOnly={readOnly}\n onChange={onInputChangeHandler}\n onBlur={onInputBlurHandler}\n placeholder={placeholder}\n ref={internalInputRef}\n autoFocus={autoFocus}\n />\n </div>\n <div>\n <InternalButton\n iconName=\"calendar\"\n className={styles['open-calendar-button']}\n onClick={onButtonClickHandler}\n ref={buttonRef}\n ariaLabel={\n openCalendarAriaLabel &&\n openCalendarAriaLabel(\n value.length === 10 ? getDateLabel(normalizedLocale, memoizedDate('value', value)) : null\n )\n }\n disabled={disabled || readOnly}\n formAction=\"none\"\n />\n </div>\n </div>\n );\n\n baseProps.className = clsx(baseProps.className, styles.root, styles['date-picker-container']);\n\n if (readOnly || disabled) {\n return <div {...baseProps}>{DateInputElement}</div>;\n }\n\n checkControlled('DatePicker', 'value', value, 'onChange', onChange);\n\n const handleMouseDown = (event: React.MouseEvent) => {\n // prevent currently focused element from losing it\n event.preventDefault();\n };\n\n return (\n <div {...baseProps} ref={mergedRef} onKeyDown={onWrapperKeyDownHandler}>\n <Dropdown\n stretchWidth={true}\n stretchHeight={true}\n open={isDropDownOpen}\n onDropdownClose={onDropdownCloseHandler}\n onMouseDown={handleMouseDown}\n trigger={DateInputElement}\n expandToViewport={expandToViewport}\n scrollable={false}\n dropdownId={dropdownId}\n >\n {isDropDownOpen && (\n <FocusLock>\n <Calendar\n selectedDate={memoizedDate('value', selectedDate)}\n displayedDate={memoizedDate('displayed', displayedDate)}\n locale={normalizedLocale}\n startOfWeek={normalizedStartOfWeek}\n isDateEnabled={isDateEnabled ? isDateEnabled : () => true}\n nextMonthLabel={nextMonthAriaLabel}\n previousMonthLabel={previousMonthAriaLabel}\n todayAriaLabel={todayAriaLabel}\n onChangeMonth={onChangeMonthHandler}\n onSelectDate={onSelectDateHandler}\n />\n </FocusLock>\n )}\n </Dropdown>\n </div>\n );\n }\n);\n\napplyDisplayName(DatePicker, 'DatePicker');\nexport default DatePicker;\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/date-picker/index.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,EAAE,EAAO,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAClE,OAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,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port clsx from 'clsx';\nimport React, { Ref, useCallback, useRef, useState } from 'react';\nimport styles from './styles.css.js';\nimport { DatePickerProps } from './interfaces';\nimport Calendar from './calendar';\nimport { normalizeLocale } from './calendar/utils/locales';\nimport { getDateLabel } from './calendar/utils/intl';\nimport { displayToIso, isoToDisplay, memoizedDate } from './calendar/utils/date';\nimport { InputProps } from '../input/interfaces';\nimport { KeyCode } from '../internal/keycode';\nimport { fireNonCancelableEvent } from '../internal/events';\nimport Dropdown from '../internal/components/dropdown';\nimport DateInput from '../internal/components/date-input';\nimport { getBaseProps } from '../internal/base-component';\nimport { applyDisplayName } from '../internal/utils/apply-display-name.js';\nimport checkControlled from '../internal/hooks/check-controlled';\nimport { useFocusTracker } from '../internal/hooks/use-focus-tracker.js';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { ButtonProps } from '../button/interfaces';\nimport { InternalButton } from '../button/internal';\nimport useBaseComponent from '../internal/hooks/use-base-component';\nimport { useUniqueId } from '../internal/hooks/use-unique-id';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport FocusLock from '../internal/components/focus-lock';\nimport { useDatePicker } from './use-date-picker.js';\n\nexport { DatePickerProps };\n\nconst DatePicker = React.forwardRef(\n (\n {\n locale = '',\n startOfWeek,\n isDateEnabled,\n nextMonthAriaLabel,\n previousMonthAriaLabel,\n todayAriaLabel,\n placeholder = '',\n value = '',\n readOnly = false,\n disabled = false,\n onBlur,\n autoFocus = false,\n onChange,\n onFocus,\n name,\n ariaLabel,\n ariaRequired,\n ariaLabelledby,\n ariaDescribedby,\n controlId,\n invalid,\n openCalendarAriaLabel,\n expandToViewport,\n ...rest\n }: DatePickerProps,\n ref: Ref<DatePickerProps.Ref>\n ) => {\n const { __internalRootRef } = useBaseComponent('DatePicker');\n\n const {\n defaultDisplayedDate,\n displayedDate,\n setDisplayedDate,\n selectedDate,\n onChangeMonthHandler,\n onSelectDateHandler,\n } = useDatePicker({\n value,\n onChange,\n });\n\n const baseProps = getBaseProps(rest);\n const [isDropDownOpen, setIsDropDownOpen] = useState<boolean>(false);\n const normalizedLocale = normalizeLocale('DatePicker', locale ?? '');\n\n const internalInputRef = useRef<HTMLInputElement>(null);\n const buttonRef = useRef<ButtonProps.Ref>(null);\n useForwardFocus(ref, internalInputRef);\n\n const rootRef = useRef<HTMLDivElement>(null);\n const dropdownId = useUniqueId('calender');\n const mergedRef = useMergeRefs(rootRef, __internalRootRef);\n\n useFocusTracker({ rootRef, onBlur, onFocus, viewportId: expandToViewport ? dropdownId : '' });\n\n const onDropdownCloseHandler = useCallback(() => {\n setDisplayedDate(defaultDisplayedDate);\n setIsDropDownOpen(false);\n }, [defaultDisplayedDate, setDisplayedDate, setIsDropDownOpen]);\n\n const onButtonClickHandler = () => {\n if (!isDropDownOpen) {\n setIsDropDownOpen(true);\n }\n };\n\n const onWrapperKeyDownHandler = (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (event.keyCode === KeyCode.escape && isDropDownOpen) {\n buttonRef.current?.focus();\n setIsDropDownOpen(false);\n }\n };\n\n const onInputChangeHandler: InputProps['onChange'] = event => {\n const isoDateString = displayToIso(event.detail.value);\n fireNonCancelableEvent(onChange, { value: isoDateString });\n };\n\n const onInputBlurHandler: InputProps['onBlur'] = () => {\n if (!isDropDownOpen) {\n setDisplayedDate(defaultDisplayedDate);\n setIsDropDownOpen(false);\n }\n };\n\n const DateInputElement = (\n <div className={styles['date-picker-trigger']}>\n <div className={styles['date-picker-input']}>\n <DateInput\n name={name}\n invalid={invalid}\n controlId={controlId}\n ariaLabelledby={ariaLabelledby}\n ariaDescribedby={ariaDescribedby}\n ariaLabel={ariaLabel}\n ariaRequired={ariaRequired}\n value={isoToDisplay(value)}\n autoComplete={false}\n disableBrowserAutocorrect={true}\n disableAutocompleteOnBlur={isDropDownOpen}\n disabled={disabled}\n readOnly={readOnly}\n onChange={onInputChangeHandler}\n onBlur={onInputBlurHandler}\n placeholder={placeholder}\n ref={internalInputRef}\n autoFocus={autoFocus}\n />\n </div>\n <div>\n <InternalButton\n iconName=\"calendar\"\n className={styles['open-calendar-button']}\n onClick={onButtonClickHandler}\n ref={buttonRef}\n ariaLabel={\n openCalendarAriaLabel &&\n openCalendarAriaLabel(\n value.length === 10 ? getDateLabel(normalizedLocale, memoizedDate('value', value)) : null\n )\n }\n disabled={disabled || readOnly}\n formAction=\"none\"\n />\n </div>\n </div>\n );\n\n baseProps.className = clsx(baseProps.className, styles.root, styles['date-picker-container']);\n\n if (readOnly || disabled) {\n return <div {...baseProps}>{DateInputElement}</div>;\n }\n\n checkControlled('DatePicker', 'value', value, 'onChange', onChange);\n\n const handleMouseDown = (event: React.MouseEvent) => {\n // prevent currently focused element from losing it\n event.preventDefault();\n };\n\n return (\n <div {...baseProps} ref={mergedRef} onKeyDown={onWrapperKeyDownHandler}>\n <Dropdown\n stretchWidth={true}\n stretchHeight={true}\n open={isDropDownOpen}\n onDropdownClose={onDropdownCloseHandler}\n onMouseDown={handleMouseDown}\n trigger={DateInputElement}\n expandToViewport={expandToViewport}\n scrollable={false}\n dropdownId={dropdownId}\n >\n {isDropDownOpen && (\n <FocusLock autoFocus={true}>\n <Calendar\n selectedDate={memoizedDate('value', selectedDate)}\n displayedDate={memoizedDate('displayed', displayedDate)}\n locale={normalizedLocale}\n startOfWeek={startOfWeek}\n isDateEnabled={isDateEnabled ? isDateEnabled : () => true}\n nextMonthLabel={nextMonthAriaLabel}\n previousMonthLabel={previousMonthAriaLabel}\n todayAriaLabel={todayAriaLabel}\n onChangeMonth={onChangeMonthHandler}\n onSelectDate={e => {\n onSelectDateHandler(e);\n buttonRef?.current?.focus();\n setIsDropDownOpen(false);\n }}\n />\n </FocusLock>\n )}\n </Dropdown>\n </div>\n );\n }\n);\n\napplyDisplayName(DatePicker, 'DatePicker');\nexport default DatePicker;\n"]}
|
|
@@ -2,15 +2,11 @@ import { BaseComponentProps } from '../internal/base-component';
|
|
|
2
2
|
import { FormFieldValidationControlProps } from '../internal/context/form-field-context';
|
|
3
3
|
import { ExpandToViewport } from '../internal/components/dropdown/interfaces';
|
|
4
4
|
import { NonCancelableEventHandler } from '../internal/events';
|
|
5
|
-
export interface
|
|
5
|
+
export interface DatePickerBaseProps {
|
|
6
6
|
/**
|
|
7
7
|
* The current input value, in YYYY-MM-DD format.
|
|
8
8
|
*/
|
|
9
9
|
value: string;
|
|
10
|
-
/**
|
|
11
|
-
* Specifies the placeholder text rendered when the value is an empty string.
|
|
12
|
-
*/
|
|
13
|
-
placeholder?: string;
|
|
14
10
|
/**
|
|
15
11
|
* Defines whether a particular date is enabled in the calendar or not.
|
|
16
12
|
* If you disable a date in the calendar, users can still enter this date using a keyboard.
|
|
@@ -43,6 +39,17 @@ export interface DatePickerProps extends BaseComponentProps, FormFieldValidation
|
|
|
43
39
|
* Specifies an `aria-label` for the 'previous month' button.
|
|
44
40
|
*/
|
|
45
41
|
previousMonthAriaLabel: string;
|
|
42
|
+
/**
|
|
43
|
+
* Called whenever a user changes the input value (by typing, pasting, or selecting a value).
|
|
44
|
+
* The event `detail` contains the current value of the field.
|
|
45
|
+
*/
|
|
46
|
+
onChange?: NonCancelableEventHandler<DatePickerProps.ChangeDetail>;
|
|
47
|
+
}
|
|
48
|
+
export interface DatePickerProps extends BaseComponentProps, FormFieldValidationControlProps, ExpandToViewport, DatePickerBaseProps {
|
|
49
|
+
/**
|
|
50
|
+
* Specifies the placeholder text rendered when the value is an empty string.
|
|
51
|
+
*/
|
|
52
|
+
placeholder?: string;
|
|
46
53
|
/**
|
|
47
54
|
* Specifies a function that generates the `aria-label` for the 'open calendar' button. The `selectedDate` parameter is
|
|
48
55
|
* a human-readable localised string representing the current value of the input.
|
|
@@ -94,11 +101,6 @@ export interface DatePickerProps extends BaseComponentProps, FormFieldValidation
|
|
|
94
101
|
* Called when input focus is removed from the UI control.
|
|
95
102
|
*/
|
|
96
103
|
onBlur?: NonCancelableEventHandler<null>;
|
|
97
|
-
/**
|
|
98
|
-
* Called whenever a user changes the input value (by typing, pasting, or selecting a value).
|
|
99
|
-
* The event `detail` contains the current value of the field.
|
|
100
|
-
*/
|
|
101
|
-
onChange?: NonCancelableEventHandler<DatePickerProps.ChangeDetail>;
|
|
102
104
|
}
|
|
103
105
|
export declare namespace DatePickerProps {
|
|
104
106
|
interface ChangeDetail {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/date-picker/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,WAAW,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../../src/date-picker/interfaces.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,+BAA+B,EAAE,MAAM,wCAAwC,CAAC;AACzF,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAE/D,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,eAAe,CAAC,qBAAqB,CAAC;IAEtD;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,kBAAkB,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,QAAQ,CAAC,EAAE,yBAAyB,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,eACf,SAAQ,kBAAkB,EACxB,+BAA+B,EAC/B,gBAAgB,EAChB,mBAAmB;IACrB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,eAAe,CAAC,qBAAqB,CAAC;IAE9D;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;OAEG;IACH,OAAO,CAAC,EAAE,yBAAyB,CAAC,IAAI,CAAC,CAAC;IAE1C;;OAEG;IACH,MAAM,CAAC,EAAE,yBAAyB,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED,yBAAiB,eAAe,CAAC;IAC/B,UAAiB,YAAY;QAC3B;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;KACf;IAED,UAAiB,qBAAqB;QACpC,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC;KACvB;IAED,UAAiB,qBAAqB;QACpC,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAAC;KACvC;IAED,UAAiB,GAAG;QAClB;;WAEG;QACH,KAAK,IAAI,IAAI,CAAC;KACf;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/date-picker/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport { FormFieldValidationControlProps } from '../internal/context/form-field-context';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\nimport { NonCancelableEventHandler } from '../internal/events';\n\nexport interface
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/date-picker/interfaces.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { BaseComponentProps } from '../internal/base-component';\nimport { FormFieldValidationControlProps } from '../internal/context/form-field-context';\nimport { ExpandToViewport } from '../internal/components/dropdown/interfaces';\nimport { NonCancelableEventHandler } from '../internal/events';\n\nexport interface DatePickerBaseProps {\n /**\n * The current input value, in YYYY-MM-DD format.\n */\n value: string;\n\n /**\n * Defines whether a particular date is enabled in the calendar or not.\n * If you disable a date in the calendar, users can still enter this date using a keyboard.\n * We recommend that you also validate these constraints on the client-side and server-side\n * as you would for other form elements.\n * @param date\n */\n isDateEnabled?: DatePickerProps.IsDateEnabledFunction;\n\n /**\n * Specifies the locale to use to render month names and determine the starting day of the week.\n * If you don't provide this, the locale is determined by the page and browser locales.\n * Supported values and formats are listed in the\n * [JavaScript Intl API specification](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl#Locale_identification_and_negotiation).\n */\n locale?: string;\n\n /**\n * Determines the starting day of the week. The values 0-6 map to Sunday-Saturday.\n * By default the starting day of the week is defined by the locale, but you can use this property to override it.\n */\n startOfWeek?: number;\n\n /**\n * Used as part of the `aria-label` for today's date in the calendar.\n */\n todayAriaLabel: string;\n\n /**\n * Specifies an `aria-label` for the 'next month' button.\n */\n nextMonthAriaLabel: string;\n\n /**\n * Specifies an `aria-label` for the 'previous month' button.\n */\n previousMonthAriaLabel: string;\n\n /**\n * Called whenever a user changes the input value (by typing, pasting, or selecting a value).\n * The event `detail` contains the current value of the field.\n */\n onChange?: NonCancelableEventHandler<DatePickerProps.ChangeDetail>;\n}\n\nexport interface DatePickerProps\n extends BaseComponentProps,\n FormFieldValidationControlProps,\n ExpandToViewport,\n DatePickerBaseProps {\n /**\n * Specifies the placeholder text rendered when the value is an empty string.\n */\n placeholder?: string;\n\n /**\n * Specifies a function that generates the `aria-label` for the 'open calendar' button. The `selectedDate` parameter is\n * a human-readable localised string representing the current value of the input.\n * (for example, ``selectedDate => 'Choose Date' + (selectedDate ? `, selected date is ${selectedDate}` : '')``)\n */\n openCalendarAriaLabel?: DatePickerProps.OpenCalendarAriaLabel;\n\n /**\n * Specifies the name of the control used in HTML forms.\n */\n name?: string;\n\n /**\n * Specifies if the control is disabled, which prevents the\n * user from modifying the value and prevents the value from\n * being included in a form submission. A disabled control can't\n * receive focus.\n */\n disabled?: boolean;\n\n /**\n * Specifies if the control is read only, which prevents the\n * user from modifying the value but includes it in a form\n * submission. A read-only control can receive focus.\n *\n * Do not use read-only inputs outside of a form.\n */\n readOnly?: boolean;\n\n /**\n * Indicates whether the control should be focused as\n * soon as the page loads, which enables the user to\n * start typing without having to manually focus the control. Don't\n * use this option on pages where the control may be\n * scrolled out of the viewport.\n */\n autoFocus?: boolean;\n\n /**\n * Adds an `aria-label` to the native control.\n *\n * Use this if you don't have a visible label for this control.\n */\n ariaLabel?: string;\n\n /**\n * Specifies whether to add `aria-required` to the native control.\n */\n ariaRequired?: boolean;\n\n /**\n * Called when input focus is moved to the UI control.\n */\n onFocus?: NonCancelableEventHandler<null>;\n\n /**\n * Called when input focus is removed from the UI control.\n */\n onBlur?: NonCancelableEventHandler<null>;\n}\n\nexport namespace DatePickerProps {\n export interface ChangeDetail {\n /**\n * The new value of this date-picker.\n */\n value: string;\n }\n\n export interface IsDateEnabledFunction {\n (date: Date): boolean;\n }\n\n export interface OpenCalendarAriaLabel {\n (selectedDate: string | null): string;\n }\n\n export interface Ref {\n /**\n * Sets the browser focus on the UI control\n */\n focus(): void;\n }\n}\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { CalendarTypes } from './calendar/definitions';
|
|
2
|
+
import { NonCancelableEventHandler } from '../internal/events';
|
|
3
|
+
import { DatePickerProps } from './interfaces';
|
|
4
|
+
export declare function useDatePicker({ value, onChange }: UseDatePickerProps): {
|
|
5
|
+
defaultDisplayedDate: string;
|
|
6
|
+
displayedDate: string;
|
|
7
|
+
setDisplayedDate: import("react").Dispatch<import("react").SetStateAction<string>>;
|
|
8
|
+
selectedDate: string | null;
|
|
9
|
+
setSelectedDate: import("react").Dispatch<import("react").SetStateAction<string | null>>;
|
|
10
|
+
onChangeMonthHandler: (newMonth: Date) => void;
|
|
11
|
+
onSelectDateHandler: ({ date }: CalendarTypes.DateDetail) => void;
|
|
12
|
+
};
|
|
13
|
+
export interface UseDatePickerProps {
|
|
14
|
+
value: string;
|
|
15
|
+
onChange: NonCancelableEventHandler<DatePickerProps.ChangeDetail> | undefined;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=use-date-picker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-date-picker.d.ts","sourceRoot":"","sources":["../../../src/date-picker/use-date-picker.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAGvD,OAAO,EAA0B,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AACvF,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAE/C,wBAAgB,aAAa,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,kBAAkB;;;;;;qCAO3B,IAAI;oCAIL,cAAc,UAAU;EAgChE;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,yBAAyB,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;CAC/E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { useState } from 'react';
|
|
4
|
+
import { formatDate } from './calendar/utils/date';
|
|
5
|
+
import { usePrevious } from '../internal/hooks/use-previous';
|
|
6
|
+
import { fireNonCancelableEvent } from '../internal/events';
|
|
7
|
+
export function useDatePicker(_a) {
|
|
8
|
+
var value = _a.value, onChange = _a.onChange;
|
|
9
|
+
var defaultSelectedDate = value.length >= 10 ? value : null;
|
|
10
|
+
var _b = useState(defaultSelectedDate), selectedDate = _b[0], setSelectedDate = _b[1];
|
|
11
|
+
var defaultDisplayedDate = value.length >= 10 ? value : formatDate(new Date());
|
|
12
|
+
var _c = useState(defaultDisplayedDate), displayedDate = _c[0], setDisplayedDate = _c[1];
|
|
13
|
+
var onChangeMonthHandler = function (newMonth) {
|
|
14
|
+
setDisplayedDate(formatDate(newMonth));
|
|
15
|
+
};
|
|
16
|
+
var onSelectDateHandler = function (_a) {
|
|
17
|
+
var date = _a.date;
|
|
18
|
+
var formattedDate = formatDate(date);
|
|
19
|
+
setSelectedDate(formattedDate);
|
|
20
|
+
setDisplayedDate(formattedDate);
|
|
21
|
+
fireNonCancelableEvent(onChange, { value: formattedDate });
|
|
22
|
+
};
|
|
23
|
+
var prevValue = usePrevious(value);
|
|
24
|
+
if (prevValue !== value) {
|
|
25
|
+
if (value === '' && selectedDate !== value) {
|
|
26
|
+
setSelectedDate(value);
|
|
27
|
+
}
|
|
28
|
+
// update the displayedDate when inputValue changes in order to
|
|
29
|
+
// display the correct month when the date picker gets open again.
|
|
30
|
+
if (value.length >= 4 && displayedDate !== value) {
|
|
31
|
+
setDisplayedDate(value);
|
|
32
|
+
}
|
|
33
|
+
// set the selected date only when a full date (yyyy-mm-dd) is entered
|
|
34
|
+
if (value.length >= 10 && selectedDate !== value) {
|
|
35
|
+
setSelectedDate(value);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
defaultDisplayedDate: defaultDisplayedDate,
|
|
40
|
+
displayedDate: displayedDate,
|
|
41
|
+
setDisplayedDate: setDisplayedDate,
|
|
42
|
+
selectedDate: selectedDate,
|
|
43
|
+
setSelectedDate: setSelectedDate,
|
|
44
|
+
onChangeMonthHandler: onChangeMonthHandler,
|
|
45
|
+
onSelectDateHandler: onSelectDateHandler
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=use-date-picker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-date-picker.js","sourceRoot":"","sources":["../../../src/date-picker/use-date-picker.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,sBAAsB,EAA6B,MAAM,oBAAoB,CAAC;AAGvF,MAAM,UAAU,aAAa,CAAC,EAAuC;QAArC,KAAK,WAAA,EAAE,QAAQ,cAAA;IAC7C,IAAM,mBAAmB,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC;IACxD,IAAA,KAAkC,QAAQ,CAAgB,mBAAmB,CAAC,EAA7E,YAAY,QAAA,EAAE,eAAe,QAAgD,CAAC;IAErF,IAAM,oBAAoB,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;IAC3E,IAAA,KAAoC,QAAQ,CAAS,oBAAoB,CAAC,EAAzE,aAAa,QAAA,EAAE,gBAAgB,QAA0C,CAAC;IAEjF,IAAM,oBAAoB,GAAG,UAAC,QAAc;QAC1C,gBAAgB,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IACzC,CAAC,CAAC;IAEF,IAAM,mBAAmB,GAAG,UAAC,EAAkC;YAAhC,IAAI,UAAA;QACjC,IAAM,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACvC,eAAe,CAAC,aAAa,CAAC,CAAC;QAC/B,gBAAgB,CAAC,aAAa,CAAC,CAAC;QAChC,sBAAsB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC;IAEF,IAAM,SAAS,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,IAAI,SAAS,KAAK,KAAK,EAAE;QACvB,IAAI,KAAK,KAAK,EAAE,IAAI,YAAY,KAAK,KAAK,EAAE;YAC1C,eAAe,CAAC,KAAK,CAAC,CAAC;SACxB;QACD,+DAA+D;QAC/D,kEAAkE;QAClE,IAAI,KAAK,CAAC,MAAM,IAAI,CAAC,IAAI,aAAa,KAAK,KAAK,EAAE;YAChD,gBAAgB,CAAC,KAAK,CAAC,CAAC;SACzB;QACD,sEAAsE;QACtE,IAAI,KAAK,CAAC,MAAM,IAAI,EAAE,IAAI,YAAY,KAAK,KAAK,EAAE;YAChD,eAAe,CAAC,KAAK,CAAC,CAAC;SACxB;KACF;IAED,OAAO;QACL,oBAAoB,sBAAA;QACpB,aAAa,eAAA;QACb,gBAAgB,kBAAA;QAChB,YAAY,cAAA;QACZ,eAAe,iBAAA;QACf,oBAAoB,sBAAA;QACpB,mBAAmB,qBAAA;KACpB,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { useState } from 'react';\nimport { CalendarTypes } from './calendar/definitions';\nimport { formatDate } from './calendar/utils/date';\nimport { usePrevious } from '../internal/hooks/use-previous';\nimport { fireNonCancelableEvent, NonCancelableEventHandler } from '../internal/events';\nimport { DatePickerProps } from './interfaces';\n\nexport function useDatePicker({ value, onChange }: UseDatePickerProps) {\n const defaultSelectedDate = value.length >= 10 ? value : null;\n const [selectedDate, setSelectedDate] = useState<string | null>(defaultSelectedDate);\n\n const defaultDisplayedDate = value.length >= 10 ? value : formatDate(new Date());\n const [displayedDate, setDisplayedDate] = useState<string>(defaultDisplayedDate);\n\n const onChangeMonthHandler = (newMonth: Date) => {\n setDisplayedDate(formatDate(newMonth));\n };\n\n const onSelectDateHandler = ({ date }: CalendarTypes.DateDetail) => {\n const formattedDate = formatDate(date);\n setSelectedDate(formattedDate);\n setDisplayedDate(formattedDate);\n fireNonCancelableEvent(onChange, { value: formattedDate });\n };\n\n const prevValue = usePrevious(value);\n if (prevValue !== value) {\n if (value === '' && selectedDate !== value) {\n setSelectedDate(value);\n }\n // update the displayedDate when inputValue changes in order to\n // display the correct month when the date picker gets open again.\n if (value.length >= 4 && displayedDate !== value) {\n setDisplayedDate(value);\n }\n // set the selected date only when a full date (yyyy-mm-dd) is entered\n if (value.length >= 10 && selectedDate !== value) {\n setSelectedDate(value);\n }\n }\n\n return {\n defaultDisplayedDate,\n displayedDate,\n setDisplayedDate,\n selectedDate,\n setSelectedDate,\n onChangeMonthHandler,\n onSelectDateHandler,\n };\n}\n\nexport interface UseDatePickerProps {\n value: string;\n onChange: NonCancelableEventHandler<DatePickerProps.ChangeDetail> | undefined;\n}\n"]}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface FocusLockProps {
|
|
3
3
|
disabled?: boolean;
|
|
4
|
+
autoFocus?: boolean;
|
|
4
5
|
children: React.ReactNode;
|
|
5
6
|
}
|
|
6
|
-
export default function FocusLock({ disabled, children }: FocusLockProps): JSX.Element;
|
|
7
|
+
export default function FocusLock({ disabled, autoFocus, children }: FocusLockProps): JSX.Element;
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/index.tsx"],"names":[],"mappings":"AAEA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAIjD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,cAAc,eA4BlF"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import React, { useRef } from 'react';
|
|
3
|
+
import React, { useEffect, useRef } from 'react';
|
|
4
4
|
import TabTrap from '../tab-trap/index';
|
|
5
5
|
import { getFirstFocusable, getLastFocusable } from './utils';
|
|
6
6
|
export default function FocusLock(_a) {
|
|
7
|
-
var disabled = _a.disabled, children = _a.children;
|
|
7
|
+
var disabled = _a.disabled, autoFocus = _a.autoFocus, children = _a.children;
|
|
8
8
|
var containerRef = useRef(null);
|
|
9
9
|
var focusFirst = function () {
|
|
10
10
|
var _a;
|
|
@@ -18,6 +18,11 @@ export default function FocusLock(_a) {
|
|
|
18
18
|
(_a = getLastFocusable(containerRef.current)) === null || _a === void 0 ? void 0 : _a.focus();
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
+
useEffect(function () {
|
|
22
|
+
if (autoFocus) {
|
|
23
|
+
focusFirst();
|
|
24
|
+
}
|
|
25
|
+
}, [autoFocus]);
|
|
21
26
|
return (React.createElement(React.Fragment, null,
|
|
22
27
|
React.createElement(TabTrap, { disabled: disabled, focusNextCallback: focusLast }),
|
|
23
28
|
React.createElement("div", { ref: containerRef }, children),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/index.tsx"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,OAAO,MAAM,mBAAmB,CAAC;AACxC,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAQ9D,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAAiD;QAA/C,QAAQ,cAAA,EAAE,SAAS,eAAA,EAAE,QAAQ,cAAA;IAC/D,IAAM,YAAY,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAElD,IAAM,UAAU,GAAG;;QACjB,IAAI,YAAY,CAAC,OAAO,EAAE;YACxB,MAAA,iBAAiB,CAAC,YAAY,CAAC,OAAO,CAAC,0CAAE,KAAK,EAAE,CAAC;SAClD;IACH,CAAC,CAAC;IAEF,IAAM,SAAS,GAAG;;QAChB,IAAI,YAAY,CAAC,OAAO,EAAE;YACxB,MAAA,gBAAgB,CAAC,YAAY,CAAC,OAAO,CAAC,0CAAE,KAAK,EAAE,CAAC;SACjD;IACH,CAAC,CAAC;IAEF,SAAS,CAAC;QACR,IAAI,SAAS,EAAE;YACb,UAAU,EAAE,CAAC;SACd;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,OAAO,CACL;QACE,oBAAC,OAAO,IAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,SAAS,GAAI;QAC7D,6BAAK,GAAG,EAAE,YAAY,IAAG,QAAQ,CAAO;QACxC,oBAAC,OAAO,IAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,UAAU,GAAI,CAC7D,CACJ,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport React, { useEffect, useRef } from 'react';\nimport TabTrap from '../tab-trap/index';\nimport { getFirstFocusable, getLastFocusable } from './utils';\n\nexport interface FocusLockProps {\n disabled?: boolean;\n autoFocus?: boolean;\n children: React.ReactNode;\n}\n\nexport default function FocusLock({ disabled, autoFocus, children }: FocusLockProps) {\n const containerRef = useRef<HTMLDivElement>(null);\n\n const focusFirst = () => {\n if (containerRef.current) {\n getFirstFocusable(containerRef.current)?.focus();\n }\n };\n\n const focusLast = () => {\n if (containerRef.current) {\n getLastFocusable(containerRef.current)?.focus();\n }\n };\n\n useEffect(() => {\n if (autoFocus) {\n focusFirst();\n }\n }, [autoFocus]);\n\n return (\n <>\n <TabTrap disabled={disabled} focusNextCallback={focusLast} />\n <div ref={containerRef}>{children}</div>\n <TabTrap disabled={disabled} focusNextCallback={focusFirst} />\n </>\n );\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare function getFocusables(container: HTMLElement):
|
|
2
|
-
export declare function getFirstFocusable(container: HTMLElement):
|
|
3
|
-
export declare function getLastFocusable(container: HTMLElement):
|
|
1
|
+
export declare function getFocusables(container: HTMLElement): HTMLElement[];
|
|
2
|
+
export declare function getFirstFocusable(container: HTMLElement): HTMLElement;
|
|
3
|
+
export declare function getLastFocusable(container: HTMLElement): HTMLElement;
|
|
4
4
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/utils.ts"],"names":[],"mappings":"AA2BA,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/utils.ts"],"names":[],"mappings":"AA2BA,wBAAgB,aAAa,CAAC,SAAS,EAAE,WAAW,GAAG,WAAW,EAAE,CAInE;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,WAAW,eAGvD;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,WAAW,eAGtD"}
|
|
@@ -20,7 +20,9 @@ var tabbables = [
|
|
|
20
20
|
'[autofocus]',
|
|
21
21
|
].join(',');
|
|
22
22
|
export function getFocusables(container) {
|
|
23
|
-
return Array.prototype.slice
|
|
23
|
+
return Array.prototype.slice
|
|
24
|
+
.call(container.querySelectorAll(tabbables))
|
|
25
|
+
.filter(function (element) { return element.tabIndex !== -1; });
|
|
24
26
|
}
|
|
25
27
|
export function getFirstFocusable(container) {
|
|
26
28
|
var _a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/utils.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,aAAa;AACb,+GAA+G;AAC/G,IAAM,SAAS,GAAG;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;IAEf,SAAS;IACT,YAAY;IAEZ,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,OAAO;IAEP,iBAAiB;IACjB,iBAAiB;IAEjB,YAAY;IACZ,mBAAmB;IACnB,aAAa;CACd,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,UAAU,aAAa,CAAC,SAAsB;IAClD,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/internal/components/focus-lock/utils.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,aAAa;AACb,+GAA+G;AAC/G,IAAM,SAAS,GAAG;IAChB,gBAAgB;IAChB,gBAAgB;IAChB,kBAAkB;IAClB,eAAe;IAEf,SAAS;IACT,YAAY;IAEZ,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,OAAO;IAEP,iBAAiB;IACjB,iBAAiB;IAEjB,YAAY;IACZ,mBAAmB;IACnB,aAAa;CACd,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAEZ,MAAM,UAAU,aAAa,CAAC,SAAsB;IAClD,OAAO,KAAK,CAAC,SAAS,CAAC,KAAK;SACzB,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;SAC3C,MAAM,CAAC,UAAC,OAAoB,IAAK,OAAA,OAAO,CAAC,QAAQ,KAAK,CAAC,CAAC,EAAvB,CAAuB,CAAC,CAAC;AAC/D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,SAAsB;;IACtD,IAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAC5C,OAAO,MAAA,UAAU,CAAC,CAAC,CAAC,mCAAI,IAAI,CAAC;AAC/B,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,SAAsB;;IACrD,IAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC;IAC5C,OAAO,MAAA,UAAU,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,mCAAI,IAAI,CAAC;AACnD,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\n// Credits to\n// https://github.com/theKashey/focus-lock/blob/33f8b4bd9675d2605b15e2e4015b77fe35fbd6d0/src/utils/tabbables.ts\nconst tabbables = [\n 'button:enabled',\n 'select:enabled',\n 'textarea:enabled',\n 'input:enabled',\n\n 'a[href]',\n 'area[href]',\n\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n\n 'audio[controls]',\n 'video[controls]',\n\n '[tabindex]',\n '[contenteditable]',\n '[autofocus]',\n].join(',');\n\nexport function getFocusables(container: HTMLElement): HTMLElement[] {\n return Array.prototype.slice\n .call(container.querySelectorAll(tabbables))\n .filter((element: HTMLElement) => element.tabIndex !== -1);\n}\n\nexport function getFirstFocusable(container: HTMLElement) {\n const focusables = getFocusables(container);\n return focusables[0] ?? null;\n}\n\nexport function getLastFocusable(container: HTMLElement) {\n const focusables = getFocusables(container);\n return focusables[focusables.length - 1] ?? null;\n}\n"]}
|
package/internal/environment.js
CHANGED
package/link/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/link/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAStC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAUlF,QAAA,MAAM,YAAY;cAHJ,SAAS,CAAC,SAAS,CAAC,GAAG,gBAAgB,GAAG,MAAM,GAAG,UAAU;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../../src/link/internal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAiB,MAAM,OAAO,CAAC;AAStC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,sCAAsC,CAAC;AAUlF,QAAA,MAAM,YAAY;cAHJ,SAAS,CAAC,SAAS,CAAC,GAAG,gBAAgB,GAAG,MAAM,GAAG,UAAU;uCA+G1E,CAAC;AAqBF,eAAe,YAAY,CAAC"}
|
package/link/internal.js
CHANGED
|
@@ -35,13 +35,8 @@ var InternalLink = React.forwardRef(function (_a, ref) {
|
|
|
35
35
|
fireFollowEvent(event);
|
|
36
36
|
};
|
|
37
37
|
var handleButtonKeyDown = function (event) {
|
|
38
|
-
// Prevent the page from scrolling down when spacebar is pressed.
|
|
39
|
-
if (event.keyCode === KeyCode.space) {
|
|
40
|
-
event.preventDefault();
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
var handleButtonKeyUp = function (event) {
|
|
44
38
|
if (event.keyCode === KeyCode.space || event.keyCode === KeyCode.enter) {
|
|
39
|
+
event.preventDefault();
|
|
45
40
|
fireFollowEvent(event);
|
|
46
41
|
}
|
|
47
42
|
};
|
|
@@ -61,7 +56,7 @@ var InternalLink = React.forwardRef(function (_a, ref) {
|
|
|
61
56
|
React.createElement("span", { className: styles.icon, "aria-label": externalIconAriaLabel, role: externalIconAriaLabel ? 'img' : undefined },
|
|
62
57
|
React.createElement(InternalIcon, { name: "external", size: "inherit" }))))));
|
|
63
58
|
if (isButton) {
|
|
64
|
-
return (React.createElement("a", __assign({}, sharedProps, { role: "button", tabIndex: 0, onKeyDown: handleButtonKeyDown,
|
|
59
|
+
return (React.createElement("a", __assign({}, sharedProps, { role: "button", tabIndex: 0, onKeyDown: handleButtonKeyDown, onClick: handleButtonClick }), content));
|
|
65
60
|
}
|
|
66
61
|
return (
|
|
67
62
|
// we dynamically set proper rel in the code above
|
package/link/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../../../src/link/internal.tsx"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,YAAY,MAAM,kBAAkB,CAAC;AAC5C,OAAO,MAAM,MAAM,iBAAiB,CAAC;AACrC,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,eAAe,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAG9C,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EA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: Apache-2.0\nimport React, { useRef } from 'react';\nimport clsx from 'clsx';\nimport InternalIcon from '../icon/internal';\nimport styles from './styles.css.js';\nimport useFocusVisible from '../internal/hooks/focus-visible';\nimport { getBaseProps } from '../internal/base-component';\nimport { fireCancelableEvent, isPlainLeftClick } from '../internal/events';\nimport useForwardFocus from '../internal/hooks/forward-focus';\nimport { KeyCode } from '../internal/keycode';\nimport { LinkProps } from './interfaces';\nimport { InternalBaseComponentProps } from '../internal/hooks/use-base-component';\nimport { useMergeRefs } from '../internal/hooks/use-merge-refs';\nimport { useVisualRefresh } from '../internal/hooks/use-visual-mode';\nimport { checkSafeUrl } from '../internal/utils/check-safe-url';\n\ntype InternalLinkProps = InternalBaseComponentProps &\n Omit<LinkProps, 'variant'> & {\n variant?: LinkProps['variant'] | 'top-navigation' | 'link' | 'recovery';\n };\n\nconst InternalLink = React.forwardRef(\n (\n {\n variant = 'secondary',\n fontSize = 'body-m',\n color = 'normal',\n external = false,\n target,\n href,\n rel,\n ariaLabel,\n externalIconAriaLabel,\n onFollow,\n children,\n __internalRootRef = null,\n ...props\n }: InternalLinkProps,\n ref: React.Ref<LinkProps.Ref>\n ) => {\n checkSafeUrl('Link', href);\n const isButton = !href;\n const specialStyles = ['top-navigation', 'link', 'recovery'];\n const hasSpecialStyle = specialStyles.indexOf(variant) > -1;\n\n const focusVisible = useFocusVisible();\n const baseProps = getBaseProps(props);\n const anchorTarget = target ?? (external ? '_blank' : undefined);\n const anchorRel = rel ?? (anchorTarget === '_blank' ? 'noopener noreferrer' : undefined);\n\n const fireFollowEvent = (event: React.SyntheticEvent) => {\n fireCancelableEvent(onFollow, { href, external, target: anchorTarget }, event);\n };\n\n const handleLinkClick = (event: React.MouseEvent) => {\n if (isPlainLeftClick(event)) {\n fireFollowEvent(event);\n }\n };\n\n const handleButtonClick = (event: React.MouseEvent) => {\n fireFollowEvent(event);\n };\n\n const handleButtonKeyDown = (event: React.KeyboardEvent) => {\n if (event.keyCode === KeyCode.space || event.keyCode === KeyCode.enter) {\n event.preventDefault();\n fireFollowEvent(event);\n }\n };\n\n const linkRef = useRef<HTMLElement>(null);\n const isVisualRefresh = useVisualRefresh(linkRef);\n useForwardFocus(ref, linkRef);\n\n // Visual refresh should only add styles to buttons that don't already have unique styles (e.g. primary/secondary variants)\n const applyButtonStyles = isButton && isVisualRefresh && !hasSpecialStyle;\n\n const sharedProps = {\n ...focusVisible,\n ...baseProps,\n // https://github.com/microsoft/TypeScript/issues/36659\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ref: useMergeRefs(linkRef as any, __internalRootRef),\n className: clsx(\n styles.link,\n baseProps.className,\n applyButtonStyles ? styles.button : null,\n styles[getVariantStyle(variant)],\n styles[getFontSizeStyle(variant, fontSize)],\n styles[getColorStyle(variant, color)]\n ),\n 'aria-label': ariaLabel,\n };\n\n const content = (\n <>\n {children}\n {external && (\n <>\n {' '}\n <span\n className={styles.icon}\n aria-label={externalIconAriaLabel}\n role={externalIconAriaLabel ? 'img' : undefined}\n >\n <InternalIcon name=\"external\" size=\"inherit\" />\n </span>\n </>\n )}\n </>\n );\n\n if (isButton) {\n return (\n <a {...sharedProps} role=\"button\" tabIndex={0} onKeyDown={handleButtonKeyDown} onClick={handleButtonClick}>\n {content}\n </a>\n );\n }\n\n return (\n // we dynamically set proper rel in the code above\n // eslint-disable-next-line react/jsx-no-target-blank\n <a {...sharedProps} target={anchorTarget} rel={anchorRel} href={href} onClick={handleLinkClick}>\n {content}\n </a>\n );\n }\n);\n\nfunction getVariantStyle(variant: Exclude<InternalLinkProps['variant'], undefined>) {\n return `variant-${variant.replace(/^awsui-/, '')}`;\n}\n\nfunction getFontSizeStyle(variant: InternalLinkProps['variant'], fontSize: InternalLinkProps['fontSize']) {\n switch (variant) {\n case 'info':\n return 'font-size-body-s';\n case 'awsui-value-large':\n return 'font-size-display-l';\n default:\n return `font-size-${fontSize}`;\n }\n}\n\nfunction getColorStyle(variant: InternalLinkProps['variant'], color: InternalLinkProps['color']) {\n return `color-${variant === 'info' ? 'normal' : color}`;\n}\n\nexport default InternalLink;\n"]}
|