Fix timezone select - create two variants (#7875)
* Fix timezone select - create two variants * Remove menu is open * Timezone fixes --------- Co-authored-by: Efraín Rochín <[email protected]>
This commit is contained in:
1 parent
8dd9b8d74b
commit
04c634ec4b
4 files changed
+32
-118
No files matched your search
@@ -13,7 +13,12 @@ export interface ICity {
|
||||
timezone: string;
|
||||
}
|
||||
|
||||
export function TimezoneSelect({ className, components, ...props }: SelectProps) {
|
||||
export function TimezoneSelect({
|
||||
className,
|
||||
components,
|
||||
variant = "default",
|
||||
...props
|
||||
}: SelectProps & { variant?: "default" | "minimal" }) {
|
||||
const [cities, setCities] = useState<ICity[]>([]);
|
||||
const { data, isLoading } = trpc.viewer.public.cityTimezones.useQuery(undefined, {
|
||||
trpc: { context: { skipBatch: true } },
|
||||
@@ -44,7 +49,8 @@ export function TimezoneSelect({ className, components, ...props }: SelectProps)
|
||||
formatOptionLabel={(option) => <p className="truncate">{(option as ITimezoneOption).value}</p>}
|
||||
getOptionLabel={(option) => handleOptionLabel(option as ITimezoneOption, cities)}
|
||||
classNames={{
|
||||
input: () => classNames("dark:text-darkgray-900 text-gray-900", props.classNames?.input),
|
||||
input: (state) =>
|
||||
classNames("dark:text-darkgray-900 text-gray-900", props.classNames?.input?.(state)),
|
||||
option: (state) =>
|
||||
classNames(
|
||||
"dark:bg-darkgray-100 flex cursor-pointer justify-between py-2.5 px-3 rounded-none text-gray-700 dark:text-darkgray-700",
|
||||
@@ -55,28 +61,35 @@ export function TimezoneSelect({ className, components, ...props }: SelectProps)
|
||||
placeholder: (state) =>
|
||||
classNames("text-gray-400 text-sm dark:text-darkgray-400", state.isFocused && "hidden"),
|
||||
dropdownIndicator: () => "text-gray-600 dark:text-darkgray-400",
|
||||
control: () => classNames("", props.classNames?.control), // We remove all styling here to fit theme of booking page - no min-h also
|
||||
singleValue: () =>
|
||||
control: (state) =>
|
||||
classNames(
|
||||
variant === "default"
|
||||
? "dark:bg-darkgray-100 dark:border-darkgray-300 !min-h-9 border-gray-300 bg-white text-sm leading-4 placeholder:text-sm placeholder:font-normal focus-within:ring-2 focus-within:ring-gray-800 hover:border-gray-400 dark:focus-within:ring-darkgray-900 rounded-md border py-2 px-3"
|
||||
: "text-sm ",
|
||||
props.classNames?.control?.(state)
|
||||
), // We remove all styling here to fit theme of booking page - no min-h also
|
||||
singleValue: (state) =>
|
||||
classNames(
|
||||
"dark:text-darkgray-900 dark:placeholder:text-darkgray-500 text-black placeholder:text-gray-400",
|
||||
props.classNames?.singleValue
|
||||
props.classNames?.singleValue?.(state)
|
||||
),
|
||||
valueContainer: () =>
|
||||
valueContainer: (state) =>
|
||||
classNames(
|
||||
"dark:text-darkgray-900 dark:placeholder:text-darkgray-500 text-black placeholder:text-gray-400 flex gap-1",
|
||||
props.classNames?.valueContainer
|
||||
props.classNames?.valueContainer?.(state)
|
||||
),
|
||||
multiValue: () =>
|
||||
multiValue: (state) =>
|
||||
classNames(
|
||||
"dark:bg-darkgray-200 dark:text-darkgray-700 rounded-md bg-gray-100 text-gray-700 py-1.5 px-2 flex items-center text-sm leading-none",
|
||||
props.classNames?.multiValue
|
||||
props.classNames?.multiValue?.(state)
|
||||
),
|
||||
menu: () =>
|
||||
menu: (state) =>
|
||||
classNames(
|
||||
"dark:bg-darkgray-100 rounded-md bg-white text-sm leading-4 dark:text-white mt-1 border border-gray-200 dark:border-darkgray-200 ",
|
||||
props.classNames?.menu
|
||||
props.classNames?.menu?.(state)
|
||||
),
|
||||
menuList: () => classNames("scroll-bar scrollbar-track-w-20 rounded-md", props.classNames?.menuList),
|
||||
menuList: (state) =>
|
||||
classNames("scroll-bar scrollbar-track-w-20 rounded-md", props.classNames?.menuList?.(state)),
|
||||
indicatorsContainer: (state) =>
|
||||
classNames(
|
||||
state.selectProps.menuIsOpen
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import classNames from "classnames";
|
||||
import { components } from "react-select";
|
||||
import type { ITimezone, ITimezoneOption, Props as SelectProps } from "react-timezone-select";
|
||||
import BaseSelect, { allTimezones } from "react-timezone-select";
|
||||
|
||||
import { InputComponent } from "../components/form/select/components";
|
||||
|
||||
function TimezoneSelect({ className, ...props }: SelectProps) {
|
||||
// @TODO: remove borderRadius and haveRoundedClassName logic from theme so we use only new style
|
||||
const haveRoundedClassName = !!(className && className.indexOf("rounded-") > -1);
|
||||
const defaultBorderRadius = 2;
|
||||
|
||||
return (
|
||||
<BaseSelect
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
...(haveRoundedClassName ? {} : { borderRadius: defaultBorderRadius }),
|
||||
colors: {
|
||||
...theme.colors,
|
||||
primary: "var(--brand-color)",
|
||||
primary50: "rgba(209 , 213, 219, var(--tw-bg-opacity))",
|
||||
primary25: "rgba(244, 245, 246, var(--tw-bg-opacity))",
|
||||
},
|
||||
})}
|
||||
styles={{
|
||||
option: (provided, state) => ({
|
||||
...provided,
|
||||
color: state.isSelected ? "var(--brand-text-color)" : "black",
|
||||
":active": {
|
||||
backgroundColor: state.isSelected ? "" : "var(--brand-color)",
|
||||
color: "var(--brand-text-color)",
|
||||
},
|
||||
}),
|
||||
}}
|
||||
timezones={{
|
||||
...allTimezones,
|
||||
"America/Asuncion": "Asuncion",
|
||||
}}
|
||||
components={{
|
||||
...components,
|
||||
IndicatorSeparator: () => null,
|
||||
Input: InputComponent,
|
||||
}}
|
||||
className={classNames("text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default TimezoneSelect;
|
||||
export type { ITimezone, ITimezoneOption };
|
||||
Reference in new issue
Block a user