Skip to content

Commit

Permalink
Add components (#147)
Browse files Browse the repository at this point in the history
* Add components

* Format tabs component
  • Loading branch information
josepjaume authored May 24, 2024
1 parent c610172 commit fa3542f
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const config: StorybookConfig = {
titlePrefix: "Components",
},
{
directory: "../lib/primitives",
titlePrefix: "Primitives",
directory: "../src/examples",
titlePrefix: "Examples",
},
],
staticDirs: ["../public"],
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"tailwindCSS.experimental.classRegex": [
[
"cva\\(([^)]*)\\)",
"cva\\(\\s*\"[^\"]*\"\\s*,\\s*({(?:[^{}]|\\{(?:[^{}]|\\{[^{}]*\\})*\\})*})\\s*\\)",
"[\"'`]([^\"'`]*).*?[\"'`]"
],
]
Expand Down
25 changes: 24 additions & 1 deletion lib/components/Forms/Input/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const meta = {
argTypes: {
type: {
control: { type: "radio" },
options: ["text", "email", "password", "number", "file"],
},
value: {
control: { type: "text" },
Expand All @@ -32,3 +31,27 @@ export const Primary: Story = {
placeholder: "Placeholder text here",
},
}

export const File: Story = {
args: {
type: "file",
disabled: false,
placeholder: "Placeholder text here",
},
}

export const Password: Story = {
args: {
type: "password",
disabled: false,
placeholder: "Placeholder text here",
},
}

export const Disabled: Story = {
args: {
type: "text",
disabled: true,
placeholder: "Placeholder text here",
},
}
1 change: 1 addition & 0 deletions lib/components/Layout/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./Grid"
export * from "./Stack"
29 changes: 29 additions & 0 deletions lib/components/Navigation/Tabs/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Meta, StoryObj } from "@storybook/react"

import { Tabs, TabsContent, TabsList, TabsTrigger } from "."

const meta = {
component: Tabs,
tags: ["autodocs"],
args: {
children: (
<>
<TabsList>
<TabsTrigger value="one">One</TabsTrigger>
<TabsTrigger value="two">Two</TabsTrigger>
</TabsList>
<TabsContent value="one">Content of section one</TabsContent>
<TabsContent value="two">Content of section two</TabsContent>
</>
),
},
} satisfies Meta<typeof Tabs>

export default meta
type Story = StoryObj<typeof meta>

export const Default: Story = {
args: {
defaultValue: "one",
},
}
1 change: 1 addition & 0 deletions lib/components/Navigation/Tabs/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "@/shadcn/tabs"
1 change: 1 addition & 0 deletions lib/components/Navigation/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Tabs"
1 change: 1 addition & 0 deletions lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./Blocks"
export * from "./Forms"
export * from "./Information"
export * from "./Layout"
export * from "./Navigation"
export * from "./Overlays"
2 changes: 1 addition & 1 deletion lib/lib/one-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const FactorialOneProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
useLayoutEffect(() => {
const classNames = "font-sans bg-background".split(" ")
const classNames = "font-sans text-foreground bg-background".split(" ")

document.body.classList.add(...classNames)

Expand Down
1 change: 1 addition & 0 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./components"
export { FactorialOneProvider } from "./lib/one-provider"
53 changes: 53 additions & 0 deletions lib/shadcn/tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as TabsPrimitive from "@radix-ui/react-tabs"
import * as React from "react"

import { cn } from "@/lib/utils"

const Tabs = TabsPrimitive.Root

const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => (
<TabsPrimitive.List
ref={ref}
className={cn(
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
className
)}
{...props}
/>
))
TabsList.displayName = TabsPrimitive.List.displayName

const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
className
)}
{...props}
/>
))
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName

const TabsContent = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Content
ref={ref}
className={cn(
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
className
)}
{...props}
/>
))
TabsContent.displayName = TabsPrimitive.Content.displayName

export { Tabs, TabsContent, TabsList, TabsTrigger }
31 changes: 31 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.7",
"@tailwindcss/container-queries": "^0.1.1",
"class-variance-authority": "^0.7.0",
Expand Down
21 changes: 15 additions & 6 deletions src/examples/layout/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from "lucide-react"
import React from "react"

import { Card, CardContent, CardHeader, CardTitle, Grid } from "@/components"
import { Button } from "@/shadcn/button"
import { Popover, PopoverContent, PopoverTrigger } from "@/shadcn/popover"
import { ScrollArea } from "@/shadcn/scrollarea"
Expand Down Expand Up @@ -149,14 +150,22 @@ const Layout: React.FC = () => {
</span>
</div>
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2 md:gap-6 lg:grid-cols-3">
<Grid size={"lg"}>
{[...Array(6)].map((_, i) => (
<div className="flex flex-col rounded-lg border p-4 font-medium transition-colors hover:cursor-pointer hover:bg-muted/50">
<Folder size="16" className="mb-1 text-secondary-foreground" />
Folder {++i}
</div>
<Card>
<CardHeader>
<Folder
size="16"
className="mb-1 text-secondary-foreground"
/>
<CardTitle>Folder {i + 1}</CardTitle>
</CardHeader>
<CardContent>
Summary of the contents of the folder.
</CardContent>
</Card>
))}
</div>
</Grid>
</div>
</ScrollArea>
</div>
Expand Down

0 comments on commit fa3542f

Please sign in to comment.