Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: Hariom Balhara <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
20 files changed
+273
-181
No files matched your search
@@ -7,7 +7,7 @@ import BaseSelect, {
|
||||
Props as SelectProps,
|
||||
} from "react-timezone-select";
|
||||
|
||||
import { InputComponent } from "@calcom/ui/v2/core/form/Select";
|
||||
import { InputComponent } from "@calcom/ui/v2/core/form/select/components";
|
||||
|
||||
function TimezoneSelect({ className, ...props }: SelectProps) {
|
||||
// @TODO: remove borderRadius and haveRoundedClassName logic from theme so we use only new style
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import classNames from "classnames";
|
||||
import { components } from "react-select";
|
||||
import { useMemo } from "react";
|
||||
import BaseSelect, {
|
||||
allTimezones,
|
||||
ITimezoneOption,
|
||||
@@ -7,42 +6,20 @@ import BaseSelect, {
|
||||
Props as SelectProps,
|
||||
} from "react-timezone-select";
|
||||
|
||||
import { InputComponent } from "./form/Select";
|
||||
import { getReactSelectProps } from "@calcom/ui/v2/core/form/select";
|
||||
|
||||
function TimezoneSelect({ className, components, ...props }: SelectProps) {
|
||||
const reactSelectProps = useMemo(() => {
|
||||
return getReactSelectProps({ className, components: components || {} });
|
||||
}, [className, components]);
|
||||
|
||||
function TimezoneSelect({ className, ...props }: SelectProps) {
|
||||
return (
|
||||
<BaseSelect
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
borderRadius: 6,
|
||||
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)",
|
||||
},
|
||||
}),
|
||||
}}
|
||||
{...reactSelectProps}
|
||||
timezones={{
|
||||
...allTimezones,
|
||||
"America/Asuncion": "Asuncion",
|
||||
}}
|
||||
components={{
|
||||
...components,
|
||||
IndicatorSeparator: () => null,
|
||||
Input: InputComponent,
|
||||
}}
|
||||
className={classNames("text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -5,7 +5,7 @@ import { Props } from "react-select";
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import Select from "./Select";
|
||||
import Select from "./select";
|
||||
|
||||
export type Option = {
|
||||
value: string;
|
||||
@@ -18,22 +18,21 @@ const InputOption: React.FC<OptionProps<any, boolean, GroupBase<any>>> = ({
|
||||
isSelected,
|
||||
children,
|
||||
innerProps,
|
||||
className,
|
||||
...rest
|
||||
}) => {
|
||||
const style = {
|
||||
alignItems: "center",
|
||||
backgroundColor: isFocused ? "rgba(244, 245, 246, var(--tw-bg-opacity))" : "transparent",
|
||||
color: "inherit",
|
||||
display: "flex ",
|
||||
};
|
||||
|
||||
const props = {
|
||||
...innerProps,
|
||||
style,
|
||||
};
|
||||
|
||||
return (
|
||||
<components.Option
|
||||
className={classNames(
|
||||
className,
|
||||
"dark:bg-darkgray-100 text-[inherit] !flex !cursor-pointer !py-3",
|
||||
isFocused && "dark:!bg-darkgray-200 !bg-gray-100",
|
||||
isSelected && "dark:!bg-darkgray-300 !bg-neutral-900"
|
||||
)}
|
||||
{...rest}
|
||||
isDisabled={isDisabled}
|
||||
isFocused={isFocused}
|
||||
@@ -75,17 +74,6 @@ export default function MultiSelectCheckboxes({
|
||||
|
||||
return (
|
||||
<Select
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
borderRadius: 6,
|
||||
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))",
|
||||
},
|
||||
})}
|
||||
value={selected}
|
||||
onChange={(s: any) => {
|
||||
setSelected(s);
|
||||
|
||||
@@ -2,6 +2,6 @@ export * from "./radio-area";
|
||||
export * from "./fields";
|
||||
export { default as Checkbox } from "./Checkbox";
|
||||
export { default as DatePicker } from "./DatePicker";
|
||||
export { default as Select, SelectWithValidation, SelectField } from "./Select";
|
||||
export { default as Select, SelectWithValidation, SelectField, getReactSelectProps } from "./select";
|
||||
|
||||
export { default as FormStep } from "./FormStep";
|
||||
@@ -1,20 +1,28 @@
|
||||
import { useId } from "@radix-ui/react-id";
|
||||
import * as React from "react";
|
||||
import ReactSelect, {
|
||||
components,
|
||||
components as reactSelectComponents,
|
||||
GroupBase,
|
||||
InputProps,
|
||||
Props,
|
||||
SingleValue,
|
||||
MultiValue,
|
||||
OptionProps,
|
||||
SelectComponentsConfig,
|
||||
} from "react-select";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
import { Label } from "./fields";
|
||||
import { Label } from "../fields";
|
||||
import {
|
||||
ControlComponent,
|
||||
InputComponent,
|
||||
MenuComponent,
|
||||
MenuListComponent,
|
||||
OptionComponent,
|
||||
SingleValueComponent,
|
||||
ValueContainerComponent,
|
||||
MultiValueComponent,
|
||||
} from "./components";
|
||||
|
||||
export type SelectProps<
|
||||
Option,
|
||||
@@ -22,85 +30,53 @@ export type SelectProps<
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
> = Props<Option, IsMulti, Group>;
|
||||
|
||||
export const InputComponent = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({
|
||||
inputClassName,
|
||||
...props
|
||||
}: InputProps<Option, IsMulti, Group>) => {
|
||||
return (
|
||||
<components.Input
|
||||
// disables our default form focus hightlight on the react-select input element
|
||||
inputClassName={classNames("focus:ring-0 focus:ring-offset-0", inputClassName)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const OptionComponent = <Option, IsMulti extends boolean, Group extends GroupBase<Option>>({
|
||||
className,
|
||||
...props
|
||||
}: OptionProps<Option, IsMulti, Group>) => {
|
||||
return (
|
||||
<components.Option className={classNames("!flex justify-between", className)} {...props}>
|
||||
<span>{props.label}</span> {props.isSelected && <Icon.FiCheck className="h-5 w-5" />}
|
||||
</components.Option>
|
||||
);
|
||||
};
|
||||
|
||||
function Select<
|
||||
export const getReactSelectProps = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({ className, ...props }: SelectProps<Option, IsMulti, Group>) {
|
||||
return (
|
||||
<ReactSelect
|
||||
className={classNames(
|
||||
"cal-react-select-container block h-[36px] w-full min-w-0 flex-1 rounded-md text-sm",
|
||||
className
|
||||
)}
|
||||
classNamePrefix="cal-react-select"
|
||||
theme={(theme) => ({
|
||||
...theme,
|
||||
borderRadius: 6,
|
||||
colors: {
|
||||
...theme.colors,
|
||||
primary: "rgba(229, 231, 235, var(--tw-bg-opacity))",
|
||||
primary50: "rgba(209 , 213, 219, var(--tw-bg-opacity))",
|
||||
primary25: "rgba(244, 245, 246, var(--tw-bg-opacity))",
|
||||
},
|
||||
})}
|
||||
styles={{
|
||||
control: (base) => ({
|
||||
...base,
|
||||
// Brute force to remove focus outline of input
|
||||
"& .react-select__input": {
|
||||
borderWidth: 0,
|
||||
boxShadow: "none",
|
||||
},
|
||||
}),
|
||||
option: (provided, state) => ({
|
||||
...provided,
|
||||
color: "black",
|
||||
":active": {
|
||||
backgroundColor: state.isSelected ? "" : "rgba(229, 231, 235, var(--tw-bg-opacity))",
|
||||
color: "rgba(51, 15, 51, var(--tw-bg-opacity))",
|
||||
},
|
||||
}),
|
||||
}}
|
||||
components={{
|
||||
...components,
|
||||
IndicatorSeparator: () => null,
|
||||
Input: InputComponent,
|
||||
Option: OptionComponent,
|
||||
...props.components,
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
}
|
||||
>({
|
||||
className,
|
||||
components,
|
||||
}: {
|
||||
className?: string;
|
||||
components: SelectComponentsConfig<Option, IsMulti, Group>;
|
||||
}) => ({
|
||||
className: classNames("block h-[36px] w-full min-w-0 flex-1 rounded-md", className),
|
||||
classNamePrefix: "cal-react-select",
|
||||
components: {
|
||||
...reactSelectComponents,
|
||||
IndicatorSeparator: () => null,
|
||||
Input: InputComponent,
|
||||
Option: OptionComponent,
|
||||
Control: ControlComponent,
|
||||
SingleValue: SingleValueComponent,
|
||||
Menu: MenuComponent,
|
||||
MenuList: MenuListComponent,
|
||||
ValueContainer: ValueContainerComponent,
|
||||
MultiValue: MultiValueComponent,
|
||||
...components,
|
||||
},
|
||||
});
|
||||
|
||||
const Select = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
components,
|
||||
...props
|
||||
}: SelectProps<Option, IsMulti, Group>) => {
|
||||
const reactSelectProps = React.useMemo(() => {
|
||||
return getReactSelectProps<Option, IsMulti, Group>({ className, components: components || {} });
|
||||
}, [className, components]);
|
||||
|
||||
return <ReactSelect {...reactSelectProps} {...props} />;
|
||||
};
|
||||
|
||||
export const SelectField = function SelectField<
|
||||
Option,
|
||||
isMulti extends boolean = false,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>(
|
||||
props: {
|
||||
@@ -110,7 +86,7 @@ export const SelectField = function SelectField<
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
className?: string;
|
||||
error?: string;
|
||||
} & SelectProps<Option, isMulti, Group>
|
||||
} & SelectProps<Option, IsMulti, Group>
|
||||
) {
|
||||
const { t } = useLocale();
|
||||
const { label = t(props.name || ""), containerClassName, labelProps, className, ...passThrough } = props;
|
||||
@@ -134,14 +110,14 @@ export const SelectField = function SelectField<
|
||||
*/
|
||||
export function SelectWithValidation<
|
||||
Option extends { label: string; value: string },
|
||||
isMulti extends boolean = false,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
required = false,
|
||||
onChange,
|
||||
value,
|
||||
...remainingProps
|
||||
}: SelectProps<Option, isMulti, Group> & { required?: boolean }) {
|
||||
}: SelectProps<Option, IsMulti, Group> & { required?: boolean }) {
|
||||
const [hiddenInputValue, _setHiddenInputValue] = React.useState(() => {
|
||||
if (value instanceof Array || !value) {
|
||||
return;
|
||||
@@ -0,0 +1,159 @@
|
||||
import {
|
||||
components as reactSelectComponents,
|
||||
ControlProps,
|
||||
GroupBase,
|
||||
InputProps,
|
||||
MenuListProps,
|
||||
MenuProps,
|
||||
MultiValueProps,
|
||||
OptionProps,
|
||||
SingleValueProps,
|
||||
ValueContainerProps,
|
||||
} from "react-select";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { Icon } from "@calcom/ui/Icon";
|
||||
|
||||
export const InputComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
inputClassName,
|
||||
...props
|
||||
}: InputProps<Option, IsMulti, Group>) => {
|
||||
return (
|
||||
<reactSelectComponents.Input
|
||||
// disables our default form focus hightlight on the react-select input element
|
||||
inputClassName={classNames(
|
||||
"focus:ring-0 focus:ring-offset-0 dark:!text-darkgray-900 !text-black",
|
||||
inputClassName
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const OptionComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: OptionProps<Option, IsMulti, Group>) => {
|
||||
return (
|
||||
<reactSelectComponents.Option
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
"dark:bg-darkgray-100 !flex !cursor-pointer justify-between !py-3",
|
||||
props.isFocused && "dark:!bg-darkgray-200 !bg-gray-100",
|
||||
props.isSelected && "dark:!bg-darkgray-300 !bg-neutral-900"
|
||||
)}>
|
||||
<span>{props.label}</span> {props.isSelected && <Icon.FiCheck className="h-4 w-4" />}
|
||||
</reactSelectComponents.Option>
|
||||
);
|
||||
};
|
||||
|
||||
export const ControlComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: ControlProps<Option, IsMulti, Group>) => (
|
||||
<reactSelectComponents.Control
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
"dark:bg-darkgray-100 dark:border-darkgray-300 border-gray-300 bg-white text-sm leading-4 placeholder:text-sm placeholder:font-normal focus-within:border-0 focus-within:ring-2 focus-within:ring-neutral-800 hover:border-neutral-400 dark:focus-within:ring-white"
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
||||
export const SingleValueComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: SingleValueProps<Option, IsMulti, Group>) => (
|
||||
<reactSelectComponents.SingleValue
|
||||
{...props}
|
||||
className={classNames(
|
||||
className,
|
||||
"dark:text-darkgray-900 dark:placeholder:text-darkgray-500 text-black placeholder:text-gray-400"
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
||||
export const ValueContainerComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: ValueContainerProps<Option, IsMulti, Group>) => (
|
||||
<reactSelectComponents.ValueContainer
|
||||
{...props}
|
||||
className={classNames(
|
||||
"dark:text-darkgray-900 dark:placeholder:text-darkgray-500 text-black placeholder:text-gray-400",
|
||||
className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
||||
export const MultiValueComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: MultiValueProps<Option, IsMulti, Group>) => (
|
||||
<reactSelectComponents.MultiValue
|
||||
{...props}
|
||||
className={classNames(
|
||||
"dark:bg-darkgray-200 dark:text-darkgray-900 !rounded-md bg-gray-100 text-gray-700",
|
||||
className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
||||
export const MenuComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: MenuProps<Option, IsMulti, Group>) => (
|
||||
<reactSelectComponents.Menu
|
||||
{...props}
|
||||
className={classNames(
|
||||
"dark:bg-darkgray-100 dark:border-darkgray-300 border-1 !rounded-md border-gray-900 bg-white text-sm leading-4 dark:text-white",
|
||||
className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
|
||||
export const MenuListComponent = <
|
||||
Option,
|
||||
IsMulti extends boolean = false,
|
||||
Group extends GroupBase<Option> = GroupBase<Option>
|
||||
>({
|
||||
className,
|
||||
...props
|
||||
}: MenuListProps<Option, IsMulti, Group>) => (
|
||||
<reactSelectComponents.MenuList
|
||||
{...props}
|
||||
className={classNames(
|
||||
"scrollbar-thin scrollbar-thumb-rounded-md dark:scrollbar-thumb-darkgray-300 scrollbar-thumb-gray-300 scrollbar-track-transparent scrollbar-track-w-[80px] rounded-md",
|
||||
className
|
||||
)}
|
||||
/>
|
||||
);
|
||||
@@ -0,0 +1,4 @@
|
||||
import Select from "./Select";
|
||||
|
||||
export default Select;
|
||||
export { SelectWithValidation, SelectField, getReactSelectProps } from "./Select";
|
||||
@@ -4,7 +4,7 @@ import React, { useEffect, useState } from "react";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { DestinationCalendar } from "@calcom/prisma/client";
|
||||
import { trpc } from "@calcom/trpc/react";
|
||||
import Select from "@calcom/ui/v2/core/form/Select";
|
||||
import Select from "@calcom/ui/v2/core/form/select";
|
||||
|
||||
interface Props {
|
||||
onChange: (value: { externalId: string; integration: string }) => void;
|
||||
|
||||
Reference in new issue
Block a user