Chor/more UI migrations (#6353)
* Move tabs to components * Lots of form components * Update apps/web/components/apps/layouts/InstalledAppsLayout.tsx Co-authored-by: Omar López <[email protected]>
This commit is contained in:
1 parent
8e8c96c267
commit
3fc6f38da9
23 files changed
+53
-33
No files matched your search
@@ -0,0 +1,95 @@
|
||||
import React, { Dispatch, SetStateAction } from "react";
|
||||
import { components, GroupBase, OptionProps } from "react-select";
|
||||
import { Props } from "react-select";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Select } from "../select";
|
||||
|
||||
export type Option = {
|
||||
value: string;
|
||||
label: string;
|
||||
};
|
||||
|
||||
const InputOption: React.FC<OptionProps<any, boolean, GroupBase<any>>> = ({
|
||||
isDisabled,
|
||||
isFocused,
|
||||
isSelected,
|
||||
children,
|
||||
innerProps,
|
||||
className,
|
||||
...rest
|
||||
}) => {
|
||||
const props = {
|
||||
...innerProps,
|
||||
};
|
||||
|
||||
return (
|
||||
<components.Option
|
||||
className={classNames(
|
||||
className,
|
||||
"dark:bg-darkgray-100 !flex !cursor-pointer !py-3 text-[inherit]",
|
||||
isFocused && "dark:!bg-darkgray-200 !bg-gray-100",
|
||||
isSelected && "dark:!bg-darkgray-300 !bg-neutral-900"
|
||||
)}
|
||||
{...rest}
|
||||
isDisabled={isDisabled}
|
||||
isFocused={isFocused}
|
||||
isSelected={isSelected}
|
||||
innerProps={props}>
|
||||
<input
|
||||
type="checkbox"
|
||||
className="text-primary-600 focus:ring-primary-500 h-4 w-4 rounded border-gray-300 ltr:mr-2 rtl:ml-2"
|
||||
checked={isSelected}
|
||||
readOnly
|
||||
/>
|
||||
{children}
|
||||
</components.Option>
|
||||
);
|
||||
};
|
||||
|
||||
type MultiSelectionCheckboxesProps = {
|
||||
options: { label: string; value: string }[];
|
||||
setSelected: Dispatch<SetStateAction<Option[]>>;
|
||||
selected: Option[];
|
||||
setValue: (s: Option[]) => unknown;
|
||||
};
|
||||
|
||||
const MultiValue = ({ index, getValue }: { index: number; getValue: any }) => {
|
||||
const { t } = useLocale();
|
||||
|
||||
return <>{!index && <div>{t("nr_event_type", { count: getValue().length })}</div>}</>;
|
||||
};
|
||||
|
||||
export default function MultiSelectCheckboxes({
|
||||
options,
|
||||
isLoading,
|
||||
selected,
|
||||
setSelected,
|
||||
setValue,
|
||||
className,
|
||||
}: Omit<Props, "options"> & MultiSelectionCheckboxesProps) {
|
||||
const additonalComponents = { MultiValue };
|
||||
|
||||
return (
|
||||
<Select
|
||||
value={selected}
|
||||
onChange={(s: any) => {
|
||||
setSelected(s);
|
||||
setValue(s);
|
||||
}}
|
||||
options={options}
|
||||
isMulti
|
||||
className={classNames(className ? className : "w-64 text-sm")}
|
||||
isSearchable={false}
|
||||
closeMenuOnSelect={false}
|
||||
hideSelectedOptions={false}
|
||||
isLoading={isLoading}
|
||||
components={{
|
||||
...additonalComponents,
|
||||
Option: InputOption,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -1 +1,3 @@
|
||||
export { default as Checkbox } from "./Checkbox";
|
||||
export { default as MultiSelectCheckbox } from "./MultiSelectCheckboxes";
|
||||
export type { Option } from "./MultiSelectCheckboxes";
|
||||
@@ -0,0 +1,35 @@
|
||||
// @see: https://github.com/wojtekmaj/react-daterange-picker/issues/91
|
||||
import "@wojtekmaj/react-daterange-picker/dist/DateRangePicker.css";
|
||||
import PrimitiveDateRangePicker from "@wojtekmaj/react-daterange-picker/dist/entry.nostyle";
|
||||
|
||||
import { Icon } from "../../..";
|
||||
import "./styles.css";
|
||||
|
||||
type Props = {
|
||||
disabled?: boolean | undefined;
|
||||
startDate: Date;
|
||||
endDate: Date;
|
||||
onDatesChange?: ((arg: { startDate: Date; endDate: Date }) => void) | undefined;
|
||||
};
|
||||
|
||||
const DateRangePicker = ({ disabled, startDate, endDate, onDatesChange }: Props) => {
|
||||
return (
|
||||
<>
|
||||
<PrimitiveDateRangePicker
|
||||
disabled={disabled || false}
|
||||
className="rounded-sm border-gray-300 text-sm"
|
||||
clearIcon={null}
|
||||
calendarIcon={<Icon.FiCalendar className="h-4 w-4 text-gray-500" />}
|
||||
rangeDivider={<Icon.FiArrowRight className="h-4 w-4 text-gray-400 ltr:mr-2 rtl:ml-2" />}
|
||||
value={[startDate, endDate]}
|
||||
onChange={([startDate, endDate]: [Date, Date]) => {
|
||||
if (typeof onDatesChange === "function") onDatesChange({ startDate, endDate });
|
||||
}}
|
||||
nextLabel={<Icon.FiChevronRight className="h-4 w-4 text-gray-500" />}
|
||||
prevLabel={<Icon.FiChevronLeft className="h-4 w-4 text-gray-500" />}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default DateRangePicker;
|
||||
@@ -0,0 +1,5 @@
|
||||
import dynamic from "next/dynamic";
|
||||
|
||||
export const DateRangePickerLazy = dynamic(
|
||||
() => import("./DateRangePicker")
|
||||
) as unknown as typeof import("./DateRangePicker").default;
|
||||
@@ -0,0 +1,261 @@
|
||||
.react-calendar {
|
||||
width: 350px;
|
||||
max-width: 100%;
|
||||
background: white;
|
||||
border: 1px solid #e5e7eb;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
line-height: 1.125em;
|
||||
}
|
||||
|
||||
.react-calendar,
|
||||
.react-calendar *,
|
||||
.react-calendar ::before,
|
||||
.react-calendar ::after {
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.react-calendar--doubleView {
|
||||
width: 700px;
|
||||
}
|
||||
|
||||
.react-calendar--doubleView .react-calendar__viewContainer {
|
||||
display: flex;
|
||||
margin: -0.5em;
|
||||
}
|
||||
|
||||
.react-calendar--doubleView .react-calendar__viewContainer > * {
|
||||
width: 50%;
|
||||
margin: 0.5em;
|
||||
}
|
||||
|
||||
.react-calendar button {
|
||||
margin: 0;
|
||||
border: 0;
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.react-calendar__navigation {
|
||||
display: flex;
|
||||
height: 44px;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.react-calendar__navigation button {
|
||||
min-width: 44px;
|
||||
background: none;
|
||||
}
|
||||
|
||||
.react-calendar button:enabled:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.react-calendar__navigation button:disabled {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.react-calendar__navigation button:enabled:hover,
|
||||
.react-calendar__navigation button:enabled:focus {
|
||||
background-color: #e5e7eb;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.react-calendar__tile {
|
||||
max-width: 100%;
|
||||
padding: 10px 6.6667px;
|
||||
background: none;
|
||||
text-align: center;
|
||||
line-height: 16px;
|
||||
}
|
||||
|
||||
.react-calendar__month-view__weekdays {
|
||||
text-align: center;
|
||||
text-transform: uppercase;
|
||||
font-weight: bold;
|
||||
font-size: 0.75em;
|
||||
}
|
||||
|
||||
.react-calendar__month-view__weekdays__weekday {
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.react-calendar__month-view__weekNumbers .react-calendar__tile {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.75em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.react-calendar__year-view .react-calendar__tile,
|
||||
.react-calendar__decade-view .react-calendar__tile,
|
||||
.react-calendar__century-view .react-calendar__tile {
|
||||
padding: 2em 0.5em;
|
||||
}
|
||||
|
||||
.react-calendar__tile:disabled {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.react-calendar__tile:enabled:hover,
|
||||
.react-calendar__tile:enabled:focus {
|
||||
background-color: #e6e6e6;
|
||||
}
|
||||
|
||||
.react-daterange-picker > .react-daterange-picker__wrapper {
|
||||
padding: 0.625rem 0.75rem;
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.25rem;
|
||||
border-radius: 0.375rem;
|
||||
border-color: #e5e7eb;
|
||||
width: 360px;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
height: 36px;
|
||||
}
|
||||
|
||||
.react-daterange-picker__wrapper > .react-daterange-picker__calendar-button.react-daterange-picker__button {
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.react-daterange-picker > .react-daterange-picker__wrapper > .react-daterange-picker__inputGroup {
|
||||
height: auto;
|
||||
}
|
||||
|
||||
.react-daterange-picker.react-daterange-picker--disabled {
|
||||
background-color: transparent;
|
||||
}
|
||||
|
||||
.react-daterange-picker.react-daterange-picker--disabled > .react-daterange-picker__wrapper {
|
||||
background-color: #f3f4f6;
|
||||
}
|
||||
|
||||
.react-daterange-picker > .react-daterange-picker__wrapper:focus-within,
|
||||
.react-daterange-picker > .react-daterange-picker__wrapper:focus-within:hover {
|
||||
border-color: #111827;
|
||||
border-width: 2px;
|
||||
}
|
||||
|
||||
.react-daterange-picker > .react-daterange-picker__wrapper input {
|
||||
margin: 0;
|
||||
height: auto;
|
||||
border-radius: 0.125rem;
|
||||
}
|
||||
|
||||
.react-daterange-picker__calendar.react-daterange-picker__calendar--open {
|
||||
width: 360px;
|
||||
}
|
||||
|
||||
.react-daterange-picker__calendar > .react-calendar {
|
||||
padding: 0.5rem;
|
||||
border-radius: 0.375rem;
|
||||
border-width: 1px;
|
||||
border-color: #e5e7eb;
|
||||
width: 360px;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.react-calendar__navigation > .react-calendar__navigation__arrow {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.react-calendar__navigation > .react-calendar__navigation__arrow.react-calendar__navigation__prev2-button,
|
||||
.react-calendar__navigation > .react-calendar__navigation__arrow.react-calendar__navigation__next2-button {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.react-calendar__navigation > .react-calendar__navigation__label {
|
||||
display: flex;
|
||||
padding-left: 0.5rem;
|
||||
padding-right: 0.5rem;
|
||||
color: #111827;
|
||||
order: -9999;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.react-calendar__navigation > .react-calendar__navigation__arrow {
|
||||
text-align: center;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.react-calendar__month-view__weekdays__weekday > abbr {
|
||||
font-weight: 500;
|
||||
text-decoration: none;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.react-calendar__month-view__days {
|
||||
padding: 0.25rem;
|
||||
gap: 0.25rem;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
button.react-calendar__tile.react-calendar__month-view__days__day {
|
||||
flex: 0 0 13.25% !important;
|
||||
border-radius: 0.375rem;
|
||||
padding-top: 13px;
|
||||
padding-bottom: 13px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.react-calendar__tile.react-calendar__tile--hover:not(.react-calendar__tile--active) {
|
||||
background-color: #e5e7eb !important;
|
||||
}
|
||||
|
||||
.react-calendar__month-view__days > .react-calendar__tile.react-calendar__tile--hasActive,
|
||||
.react-calendar__month-view__days > .react-calendar__tile.react-calendar__tile--active,
|
||||
.react-calendar__month-view__days > button.react-calendar__tile.react-calendar__tile--active:hover {
|
||||
background-color: #111827;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.react-calendar__tile.react-calendar__tile--active.react-calendar__month-view__days__day--weekend {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.react-calendar__tile.react-calendar__month-view__days__day--weekend {
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.react-calendar__tile.react-calendar__month-view__days__day--neighboringMonth {
|
||||
color: #9ca3af;
|
||||
}
|
||||
|
||||
.react-calendar__tile--now::before {
|
||||
content: "\A";
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
border-radius: 50%;
|
||||
position: absolute;
|
||||
background-color: #111827;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
bottom: 0;
|
||||
z-index: inherit;
|
||||
}
|
||||
|
||||
button.react-calendar__tile.react-calendar__month-view__days__day:hover,
|
||||
.react-calendar__tile.react-calendar__year-view__months__month:hover {
|
||||
background-color: #d1d5db;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.react-daterange-picker > .react-daterange-picker__wrapper:hover {
|
||||
border-color: #9ca3af;
|
||||
}
|
||||
|
||||
.react-daterange-picker.react-daterange-picker--disabled > .react-daterange-picker__wrapper:hover {
|
||||
border-color: #e5e7eb;
|
||||
}
|
||||
|
||||
.react-calendar__navigation button.react-calendar__navigation__label:enabled:hover,
|
||||
.react-calendar__navigation button.react-calendar__navigation__label:enabled:focus {
|
||||
background-color: transparent;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import "react-calendar/dist/Calendar.css";
|
||||
import "react-date-picker/dist/DatePicker.css";
|
||||
import PrimitiveDatePicker from "react-date-picker/dist/entry.nostyle";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { Icon } from "@calcom/ui";
|
||||
|
||||
type Props = {
|
||||
date: Date;
|
||||
onDatesChange?: ((date: Date) => void) | undefined;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
minDate?: Date;
|
||||
};
|
||||
|
||||
const DatePicker = ({ minDate, disabled, date, onDatesChange, className }: Props) => {
|
||||
return (
|
||||
<PrimitiveDatePicker
|
||||
className={classNames(
|
||||
"focus:ring-primary-500 focus:border-primary-500 rounded-md border border-gray-300 p-1 pl-2 shadow-sm sm:text-sm",
|
||||
className
|
||||
)}
|
||||
calendarClassName="rounded-md"
|
||||
clearIcon={null}
|
||||
calendarIcon={<Icon.FiCalendar className="h-5 w-5 rounded-md text-gray-500" />}
|
||||
value={date}
|
||||
minDate={minDate}
|
||||
disabled={disabled}
|
||||
onChange={onDatesChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default DatePicker;
|
||||
@@ -0,0 +1 @@
|
||||
export { default as DatePicker } from "./DatePicker";
|
||||
@@ -1,4 +1,5 @@
|
||||
export { Checkbox } from "./checkbox";
|
||||
export { Checkbox, MultiSelectCheckbox } from "./checkbox";
|
||||
export type { Option } from "./checkbox";
|
||||
export { HintsOrErrors } from "./inputs/HintOrErrors";
|
||||
export {
|
||||
EmailField,
|
||||
@@ -19,3 +20,6 @@ export { Label } from "./inputs/Label";
|
||||
export { Select, SelectField, SelectWithValidation, getReactSelectProps } from "./select";
|
||||
export { TimezoneSelect } from "./timezone-select";
|
||||
export type { ITimezone, ITimezoneOption } from "./timezone-select";
|
||||
export { DateRangePickerLazy as DateRangePicker } from "./date-range-picker";
|
||||
export { BooleanToggleGroup, BooleanToggleGroupField, ToggleGroup, ToggleGroupItem } from "./toggleGroup";
|
||||
export { DatePicker } from "./datepicker";
|
||||
@@ -0,0 +1,89 @@
|
||||
import { useId } from "@radix-ui/react-id";
|
||||
import { Root as ToggleGroupPrimitive, Item as ToggleGroupItemPrimitive } from "@radix-ui/react-toggle-group";
|
||||
import { useState } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
|
||||
import { Label } from "../../../components/form/inputs/Label";
|
||||
|
||||
const boolean = (yesNo: "yes" | "no") => (yesNo === "yes" ? true : yesNo === "no" ? false : undefined);
|
||||
const yesNo = (boolean?: boolean) => (boolean === true ? "yes" : boolean === false ? "no" : undefined);
|
||||
|
||||
export const BooleanToggleGroup = function BooleanToggleGroup({
|
||||
defaultValue = true,
|
||||
value,
|
||||
disabled = false,
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
onValueChange = () => {},
|
||||
}: {
|
||||
defaultValue?: boolean;
|
||||
value?: boolean;
|
||||
onValueChange?: (value?: boolean) => void;
|
||||
disabled?: boolean;
|
||||
}) {
|
||||
// Maintain a state because it is not necessary that onValueChange the parent component would re-render. Think react-hook-form
|
||||
// Also maintain a string as boolean isn't accepted as ToggleGroupPrimitive value
|
||||
const [yesNoValue, setYesNoValue] = useState<"yes" | "no" | undefined>(yesNo(value));
|
||||
|
||||
if (!yesNoValue) {
|
||||
setYesNoValue(yesNo(defaultValue));
|
||||
onValueChange(defaultValue);
|
||||
return null;
|
||||
}
|
||||
const commonClass =
|
||||
"mb-2 inline-flex items-center justify-center rounded-md py-[10px] px-4 text-sm font-medium leading-4 md:mb-0";
|
||||
const selectedClass = classNames(commonClass, "bg-gray-200 text-gray-900");
|
||||
const unselectedClass = classNames(commonClass, "text-gray-600 hover:bg-gray-100 hover:text-gray-900");
|
||||
return (
|
||||
<ToggleGroupPrimitive
|
||||
value={yesNoValue}
|
||||
type="single"
|
||||
disabled={disabled}
|
||||
className="space-x-2 rounded-sm rtl:space-x-reverse"
|
||||
onValueChange={(yesNoValue: "yes" | "no") => {
|
||||
setYesNoValue(yesNoValue);
|
||||
onValueChange(boolean(yesNoValue));
|
||||
}}>
|
||||
<ToggleGroupItemPrimitive
|
||||
className={classNames(boolean(yesNoValue) ? selectedClass : unselectedClass)}
|
||||
disabled={disabled}
|
||||
value="yes">
|
||||
Yes
|
||||
</ToggleGroupItemPrimitive>
|
||||
<ToggleGroupItemPrimitive
|
||||
disabled={disabled}
|
||||
className={classNames(!boolean(yesNoValue) ? selectedClass : unselectedClass)}
|
||||
value="no">
|
||||
No
|
||||
</ToggleGroupItemPrimitive>
|
||||
</ToggleGroupPrimitive>
|
||||
);
|
||||
};
|
||||
|
||||
export const BooleanToggleGroupField = function BooleanToggleGroupField(
|
||||
props: Parameters<typeof BooleanToggleGroup>[0] & {
|
||||
label?: string;
|
||||
containerClassName?: string;
|
||||
name?: string;
|
||||
labelProps?: React.ComponentProps<typeof Label>;
|
||||
className?: string;
|
||||
error?: string;
|
||||
}
|
||||
) {
|
||||
const { t } = useLocale();
|
||||
const { label = t(props.name || ""), containerClassName, labelProps, className, ...passThrough } = props;
|
||||
const id = useId();
|
||||
return (
|
||||
<div className={classNames(containerClassName)}>
|
||||
<div className={className}>
|
||||
{!!label && (
|
||||
<Label htmlFor={id} {...labelProps} className={classNames(props.error && "text-red-900", "mt-4")}>
|
||||
{label}
|
||||
</Label>
|
||||
)}
|
||||
</div>
|
||||
<BooleanToggleGroup {...passThrough} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,62 @@
|
||||
import * as RadixToggleGroup from "@radix-ui/react-toggle-group";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
export const ToggleGroupItem = () => <div>hi</div>;
|
||||
|
||||
interface ToggleGroupProps extends Omit<RadixToggleGroup.ToggleGroupSingleProps, "type"> {
|
||||
options: { value: string; label: string; disabled?: boolean }[];
|
||||
isFullWidth?: boolean;
|
||||
}
|
||||
|
||||
export const ToggleGroup = ({ options, onValueChange, isFullWidth, ...props }: ToggleGroupProps) => {
|
||||
const [value, setValue] = useState<string | undefined>(props.defaultValue);
|
||||
const [activeToggleElement, setActiveToggleElement] = useState<null | HTMLButtonElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (value && onValueChange) onValueChange(value);
|
||||
}, [value, onValueChange]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<RadixToggleGroup.Root
|
||||
type="single"
|
||||
{...props}
|
||||
onValueChange={setValue}
|
||||
className={classNames(
|
||||
"dark:border-darkgray-200 relative inline-flex rounded-md border border-gray-200 p-1",
|
||||
props.className,
|
||||
isFullWidth && "w-full"
|
||||
)}>
|
||||
{/* Active toggle. It's a separate element so we can animate it nicely. */}
|
||||
<span
|
||||
aria-hidden
|
||||
className="dark:bg-darkgray-200 absolute top-[4px] bottom-[4px] left-0 z-[0] rounded-[4px] bg-gray-200 transition-all"
|
||||
style={{ left: activeToggleElement?.offsetLeft, width: activeToggleElement?.offsetWidth }}
|
||||
/>
|
||||
{options.map((option) => (
|
||||
<RadixToggleGroup.Item
|
||||
disabled={option.disabled}
|
||||
key={option.value}
|
||||
value={option.value}
|
||||
className={classNames(
|
||||
"relative rounded-[4px] px-3 py-1 text-sm",
|
||||
option.disabled
|
||||
? "text-gray-400 hover:cursor-not-allowed dark:text-neutral-100"
|
||||
: "dark:text-neutral-200 [&[aria-checked='false']]:hover:font-medium",
|
||||
isFullWidth && "w-full"
|
||||
)}
|
||||
ref={(node) => {
|
||||
if (node && value === option.value) {
|
||||
setActiveToggleElement(node);
|
||||
}
|
||||
return node;
|
||||
}}>
|
||||
{option.label}
|
||||
</RadixToggleGroup.Item>
|
||||
))}
|
||||
</RadixToggleGroup.Root>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,2 @@
|
||||
export { ToggleGroup, ToggleGroupItem } from "./ToggleGroup";
|
||||
export { BooleanToggleGroup, BooleanToggleGroupField } from "./BooleanToggleGroup";
|
||||
@@ -27,6 +27,14 @@ export {
|
||||
SelectField,
|
||||
SelectWithValidation,
|
||||
TimezoneSelect,
|
||||
BooleanToggleGroup,
|
||||
BooleanToggleGroupField,
|
||||
DatePicker,
|
||||
DateRangePicker,
|
||||
MultiSelectCheckbox,
|
||||
ToggleGroup,
|
||||
ToggleGroupItem,
|
||||
getReactSelectProps,
|
||||
} from "./form";
|
||||
export type { ITimezone, ITimezoneOption } from "./form";
|
||||
export {
|
||||
@@ -56,6 +64,8 @@ export { List, ListItem, ListItemText, ListItemTitle, ListLinkItem } from "./lis
|
||||
export type { ListItemProps, ListProps } from "./list";
|
||||
export { HeadSeo } from "./head-seo";
|
||||
export { Skeleton, SkeletonAvatar, SkeletonButton, SkeletonContainer, SkeletonText } from "./skeleton";
|
||||
export { HorizontalTabs, HorizontalTabItem, VerticalTabs, VerticalTabItem } from "./navigation";
|
||||
export type { HorizontalTabItemProps, NavTabProps, VerticalTabItemProps } from "./navigation";
|
||||
export { Card, StepCard } from "./card";
|
||||
export type { BaseCardProps } from "./card";
|
||||
export { Tooltip } from "./tooltip";
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
/* TODO: Implement NavigationItem */
|
||||
export {};
|
||||
@@ -0,0 +1,7 @@
|
||||
export { default as HorizontalTabItem } from "./tabs/HorizontalTabItem";
|
||||
export type { HorizontalTabItemProps } from "./tabs/HorizontalTabItem";
|
||||
export { default as HorizontalTabs } from "./tabs/HorizontalTabs";
|
||||
export type { NavTabProps } from "./tabs/HorizontalTabs";
|
||||
export { default as VerticalTabItem } from "./tabs/VerticalTabItem";
|
||||
export type { VerticalTabItemProps } from "./tabs/VerticalTabItem";
|
||||
export { default as VerticalTabs } from "./tabs/VerticalTabs";
|
||||
@@ -0,0 +1,53 @@
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { ComponentProps } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
|
||||
import { SkeletonText } from "../../skeleton";
|
||||
|
||||
export type HorizontalTabItemProps = {
|
||||
name: string;
|
||||
disabled?: boolean;
|
||||
className?: string;
|
||||
href: string;
|
||||
linkProps?: Omit<ComponentProps<typeof Link>, "href">;
|
||||
icon?: SVGComponent;
|
||||
};
|
||||
|
||||
const HorizontalTabItem = function ({ name, href, linkProps, ...props }: HorizontalTabItemProps) {
|
||||
const { t, isLocaleReady } = useLocale();
|
||||
const { asPath } = useRouter();
|
||||
const isCurrent = asPath.startsWith(href);
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={name}
|
||||
href={href}
|
||||
{...linkProps}
|
||||
className={classNames(
|
||||
isCurrent ? "bg-gray-200 text-gray-900" : " text-gray-600 hover:bg-gray-100 hover:text-gray-900 ",
|
||||
"inline-flex items-center justify-center whitespace-nowrap rounded-[4px] py-[10px] px-4 text-sm font-medium leading-4 md:mb-0",
|
||||
props.disabled && "pointer-events-none !opacity-30",
|
||||
props.className
|
||||
)}
|
||||
aria-current={isCurrent ? "page" : undefined}>
|
||||
{props.icon && (
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
<props.icon
|
||||
className={classNames(
|
||||
isCurrent ? "text-neutral-900" : "text-gray-400 group-hover:text-gray-500",
|
||||
"-ml-0.5 hidden h-4 w-4 ltr:mr-2 rtl:ml-2 sm:inline-block"
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
)}
|
||||
{isLocaleReady ? t(name) : <SkeletonText className="h-4 w-24" />}
|
||||
</Link>
|
||||
);
|
||||
};
|
||||
|
||||
export default HorizontalTabItem;
|
||||
@@ -0,0 +1,22 @@
|
||||
import HorizontalTabItem, { HorizontalTabItemProps } from "./HorizontalTabItem";
|
||||
|
||||
export interface NavTabProps {
|
||||
tabs: HorizontalTabItemProps[];
|
||||
linkProps?: HorizontalTabItemProps["linkProps"];
|
||||
actions?: JSX.Element;
|
||||
}
|
||||
|
||||
const HorizontalTabs = function ({ tabs, linkProps, actions, ...props }: NavTabProps) {
|
||||
return (
|
||||
<div className="mb-2 max-w-[calc(100%+40px)] lg:mb-5">
|
||||
<nav className="no-scrollbar flex overflow-scroll rounded-md border p-1" aria-label="Tabs" {...props}>
|
||||
{tabs.map((tab, idx) => (
|
||||
<HorizontalTabItem {...tab} key={idx} {...linkProps} />
|
||||
))}
|
||||
</nav>
|
||||
{actions && actions}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default HorizontalTabs;
|
||||
@@ -0,0 +1,96 @@
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/router";
|
||||
import { ComponentProps, Fragment } from "react";
|
||||
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
import { SVGComponent } from "@calcom/types/SVGComponent";
|
||||
|
||||
import { Icon } from "../../..";
|
||||
import { Skeleton } from "../../skeleton";
|
||||
|
||||
export type VerticalTabItemProps = {
|
||||
name: string;
|
||||
info?: string;
|
||||
icon?: SVGComponent;
|
||||
disabled?: boolean;
|
||||
children?: VerticalTabItemProps[];
|
||||
textClassNames?: string;
|
||||
className?: string;
|
||||
isChild?: boolean;
|
||||
hidden?: boolean;
|
||||
disableChevron?: boolean;
|
||||
href: string;
|
||||
isExternalLink?: boolean;
|
||||
linkProps?: Omit<ComponentProps<typeof Link>, "href">;
|
||||
avatar?: string;
|
||||
};
|
||||
|
||||
const VerticalTabItem = function ({
|
||||
name,
|
||||
href,
|
||||
info,
|
||||
isChild,
|
||||
disableChevron,
|
||||
linkProps,
|
||||
...props
|
||||
}: VerticalTabItemProps) {
|
||||
const { t } = useLocale();
|
||||
const { asPath } = useRouter();
|
||||
const isCurrent = asPath.startsWith(href);
|
||||
|
||||
return (
|
||||
<Fragment key={name}>
|
||||
{!props.hidden && (
|
||||
<>
|
||||
<Link
|
||||
key={name}
|
||||
href={href}
|
||||
{...linkProps}
|
||||
target={props.isExternalLink ? "_blank" : "_self"}
|
||||
className={classNames(
|
||||
props.textClassNames || "text-sm font-medium leading-none text-gray-600",
|
||||
"min-h-9 group flex w-64 flex-row items-center rounded-md px-2 py-[10px] hover:bg-gray-100 group-hover:text-gray-700 [&[aria-current='page']]:bg-gray-200 [&[aria-current='page']]:text-gray-900",
|
||||
props.disabled && "pointer-events-none !opacity-30",
|
||||
(isChild || !props.icon) && "ml-7 w-auto ltr:mr-5 rtl:ml-5",
|
||||
!info ? "h-6" : "h-14",
|
||||
props.className
|
||||
)}
|
||||
data-testid={`vertical-tab-${name}`}
|
||||
aria-current={isCurrent ? "page" : undefined}>
|
||||
{props.icon && (
|
||||
<props.icon className="h-[16px] w-[16px] stroke-[2px] ltr:mr-[10px] rtl:ml-[10px] md:mt-0" />
|
||||
)}
|
||||
<div className="h-fit">
|
||||
<span className="flex items-center space-x-2 rtl:space-x-reverse">
|
||||
<Skeleton title={t(name)} as="p" className="max-w-36 min-h-4 truncate">
|
||||
{t(name)}
|
||||
</Skeleton>
|
||||
{props.isExternalLink ? <Icon.FiExternalLink /> : null}
|
||||
</span>
|
||||
{info && (
|
||||
<Skeleton as="p" title={t(info)} className="max-w-44 mt-1 truncate text-xs font-normal">
|
||||
{t(info)}
|
||||
</Skeleton>
|
||||
)}
|
||||
</div>
|
||||
{!disableChevron && isCurrent && (
|
||||
<div className="ml-auto self-center">
|
||||
<Icon.FiChevronRight
|
||||
width={20}
|
||||
height={20}
|
||||
className="h-auto w-[20px] stroke-[1.5px] text-gray-700"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</Link>
|
||||
{props.children?.map((child) => (
|
||||
<VerticalTabItem key={child.name} {...child} isChild />
|
||||
))}
|
||||
</>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
};
|
||||
|
||||
export default VerticalTabItem;
|
||||
@@ -0,0 +1,35 @@
|
||||
import { classNames } from "@calcom/lib";
|
||||
|
||||
import VerticalTabItem, { VerticalTabItemProps } from "./VerticalTabItem";
|
||||
|
||||
export { VerticalTabItem };
|
||||
|
||||
export interface NavTabProps {
|
||||
tabs: VerticalTabItemProps[];
|
||||
children?: React.ReactNode;
|
||||
className?: string;
|
||||
sticky?: boolean;
|
||||
linkProps?: VerticalTabItemProps["linkProps"];
|
||||
itemClassname?: string;
|
||||
}
|
||||
|
||||
const NavTabs = function ({ tabs, className = "", sticky, linkProps, ...props }: NavTabProps) {
|
||||
return (
|
||||
<nav
|
||||
className={classNames(
|
||||
`no-scrollbar flex flex-col space-y-1 overflow-scroll ${className}`,
|
||||
sticky && "sticky top-0 -mt-7"
|
||||
)}
|
||||
aria-label="Tabs"
|
||||
{...props}>
|
||||
{/* padding top for sticky */}
|
||||
{sticky && <div className="pt-6" />}
|
||||
{props.children}
|
||||
{tabs.map((tab, idx) => (
|
||||
<VerticalTabItem {...tab} key={idx} linkProps={linkProps} className={props.itemClassname} />
|
||||
))}
|
||||
</nav>
|
||||
);
|
||||
};
|
||||
|
||||
export default NavTabs;
|
||||
Reference in new issue
Block a user