Skip to content

Commit b42d459

Browse files
committed
Finished styling.
1 parent 448e290 commit b42d459

File tree

4 files changed

+80
-18
lines changed

4 files changed

+80
-18
lines changed

src/components/Calendar/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { CALENDAR_SIZE, DATE_FORMAT } from "../../constants";
55
import DatepickerContext from "../../contexts/DatepickerContext";
66
import {
77
formatDate,
8+
formatDateTimeToISO,
89
getDaysInMonth,
910
getFirstDayInMonth,
1011
getFirstDaysInMonth,
@@ -128,8 +129,12 @@ const Calendar: React.FC<Props> = ({
128129
const ipt = input?.current;
129130
changeDatepickerValue(
130131
{
131-
startDate: dayjs(start).format(DATE_FORMAT),
132-
endDate: dayjs(end).format(DATE_FORMAT)
132+
startDate: asTimePicker
133+
? formatDateTimeToISO(start, hour, minute, periodDay)
134+
: dayjs(start).format(DATE_FORMAT),
135+
endDate: asTimePicker
136+
? formatDateTimeToISO(end, hour, minute, periodDay)
137+
: dayjs(end).format(DATE_FORMAT)
133138
},
134139
ipt
135140
);
@@ -196,6 +201,9 @@ const Calendar: React.FC<Props> = ({
196201
input,
197202
changeDatepickerValue,
198203
asTimePicker,
204+
hour,
205+
minute,
206+
periodDay,
199207
hideDatepicker,
200208
changeDayHover,
201209
changePeriod,
@@ -226,6 +234,10 @@ const Calendar: React.FC<Props> = ({
226234
setYear(date.year());
227235
}, [date]);
228236

237+
useEffect(() => {
238+
console.log({ hour, minute, periodDay, period });
239+
}, [hour, minute, periodDay, period]);
240+
229241
// Variables
230242
const calendarData = useMemo(() => {
231243
return {

src/components/Input.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,7 @@ const Input: React.FC<Props> = (e: Props) => {
7171

7272
const dates = [];
7373

74-
if (asSingle && asTimePicker) {
75-
const date = parseFormattedDate(inputValue, displayFormat);
76-
if (dateIsValid(date.toDate())) {
77-
dates.push(date.format(DATE_FORMAT));
78-
}
79-
} else if (asSingle) {
74+
if (asSingle || asTimePicker) {
8075
const date = parseFormattedDate(inputValue, displayFormat);
8176
if (dateIsValid(date.toDate())) {
8277
dates.push(date.format(DATE_FORMAT));

src/components/Time.tsx

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,37 @@ import { RING_COLOR } from "../constants";
44
import DatepickerContext from "../contexts/DatepickerContext";
55
import { classNames as cn } from "../helpers";
66

7+
import { DoubleVerticalChevronRightIcon } from "./utils";
8+
79
import { PeriodDay } from "types";
810

911
const Time: React.FC = () => {
1012
// Contexts
11-
1213
const { primaryColor, changeHour, changeMinute, changePeriodDay } =
1314
useContext(DatepickerContext);
15+
1416
const ringFocusColor = RING_COLOR.focus[primaryColor as keyof typeof RING_COLOR.focus];
1517

16-
const HOURS = Array.from({ length: 12 });
17-
const MINUTES = Array.from({ length: 12 });
18+
const svgString = `
19+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16" fill="none">
20+
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.35355 4.06066C8.15829 3.8654 7.84171 3.8654 7.64645 4.06066L5.35355 6.35355C5.15829 6.54882 4.84171 6.54882 4.64645 6.35355C4.45118 6.15829 4.45118 5.84171 4.64645 5.64645L6.93934 3.35356C7.52513 2.76777 8.47487 2.76777 9.06066 3.35355L11.3536 5.64645C11.5488 5.84171 11.5488 6.15829 11.3536 6.35355C11.1583 6.54882 10.8417 6.54882 10.6464 6.35355L8.35355 4.06066Z" fill="#6b7280"/>
21+
<path fill-rule="evenodd" clip-rule="evenodd" d="M8.35355 11.9393C8.15829 12.1346 7.84171 12.1346 7.64645 11.9393L5.35355 9.64645C5.15829 9.45119 4.84171 9.45119 4.64645 9.64645C4.45118 9.84171 4.45118 10.1583 4.64645 10.3536L6.93934 12.6464C7.52513 13.2322 8.47487 13.2322 9.06066 12.6464L11.3536 10.3536C11.5488 10.1583 11.5488 9.84171 11.3536 9.64645C11.1583 9.45119 10.8417 9.45119 10.6464 9.64645L8.35355 11.9393Z" fill="#6b7280"/>
22+
</svg>
23+
`;
24+
const dataUri = `data:image/svg+xml;base64,${Buffer.from(svgString).toString("base64")}`;
1825

1926
const selectClassname = cn(
20-
"!bg-none !bg-transparent !text-sm !text-center !outline-none !focus:outline-none",
21-
"!px-2 !py-1 rounded-[8px] !w-fit",
27+
"!bg-[length:1rem_1rem]",
28+
"bg-[right_0.25rem_center]",
29+
"!bg-no-repeat !bg-transparent !text-sm !text-center !outline-none !focus:outline-none",
30+
"!pl-2 !pr-6 !py-1 rounded-[8px] !w-fit",
2231
"!border border-gray-300 focus:border-none",
2332
`${ringFocusColor}`
2433
);
2534

35+
const HOURS = Array.from({ length: 12 });
36+
const MINUTES = Array.from({ length: 12 });
37+
2638
const handleChangeHour = (e: ChangeEvent<HTMLSelectElement>) => changeHour(e.target.value);
2739

2840
const handleChangeMinute = (e: ChangeEvent<HTMLSelectElement>) => changeMinute(e.target.value);
@@ -33,11 +45,18 @@ const Time: React.FC = () => {
3345
return (
3446
<div className="w-full md:w-auto flex items-center justify-center space-x-3">
3547
<div className="pb-6">
36-
<select name="hour" className={selectClassname} onChange={handleChangeHour}>
48+
<select
49+
name="hour"
50+
className={selectClassname}
51+
onChange={handleChangeHour}
52+
style={{
53+
backgroundImage: "url(" + dataUri + ")"
54+
}}
55+
>
3756
{HOURS.map((_, index) => {
3857
const hour = index + 1;
3958
return (
40-
<option key={hour} value={hour + 1}>
59+
<option key={hour} value={hour}>
4160
{hour}
4261
</option>
4362
);
@@ -48,19 +67,29 @@ const Time: React.FC = () => {
4867
name="minute"
4968
className={cn(selectClassname, "mr-4")}
5069
onChange={handleChangeMinute}
70+
style={{
71+
backgroundImage: "url(" + dataUri + ")"
72+
}}
5173
>
5274
{MINUTES.map((_, index) => {
5375
const minute = index * 5;
5476
return (
55-
<option key={minute} value={minute + 1}>
77+
<option key={minute} value={minute}>
5678
{new Intl.NumberFormat("en-US", {
5779
minimumIntegerDigits: 2
5880
}).format(minute)}
5981
</option>
6082
);
6183
})}
6284
</select>
63-
<select name="ampm" className={selectClassname} onChange={handleChangePeriodDay}>
85+
<select
86+
name="ampm"
87+
className={selectClassname}
88+
onChange={handleChangePeriodDay}
89+
style={{
90+
backgroundImage: "url(" + dataUri + ")"
91+
}}
92+
>
6493
<option value="AM">AM</option>
6594
<option value="PM">PM</option>
6695
</select>

src/components/utils.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { BG_COLOR, BORDER_COLOR, BUTTON_COLOR, RING_COLOR } from "../constants";
44
import DatepickerContext from "../contexts/DatepickerContext";
55

66
interface IconProps {
7-
className: string;
7+
className?: string;
88
}
99

1010
interface Button {
@@ -118,6 +118,32 @@ export const DoubleChevronRightIcon: React.FC<IconProps> = ({ className = "w-6 h
118118
);
119119
};
120120

121+
export const DoubleVerticalChevronRightIcon: React.FC<IconProps> = ({ className = "w-6 h-6" }) => {
122+
return (
123+
<svg
124+
className={className}
125+
xmlns="http://www.w3.org/2000/svg"
126+
width="16"
127+
height="16"
128+
viewBox="0 0 16 16"
129+
fill="none"
130+
>
131+
<path
132+
fill-rule="evenodd"
133+
clip-rule="evenodd"
134+
d="M8.35355 4.06066C8.15829 3.8654 7.84171 3.8654 7.64645 4.06066L5.35355 6.35355C5.15829 6.54882 4.84171 6.54882 4.64645 6.35355C4.45118 6.15829 4.45118 5.84171 4.64645 5.64645L6.93934 3.35356C7.52513 2.76777 8.47487 2.76777 9.06066 3.35355L11.3536 5.64645C11.5488 5.84171 11.5488 6.15829 11.3536 6.35355C11.1583 6.54882 10.8417 6.54882 10.6464 6.35355L8.35355 4.06066Z"
135+
fill="#6b7280"
136+
/>
137+
<path
138+
fill-rule="evenodd"
139+
clip-rule="evenodd"
140+
d="M8.35355 11.9393C8.15829 12.1346 7.84171 12.1346 7.64645 11.9393L5.35355 9.64645C5.15829 9.45119 4.84171 9.45119 4.64645 9.64645C4.45118 9.84171 4.45118 10.1583 4.64645 10.3536L6.93934 12.6464C7.52513 13.2322 8.47487 13.2322 9.06066 12.6464L11.3536 10.3536C11.5488 10.1583 11.5488 9.84171 11.3536 9.64645C11.1583 9.45119 10.8417 9.45119 10.6464 9.64645L8.35355 11.9393Z"
141+
fill="#6b7280"
142+
/>
143+
</svg>
144+
);
145+
};
146+
121147
// eslint-disable-next-line react/display-name,@typescript-eslint/ban-types
122148
export const Arrow = React.forwardRef<HTMLDivElement, {}>((props, ref) => {
123149
return (

0 commit comments

Comments
 (0)