Skip to content

new conf design — button #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"typescript.tsdk": "node_modules/typescript/lib",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"tailwindCSS.classFunctions": ["clsx"]
}
1 change: 1 addition & 0 deletions src/app/conf/_design-system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UI from 2025's designs
42 changes: 42 additions & 0 deletions src/app/conf/_design-system/anchor.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ForwardedRef, forwardRef, ReactElement } from "react"
import NextLink from "next/link"
import type { LinkProps as NextLinkProps } from "next/link"

// eslint-disable-next-line @typescript-eslint/no-namespace
export declare namespace AnchorProps {
interface IntrinsicAnchorProps
extends React.DetailedHTMLProps<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
> {
href: `#${string}` | `http${string}`
}

interface InternalAnchorProps extends NextLinkProps {}
}

export type AnchorProps =
| AnchorProps.IntrinsicAnchorProps
| AnchorProps.InternalAnchorProps

export const Anchor = forwardRef(function Anchor(
props: AnchorProps,
ref: ForwardedRef<HTMLAnchorElement>,
) {
return isInternal(props) ? (
<NextLink {...props} ref={ref} />
) : (
<a ref={ref} rel="noopener noreferrer" target="_blank" {...props} />
)
}) as (props: AnchorProps) => ReactElement

function isInternal(
props: AnchorProps,
): props is AnchorProps.InternalAnchorProps {
return (
typeof props.href === "object" ||
(typeof props.href === "string" &&
!props.href.startsWith("http") &&
!props.href.startsWith("#"))
)
}
92 changes: 92 additions & 0 deletions src/app/conf/_design-system/button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { clsx } from "clsx"
import { Anchor } from "./anchor"

type Size = "md" | "lg"
type Variant = "primary" | "secondary"

// eslint-disable-next-line @typescript-eslint/no-namespace
export declare namespace ButtonProps {
export interface BaseProps {
size?: Size
variant?: Variant
}

export interface AnchorProps
extends BaseProps,
React.DetailedHTMLProps<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
HTMLAnchorElement
> {
href: string
as?: never
className?: string
}

export interface ButtonProps
extends BaseProps,
React.DetailedHTMLProps<
React.ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
> {
href?: never
as?: never
className?: string
disabled?: boolean
type?: "button" | "submit" | "reset"
onClick?: React.MouseEventHandler<HTMLButtonElement>
}

/**
* Use inside `<summary>` or as visual part of bigger interactive element.
* Prefer `a` and `button` Buttons otherwise.
*/
export interface NonInteractiveProps
extends BaseProps,
React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement> {
href?: never
as: "span" | "div"
className?: string
}
}

export type ButtonProps =
| ButtonProps.AnchorProps
| ButtonProps.ButtonProps
| ButtonProps.NonInteractiveProps

export function Button(props: ButtonProps) {
const className = clsx(
"relative flex items-center justify-center gap-2.5 font-normal text-base/none text-neu-0 bg-neu-900 hover:bg-neu-800 active:bg-neu-700 font-sans h-14 px-8 data-[size=md]:h-12 data-[variant=secondary]:bg-neu-100 data-[variant=secondary]:text-neu-900 dark:data-[variant=secondary]:text-neu-0 data-[variant=secondary]:hover:bg-neu-200/75 data-[variant=secondary]:active:bg-neu-200/90",
props.className,
)

const styleAttrs = { "data-size": props.size, "data-variant": props.variant }

if ("href" in props && typeof props.href === "string") {
const { className: _1, size: _2, children, ...rest } = props

return (
<Anchor className={className} {...styleAttrs} {...rest}>
{children}
</Anchor>
)
}

if (props.as) {
const { className: _1, size: _2, children, as, ...rest } = props
const Root = as as "span" // we don't need HTMLDivElement type
return (
<Root className={className} {...styleAttrs} {...rest}>
{children}
</Root>
)
}

const { className: _1, size: _2, children, ...rest } = props

return (
<button className={className} {...styleAttrs} {...rest}>
{children}
</button>
)
}