@majoo-ui/react 2.4.5 → 2.4.7

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.
@@ -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') {
@@ -291,7 +319,7 @@ function InputDatePicker({
291
319
  overflow: 'hidden',
292
320
  clip: 'rect(0 0 0 0)'
293
321
  },
294
- children: t('label.selectDate', 'Pilih tanggal')
322
+ children: text.drawerTitle
295
323
  }), renderDatePicker()]
296
324
  })
297
325
  })]
@@ -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 };
@@ -22,20 +22,37 @@ const defaultDatePickerLocaleText = {
22
22
  maxRange
23
23
  }) => `Maksimal range adalah ${maxRange} hari`,
24
24
  selectRangeToggle: 'Pilih Rentang Waktu',
25
+ drawerTitle: 'Pilih tanggal',
25
26
  dateLabel: 'Tanggal',
26
27
  timeLabel: 'Waktu',
27
28
  dateFromLabel: 'Dari Tanggal',
28
29
  dateUntilLabel: 'Hingga Tanggal',
29
30
  timeFromLabel: 'Dari Pukul',
30
31
  timeUntilLabel: 'Hingga Pukul',
31
- 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'
32
49
  };
33
50
  // Transitional: keeps apps that still ship `MajooUI/datePicker` locale files translated until they pass
34
51
  // `localeText`, and keeps the English quick range labels for `en`. Remove together with the
35
52
  // react-i18next dependency of the date picker family.
36
53
  const i18nDatePickerLocaleText = (t, locale) => {
37
54
  const d = defaultDatePickerLocaleText;
38
- return {
55
+ return Object.assign({
39
56
  placeholder: t('datePickerPlaceholder', d.placeholder),
40
57
  cancelButton: t('label.cancel', d.cancelButton, {
41
58
  ns: 'translation'
@@ -54,14 +71,19 @@ const i18nDatePickerLocaleText = (t, locale) => {
54
71
  maxRange
55
72
  }),
56
73
  selectRangeToggle: t('selectTimeRangeText', d.selectRangeToggle),
74
+ drawerTitle: t('label.selectDate', d.drawerTitle),
57
75
  dateLabel: t('label.date', d.dateLabel),
58
76
  timeLabel: t('time', d.timeLabel),
59
77
  dateFromLabel: t('dateFromLabel', d.dateFromLabel),
60
78
  dateUntilLabel: t('dateUntilLabel', d.dateUntilLabel),
61
79
  timeFromLabel: t('timeFromLabel', d.timeFromLabel),
62
80
  timeUntilLabel: t('timeUntilLabel', d.timeUntilLabel),
63
- advanceOptions: locale === 'en' ? toLabels(advancePickerOptionsEn) : d.advanceOptions
64
- };
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);
65
87
  };
66
88
  const definedEntries = obj => obj ? Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined)) : {};
67
89
  /** Later sources win; an `undefined` value never erases an earlier one. */
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.5",
3
+ "version": "2.4.7",
4
4
  "main": "./index.esm.js",
5
5
  "sideEffects": [
6
6
  "*.css",
@@ -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;
@@ -16,6 +16,8 @@ export interface DatePickerLocaleText {
16
16
  }) => string;
17
17
  /** Mobile toggle that shows the quick range options. */
18
18
  selectRangeToggle: string;
19
+ /** Title of the mobile drawer, read by screen readers only. */
20
+ drawerTitle: string;
19
21
  /** Time picker labels of a single picker. */
20
22
  dateLabel: string;
21
23
  timeLabel: string;
@@ -25,6 +27,14 @@ export interface DatePickerLocaleText {
25
27
  timeFromLabel: string;
26
28
  timeUntilLabel: string;
27
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;
28
38
  }
29
39
  export declare const defaultDatePickerLocaleText: DatePickerLocaleText;
30
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;