Migrate to npm-workspaces monorepo (#294)
* spec update * update md files * add plan: monorepo * feat: add empty apps and packages directories * Add shared tsconfig.base.json * feat add workspaces * feat: move hudozka-writer into apps/ * feat: move migrate-to-pocketbase into apps/ * feat: split package.json for apps/hudozka workspace * feat: extend tsconfig.base.json in apps/hudozka * add dockerfile path * feat: verify Phase 3 monorepo migration of Next app * feat: scaffold @hudozka/utils package * feat: add utils barrel export * feat: extract utilities into hudozka-utils package * feat: extract hooks into hudozka-hooks package * Extract Box/Button/Panel/Title/Overlay into @hudozka/ui * Scope Next ESLint rules to apps/hudozka in root flat config * Update README and CLAUDE.md for monorepo layout * disable image optimisation
This commit is contained in:
1 parent
0665fa7ae7
commit
f874b58dd9
258 files changed
+3793
-214
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { render, screen } from "@testing-library/react"
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { Box } from "."
|
||||
|
||||
describe("Box", () => {
|
||||
it("renders children", () => {
|
||||
render(<Box>hello</Box>)
|
||||
expect(screen.getByText("hello")).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it("defaults to a div tag", () => {
|
||||
render(<Box>content</Box>)
|
||||
expect(screen.getByText("content").tagName).toBe("DIV")
|
||||
})
|
||||
|
||||
it("renders as a custom tag via the as prop", () => {
|
||||
render(<Box as="section">section content</Box>)
|
||||
expect(screen.getByText("section content").tagName).toBe("SECTION")
|
||||
})
|
||||
|
||||
it("applies vertical class", () => {
|
||||
const { container } = render(<Box vertical>v</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/vertical/)
|
||||
})
|
||||
|
||||
it("applies center class", () => {
|
||||
const { container } = render(<Box center>c</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/center/)
|
||||
})
|
||||
|
||||
it("applies wrap class", () => {
|
||||
const { container } = render(<Box wrap>w</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/wrap/)
|
||||
})
|
||||
|
||||
it("passes gap to inline style", () => {
|
||||
const { container } = render(<Box gap={8}>g</Box>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el).toHaveStyle({ gap: "8px" })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
.box {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
flex-wrap: nowrap;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.box.align {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.box.wrap {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.box.center {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.box.vertical {
|
||||
flex-direction: column;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import s from "./box.module.css"
|
||||
|
||||
import classnames from "classnames/bind"
|
||||
import { createElement } from "react"
|
||||
|
||||
const cx = classnames.bind(s)
|
||||
|
||||
export type BoxProps = {
|
||||
as?: keyof HTMLElementTagNameMap
|
||||
children?: React.ReactNode
|
||||
className?: string
|
||||
style?: React.CSSProperties
|
||||
wrap?: boolean
|
||||
align?: boolean
|
||||
vertical?: boolean
|
||||
center?: boolean
|
||||
gap?: number | string
|
||||
}
|
||||
|
||||
export const Box: React.FC<BoxProps> = ({
|
||||
as = "div",
|
||||
wrap = false,
|
||||
vertical = false,
|
||||
center = false,
|
||||
align = true,
|
||||
style,
|
||||
gap,
|
||||
className,
|
||||
...props
|
||||
}) => {
|
||||
const newProps = {
|
||||
className: cx(className, s.box, { vertical, align, center, wrap }),
|
||||
style: {
|
||||
...style,
|
||||
gap,
|
||||
},
|
||||
}
|
||||
|
||||
return createElement(as, newProps, props.children)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import { render, screen, fireEvent } from "@testing-library/react"
|
||||
import { describe, it, expect, vi } from "vitest"
|
||||
import { Button } from "."
|
||||
|
||||
describe("Button", () => {
|
||||
it("renders children in a button element", () => {
|
||||
render(<Button>Click me</Button>)
|
||||
const button = screen.getByRole("button", { name: "Click me" })
|
||||
expect(button).toBeInTheDocument()
|
||||
expect(button.tagName).toBe("BUTTON")
|
||||
})
|
||||
|
||||
it("renders as a link when href is provided", () => {
|
||||
render(<Button href="/about">About</Button>)
|
||||
const link = screen.getByRole("link", { name: "About" })
|
||||
expect(link).toBeInTheDocument()
|
||||
expect(link).toHaveAttribute("href", "/about")
|
||||
})
|
||||
|
||||
it("calls onClick with value when clicked", () => {
|
||||
const onClick = vi.fn()
|
||||
render(<Button value="test-value" onClick={onClick}>Click</Button>)
|
||||
fireEvent.click(screen.getByRole("button", { name: "Click" }))
|
||||
expect(onClick).toHaveBeenCalledOnce()
|
||||
expect(onClick).toHaveBeenCalledWith("test-value", expect.anything())
|
||||
})
|
||||
|
||||
it("calls onClick with undefined when no value is provided", () => {
|
||||
const onClick = vi.fn()
|
||||
render(<Button onClick={onClick}>Press</Button>)
|
||||
fireEvent.click(screen.getByRole("button", { name: "Press" }))
|
||||
expect(onClick).toHaveBeenCalledOnce()
|
||||
expect(onClick).toHaveBeenCalledWith(undefined, expect.anything())
|
||||
})
|
||||
|
||||
it("applies disabled class when disabled is true", () => {
|
||||
const { container } = render(<Button disabled>Disabled</Button>)
|
||||
expect(container.firstElementChild!.className).toMatch(/disabled/)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,60 @@
|
||||
.button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
|
||||
font-size: var(--font-size-default);
|
||||
|
||||
text-align: center;
|
||||
|
||||
border-radius: var(--size-s);
|
||||
border: 1px solid var(--color-shadow);
|
||||
|
||||
color: var(--color-text);
|
||||
background-color: var(--color-back);
|
||||
box-shadow: none;
|
||||
transition: box-shadow 200ms ease-in, background-color 200ms ease-in;
|
||||
|
||||
outline: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
border-color: rgba(0, 0, 0, 0);
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
/* MODIFICATORS */
|
||||
|
||||
.disabled {
|
||||
pointer-events: none;
|
||||
color: var(--color-text-second);
|
||||
}
|
||||
|
||||
/* SIZE */
|
||||
|
||||
.sizeDefault {
|
||||
padding: var(--size-s) var(--size-m);
|
||||
}
|
||||
|
||||
.sizeSmall {
|
||||
padding: var(--size-xs) var(--size-s);
|
||||
font-size: var(--font-size-second);
|
||||
}
|
||||
|
||||
/* THEME */
|
||||
|
||||
.themeGhost {
|
||||
border-color: rgba(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
.themeIcon {
|
||||
border-color: rgba(0, 0, 0, 0);
|
||||
padding: var(--size-xs) var(--size-xs);
|
||||
}
|
||||
|
||||
/* DARK THEME */
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.button:hover {
|
||||
background-color: var(--color-back-active);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
import s from "./button.module.css"
|
||||
|
||||
import Link from "next/link"
|
||||
import cx from "classnames"
|
||||
import { useCallback } from "react"
|
||||
import type { MouseEvent, MouseEventHandler } from "react"
|
||||
|
||||
const sizeClass = {
|
||||
default: s.sizeDefault,
|
||||
small: s.sizeSmall,
|
||||
}
|
||||
|
||||
const themeClass = {
|
||||
default: "",
|
||||
icon: s.themeIcon,
|
||||
ghost: s.themeGhost,
|
||||
}
|
||||
|
||||
export type ButtonProps = {
|
||||
children?: React.ReactNode
|
||||
value?: string
|
||||
style?: React.CSSProperties
|
||||
href?: string
|
||||
theme?: "default" | "ghost" | "icon"
|
||||
size?: "default" | "small"
|
||||
disabled?: boolean
|
||||
onClick?: (value: string | undefined, event: MouseEvent) => void
|
||||
}
|
||||
|
||||
export const Button: React.FC<ButtonProps> = ({ size = "default", theme = "default", disabled = false, ...props }) => {
|
||||
const className = cx(s.button, sizeClass[size], themeClass[theme], {
|
||||
[s.disabled]: disabled,
|
||||
})
|
||||
const onClick = useCallback<MouseEventHandler<HTMLButtonElement>>(event => {
|
||||
if (typeof props.onClick === "function") {
|
||||
props.onClick(props.value, event)
|
||||
}
|
||||
}, [props])
|
||||
|
||||
if (props.href) {
|
||||
return (
|
||||
<Link href={props.href} className={className} style={props.style}>
|
||||
{props.children}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
className={className}
|
||||
style={props.style}
|
||||
onClick={onClick}
|
||||
>
|
||||
{props.children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||
|
||||
export type TransitionProps = {
|
||||
children?: React.ReactNode
|
||||
duration: number
|
||||
extraStyle?: React.CSSProperties
|
||||
show: boolean
|
||||
}
|
||||
|
||||
export function Transition(props: TransitionProps) {
|
||||
const [mounted, setMounted] = useState(props.show)
|
||||
const [opacity, setOpacity] = useState(0)
|
||||
const timerRef = useRef<ReturnType<typeof setTimeout>>(null)
|
||||
|
||||
const onTransitionEnd = useCallback(() => {
|
||||
if (opacity === 0) {
|
||||
setMounted(false)
|
||||
}
|
||||
}, [opacity])
|
||||
const transition = useMemo(
|
||||
() => `all ${props.duration}ms`,
|
||||
[props.duration],
|
||||
)
|
||||
|
||||
if (props.show && !mounted) {
|
||||
setMounted(true)
|
||||
}
|
||||
|
||||
if (!props.show && opacity !== 0) {
|
||||
setOpacity(0)
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.show) {
|
||||
return
|
||||
}
|
||||
|
||||
timerRef.current = setTimeout(() => {
|
||||
setOpacity(1)
|
||||
}, 16)
|
||||
|
||||
return () => {
|
||||
if (timerRef.current) {
|
||||
clearTimeout(timerRef.current)
|
||||
}
|
||||
}
|
||||
}, [props.show])
|
||||
|
||||
if (!mounted) {
|
||||
return null
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
...props.extraStyle,
|
||||
opacity,
|
||||
transition,
|
||||
}}
|
||||
onTransitionEnd={onTransitionEnd}
|
||||
>
|
||||
{props.children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import s from "./styles.module.css"
|
||||
|
||||
import { Transition } from "./Transition"
|
||||
import { useLockBodyScroll, useReducedMotion } from "@hudozka/hooks"
|
||||
|
||||
export type OverlayProps = {
|
||||
children?: React.ReactNode
|
||||
show: boolean
|
||||
onClickOverlay: () => void
|
||||
style?: React.CSSProperties
|
||||
duration: number
|
||||
}
|
||||
|
||||
export const Overlay: React.FC<OverlayProps> = props => {
|
||||
const motionDisabled = useReducedMotion()
|
||||
const duration = motionDisabled ? 0 : props.duration
|
||||
|
||||
useLockBodyScroll(props.show)
|
||||
|
||||
return (
|
||||
<Transition
|
||||
duration={duration}
|
||||
show={props.show}
|
||||
>
|
||||
<div
|
||||
onClick={(event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
props.onClickOverlay()
|
||||
}
|
||||
}}
|
||||
className={s.overlay}
|
||||
style={props.style}
|
||||
>
|
||||
{props.children}
|
||||
</div>
|
||||
</Transition>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
.overlay {
|
||||
position: fixed;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
top: 0;
|
||||
left: 0;
|
||||
overflow-y: auto;
|
||||
z-index: 1000000;
|
||||
|
||||
background-color: var(--color-back-main);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { render } from "@testing-library/react"
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { Panel } from "."
|
||||
|
||||
describe("Panel", () => {
|
||||
it("renders children", () => {
|
||||
const { container } = render(<Panel>hello</Panel>)
|
||||
expect(container).toHaveTextContent("hello")
|
||||
})
|
||||
|
||||
it("applies the default variant class", () => {
|
||||
const { container } = render(<Panel>content</Panel>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/default/)
|
||||
})
|
||||
|
||||
it("applies the ghost variant class when ghost is true", () => {
|
||||
const { container } = render(<Panel ghost>content</Panel>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toMatch(/ghost/)
|
||||
expect(el.className).not.toMatch(/default/)
|
||||
})
|
||||
|
||||
it("forwards a custom className", () => {
|
||||
const { container } = render(<Panel className="custom">content</Panel>)
|
||||
const el = container.firstElementChild!
|
||||
expect(el.className).toContain("custom")
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,25 @@
|
||||
import s from "./panel.module.css"
|
||||
|
||||
import { Box } from "../Box"
|
||||
|
||||
export type PanelProps = {
|
||||
children?: React.ReactNode
|
||||
style?: React.CSSProperties
|
||||
className?: string
|
||||
ghost?: boolean
|
||||
}
|
||||
|
||||
export function Panel({
|
||||
style,
|
||||
className,
|
||||
children,
|
||||
ghost = false,
|
||||
}: PanelProps) {
|
||||
const variant = ghost ? s.ghost : s.default
|
||||
|
||||
return (
|
||||
<Box vertical align={false} className={`${s.panel} ${variant}${className ? ` ${className}` : ""}`} style={style}>
|
||||
{children}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
.panel {
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.default {
|
||||
padding: var(--size-m);
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.ghost {
|
||||
background-color: none;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { createElement } from "react"
|
||||
|
||||
export type TitleProps = {
|
||||
level?: 1 | 2 | 3 | 4 | 5 | 6
|
||||
children?: React.ReactNode
|
||||
className?: string
|
||||
style?: React.CSSProperties
|
||||
}
|
||||
|
||||
export const Title: React.FC<TitleProps> = ({ level = 1, children, ...props }) => {
|
||||
return createElement(`h${level}`, props, children)
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from "./Box"
|
||||
export * from "./Button"
|
||||
export * from "./Panel"
|
||||
export * from "./Title"
|
||||
export * from "./Overlay"
|
||||
Reference in new issue
Block a user