2021-08-23 12:45:25 +00:00
|
|
|
import classNames from "@lib/classNames";
|
|
|
|
import Link, { LinkProps } from "next/link";
|
2021-09-15 12:33:00 +00:00
|
|
|
import React, { forwardRef } from "react";
|
2021-08-23 12:45:25 +00:00
|
|
|
|
2021-09-03 15:34:57 +00:00
|
|
|
type SVGComponent = React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
|
|
|
|
|
2021-08-23 12:45:25 +00:00
|
|
|
export type ButtonProps = {
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
color?: "primary" | "secondary" | "minimal" | "warn";
|
2021-08-23 20:42:24 +00:00
|
|
|
size?: "base" | "sm" | "lg" | "fab";
|
2021-08-23 12:45:25 +00:00
|
|
|
loading?: boolean;
|
|
|
|
disabled?: boolean;
|
|
|
|
onClick?: (event: React.MouseEvent<HTMLElement, MouseEvent>) => void;
|
2021-09-03 15:34:57 +00:00
|
|
|
StartIcon?: SVGComponent;
|
|
|
|
EndIcon?: SVGComponent;
|
2021-09-14 13:27:41 +00:00
|
|
|
shallow?: boolean;
|
2021-09-02 10:02:45 +00:00
|
|
|
} & (
|
|
|
|
| (Omit<JSX.IntrinsicElements["a"], "href"> & { href: LinkProps["href"] })
|
|
|
|
| (JSX.IntrinsicElements["button"] & { href?: never })
|
|
|
|
);
|
2021-08-23 12:45:25 +00:00
|
|
|
|
2021-09-15 12:33:00 +00:00
|
|
|
export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, ButtonProps>(function Button(
|
|
|
|
props: ButtonProps,
|
|
|
|
forwardedRef
|
|
|
|
) {
|
2021-08-23 12:45:25 +00:00
|
|
|
const {
|
|
|
|
loading = false,
|
|
|
|
color = "primary",
|
|
|
|
size = "base",
|
|
|
|
StartIcon,
|
|
|
|
EndIcon,
|
2021-09-14 13:27:41 +00:00
|
|
|
shallow,
|
2021-08-23 12:45:25 +00:00
|
|
|
// attributes propagated from `HTMLAnchorProps` or `HTMLButtonProps`
|
|
|
|
...passThroughProps
|
|
|
|
} = props;
|
|
|
|
// Buttons are **always** disabled if we're in a `loading` state
|
|
|
|
const disabled = props.disabled || loading;
|
|
|
|
|
|
|
|
// If pass an `href`-attr is passed it's `<a>`, otherwise it's a `<button />`
|
|
|
|
const isLink = typeof props.href !== "undefined";
|
|
|
|
const elementType = isLink ? "a" : "button";
|
|
|
|
|
|
|
|
const element = React.createElement(
|
|
|
|
elementType,
|
|
|
|
{
|
|
|
|
...passThroughProps,
|
|
|
|
disabled,
|
2021-09-15 12:33:00 +00:00
|
|
|
ref: forwardedRef,
|
2021-08-23 12:45:25 +00:00
|
|
|
className: classNames(
|
|
|
|
// base styles independent what type of button it is
|
2021-08-23 20:42:24 +00:00
|
|
|
"inline-flex items-center",
|
2021-08-23 12:45:25 +00:00
|
|
|
// different styles depending on size
|
|
|
|
size === "sm" && "px-3 py-2 text-sm leading-4 font-medium rounded-sm",
|
|
|
|
size === "base" && "px-3 py-2 text-sm font-medium rounded-sm",
|
|
|
|
size === "lg" && "px-4 py-2 text-base font-medium rounded-sm",
|
2021-08-23 20:42:24 +00:00
|
|
|
// turn button into a floating action button (fab)
|
|
|
|
size === "fab" ? "fixed" : "relative",
|
|
|
|
size === "fab" && "justify-center bottom-20 right-8 rounded-full p-4 w-14 h-14",
|
|
|
|
|
2021-08-23 12:45:25 +00:00
|
|
|
// different styles depending on color
|
|
|
|
color === "primary" &&
|
|
|
|
(disabled
|
|
|
|
? "border border-transparent bg-gray-400 text-white"
|
|
|
|
: "border border-transparent text-white bg-neutral-900 hover:bg-neutral-800 hover:shadow-md focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-neutral-900"),
|
|
|
|
color === "secondary" &&
|
|
|
|
(disabled
|
|
|
|
? "border border-gray-200 text-gray-400 bg-white"
|
2021-09-14 13:27:41 +00:00
|
|
|
: "border border-gray-300 text-gray-700 bg-white hover:bg-gray-50 hover:text-gray-900 hover:shadow-sm focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-neutral-900 dark:bg-transparent dark:text-white dark:border-gray-800 dark:hover:bg-gray-900"),
|
2021-08-23 12:45:25 +00:00
|
|
|
color === "minimal" &&
|
|
|
|
(disabled
|
|
|
|
? "text-gray-400 bg-transparent"
|
|
|
|
: "text-gray-700 bg-transparent hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:bg-gray-100 focus:ring-neutral-500"),
|
Cal 262 refactor edit teams according to the design reference (#516)
* refactored settings/team landing page
* changed team edit flow, WIP
* merge conflict fix for teams.tsx
* minor fixes to edit team, WIP
* invite-member and disband team APIs attached inside edit-team page
* added remove-member API in edit-team page, minor fixes
* minor code fix, WIP
* WIP
* add logo, bio, branding to team schema
* bio, logo, branding, slug patch API and minor code fix-- WIP
* fn to Disband team directly from the dropdown menu in settings/teams page, removed debug remnants --WIP
* Pull latest data after an action in settings/teams-edit page
* added slug conflict check at Patch time
* code clean-up
* initial change request fixes --WIP
* prop type fix and add warn button color theme --WIP
* added warn Button to Dialog
* remaining change request fixes
* added noop from react-query
* updated invited team-list design
* prettier fix for api/teams/profile
* removed noop import and added custom noop
* minor Button fix
* requested changes addressed
2021-09-06 13:22:22 +00:00
|
|
|
color === "warn" &&
|
|
|
|
(disabled
|
|
|
|
? "text-gray-400 bg-transparent"
|
|
|
|
: "text-red-700 bg-transparent hover:bg-red-100 focus:outline-none focus:ring-2 focus:ring-offset-1 focus:bg-red-50 focus:ring-red-500"),
|
2021-08-23 12:45:25 +00:00
|
|
|
// set not-allowed cursor if disabled
|
2021-09-06 13:51:15 +00:00
|
|
|
loading ? "cursor-wait" : disabled ? "cursor-not-allowed" : "",
|
2021-08-23 12:45:25 +00:00
|
|
|
props.className
|
|
|
|
),
|
|
|
|
// if we click a disabled button, we prevent going through the click handler
|
|
|
|
onClick: disabled
|
|
|
|
? (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
: props.onClick,
|
|
|
|
},
|
|
|
|
<>
|
|
|
|
{StartIcon && <StartIcon className="inline w-5 h-5 mr-2 -ml-1" />}
|
|
|
|
{props.children}
|
|
|
|
{loading && (
|
|
|
|
<div className="absolute transform -translate-x-1/2 -translate-y-1/2 top-1/2 left-1/2">
|
|
|
|
<svg
|
|
|
|
className={classNames(
|
|
|
|
"w-5 h-5 mx-4 animate-spin",
|
|
|
|
color === "primary" ? "text-white" : "text-black"
|
|
|
|
)}
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
fill="none"
|
|
|
|
viewBox="0 0 24 24">
|
|
|
|
<circle
|
|
|
|
className="opacity-25"
|
|
|
|
cx="12"
|
|
|
|
cy="12"
|
|
|
|
r="10"
|
|
|
|
stroke="currentColor"
|
|
|
|
strokeWidth="4"></circle>
|
|
|
|
<path
|
|
|
|
className="opacity-75"
|
|
|
|
fill="currentColor"
|
|
|
|
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
|
|
|
|
</svg>
|
|
|
|
</div>
|
2021-08-08 16:17:17 +00:00
|
|
|
)}
|
2021-08-23 12:45:25 +00:00
|
|
|
{EndIcon && <EndIcon className="inline w-5 h-5 ml-2 -mr-1" />}
|
|
|
|
</>
|
2021-06-03 20:42:05 +00:00
|
|
|
);
|
2021-08-23 12:45:25 +00:00
|
|
|
return props.href ? (
|
2021-09-14 13:27:41 +00:00
|
|
|
<Link passHref href={props.href} shallow={shallow && shallow}>
|
2021-08-23 12:45:25 +00:00
|
|
|
{element}
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
element
|
|
|
|
);
|
2021-09-15 12:33:00 +00:00
|
|
|
});
|
2021-08-23 22:17:05 +00:00
|
|
|
|
|
|
|
export default Button;
|