# @yasinsensoy/web 0.1.0 Fast, dependency-free React and Next.js component library built on Tailwind CSS v4. Component library for React and Next.js. Works with Tailwind CSS v4, has no runtime dependencies, and ships mobile behaviors and accessibility built in. ## Installation ```sh pnpm add @yasinsensoy/web ``` The project's main CSS file: ```css @import "tailwindcss"; @import "@yasinsensoy/web/styles.css"; ``` Root layout (Next.js App Router): ```tsx import { ThemeProvider, Toaster } from "@yasinsensoy/web"; import { UIProvider } from "@yasinsensoy/web/next"; export default function RootLayout({ children }: { children: React.ReactNode }) { return ( {children} ); } ``` ## License Free in development (`next dev`, `localhost`); no key is required. In production, if `UIProvider`'s `licenseKey` prop is not given a valid license key, the page is locked behind a "License required" screen. The key works only on the domains it is bound to (set them in the license portal). Do not hard-code the key; read it from an environment variable. ## Language (i18n) The app's translations and the library's own texts ("Close", "Cancel"…) live in one dictionary; keys and `{name}` placeholders are inferred from the type. Setup is three files: ```ts // messages/en.ts — default locale, type source import { defineMessages } from "@yasinsensoy/web"; export default defineMessages({ ui: { cancel: "Dismiss" }, // library text (optional) home: { title: "Welcome, {name}" }, cart: { items: { one: "{count} item", other: "{count} items" } }, }); // messages/tr.ts — a missing key or forgotten {name} is a compile error import { trMessages, type Translation } from "@yasinsensoy/web"; export default { ui: trMessages, // the library's ready Turkish set home: { title: "Hoş geldin, {name}" }, cart: { items: { one: "{count} ürün", other: "{count} ürün" } }, } satisfies Translation; // i18n.ts — not "use client"; shared by server and client import { createI18n } from "@yasinsensoy/web"; import en from "./messages/en"; export const i18n = createI18n({ defaultLocale: "en", locales: { en, tr: () => import("./messages/tr") }, // tr loads when needed }); declare module "@yasinsensoy/web" { interface Register { messages: typeof en } } ``` Usage: ```tsx // app/[lang]/layout.tsx (server) {children} // server component, generateMetadata, route handler, server action const t = await i18n.getT(lang);

{t("home.title", { name })}

