Skip to content

Commit

Permalink
Merge pull request #53 from CalvinWalzel/v2/layout-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinWalzel authored Sep 22, 2024
2 parents 79c8ebd + b6a78ce commit 1a9d3ec
Show file tree
Hide file tree
Showing 14 changed files with 264 additions and 67 deletions.
6 changes: 5 additions & 1 deletion app/frontend/components/data_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@ import {
TableRow,
} from "@/components/ui/table";

import { cn } from "@/utils/ui";

interface DataTableProps<TData, TValue> {
columns: ColumnDef<TData, TValue>[];
data: TData[];
pagination: PaginatorProps;
className?: string;
}

export function DataTable<TData, TValue>({
columns,
data,
pagination,
className,
}: DataTableProps<TData, TValue>) {
const table = useReactTable({
data,
Expand All @@ -38,7 +42,7 @@ export function DataTable<TData, TValue>({

return (
<>
<div className="rounded-md border">
<div className={cn(className)}>
<Table>
<TableHeader>
{table.getHeaderGroups().map((headerGroup) => (
Expand Down
28 changes: 19 additions & 9 deletions app/frontend/components/external_link.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import { Link, type LucideProps } from "lucide-react";
import { Link as LinkIcon, type LucideProps } from "lucide-react";

import { Button } from "@/components/ui/button";

import { cn } from "@/utils/ui";

interface Props {
href: string;
children: React.ReactNode;
icon?: React.ForwardRefExoticComponent<
Omit<LucideProps, "ref"> & React.RefAttributes<SVGSVGElement>
>;
> | null;
className?: string;
}

function ExternalLink({ href, children, icon }: Props) {
const Icon = icon || Link;
function ExternalLink({ href, children, icon, className }: Props) {
const Icon = icon || LinkIcon;

return (
<div className="flex items-center">
<Icon className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400" />
<a href={href} target="_blank" rel="noopener noreferrer">
{children}
</a>
<div className={cn("inline-flex items-center", className)}>
{icon !== null && (
<Icon className="mr-0.5 h-5 w-5 flex-shrink-0 text-gray-400" />
)}

<Button variant="link" asChild className="px-0 py-0">
<a href={href} target="_blank" rel="noopener noreferrer">
{children}
</a>
</Button>
</div>
);
}
Expand Down
15 changes: 15 additions & 0 deletions app/frontend/components/link.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Link as InertiaLink, InertiaLinkProps } from "@inertiajs/react";

import { Button } from "@/components/ui/button";

interface Props extends InertiaLinkProps {}

function Link({ children, ...props }: Props) {
return (
<Button variant="link" asChild className="px-0 py-0">
<InertiaLink {...props}>{children}</InertiaLink>
</Button>
);
}

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

import { cn } from "@/utils/ui"
import { cn } from "@/utils/ui";

const buttonVariants = cva(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50",
Expand Down Expand Up @@ -30,27 +30,27 @@ const buttonVariants = cva(
variant: "default",
size: "default",
},
}
)
},
);

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

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

export { Button, buttonVariants }
export { Button, buttonVariants };
88 changes: 88 additions & 0 deletions app/frontend/components/ui/card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import * as React from "react";

import { cn } from "@/utils/ui";

const Card = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
className,
)}
{...props}
/>
));
Card.displayName = "Card";

const CardHeader = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex flex-col space-y-1.5 p-6", className)}
{...props}
/>
));
CardHeader.displayName = "CardHeader";

const CardTitle = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLHeadingElement>
>(({ className, children, ...props }, ref) => (
<h3
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
className,
)}
{...props}
>
{children}
</h3>
));
CardTitle.displayName = "CardTitle";

const CardDescription = React.forwardRef<
HTMLParagraphElement,
React.HTMLAttributes<HTMLParagraphElement>
>(({ className, ...props }, ref) => (
<p
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
));
CardDescription.displayName = "CardDescription";

const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
));
CardContent.displayName = "CardContent";

const CardFooter = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div
ref={ref}
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
));
CardFooter.displayName = "CardFooter";

export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardDescription,
CardContent,
};
16 changes: 8 additions & 8 deletions app/frontend/components/ui/input.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react"
import * as React from "react";

import { cn } from "@/utils/ui"
import { cn } from "@/utils/ui";

