Skip to content

Commit

Permalink
feat: add variants to Tabs
Browse files Browse the repository at this point in the history
SIKKA-6365[closed]
  • Loading branch information
zaaakher committed Feb 10, 2024
1 parent 2e4b2c1 commit 23e4fd8
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 38 deletions.
10 changes: 7 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"todo-tree.tree.showBadges": true,
"css.customData": [
".vscode/tailwind.json"
],
"css.customData": [".vscode/tailwind.json"],
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#007fff",
"titleBar.activeForeground": "#ffffff",
"titleBar.inactiveBackground": "#007fff",
"titleBar.inactiveForeground": "#ffffff"
},
"typescript.tsdk": "node_modules\\typescript\\lib"
}
7 changes: 7 additions & 0 deletions apps/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# hawa-docs

## 0.0.23

### Patch Changes

- Updated dependencies
- @sikka/hawa@0.28.0

## 0.0.22

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawa-docs",
"version": "0.0.22",
"version": "0.0.23",
"private": true,
"scripts": {
"dev": "next dev -p 3001",
Expand Down
7 changes: 7 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @sikka/hawa

## 0.28.0

### Minor Changes

- Adds new variants (`underlined` and `underlined_tabs`) to `Tabs`
- Initial integration of 'tailwind-variants' package

## 0.27.24

### Patch Changes
Expand Down
141 changes: 111 additions & 30 deletions packages/components/elements/tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,137 @@
import * as React from "react";

import { OrientationType } from "@_types/commonTypes";
import * as TabsPrimitive from "@radix-ui/react-tabs";

import { cn } from "@util/index";
import { VariantProps, cva } from "class-variance-authority";
import { tv } from "tailwind-variants";

import { OrientationType } from "@_types/commonTypes";

import { Chip, ChipTypes } from "../chip/Chip";

const tabsListVariant = tv({
base: "",
variants: {
variant: {
default:
"hawa-flex hawa-w-fit hawa-flex-wrap hawa-items-center hawa-justify-start hawa-gap-1 hawa-rounded hawa-border hawa-bg-muted hawa-p-1 hawa-text-muted-foreground dark:hawa-border-primary/10",
underlined:
"hawa-flex hawa-w-fit hawa-flex-wrap hawa-items-center hawa-justify-start hawa-gap-1 hawa-rounded hawa-p-1 hawa-text-muted-foreground dark:hawa-border-primary/10",
underlined_tabs:
"hawa-flex hawa-w-fit hawa-flex-wrap hawa-items-center hawa-justify-start hawa-gap-1 hawa-text-muted-foreground"
},
orientation: {
horizontal: "",
vertical: ""
}
},
compoundVariants: [
{
variant: "underlined_tabs",
orientation: "vertical",
class: "hawa-border-e-2 hawa-border-e-primary"
},
{
variant: "underlined_tabs",
orientation: "horizontal",
class: "hawa-border-b-2 hawa-border-b-primary"
}
],
defaultVariants: {
variant: "default",
orientation: "horizontal"
}
});

const tabsTriggerVariant = tv({
base: "",
variants: {
variant: {
default:
"hawa-inline-flex hawa-w-full hawa-flex-1 hawa-select-none hawa-items-center hawa-justify-center hawa-gap-2 hawa-whitespace-nowrap hawa-rounded hawa-border hawa-px-3 hawa-py-1.5 hawa-text-sm hawa-font-medium hawa-ring-offset-background hawa-transition-all focus-visible:hawa-outline-none focus-visible:hawa-ring-2 focus-visible:hawa-ring-ring focus-visible:hawa-ring-offset-2 disabled:hawa-pointer-events-none disabled:hawa-opacity-50 data-[state=active]:hawa-bg-primary data-[state=active]:hawa-text-primary-foreground data-[state=active]:hawa-shadow-sm dark:hawa-border-primary/10",
underlined:
"hawa-inline-flex hawa-w-full hawa-flex-1 hawa-select-none hawa-items-center hawa-justify-center hawa-gap-2 hawa-whitespace-nowrap hawa-rounded hawa-rounded-none hawa-px-3 hawa-py-1.5 hawa-text-sm hawa-font-medium hawa-ring-offset-background hawa-transition-all focus-visible:hawa-outline-none focus-visible:hawa-ring-2 focus-visible:hawa-ring-ring focus-visible:hawa-ring-offset-2 disabled:hawa-pointer-events-none disabled:hawa-opacity-50",
underlined_tabs:
"hawa-inline-flex hawa-w-full hawa-flex-1 hawa-select-none hawa-items-center hawa-justify-center hawa-gap-2 hawa-whitespace-nowrap hawa-rounded hawa-px-3 hawa-py-1.5 hawa-text-sm hawa-font-medium hawa-ring-offset-background hawa-transition-all focus-visible:hawa-outline-none focus-visible:hawa-ring-2 focus-visible:hawa-ring-ring focus-visible:hawa-ring-offset-2 disabled:hawa-pointer-events-none disabled:hawa-opacity-50 hawa-bg-primary/10 data-[state=active]:hawa-bg-primary data-[state=active]:hawa-text-primary-foreground dark:hawa-border-primary/10"
},
orientation: {
horizontal: "",
vertical: ""
}
},
compoundVariants: [
{
variant: "underlined",
orientation: "horizontal",
class:
"data-[state=active]:hawa-border-b-primary hawa-border-b hawa-border-b-2"
},
{
variant: "underlined",
orientation: "vertical",
class:
"data-[state=active]:hawa-border-e-primary hawa-border-e hawa-border-e-2"
},
{
variant: "underlined_tabs",
orientation: "horizontal",
class: "hawa-rounded-b-none"
},
{
variant: "underlined_tabs",
orientation: "vertical",
class: "hawa-rounded-e-none"
}
],
defaultVariants: {
variant: "default",
orientation: "horizontal"
}
});

type TabsVariants = "default" | "underlined" | "underlined_tabs";

const TabsContext = React.createContext<{
orientation?: OrientationType;
}>({ orientation: "vertical" });
variant?: TabsVariants;
}>({ orientation: "horizontal", variant: "default" });

