@homebound/beam 2.96.3 → 2.97.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from "react";
|
|
2
|
+
import { Modifier } from "react-day-picker";
|
|
2
3
|
import { TextFieldBaseProps } from "./TextFieldBase";
|
|
3
4
|
import "./DateField.css";
|
|
4
5
|
export interface DateFieldProps extends Pick<TextFieldBaseProps<{}>, "borderless" | "visuallyDisabled" | "hideLabel" | "compact"> {
|
|
@@ -19,6 +20,11 @@ export interface DateFieldProps extends Pick<TextFieldBaseProps<{}>, "borderless
|
|
|
19
20
|
placeholder?: string;
|
|
20
21
|
format?: keyof typeof dateFormats;
|
|
21
22
|
iconLeft?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Set custom logic for individual dates or date ranges to be disabled in the picker
|
|
25
|
+
* exposed from `react-day-picker`: https://react-day-picker.js.org/api/DayPicker#modifiers
|
|
26
|
+
*/
|
|
27
|
+
disabledDays?: Modifier;
|
|
22
28
|
}
|
|
23
29
|
export declare function DateField(props: DateFieldProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
24
30
|
declare const dateFormats: {
|
package/dist/inputs/DateField.js
CHANGED
|
@@ -16,7 +16,7 @@ const utils_1 = require("../utils");
|
|
|
16
16
|
const defaultTestId_1 = require("../utils/defaultTestId");
|
|
17
17
|
require("./DateField.css");
|
|
18
18
|
function DateField(props) {
|
|
19
|
-
const { label, disabled, required, value, onChange, onFocus, onBlur, errorMsg, helperText, inlineLabel = false, readOnly = false, format = "short", iconLeft = false, ...others } = props;
|
|
19
|
+
const { label, disabled, required, value, onChange, onFocus, onBlur, errorMsg, helperText, inlineLabel = false, readOnly = false, format = "short", iconLeft = false, disabledDays, ...others } = props;
|
|
20
20
|
const inputRef = (0, react_1.useRef)(null);
|
|
21
21
|
const inputWrapRef = (0, react_1.useRef)(null);
|
|
22
22
|
const buttonRef = (0, react_1.useRef)(null);
|
|
@@ -123,7 +123,7 @@ function DateField(props) {
|
|
|
123
123
|
}, endAdornment: !iconLeft && calendarButton, startAdornment: iconLeft && calendarButton, tooltip: isDisabled && typeof disabled !== "boolean" ? disabled : undefined }, others), void 0), state.isOpen && ((0, jsx_runtime_1.jsx)(internal_1.Popover, Object.assign({ triggerRef: inputWrapRef, popoverRef: overlayRef, positionProps: { ...overlayProps, ...positionProps }, onClose: state.close, isOpen: state.isOpen }, { children: (0, jsx_runtime_1.jsx)(DatePickerOverlay_1.DatePickerOverlay, Object.assign({ state: state, value: value, positionProps: positionProps, onChange: (d) => {
|
|
124
124
|
setInputValue(formatDate(d, dateFormat));
|
|
125
125
|
onChange(d);
|
|
126
|
-
} }, tid.datePicker), void 0) }), void 0))] }, void 0));
|
|
126
|
+
}, disabledDays: disabledDays }, tid.datePicker), void 0) }), void 0))] }, void 0));
|
|
127
127
|
}
|
|
128
128
|
exports.DateField = DateField;
|
|
129
129
|
function formatDate(date, format) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { Modifier } from "react-day-picker";
|
|
2
3
|
import { OverlayTriggerState } from "react-stately";
|
|
3
4
|
interface DatePickerOverlayProps {
|
|
4
5
|
value: Date | undefined;
|
|
5
6
|
state: OverlayTriggerState;
|
|
6
7
|
positionProps: React.HTMLAttributes<Element>;
|
|
7
8
|
onChange: (value: Date) => void;
|
|
9
|
+
disabledDays: Modifier;
|
|
8
10
|
}
|
|
9
11
|
export declare function DatePickerOverlay(props: DatePickerOverlayProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
10
12
|
export {};
|
|
@@ -11,7 +11,7 @@ const Css_1 = require("../../Css");
|
|
|
11
11
|
const utils_1 = require("../../utils");
|
|
12
12
|
function DatePickerOverlay(props) {
|
|
13
13
|
var _a;
|
|
14
|
-
const { value, state, positionProps, onChange } = props;
|
|
14
|
+
const { value, state, positionProps, onChange, disabledDays } = props;
|
|
15
15
|
// We define some spacing between the Calendar overlay and the trigger element, and depending on where the overlay renders (above or below) we need to adjust the spacing.
|
|
16
16
|
// We can determine if the position was flipped based on what style is defined, `top` (for positioned below the trigger), and `bottom` (for above the trigger).
|
|
17
17
|
// The above assumption regarding `top` and `bottom` is true as long as we use `bottom` as our default `OverlayPosition.placement` (set in DateField).
|
|
@@ -35,11 +35,17 @@ function DatePickerOverlay(props) {
|
|
|
35
35
|
"& .DayPicker-Day:active": Css_1.Css.bgGray400.$,
|
|
36
36
|
// Make the month title, i.e. "May 2021", match figma; pyPx nudge matches the NavbarElement nudging
|
|
37
37
|
"& .DayPicker-Caption > div": Css_1.Css.base.pyPx(2).$,
|
|
38
|
-
|
|
38
|
+
// For days that are disabled via `disabledDays`,
|
|
39
|
+
"& .DayPicker-Day--disabled": Css_1.Css.cursorNotAllowed.$,
|
|
40
|
+
// Override `.DayPicker-Day:active` background when the day is disabled
|
|
41
|
+
"& .DayPicker-Day--disabled:active": Css_1.Css.bgWhite.$,
|
|
42
|
+
} }, tid, { children: (0, jsx_runtime_1.jsx)(react_day_picker_1.default, { navbarElement: NavbarElement, weekdayElement: Weekday, selectedDays: [value], initialMonth: value !== null && value !== void 0 ? value : new Date(), onDayClick: (day, modifiers) => {
|
|
43
|
+
if (modifiers.disabled)
|
|
44
|
+
return;
|
|
39
45
|
// Set the day value, and close the picker.
|
|
40
46
|
onChange(day);
|
|
41
47
|
state.close();
|
|
42
|
-
} }, void 0) }), void 0));
|
|
48
|
+
}, disabledDays: disabledDays }, void 0) }), void 0));
|
|
43
49
|
}
|
|
44
50
|
exports.DatePickerOverlay = DatePickerOverlay;
|
|
45
51
|
/** Customize the prev/next button to be our SVG icons. */
|