Skip to content

Commit 5a2abd7

Browse files
committed
chore: implement ui for Date picker and Date range picker for mobile screen
1 parent f1f872d commit 5a2abd7

96 files changed

Lines changed: 593 additions & 484 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ui/dashboard/src/@locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"yes": "Yes",
3838
"no": "No",
3939
"if": "IF",
40+
"is": "is",
4041
"clear": "Clear",
4142
"confirm": "Confirm",
4243
"close": "Close",

ui/dashboard/src/@locales/ja/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"yes": "はい",
3939
"no": "いいえ",
4040
"if": "IF",
41+
"is": "",
4142
"clear": "クリア",
4243
"confirm": "確認",
4344
"close": "閉じる",

ui/dashboard/src/app/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const Root = memo(() => {
145145
const authToken = getTokenStorage();
146146
const [pageKey, setPageKey] = useState<string>(uuid());
147147
const [showMenu, setShowMenu] = useState<boolean>(false);
148-
const { fromMobileScreen } = useScreen();
148+
const { isMobile } = useScreen();
149149
const { isInitialLoading, isLogin, consoleAccount, myOrganizations } =
150150
useAuth();
151151

@@ -176,15 +176,16 @@ export const Root = memo(() => {
176176
</Button>
177177
)}
178178
</div>
179-
{fromMobileScreen ? (
179+
{!isMobile ? (
180180
<Navigation onClickNavLink={handleChangePageKey} />
181181
) : (
182182
<Drawer
183183
side="left"
184184
open={showMenu}
185185
onClose={() => setShowMenu(false)}
186+
className="!z-30"
186187
>
187-
<Navigation onClickNavLink={handleChangePageKey} />
188+
<Navigation onClickNavLink={handleChangePageKey} forceExpanded />
188189
</Drawer>
189190
)}
190191

ui/dashboard/src/components/date-range-picker/customize-date-range-picker.css

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,53 @@
160160
}
161161

162162
.rdrCalendarWrapper {
163-
@apply sm:!w-[645px]
163+
@apply !w-full sm:!w-[645px];
164+
}
165+
166+
@media (max-width: 599px) {
167+
.rdrDateRangePickerWrapper {
168+
display: flex;
169+
width: 100% !important;
170+
}
171+
172+
.rdrCalendarWrapper {
173+
font-size: 11px;
174+
}
175+
176+
.range__months {
177+
@apply p-3;
178+
}
179+
180+
.range__weekDay {
181+
@apply !h-5 !text-[10px];
182+
}
183+
184+
.range__days--day {
185+
@apply !min-h-[34px];
186+
}
187+
188+
.range__days--number {
189+
@apply !size-[34px] !text-[11px];
190+
}
191+
192+
.rdrStartEdge,
193+
.rdrEndEdge {
194+
@apply !size-[34px];
195+
}
196+
197+
.range__days--dayPreview {
198+
@apply !h-[34px];
199+
}
200+
201+
.rdrDateDisplayWrapper {
202+
@apply !mx-3 !mt-8;
203+
}
204+
205+
.rdrDateInput input {
206+
@apply !h-9 !text-xs !p-2 !pr-8;
207+
}
208+
209+
.rdrDateInput:last-child {
210+
@apply !ml-2;
211+
}
164212
}

ui/dashboard/src/components/date-range-picker/customize-navigator.tsx

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { StaticRangeOption } from '.';
1010
interface Props {
1111
currFocusedDate: Date;
1212
staticRanges: StaticRangeOption[];
13+
selectedLabel?: string;
1314
handleStaticRangeClick: (range: StaticRangeOption) => void;
1415
changeShownDate: (
1516
value: Date | number | string,
@@ -30,6 +31,7 @@ const CustomizeNavigator = memo(
3031
({
3132
currFocusedDate,
3233
staticRanges,
34+
selectedLabel,
3335
handleStaticRangeClick,
3436
changeShownDate
3537
}: Props) => {
@@ -48,20 +50,19 @@ const CustomizeNavigator = memo(
4850

4951
return (
5052
<div className={cn('w-full relative z-[1000] p-5 pb-0')}>
51-
<div className="md:hidden w-full max-w-[350px] sm:max-w-[570px] mb-3">
52-
<div className="w-[350px] sm:w-[570px] overflow-x-scroll flex items-center gap-x-3 ">
53-
{staticRanges.map(staticRange => (
54-
<div
55-
key={staticRange.label}
56-
onClick={() =>
57-
handleStaticRangeClick(staticRange as StaticRangeOption)
58-
}
59-
className="w-[120px] bg-gray-100 py-2 px-3 rounded-full text-nowrap typo-para-medium text-gray-700"
60-
>
61-
{staticRange.label}
62-
</div>
63-
))}
64-
</div>
53+
<div className="md:hidden w-full mb-3">
54+
<Dropdown
55+
options={staticRanges.map(r => ({
56+
label: r.label,
57+
value: r.label
58+
}))}
59+
value={selectedLabel ?? ''}
60+
onChange={value => {
61+
const found = staticRanges.find(r => r.label === value);
62+
if (found) handleStaticRangeClick(found);
63+
}}
64+
isExpand
65+
/>
6566
</div>
6667
<div className="flex items-center justify-between w-full border-b border-gray-200 pb-5">
6768
<Button

ui/dashboard/src/components/date-range-picker/index.tsx

Lines changed: 108 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ import en from 'date-fns/locale/en-US';
66
import ja from 'date-fns/locale/ja';
77
import dayjs from 'dayjs';
88
import { useToggleOpen } from 'hooks';
9+
import { useScreen } from 'hooks/use-screen';
910
import { getLanguage, useTranslation } from 'i18n';
1011
import { formatLongDateTime } from 'utils/date-time';
1112
import { cn } from 'utils/style';
1213
import { IconCalendar } from '@icons';
1314
import { truncNumber } from 'pages/audit-logs/utils';
1415
import Button from 'components/button';
16+
import Drawer from 'components/drawer';
1517
import Icon from 'components/icon';
1618
import DialogModal from 'components/modal/dialog';
1719
import ActionBar from './action-bar';
@@ -131,6 +133,7 @@ export const ReactDateRangePicker = memo<ReactDateRangePickerProps>(
131133
}) => {
132134
const { t } = useTranslation(['common']);
133135
const isLanguageJapanese = getLanguage() === 'ja';
136+
const { isMobile } = useScreen();
134137

135138
const [isOpenRangePicker, onOpenRangePicker, onCloseRangePicker] =
136139
useToggleOpen(false);
@@ -259,6 +262,85 @@ export const ReactDateRangePicker = memo<ReactDateRangePickerProps>(
259262
useEffect(() => {
260263
getTriggerLabel?.(triggerLabel ?? '');
261264
}, [triggerLabel]);
265+
266+
const pickerContent = (
267+
<>
268+
<ReactDateRangePickerComp
269+
{...props}
270+
onChange={item => {
271+
setRange(item.selection);
272+
onRangeChange?.(item.selection);
273+
}}
274+
showPreview={showPreview}
275+
moveRangeOnFirstSelection={moveRangeOnFirstSelection}
276+
months={months}
277+
ranges={[range]}
278+
direction={direction}
279+
rangeColors={rangeColors}
280+
staticRanges={staticRanges}
281+
showDateDisplay={showDateDisplay}
282+
dateDisplayFormat="yyyy/MM/dd"
283+
inputRanges={[]}
284+
renderStaticRangeLabel={staticRange => (
285+
<div
286+
onClick={() =>
287+
setStaticRangeSelected(staticRange as StaticRangeOption)
288+
}
289+
className={cn('hidden md:flex items-center md:size-full pl-3', {
290+
'range-selected': staticRange.isSelected(range)
291+
})}
292+
>
293+
{staticRange.label}
294+
</div>
295+
)}
296+
dayContentRenderer={date => (
297+
<span
298+
onClick={() => setStaticRangeSelected(undefined)}
299+
style={{ width: '100%', height: '100%' }}
300+
className={cn('flex-center size-full', {
301+
'range__days--all-time':
302+
staticRangeSelected?.type === 'all-time'
303+
})}
304+
>
305+
{date.getDate()}
306+
</span>
307+
)}
308+
navigatorRenderer={(currFocusedDate, changeShownDate) => (
309+
<CustomizeNavigator
310+
staticRanges={staticRanges as StaticRangeOption[]}
311+
handleStaticRangeClick={handleStaticRangeClick}
312+
selectedLabel={staticRangeSelected?.label}
313+
currFocusedDate={currFocusedDate}
314+
changeShownDate={changeShownDate}
315+
/>
316+
)}
317+
locale={isLanguageJapanese ? ja : en}
318+
classNames={{
319+
...defaultClassNames,
320+
...props?.classNames
321+
}}
322+
/>
323+
{renderActionBar ? (
324+
renderActionBar({
325+
onApply: handleApply,
326+
onCancel: () => {
327+
handleSetRange();
328+
onCloseRangePicker();
329+
onClose?.();
330+
}
331+
})
332+
) : (
333+
<ActionBar
334+
onCancel={() => {
335+
handleSetRange();
336+
onCloseRangePicker();
337+
}}
338+
onApply={handleApply}
339+
/>
340+
)}
341+
</>
342+
);
343+
262344
return (
263345
<div className="w-fit max-w-[180px] sm:max-w-full">
264346
<Button
@@ -278,97 +360,34 @@ export const ReactDateRangePicker = memo<ReactDateRangePickerProps>(
278360
{triggerLabel}
279361
</p>
280362
</Button>
281-
<DialogModal
282-
title="Date Range Picker"
283-
isShowHeader={false}
284-
isOpen={isOpenRangePicker || !!isShowRange}
285-
onClose={() => {
286-
handleSetRange();
287-
onCloseRangePicker();
288-
onClose?.();
289-
}}
290-
className="!w-fit lg:w-[820px] p-4 sm:p-0 rounded-lg overflow-y-auto"
291-
>
292-
<ReactDateRangePickerComp
293-
{...props}
294-
onChange={item => {
295-
setRange(item.selection);
296-
onRangeChange?.(item.selection);
363+
{isMobile ? (
364+
<Drawer
365+
open={isOpenRangePicker || !!isShowRange}
366+
onClose={() => {
367+
handleSetRange();
368+
onCloseRangePicker();
369+
onClose?.();
297370
}}
298-
showPreview={showPreview}
299-
moveRangeOnFirstSelection={moveRangeOnFirstSelection}
300-
months={months}
301-
ranges={[range]}
302-
direction={direction}
303-
rangeColors={rangeColors}
304-
staticRanges={staticRanges}
305-
showDateDisplay={showDateDisplay}
306-
dateDisplayFormat="yyyy/MM/dd"
307-
inputRanges={[]}
308-
renderStaticRangeLabel={staticRange => (
309-
<div
310-
onClick={() =>
311-
setStaticRangeSelected(staticRange as StaticRangeOption)
312-
}
313-
className={cn(
314-
'hidden md:flex items-center size-0 md:size-full pl-3',
315-
{
316-
'range-selected': staticRange.isSelected(range)
317-
}
318-
)}
319-
>
320-
{staticRange.label}
321-
</div>
322-
)}
323-
dayContentRenderer={date => (
324-
<span
325-
onClick={() => setStaticRangeSelected(undefined)}
326-
style={{
327-
width: '100%',
328-
height: '100%'
329-
}}
330-
className={cn('flex-center size-full', {
331-
'range__days--all-time':
332-
staticRangeSelected?.type === 'all-time'
333-
})}
334-
>
335-
{date.getDate()}
336-
</span>
337-
)}
338-
navigatorRenderer={(currFocusedDate, changeShownDate) => (
339-
<CustomizeNavigator
340-
staticRanges={staticRanges as StaticRangeOption[]}
341-
handleStaticRangeClick={handleStaticRangeClick}
342-
currFocusedDate={currFocusedDate}
343-
changeShownDate={changeShownDate}
344-
/>
345-
)}
346-
locale={isLanguageJapanese ? ja : en}
347-
classNames={{
348-
...defaultClassNames,
349-
...props?.classNames
371+
side="bottom"
372+
className="z-10"
373+
>
374+
{pickerContent}
375+
</Drawer>
376+
) : (
377+
<DialogModal
378+
title="Date Range Picker"
379+
isShowHeader={false}
380+
isOpen={isOpenRangePicker || !!isShowRange}
381+
onClose={() => {
382+
handleSetRange();
383+
onCloseRangePicker();
384+
onClose?.();
350385
}}
351-
/>
352-
353-
{renderActionBar ? (
354-
renderActionBar({
355-
onApply: handleApply,
356-
onCancel: () => {
357-
handleSetRange();
358-
onCloseRangePicker();
359-
onClose?.();
360-
}
361-
})
362-
) : (
363-
<ActionBar
364-
onCancel={() => {
365-
handleSetRange();
366-
onCloseRangePicker();
367-
}}
368-
onApply={handleApply}
369-
/>
370-
)}
371-
</DialogModal>
386+
className="!w-fit lg:w-[820px] p-4 sm:p-0 rounded-lg overflow-y-auto"
387+
>
388+
{pickerContent}
389+
</DialogModal>
390+
)}
372391
</div>
373392
);
374393
}

0 commit comments

Comments
 (0)