@majoo-ui/react 2.4.6 → 2.4.8

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.
@@ -23,7 +23,6 @@ const ProductList = props => {
23
23
  return jsx(Tooltip, {
24
24
  label: tooltipLabel(name, variants),
25
25
  children: jsxs(Box, {
26
- gap: 2,
27
26
  css: Object.assign({
28
27
  display: 'flex',
29
28
  alignItems: 'center',
@@ -7,6 +7,7 @@ import MobileCalendar from './components/MobileCalendar.esm.js';
7
7
  import './components/DateNumber.esm.js';
8
8
  import './components/CalendarMulti.esm.js';
9
9
  import useMediaQuery from '../../utils/useMediaQuery.esm.js';
10
+ import { MonthRangeCalendar } from './components/MonthRangeCalendar.esm.js';
10
11
  import moment from 'moment';
11
12
  import { useMountedLayoutEffect } from 'react-table';
12
13
 
@@ -15,6 +16,7 @@ const SINGLE_PICKER = 'single';
15
16
  const RANGE_PICKER = 'range';
16
17
  const DATE_RANGE_PICKER = 'range_picker';
17
18
  const ADVANCE_PICKER = 'advance';
19
+ const MONTH_RANGE_PICKER = 'month_range';
18
20
  const RANGE_CONTROL = 'range_control';
19
21
  const WEEKLY = 'weekly';
20
22
  const MONTHLY = 'monthly';
@@ -245,6 +247,11 @@ const DatePicker = props => {
245
247
  type
246
248
  } = props,
247
249
  otherProps = __rest(props, ["type"]);
250
+ if (type === MONTH_RANGE_PICKER) {
251
+ return jsx(MonthRangeCalendar, Object.assign({}, otherProps, {
252
+ helper: otherProps.monthRangeHelper
253
+ }));
254
+ }
248
255
  const isDateRangePicker = type === DATE_RANGE_PICKER;
249
256
  if (type !== SINGLE_PICKER || isDateRangePicker) {
250
257
  return jsx(CalendarRangePicker, Object.assign({}, otherProps, {
@@ -254,4 +261,4 @@ const DatePicker = props => {
254
261
  return jsx(CalendarPicker, Object.assign({}, otherProps));
255
262
  };
256
263
 
257
- export { ADVANCE_PICKER, DATE_RANGE_PICKER, DEFAULT, DatePicker, MONTHLY, RANGE_CONTROL, RANGE_PICKER, SINGLE_PICKER, WEEKLY };
264
+ export { ADVANCE_PICKER, DATE_RANGE_PICKER, DEFAULT, DatePicker, MONTHLY, MONTH_RANGE_PICKER, RANGE_CONTROL, RANGE_PICKER, SINGLE_PICKER, WEEKLY };
@@ -8,7 +8,8 @@ import { InputGroup } from '../form/components/InputGroup/InputGroup.esm.js';
8
8
  import { InputLeftElement } from '../form/components/InputElement/InputElement.esm.js';
9
9
  import { InputText } from '../form/components/InputText/InputText.esm.js';
10
10
  import { AdvancedOption } from './AdvancedOption.esm.js';
11
- import { SINGLE_PICKER, WEEKLY, DatePicker, DATE_RANGE_PICKER, ADVANCE_PICKER } from './DatePicker.esm.js';
11
+ import { SINGLE_PICKER, MONTH_RANGE_PICKER, WEEKLY, DatePicker, DATE_RANGE_PICKER, ADVANCE_PICKER } from './DatePicker.esm.js';
12
+ import { MonthRangeCalendar, formatMonthRange } from './components/MonthRangeCalendar.esm.js';
12
13
  import { pickerReducer, UPDATE_PICKER, advancePickerDate, advancePickerOptionsId } from './state/reducer.esm.js';
13
14
  import moment from 'moment';
14
15
  import { ContainerDateRangePicker, InputDateRangePicker } from './InputDateRangePicker.esm.js';
@@ -17,8 +18,9 @@ import { useLocale } from '../../config/locale/LocaleContext.esm.js';
17
18
  import { useDatePickerLocaleText, localizeAdvanceOptions } from './locale.esm.js';
18
19
  import { Popover, PopoverTrigger, PopoverContent } from '../popover/Popover.esm.js';
19
20
 
20
- const getInputPickerValue = (type, date, isTimePicker) => {
21
+ const getInputPickerValue = (type, date, isTimePicker, language) => {
21
22
  if (!date) return '';
23
+ if (type === MONTH_RANGE_PICKER) return formatMonthRange(date, language);
22
24
  if (type === SINGLE_PICKER) {
23
25
  return `${moment(date).format(isTimePicker ? 'DD MMMM YYYY, HH:mm' : 'DD MMMM YYYY')}`;
24
26
  } else {
@@ -57,6 +59,8 @@ function InputDatePicker({
57
59
  drawerContentCss = {},
58
60
  isMobile = false,
59
61
  maxRange,
62
+ maxMonths,
63
+ monthRangeHelper,
60
64
  locale,
61
65
  localeText
62
66
  }) {
@@ -84,7 +88,7 @@ function InputDatePicker({
84
88
  });
85
89
  }
86
90
  }, [value]);
87
- const isMobileView = useMediaQuery(`(max-width: ${type === SINGLE_PICKER ? '480px' : '1090px'})`);
91
+ const isMobileView = useMediaQuery(`(max-width: ${type === SINGLE_PICKER || type === MONTH_RANGE_PICKER ? '480px' : '1090px'})`);
88
92
  function handleChange() {
89
93
  if (!disabled && !readOnly) {
90
94
  setOpenPicker(!openPicker);
@@ -124,7 +128,7 @@ function InputDatePicker({
124
128
  })
125
129
  }), jsx(InputText, {
126
130
  placeholder: placeholder || text.placeholder,
127
- value: getInputPickerValue(type, selectedDate, showTimePicker),
131
+ value: getInputPickerValue(type, selectedDate, showTimePicker, language),
128
132
  // eslint-disable-next-line @typescript-eslint/no-empty-function
129
133
  onChange: () => {},
130
134
  isPicker: true,
@@ -146,6 +150,30 @@ function InputDatePicker({
146
150
  }
147
151
  };
148
152
  const renderDatePicker = () => {
153
+ if (type === MONTH_RANGE_PICKER) {
154
+ return jsx(MonthRangeCalendar, {
155
+ selected: selectedDate,
156
+ minDate: minDate,
157
+ maxDate: maxDate,
158
+ maxMonths: maxMonths,
159
+ helper: monthRangeHelper,
160
+ disabled: disabled,
161
+ isMobile: isMobile || isMobileView,
162
+ onChange: value => {
163
+ dispatch({
164
+ type: UPDATE_PICKER,
165
+ payload: value
166
+ });
167
+ onChange === null || onChange === void 0 ? void 0 : onChange(value);
168
+ },
169
+ onClose: () => {
170
+ setOpenPicker(false);
171
+ onClose === null || onClose === void 0 ? void 0 : onClose();
172
+ },
173
+ locale: language,
174
+ localeText: localeText
175
+ });
176
+ }
149
177
  const handleDatePickerChange = value => {
150
178
  if (showRangeControl || type === 'range_picker') {
151
179
  if (rangePickerType === 'monthly') {
@@ -63,6 +63,10 @@ const ArrowButton = styled('button', {
63
63
  backgroundColor: '$bgBrand',
64
64
  color: '$bgWhite'
65
65
  },
66
+ // `all: unset` drops the browser focus outline.
67
+ '&:focus-visible': {
68
+ boxShadow: '0 0 0 2px $colors$borderFocus'
69
+ },
66
70
  cursor: 'pointer',
67
71
  '&:disabled': {
68
72
  backgroundColor: '$btnDisable',
@@ -111,15 +115,6 @@ const TitleButton = styled('p', {
111
115
  fontStyle: 'normal',
112
116
  fontSize: 16,
113
117
  color: '$textPrimary',
114
- '&:hover': {
115
- backgroundColor: '$bgSelectedLight',
116
- color: '$textBrand'
117
- },
118
- '&:active': {
119
- backgroundColor: '$bgBrand',
120
- color: '$bgWhite'
121
- },
122
- cursor: 'pointer',
123
118
  '&:disabled': {
124
119
  backgroundColor: '$btnDisable',
125
120
  color: '$iconDisable',
@@ -130,7 +125,23 @@ const TitleButton = styled('p', {
130
125
  true: {
131
126
  pointerEvents: 'none'
132
127
  }
128
+ },
129
+ clickable: {
130
+ true: {
131
+ '&:hover': {
132
+ backgroundColor: '$bgSelectedLight',
133
+ color: '$textBrand'
134
+ },
135
+ '&:active': {
136
+ backgroundColor: '$bgBrand',
137
+ color: '$bgWhite'
138
+ },
139
+ cursor: 'pointer'
140
+ }
133
141
  }
142
+ },
143
+ defaultVariants: {
144
+ clickable: true
134
145
  }
135
146
  });
136
147
  const MonthButton = styled(Text, {
@@ -645,4 +656,4 @@ const Calendar = ({
645
656
  return null;
646
657
  };
647
658
 
648
- export { DATE_PICKER, MONTH_PICKER, TIME_PICKER, YEAR_PICKER, YEAR_RANGE_PICKER, Calendar as default };
659
+ export { ArrowButton, DATE_PICKER, MONTH_PICKER, TIME_PICKER, TitleButton, YEAR_PICKER, YEAR_RANGE_PICKER, Calendar as default };
@@ -0,0 +1,259 @@
1
+ import 'core-js/modules/es.iterator.constructor.js';
2
+ import 'core-js/modules/es.iterator.map.js';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+ import { ChevronLeftOutline, ChevronRightOutline } from '@majoo-ui/icons';
5
+ import moment from 'moment';
6
+ import { useState } from 'react';
7
+ import { Button } from '../../button/Button.esm.js';
8
+ import Paragraph from '../../paragraph/Paragraph.esm.js';
9
+ import { Separator } from '../../separator/Separator.esm.js';
10
+ import { styled } from '../../../config/stitches.config.esm.js';
11
+ import Box from '../../../layout/box/Box.esm.js';
12
+ import Flex from '../../../layout/flex/Flex.esm.js';
13
+ import { monthNamesFullEng, monthNamesFullId } from '../../../utils/calendar.esm.js';
14
+ import { useLocale } from '../../../config/locale/LocaleContext.esm.js';
15
+ import { useDatePickerLocaleText } from '../locale.esm.js';
16
+ import { ArrowButton, TitleButton } from './Calendar.esm.js';
17
+
18
+ // A month is handled as `year * 12 + month`, so ranges compare and add as plain integers. Reading the
19
+ // date through moment also takes the moment objects, timestamps and date strings JS callers pass.
20
+ const toMonthIndex = date => {
21
+ const value = moment(date);
22
+ return value.year() * 12 + value.month();
23
+ };
24
+ const yearOf = index => Math.floor(index / 12);
25
+ const monthStart = index => new Date(yearOf(index), index % 12, 1);
26
+ const monthEnd = index => moment(monthStart(index)).endOf('month').toDate();
27
+ const getMonthNames = language => language === 'en' ? monthNamesFullEng : monthNamesFullId;
28
+ /**
29
+ * `Jul 2027 - Des 2027`, or `Jul 2027` when the range is a single month. The short names come from moment,
30
+ * like the dates the other picker types show, so August reads `Agt` in all of them.
31
+ */
32
+ const formatMonthRange = (value, language = 'id') => {
33
+ if (!(value === null || value === void 0 ? void 0 : value[0])) return '';
34
+ const label = date => moment(date).locale(language).format('MMM YYYY');
35
+ const start = label(value[0]);
36
+ const end = value[1] ? label(value[1]) : start;
37
+ return start === end ? start : `${start} - ${end}`;
38
+ };
39
+ const MonthCell = styled('button', {
40
+ all: 'unset',
41
+ boxSizing: 'border-box',
42
+ width: '70px',
43
+ textAlign: 'center',
44
+ borderRadius: '$md',
45
+ padding: '$spacing-03 0',
46
+ // Same type scale as the month view of the day calendar (Calendar's MonthButton).
47
+ fontSize: '$label',
48
+ lineHeight: '$label',
49
+ letterSpacing: '$label',
50
+ fontWeight: 400,
51
+ color: '$textBrand',
52
+ cursor: 'pointer',
53
+ '&:hover': {
54
+ backgroundColor: '$btnHoverSecondary'
55
+ },
56
+ '&:focus-visible': {
57
+ boxShadow: '0 0 0 2px $colors$borderFocus'
58
+ },
59
+ '&:disabled': {
60
+ color: '$textDisable',
61
+ backgroundColor: 'transparent',
62
+ cursor: 'default'
63
+ },
64
+ // A month outside minDate / maxDate can still lie in the applied range, so the range look also wins
65
+ // over `:disabled`, as it does in the day calendar.
66
+ variants: {
67
+ state: {
68
+ idle: {},
69
+ between: {
70
+ backgroundColor: '$bgAccent',
71
+ color: '$textPrimary',
72
+ '&:hover, &:disabled': {
73
+ backgroundColor: '$bgAccent',
74
+ color: '$textPrimary'
75
+ }
76
+ },
77
+ edge: {
78
+ backgroundColor: '$bgBrand',
79
+ color: '$textWhite',
80
+ '&:hover': {
81
+ backgroundColor: '$btnHoverPrimary'
82
+ },
83
+ '&:disabled': {
84
+ backgroundColor: '$bgBrand',
85
+ color: '$textWhite'
86
+ }
87
+ }
88
+ }
89
+ },
90
+ defaultVariants: {
91
+ state: 'idle'
92
+ }
93
+ });
94
+ const MonthRangeCalendar = ({
95
+ selected,
96
+ minDate,
97
+ maxDate,
98
+ maxMonths,
99
+ helper,
100
+ disabled,
101
+ isMobile,
102
+ onChange,
103
+ onClose,
104
+ locale,
105
+ localeText
106
+ }) => {
107
+ const language = useLocale(locale);
108
+ const text = useDatePickerLocaleText(language, localeText);
109
+ const monthNames = getMonthNames(language);
110
+ const defaultHelper = typeof text.monthRangeHelper === 'function' ? text.monthRangeHelper({
111
+ maxMonths
112
+ }) : text.monthRangeHelper;
113
+ const minIndex = minDate ? toMonthIndex(minDate) : -Infinity;
114
+ const maxIndex = maxDate ? toMonthIndex(maxDate) : Infinity;
115
+ const [draft, setDraft] = useState(() => {
116
+ var _a;
117
+ return (selected === null || selected === void 0 ? void 0 : selected[0]) ? {
118
+ start: toMonthIndex(selected[0]),
119
+ end: toMonthIndex((_a = selected[1]) !== null && _a !== void 0 ? _a : selected[0])
120
+ } : {};
121
+ });
122
+ const [year, setYear] = useState(() => {
123
+ if (selected === null || selected === void 0 ? void 0 : selected[0]) return yearOf(toMonthIndex(selected[0]));
124
+ const thisYear = new Date().getFullYear();
125
+ if (yearOf(minIndex) > thisYear) return yearOf(minIndex);
126
+ if (yearOf(maxIndex) < thisYear) return yearOf(maxIndex);
127
+ return thisYear;
128
+ });
129
+ const {
130
+ start,
131
+ end
132
+ } = draft;
133
+ const pickingEndFrom = start !== undefined && end === undefined ? start : undefined;
134
+ const lastEnd = pickingEndFrom !== undefined && maxMonths ? pickingEndFrom + maxMonths - 1 : Infinity;
135
+ const isMonthDisabled = index => disabled || index < minIndex || index > maxIndex || index > lastEnd;
136
+ const pickMonth = index => {
137
+ // A month before the chosen start restarts the range instead of closing it backwards.
138
+ if (pickingEndFrom !== undefined && index >= pickingEndFrom) setDraft({
139
+ start: pickingEndFrom,
140
+ end: index
141
+ });else setDraft({
142
+ start: index
143
+ });
144
+ };
145
+ const getState = index => {
146
+ if (index === start || index === end) return 'edge';
147
+ if (start !== undefined && end !== undefined && index > start && index < end) return 'between';
148
+ return 'idle';
149
+ };
150
+ const apply = () => {
151
+ if (start === undefined || end === undefined) return;
152
+ onChange === null || onChange === void 0 ? void 0 : onChange([monthStart(start), monthEnd(end)]);
153
+ onClose === null || onClose === void 0 ? void 0 : onClose();
154
+ };
155
+ return jsxs(Box, {
156
+ css: {
157
+ // In a popover the month grid sets the width and the helper text wraps under it.
158
+ width: isMobile ? '100%' : 'min-content',
159
+ boxSizing: 'border-box',
160
+ backgroundColor: '$bgWhite',
161
+ borderRadius: '$lg',
162
+ boxShadow: '0px 4px 8px rgba(0, 0, 0, 0.12)',
163
+ padding: '$spacing-05'
164
+ },
165
+ children: [jsxs(Box, {
166
+ css: {
167
+ border: '1px solid $bgBorder',
168
+ borderRadius: '$lg',
169
+ boxShadow: '0px 1px 4px rgba(0, 0, 0, 0.06)',
170
+ padding: '$spacing-03'
171
+ },
172
+ children: [jsxs(Flex, {
173
+ justify: "between",
174
+ align: "center",
175
+ children: [jsx(ArrowButton, {
176
+ type: "button",
177
+ "aria-label": text.previousYearLabel,
178
+ disabled: disabled || year * 12 <= minIndex,
179
+ onClick: () => setYear(year - 1),
180
+ children: jsx(ChevronLeftOutline, {
181
+ color: "currentColor"
182
+ })
183
+ }), jsx(TitleButton, {
184
+ clickable: false,
185
+ "aria-live": "polite",
186
+ children: year
187
+ }), jsx(ArrowButton, {
188
+ type: "button",
189
+ "aria-label": text.nextYearLabel,
190
+ disabled: disabled || year * 12 + 11 >= maxIndex,
191
+ onClick: () => setYear(year + 1),
192
+ children: jsx(ChevronRightOutline, {
193
+ color: "currentColor"
194
+ })
195
+ })]
196
+ }), jsx(Separator, {
197
+ css: {
198
+ my: '$spacing-03'
199
+ }
200
+ }), jsx(Box, {
201
+ css: {
202
+ display: 'grid',
203
+ gridTemplateColumns: 'repeat(3, 70px)',
204
+ width: 'max-content',
205
+ marginInline: 'auto',
206
+ gridRowGap: '$spacing-05',
207
+ gridColumnGap: '$spacing-04',
208
+ padding: '6px 4px 8px 4px'
209
+ },
210
+ children: monthNames.map((name, month) => {
211
+ const index = year * 12 + month;
212
+ const state = getState(index);
213
+ return jsx(MonthCell, {
214
+ type: "button",
215
+ state: state,
216
+ "aria-pressed": state !== 'idle',
217
+ disabled: isMonthDisabled(index),
218
+ onClick: () => pickMonth(index),
219
+ children: name
220
+ }, name);
221
+ })
222
+ })]
223
+ }), helper !== null && jsx(Paragraph, {
224
+ paragraph: "shortContentRegular",
225
+ color: "secondary",
226
+ css: {
227
+ mt: '$spacing-05'
228
+ },
229
+ children: helper !== null && helper !== void 0 ? helper : defaultHelper
230
+ }), jsxs(Flex, {
231
+ justify: "end",
232
+ gap: 3,
233
+ css: {
234
+ mt: '$spacing-05'
235
+ },
236
+ children: [jsx(Button, {
237
+ type: "button",
238
+ size: "sm",
239
+ buttonType: "ghost",
240
+ css: {
241
+ fontWeight: 600
242
+ },
243
+ onClick: onClose,
244
+ children: text.cancelButton
245
+ }), jsx(Button, {
246
+ type: "button",
247
+ size: "sm",
248
+ css: {
249
+ fontWeight: 600
250
+ },
251
+ disabled: disabled || start === undefined || end === undefined,
252
+ onClick: apply,
253
+ children: text.applyButton
254
+ })]
255
+ })]
256
+ });
257
+ };
258
+
259
+ export { MonthRangeCalendar, formatMonthRange, getMonthNames };
@@ -29,14 +29,30 @@ const defaultDatePickerLocaleText = {
29
29
  dateUntilLabel: 'Hingga Tanggal',
30
30
  timeFromLabel: 'Dari Pukul',
31
31
  timeUntilLabel: 'Hingga Pukul',
32
- advanceOptions: toLabels(advancePickerOptionsId)
32
+ advanceOptions: toLabels(advancePickerOptionsId),
33
+ applyButton: 'Terapkan',
34
+ monthRangeHelper: ({
35
+ maxMonths
36
+ }) => maxMonths ? `Pilih bulan mulai dan akhir. Maksimal ${maxMonths} bulan.` : 'Pilih bulan mulai dan akhir.',
37
+ previousYearLabel: 'Tahun sebelumnya',
38
+ nextYearLabel: 'Tahun berikutnya'
39
+ };
40
+ // The month range texts are newer than the `MajooUI/datePicker` locale files, so no app translates
41
+ // them yet; English gets its own defaults the same way the quick range labels do.
42
+ const monthRangeLocaleTextEn = {
43
+ applyButton: 'Apply',
44
+ monthRangeHelper: ({
45
+ maxMonths
46
+ }) => maxMonths ? `Pick the start and end months. At most ${maxMonths} months.` : 'Pick the start and end months.',
47
+ previousYearLabel: 'Previous year',
48
+ nextYearLabel: 'Next year'
33
49
  };
34
50
  // Transitional: keeps apps that still ship `MajooUI/datePicker` locale files translated until they pass
35
51
  // `localeText`, and keeps the English quick range labels for `en`. Remove together with the
36
52
  // react-i18next dependency of the date picker family.
37
53
  const i18nDatePickerLocaleText = (t, locale) => {
38
54
  const d = defaultDatePickerLocaleText;
39
- return {
55
+ return Object.assign({
40
56
  placeholder: t('datePickerPlaceholder', d.placeholder),
41
57
  cancelButton: t('label.cancel', d.cancelButton, {
42
58
  ns: 'translation'
@@ -62,8 +78,12 @@ const i18nDatePickerLocaleText = (t, locale) => {
62
78
  dateUntilLabel: t('dateUntilLabel', d.dateUntilLabel),
63
79
  timeFromLabel: t('timeFromLabel', d.timeFromLabel),
64
80
  timeUntilLabel: t('timeUntilLabel', d.timeUntilLabel),
65
- advanceOptions: locale === 'en' ? toLabels(advancePickerOptionsEn) : d.advanceOptions
66
- };
81
+ advanceOptions: locale === 'en' ? toLabels(advancePickerOptionsEn) : d.advanceOptions,
82
+ applyButton: d.applyButton,
83
+ monthRangeHelper: d.monthRangeHelper,
84
+ previousYearLabel: d.previousYearLabel,
85
+ nextYearLabel: d.nextYearLabel
86
+ }, locale === 'en' && monthRangeLocaleTextEn);
67
87
  };
68
88
  const definedEntries = obj => obj ? Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined)) : {};
69
89
  /** Later sources win; an `undefined` value never erases an earlier one. */
@@ -229,7 +229,16 @@ const CloseButton = styled(DialogPrimitive.Close, {
229
229
  backgroundColor: '#FAFAFA'
230
230
  }
231
231
  });
232
- const DrawerContent = ({
232
+ const DrawerContent = (
233
+ /**
234
+ * @type {{
235
+ * children?: import('react').ReactNode,
236
+ * side?: 'top' | 'left' | 'bottom' | 'right',
237
+ * showOverlay?: boolean,
238
+ * [key: string]: any,
239
+ * }}
240
+ */
241
+ {
233
242
  children,
234
243
  showOverlay,
235
244
  ...props
@@ -310,7 +319,6 @@ Drawer.propTypes = {
310
319
  };
311
320
  DrawerContent.propTypes = {
312
321
  side: PropTypes.oneOf(['top', 'left', 'bottom', 'right']),
313
- isMobile: PropTypes.bool,
314
322
  showOverlay: PropTypes.bool
315
323
  };
316
324
  DrawerContent.defaultProps = {
@@ -259,7 +259,15 @@ const setRef = (ref, node) => {
259
259
 
260
260
  // forwardRef because DropdownMenuPortal renders its child through Radix's `Portal asChild`,
261
261
  // which hands that child a ref; a plain function component would drop it with a warning.
262
- const DropdownMenuContentContext = /*#__PURE__*/React__default.forwardRef(({
262
+ // Cast rather than a JSDoc @param on the render function, which forwardRef would flatten (see InputText).
263
+ const DropdownMenuContentContext =
264
+ /*#__PURE__*/
265
+ /**
266
+ * @type {React.ForwardRefExoticComponent<
267
+ * { theme?: string, [key: string]: any } & React.RefAttributes<HTMLDivElement>
268
+ * >}
269
+ */
270
+ React__default.forwardRef(({
263
271
  theme = 'default',
264
272
  ...props
265
273
  }, forwardedRef) => {
@@ -295,7 +303,14 @@ DropdownMenuContentContext.propTypes = {
295
303
  };
296
304
 
297
305
  // Radix positions submenus itself, so this only carries the theme class across the portal.
298
- const DropdownMenuSubContentContext = /*#__PURE__*/React__default.forwardRef(({
306
+ const DropdownMenuSubContentContext =
307
+ /*#__PURE__*/
308
+ /**
309
+ * @type {React.ForwardRefExoticComponent<
310
+ * { theme?: string, children?: React.ReactNode, [key: string]: any } & React.RefAttributes<HTMLDivElement>
311
+ * >}
312
+ */
313
+ React__default.forwardRef(({
299
314
  theme = 'default',
300
315
  children,
301
316
  ...props
@@ -186,7 +186,28 @@ function getMaxValueLength(maxValue, prefix = '', suffix = '', thousandSeparator
186
186
  const tsLength = thousandSeparator ? countThousandSeparatorsByLength(maxValue) : 0;
187
187
  return maxValue + prefix?.length + suffix?.length + tsLength;
188
188
  }
189
- const InputNumber = /*#__PURE__*/React__default.forwardRef(({
189
+
190
+ // Cast rather than a JSDoc @param on the render function, which forwardRef would flatten (see InputText).
191
+ // The ref reaches the NumberFormat instance, not the <input> (that is getInputRef), so it stays untyped.
192
+ const InputNumber =
193
+ /*#__PURE__*/
194
+ /**
195
+ * @type {React.ForwardRefExoticComponent<{
196
+ * placeholder?: string,
197
+ * value?: string | number,
198
+ * size?: 'sm' | 'md' | 'lg',
199
+ * isInvalid?: boolean,
200
+ * readOnly?: boolean,
201
+ * disabled?: boolean,
202
+ * control?: object,
203
+ * name?: string,
204
+ * maxValueLength?: number,
205
+ * maxLength?: number,
206
+ * thousandSeparator?: boolean | string,
207
+ * [key: string]: any,
208
+ * } & React.RefAttributes<unknown>>}
209
+ */
210
+ React__default.forwardRef(({
190
211
  placeholder,
191
212
  value,
192
213
  size,
@@ -232,7 +253,7 @@ const InputNumber = /*#__PURE__*/React__default.forwardRef(({
232
253
  InputNumber.propTypes = {
233
254
  placeholder: PropTypes.string,
234
255
  value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
235
- size: PropTypes.oneOf(['sm', 'lg']),
256
+ size: PropTypes.oneOf(['sm', 'md', 'lg']),
236
257
  isInvalid: PropTypes.bool,
237
258
  readOnly: PropTypes.bool,
238
259
  disabled: PropTypes.bool
@@ -13,7 +13,26 @@ import { jsxs, jsx } from 'react/jsx-runtime';
13
13
  const {
14
14
  colors
15
15
  } = foundations;
16
- const InputSearchbox = ({
16
+ const InputSearchbox = (
17
+ /**
18
+ * @type {{
19
+ * placeholder?: string,
20
+ * value?: string,
21
+ * size?: 'sm' | 'lg',
22
+ * isInvalid?: boolean,
23
+ * readOnly?: boolean,
24
+ * disabled?: boolean,
25
+ * onChange?: Function,
26
+ * withDebounce?: boolean,
27
+ * defaultValue?: string,
28
+ * mobileOnly?: boolean,
29
+ * desktopOnly?: boolean,
30
+ * css?: object,
31
+ * localeText?: Partial<import('./locale').InputSearchboxLocaleText>,
32
+ * [key: string]: any,
33
+ * }}
34
+ */
35
+ {
17
36
  size,
18
37
  onChange,
19
38
  css,
@@ -170,7 +170,19 @@ const StyledInput = styled('input', {
170
170
  size: 'lg'
171
171
  }
172
172
  });
173
- const InputText = /*#__PURE__*/React__default.forwardRef(({
173
+
174
+ // Untyped forwardRef render props make TS call sites accept nothing but `ref`, and a JSDoc @param on the
175
+ // render function does not help: forwardRef's PropsWithoutRef flattens a props type with an index signature
176
+ // to `{ [key: string]: any }`. Casting the result keeps disabled/readOnly checked and the rest open, matching
177
+ // the spread onto StyledInput.
178
+ const InputText =
179
+ /*#__PURE__*/
180
+ /**
181
+ * @type {React.ForwardRefExoticComponent<
182
+ * { disabled?: boolean, readOnly?: boolean, [key: string]: any } & React.RefAttributes<HTMLInputElement>
183
+ * >}
184
+ */
185
+ React__default.forwardRef(({
174
186
  disabled,
175
187
  readOnly,
176
188
  ...props
@@ -40,7 +40,25 @@ const StyledImage = styled('img', {
40
40
  }
41
41
  }
42
42
  });
43
- function Image({
43
+ function Image(
44
+ /**
45
+ * @type {{
46
+ * className?: string,
47
+ * src?: string,
48
+ * alt?: string,
49
+ * css?: object,
50
+ * cssFallback?: object,
51
+ * width?: string | number,
52
+ * height?: string | number,
53
+ * rounded?: boolean,
54
+ * objectFit?: string,
55
+ * fallback?: string,
56
+ * fallbackTitle?: string,
57
+ * localeText?: Partial<import('./locale').ImageLocaleText>,
58
+ * [key: string]: any,
59
+ * }}
60
+ */
61
+ {
44
62
  className,
45
63
  src,
46
64
  alt,
@@ -145,7 +145,17 @@ Popover.propTypes = {
145
145
  onOpenChange: PropTypes.func,
146
146
  placement: PropTypes.oneOf(['top', 'top-start', 'top-end', 'right', 'right-start', 'right-end', 'bottom', 'bottom-start', 'bottom-end', 'left', 'left-start', 'left-end']),
147
147
  sideOffset: PropTypes.number,
148
- hideOnScroll: PropTypes.bool
148
+ hideOnScroll: PropTypes.bool,
149
+ flip: PropTypes.bool,
150
+ onClose: PropTypes.func
151
+ };
152
+ PopoverTrigger.propTypes = {
153
+ disabled: PropTypes.bool
154
+ };
155
+ PopoverContent.propTypes = {
156
+ isMobile: PropTypes.bool,
157
+ style: PropTypes.object,
158
+ portalled: PropTypes.bool
149
159
  };
150
160
  Popover.displayName = 'Popover';
151
161
 
@@ -229,7 +229,17 @@ function TableOfContent({
229
229
  const StyledPage = styled(Box, {
230
230
  maxWidth: 982
231
231
  });
232
- const Page = /*#__PURE__*/forwardRef((props, ref) => /*#__PURE__*/jsx(StyledPage, {
232
+
233
+ // ScrollSpy's props pass straight through; index.tsx documents them as ScrollSpyProps. Cast rather than a
234
+ // JSDoc @param on the render function, which forwardRef would flatten (see InputText).
235
+ const Page =
236
+ /*#__PURE__*/
237
+ /**
238
+ * @type {React.ForwardRefExoticComponent<
239
+ * { children?: React.ReactNode, [key: string]: any } & React.RefAttributes<HTMLDivElement>
240
+ * >}
241
+ */
242
+ forwardRef((props, ref) => /*#__PURE__*/jsx(StyledPage, {
233
243
  ref: ref,
234
244
  children: /*#__PURE__*/jsx(ScrollSpy, {
235
245
  ...props
@@ -99,7 +99,26 @@ const StyledIconLeft = styled('div', {
99
99
  alignItems: 'center',
100
100
  color: 'inherit'
101
101
  });
102
- const Tag = /*#__PURE__*/React__default.forwardRef(({
102
+
103
+ // Cast rather than a JSDoc @param on the render function, which forwardRef would flatten (see InputText).
104
+ const Tag =
105
+ /*#__PURE__*/
106
+ /**
107
+ * @type {React.ForwardRefExoticComponent<{
108
+ * className?: string,
109
+ * children?: React.ReactNode,
110
+ * onClick?: Function,
111
+ * size?: string,
112
+ * icon?: React.ReactNode,
113
+ * isRemovable?: boolean,
114
+ * disabled?: boolean,
115
+ * type?: string,
116
+ * onRemove?: Function,
117
+ * readOnly?: boolean,
118
+ * [key: string]: any,
119
+ * } & React.RefAttributes<HTMLDivElement>>}
120
+ */
121
+ React__default.forwardRef(({
103
122
  className,
104
123
  children,
105
124
  onClick,
@@ -109,7 +109,22 @@ const darkArrow = {
109
109
  const lightArrow = {
110
110
  fill: foundations.colors.bgWhite
111
111
  };
112
- const Tooltip = ({
112
+ // The props are typed on the parameter: Storybook shows a /** */ block above a component as its description.
113
+ const Tooltip = (
114
+ /**
115
+ * @type {{
116
+ * children?: import('react').ReactNode,
117
+ * label?: import('react').ReactNode,
118
+ * color?: string,
119
+ * css?: object,
120
+ * withClick?: boolean,
121
+ * side?: 'top' | 'bottom' | 'right' | 'left',
122
+ * align?: 'start' | 'center' | 'end',
123
+ * delayDuration?: number,
124
+ * [key: string]: any,
125
+ * }}
126
+ */
127
+ {
113
128
  children,
114
129
  label,
115
130
  color,
package/index.esm.css CHANGED
@@ -1,3 +1,7 @@
1
+ .recharts-pie-sector {
2
+ outline: none;
3
+ }
4
+
1
5
  .rdw-option-wrapper {
2
6
  padding: 5px;
3
7
  min-width: 25px;
@@ -1045,10 +1049,6 @@
1045
1049
  counter-reset: ol4;
1046
1050
  }
1047
1051
 
1048
- .recharts-pie-sector {
1049
- outline: none;
1050
- }
1051
-
1052
1052
  .ReactCrop {
1053
1053
  position: relative;
1054
1054
  display: inline-block;
package/index.esm.js CHANGED
@@ -43,7 +43,7 @@ export { default as Dialog, DialogClose, DialogContent, DialogDescription, Dialo
43
43
  export { default as ModalDialog, ModalDialogContent, ModalDialogDescription, ModalDialogFooter, ModalDialogTitle, ModalDialogTrigger } from './components/modalDialog/ModalDialog.esm.js';
44
44
  export { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from './components/accordion/Accordion.esm.js';
45
45
  export { InputDatePicker } from './components/datePicker/InputDatePicker.esm.js';
46
- export { ADVANCE_PICKER, DATE_RANGE_PICKER, DEFAULT, DatePicker, MONTHLY, RANGE_CONTROL, RANGE_PICKER, SINGLE_PICKER, WEEKLY } from './components/datePicker/DatePicker.esm.js';
46
+ export { ADVANCE_PICKER, DATE_RANGE_PICKER, DEFAULT, DatePicker, MONTHLY, MONTH_RANGE_PICKER, RANGE_CONTROL, RANGE_PICKER, SINGLE_PICKER, WEEKLY } from './components/datePicker/DatePicker.esm.js';
47
47
  export { CustomDatePicker } from './components/datePicker/CustomDatePicker.esm.js';
48
48
  export { AdvancedOption } from './components/datePicker/AdvancedOption.esm.js';
49
49
  export { LAST_30_DAYS, LAST_7_DAYS, LAST_MONTH, LAST_TWO_MONTHS, LAST_WEEK, NEXT_MONTH, NEXT_WEEK, PREV_MONTH, PREV_WEEK, RANGE_MONTH, RANGE_WEEK, THIS_MONTH, THIS_WEEK, TODAY, UPDATE_PICKER, YESTERDAY, advancePickerDate, advancePickerOptionsEn, advancePickerOptionsId, pickerReducer } from './components/datePicker/state/reducer.esm.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@majoo-ui/react",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
4
4
  "main": "./index.esm.js",
5
5
  "sideEffects": [
6
6
  "*.css",
@@ -36,7 +36,7 @@
36
36
  "dependencies": {
37
37
  "@floating-ui/react": "^0.19.2",
38
38
  "@majoo-ui/core": "1.32.0",
39
- "@majoo-ui/helpers": "1.30.9",
39
+ "@majoo-ui/helpers": "1.30.10",
40
40
  "@majoo-ui/icons": "1.40.5",
41
41
  "@monsonjeremy/react-leaflet": "^3.2.2",
42
42
  "@radix-ui/react-accordion": "^1.0.0",
@@ -4,6 +4,7 @@ export declare const SINGLE_PICKER: "single";
4
4
  export declare const RANGE_PICKER: "range";
5
5
  export declare const DATE_RANGE_PICKER: "range_picker";
6
6
  export declare const ADVANCE_PICKER: "advance";
7
+ export declare const MONTH_RANGE_PICKER: "month_range";
7
8
  export declare const RANGE_CONTROL: "range_control";
8
9
  export declare const WEEKLY: "weekly";
9
10
  export declare const MONTHLY: "monthly";
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ADVANCE_PICKER, RANGE_PICKER, SINGLE_PICKER, WEEKLY, MONTHLY, DATE_RANGE_PICKER } from './DatePicker';
2
+ import { ADVANCE_PICKER, RANGE_PICKER, SINGLE_PICKER, WEEKLY, MONTHLY, DATE_RANGE_PICKER, MONTH_RANGE_PICKER } from './DatePicker';
3
3
  import { CSS } from '../../config/stitches.config';
4
4
  import { PopoverPlacement } from '../../type/base.types';
5
5
  import { DatePickerLocaleText } from './locale';
@@ -45,7 +45,7 @@ export interface InputDatePickerProps {
45
45
  /**
46
46
  * Specify the DatePicker type.
47
47
  */
48
- type?: typeof SINGLE_PICKER | typeof RANGE_PICKER | typeof DATE_RANGE_PICKER | typeof ADVANCE_PICKER;
48
+ type?: typeof SINGLE_PICKER | typeof RANGE_PICKER | typeof DATE_RANGE_PICKER | typeof ADVANCE_PICKER | typeof MONTH_RANGE_PICKER;
49
49
  /**
50
50
  * Show input range control state.
51
51
  */
@@ -166,6 +166,15 @@ export interface InputDatePickerProps {
166
166
  * Max range date picker in days
167
167
  */
168
168
  maxRange?: number;
169
+ /**
170
+ * Longest range of a `month_range` picker, in months, counting both ends.
171
+ */
172
+ maxMonths?: number;
173
+ /**
174
+ * Helper text below the month grid of a `month_range` picker. Wins over `localeText.monthRangeHelper`;
175
+ * pass `null` to hide it.
176
+ */
177
+ monthRangeHelper?: React.ReactNode;
169
178
  /**
170
179
  * Language of the month and weekday names and the picked dates. Falls back to `MajooProvider`'s
171
180
  * `locale`, then the app's i18next language, then `id`.
@@ -177,5 +186,5 @@ export interface InputDatePickerProps {
177
186
  */
178
187
  localeText?: Partial<DatePickerLocaleText>;
179
188
  }
180
- export declare function InputDatePicker({ type, showRangeControl, rangePickerType, placeholder, size, disabled, onChange, onDateSelected, defaultValue: defaultDateValue, value: dateValue, defaultDate, date, advanceView, placement, css, showTimePicker, timePickerProps, minDate, maxDate, readOnly, isInvalid, allowReset, portalled, portalledMobile, onClose, mobileOnly, desktopOnly, drawerCss, drawerContentCss, isMobile, maxRange, locale, localeText, }: InputDatePickerProps): JSX.Element;
189
+ export declare function InputDatePicker({ type, showRangeControl, rangePickerType, placeholder, size, disabled, onChange, onDateSelected, defaultValue: defaultDateValue, value: dateValue, defaultDate, date, advanceView, placement, css, showTimePicker, timePickerProps, minDate, maxDate, readOnly, isInvalid, allowReset, portalled, portalledMobile, onClose, mobileOnly, desktopOnly, drawerCss, drawerContentCss, isMobile, maxRange, maxMonths, monthRangeHelper, locale, localeText, }: InputDatePickerProps): JSX.Element;
181
190
  export {};
@@ -0,0 +1,27 @@
1
+ import React from 'react';
2
+ import { DatePickerLocaleText } from '../locale';
3
+ export declare const getMonthNames: (language: string) => any;
4
+ /**
5
+ * `Jul 2027 - Des 2027`, or `Jul 2027` when the range is a single month. The short names come from moment,
6
+ * like the dates the other picker types show, so August reads `Agt` in all of them.
7
+ */
8
+ export declare const formatMonthRange: (value: Date[] | undefined, language?: string) => string;
9
+ export interface MonthRangeCalendarProps {
10
+ /** The applied range: the first day of the start month and the last moment of the end month. */
11
+ selected?: Date[];
12
+ minDate?: Date;
13
+ maxDate?: Date;
14
+ /** Longest range allowed, in months, counting both ends. */
15
+ maxMonths?: number;
16
+ /** Replaces `localeText.monthRangeHelper`; `null` hides the helper. */
17
+ helper?: React.ReactNode;
18
+ disabled?: boolean;
19
+ /** Fills the width of the mobile drawer instead of shrinking to the month grid. */
20
+ isMobile?: boolean;
21
+ onChange?: (value: Date[]) => void;
22
+ onClose?: () => void;
23
+ locale?: string;
24
+ localeText?: Partial<DatePickerLocaleText>;
25
+ }
26
+ export declare const MonthRangeCalendar: ({ selected, minDate, maxDate, maxMonths, helper, disabled, isMobile, onChange, onClose, locale, localeText, }: MonthRangeCalendarProps) => JSX.Element;
27
+ export default MonthRangeCalendar;
@@ -27,6 +27,14 @@ export interface DatePickerLocaleText {
27
27
  timeFromLabel: string;
28
28
  timeUntilLabel: string;
29
29
  advanceOptions: DatePickerAdvanceOptionLabels;
30
+ /** Confirm button of the month range picker. */
31
+ applyButton: string;
32
+ /** Helper below the month grid. A function gets `maxMonths`, which is unset when the range is unlimited. */
33
+ monthRangeHelper: string | ((params: {
34
+ maxMonths?: number;
35
+ }) => string);
36
+ previousYearLabel: string;
37
+ nextYearLabel: string;
30
38
  }
31
39
  export declare const defaultDatePickerLocaleText: DatePickerLocaleText;
32
40
  export declare const i18nDatePickerLocaleText: (t: any, locale: MajooLocale) => DatePickerLocaleText;
@@ -1,43 +0,0 @@
1
- import { RenderProps } from 'dayzed';
2
- import React, { Dispatch, SetStateAction } from 'react';
3
- import { CSS } from '../../../config/stitches.config';
4
- import { DatePickerLocaleText } from '../locale';
5
- export declare const DATE_PICKER = 0;
6
- export declare const MONTH_PICKER = 1;
7
- export declare const YEAR_PICKER = 2;
8
- export declare const YEAR_RANGE_PICKER = 3;
9
- export declare const TIME_PICKER = 4;
10
- export interface CalendarProps extends RenderProps {
11
- advanceView?: React.ReactNode;
12
- onCalendarDateChange: (date: Date) => void;
13
- onIsMultiDateChange?: (isMultiDate: boolean) => void;
14
- onUpdate?: () => void;
15
- onCancel: () => void;
16
- onReset?: () => void;
17
- selected?: Date[];
18
- containerStyle?: CSS;
19
- disabled?: boolean;
20
- showTimePicker?: boolean;
21
- renderTimePicker?: () => React.ReactNode;
22
- minDate?: Date;
23
- maxDate?: Date;
24
- allowReset?: boolean;
25
- onSetDateValue?: Dispatch<SetStateAction<Date[]>>;
26
- maxRange?: number;
27
- overMaxRange?: boolean;
28
- timePickerProps?: {
29
- minDate?: Date;
30
- };
31
- /**
32
- * Language of the month and weekday names and the picked dates. Falls back to `MajooProvider`'s
33
- * `locale`, then the app's i18next language, then `id`.
34
- */
35
- locale?: string;
36
- /**
37
- * Texts of this calendar. Keys left unset fall back to `MajooProvider`'s `localeText.datePicker`,
38
- * then to the Indonesian defaults (`defaultDatePickerLocaleText`).
39
- */
40
- localeText?: Partial<DatePickerLocaleText>;
41
- }
42
- declare const Calendar: ({ calendars, getDateProps, advanceView, onCalendarDateChange, onIsMultiDateChange, onUpdate, onCancel, onReset, selected, containerStyle, disabled, showTimePicker, renderTimePicker, minDate, maxDate, allowReset, onSetDateValue, maxRange, overMaxRange, timePickerProps, locale, localeText, }: CalendarProps) => JSX.Element | null;
43
- export default Calendar;