Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
@@ -0,0 +1,26 @@
|
||||
import { Button } from "../button";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { t as i18nT } from "i18next";
|
||||
|
||||
export default function BackButtonWithTitle({
|
||||
href,
|
||||
children,
|
||||
className,
|
||||
size = "xs",
|
||||
}: {
|
||||
href: string;
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
size?: "default" | "sm" | "xs" | "sm" | "lg";
|
||||
}) {
|
||||
return (
|
||||
<div className={cn("flex items-center space-x-2 truncate", className)}>
|
||||
<Button size={size} variant="outline" asChild className="truncate font-normal">
|
||||
<a href={href} aria-label={i18nT("shared.back")}>
|
||||
←
|
||||
</a>
|
||||
</Button>
|
||||
<div className="truncate">{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
import { useLocation, useMatches } from "react-router";
|
||||
import { ReactNode } from "react";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import AnalyticsHelper from "~/utils/helpers/AnalyticsHelper";
|
||||
import LinkOrAhref from "./LinkOrAhref";
|
||||
import clsx from "clsx";
|
||||
|
||||
const DEBUG_MODE = false;
|
||||
|
||||
interface Props {
|
||||
type?: "button" | "submit";
|
||||
to?: string | undefined;
|
||||
children?: ReactNode;
|
||||
className?: string;
|
||||
target?: undefined | "_blank";
|
||||
role?: string;
|
||||
rel?: string;
|
||||
event: {
|
||||
action: string;
|
||||
category: string;
|
||||
label: string;
|
||||
value: string;
|
||||
};
|
||||
onClick?: () => void;
|
||||
sendEvent?: boolean;
|
||||
disabled?: boolean;
|
||||
isLoading?: boolean;
|
||||
reloadDocument?: boolean;
|
||||
}
|
||||
export default function ButtonEvent({
|
||||
type,
|
||||
to,
|
||||
target,
|
||||
children,
|
||||
className,
|
||||
role,
|
||||
rel,
|
||||
event,
|
||||
onClick,
|
||||
sendEvent = true,
|
||||
disabled,
|
||||
isLoading,
|
||||
reloadDocument,
|
||||
}: Props) {
|
||||
let location = useLocation();
|
||||
const rootData = useRootData();
|
||||
const matches = useMatches();
|
||||
|
||||
function onClicked() {
|
||||
if (onClick) {
|
||||
onClick();
|
||||
}
|
||||
if (!event || !sendEvent) {
|
||||
return;
|
||||
}
|
||||
const routeMatch = matches.find((m) => m.pathname == location.pathname);
|
||||
AnalyticsHelper.addEvent({
|
||||
url: location.pathname,
|
||||
route: routeMatch?.id,
|
||||
rootData,
|
||||
action: event.action,
|
||||
category: event.category,
|
||||
label: event.label,
|
||||
value: event.value,
|
||||
});
|
||||
}
|
||||
return (
|
||||
<LinkOrAhref
|
||||
type={type}
|
||||
to={to}
|
||||
target={target}
|
||||
className={clsx(className, DEBUG_MODE && "ring-2 ring-red-500 ring-offset-2")}
|
||||
role={role}
|
||||
rel={rel}
|
||||
onClick={onClicked}
|
||||
disabled={disabled}
|
||||
isLoading={isLoading}
|
||||
reloadDocument={reloadDocument}
|
||||
>
|
||||
{children}
|
||||
</LinkOrAhref>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/* This example requires Tailwind CSS v2.0+ */
|
||||
import { Fragment, ReactNode } from "react";
|
||||
import { Popover, Transition } from "@headlessui/react";
|
||||
import ChevronDownIcon from "../icons/ChevronDownIcon";
|
||||
import { Button } from "../button";
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
children: ReactNode;
|
||||
}
|
||||
export default function ButtonFlyout({ title, className, disabled, children }: Props) {
|
||||
return (
|
||||
<Popover className="relative">
|
||||
{() => (
|
||||
<>
|
||||
<Popover.Button as={Button} type="button" variant="outline" disabled={disabled} className={className}>
|
||||
<span className="inline-flex items-center space-x-2">
|
||||
<span>{title}</span>
|
||||
<ChevronDownIcon className="h-5 w-5 text-muted-foreground" />
|
||||
</span>
|
||||
</Popover.Button>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
enter="transition ease-out duration-200"
|
||||
enterFrom="opacity-0 translate-y-1"
|
||||
enterTo="opacity-100 translate-y-0"
|
||||
leave="transition ease-in duration-150"
|
||||
leaveFrom="opacity-100 translate-y-0"
|
||||
leaveTo="opacity-0 translate-y-1"
|
||||
>
|
||||
<Popover.Panel className="absolute left-1/2 z-10 mt-3 w-screen max-w-xs -translate-x-1/2 transform px-2 sm:px-0">
|
||||
<div className="overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5">
|
||||
<div className="bg-background relative grid gap-6 px-5 py-6 sm:gap-8 sm:p-8">{children}</div>
|
||||
</div>
|
||||
</Popover.Panel>
|
||||
</Transition>
|
||||
</>
|
||||
)}
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import { MouseEventHandler, ReactNode, Ref, useEffect, useRef } from "react";
|
||||
import LinkOrAhref from "./LinkOrAhref";
|
||||
import { Button } from "../button";
|
||||
import { useLocation, useMatches } from "react-router";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import AnalyticsHelper from "~/utils/helpers/AnalyticsHelper";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
type?: "button" | "submit" | "reset" | undefined;
|
||||
to?: string;
|
||||
target?: undefined | "_blank";
|
||||
rel?: string;
|
||||
disabled?: boolean;
|
||||
destructive?: boolean;
|
||||
isExternal?: boolean;
|
||||
onClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
||||
autoFocus?: boolean;
|
||||
children: ReactNode;
|
||||
prefetch?: "intent" | "render" | "none";
|
||||
event?: { action: string; category: string; label: string; value: string };
|
||||
sendEvent?: boolean;
|
||||
dataUiId?: string;
|
||||
}
|
||||
|
||||
export default function ButtonPrimary({
|
||||
className = "",
|
||||
type = "button",
|
||||
onClick,
|
||||
disabled,
|
||||
destructive,
|
||||
to,
|
||||
target,
|
||||
rel,
|
||||
isExternal = false,
|
||||
autoFocus,
|
||||
prefetch,
|
||||
children,
|
||||
event,
|
||||
sendEvent = true,
|
||||
dataUiId,
|
||||
}: Props) {
|
||||
// const combinedClassName = clsx(
|
||||
// className,
|
||||
// "inline-flex items-center space-x-2 px-4 py-2 border border-transparent shadow-2xs text-sm font-medium rounded-md text-white focus:outline-hidden focus:ring-2 focus:ring-accent-300",
|
||||
// disabled && "cursor-not-allowed opacity-75",
|
||||
// !destructive && "bg-primary",
|
||||
// destructive && "bg-red-600",
|
||||
// !disabled && !destructive && !className && "hover:bg-accent-900 focus:ring-ring hover:text-accent-100",
|
||||
// !disabled && destructive && "hover:bg-red-700 focus:ring-red-500"
|
||||
// );
|
||||
|
||||
let location = useLocation();
|
||||
const rootData = useRootData();
|
||||
const matches = useMatches();
|
||||
const focusRef = useRef<HTMLButtonElement | HTMLAnchorElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoFocus) {
|
||||
return;
|
||||
}
|
||||
const timeout = window.setTimeout(() => focusRef.current?.focus(), 0);
|
||||
return () => window.clearTimeout(timeout);
|
||||
}, [autoFocus]);
|
||||
|
||||
function onClicked(e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) {
|
||||
if (onClick) {
|
||||
onClick(e);
|
||||
}
|
||||
if (!event || !sendEvent) {
|
||||
return;
|
||||
}
|
||||
const routeMatch = matches.find((m) => m.pathname == location.pathname);
|
||||
AnalyticsHelper.addEvent({
|
||||
url: location.pathname,
|
||||
route: routeMatch?.id,
|
||||
rootData,
|
||||
action: event.action,
|
||||
category: event.category,
|
||||
label: event.label,
|
||||
value: event.value,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<span>
|
||||
{(() => {
|
||||
if (!to || disabled) {
|
||||
return (
|
||||
<Button
|
||||
variant={destructive ? "destructive" : undefined}
|
||||
className={clsx("inline-flex items-center space-x-2", className)}
|
||||
onClick={onClicked}
|
||||
type={type}
|
||||
disabled={disabled}
|
||||
ref={focusRef as Ref<HTMLButtonElement>}
|
||||
data-ui-id={dataUiId}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
} else if (to && isExternal) {
|
||||
return (
|
||||
<Button asChild>
|
||||
<a
|
||||
href={to}
|
||||
target={target}
|
||||
rel={rel}
|
||||
ref={focusRef as Ref<HTMLAnchorElement>}
|
||||
onClick={onClicked}
|
||||
data-ui-id={dataUiId}
|
||||
className={clsx("inline-flex items-center space-x-2", className)}
|
||||
>
|
||||
{children}
|
||||
</a>
|
||||
</Button>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Button asChild>
|
||||
<LinkOrAhref
|
||||
to={disabled ? "" : to}
|
||||
target={target}
|
||||
rel={rel}
|
||||
prefetch={prefetch}
|
||||
className={clsx("inline-flex items-center space-x-2", className)}
|
||||
// className={clsx(
|
||||
// className,
|
||||
// "borde1-transparent focus:ring-accent-300 inline-flex items-center space-x-2 rounded-md border px-4 py-2 text-sm font-medium text-white shadow-2xs focus:outline-hidden focus:ring-2",
|
||||
// disabled && "cursor-not-allowed opacity-75",
|
||||
// !destructive && "bg-primary",
|
||||
// destructive && "bg-red-600",
|
||||
// !disabled && !destructive && !className && "hover:bg-accent-900 hover:text-accent-100 focus:ring-ring",
|
||||
// !disabled && destructive && "hover:bg-red-700 focus:ring-red-500"
|
||||
// )}
|
||||
autoFocus={autoFocus}
|
||||
onClick={onClicked}
|
||||
data-ui-id={dataUiId}
|
||||
>
|
||||
{children}
|
||||
</LinkOrAhref>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
import { MouseEventHandler, ReactNode } from "react";
|
||||
import LinkOrAhref from "./LinkOrAhref";
|
||||
import { Button } from "../button";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
type?: "button" | "submit" | "reset" | undefined;
|
||||
to?: string;
|
||||
target?: undefined | "_blank";
|
||||
rel?: string;
|
||||
ariaLabel?: string;
|
||||
disabled?: boolean;
|
||||
destructive?: boolean;
|
||||
children: ReactNode;
|
||||
onClick?: MouseEventHandler<HTMLButtonElement>;
|
||||
isLoading?: boolean;
|
||||
prefetch?: "intent" | "render" | "none";
|
||||
reloadDocument?: boolean;
|
||||
}
|
||||
|
||||
export default function ButtonSecondary({
|
||||
className = "",
|
||||
type = "button",
|
||||
onClick,
|
||||
disabled,
|
||||
destructive,
|
||||
to,
|
||||
target,
|
||||
rel,
|
||||
ariaLabel,
|
||||
children,
|
||||
isLoading,
|
||||
prefetch,
|
||||
reloadDocument,
|
||||
}: Props) {
|
||||
return (
|
||||
<span>
|
||||
{(() => {
|
||||
if (!to || disabled) {
|
||||
return (
|
||||
<Button
|
||||
variant={destructive ? "destructive" : "secondary"}
|
||||
onClick={onClick}
|
||||
type={type}
|
||||
disabled={disabled || isLoading}
|
||||
className={clsx("inline-flex items-center space-x-2", className)}
|
||||
aria-label={ariaLabel}
|
||||
// className={clsx(
|
||||
// isLoading && "base-spinner cursor-not-allowed",
|
||||
// className,
|
||||
// "focus:border-accent-300 inline-flex items-center space-x-2 rounded-md border border-border px-3 py-2 text-sm font-medium shadow-2xs focus:outline-hidden focus:ring-2",
|
||||
// disabled ? "cursor-not-allowed bg-secondary/90 opacity-75" : "bg-background",
|
||||
// !destructive && "text-accent-700",
|
||||
// destructive && "text-red-700",
|
||||
// !disabled && !destructive && !className && "hover:border-accent-300 hover:text-accent-900 focus:ring-ring hover:bg-secondary",
|
||||
// !disabled && destructive && "hover:bg-red-50 focus:ring-red-500"
|
||||
// )}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Button asChild variant="secondary">
|
||||
<LinkOrAhref
|
||||
to={to}
|
||||
target={target}
|
||||
rel={rel}
|
||||
prefetch={prefetch}
|
||||
reloadDocument={reloadDocument}
|
||||
className={clsx("inline-flex items-center space-x-2", className)}
|
||||
ariaLabel={ariaLabel}
|
||||
// className={clsx(
|
||||
// isLoading && "base-spinner cursor-not-allowed",
|
||||
// className,
|
||||
// "focus:border-accent-300 inline-flex items-center space-x-2 rounded-md border border-border px-3 py-2 text-sm font-medium shadow-2xs focus:outline-hidden focus:ring-2",
|
||||
// disabled ? "cursor-not-allowed bg-secondary/90 opacity-75" : "bg-background",
|
||||
// !destructive && "text-accent-700",
|
||||
// destructive && "text-red-700",
|
||||
// !disabled && !destructive && !className && "hover:border-accent-300 hover:text-accent-900 focus:ring-ring hover:bg-secondary",
|
||||
// !disabled && destructive && "hover:bg-red-50 focus:ring-red-500"
|
||||
// )}
|
||||
>
|
||||
{children}
|
||||
</LinkOrAhref>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { Fragment, ReactNode } from "react";
|
||||
import { Popover, Transition } from "@headlessui/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import ShareIcon from "../icons/ShareIcon";
|
||||
import { Button } from "../button";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
disabled?: boolean;
|
||||
children: ReactNode;
|
||||
}
|
||||
export default function ButtonFlyout({ className, disabled, children }: Props) {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Popover className="relative">
|
||||
{({ open }) => (
|
||||
<>
|
||||
<Popover.Button as={Button} type="button" variant="outline" disabled={disabled} className={className}>
|
||||
<span className="inline-flex items-center space-x-2">
|
||||
<span>{t("shared.share")}</span>
|
||||
<ShareIcon className={open ? "h-4 w-4 text-foreground/80" : "h-4 w-4 text-muted-foreground"} />
|
||||
</span>
|
||||
</Popover.Button>
|
||||
|
||||
<Transition
|
||||
as={Fragment}
|
||||
enter="transition ease-out duration-200"
|
||||
enterFrom="opacity-0 translate-y-1"
|
||||
enterTo="opacity-100 translate-y-0"
|
||||
leave="transition ease-in duration-150"
|
||||
leaveFrom="opacity-100 translate-y-0"
|
||||
leaveTo="opacity-0 translate-y-1"
|
||||
>
|
||||
<Popover.Panel className="absolute left-1/2 z-10 mt-3 w-screen max-w-xs -translate-x-1/2 transform px-2 sm:px-0">
|
||||
<div className="overflow-hidden rounded-lg shadow-lg ring-1 ring-black ring-opacity-5">
|
||||
<div className="bg-background relative grid gap-6 px-5 py-6 sm:gap-8 sm:p-8">{children}</div>
|
||||
</div>
|
||||
</Popover.Panel>
|
||||
</Transition>
|
||||
</>
|
||||
)}
|
||||
</Popover>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
import { Fragment, ReactNode } from "react";
|
||||
import LinkOrAhref from "./LinkOrAhref";
|
||||
import ButtonEvent from "./ButtonEvent";
|
||||
import { useNavigation, useSearchParams, useSubmit } from "react-router";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Props {
|
||||
type?: "button" | "submit";
|
||||
to?: string | undefined;
|
||||
submits?: { action: string; values: { [key: string]: string } };
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
target?: undefined | "_blank";
|
||||
role?: string;
|
||||
rel?: string;
|
||||
event?: {
|
||||
action: string;
|
||||
category: string;
|
||||
label: string;
|
||||
value: string;
|
||||
};
|
||||
onClick?: () => void;
|
||||
sendEvent?: boolean;
|
||||
disabled?: boolean;
|
||||
}
|
||||
export default function ButtonSubmitForm({ submits, type, to, target, children, className, role, rel, event, onClick, sendEvent = true, disabled }: Props) {
|
||||
const submit = useSubmit();
|
||||
const navigation = useNavigation();
|
||||
const [searchParams] = useSearchParams();
|
||||
const isLoading = navigation.state === "submitting" && navigation.formData?.get("action") === submits?.action;
|
||||
|
||||
function onClicked() {
|
||||
if (!submits) {
|
||||
return;
|
||||
}
|
||||
const formData = new FormData();
|
||||
formData.append("action", submits.action ?? "");
|
||||
const values: { [key: string]: string } = submits?.values;
|
||||
for (const key in values) {
|
||||
formData.append(key, values[key]);
|
||||
}
|
||||
if (submits.action === "subscribe") {
|
||||
formData.set("coupon", searchParams.get("coupon")?.toString() ?? "");
|
||||
}
|
||||
submit(formData, {
|
||||
method: "post",
|
||||
});
|
||||
}
|
||||
return (
|
||||
<Fragment>
|
||||
{event ? (
|
||||
<ButtonEvent
|
||||
event={event}
|
||||
type={type}
|
||||
to={submits ? undefined : to}
|
||||
target={target}
|
||||
className={clsx(className, isLoading && "base-spinner")}
|
||||
role={role}
|
||||
rel={rel}
|
||||
onClick={onClicked}
|
||||
disabled={disabled}
|
||||
>
|
||||
{children}
|
||||
</ButtonEvent>
|
||||
) : (
|
||||
<LinkOrAhref
|
||||
type={type}
|
||||
to={submits ? undefined : to}
|
||||
target={target}
|
||||
className={clsx(className, isLoading && "base-spinner")}
|
||||
role={role}
|
||||
rel={rel}
|
||||
onClick={onClicked}
|
||||
disabled={disabled}
|
||||
>
|
||||
{children}
|
||||
</LinkOrAhref>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { MouseEventHandler, ReactNode, useRef } from "react";
|
||||
import clsx from "clsx";
|
||||
import LinkOrAhref from "./LinkOrAhref";
|
||||
import ConfirmModal, { RefConfirmModal } from "../modals/ConfirmModal";
|
||||
import { Button } from "../button";
|
||||
import { useLocation, useMatches } from "react-router";
|
||||
import { useRootData } from "~/utils/data/useRootData";
|
||||
import AnalyticsHelper from "~/utils/helpers/AnalyticsHelper";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
type?: "button" | "submit" | "reset" | undefined;
|
||||
to?: string;
|
||||
target?: undefined | "_blank";
|
||||
rel?: string;
|
||||
disabled?: boolean;
|
||||
destructive?: boolean;
|
||||
children: ReactNode;
|
||||
onClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
|
||||
reloadDocument?: boolean;
|
||||
prefetch?: "intent" | "render" | "none";
|
||||
confirmation?: {
|
||||
title: string;
|
||||
description: string;
|
||||
};
|
||||
event?: { action: string; category: string; label: string; value: string };
|
||||
sendEvent?: boolean;
|
||||
}
|
||||
|
||||
export default function ButtonTertiary({
|
||||
className = "",
|
||||
type = "button",
|
||||
onClick,
|
||||
disabled,
|
||||
destructive,
|
||||
to,
|
||||
target,
|
||||
rel,
|
||||
children,
|
||||
reloadDocument,
|
||||
prefetch,
|
||||
confirmation,
|
||||
event,
|
||||
sendEvent,
|
||||
}: Props) {
|
||||
const { t } = useTranslation();
|
||||
const refConfirm = useRef<RefConfirmModal>(null);
|
||||
let location = useLocation();
|
||||
const rootData = useRootData();
|
||||
const matches = useMatches();
|
||||
|
||||
function onClicked(e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) {
|
||||
if (onClick) {
|
||||
onClick(e);
|
||||
}
|
||||
if (!event || !sendEvent) {
|
||||
return;
|
||||
}
|
||||
const routeMatch = matches.find((m) => m.pathname == location.pathname);
|
||||
AnalyticsHelper.addEvent({
|
||||
url: location.pathname,
|
||||
route: routeMatch?.id,
|
||||
rootData,
|
||||
action: event.action,
|
||||
category: event.category,
|
||||
label: event.label,
|
||||
value: event.value,
|
||||
});
|
||||
}
|
||||
return (
|
||||
<span>
|
||||
{(() => {
|
||||
if (!to || disabled) {
|
||||
return (
|
||||
<Button
|
||||
variant={"ghost"}
|
||||
className={clsx(className, destructive && "text-red-500 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900 dark:hover:text-white")}
|
||||
onClick={
|
||||
confirmation
|
||||
? () => {
|
||||
refConfirm.current?.setDestructive(destructive || false);
|
||||
refConfirm.current?.show(confirmation.title, t("shared.confirm"), t("shared.cancel"), confirmation.description);
|
||||
}
|
||||
: onClicked
|
||||
}
|
||||
type={type}
|
||||
disabled={disabled}
|
||||
// className={clsx(
|
||||
// className,
|
||||
// "focus:ring-accent-300 mx-1 my-2 inline-flex items-center space-x-2 border-b border-transparent text-sm font-medium focus:rounded-md focus:outline-hidden focus:ring-2 focus:ring-offset-2",
|
||||
// disabled ? "cursor-not-allowed opacity-75" : "hover:border-dotted",
|
||||
// !destructive && "text-theme-700 border-b ",
|
||||
// destructive && "text-red-600",
|
||||
// !disabled && !destructive && !className && "hover:text-theme-800 focus:text-theme-900 ",
|
||||
// !disabled && destructive && "hover:border-red-300 hover:text-red-800 focus:text-red-900"
|
||||
// )}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<Button asChild variant={"ghost"} className={clsx(destructive && "text-red-500")}>
|
||||
<LinkOrAhref
|
||||
reloadDocument={reloadDocument}
|
||||
to={to}
|
||||
target={target}
|
||||
rel={rel}
|
||||
prefetch={prefetch}
|
||||
className={clsx(className)}
|
||||
// className={clsx(
|
||||
// className,
|
||||
// "focus:ring-accent-300 mx-1 my-2 inline-flex items-center space-x-2 border-b border-transparent text-sm font-medium focus:rounded-md focus:outline-hidden focus:ring-2 focus:ring-offset-2",
|
||||
// disabled ? "cursor-not-allowed opacity-75" : " hover:border-dotted",
|
||||
// !destructive && "text-theme-700 border-b ",
|
||||
// destructive && "text-red-600",
|
||||
// !disabled && !destructive && !className && "hover:text-theme-800 focus:text-theme-900 ",
|
||||
// !disabled && destructive && "hover:border-red-300 hover:text-red-800 focus:text-red-900"
|
||||
// )}
|
||||
>
|
||||
{children}
|
||||
</LinkOrAhref>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
})()}
|
||||
|
||||
<ConfirmModal ref={refConfirm} onYes={onClick} />
|
||||
</span>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
import { Link } from "react-router";
|
||||
import clsx from "clsx";
|
||||
import { Fragment, ReactNode, Ref, useEffect, useRef } from "react";
|
||||
import { Button } from "../button";
|
||||
|
||||
interface Props {
|
||||
type?: "button" | "submit";
|
||||
to: string | undefined;
|
||||
children: ReactNode;
|
||||
className?: string;
|
||||
target?: undefined | "_blank" | string;
|
||||
role?: string;
|
||||
ariaLabel?: string;
|
||||
rel?: string;
|
||||
onClick?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement>) => void;
|
||||
reloadDocument?: boolean;
|
||||
autoFocus?: boolean;
|
||||
prefetch?: "intent" | "render" | "none";
|
||||
disabled?: boolean;
|
||||
isLoading?: boolean;
|
||||
onMouseEnter?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement | HTMLDivElement>) => void;
|
||||
onMouseLeave?: (e: React.MouseEvent<HTMLButtonElement | HTMLAnchorElement | HTMLDivElement>) => void;
|
||||
}
|
||||
export default function LinkOrAhref({
|
||||
type = "button",
|
||||
to,
|
||||
target,
|
||||
children,
|
||||
className,
|
||||
role,
|
||||
ariaLabel,
|
||||
rel,
|
||||
onClick,
|
||||
reloadDocument,
|
||||
autoFocus,
|
||||
prefetch,
|
||||
disabled,
|
||||
isLoading,
|
||||
onMouseEnter,
|
||||
onMouseLeave,
|
||||
}: Props) {
|
||||
const focusRef = useRef<HTMLButtonElement | HTMLAnchorElement | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!autoFocus) {
|
||||
return;
|
||||
}
|
||||
const timeout = window.setTimeout(() => focusRef.current?.focus(), 0);
|
||||
return () => window.clearTimeout(timeout);
|
||||
}, [autoFocus]);
|
||||
|
||||
return (
|
||||
<Fragment>
|
||||
{(!to && !onClick) || (to && disabled) ? (
|
||||
<div className={className} role={role} aria-label={ariaLabel} onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>
|
||||
{children}
|
||||
</div>
|
||||
) : to == undefined ? (
|
||||
<Button
|
||||
ref={focusRef as Ref<HTMLButtonElement>}
|
||||
type={type}
|
||||
onClick={onClick}
|
||||
className={clsx(className, isLoading && "base-spinner cursor-not-allowed")}
|
||||
role={role}
|
||||
aria-label={ariaLabel}
|
||||
disabled={disabled}
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
>
|
||||
{children}
|
||||
</Button>
|
||||
) : (
|
||||
<Link
|
||||
reloadDocument={reloadDocument}
|
||||
onClick={onClick}
|
||||
to={to}
|
||||
target={target}
|
||||
className={className}
|
||||
role={role}
|
||||
aria-label={ariaLabel}
|
||||
ref={focusRef as Ref<HTMLAnchorElement>}
|
||||
prefetch={prefetch}
|
||||
rel={rel}
|
||||
onMouseEnter={onMouseEnter}
|
||||
onMouseLeave={onMouseLeave}
|
||||
>
|
||||
{children}
|
||||
</Link>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
import ButtonPrimary from "./ButtonPrimary";
|
||||
import { forwardRef, MouseEventHandler, ReactNode, Ref, useImperativeHandle, useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import { useNavigation } from "react-router";
|
||||
|
||||
export interface RefLoadingButton {
|
||||
start: () => void;
|
||||
stop: () => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
type?: "button" | "submit" | "reset" | undefined;
|
||||
disabled?: boolean;
|
||||
children: ReactNode;
|
||||
onClick?: MouseEventHandler<HTMLButtonElement>;
|
||||
to?: string;
|
||||
actionName?: string;
|
||||
isLoading?: boolean;
|
||||
dataUiId?: string;
|
||||
}
|
||||
|
||||
const LoadingButton = ({ className, type = "button", children, disabled, onClick, to, actionName, isLoading, dataUiId }: Props, ref: Ref<RefLoadingButton>) => {
|
||||
const navigation = useNavigation();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
start,
|
||||
stop,
|
||||
}));
|
||||
|
||||
function start() {
|
||||
setLoading(true);
|
||||
}
|
||||
function stop() {
|
||||
setLoading(false);
|
||||
}
|
||||
const submitting = navigation.state === "submitting";
|
||||
|
||||
function checkIsLoading() {
|
||||
if (isLoading !== undefined) {
|
||||
return isLoading;
|
||||
}
|
||||
const loadingOrSubmitting = loading || submitting;
|
||||
if (actionName) {
|
||||
return loadingOrSubmitting && navigation.state === "submitting" && navigation.formData?.get("action") === actionName;
|
||||
}
|
||||
return loadingOrSubmitting;
|
||||
}
|
||||
|
||||
return (
|
||||
<ButtonPrimary
|
||||
disabled={disabled || checkIsLoading()}
|
||||
className={clsx(className, "relative justify-center", checkIsLoading() && "base-spinner cursor-not-allowed")}
|
||||
type={type}
|
||||
onClick={onClick}
|
||||
to={to}
|
||||
dataUiId={dataUiId}
|
||||
>
|
||||
{/* {checkIsLoading() && <ReloadIcon className="mr-2 h-4 w-4 animate-spin" />} */}
|
||||
|
||||
{children}
|
||||
</ButtonPrimary>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(LoadingButton);
|
||||
@@ -0,0 +1,40 @@
|
||||
import ButtonPrimary from "./ButtonPrimary";
|
||||
import { t as i18nT } from "i18next";
|
||||
import ButtonSecondary from "./ButtonSecondary";
|
||||
import ButtonTertiary from "./ButtonTertiary";
|
||||
import LoadingButton, { RefLoadingButton } from "./LoadingButton";
|
||||
import { useRef } from "react";
|
||||
|
||||
export default function PreviewButtons() {
|
||||
const loadingButton = useRef<RefLoadingButton>(null);
|
||||
function startLoading() {
|
||||
if (loadingButton.current) {
|
||||
loadingButton.current?.start();
|
||||
setTimeout(() => {
|
||||
loadingButton.current?.stop();
|
||||
}, 2000);
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div id="buttons">
|
||||
<div className="border-muted-foreground overflow-hidden rounded-lg border-2 border-dashed p-6">
|
||||
<div id="buttons" className="w-full space-y-2">
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-y-0 sm:space-x-4">
|
||||
<ButtonPrimary onClick={() => alert(i18nT("components.buttons.preview.clickedPrimary"))}>{i18nT("components.buttons.preview.primary")}</ButtonPrimary>
|
||||
<ButtonSecondary onClick={() => alert(i18nT("components.buttons.preview.clickedSecondary"))}>{i18nT("components.buttons.preview.secondary")}</ButtonSecondary>
|
||||
<ButtonTertiary onClick={() => alert(i18nT("components.buttons.preview.clickedTertiary"))}>{i18nT("components.buttons.preview.tertiary")}</ButtonTertiary>
|
||||
<LoadingButton ref={loadingButton} onClick={() => startLoading()}>
|
||||
{i18nT("components.buttons.preview.loading")}
|
||||
</LoadingButton>
|
||||
</div>
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-y-0 sm:space-x-4">
|
||||
<ButtonPrimary disabled={true}>{i18nT("components.buttons.preview.primary")}</ButtonPrimary>
|
||||
<ButtonSecondary disabled={true}>{i18nT("components.buttons.preview.secondary")}</ButtonSecondary>
|
||||
<ButtonTertiary disabled={true}>{i18nT("components.buttons.preview.tertiary")}</ButtonTertiary>
|
||||
<LoadingButton disabled={true}>{i18nT("components.buttons.preview.loading")}</LoadingButton>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useLocation } from "react-router";
|
||||
import { t as i18nT } from "i18next";
|
||||
import ButtonPrimary from "./ButtonPrimary";
|
||||
import ButtonSecondary from "./ButtonSecondary";
|
||||
import ButtonTertiary from "./ButtonTertiary";
|
||||
|
||||
export default function PreviewButtonsAsLinks() {
|
||||
const currentRoute = useLocation().pathname;
|
||||
return (
|
||||
<div id="buttons-as-links">
|
||||
<div className="not-prose border-border bg-background border border-dashed p-6">
|
||||
<div className="w-full space-y-2">
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-y-0 sm:space-x-4">
|
||||
<ButtonPrimary to={currentRoute}>{i18nT("components.buttons.preview.primary")}</ButtonPrimary>
|
||||
<ButtonSecondary to={currentRoute}>{i18nT("components.buttons.preview.secondary")}</ButtonSecondary>
|
||||
<ButtonTertiary to={currentRoute}>{i18nT("components.buttons.preview.tertiary")}</ButtonTertiary>
|
||||
</div>
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-y-0 sm:space-x-4">
|
||||
<ButtonPrimary disabled={true} to={currentRoute}>
|
||||
{i18nT("components.buttons.preview.primary")}
|
||||
</ButtonPrimary>
|
||||
<ButtonSecondary disabled={true} to={currentRoute}>
|
||||
{i18nT("components.buttons.preview.secondary")}
|
||||
</ButtonSecondary>
|
||||
<ButtonTertiary disabled={true} to={currentRoute}>
|
||||
{i18nT("components.buttons.preview.tertiary")}
|
||||
</ButtonTertiary>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { t as i18nT } from "i18next";
|
||||
import ButtonPrimary from "./ButtonPrimary";
|
||||
import ButtonSecondary from "./ButtonSecondary";
|
||||
import ButtonTertiary from "./ButtonTertiary";
|
||||
|
||||
export default function PreviewButtonsDestructive() {
|
||||
return (
|
||||
<div id="buttons-as-links">
|
||||
<div className="border-border bg-background border border-dashed p-6">
|
||||
<div className="w-full space-y-2">
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-x-4 sm:space-y-0">
|
||||
<ButtonPrimary onClick={() => alert(i18nT("components.buttons.preview.clickedPrimaryDestructive"))} destructive={true}>
|
||||
{i18nT("components.buttons.preview.primary")}
|
||||
</ButtonPrimary>
|
||||
<ButtonSecondary onClick={() => alert(i18nT("components.buttons.preview.clickedSecondaryDestructive"))} destructive={true}>
|
||||
{i18nT("components.buttons.preview.secondary")}
|
||||
</ButtonSecondary>
|
||||
<ButtonTertiary onClick={() => alert(i18nT("components.buttons.preview.clickedTertiaryDestructive"))} destructive={true}>
|
||||
{i18nT("components.buttons.preview.tertiary")}
|
||||
</ButtonTertiary>
|
||||
</div>
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-x-4 sm:space-y-0">
|
||||
<ButtonPrimary disabled={true} destructive={true}>
|
||||
{i18nT("components.buttons.preview.primary")}
|
||||
</ButtonPrimary>
|
||||
<ButtonSecondary disabled={true} destructive={true}>
|
||||
{i18nT("components.buttons.preview.secondary")}
|
||||
</ButtonSecondary>
|
||||
<ButtonTertiary disabled={true} destructive={true}>
|
||||
{i18nT("components.buttons.preview.tertiary")}
|
||||
</ButtonTertiary>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user