Skip to content

Commit

Permalink
feat: create separator ui component (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonible14012002 authored Nov 9, 2023
1 parent fc12062 commit 4b212ba
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/components/separator/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['custom/react'],
}
41 changes: 41 additions & 0 deletions packages/components/separator/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@consolelabs/separator",
"version": "0.0.1",
"sideEffects": false,
"main": "src/index.ts",
"files": [
"dist"
],
"publishConfig": {
"access": "public"
},
"license": "MIT",
"scripts": {
"build": "tsup src --dts",
"build:fast": "tsup src",
"dev": "yarn build:fast -- --watch",
"lint": "eslint src/",
"clean": "rimraf dist .turbo",
"typecheck": "tsc --noEmit",
"prepack": "clean-package",
"postpack": "clean-package restore"
},
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"clean-package": "^2.2.0",
"eslint-config-custom": "workspace:*",
"prettier": "^3.0.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tsconfig": "workspace:*"
},
"dependencies": {
"@consolelabs/theme": "workspace:*",
"@radix-ui/react-separator": "^1.0.3",
"clsx": "^2.0.0"
},
"clean-package": "../../../clean-package.config.json"
}
1 change: 1 addition & 0 deletions packages/components/separator/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './separator'
36 changes: 36 additions & 0 deletions packages/components/separator/src/separator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import * as SeparatorPrimitive from '@radix-ui/react-separator'
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react'
import clsx from 'clsx'
import { separator as separatorClassName } from '@consolelabs/theme'

const Separator = forwardRef<
ElementRef<typeof SeparatorPrimitive.Root>,
ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>((props, ref) => {
const {
orientation = 'horizontal',
className,
decorative = true,
...restProps
} = props

return (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
className={clsx(
separatorClassName.base,
{
[separatorClassName.horizontal]: orientation === 'horizontal',
[separatorClassName.vertical]: orientation === 'vertical',
},
className,
)}
{...restProps}
/>
)
})

Separator.displayName = SeparatorPrimitive.Root.displayName

export { Separator }
37 changes: 37 additions & 0 deletions packages/components/separator/stories/separator.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Meta, StoryObj } from '@storybook/react'
import { Separator } from '../src'

const meta: Meta<typeof Separator> = {
title: 'ui/Separator',
component: Separator,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
}

export default meta

export const Default: StoryObj = {
render() {
return (
<div>
<div className="space-y-1">
<h4 className="text-sm font-medium leading-none">Radix Primitives</h4>
<p className="text-sm text-muted-foreground">
An open-source UI component library.
</p>
</div>
<Separator className="my-4" />
<div className="flex h-5 items-center space-x-4 text-sm">
<div>Blog</div>
<Separator orientation="vertical" />
<div>Docs</div>
<Separator orientation="vertical" />
<div>Source</div>
</div>
</div>
)
},
}
5 changes: 5 additions & 0 deletions packages/components/separator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "tsconfig/react-library.json",
"include": ["src", "stories", "index.ts"],
"exclude": ["dist", "node_modules"]
}
7 changes: 7 additions & 0 deletions packages/components/separator/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'tsup'

export default defineConfig(() => ({
clean: true,
target: 'es2019',
format: ['cjs', 'esm'],
}))
1 change: 1 addition & 0 deletions packages/theme/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './list'
export * from './toggle-button'
export * from './select'
export * from './tabs'
export * from './separator'
11 changes: 11 additions & 0 deletions packages/theme/src/components/separator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const horizontal = 'h-[0.5px] w-full'
const vertical = 'w-[0.5px] h-full'
const base = 'shrink-0 bg-neutral-400 rounded-full'

const separator = {
horizontal,
vertical,
base,
}

export { separator }
1 change: 1 addition & 0 deletions packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toggle-group": "^1.0.4",
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/separator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './separator'
37 changes: 37 additions & 0 deletions packages/ui/src/separator/separator.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Meta, StoryObj } from '@storybook/react'
import { Separator } from './separator'

const meta: Meta<typeof Separator> = {
title: 'ui/Separator',
component: Separator,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
}

export default meta

export const Default: StoryObj = {
render() {
return (
<div>
<div className="space-y-1">
<h4 className="text-sm font-medium leading-none">Radix Primitives</h4>
<p className="text-sm text-muted-foreground">
An open-source UI component library.
</p>
</div>
<Separator className="my-4" />
<div className="flex h-5 items-center space-x-4 text-sm">
<div>Blog</div>
<Separator orientation="vertical" />
<div>Docs</div>
<Separator orientation="vertical" />
<div>Source</div>
</div>
</div>
)
},
}
35 changes: 35 additions & 0 deletions packages/ui/src/separator/separator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as SeparatorPrimitive from '@radix-ui/react-separator'
import clsx from 'clsx'
import { ComponentPropsWithoutRef, ElementRef, forwardRef } from 'react'

const Separator = forwardRef<
ElementRef<typeof SeparatorPrimitive.Root>,
ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>((props, ref) => {
const {
orientation = 'horizontal',
className,
decorative = true,
...restProps
} = props

return (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
className={clsx(
'shrink-0 bg-neutral-400 rounded-full',
{
'h-[0.5px] w-full': orientation === 'horizontal',
'w-[0.5px] h-full': orientation === 'vertical',
},
className,
)}
{...restProps}
/>
)
})

Separator.displayName = SeparatorPrimitive.Root.displayName

export { Separator }
35 changes: 34 additions & 1 deletion pnpm-lock.yaml

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

1 comment on commit 4b212ba

@vercel
Copy link

@vercel vercel bot commented on 4b212ba Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

websites-mochi – ./apps/mochi-web

websites-mochi-consolelabs.vercel.app
websites-mochi-git-main-consolelabs.vercel.app
websites-mochi.vercel.app
beta.mochi.gg

Please sign in to comment.