type TabsRootProps = React.ComponentPropsWithoutRef<
typeof TabsPrimitive.Root
> & { orientation?: "vertical" | "horizontal" };
> & {
variant?: TabsVariants;
};

const Tabs = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Root>,
TabsRootProps
>(
(
{ className, orientation = "vertical" as OrientationType, ...props },
ref
) => (
<TabsPrimitive.Root
ref={ref}
className={cn(
"hawa-flex hawa-gap-2",
orientation === "vertical" ? "hawa-flex-row" : "hawa-flex-col",
className
)}
{...props}
>
<TabsContext.Provider value={{ orientation }}>
{props.children}
</TabsContext.Provider>
</TabsPrimitive.Root>
)
);
>(({ className, orientation, variant = "default", ...props }, ref) => (
<TabsPrimitive.Root
ref={ref}
className={cn(
"hawa-flex hawa-gap-2",
orientation === "vertical" ? "hawa-flex-row" : "hawa-flex-col",
className
)}
{...props}
>
<TabsContext.Provider value={{ orientation, variant }}>
{props.children}
</TabsContext.Provider>
</TabsPrimitive.Root>
));
Tabs.displayName = TabsPrimitive.Root.displayName;

const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => {
const { orientation } = React.useContext(TabsContext);
const { orientation, variant } = React.useContext(TabsContext);
return (
<TabsPrimitive.List
ref={ref}
className={cn(
"hawa-flex hawa-w-fit hawa-flex-wrap hawa-items-center hawa-justify-start hawa-gap-1 hawa-rounded hawa-border hawa-bg-muted hawa-p-1 hawa-text-muted-foreground dark:hawa-border-primary/10",
tabsListVariant({ variant, orientation }),
orientation === "vertical" ? "hawa-flex-col" : "hawa-flex-row",
className
)}
Expand All @@ -69,13 +152,11 @@ const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
TabsTriggerProps
>(({ className, chipProps, ...props }, ref) => {
const { orientation, variant } = React.useContext(TabsContext);
return (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
"hawa-inline-flex hawa-w-full hawa-flex-1 hawa-select-none hawa-items-center hawa-justify-center hawa-gap-2 hawa-whitespace-nowrap hawa-rounded hawa-border hawa-px-3 hawa-py-1.5 hawa-text-sm hawa-font-medium hawa-ring-offset-background hawa-transition-all focus-visible:hawa-outline-none focus-visible:hawa-ring-2 focus-visible:hawa-ring-ring focus-visible:hawa-ring-offset-2 disabled:hawa-pointer-events-none disabled:hawa-opacity-50 data-[state=active]:hawa-bg-primary data-[state=active]:hawa-text-primary-foreground data-[state=active]:hawa-shadow-sm dark:hawa-border-primary/10",
className
)}
className={cn(tabsTriggerVariant({ variant, orientation }), className)}
{...props}
>
{props.children}
Expand Down
3 changes: 2 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sikka/hawa",
"version": "0.27.24",
"version": "0.28.0",
"description": "Modern UI Kit made with Tailwind",
"author": {
"name": "Sikka Software",
Expand Down Expand Up @@ -91,6 +91,7 @@
"react-select": "^5.8.0",
"signature_pad": "^4.1.7",
"tailwind-merge": "^2.2.1",
"tailwind-variants": "^0.1.20",
"trim-canvas": "^0.1.2",
"zod": "^3.22.4"
},
Expand Down
7 changes: 7 additions & 0 deletions packages/storybook/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# hawa-storybook

## 0.26.40

### Patch Changes

- Updated dependencies
- @sikka/hawa@0.28.0

## 0.26.39

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hawa-storybook",
"version": "0.26.39",
"version": "0.26.40",
"description": "Modern UI Kit made with Tailwind",
"author": {
"name": "Sikka Software",
Expand Down
16 changes: 14 additions & 2 deletions packages/storybook/stories/ElementsStories/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TabsList,
TabsTrigger
} from "@sikka/hawa/elements/tabs";
import { OrientationType } from "@sikka/hawa/types/commonTypes";

import { setLocale, t } from "../../translations/i18n";

Expand All @@ -25,7 +26,7 @@ export const Default: Story = {
setLocale(locale);

return (
<Tabs defaultValue="account" dir={direction}>
<Tabs variant={args.variant} defaultValue="account" dir={direction}>
<TabsList className="hawa-w-full">
<TabsTrigger value="account">{t("account")}</TabsTrigger>
<TabsTrigger value="password">{t("password")}</TabsTrigger>
Expand Down Expand Up @@ -70,6 +71,9 @@ export const Default: Story = {
</TabsContent>
</Tabs>
);
},
args: {
variant: "default"
}
};
export const Vertical: Story = {
Expand All @@ -79,7 +83,12 @@ export const Vertical: Story = {
const direction = locale === "ar" ? "rtl" : "ltr";

return (
<Tabs defaultValue="account" orientation="vertical" dir={direction}>
<Tabs
variant={args.variant}
defaultValue="account"
orientation="vertical"
dir={direction}
>
<TabsList>
<TabsTrigger value="account">{t("account")}</TabsTrigger>
<TabsTrigger value="password">{t("password")}</TabsTrigger>
Expand Down Expand Up @@ -114,5 +123,8 @@ export const Vertical: Story = {
</TabsContent>
</Tabs>
);
},
args: {
variant: "default"
}
};
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 23e4fd8

Please sign in to comment.