Skip to content

Commit a35e071

Browse files
committed
feat(calendar): today design
1 parent 69ebc4b commit a35e071

File tree

7 files changed

+114
-8
lines changed

7 files changed

+114
-8
lines changed

Diff for: packages/styles/bases/calendar.css.ts

+5
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,8 @@ export const calendarItemInteractiveStyle = style([
125125
},
126126
},
127127
]);
128+
export const calendarItemInteractiveTodayStyle = style({
129+
border: `1px solid ${THEME.color.green[800]}`,
130+
borderRadius: "50%",
131+
boxSizing: "border-box",
132+
});

Diff for: packages/wiz-ui-react/src/components/base/calendar/components/calendar.tsx

+24-8
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ type Props = BaseProps & {
9393
currentMonth?: Date;
9494
activeDates?: DateStatus[];
9595
filledWeeks?: boolean;
96+
_today?: Date;
9697
onClickDate?: (selectedValue: Date) => void;
9798
/**
9899
* @description 日付が無効かどうかを判定する関数です。無効な日付はクリック不可になります。
@@ -108,6 +109,7 @@ const Calendar: FC<Props> = ({
108109
currentMonth = new Date(),
109110
activeDates,
110111
filledWeeks,
112+
_today,
111113
onClickDate,
112114
disabledDate,
113115
}) => {
@@ -126,6 +128,18 @@ const Calendar: FC<Props> = ({
126128
});
127129
}
128130

131+
function getItemDate(item: CalendarDataItem) {
132+
return new Date(
133+
currentMonth.getFullYear(),
134+
currentMonth.getMonth(),
135+
Number(item.label)
136+
);
137+
}
138+
139+
function getIsToday(a: Date) {
140+
return a.toDateString() === (_today || new Date()).toDateString();
141+
}
142+
129143
function getItemStyleState(
130144
item: CalendarDataItem,
131145
dateStatus?: DateStatus
@@ -139,13 +153,7 @@ const Calendar: FC<Props> = ({
139153
if (item.isOutOfCurrentMonth) {
140154
return;
141155
}
142-
onClickDate?.(
143-
new Date(
144-
currentMonth.getFullYear(),
145-
currentMonth.getMonth(),
146-
Number(item.label)
147-
)
148-
);
156+
onClickDate?.(getItemDate(item));
149157
}
150158
const calendarItems = calendarData.map((weekDateItems) => {
151159
return weekDateItems.map((item) => {
@@ -214,6 +222,7 @@ const Calendar: FC<Props> = ({
214222
const item = adjacent.current.item;
215223
const itemStyle = adjacent.current.itemStyle;
216224
const activeDateStatus = adjacent.current.activeDateStatus;
225+
const isToday = getIsToday(getItemDate(item));
217226
return (
218227
<td
219228
key={`${item.label}-${col}`}
@@ -244,7 +253,14 @@ const Calendar: FC<Props> = ({
244253
adjacent.current.itemStyle === "primary"
245254
)}
246255
>
247-
<div className={styles.calendarItemInteractiveStyle}>
256+
<div
257+
className={clsx(
258+
styles.calendarItemInteractiveStyle,
259+
!item.isOutOfCurrentMonth &&
260+
isToday &&
261+
styles.calendarItemInteractiveTodayStyle
262+
)}
263+
>
248264
{item.label}
249265
</div>
250266
</div>

Diff for: packages/wiz-ui-react/src/components/base/calendar/stories/calendar.stories.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,29 @@ export const FilledWeeks: Story = {
107107
},
108108
},
109109
};
110+
111+
export const Today: Story = {
112+
...Template,
113+
args: {
114+
currentMonth: new Date("2023-03"),
115+
_today: new Date("2023-03-05"),
116+
},
117+
};
118+
119+
export const DisabledToday: Story = {
120+
...Template,
121+
args: {
122+
currentMonth: new Date("2023-03"),
123+
_today: new Date("2023-03-05"),
124+
disabledDate: (date: Date) => date.getDate() === 5,
125+
},
126+
};
127+
128+
export const SelectedToday: Story = {
129+
...Template,
130+
args: {
131+
currentMonth: new Date("2023-03"),
132+
_today: new Date("2023-03-05"),
133+
activeDates: [{ date: new Date("2023-03-05"), state: "primary" }],
134+
},
135+
};

Diff for: packages/wiz-ui-react/src/components/base/inputs/date-picker/components/date-picker.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Props = BaseProps & {
2626
disabled?: boolean;
2727
error?: boolean;
2828
isDirectionFixed?: boolean;
29+
_today?: Date;
2930
onChangeDate: (selectedValue: Date | null) => void;
3031
/**
3132
* @description 日付が無効かどうかを判定する関数です。無効な日付はクリック不可になります。
@@ -60,6 +61,7 @@ const DatePicker: FC<Props> = ({
6061
formatYear = (year) => `${year}`,
6162
formatDate = (date) =>
6263
`${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}日`,
64+
_today,
6365
}: Props) => {
6466
const [isOpen, setIsOpen] = useState(false);
6567
const cancelButtonVisible = !disabled && !!date;
@@ -243,6 +245,7 @@ const DatePicker: FC<Props> = ({
243245
onClickDate={(date) => onChangeDate(date)}
244246
currentMonth={currentMonth}
245247
filledWeeks
248+
_today={_today || new Date()}
246249
disabledDate={disabledDate}
247250
/>
248251
</div>

Diff for: packages/wiz-ui-react/src/components/base/inputs/date-picker/stories/date-picker.stories.tsx

+23
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,26 @@ export const Playground: Story = {
9898
return <WizDatePicker {...args} date={date} onChangeDate={setDate} />;
9999
},
100100
};
101+
102+
export const Today: Story = {
103+
args: {
104+
date: new Date(2023, 0, 1),
105+
_today: new Date("2023-01-15"),
106+
},
107+
play: async ({ canvasElement }) => {
108+
const canvas = within(canvasElement);
109+
canvas.getByLabelText(ARIA_LABELS.DATE_PICKER_INPUT).click();
110+
},
111+
};
112+
113+
export const DisabledToday: Story = {
114+
args: {
115+
date: new Date(2023, 0, 1),
116+
disabledDate: (date: Date) => date.getDate() >= 10 && date.getDate() < 17,
117+
_today: new Date("2023-01-15"),
118+
},
119+
play: async ({ canvasElement }) => {
120+
const canvas = within(canvasElement);
121+
canvas.getByLabelText(ARIA_LABELS.DATE_PICKER_INPUT).click();
122+
},
123+
};

Diff for: packages/wiz-ui-react/src/components/base/inputs/date-range-picker/components/date-range-picker.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Props = BaseProps & {
4040
selectBoxValue?: string;
4141
isDirectionFixed?: boolean;
4242
error?: boolean;
43+
_today?: Date;
4344
onChangeDateRange: (dateRange: DateRange) => void;
4445
onChangeSelectBoxValue?: (value: string) => void;
4546
disabledDate?: (date: Date) => boolean;
@@ -60,6 +61,7 @@ const DateRangePicker: FC<Props> = ({
6061
selectBoxValue,
6162
isDirectionFixed = false,
6263
error,
64+
_today,
6365
onChangeDateRange,
6466
onChangeSelectBoxValue,
6567
disabledDate = () => false,
@@ -316,6 +318,7 @@ const DateRangePicker: FC<Props> = ({
316318
onClickDate={onClickDate}
317319
disabledDate={disabledDate}
318320
filledWeeks={true}
321+
_today={_today || new Date()}
319322
/>
320323
</div>
321324
<div className={styles.popupCalendarContainerStyle["right"]}>
@@ -345,6 +348,7 @@ const DateRangePicker: FC<Props> = ({
345348
onClickDate={onClickDate}
346349
disabledDate={disabledDate}
347350
filledWeeks={true}
351+
_today={_today || new Date()}
348352
/>
349353
</div>
350354
</div>

Diff for: packages/wiz-ui-react/src/components/base/inputs/date-range-picker/stories/date-range-picker.stories.tsx

+29
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,32 @@ export const Playground: Story = {
185185
);
186186
},
187187
};
188+
189+
export const Today: Story = {
190+
args: {
191+
dateRange: {
192+
start: new Date("2021-01-15"),
193+
end: new Date("2021-02-15"),
194+
},
195+
_today: new Date("2021-01-28"),
196+
},
197+
play: async ({ canvasElement }) => {
198+
const canvas = within(canvasElement);
199+
canvas.getByLabelText(ARIA_LABELS.RANGE_DATE_PICKER_INPUT).click();
200+
},
201+
};
202+
203+
export const DisabledWithToday: Story = {
204+
args: {
205+
dateRange: {
206+
start: new Date("2021-01-01"),
207+
end: new Date("2021-01-31"),
208+
},
209+
disabledDate: (date: Date) => date.getDate() >= 10 && date.getDate() < 17,
210+
_today: new Date("2021-01-15"),
211+
},
212+
play: async ({ canvasElement }) => {
213+
const canvas = within(canvasElement);
214+
canvas.getByLabelText(ARIA_LABELS.RANGE_DATE_PICKER_INPUT).click();
215+
},
216+
};

0 commit comments

Comments
 (0)