Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 123aca5

Browse files
committed
style
1 parent 77dbee6 commit 123aca5

File tree

10 files changed

+93
-68
lines changed

10 files changed

+93
-68
lines changed

packages/react-databrowser/src/components/databrowser/components/add-key-modal.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
} from "@/components/ui/select"
2424
import { Spinner } from "@/components/ui/spinner"
2525
import { toast } from "@/components/ui/use-toast"
26-
import { RedisTypeTag } from "@/components/databrowser/components/type-tag"
26+
import { TypeTag } from "@/components/databrowser/components/type-tag"
2727
import { useAddKey } from "@/components/databrowser/hooks/use-add-key"
2828

2929
export function AddKeyModal() {
@@ -63,33 +63,31 @@ export function AddKeyModal() {
6363
}}
6464
>
6565
<DialogTrigger asChild>
66-
<Button
67-
variant="outline"
68-
size="icon-sm"
69-
className="border-none bg-[#13B981] hover:bg-[#13B981]/90"
70-
>
71-
<PlusIcon className="h-4 w-4 text-white" />
66+
<Button variant="primary" size="icon-sm">
67+
<PlusIcon className="h-4 w-4" />
7268
</Button>
7369
</DialogTrigger>
74-
<DialogContent className="sm:max-w-[550px]">
70+
71+
<DialogContent className="max-w-[400px]">
7572
<DialogHeader>
7673
<DialogTitle>Create new key</DialogTitle>
7774
</DialogHeader>
75+
7876
<form className="mt-4" onSubmit={onSubmit}>
7977
<div className="flex gap-1">
8078
<Controller
8179
control={control}
8280
name="type"
8381
render={({ field }) => (
8482
<Select value={field.value} onValueChange={field.onChange}>
85-
<SelectTrigger className="h-8 w-auto pl-[3px] pr-10">
83+
<SelectTrigger className="h-8 w-auto pl-[3px] pr-8">
8684
<SelectValue />
8785
</SelectTrigger>
8886
<SelectContent>
8987
<SelectGroup>
9088
{DATA_TYPES.map((type) => (
9189
<SelectItem key={type} value={type}>
92-
<RedisTypeTag type={type as DataType} />
90+
<TypeTag variant={type} type="badge" />
9391
</SelectItem>
9492
))}
9593
</SelectGroup>
@@ -108,12 +106,15 @@ export function AddKeyModal() {
108106
)}
109107
/>
110108
</div>
109+
111110
{formState.errors.key && (
112-
<div className="mb-3 mt-1 text-xs text-red-500">{formState.errors.key?.message}</div>
111+
<p className="mb-3 mt-2 text-xs text-red-500">{formState.errors.key?.message}</p>
113112
)}
114-
<div className="mt-1 text-xs text-zinc-500">
113+
114+
<p className="mt-2 text-xs text-zinc-500">
115115
After creating the key, you can edit the value
116-
</div>
116+
</p>
117+
117118
<div className="mt-6 flex justify-end gap-2">
118119
<Button
119120
type="button"

packages/react-databrowser/src/components/databrowser/components/display/display-header.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FETCH_TTL_QUERY_KEY, useFetchTTL } from "../../hooks"
1313
import { useDeleteKeyCache } from "../../hooks/use-delete-key-cache"
1414
import { useFetchKeyLength } from "../../hooks/use-fetch-key-length"
1515
import { useFetchKeySize } from "../../hooks/use-fetch-key-size"
16-
import { RedisTypeTag } from "../type-tag"
16+
import { TypeTag } from "../type-tag"
1717
import { KeyActions } from "./key-actions"
1818
import { TTLPopover } from "./ttl-popover"
1919

