From aaecf5ba449564b3fb2388d5a74e80b59844d332 Mon Sep 17 00:00:00 2001 From: Matti Nannt Date: Thu, 19 Oct 2023 12:21:49 +0200 Subject: [PATCH] chore: add folder structure for v2 components (#1314) --- apps/storybook/tailwind.config.js | 7 +- packages/ui/v2/Button/index.tsx | 154 +++++++++++++++++++++++++ packages/ui/{ => v2}/Button/stories.ts | 0 3 files changed, 155 insertions(+), 6 deletions(-) create mode 100644 packages/ui/v2/Button/index.tsx rename packages/ui/{ => v2}/Button/stories.ts (100%) diff --git a/apps/storybook/tailwind.config.js b/apps/storybook/tailwind.config.js index c749dff323..bb0aed46cd 100644 --- a/apps/storybook/tailwind.config.js +++ b/apps/storybook/tailwind.config.js @@ -4,10 +4,5 @@ import base from "../../packages/tailwind-config/tailwind.config"; export default { ...base, - content: [ - "./index.html", - "./src/**/*.{js,ts,jsx,tsx}", - "../../packages/ui/**/*.{js,ts,jsx,tsx}", - "!../../packages/ui/node_modules/**/*.{js,ts,jsx,tsx}", - ], + content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}", "../../packages/ui/**/*.{js,ts,jsx,tsx}"], }; diff --git a/packages/ui/v2/Button/index.tsx b/packages/ui/v2/Button/index.tsx new file mode 100644 index 0000000000..62f762e22d --- /dev/null +++ b/packages/ui/v2/Button/index.tsx @@ -0,0 +1,154 @@ +import { cn } from "@formbricks/lib/cn"; +import { LucideIcon } from "lucide-react"; +import Link, { LinkProps } from "next/link"; +import React, { AnchorHTMLAttributes, ButtonHTMLAttributes, forwardRef } from "react"; + +type SVGComponent = React.FunctionComponent> | LucideIcon; + +export type ButtonBaseProps = { + variant?: "highlight" | "primary" | "secondary" | "minimal" | "warn" | "alert" | "darkCTA"; + size?: "base" | "sm" | "lg" | "fab" | "icon"; + loading?: boolean; + disabled?: boolean; + onClick?: (event: React.MouseEvent) => void; + StartIcon?: SVGComponent | React.ComponentType>; + startIconClassName?: string; + EndIcon?: SVGComponent | React.ComponentType>; + endIconClassName?: string; + shallow?: boolean; +}; +type ButtonBasePropsWithTarget = ButtonBaseProps & { target?: string }; + +export type ButtonProps = ButtonBasePropsWithTarget & + ( + | (Omit, "href" | "onClick" | "target"> & LinkProps) + | (Omit, "onClick" | "target"> & { href?: never }) + ); + +export const Button: React.ForwardRefExoticComponent< + React.PropsWithoutRef & React.RefAttributes +> = forwardRef(function Button( + props: ButtonProps, + forwardedRef +) { + const { + loading = false, + variant = "primary", + size = "base", + StartIcon, + startIconClassName, + endIconClassName, + 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 `