Skip to content

Commit 6ede440

Browse files
committed
feat: availability time picker styles
1 parent 4cbe8b6 commit 6ede440

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

packages/features/schedules/components/Schedule.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { useLocale } from "@calcom/lib/hooks/useLocale";
2020
import { weekdayNames } from "@calcom/lib/weekday";
2121
import useMeQuery from "@calcom/trpc/react/hooks/useMeQuery";
2222
import type { TimeRange } from "@calcom/types/schedule";
23-
2423
import cn from "@calcom/ui/classNames";
2524
import { Button } from "@calcom/ui/components/button";
2625
import { Dropdown, DropdownMenuContent, DropdownMenuTrigger } from "@calcom/ui/components/dropdown";
@@ -37,6 +36,14 @@ export type ScheduleLabelsType = {
3736
deleteTime: string;
3837
};
3938

39+
export type SelectInnerClassNames = {
40+
control?: string;
41+
singleValue?: string;
42+
valueContainer?: string;
43+
input?: string;
44+
menu?: string;
45+
};
46+
4047
export type FieldPathByValue<TFieldValues extends FieldValues, TValue> = {
4148
[Key in FieldPath<TFieldValues>]: FieldPathValue<TFieldValues, Key> extends TValue ? Key : never;
4249
}[FieldPath<TFieldValues>];
@@ -106,6 +113,7 @@ export const ScheduleDay = <TFieldValues extends FieldValues>({
106113
classNames={{
107114
dayRanges: classNames?.dayRanges,
108115
timeRangeField: classNames?.timeRangeField,
116+
timePicker: classNames?.timePicker,
109117
}}
110118
/>
111119
{!disabled && <div className="block">{CopyButton}</div>}
@@ -238,7 +246,7 @@ export const DayRanges = <TFieldValues extends FieldValues>({
238246
disabled?: boolean;
239247
labels?: ScheduleLabelsType;
240248
userTimeFormat: number | null;
241-
classNames?: Pick<scheduleClassNames, "dayRanges" | "timeRangeField">;
249+
classNames?: Pick<scheduleClassNames, "dayRanges" | "timeRangeField" | "timePicker">;
242250
}) => {
243251
const { t } = useLocale();
244252
const { getValues } = useFormContext();
@@ -261,6 +269,7 @@ export const DayRanges = <TFieldValues extends FieldValues>({
261269
<TimeRangeField
262270
className={classNames?.timeRangeField}
263271
userTimeFormat={userTimeFormat}
272+
timePickerClassNames={classNames?.timePicker}
264273
{...field}
265274
/>
266275
)}
@@ -336,11 +345,27 @@ const TimeRangeField = ({
336345
onChange,
337346
disabled,
338347
userTimeFormat,
348+
timePickerClassNames,
339349
}: {
340350
className?: string;
341351
disabled?: boolean;
342352
userTimeFormat: number | null;
353+
timePickerClassNames?: {
354+
container?: string;
355+
value?: string;
356+
valueContainer?: string;
357+
input?: string;
358+
dropdown?: string;
359+
};
343360
} & ControllerRenderProps) => {
361+
const innerClassNames: SelectInnerClassNames = {
362+
control: timePickerClassNames?.container,
363+
singleValue: timePickerClassNames?.value,
364+
valueContainer: timePickerClassNames?.valueContainer,
365+
input: timePickerClassNames?.input,
366+
menu: timePickerClassNames?.dropdown,
367+
};
368+
344369
// this is a controlled component anyway given it uses LazySelect, so keep it RHF agnostic.
345370
return (
346371
<div className={cn("flex flex-row gap-2 sm:gap-3", className)}>
@@ -350,6 +375,7 @@ const TimeRangeField = ({
350375
isDisabled={disabled}
351376
value={value.start}
352377
menuPlacement="bottom"
378+
innerClassNames={innerClassNames}
353379
onChange={(option) => {
354380
const newStart = new Date(option?.value as number);
355381
if (newStart >= new Date(value.end)) {
@@ -368,6 +394,7 @@ const TimeRangeField = ({
368394
isDisabled={disabled}
369395
value={value.end}
370396
min={value.start}
397+
innerClassNames={innerClassNames}
371398
menuPlacement="bottom"
372399
onChange={(option) => {
373400
onChange({ ...value, end: new Date(option?.value as number) });
@@ -389,6 +416,7 @@ const LazySelect = ({
389416
min?: ConfigType;
390417
max?: ConfigType;
391418
userTimeFormat: number | null;
419+
innerClassNames?: SelectInnerClassNames;
392420
}) => {
393421
// Lazy-loaded options, otherwise adding a field has a noticeable redraw delay.
394422
const { options, filter } = useOptions(userTimeFormat);

packages/platform/atoms/availability/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ export type scheduleClassNames = {
2828
timeRangeField?: string;
2929
labelAndSwitchContainer?: string;
3030
scheduleContainer?: string;
31+
timePicker?: {
32+
container?: string;
33+
valueContainer?: string;
34+
value?: string;
35+
input?: string;
36+
dropdown?: string;
37+
};
3138
};
3239

3340
export type AvailabilityFormValidationResult = {

packages/platform/examples/base/src/pages/availability.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Navbar } from "@/components/Navbar";
22
import { Inter } from "next/font/google";
3-
import { useRef, useCallback, useState } from "react";
3+
import { useRef, useCallback } from "react";
44

55
import type { AvailabilitySettingsFormRef } from "@calcom/atoms";
66
import { AvailabilitySettings } from "@calcom/atoms";
@@ -57,6 +57,24 @@ export default function Availability(props: { calUsername: string; calEmail: str
5757
ctaClassName: "border p-4 rounded-md",
5858
editableHeadingClassName: "underline font-semibold",
5959
hiddenSwitchClassname: { thumb: "bg-red-500" },
60+
scheduleClassNames: {
61+
schedule: "bg-blue-50 border-2 border-blue-200 rounded-lg p-4",
62+
scheduleDay: "bg-green-50 border border-green-300 rounded-md mb-2",
63+
dayRanges: "bg-yellow-50 p-3 rounded border-l-4 border-yellow-400",
64+
timeRangeField: "!text-2xl bg-red-50 border-2 border-red-300 rounded-xl px-4 py-2",
65+
labelAndSwitchContainer: "bg-purple-50 border border-purple-200 rounded p-2",
66+
scheduleContainer: "bg-gray-100 border-4 border-gray-400 rounded-2xl shadow-lg",
67+
timePicker: {
68+
container: "!bg-blue-900",
69+
valueContainer: "!bg-pink-500",
70+
value: "!bg-yellow-500",
71+
input: "!bg-green-500",
72+
dropdown: "!bg-cyan-500",
73+
},
74+
},
75+
dateOverrideClassNames: {
76+
container: "p-0",
77+
},
6078
}}
6179
onFormStateChange={handleFormStateChange}
6280
onUpdateSuccess={() => {

0 commit comments

Comments
 (0)