@moneyforward/mfui-components 3.5.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/DateTimeSelection/MonthRangePicker/MonthRangePicker.d.ts +1 -1
- package/dist/src/DateTimeSelection/MonthRangePicker/MonthRangePicker.js +11 -2
- package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePicker.d.ts +1 -1
- package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePicker.js +2 -2
- package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePicker.types.d.ts +28 -0
- package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerProvider/BaseRangePickerProvider.js +7 -2
- package/dist/src/DateTimeSelection/shared/BaseRangePicker/BaseRangePickerProvider/BaseRangePickerProvider.types.d.ts +20 -0
- package/package.json +4 -4
|
@@ -14,4 +14,4 @@ import { type MonthRangePickerProps } from './MonthRangePicker.types';
|
|
|
14
14
|
* />
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
|
-
export declare function MonthRangePicker({ format, minMonth, maxMonth, startInputProps, endInputProps, ...restProps }: MonthRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare function MonthRangePicker({ format, minMonth, maxMonth, startInputProps, endInputProps, initialDisplayedMonths, ...restProps }: MonthRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -29,8 +29,17 @@ import { MonthRangePickerPanel } from './MonthRangePickerPanel';
|
|
|
29
29
|
* />
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
export function MonthRangePicker({ format = 'YYYY/MM', minMonth, maxMonth, startInputProps = {}, endInputProps = {}, ...restProps }) {
|
|
33
|
-
|
|
32
|
+
export function MonthRangePicker({ format = 'YYYY/MM', minMonth, maxMonth, startInputProps = {}, endInputProps = {}, initialDisplayedMonths, ...restProps }) {
|
|
33
|
+
// MonthRangePicker panels are grouped by year (left = viewingYear, right = viewingYear + 1).
|
|
34
|
+
// When `previousAndCurrent` is requested, we must shift by a full year so the left panel
|
|
35
|
+
// shows the previous year instead of the current year.
|
|
36
|
+
const initialViewingDate = initialDisplayedMonths === 'previousAndCurrent' && !restProps.value && !restProps.defaultValue
|
|
37
|
+
? (() => {
|
|
38
|
+
const today = new Date();
|
|
39
|
+
return new Date(today.getFullYear() - 1, 0, 1);
|
|
40
|
+
})()
|
|
41
|
+
: undefined;
|
|
42
|
+
return (_jsx(BaseRangePicker, { ...restProps, format: format, initialDisplayedMonths: initialDisplayedMonths, initialViewingDate: initialViewingDate, startInputProps: {
|
|
34
43
|
placeholder: '開始月',
|
|
35
44
|
...startInputProps,
|
|
36
45
|
}, endInputProps: {
|
|
@@ -3,4 +3,4 @@ import { type BaseRangePickerProps } from './BaseRangePicker.types';
|
|
|
3
3
|
* BaseRangePicker component
|
|
4
4
|
* A generic component for selecting a range of dates with configurable format
|
|
5
5
|
*/
|
|
6
|
-
export declare function BaseRangePicker({ value, defaultValue, disabled, invalid, targetDOMNode, onChange, format, onOpenStateChanged, disableAutoOpen, onBlur, allowedPlacements, enableViewportConstraint, enableClearButton, clearButtonProps, minDate, maxDate, enableAutoUnmount, minWidth, renderPopoverContent, startInputProps, endInputProps, calendarLocale, }: BaseRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare function BaseRangePicker({ value, defaultValue, disabled, invalid, targetDOMNode, onChange, format, onOpenStateChanged, disableAutoOpen, onBlur, allowedPlacements, enableViewportConstraint, enableClearButton, clearButtonProps, minDate, maxDate, enableAutoUnmount, minWidth, renderPopoverContent, startInputProps, endInputProps, calendarLocale, initialDisplayedMonths, initialViewingDate, }: BaseRangePickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -61,12 +61,12 @@ function InternalBaseRangePicker({ startInputRef, endInputRef, disabled, invalid
|
|
|
61
61
|
* BaseRangePicker component
|
|
62
62
|
* A generic component for selecting a range of dates with configurable format
|
|
63
63
|
*/
|
|
64
|
-
export function BaseRangePicker({ value, defaultValue, disabled, invalid, targetDOMNode, onChange, format = 'YYYY/MM/DD', onOpenStateChanged, disableAutoOpen = false, onBlur, allowedPlacements, enableViewportConstraint, enableClearButton = false, clearButtonProps, minDate, maxDate, enableAutoUnmount = true, minWidth, renderPopoverContent, startInputProps, endInputProps, calendarLocale = 'ja', }) {
|
|
64
|
+
export function BaseRangePicker({ value, defaultValue, disabled, invalid, targetDOMNode, onChange, format = 'YYYY/MM/DD', onOpenStateChanged, disableAutoOpen = false, onBlur, allowedPlacements, enableViewportConstraint, enableClearButton = false, clearButtonProps, minDate, maxDate, enableAutoUnmount = true, minWidth, renderPopoverContent, startInputProps, endInputProps, calendarLocale = 'ja', initialDisplayedMonths, initialViewingDate, }) {
|
|
65
65
|
const { isOpen, open, close } = useDisclosure({ value: false });
|
|
66
66
|
const startInputRef = useRef(null);
|
|
67
67
|
const endInputRef = useRef(null);
|
|
68
68
|
// Default renderPopoverContent implementation for backward compatibility
|
|
69
69
|
const defaultRenderPopoverContent = useCallback(() => _jsx(BaseRangePickerPopover, { calendarLocale: calendarLocale }), [calendarLocale]);
|
|
70
70
|
const finalRenderPopoverContent = renderPopoverContent ?? defaultRenderPopoverContent;
|
|
71
|
-
return (_jsx(BaseRangePickerProvider, { value: value, defaultValue: defaultValue, disabled: disabled, format: format, isOpen: isOpen, open: open, close: close, disableAutoOpen: disableAutoOpen, minDate: minDate, maxDate: maxDate, onChange: onChange, children: _jsx(InternalBaseRangePicker, { startInputRef: startInputRef, endInputRef: endInputRef, disabled: disabled, invalid: invalid, format: format, enableClearButton: enableClearButton, clearButtonProps: clearButtonProps, targetDOMNode: targetDOMNode, allowedPlacements: allowedPlacements, enableViewportConstraint: enableViewportConstraint, enableAutoUnmount: enableAutoUnmount, minWidth: minWidth, startInputProps: startInputProps, endInputProps: endInputProps, isOpen: isOpen, open: open, close: close, renderPopoverContent: finalRenderPopoverContent, calendarLocale: calendarLocale, onBlur: onBlur, onOpenStateChanged: onOpenStateChanged }) }));
|
|
71
|
+
return (_jsx(BaseRangePickerProvider, { value: value, defaultValue: defaultValue, disabled: disabled, format: format, isOpen: isOpen, open: open, close: close, disableAutoOpen: disableAutoOpen, minDate: minDate, maxDate: maxDate, initialDisplayedMonths: initialDisplayedMonths, initialViewingDate: initialViewingDate, onChange: onChange, children: _jsx(InternalBaseRangePicker, { startInputRef: startInputRef, endInputRef: endInputRef, disabled: disabled, invalid: invalid, format: format, enableClearButton: enableClearButton, clearButtonProps: clearButtonProps, targetDOMNode: targetDOMNode, allowedPlacements: allowedPlacements, enableViewportConstraint: enableViewportConstraint, enableAutoUnmount: enableAutoUnmount, minWidth: minWidth, startInputProps: startInputProps, endInputProps: endInputProps, isOpen: isOpen, open: open, close: close, renderPopoverContent: finalRenderPopoverContent, calendarLocale: calendarLocale, onBlur: onBlur, onOpenStateChanged: onOpenStateChanged }) }));
|
|
72
72
|
}
|
|
@@ -270,4 +270,32 @@ export type BaseRangePickerProps = {
|
|
|
270
270
|
* @default 'ja'
|
|
271
271
|
*/
|
|
272
272
|
calendarLocale?: BasePickerProps['calendarLocale'];
|
|
273
|
+
/**
|
|
274
|
+
* Controls which months are initially displayed in the two-panel calendar view.
|
|
275
|
+
* - `'currentAndNext'`: Shows current month on the left and next month on the right (default behavior).
|
|
276
|
+
* - `'previousAndCurrent'`: Shows previous month on the left and current month on the right.
|
|
277
|
+
* Useful for log date range selection where showing future months is not meaningful.
|
|
278
|
+
*
|
|
279
|
+
* This prop only affects the initial view when no `value` or `defaultValue` is provided.
|
|
280
|
+
* When a `value` or `defaultValue` is set, the calendar will show the months containing the selected dates.
|
|
281
|
+
*
|
|
282
|
+
* @default 'currentAndNext'
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```tsx
|
|
286
|
+
* // Show previous month + current month for log date selection
|
|
287
|
+
* <DateRangePicker initialDisplayedMonths="previousAndCurrent" />
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
initialDisplayedMonths?: 'currentAndNext' | 'previousAndCurrent';
|
|
291
|
+
/**
|
|
292
|
+
* Overrides the computed initial viewing date derived from `initialDisplayedMonths`.
|
|
293
|
+
* Use this when the component operates at a different granularity than months
|
|
294
|
+
* (e.g., MonthRangePicker uses years for panel navigation).
|
|
295
|
+
*
|
|
296
|
+
* This prop only affects the initial view when no `value` or `defaultValue` is provided.
|
|
297
|
+
*
|
|
298
|
+
* @internal
|
|
299
|
+
*/
|
|
300
|
+
initialViewingDate?: Date;
|
|
273
301
|
};
|
|
@@ -63,7 +63,7 @@ function autoCompletePartialRange(dates) {
|
|
|
63
63
|
}
|
|
64
64
|
return dates;
|
|
65
65
|
}
|
|
66
|
-
const useBaseRangePickerContextValue = ({ value, defaultValue, disabled = false, onChange, format = 'YYYY/MM/DD', isOpen = false, open = noop, close = noop, disableAutoOpen, minDate, maxDate, }) => {
|
|
66
|
+
const useBaseRangePickerContextValue = ({ value, defaultValue, disabled = false, onChange, format = 'YYYY/MM/DD', isOpen = false, open = noop, close = noop, disableAutoOpen, minDate, maxDate, initialDisplayedMonths = 'currentAndNext', initialViewingDate, }) => {
|
|
67
67
|
const [dates, setDates] = useTransformedState(defaultValue ?? [undefined, undefined], normalizeToStartOfDay);
|
|
68
68
|
const [dateStrings, setDateStrings] = useState(() => {
|
|
69
69
|
const [startDate, endDate] = value ?? defaultValue ?? [undefined, undefined];
|
|
@@ -73,7 +73,12 @@ const useBaseRangePickerContextValue = ({ value, defaultValue, disabled = false,
|
|
|
73
73
|
const [startDateString, endDateString] = dateStrings;
|
|
74
74
|
// Add viewingMonth state
|
|
75
75
|
const today = useMemo(() => new Date(), []);
|
|
76
|
-
const [viewingMonth, setViewingMonth] = useTransformedState(value?.[0] ??
|
|
76
|
+
const [viewingMonth, setViewingMonth] = useTransformedState(value?.[0] ??
|
|
77
|
+
defaultValue?.[0] ??
|
|
78
|
+
initialViewingDate ??
|
|
79
|
+
(initialDisplayedMonths === 'previousAndCurrent'
|
|
80
|
+
? new Date(today.getFullYear(), today.getMonth() - 1, 1)
|
|
81
|
+
: new Date(today.getFullYear(), today.getMonth(), 1)), normalizeToFirstOfMonth);
|
|
77
82
|
// --- Selection/Preview State and Logic ---
|
|
78
83
|
const [selecting, setSelecting] = useState('start');
|
|
79
84
|
const [temporaryStart, setTemporaryStart] = useState(startDate);
|
|
@@ -77,4 +77,24 @@ export type BaseRangePickerProviderProps = {
|
|
|
77
77
|
* @default undefined
|
|
78
78
|
*/
|
|
79
79
|
maxDate?: Date;
|
|
80
|
+
/**
|
|
81
|
+
* Controls which months are initially displayed in the two-panel calendar view.
|
|
82
|
+
* - `'currentAndNext'`: Shows current month on the left and next month on the right (default behavior).
|
|
83
|
+
* - `'previousAndCurrent'`: Shows previous month on the left and current month on the right.
|
|
84
|
+
*
|
|
85
|
+
* This prop only affects the initial view when no `value` or `defaultValue` is provided.
|
|
86
|
+
*
|
|
87
|
+
* @default 'currentAndNext'
|
|
88
|
+
*/
|
|
89
|
+
initialDisplayedMonths?: 'currentAndNext' | 'previousAndCurrent';
|
|
90
|
+
/**
|
|
91
|
+
* Overrides the computed initial viewing date derived from `initialDisplayedMonths`.
|
|
92
|
+
* Use this when the component operates at a different granularity than months
|
|
93
|
+
* (e.g., MonthRangePicker uses years).
|
|
94
|
+
*
|
|
95
|
+
* This prop only affects the initial view when no `value` or `defaultValue` is provided.
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
*/
|
|
99
|
+
initialViewingDate?: Date;
|
|
80
100
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneyforward/mfui-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.0",
|
|
4
4
|
"description": "React UI Component Library for all Money Forward products",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"jsdom": "26.1.0",
|
|
48
48
|
"react": "19.2.3",
|
|
49
49
|
"react-dom": "19.2.3",
|
|
50
|
-
"storybook": "9.1.
|
|
50
|
+
"storybook": "9.1.19",
|
|
51
51
|
"ts-node": "10.9.2",
|
|
52
52
|
"tsx": "4.21.0",
|
|
53
53
|
"vitest": "3.2.4"
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@floating-ui/react-dom": "^2.1.2",
|
|
61
61
|
"@tanstack/react-virtual": "^3.13.18",
|
|
62
62
|
"dayjs": "^1.11.13",
|
|
63
|
-
"@moneyforward/mfui-
|
|
64
|
-
"@moneyforward/mfui-
|
|
63
|
+
"@moneyforward/mfui-icons-react": "^3.0.0",
|
|
64
|
+
"@moneyforward/mfui-design-tokens": "^3.0.0"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
67
|
"prepare:panda": "panda codegen",
|