Skip to content

Commit

Permalink
add radix ui + comboBox component
Browse files Browse the repository at this point in the history
  • Loading branch information
avalos010 committed Oct 24, 2024
1 parent 6d1f679 commit 73496c9
Show file tree
Hide file tree
Showing 13 changed files with 1,144 additions and 12 deletions.
20 changes: 20 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.js",
"css": "src/app/globals.css",
"baseColor": "zinc",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
}
}
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
},
"dependencies": {
"@heroicons/react": "^2.0.18",
"@radix-ui/react-dialog": "^1.1.2",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-popover": "^1.1.2",
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"cmdk": "1.0.0",
"cypress": "^13.13.2",
"eslint": "^9.8.0",
"eslint-config-next": "^14.2.5",
"lucide-react": "^0.451.0",
"next": "^14.2.5",
"react": "18.3.1",
"react-dom": "18.3.1",
"swr": "^2.1.5",
"tailwind-merge": "^2.5.3",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.1.3"
},
"devDependencies": {
Expand Down
63 changes: 63 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
:root {
--background: 0 0% 100%;
--foreground: 240 10% 3.9%;
--card: 0 0% 100%;
--card-foreground: 240 10% 3.9%;
--popover: 0 0% 100%;
--popover-foreground: 240 10% 3.9%;
--primary: 240 5.9% 10%;
--primary-foreground: 0 0% 98%;
--secondary: 240 4.8% 95.9%;
--secondary-foreground: 240 5.9% 10%;
--muted: 240 4.8% 95.9%;
--muted-foreground: 240 3.8% 46.1%;
--accent: 240 4.8% 95.9%;
--accent-foreground: 240 5.9% 10%;
--destructive: 0 84.2% 60.2%;
--destructive-foreground: 0 0% 98%;
--border: 240 5.9% 90%;
--input: 240 5.9% 90%;
--ring: 240 10% 3.9%;
--chart-1: 12 76% 61%;
--chart-2: 173 58% 39%;
--chart-3: 197 37% 24%;
--chart-4: 43 74% 66%;
--chart-5: 27 87% 67%;
--radius: 0.5rem
}
.dark {
--background: 240 10% 3.9%;
--foreground: 0 0% 98%;
--card: 240 10% 3.9%;
--card-foreground: 0 0% 98%;
--popover: 240 10% 3.9%;
--popover-foreground: 0 0% 98%;
--primary: 0 0% 98%;
--primary-foreground: 240 5.9% 10%;
--secondary: 240 3.7% 15.9%;
--secondary-foreground: 0 0% 98%;
--muted: 240 3.7% 15.9%;
--muted-foreground: 240 5% 64.9%;
--accent: 240 3.7% 15.9%;
--accent-foreground: 0 0% 98%;
--destructive: 0 62.8% 30.6%;
--destructive-foreground: 0 0% 98%;
--border: 240 3.7% 15.9%;
--input: 240 3.7% 15.9%;
--ring: 240 4.9% 83.9%;
--chart-1: 220 70% 50%;
--chart-2: 160 60% 45%;
--chart-3: 30 80% 55%;
--chart-4: 280 65% 60%;
--chart-5: 340 75% 55%
}
}
@layer base {
* {
@apply border-border;
}
body {
@apply bg-background text-foreground;
}
}
19 changes: 19 additions & 0 deletions src/app/odds/playerProps/ComboBoxClient.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ComboBox from "@/components/ComboBox";
import React from "react";

interface ComboBoxClientProps {
marketsList: {
label: string;
value: string;
}[];
handlePropSelect: (value: string) => void;
}

function ComboBoxClient({
marketsList,
handlePropSelect,
}: ComboBoxClientProps) {
return <ComboBox list={marketsList} onSelect={handlePropSelect} />;
}

export default ComboBoxClient;
25 changes: 17 additions & 8 deletions src/app/odds/playerProps/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getPlayerProps } from "../../../../lib/api";
import markets from "../../../../lib/playerPropMarkets.json";
import ComboBoxClient from "./ComboBoxClient";

interface PlayerPropsParams {
searchParams: {
Expand All @@ -14,19 +15,27 @@ const playerProps = async ({ searchParams }: PlayerPropsParams) => {
const supportedMarkets = markets[league as keyof typeof markets];

if (supportedMarkets) {
const props = getPlayerProps(sport, eventId);
return (
<div>
<h1>Player Props real</h1>
</div>
);
} else {
// const props = getPlayerProps(sport, eventId);
const marketsList = Object.entries(supportedMarkets).map((market) => ({
//TODO! Get rid of this and just use object btacket notation to do something simpler.
label: market[1],
value: market[0],
}));

//TODO!: Broken. will fix it soon. Hint use URL query parameters when selecting a player prop.
// return <ComboBoxClient marketsList={marketsList} />;
return (
<div>
<h2>Player Props for this league not supported!</h2>
<p>Player props available</p>
</div>
);
}

return (
<div>
<p>Player props not supported</p>
</div>
);
};

export default playerProps;
96 changes: 96 additions & 0 deletions src/components/ComboBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"use client";

import { Button } from "@/components/ui/button";
import {
Command,
CommandEmpty,
CommandGroup,
CommandInput,
CommandItem,
CommandList,
} from "@/components/ui/command";
import {
Popover,
PopoverContent,
PopoverTrigger,
} from "@/components/ui/popover";
import { useState } from "react";

const frameworks = [
{
value: "next.js",
label: "Next.js",
},
{
value: "sveltekit",
label: "SvelteKit",
},
{
value: "nuxt.js",
label: "Nuxt.js",
},
{
value: "remix",
label: "Remix",
},
{
value: "astro",
label: "Astro",
},
];

interface listItem {
value: string;
label: string;
}

interface ComboBoxProps {
list: listItem[];
onSelect: (value: string) => void;
}

export function ComboBox({ list, onSelect }: ComboBoxProps) {
const [open, setOpen] = useState(false);
const [value, setValue] = useState("");

return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<Button
variant="outline"
role="combobox"
aria-expanded={open}
className="w-[200px] justify-between"
>
{value
? list.find((item) => item.value === value)?.label
: "Select item..."}
</Button>
</PopoverTrigger>
<PopoverContent className="w-[200px] p-0">
<Command>
{/* <CommandInput placeholder="Search framework..." /> */}
<CommandList>
<CommandEmpty>No framework found.</CommandEmpty>
<CommandGroup>
{list.map((item) => (
<CommandItem
key={item.value}
value={item.value}
onSelect={(currentValue) => {
setValue(currentValue === value ? "" : currentValue);
setOpen(false);
}}
>
{item.label}
</CommandItem>
))}
</CommandGroup>
</CommandList>
</Command>
</PopoverContent>
</Popover>
);
}

export default ComboBox;
57 changes: 57 additions & 0 deletions src/components/ui/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as React from "react"
import { Slot } from "@radix-ui/react-slot"
import { cva, type VariantProps } from "class-variance-authority"

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

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
{
variants: {
variant: {
default:
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
destructive:
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
outline:
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
secondary:
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
ghost: "hover:bg-accent hover:text-accent-foreground",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2",
sm: "h-8 rounded-md px-3 text-xs",
lg: "h-10 rounded-md px-8",
icon: "h-9 w-9",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)

export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}

const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : "button"
return (
<Comp
className={cn(buttonVariants({ variant, size, className }))}
ref={ref}
{...props}
/>
)
}
)
Button.displayName = "Button"

export { Button, buttonVariants }
Loading

0 comments on commit 73496c9

Please sign in to comment.