// client component const t = useT(); // middleware/proxy: redirect by the browser's language i18n.match(request.headers.get("accept-language")) ``` - Pass translations to props such as `label` and `title` with `t(...)`; a key string (`label="home.title"`) is not translated automatically. - Numbers and dates are formatted per `locale` (`{count}` → `1,234`); the plural form is chosen by the locale's rules. - Each component bundles only its own texts; an app that passes no dictionary gets the Turkish defaults. ## Rules - Import everything from the package root: `import { Button } from "@yasinsensoy/web"`. The package is side-effect free (`sideEffects` is CSS only); bundlers drop unused components, so importing from the root adds no size. The same components are also available from subpaths (`@yasinsensoy/web/button`, `/data-grid`, `/hooks`, `/utils`, `/theme`…); this lets the dev server compile only the files it needs. In Next.js, `experimental.optimizePackageImports: ["@yasinsensoy/web"]` gives the root the same effect. - Heavy parts that only appear on interaction (confirm dialog, the gallery's fullscreen viewer, code languages) load in separate chunks via `import()`; they are not part of the initial page load. - Style with Tailwind classes via `className`. Conflicting classes are merged with `cn` and yours win. - Use theme classes for colors (`bg-primary`, `text-muted-foreground`, `border-border`…); do not hard-code colors. For a new theme, define the `--ui-*` variables. - Components are used through props; no nested parts are written: ``, ``, ``, ``, ``, ``, `await confirm({...})`. Lists are given as an `items` array. - Text props such as `title`, `label` and `description` accept both text and elements. `icon` is either an element (``) or a name in the library given to `UIProvider` via `icons` (`icon="trash"`); names are type-checked via the `Register` interface. - The appearance vocabulary is the same on every component: `tone` is meaning (`primary | neutral | danger | success | warning`), `size` is size (`sm | md | lg`), `variant` is style. On buttons `variant` is `solid | soft | outline | ghost | link | gradient | elevated | dashed` and `shape` is `rounded | pill | sharp`. On form fields `variant` is `outline | filled | underline | ghost`. - **Effects** (`effect`) are the same on every component and combine as an array: on press `scale | ripple | pulse | bounce`; on hover `lift | border | beam | glow | tilt | shine`; `none` turns them off. Buttons, cards, badges, all form fields (`Input`, `Select`, `NumberInput`, `DatePicker`… and the `*Field`s), choice controls, `Tabs`, `Accordion`, `Collapsible`, `Stepper`, `OtpInput`, `Timeline`, `TableOfContents`, `Countdown`, `Rating`, `Menu`/`ContextMenu`, `Sidebar`, `NavigationMenu`, `Breadcrumb`, `TreeView`, `Kanban`, `NotificationCenter`, `FileUpload`, `Image`, `Gallery`, `ColorSwatch`, `Dialog`, `Sheet`, `Popover`, `HoverCard`, `Toaster`, `Fab` accept it. For effects on your own element use `getEffects(["tilt", "glow"])`. - **App-wide appearance is set in one place**; do not repeat it on every component: define it with `defineAppearance({ defaults, effects, variants })` and pass it to `UIProvider appearance={...}`. `defaults` are per-component default `variant`, `effect`, `tone`, `size`, `shape` (the component name starting lowercase: `button`, `card`, `field` (all form fields), `menu`, `dialog`, `tableOfContents`…); `effects` are your own effects (`className`, `press`, `setup`); `variants` are your own styles (`button: { neon: "…classes" }`, `field: { glass: { extends: "filled", className } }`, `extends`, `tones`). Names become type-checked with `Register { appearance: typeof appearance }`. Server components (`Card`, `Badge`) read the settings from the `defineAppearance` registry; import the settings file in the root layout. Floating label: `UIProvider floatingLabel`; field appearance in a container: `data-field-variant="filled"` (all fields in that section). The focus color is the `--ui-field-focus` variable. - For a link write `} onClose={close} /> ``` ### AlertVariant _type_ Style of the alert box. ```ts type AlertVariant = "outline" | "soft" ``` ### AlertClassNames _type_ Classes that can be given to the inner parts of `Alert`. | Property | Type | Default | Description | | --- | --- | --- | --- | | `icon?` | `string` | | Icon box. | | `title?` | `string` | | Title. | | `description?` | `string` | | Description (`children`). | | `action?` | `string` | | Action area. | ### AlertProps _type_ Props of the `Alert` component. Also accepts the properties of: `Omit, "title">` | Property | Type | Default | Description | | --- | --- | --- | --- | | `tone?` | `Tone` | `"neutral"` | Color and default icon. | | `variant?` | `AlertVariant \| CustomVariant<"alert">` | `"outline"` | Style: built-in or a custom style added with `defineAppearance`. Defaults to `UIProvider` `appearance.defaults.alert.variant`. | | `effect?` | `EffectProp` | | Effect or effects (e.g. `"beam"`, `["border", "glow"]`). The accent color comes from `tone`. See `BuiltinEffect`. | | `title?` | `ReactNode` | | Bold title. | | `icon?` | `IconProp` | | Icon left of the title: a name or an element. When omitted an icon matching the color is drawn; hidden with `false`. | | `action?` | `ReactNode` | | Action shown on the right (below on mobile), e.g. a `Button`. | | `onClose?` | `() => void` | | When given, a close (×) button appears at the top right and is called on click. | | `classNames?` | `AlertClassNames` | | Classes added to the inner parts. | ## EffectLayer ### EffectLayer _client component_ Client layer of effects. Placed inside the element with effects and binds listeners to its parent (the owner of the effect); also works inside server components (Card, Badge): - **Pointer tracking** (`glow`, `tilt`, custom effects with `pointer: true`): writes the pointer position to the `--ui-effect-x/y` (pixels) and `--ui-effect-px/py` (-1…1 relative to the center) variables. Light and tilt are drawn entirely in CSS; React doesn't re-render. Writes are reduced to one per frame and, since layers only change `translate`/`transform`, they are composited without painting. No listeners are bound on touch screens; the element doesn't move while scrolling. - **Press** (`ripple`, `pulse`, `bounce`, custom `press`): plays from the pressed point on mouse/touch press and from the center on keyboard. Doesn't play on disabled elements or with the "reduce motion" preference. - **Custom setup** (`setup`): called when the element appears and cleaned up when it is removed. To add effects to your own component, give the element `data-effect` and put this inside it; or use `EffectParts`. The measured box (getBoundingClientRect) changes slightly while the element rotates, so the position is computed from `offsetWidth/Height`, which rotation doesn't affect, and the box center. That way tilt doesn't feed back into the pointer position and jitter. ### EffectParts _server component_ Decoration layers placed inside an element with effects: the rotating beam (`beam`), the shine (`shine`) and, where needed, the pointer/press layer (`EffectLayer`). The element itself must carry the `data-effect` attribute; see `getEffects`. ### getEffects _function_ Adds the library's effects to your own element or component. Also works in server components. The element must be positioned (`relative`); effect layers take the element's corner radius. ```ts getEffects(effect: EffectInput, { component, fallback, appearance }?: GetEffectsOptions): EffectsResult ``` ```tsx const fx = getEffects(["tilt", "glow"]);
{fx.parts} Content
``` ### mergeAppearance _function_ Merges two appearance settings; `next` wins. ```ts mergeAppearance(base: AppearanceConfig, next: AppearanceConfig | undefined): AppearanceConfig ``` ### defineAppearance _function_ Defines the app's appearance settings and registers them app-wide: component defaults, custom effects and custom variants. Returns the same object; pass it to the `UIProvider` `appearance` prop and register it with the `Register` interface so the names are type-checked. **Server components** (`Card`, `Badge`…) can't read context; they take the settings from this registry. In Next.js App Router, import the settings file in the root layout (server-side registration) and pass it to the provider (client side). Custom effects containing functions (`press`, `setup`) can't be passed from server to client; if you have such effects, also import the file in your client provider file. ```ts defineAppearance(appearance: A): A ``` ```ts // app/appearance.ts import { defineAppearance } from "@yasinsensoy/web"; export const appearance = defineAppearance({ defaults: { button: { effect: "ripple", shape: "pill" }, card: { variant: "elevated", effect: ["lift", "glow"] }, }, effects: { neon: { className: "hover:shadow-[0_0_24px] hover:shadow-primary/50" }, }, variants: { button: { neon: "bg-black text-lime-300 border border-lime-400" }, card: { brand: { extends: "gradient", className: "border-violet-400/40" } }, }, }); // app/layout.tsx (server) import { appearance } from "./appearance"; … // ui.d.ts — so names are type-checked: declare module "@yasinsensoy/web" { interface Register { appearance: typeof import("./app/appearance").appearance } } ``` ### getAppearance _function_ Returns the app-wide appearance settings. For server components and code outside components; in client components use `useAppearance`, which also sees nested providers. ```ts getAppearance(): AppearanceConfig ``` ### EffectLayerProps _type_ Props of the `EffectLayer` component. | Property | Type | Default | Description | | --- | --- | --- | --- | | `effects` | `string` | | Effects to run, space-separated (e.g. `"tilt glow ripple"`). | ### EffectPartsProps _type_ Props of the `EffectParts` component. | Property | Type | Default | Description | | --- | --- | --- | --- | | `effects` | `readonly string[]` | | Effects to run. | | `appearance?` | `AppearanceConfig` | | Settings from which custom effects are read. Defaults to the app-wide registry (`getAppearance`). | ### GetEffectsOptions _type_ `getEffects` options. | Property | Type | Default | Description | | --- | --- | --- | --- | | `component?` | `EffectComponent` | | Component key whose default is read from `UIProvider` `appearance.defaults` (e.g. `"card"`). | | `fallback?` | `EffectInput` | | Effect to use when there is neither a prop nor a provider default. | | `appearance?` | `AppearanceConfig` | | Settings. In a client component pass `useAppearance()`; otherwise the app-wide registry is used. | ### EffectsResult _type_ Result of `getEffects`. | Property | Type | Default | Description | | --- | --- | --- | --- | | `effects` | `readonly string[]` | | Effects to run (`none` and empties filtered out). | | `props` | `{ "data-effect"?: string; className?: string; }` | | Attributes to spread on the element: `data-effect` and custom effect classes. | | `parts` | `ReactNode` | | Decoration layers to place inside the element. | ### EffectInput _type_ Effect prop; a name or an array of names. @internal ```ts type EffectInput = string | readonly string[] | undefined | null | false ``` ### BuiltinEffect _type_ The library's built-in effects. Each effect works on every component with an `effect` prop (`Button`, `Card`, `Badge`, `Alert`, all form fields, `Tabs`, `Accordion`, `Menu`, `Sidebar`, `Dialog`, `Popover`, `Toaster`, `Image`, `Gallery`…; full list in `EffectComponent`) and can be combined as an array (`["tilt", "glow", "ripple"]`). Played on press: - `scale`: sinks in slightly; CSS only. - `ripple`: a wave spreading from the pressed point. - `pulse`: a ring that expands outward from the element and fades. - `bounce`: springs in and bounces back. Active on hover, keyboard focus or while `active`: - `lift`: the element rises slightly and its shadow grows. - `border`: the border turns the accent color. - `beam`: a light beam rotating around the border. - `glow`: a light following the pointer; the background and border glow where the pointer is. - `tilt`: the element tilts in 3D toward the pointer's corner. - `shine`: a diagonal shine passes over the element (on press on touch screens). - `none`: no effect; turns off the `UIProvider` `appearance` default. Colors come from the element's accent color (`--ui-effect-accent`, the text color by default; `tone` on `Card`). With the "reduce motion" preference moving effects don't play; `glow` and `tilt` stay still on touch screens so they don't interfere with scrolling. ```ts type BuiltinEffect = "scale" | "ripple" | "pulse" | "bounce" | "lift" | "border" | "beam" | "glow" | "tilt" | "shine" | "none" ``` ### EffectName _type_ Effect name: one of the built-in effects (`BuiltinEffect`) or a custom effect added with `defineAppearance` and registered with `Register`. ```ts type EffectName = BuiltinEffect | CustomEffectName ``` ### EffectProp _type_ Type of the `effect` prop: a single effect or effects that run together. When omitted, the component's `UIProvider` `appearance.defaults` setting is used, otherwise the component's own default. `"none"` turns them all off. ```ts type EffectProp = EffectName | readonly EffectName[] ``` ```tsx … New ``` ### CustomVariant _type_ Names of a custom variant in the registry. `C` is the component key (`"button"`, `"card"`…). `never` when `Register` isn't extended. ```ts type CustomVariant = [RegisteredAppearance] extends [never] ? never : RegisteredAppearance extends { variants: infer V; } ? C extends keyof V ? Extract : never : never ``` ### EffectPress _type_ Info given to a press effect. | Property | Type | Default | Description | | --- | --- | --- | --- | | `x` | `number` | | Horizontal position of the pressed point relative to the element (pixels). Center on keyboard. | | `y` | `number` | | Vertical position of the pressed point relative to the element (pixels). Center on keyboard. | | `event` | `Event` | | Event that started the press: `pointerdown` or a keyboard `click`. | ### EffectDefinition _type_ Custom effect definition. One or more of three ways can be used together: - **CSS only:** `className` is added to the element (Tailwind classes or your own CSS). Also works in server components. The element also carries the effect name in its `data-effect` attribute; you can select it in CSS with `[data-effect~="neon"]`. - **JavaScript on press:** `press` is called on every press (mouse, touch or keyboard). Use `element.animate()` for animation. - **Free setup:** `setup` is called once when the element appears; bind your own listeners and return the cleanup function. Definitions containing functions can't be passed from server to client; define them in a client file (see `defineAppearance`). | Property | Type | Default | Description | | --- | --- | --- | --- | | `className?` | `string` | | Classes added to the element. | | `pointer?` | `boolean` | | Writes the pointer position to the `--ui-effect-x/y` (pixels) and `--ui-effect-px/py` (-1…1) variables; while the pointer is over it the element carries `data-pointer`. Works only on mouse devices. | | `press?` | `(element: HTMLElement, press: EffectPress) => void` | | Called on every press. Not called with the "reduce motion" preference. | | `setup?` | `(element: HTMLElement) => undefined \| (() => void)` | | Called when the element appears; may return a cleanup function. | ```ts const effects = { neon: { className: "hover:shadow-[0_0_24px] hover:shadow-primary/60" }, confetti: { press: (el, { x, y }) => burstConfetti(el, x, y), }, } satisfies Record; ``` ### VariantEntry _type_ Custom variant definition. A string is classes directly; an object can derive from a built-in variant and take separate classes per color (`tone`). When given under a built-in variant's name (e.g. `button: { solid: "…" }`), the classes are added on top of that variant. ```ts type VariantEntry = string | { /** Built-in variant to base on (e.g. `"outline"`). When omitted only the base layout classes remain. */ extends?: string; /** Classes added for every color. */ className?: string; /** Classes added per color (`tone`). */ tones?: Partial>; } ``` ```ts variants: { button: { neon: "bg-black text-lime-300 border border-lime-400 hover:bg-lime-400/10", glassy: { extends: "outline", className: "backdrop-blur bg-background/60" }, brand: { extends: "solid", tones: { primary: "bg-violet-600 hover:bg-violet-700" } }, }, card: { neon: "border-lime-400 shadow-[0_0_24px] shadow-lime-400/30" }, } ``` ### VariantComponent _type_ Keys of components that take custom variants. - `button`: `Button`, `IconButton`, `ButtonGroup` and everything that uses buttons (Dialog, Form buttons…). - `field`: all form fields (`Input`, `Textarea`, `Select`, `NumberInput`, `DatePicker`…) and their `*Field` wrappers. - The others are the component of the same name (`tableOfContents` → `TableOfContents`, `otpInput` → `OtpInput`). ```ts type VariantComponent = "button" | "card" | "badge" | "alert" | "stat" | "kbd" | "tabs" | "emptyState" | "field" | "accordion" | "stepper" | "otpInput" | "fab" | "timeline" | "tableOfContents" | "radio" | "countdown" ``` ### ComponentDefaults _type_ Default appearance settings of a component. | Property | Type | Default | Description | | --- | --- | --- | --- | | `variant?` | `string` | | Default variant name: built-in or added with `variants`. | | `effect?` | `EffectName \| (string & {}) \| readonly (EffectName \| (string & {}))[]` | | Default effect or effects. | | `tone?` | `Tone` | | Default color (if the component supports it). | | `size?` | `Size` | | Default size (if the component supports it). | | `shape?` | `string` | | Default corner shape (buttons only: `rounded`, `pill`, `sharp`). | ### EffectComponent _type_ Keys of components that take effects; `AppearanceConfig.defaults` is given with these keys. ```ts type EffectComponent = VariantComponent | "avatar" | "checkbox" | "switch" | "collapsible" | "sidebar" | "navigationMenu" | "breadcrumb" | "menu" | "treeView" | "rating" | "colorSwatch" | "kanban" | "notificationCenter" | "fileUpload" | "image" | "gallery" | "dialog" | "sheet" | "popover" | "hoverCard" | "toast" ``` ### AppearanceConfig _type_ The app's appearance settings: component defaults, custom effects and custom variants. Defined with `defineAppearance` and passed to the `UIProvider` `appearance` prop. | Property | Type | Default | Description | | --- | --- | --- | --- | | `defaults?` | `Partial>` | | Default `variant`, `effect`, `tone`, `size`, `shape` per component. A prop given to the component always wins. | | `effects?` | `Readonly>` | | Custom effects: name → definition. See `EffectDefinition`. | | `variants?` | `Partial>>>` | | Custom variants per component: name → classes. See `VariantEntry`. | ## Autocomplete ### Autocomplete _client component_ A text box that filters suggestions as you type. Uses the same options, the same list and the same loading modes as `Select`; the only difference is a box you type into directly instead of a trigger button. - **Suggestions:** `items` (array, Promise, function) searches in the browser; `loadItems` searches on the server and loads pages while scrolling. Turkish character and accent differences are ignored, the matching part is highlighted; large lists are virtualized. - **Free text:** with `allowCustomValue`, text not in the list also becomes a value (a tag, an email recipient, etc.). - **Multiple selection:** with `multiple`, selections become tags in the box; removed with ✕ or Backspace in an empty box. - **Keyboard:** ↓/↑ move through suggestions (focus stays in the box), Enter selects, Esc closes the list, a second Esc reverts the typed text. - **Mobile:** since the keyboard stays open, the list opens below the box instead of as a bottom sheet and doesn't exceed 40% of the screen; rows are thumb-sized. - **Form:** enters `FormData` with `name`, `required` works and it resets with the form. Use `AutocompleteField` for label, description and error. ```tsx searchPeople(query, page, signal)} /> ``` ### AutocompleteClassNames _type_ Classes that can be given to the inner parts of `Autocomplete`. | Property | Type | Default | Description | | --- | --- | --- | --- | | `control?` | `string` | | The box itself (the frame around the text field, tags and buttons). | | `input?` | `string` | | Text field. | | `chip?` | `string` | | Each tag in multiple selection. | | `content?` | `string` | | The open panel. | | `item?` | `string` | | Each option. | ### SingleAutocompleteProps _type_ Single-select `Autocomplete`. | Property | Type | Default | Description | | --- | --- | --- | --- | | `multiple?` | `false` | `false` | When `true` multiple values are selected; selections appear as tags in the box. | | `value?` | `string` | | Selected value in controlled use; `""` for none. | | `defaultValue?` | `string` | | Initial value in uncontrolled use. | | `onValueChange?` | `(value: string, item: SelectItem \| undefined) => void` | | Called with the new value and the selected item when the selection changes (`""` when cleared). | | `variant?` | `FieldVariant \| CustomVariant<"field">` | | Appearance: `outline` (bordered), `filled`, `underline` or `ghost` (plain). When omitted, the nearest `data-field-variant` container's setting is used, otherwise `outline`. See `FieldVariant`. | | `effect?` | `EffectProp` | | Effect or effects of the field box (e.g. `"glow"`, `["lift", "beam"]`). The accent color is the focus color (`--ui-field-focus`). Defaults to `UIProvider` `appearance.defaults.field.effect`. See `BuiltinEffect`. | | `items?` | `SelectItemsSource` | | Options: an array, a Promise or a function called once. Typed text is searched among these items in the browser. Same shape as `Select` (a string, `{ value, label, icon, description, disabled }`, `{ group, items }`). | | `loadItems?` | `SelectLoader` | | Function that searches the typed text on the server and fetches page by page. Requested 250 ms after typing stops; old requests are cancelled with `signal`. See `Select` `loadItems`. | | `allowCustomValue?` | `boolean` | `false` | Can text not in the list also be a value? (tag input, email recipients, an "other" option, etc.). When on, Enter or leaving the box makes the typed text the value; in multiple selection it is added as a tag. When off, only list items can be chosen; unmatched text reverts to the selected value on leave. | | `openOnFocus?` | `boolean` | `false` | Open the list when the box is focused (without typing)? When off, the list opens on typing, the ↓ key or a click on the box. | | `inputValue?` | `string` | | Text in the text field in controlled use. | | `onInputChange?` | `(text: string) => void` | | Called when the text in the field changes (e.g. to run your own search). | | `placeholder?` | `string` | | Text shown while the box is empty. | | `emptyMessage?` | `ReactNode` | | Content shown when the list is empty or the search has no results. | | `icon?` | `IconProp` | | Icon at the start of the box (e.g. `"search"`). In single selection the selected item's icon is shown if it has one. | | `clearable?` | `boolean` | `true` | × button that clears the selection and text. | | `name?` | `string` | | Form field name; the selected value(s) are submitted under this name. | | `form?` | `string` | | Id of the form the field belongs to (when outside the form). | | `required?` | `boolean` | | The form can't be submitted without a selection. | | `disabled?` | `boolean` | | Disabled. | | `id?` | `string` | | Id of the text field; `