Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

make select look better

ameer2468c760b8d99430
diff --git a/apps/web/app/(org)/dashboard/analytics/components/Header.tsx b/apps/web/app/(org)/dashboard/analytics/components/Header.tsx
index eab2d82c0..a20397662 100644
--- a/apps/web/app/(org)/dashboard/analytics/components/Header.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/components/Header.tsx
@@ -3,6 +3,8 @@
import { Button, Select } from "@cap/ui";
import { useState } from "react";
import { CompareDataDialog } from "./CompareDataDialog";
+import { faCalendar } from "@fortawesome/free-solid-svg-icons";
+import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
export default function Header() {
const [openCompareDataDialog, setOpenCompareDataDialog] = useState(false);
@@ -13,20 +15,10 @@ export default function Header() {
onOpenChange={setOpenCompareDataDialog}
/>
<div className="flex gap-2 items-center">
- {/* <Select
- variant="dark"
- size="fit"
- options={[
- { value: "views", label: "Views" },
- { value: "comments", label: "Comments" },
- { value: "reactions", label: "Reactions" },
- ]}
- onValueChange={() => {}}
- placeholder="Metric"
- /> */}
<Select
- variant="dark"
- size="fit"
+ variant="light"
+ icon={<FontAwesomeIcon icon={faCalendar} />}
+ size="md"
options={[
{ value: "24_hours", label: "24 hours" },
{ value: "7_days", label: "7 days" },
diff --git a/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx b/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx
index c960107bc..f9e50cbb6 100644
--- a/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx
+++ b/apps/web/app/(org)/dashboard/analytics/components/TableCard.tsx
@@ -1,5 +1,6 @@
import {
LogoBadge,
+ Select,
Table,
TableBody,
TableCell,
@@ -11,7 +12,9 @@ import {
faAppleWhole,
faDesktop,
faMobileScreen,
+ faFilter,
faTablet,
+ faDownLong,
} from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import clsx from "clsx";
@@ -120,7 +123,22 @@ const TableCard = ({
}: TableCardProps) => {
return (
<div className="p-5 w-full rounded-xl border bg-gray-2 border-gray-4">
- <p className="text-lg font-medium text-gray-12">{title}</p>
+ <div className="flex flex-1 gap-2 justify-between items-center h-[48px]">
+ <p className="text-lg font-medium text-gray-12">{title}</p>
+ <Select
+ variant="light"
+ icon={<FontAwesomeIcon icon={faFilter} />}
+ size="md"
+ options={[
+ { label: "Views", value: "views_desc" },
+ { label: "Comments", value: "comments_desc" },
+ { label: "Reactions", value: "reactions_desc" },
+ { label: "Percentage", value: "percentage_desc" },
+ ]}
+ onValueChange={() => {}}
+ placeholder="Sort by"
+ />
+ </div>
<div className="w-full">
<Table
className={clsx(
@@ -159,16 +177,16 @@ const TableCard = ({
<span className="truncate">{row.name}</span>
</div>
</TableCell>
- <TableCell className="p-2.5 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ <TableCell className="py-2.5 px-3 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
{row.views}
</TableCell>
- <TableCell className="p-2.5 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ <TableCell className="p-2.5 px-3 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
{row.comments}
</TableCell>
- <TableCell className="p-2.5 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ <TableCell className="p-2.5 px-3 text-sm text-nowrap text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
{row.reactions}
</TableCell>
- <TableCell className="p-2.5 text-sm text-nowrap rounded-r-lg border-r text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
+ <TableCell className="p-2.5 px-3 text-sm text-nowrap rounded-r-lg border-r text-gray-11 bg-gray-3 border-y border-gray-5 whitespace-nowrap">
{row.percentage}
</TableCell>
</TableRow>
diff --git a/packages/ui/src/components/Select.tsx b/packages/ui/src/components/Select.tsx
index 0840309ce..c63571043 100644
--- a/packages/ui/src/components/Select.tsx
+++ b/packages/ui/src/components/Select.tsx
@@ -5,20 +5,21 @@ import { cva, cx } from "class-variance-authority";
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react";
import * as React from "react";
-type SelectVariant = "default" | "dark" | "gray" | "transparent";
+type SelectVariant = "default" | "light" | "dark" | "gray" | "transparent"
+type Size = "default" | "fit" | "sm" | "md" | "lg"
const SelectVariantContext = React.createContext<SelectVariant>("default");
const selectTriggerVariants = cva(
cx(
- "font-medium flex px-4 py-2 transition-all duration-200 text-sm outline-0",
- "rounded-xl border-[1px] items-center justify-between gap-2 whitespace-nowrap",
+ "font-medium flex transition-all duration-200 text-[13px] outline-0",
+ "border-[1px] items-center justify-between gap-2 whitespace-nowrap",
"disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-gray-3 disabled:text-gray-9",
- "ring-0 ring-gray-12 ring-offset-0 data-[state=open]:ring-offset-2 ring-offset-gray-1 data-[state=open]:ring-1",
- "data-[placeholder]:text-gray-1 data-[size=default]:h-[44px] data-[size=sm]:h-[40px]",
+ "ring-0 ring-gray-6 ring-offset-gray-6 data-[state=open]:border-gray-7 data-[state=open]:ring-gray-7 data-[state=open]:ring-1 data-[state=open]:ring-offset-0",
+ "data-[placeholder]:text-gray-12",
"*:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2",
"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg]:transition-transform [&_svg]:duration-200",
- "[&[data-state=open]_svg]:rotate-180",
+ "[&[data-state=open]_svg.caret-icon]:rotate-180",
),
{
defaultVariants: {
@@ -30,15 +31,17 @@ const selectTriggerVariants = cva(
default:
"bg-gray-2 border-gray-5 text-gray-12 hover:bg-gray-3 hover:border-gray-6",
dark: "bg-gray-12 transition-all duration-200 data-[state=open]:ring-offset-2 data-[state=open]:ring-gray-10 ring-transparent ring-offset-gray-3 text-gray-1 border-gray-5 hover:bg-gray-11 hover:border-gray-6",
- white:
- "bg-gray-1 text-gray-12 border-gray-5 hover:bg-gray-3 hover:border-gray-6",
+ light: "bg-gray-1 transition-all duration-200 data-[state=open]:ring-offset-2 data-[state=open]:ring-gray-10 ring-transparent ring-offset-gray-3 text-gray-12 border-gray-5 hover:bg-gray-3 hover:border-gray-6",
gray: "bg-gray-5 text-gray-12 border-gray-5 hover:bg-gray-7 hover:border-gray-6",
transparent:
"bg-transparent text-gray-12 border-transparent hover:bg-gray-3 hover:border-gray-6",
},
size: {
- default: "w-full",
- fit: "w-fit",
+ default: "w-full h-[44px] px-4 rounded-xl",
+ fit: "w-fit h-[32px] px-3 rounded-[10px]",
+ sm: "w-fit h-[32px] px-3 rounded-[10px]",
+ md: "w-fit h-[40px] px-3 rounded-xl",
+ lg: "w-fit h-[48px] px-4 rounded-xl",
},
},
},
@@ -62,6 +65,7 @@ const selectContentVariants = cva(
variant: {
default: "bg-gray-2 border-gray-5 text-gray-12",
dark: "hover:bg-gray-11-50 bg-gray-12 dark-button-border dark-button-shadow text-gray-1 border-gray-5",
+ light: "bg-gray-1 transition-all duration-200 data-[state=open]:ring-offset-2 data-[state=open]:ring-gray-10 ring-transparent ring-offset-gray-3 text-gray-12 border-gray-5",
gray: "bg-gray-5 text-gray-12 border-gray-5",
transparent:
"bg-transparent hover:bg-gray-3 text-gray-12 border-transparent",
@@ -85,6 +89,7 @@ const selectItemVariants = cva(
variant: {
default: "text-gray-12 hover:bg-gray-3 focus:bg-gray-3",
dark: "text-gray-1 hover:text-gray-12 focus:text-gray-12 hover:bg-gray-1 focus:bg-gray-1",
+ light: "text-gray-12 hover:text-gray-12 hover:bg-gray-3 focus:bg-gray-3",
gray: "text-gray-12 hover:text-gray-12 hover:bg-gray-6 focus:bg-gray-6",
transparent:
"text-gray-12 hover:text-gray-12 hover:bg-gray-3 focus:bg-gray-3",
@@ -98,6 +103,7 @@ function Select({
variant = "default",
size = "default",
options,
+ icon,
placeholder,
onValueChange,
value,
@@ -108,11 +114,13 @@ function Select({
options: {
value: string;
label: string;
+ icon?: React.ReactNode;
image?: React.ReactNode;
}[];
onValueChange: (value: string) => void;
placeholder: string;
- size?: "default" | "fit";
+ size?: Size;
+ icon?: React.ReactNode;
}) {
return (
<SelectRoot
@@ -121,14 +129,14 @@ function Select({
data-slot="select"
{...props}
>
- <SelectTrigger variant={variant} size={size} className={className}>
+ <SelectTrigger variant={variant} size={size} className={className} icon={icon}>
<SelectValue className="text-sm" placeholder={placeholder} />
</SelectTrigger>
- <SelectContent className="mt-2" variant={variant}>
+ <SelectContent variant={variant}>
{options.map((option) => (
- <SelectItem key={option.value} value={option.value}>
- <div className="flex gap-2 items-center">
- {option.image}
+ <SelectItem key={option.value} value={option.value} icon={option.icon}>
+ <div className="flex items-center">
+ {option.image && option.image}
{option.label}
</div>
</SelectItem>
@@ -158,14 +166,23 @@ function SelectValue({
function SelectTrigger({
className,
+ icon,
size = "default",
variant = "default",
children,
...props
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
- size?: "default" | "fit";
+ size?: Size;
variant?: SelectVariant;
+ icon?: React.ReactNode;
}) {
+ const iconSizeVariant = {
+ default: "size-2.5",
+ fit: "size-2",
+ sm: "size-2",
+ md: "size-3",
+ lg: "size-3",
+ }
return (
<SelectPrimitive.Trigger
data-slot="select-trigger"
@@ -173,9 +190,10 @@ function SelectTrigger({
className={cx(selectTriggerVariants({ size, variant }), className)}
{...props}
>
+ {icon && React.cloneElement(icon as React.ReactElement<{ className: string }>, { className: cx(iconSizeVariant[size], "text-gray-9") })}
{children}
<SelectPrimitive.Icon asChild>
- <ChevronDownIcon className="opacity-50 size-4" />
+ <ChevronDownIcon className="opacity-50 size-4 caret-icon" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
);
@@ -186,6 +204,7 @@ function SelectContent({
children,
position = "popper",
variant = "default",
+ sideOffset = 4,
...props
}: React.ComponentProps<typeof SelectPrimitive.Content> & {
variant?: SelectVariant;
@@ -196,6 +215,7 @@ function SelectContent({
data-slot="select-content"
className={cx(selectContentVariants({ variant }), className)}
position={position}
+ sideOffset={sideOffset}
{...props}
>
<SelectScrollUpButton />
@@ -232,8 +252,11 @@ function SelectLabel({
function SelectItem({
className,
children,
+ icon,
...props
-}: React.ComponentProps<typeof SelectPrimitive.Item>) {
+}: React.ComponentProps<typeof SelectPrimitive.Item> & {
+ icon?: React.ReactNode;
+}) {
const variant = React.useContext(SelectVariantContext);
return (
@@ -242,12 +265,16 @@ function SelectItem({
className={cx(selectItemVariants({ variant }), className)}
{...props}
>
+
<span className="absolute right-2 flex size-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<CheckIcon className="size-4" />
</SelectPrimitive.ItemIndicator>
</span>
+ <div className="flex justify-between items-center w-full">
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
+ {icon && React.cloneElement(icon as React.ReactElement<{ className: string }>, { className: cx("size-3", "text-gray-9") })}
+ </div>
</SelectPrimitive.Item>
);
}