Skip to content

Commit

Permalink
Rename Button type prop to variant
Browse files Browse the repository at this point in the history
Signed-off-by: Andrés Vidal <[email protected]>
  • Loading branch information
andres-vidal committed Mar 11, 2024
1 parent f4cac6f commit 16acb40
Show file tree
Hide file tree
Showing 17 changed files with 49 additions and 46 deletions.
15 changes: 9 additions & 6 deletions frontend/components/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,32 @@ import { FC, forwardRef, HTMLProps, ReactNode } from "react";

type Props = HTMLProps<HTMLButtonElement> & {
label: string;
type?: "primary" | "secondary" | "outline" | "danger";
variant?: "primary" | "secondary" | "outline" | "danger";
Icon?: FC<{ className: string }> | ReactNode;
alignment?: "center" | "left";
width?: "full" | "fixed" | "fit";
labelSrOnly?: boolean;
type?: "button" | "submit" | "reset";
};

const Button = forwardRef<HTMLButtonElement, Props>(function Button(
{
label,
onClick,
type = "primary",
variant = "primary",
Icon,
alignment = "center",
width = "full",
type = "button",
labelSrOnly,
...props
},
ref,
) {
const isPrimary = type === "primary";
const isSecondary = type === "secondary";
const isOutline = type === "outline";
const isDanger = type === "danger";
const isPrimary = variant === "primary";
const isSecondary = variant === "secondary";
const isOutline = variant === "outline";
const isDanger = variant === "danger";
const isTextCentered = alignment === "center";
const isFixedWidth = width === "fixed";
const isFullWidth = width === "full";
Expand All @@ -52,6 +54,7 @@ const Button = forwardRef<HTMLButtonElement, Props>(function Button(
},
)}
onClick={onClick}
type={type}
>
{Icon && isFunction(Icon) ? (
<Icon
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/LearnMoreButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const LearnMoreButton: FC = () => {

return (
<Button
type="outline"
variant="outline"
label="Learn more about the Richard Burton Platform here"
onClick={() => modal.open()}
/>
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/PublicationCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import SparklesIcon from "assets/sparkles.svg";
import { Publication } from "modules/publication";
import { FC } from "react";
import SparklesIcon from "assets/sparkles.svg";
import Tooltip from "./Tooltip";
import Button from "./Button";
import Tooltip from "./Tooltip";

const PublicationCounter: FC = () => {
const publicationCount = Publication.STORE.useVisibleCount();
Expand All @@ -14,7 +14,7 @@ const PublicationCounter: FC = () => {
return publicationCount !== 0 ? (
<Tooltip info message={message}>
<Button
type="outline"
variant="outline"
width="fit"
Icon={SparklesIcon}
label={`${publicationCount}`}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/PublicationDelete.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import TrashIcon from "assets/trash.svg";
import { Publication } from "modules/publication";
import { FC } from "react";
import {
Expand All @@ -6,7 +7,6 @@ import {
useSelectionSize,
} from "react-selection-manager";
import Button from "./Button";
import TrashIcon from "assets/trash.svg";

const PublicationDelete: FC = () => {
const setDeleted = Publication.STORE.useSetDeleted();
Expand All @@ -24,7 +24,7 @@ const PublicationDelete: FC = () => {
return (
<Button
label={`Delete ${selectionSize}`}
type="danger"
variant="danger"
alignment="left"
width="fit"
Icon={TrashIcon}
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/PublicationDeselect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FC } from "react";
import DeselectIcon from "assets/deselect.svg";
import { useSelectionSize, useClearSelection } from "react-selection-manager";
import { FC } from "react";
import { useClearSelection, useSelectionSize } from "react-selection-manager";
import Button from "./Button";

const PublicationDeselect: FC = () => {
Expand All @@ -9,7 +9,7 @@ const PublicationDeselect: FC = () => {

return (
<Button
type="outline"
variant="outline"
width="fit"
label={`Deselect ${selectionSize}`}
Icon={DeselectIcon}
Expand Down
8 changes: 4 additions & 4 deletions frontend/components/PublicationDownload.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FILES_URL, request } from "app";
import DownloadIcon from "assets/download.svg";
import { snakeCase } from "lodash";
import { Publication } from "modules/publication";
import { useRouter } from "next/router";
import qs from "qs";
import { FC, useRef } from "react";
import { FILES_URL, request } from "app";
import DownloadIcon from "assets/download.svg";
import Button from "./Button";
import qs from "qs";

const PublicationDownload: FC = () => {
const visibleCount = Publication.STORE.useVisibleCount();
Expand Down Expand Up @@ -51,7 +51,7 @@ const PublicationDownload: FC = () => {
<>
<Button
label="Download .csv"
type="outline"
variant="outline"
alignment="left"
Icon={DownloadIcon}
disabled={visibleCount === 0}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/PublicationDuplicate.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import CopyIcon from "assets/copy.svg";
import { Publication } from "modules/publication";
import { FC } from "react";
import {
Expand All @@ -6,7 +7,6 @@ import {
useSelectionSize,
} from "react-selection-manager";
import Button from "./Button";
import CopyIcon from "assets/copy.svg";

const PublicationDuplicate: FC = () => {
const duplicate = Publication.STORE.useDuplicate();
Expand All @@ -26,7 +26,7 @@ const PublicationDuplicate: FC = () => {
return (
<Button
label={`Duplicate ${selectionSize}`}
type="secondary"
variant="secondary"
alignment="left"
width="fit"
Icon={CopyIcon}
Expand Down
10 changes: 5 additions & 5 deletions frontend/components/PublicationErrorCounter.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Publication } from "modules/publication";
import { FC } from "react";
import ErrorCircleIcon from "assets/error-circle.svg";
import Tooltip from "./Tooltip";
import Button from "./Button";
import { toString } from "lodash";
import { Publication } from "modules/publication";
import { FC } from "react";
import { useRecoilCallback } from "recoil";
import Button from "./Button";
import Tooltip from "./Tooltip";

const PublicationErrorCounter: FC = () => {
const publicationCount = Publication.STORE.useVisibleCount();
Expand Down Expand Up @@ -40,7 +40,7 @@ const PublicationErrorCounter: FC = () => {
} with errors`}
>
<Button
type="danger"
variant="danger"
width="fit"
Icon={ErrorCircleIcon}
label={toString(invalidPublicationCount)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/PublicationIndexTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const ColumnHeader: FC<{ colId: ColId; toggleable?: boolean }> = ({
label={hideLabel}
labelSrOnly
width="fit"
type="outline"
variant="outline"
Icon={VisibilityOffIcon}
onClick={() => setVisible([colId], false)}
/>
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/PublicationUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import UploadIcon from "assets/upload.svg";
import { Publication, ValidationResult } from "modules/publication";
import { ChangeEvent, FC, useRef, useState } from "react";
import Tooltip from "./Tooltip";
import UploadIcon from "assets/upload.svg";
import Button from "./Button";
import Tooltip from "./Tooltip";

const PublicationUpload: FC = () => {
const { useResetAll, useTotalCount } = Publication.STORE;
Expand Down Expand Up @@ -48,7 +48,7 @@ const PublicationUpload: FC = () => {
<Tooltip warning message={message} placement="top">
<Button
label="Upload.csv"
type="outline"
variant="outline"
Icon={UploadIcon}
alignment="left"
width="fixed"
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/ResetDeleted.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import RestoreTrashIcon from "assets/restore-trash.svg";
import { Publication } from "modules/publication";
import { FC } from "react";
import Button from "./Button";
import RestoreTrashIcon from "assets/restore-trash.svg";
import { useClearSelection } from "react-selection-manager";
import Button from "./Button";

const ResetDeleted: FC = () => {
const deletedCount = Publication.STORE.useDeletedCount();
Expand All @@ -17,7 +17,7 @@ const ResetDeleted: FC = () => {
return deletedCount !== 0 ? (
<Button
label={`Reset ${deletedCount} deleted`}
type="outline"
variant="outline"
Icon={RestoreTrashIcon}
alignment="left"
width="fit"
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/ResetOverridden.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import RestorePageIcon from "assets/restore-page.svg";
import { Publication } from "modules/publication";
import { FC } from "react";
import Button from "./Button";
import RestorePageIcon from "assets/restore-page.svg";
import { useClearSelection } from "react-selection-manager";
import Button from "./Button";

const ResetOverridden: FC = () => {
const overriddenCount = Publication.STORE.useOverriddenCount();
Expand All @@ -23,7 +23,7 @@ const ResetOverridden: FC = () => {
return overriddenCount !== 0 ? (
<Button
label={`Reset ${overriddenCount} overriden`}
type="outline"
variant="outline"
Icon={RestorePageIcon}
alignment="left"
width="fit"
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/SignInButton.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import GoogleIcon from "assets/google.svg";
import { signIn } from "next-auth/react";
import { FC } from "react";
import Button from "./Button";
import GoogleIcon from "assets/google.svg";

const SignInButton: FC = () => {
return (
<Button
label="Sign in"
type="outline"
variant="outline"
alignment="left"
onClick={() => signIn("google")}
Icon={GoogleIcon}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/SignOutButton.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import ExitIcon from "assets/exit.svg";
import { signOut } from "next-auth/react";
import { FC } from "react";
import Button from "./Button";
import ExitIcon from "assets/exit.svg";

const SignOutButton: FC = () => {
return (
<Button
label="Sign out"
type="outline"
variant="outline"
alignment="left"
onClick={() => signOut({ callbackUrl: "/" })}
Icon={ExitIcon}
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef } from "react";
import CheckIcon from "assets/check.svg";
import { forwardRef } from "react";
import Button, { ButtonProps } from "./Button";

type Props = ButtonProps & {
Expand All @@ -18,7 +18,7 @@ const Toggle = forwardRef<HTMLButtonElement, Props>(function Toggle(
<Button
{...props}
ref={ref}
type={checked ? "primary" : "outline"}
variant={checked ? "primary" : "outline"}
Icon={checked ? CheckedIcon : UncheckedIcon}
label={label}
onClick={onClick}
Expand Down
6 changes: 3 additions & 3 deletions frontend/pages/auth/error.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import GoogleIcon from "assets/google.svg";
import Button from "components/Button";
import Layout from "components/Layout";
import { NextPage } from "next";
import { useRouter } from "next/router";
import GoogleIcon from "assets/google.svg";
import { signIn, useSession } from "next-auth/react";
import { useRouter } from "next/router";
import { useEffect } from "react";

type ErrorCode = "AccessDenied" | "Verification" | "Default" | "Configuration";
Expand Down Expand Up @@ -66,7 +66,7 @@ const SignIn: NextPage = () => {
</div>
<Button
label="Try again"
type="outline"
variant="outline"
onClick={() => signIn("google", { callbackUrl: "/" })}
Icon={GoogleIcon}
/>
Expand Down
2 changes: 1 addition & 1 deletion frontend/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const Home: NextPage = () => {
<Link href="/publications/new">
<Button
label="Add publications"
type="outline"
variant="outline"
Icon={AddIcon}
alignment="left"
width="fixed"
Expand Down

0 comments on commit 16acb40

Please sign in to comment.