From 95b3397e4277b2691935fc264e1cf1401ea5a08c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Mon, 21 Feb 2022 09:41:25 -0700 Subject: [PATCH] Add ui package for reusable components (#1916) * Add ui package for reusable components * Add fallback * Type fixes * Type fixes Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- apps/web/components/ui/Button.tsx | 140 +----------------------------- apps/web/lib/classNames.ts | 5 +- apps/web/next.config.js | 6 +- apps/web/package.json | 1 + packages/lib/classNames.ts | 3 + packages/ui/Button.tsx | 138 +++++++++++++++++++++++++++++ packages/ui/index.tsx | 3 + packages/ui/package.json | 15 ++++ packages/ui/tsconfig.json | 5 ++ yarn.lock | 7 ++ 10 files changed, 182 insertions(+), 141 deletions(-) create mode 100644 packages/lib/classNames.ts create mode 100644 packages/ui/Button.tsx create mode 100644 packages/ui/index.tsx create mode 100644 packages/ui/package.json create mode 100644 packages/ui/tsconfig.json diff --git a/apps/web/components/ui/Button.tsx b/apps/web/components/ui/Button.tsx index 5079c7f03f..979b55b369 100644 --- a/apps/web/components/ui/Button.tsx +++ b/apps/web/components/ui/Button.tsx @@ -1,137 +1,3 @@ -import Link, { LinkProps } from "next/link"; -import React, { forwardRef } from "react"; - -import classNames from "@lib/classNames"; -import { SVGComponent } from "@lib/types/SVGComponent"; - -export type ButtonBaseProps = { - color?: "primary" | "secondary" | "minimal" | "warn"; - size?: "base" | "sm" | "lg" | "fab" | "icon"; - loading?: boolean; - disabled?: boolean; - onClick?: (event: React.MouseEvent) => void; - StartIcon?: SVGComponent; - EndIcon?: SVGComponent; - shallow?: boolean; -}; -export type ButtonProps = ButtonBaseProps & - ( - | (Omit & { href: LinkProps["href"] }) - | (JSX.IntrinsicElements["button"] & { href?: never }) - ); - -export const Button = forwardRef(function Button( - props: ButtonProps, - forwardedRef -) { - const { - loading = false, - color = "primary", - size = "base", - StartIcon, - EndIcon, - shallow, - // 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 ``, otherwise it's a `