@@ -62,7 +62,7 @@ export const DisplayHeader = ({
6262
</div>
6363
{!hideBadges && (
6464
<div className="flex flex-wrap gap-1">
65-
<RedisTypeTag type={type} isIcon={false} />
65+
<TypeTag variant={type} type="badge" />
6666
<SizeBadge dataKey={dataKey} />
6767
<LengthBadge dataKey={dataKey} type={type} content={content} />
6868
{length && <Badge label="Length:">{size}</Badge>}

packages/react-databrowser/src/components/databrowser/components/sidebar/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,32 @@ export function Sidebar() {
1717

1818
return (
1919
<div className="flex h-full flex-col gap-2 rounded-xl border p-1">
20-
{/* start -> Header */}
2120
<div className="rounded-lg bg-zinc-100 px-3 py-2">
22-
{/* Header top */}
23-
<div className="flex h-10 items-center justify-between">
21+
{/* Meta */}
22+
<div className="flex h-10 items-center justify-between pl-1">
2423
<DisplayDbSize />
2524
<div className="flex gap-1">
2625
<AddKeyModal />
2726
</div>
2827
</div>
2928

30-
{/* Header bottom */}
31-
<div className="flex h-10">
29+
{/* Filter */}
30+
<div className="flex h-10 items-center">
31+
{/* Types */}
3232
<DataTypeSelector />
33+
34+
{/* Search */}
3335
<Input
3436
type="text"
3537
placeholder="Search"
3638
className={
37-
"block rounded-l-none border-zinc-300 px-2 font-normal placeholder-zinc-300 focus-visible:ring-0"
39+
"rounded-l-none border-zinc-300 px-2 font-normal placeholder-zinc-300 focus-visible:ring-0"
3840
}
3941
onChange={(e) => setSearchKey(e.target.value)}
4042
value={search.key}
4143
/>
4244
</div>
4345
</div>
44-
{/* finish -> Header */}
4546

4647
{query.isLoading ? (
4748
<LoadingSkeleton />

packages/react-databrowser/src/components/databrowser/components/sidebar/infinite-scroll.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const InfiniteScroll = ({
2323
return (
2424
<ScrollArea className="block h-full w-full transition-all" onScroll={handleScroll}>
2525
{children}
26+
27+
{/* scroll trigger */}
2628
<div className="flex h-[100px] justify-center py-2 text-zinc-300">
2729
{query.isFetching && <IconLoader2 className="animate-spin" size={16} />}
2830
</div>

packages/react-databrowser/src/components/databrowser/components/sidebar/keys-list.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useDatabrowserStore } from "@/store"
22

33
import { cn } from "@/lib/utils"
44
import { Button } from "@/components/ui/button"
5-
import { RedisTypeTag } from "@/components/databrowser/components/type-tag"
5+
import { TypeTag } from "@/components/databrowser/components/type-tag"
66
import type { RedisKey } from "@/components/databrowser/hooks"
77

88
import { useKeys } from "../../hooks/use-keys"
@@ -28,17 +28,18 @@ const KeyItem = ({ data }: { data: RedisKey }) => {
2828
return (
2929
<Button
3030
key={dataKey}
31+
variant={isKeySelected ? "default" : "ghost"}
3132
className={cn(
32-
"flex w-full items-center justify-start gap-2 border text-left",
33-
isKeySelected
34-
? "border-emerald-400 bg-emerald-50 shadow-sm hover:bg-emerald-100/60"
35-
: "border-transparent"
33+
"relative flex h-10 w-full items-center justify-start gap-3 px-3 py-0 ",
34+
"border border-transparent text-left",
35+
isKeySelected && "border-zinc-500 !bg-zinc-100 shadow-sm"
3636
)}
37-
variant={isKeySelected ? "default" : "ghost"}
3837
onClick={() => setSelectedKey(dataKey)}
3938
>
40-
<RedisTypeTag type={dataType} isIcon />
39+
<TypeTag variant={dataType} type="icon" />
4140
<p className="truncate whitespace-nowrap text-black">{dataKey}</p>
41+
42+
{!isKeySelected && <span className="absolute -bottom-px left-3 right-3 h-px bg-zinc-100" />}
4243
</Button>
4344
)
4445
}

packages/react-databrowser/src/components/databrowser/components/sidebar/skeleton-buttons.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Skeleton } from "@/components/ui/skeleton"
22

3-
const DEFAULT_SKELETON_COUNT = 10
3+
const DEFAULT_SKELETON_COUNT = 6
4+
45
export const LoadingSkeleton = () => (
5-
<div className="flex flex-col pr-1">
6+
<div className="grid">
67
{Array.from({ length: DEFAULT_SKELETON_COUNT })
78
.fill(0)
89
.map((_, idx) => (
9-
<div className="flex h-[40px] items-center rounded-md bg-zinc-100 pl-4 pr-8" key={idx}>
10-
<Skeleton className="mr-2 h-[20px] w-[20px] rounded" />
11-
<Skeleton className="h-[20px] w-full rounded" />
10+
<div className="flex h-10 items-center gap-3 px-3" key={idx}>
11+
<Skeleton className="size-5 shrink-0 rounded" />
12+
<Skeleton className="h-4 grow rounded" />
1213
</div>
1314
))}
1415
</div>
Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as React from "react"
12
import { DATA_TYPE_NAMES, type DataType } from "@/types"
23
import {
34
IconArrowsSort,
@@ -7,43 +8,50 @@ import {
78
IconList,
89
IconQuote,
910
} from "@tabler/icons-react"
10-
import colors from "tailwindcss/colors"
11+
import { cva, type VariantProps } from "class-variance-authority"
1112

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

14-
const colorsMap = {
15-
string: colors.sky,
16-
set: colors.indigo,
17-
hash: colors.amber,
18-
json: colors.purple,
19-
zset: colors.pink,
20-
list: colors.orange,
21-
stream: colors.orange,
22-
} as const
23-
2415
const iconsMap = {
25-
string: <IconQuote size={16} />,
26-
set: <IconLayersIntersect size={16} />,
27-
hash: <IconHash size={16} />,
28-
json: <IconCodeDots size={16} />,
29-
zset: <IconArrowsSort size={16} />,
30-
list: <IconList size={16} />,
31-
stream: <IconList size={16} />,
16+
string: <IconQuote size={16} stroke={1.5} />,
17+
set: <IconLayersIntersect size={16} stroke={1.5} />,
18+
hash: <IconHash size={16} stroke={1.5} />,
19+
json: <IconCodeDots size={16} stroke={1.5} />,
20+
zset: <IconArrowsSort size={16} stroke={1.5} />,
21+
list: <IconList size={16} stroke={1.5} />,
22+
stream: <IconList size={16} stroke={1.5} />,
3223
} as const
3324

34-
export function RedisTypeTag({ type, isIcon }: { type: DataType; isIcon?: boolean }) {
25+
const tagVariants = cva("inline-flex shrink-0 items-center rounded-md justify-center", {
26+
variants: {
27+
variant: {
28+
string: "bg-sky-200 text-sky-800",
29+
list: "bg-orange-200 text-orange-800",
30+
hash: "bg-amber-200 text-amber-800",
31+
set: "bg-indigo-200 text-indigo-800",
32+
zset: "bg-pink-200 text-pink-800",
33+
json: "bg-purple-200 text-purple-800",
34+
stream: "bg-orange-200 text-orange-800",
35+
},
36+
type: {
37+
icon: "size-5",
38+
badge: "h-6 px-2 uppercase whitespace-nowrap text-xs font-medium leading-none tracking-wide",
39+
},
40+
},
41+
defaultVariants: {
42+
variant: "string",
43+
type: "icon",
44+
},
45+
})
46+
47+
export interface TypeTagProps
48+
extends React.ComponentProps<"span">,
49+
VariantProps<typeof tagVariants> {}
50+
51+
export function TypeTag({ className, variant, type }: TypeTagProps) {
3552
return (
36-
<div
37-
className={cn(
38-
"inline-flex shrink-0 items-center justify-center whitespace-nowrap rounded-md text-xs font-medium leading-none tracking-wide",
39-
isIcon ? "h-5 w-5" : "h-6 px-1 uppercase"
40-
)}
41-
style={{
42-
backgroundColor: colorsMap[type][200],
43-
color: colorsMap[type][800],
44-
}}
45-
>
46-
{isIcon ? iconsMap[type] : DATA_TYPE_NAMES[type]}
47-
</div>
53+
<span className={cn(tagVariants({ variant, type, className }))}>
54+
{type === "icon" ? iconsMap[variant as DataType] : DATA_TYPE_NAMES[variant as DataType]}
55+
</span>
4856
)
4957
}

packages/react-databrowser/src/components/ui/dialog.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ const DialogOverlay = React.forwardRef<
1919
<DialogPrimitive.Overlay
2020
ref={ref}
2121
className={cn(
22-
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-white/80 backdrop-blur-sm dark:bg-neutral-950/80",
22+
"data-[state=open]:animate-in data-[state=closed]:animate-out",
23+
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
24+
"fixed inset-0 z-50 bg-black/50 backdrop-blur-sm",
2325
className
2426
)}
2527
{...props}
@@ -36,7 +38,15 @@ const DialogContent = React.forwardRef<
3638
<DialogPrimitive.Content
3739
ref={ref}
3840
className={cn(
39-
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-200 bg-white p-6 shadow-lg duration-200 sm:rounded-lg md:w-full dark:border-neutral-800 dark:bg-neutral-950",
41+
"data-[state=open]:animate-in data-[state=closed]:animate-out ",
42+
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 ",
43+
"data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 ",
44+
"data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%]",
45+
"data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%]",
46+
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg ",
47+
"translate-x-[-50%] translate-y-[-50%] gap-4",
48+
"bg-white p-6 shadow-lg duration-200 ",
49+
"sm:rounded-lg md:w-full",
4050
className
4151
)}
4252
{...props}

packages/react-databrowser/src/playground.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ReactDOM from "react-dom/client"
33
import { Databrowser } from "@/components/databrowser"
44

55
ReactDOM.createRoot(document.querySelector("#root")!).render(
6-
<main className="h-screen max-h-full rounded-xl bg-white">
6+
<main className="h-screen max-h-full rounded-xl bg-white antialiased">
77
<Databrowser
88
token={process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_TOKEN}
99
url={process.env.NEXT_PUBLIC_UPSTASH_REDIS_REST_URL}

packages/react-databrowser/tailwind.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const defaultTheme = require("tailwindcss/defaultTheme")
2+
const colors = require("tailwindcss/colors")
23

34
/** @type {import('tailwindcss').Config} */
45
module.exports = {

0 commit comments

Comments
 (0)