From 6edfb0ebf9f6b04ec485b3d5d9ece105dd01447f Mon Sep 17 00:00:00 2001 From: SySagar Date: Sat, 7 Sep 2024 21:03:52 +0530 Subject: [PATCH 1/4] chore(Typography): tailwind support --- apps/ui/.storybook/preview.tsx | 1 + apps/ui/lib/components/Typography/Text.tsx | 13 +++++-------- apps/ui/package.json | 2 +- apps/ui/stories/Typography.stories.tsx | 11 +++++++++++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/apps/ui/.storybook/preview.tsx b/apps/ui/.storybook/preview.tsx index cba9176..c2b1abd 100644 --- a/apps/ui/.storybook/preview.tsx +++ b/apps/ui/.storybook/preview.tsx @@ -1,4 +1,5 @@ // https://storybook.js.org/docs/react/writing-stories/parameters#global-parameters +import '../lib/tailwind.css'; const customViewports = { xs: { diff --git a/apps/ui/lib/components/Typography/Text.tsx b/apps/ui/lib/components/Typography/Text.tsx index 0649a12..bf3aad5 100644 --- a/apps/ui/lib/components/Typography/Text.tsx +++ b/apps/ui/lib/components/Typography/Text.tsx @@ -2,13 +2,12 @@ import React from 'react'; import { VARIANT_MAPPINGS } from './constants'; import { Slot } from './Slot'; import style from './text.module.css'; -import clsx from 'clsx'; -export interface TextProps { +import { cn } from '@utils/utils'; +export interface TextProps extends React.HTMLAttributes { variant?: keyof typeof VARIANT_MAPPINGS; alignment?: 'left' | 'right' | 'center' | 'justify'; color?: string; width?: number; - minHeight?: number; maxLines?: number; asChild?: boolean; children: React.ReactNode; @@ -26,7 +25,7 @@ export const Text: React.FC = ({ }) => { const textStyle = { textAlign: alignment || 'center', - color: color || 'inherit', + color: color, margin: '0 0 0 0', padding: '0 0 0 0', display: asChild ? 'inline-block' : 'block', @@ -38,14 +37,12 @@ export const Text: React.FC = ({ const Comp = asChild ? Slot : 'p'; const classNames = VARIANT_MAPPINGS[variant as keyof typeof VARIANT_MAPPINGS]; - const mergedClassess = variant - ? clsx(style.text, classNames.slice(1)) - : style.text; + const mergedClasses = cn(style.text, classNames?.slice(1), props.className); return (
{ + return ( +
+ + With color props + + with tailwind classes +
+ ); +}; + // Alignment Center export const AlignmentCenterStory = Template.bind({}); AlignmentCenterStory.args = { From 6df49c04e53c6e8596ba73b97fd2f460e644e59b Mon Sep 17 00:00:00 2001 From: SySagar Date: Sat, 7 Sep 2024 21:38:53 +0530 Subject: [PATCH 2/4] refactor(button): base color and variant --- apps/ui/lib/components/Button/index.tsx | 92 ++++++++++++------------ apps/ui/lib/components/Select/Select.tsx | 2 +- apps/ui/stories/Button.stories.tsx | 69 ++++-------------- packages/tokens/src/colors/base.ts | 2 + 4 files changed, 65 insertions(+), 100 deletions(-) diff --git a/apps/ui/lib/components/Button/index.tsx b/apps/ui/lib/components/Button/index.tsx index db008b6..b204370 100644 --- a/apps/ui/lib/components/Button/index.tsx +++ b/apps/ui/lib/components/Button/index.tsx @@ -1,51 +1,53 @@ -import React from 'react'; +import * as React from 'react'; +import { Slot } from '@radix-ui/react-slot'; +import { cva, type VariantProps } from 'class-variance-authority'; -type ButtonVariant = 'filled' | 'outlined' | 'text'; -type ButtonSize = 'sm' | 'md' | 'lg'; -type ButtonColor = 'primary' | 'secondary'; +import { cn } from '@utils/utils'; -export interface ButtonProps - extends React.ButtonHTMLAttributes { - variant?: ButtonVariant; - size?: ButtonSize; - color?: ButtonColor; -} - -export const Button: React.FC = ({ - variant = 'filled', - size = 'md', - color = 'primary', - children, - ...props -}) => { - const baseStyles = 'rounded font-semibold'; - - const sizeStyles = { - sm: 'py-1 px-2 text-sm', - md: 'py-2 px-4', - lg: 'py-3 px-10 text-lg', - }; - - const colorStyles = { - primary: { - filled: 'bg-primary-700 hover:bg-primary-500 text-primaryText', - outlined: - 'bg-transparent bg-opacity-5 bg-primary-300 hover:bg-primary-500 hover:bg-opacity-10 text-primary-700 border-primary-700 border focus:ring-[#00C200]', - text: 'bg-transparent hover:bg-primary-500 hover:bg-opacity-30 text-primary-700', +const buttonVariants = cva( + 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', + { + variants: { + variant: { + default: 'bg-primary-700 text-primaryText hover:bg-primary/90', + destructive: 'bg-error-900 text-primaryText hover:bg-destructive/90', + outline: + 'border border-input hover:bg-accent hover:text-accent-foreground', + secondary: 'bg-secondary-700 text-primaryText hover:bg-secondary/80', + link: 'text-primary-500 underline-offset-4 hover:underline', + }, + size: { + default: 'h-10 px-4 py-2', + sm: 'h-9 rounded-md px-3', + lg: 'h-11 rounded-md px-8', + icon: 'h-10 w-10', + }, }, - secondary: { - filled: 'bg-secondary-700 hover:bg-secondary-500 text-primaryText', - outlined: - 'bg-transparent hover:bg-secondary-900 hover:bg-opacity-10 text-secondary-700 border-secondary-700 border', - text: 'bg-transparent hover:bg-secondary-700 hover:bg-opacity-10 text-secondary-700', + defaultVariants: { + variant: 'default', + size: 'default', }, - }; + } +); + +export interface ButtonProps + extends React.ButtonHTMLAttributes, + VariantProps { + asChild?: boolean; +} - const buttonStyles = `${baseStyles} ${sizeStyles[size]} ${colorStyles[color][variant]}`; +const Button = React.forwardRef( + ({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : 'button'; + return ( + + ); + } +); +Button.displayName = 'Button'; - return ( - - ); -}; +export { Button, buttonVariants }; diff --git a/apps/ui/lib/components/Select/Select.tsx b/apps/ui/lib/components/Select/Select.tsx index 23006b9..6f17ed0 100644 --- a/apps/ui/lib/components/Select/Select.tsx +++ b/apps/ui/lib/components/Select/Select.tsx @@ -115,7 +115,7 @@ const SelectItem = React.forwardRef< ( +export const Variants = () => (
( }} >
- +
- + +
+
+
-
-); - -Colors.args = { - variant: 'filled', -}; - -export const Variants = (args: ButtonProps) => ( -
- +
- +
); -Variants.args = { - color: 'primary', +export const tailwindButton = () => { + return ; }; -export const Sizes = (args: ButtonProps) => ( +export const Sizes = () => (
( }} >
- +
- +
- +
); diff --git a/packages/tokens/src/colors/base.ts b/packages/tokens/src/colors/base.ts index bec400e..69547e4 100644 --- a/packages/tokens/src/colors/base.ts +++ b/packages/tokens/src/colors/base.ts @@ -31,4 +31,6 @@ export const colors = { primaryText: '#EBEBEB', secondaryText: '#1E1E1E', + + accent: '#EBEBEB', }; From 8df942b1e436588179f4f9ef5730417b11f5baf4 Mon Sep 17 00:00:00 2001 From: SySagar Date: Sat, 7 Sep 2024 23:12:07 +0530 Subject: [PATCH 3/4] chore: new release --- .changeset/calm-needles-pay.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/calm-needles-pay.md diff --git a/.changeset/calm-needles-pay.md b/.changeset/calm-needles-pay.md new file mode 100644 index 0000000..8b4cc3b --- /dev/null +++ b/.changeset/calm-needles-pay.md @@ -0,0 +1,5 @@ +--- +'@groovy-box/ui': patch +--- + +tailwind support From 8d030ed7a877b9ec67ca79c803726565dff7a83c Mon Sep 17 00:00:00 2001 From: SySagar Date: Sat, 7 Sep 2024 23:24:08 +0530 Subject: [PATCH 4/4] test(button): variant --- apps/ui/__test__/Button.spec.js | 21 +- apps/ui/coverage/clover.xml | 344 +++++++++ apps/ui/coverage/coverage-final.json | 28 + apps/ui/coverage/lcov-report/base.css | 224 ++++++ .../coverage/lcov-report/block-navigation.js | 87 +++ apps/ui/coverage/lcov-report/favicon.png | Bin 0 -> 445 bytes apps/ui/coverage/lcov-report/index.html | 326 +++++++++ .../components/Accordion/Accordion.tsx.html | 271 +++++++ .../lib/components/Accordion/index.html | 131 ++++ .../lib/components/Accordion/index.tsx.html | 88 +++ .../lib/components/Avatar/Avatar.tsx.html | 355 ++++++++++ .../lib/components/Avatar/index.html | 131 ++++ .../lib/components/Avatar/index.tsx.html | 88 +++ .../lib/components/Button/index.html | 116 +++ .../lib/components/Button/index.tsx.html | 244 +++++++ .../lib/components/Label/Label.tsx.html | 157 +++++ .../lib/components/Label/index.html | 131 ++++ .../lib/components/Label/index.ts.html | 88 +++ .../Navigation-menu/Navigation.tsx.html | 550 +++++++++++++++ .../lib/components/Navigation-menu/index.html | 131 ++++ .../components/Navigation-menu/index.tsx.html | 88 +++ .../lib/components/Progress/Progress.tsx.html | 163 +++++ .../lib/components/Progress/index.html | 131 ++++ .../lib/components/Progress/index.tsx.html | 88 +++ .../lib/components/Select/Select.tsx.html | 604 ++++++++++++++++ .../lib/components/Select/index.html | 131 ++++ .../lib/components/Select/index.tsx.html | 88 +++ .../lib/components/Switch/Switch.tsx.html | 178 +++++ .../lib/components/Switch/index.html | 131 ++++ .../lib/components/Switch/index.tsx.html | 88 +++ .../lib/components/Textfield/index.html | 116 +++ .../lib/components/Textfield/index.tsx.html | 556 +++++++++++++++ .../lib/components/Toast/Toast.tsx.html | 475 +++++++++++++ .../lib/components/Toast/Toaster.tsx.html | 193 +++++ .../lib/components/Toast/hooks/index.html | 116 +++ .../components/Toast/hooks/use-toast.ts.html | 655 +++++++++++++++++ .../lib/components/Toast/index.html | 146 ++++ .../lib/components/Toast/index.tsx.html | 91 +++ .../lib/components/Typography/Slot.tsx.html | 148 ++++ .../lib/components/Typography/Text.tsx.html | 241 +++++++ .../components/Typography/constants.ts.html | 148 ++++ .../lib/components/Typography/index.html | 161 +++++ .../lib/components/Typography/index.ts.html | 88 +++ apps/ui/coverage/lcov-report/lib/index.html | 116 +++ .../coverage/lcov-report/lib/index.tsx.html | 127 ++++ apps/ui/coverage/lcov-report/prettify.css | 1 + apps/ui/coverage/lcov-report/prettify.js | 2 + .../lcov-report/sort-arrow-sprite.png | Bin 0 -> 138 bytes apps/ui/coverage/lcov-report/sorter.js | 196 ++++++ .../stories/Button.stories.tsx.html | 286 ++++++++ .../coverage/lcov-report/stories/index.html | 116 +++ apps/ui/coverage/lcov-report/utils/index.html | 116 +++ .../coverage/lcov-report/utils/utils.ts.html | 100 +++ apps/ui/coverage/lcov.info | 666 ++++++++++++++++++ 54 files changed, 10045 insertions(+), 16 deletions(-) create mode 100644 apps/ui/coverage/clover.xml create mode 100644 apps/ui/coverage/coverage-final.json create mode 100644 apps/ui/coverage/lcov-report/base.css create mode 100644 apps/ui/coverage/lcov-report/block-navigation.js create mode 100644 apps/ui/coverage/lcov-report/favicon.png create mode 100644 apps/ui/coverage/lcov-report/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Accordion/Accordion.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Accordion/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Accordion/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Avatar/Avatar.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Avatar/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Avatar/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Button/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Button/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Label/Label.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Label/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Label/index.ts.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Navigation-menu/Navigation.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Navigation-menu/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Navigation-menu/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Progress/Progress.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Progress/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Progress/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Select/Select.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Select/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Select/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Switch/Switch.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Switch/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Switch/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Textfield/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Textfield/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Toast/Toast.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Toast/Toaster.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Toast/hooks/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Toast/hooks/use-toast.ts.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Toast/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Toast/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Typography/Slot.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Typography/Text.tsx.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Typography/constants.ts.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Typography/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/components/Typography/index.ts.html create mode 100644 apps/ui/coverage/lcov-report/lib/index.html create mode 100644 apps/ui/coverage/lcov-report/lib/index.tsx.html create mode 100644 apps/ui/coverage/lcov-report/prettify.css create mode 100644 apps/ui/coverage/lcov-report/prettify.js create mode 100644 apps/ui/coverage/lcov-report/sort-arrow-sprite.png create mode 100644 apps/ui/coverage/lcov-report/sorter.js create mode 100644 apps/ui/coverage/lcov-report/stories/Button.stories.tsx.html create mode 100644 apps/ui/coverage/lcov-report/stories/index.html create mode 100644 apps/ui/coverage/lcov-report/utils/index.html create mode 100644 apps/ui/coverage/lcov-report/utils/utils.ts.html create mode 100644 apps/ui/coverage/lcov.info diff --git a/apps/ui/__test__/Button.spec.js b/apps/ui/__test__/Button.spec.js index 84fc324..0d15fcd 100644 --- a/apps/ui/__test__/Button.spec.js +++ b/apps/ui/__test__/Button.spec.js @@ -1,18 +1,17 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; import { Button } from '../lib/components/Button/index'; -import { Colors, Variants, Sizes } from '../stories/Button.stories'; +import { Variants, Sizes } from '../stories/Button.stories'; import '@testing-library/jest-dom'; const argsColor = { - variant: 'filled', + variant: 'default', size: 'md', }; const args = { - variant: 'filled', + variant: 'default', size: 'md', - color: 'primary', }; describe('Button Component', () => { @@ -20,20 +19,10 @@ describe('Button Component', () => { render(