export interface InputProps
extends React.InputHTMLAttributes<HTMLInputElement> {}
Expand All @@ -12,14 +12,14 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
type={type}
className={cn(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
className,
)}
ref={ref}
{...props}
/>
)
}
)
Input.displayName = "Input"
);
},
);
Input.displayName = "Input";

export { Input }
export { Input };
18 changes: 9 additions & 9 deletions app/frontend/components/ui/separator.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from "react"
import * as SeparatorPrimitive from "@radix-ui/react-separator"
import * as SeparatorPrimitive from "@radix-ui/react-separator";
import * as React from "react";

import { cn } from "@/utils/ui"
import { cn } from "@/utils/ui";

const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(
(
{ className, orientation = "horizontal", decorative = true, ...props },
ref
ref,
) => (
<SeparatorPrimitive.Root
ref={ref}
Expand All @@ -18,12 +18,12 @@ const Separator = React.forwardRef<
className={cn(
"shrink-0 bg-border",
orientation === "horizontal" ? "h-[1px] w-full" : "h-full w-[1px]",
className
className,
)}
{...props}
/>
)
)
Separator.displayName = SeparatorPrimitive.Root.displayName
),
);
Separator.displayName = SeparatorPrimitive.Root.displayName;

export { Separator }
export { Separator };
16 changes: 12 additions & 4 deletions app/frontend/entrypoints/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,24 @@ import { createRoot } from "react-dom/client";

import NotFoundPage from "@/pages/errors/not_found";

import Layout from "@/layouts/application";
import "@/stylesheets/globals.css";

createInertiaApp({
resolve: (name) => {
const pages = import.meta.glob("../pages/**/*.tsx", { eager: true });
const page = pages[`../pages/${name}.tsx`];
const pages = import.meta.glob("../pages/**/*.tsx", {
eager: true,
});
const page = pages[`../pages/${name}.tsx`] as any;

if (page) return page;
if (!page) {
return { default: NotFoundPage };
}

return NotFoundPage;
page.default.layout =
page.default.layout || ((page: any) => <Layout>{page}</Layout>);

return page;
},
setup({ el, App, props }) {
createRoot(el).render(
Expand Down
1 change: 1 addition & 0 deletions app/frontend/images/brands/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/frontend/layouts/application.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import Footer from "@/layouts/application/footer";

interface Props {
children: React.ReactNode;
}

function Layout({ children }: Props) {
return (
<div className="min-h-screen bg-gray-100">
<header className="bg-white shadow">
<div className="container mx-auto py-6">
<h1 className="text-3xl font-bold text-red-600">Ruby Companies</h1>
</div>
</header>
<main>
<div className="container mx-auto pt-5 pb-10">{children}</div>
</main>
<Footer />
</div>
);
}

Layout.displayName = "layouts/application";

export default Layout;
46 changes: 46 additions & 0 deletions app/frontend/layouts/application/footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import ExternalLink from "@/components/external_link";
import { Button } from "@/components/ui/button";

import githubImage from "@/images/brands/github.svg";

function Footer() {
return (
<footer className="bg-background border-t">
<div className="container mx-auto py-4 px-4 sm:px-6 lg:px-8">
<div className="flex flex-col sm:flex-row justify-between items-start sm:items-center space-y-4 sm:space-y-0">
<div className="flex flex-row items-center space-x-2">
<Button variant="ghost" size="icon" asChild className="p-0 h-auto">
<a
href="https://github.com/CalvinWalzel/ruby-companies"
target="_blank"
rel="noopener noreferrer"
>
<img src={githubImage} alt="GitHub" className="w-5 h-5 m-0" />
<span className="sr-only">GitHub repository</span>
</a>
</Button>
<div className="text-sm text-muted-foreground">
created by Calvin Walzel & Gitta van der Pol
</div>
</div>
<div className="flex items-center space-x-4">
<span className="text-sm text-muted-foreground flex items-center">
sponsored by{" "}
<ExternalLink
href="https://avohq.io"
className="ml-1"
icon={null}
>
AvoHQ
</ExternalLink>
</span>
</div>
</div>
</div>
</footer>
);
}

Footer.displayName = "layouts/application/footer";

export default Footer;
Loading

0 comments on commit 1a9d3ec

Please sign in to comment.