@vjdesigns/vjdesigns-ui 3.6.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +854 -854
- package/dist/ai/llms-full.txt +647 -576
- package/dist/ai/llms.txt +1 -0
- package/dist/ai/registry.json +238 -6
- package/dist/components/navigation/MobileNav/MobileNav.cjs.js +1 -0
- package/dist/components/navigation/MobileNav/MobileNav.d.ts +170 -0
- package/dist/components/navigation/MobileNav/MobileNav.mjs +174 -0
- package/dist/components/navigation/MobileNav/MobileNav.module.css.cjs.js +1 -0
- package/dist/components/navigation/MobileNav/MobileNav.module.css.mjs +46 -0
- package/dist/components/navigation/MobileNav/index.d.ts +1 -0
- package/dist/i18n/en.cjs.js +1 -1
- package/dist/i18n/en.mjs +1 -0
- package/dist/i18n/types.d.ts +4 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +37 -36
- package/dist/locales/ar.cjs.js +1 -1
- package/dist/locales/ar.mjs +1 -0
- package/dist/locales/bn.cjs.js +1 -1
- package/dist/locales/bn.mjs +1 -0
- package/dist/locales/cs.cjs.js +1 -1
- package/dist/locales/cs.mjs +1 -0
- package/dist/locales/da.cjs.js +1 -1
- package/dist/locales/da.mjs +1 -0
- package/dist/locales/de.cjs.js +1 -1
- package/dist/locales/de.mjs +1 -0
- package/dist/locales/el.cjs.js +1 -1
- package/dist/locales/el.mjs +1 -0
- package/dist/locales/es.cjs.js +1 -1
- package/dist/locales/es.mjs +1 -0
- package/dist/locales/fa.cjs.js +1 -1
- package/dist/locales/fa.mjs +1 -0
- package/dist/locales/fi.cjs.js +1 -1
- package/dist/locales/fi.mjs +1 -0
- package/dist/locales/fr.cjs.js +1 -1
- package/dist/locales/fr.mjs +1 -0
- package/dist/locales/he.cjs.js +1 -1
- package/dist/locales/he.mjs +1 -0
- package/dist/locales/hi.cjs.js +1 -1
- package/dist/locales/hi.mjs +1 -0
- package/dist/locales/hu.cjs.js +1 -1
- package/dist/locales/hu.mjs +1 -0
- package/dist/locales/id.cjs.js +1 -1
- package/dist/locales/id.mjs +1 -0
- package/dist/locales/it.cjs.js +1 -1
- package/dist/locales/it.mjs +1 -0
- package/dist/locales/ja.cjs.js +1 -1
- package/dist/locales/ja.mjs +1 -0
- package/dist/locales/ko.cjs.js +1 -1
- package/dist/locales/ko.mjs +1 -0
- package/dist/locales/nb.cjs.js +1 -1
- package/dist/locales/nb.mjs +1 -0
- package/dist/locales/nl.cjs.js +1 -1
- package/dist/locales/nl.mjs +1 -0
- package/dist/locales/pl.cjs.js +1 -1
- package/dist/locales/pl.mjs +1 -0
- package/dist/locales/pt-BR.cjs.js +1 -1
- package/dist/locales/pt-BR.mjs +1 -0
- package/dist/locales/ro.cjs.js +1 -1
- package/dist/locales/ro.mjs +1 -0
- package/dist/locales/ru.cjs.js +1 -1
- package/dist/locales/ru.mjs +1 -0
- package/dist/locales/sv.cjs.js +1 -1
- package/dist/locales/sv.mjs +1 -0
- package/dist/locales/th.cjs.js +1 -1
- package/dist/locales/th.mjs +1 -0
- package/dist/locales/tr.cjs.js +1 -1
- package/dist/locales/tr.mjs +1 -0
- package/dist/locales/uk.cjs.js +1 -1
- package/dist/locales/uk.mjs +1 -0
- package/dist/locales/ur.cjs.js +1 -1
- package/dist/locales/ur.mjs +1 -0
- package/dist/locales/vi.cjs.js +1 -1
- package/dist/locales/vi.mjs +1 -0
- package/dist/locales/zh-Hans.cjs.js +1 -1
- package/dist/locales/zh-Hans.mjs +1 -0
- package/dist/locales/zh-Hant.cjs.js +1 -1
- package/dist/locales/zh-Hant.mjs +1 -0
- package/dist/vjdesigns-ui.css +1 -1
- package/package.json +1 -1
package/dist/ai/llms.txt
CHANGED
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
- [ContextMenu](llms-full.txt#contextmenu): A menu that opens at the pointer on right-click (or a long press on touch screens), for actions on the thing under the pointer.
|
|
119
119
|
- [Link](llms-full.txt#link): Accessible text link.
|
|
120
120
|
- [Menu](llms-full.txt#menu): A dropdown menu of actions or options, opened from a button (WAI-ARIA APG "Menu Button" and "Menu" patterns).
|
|
121
|
+
- [MobileNav](llms-full.txt#mobilenav): A mobile navigation bar: a bottom tab bar, a top bar, or a side rail of icon-and-label links.
|
|
121
122
|
- [Navbar](llms-full.txt#navbar): The top header of an app or site.
|
|
122
123
|
- [Pagination](llms-full.txt#pagination): Page navigation: a `<nav>` landmark with a list of pill page buttons, Previous/Next arrows, optional First/Last, and gaps for long ranges.
|
|
123
124
|
- [Sidebar](llms-full.txt#sidebar): App side navigation.
|
package/dist/ai/registry.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vjdesigns/vjdesigns-ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"summary": "Accessible React 19 component library: WCAG 2.2 AA verified (axe on every story, a contrast check on every color pair), 31 languages with right-to-left support, themeable with any brand color (auto-adjusted to stay accessible), tree-shakable, no runtime dependencies besides React.",
|
|
5
5
|
"install": "npm install @vjdesigns/vjdesigns-ui",
|
|
6
6
|
"stylesheet": "@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css",
|
|
@@ -17,27 +17,27 @@
|
|
|
17
17
|
{
|
|
18
18
|
"id": "setup",
|
|
19
19
|
"title": "Installation",
|
|
20
|
-
"markdown": "Install the package along with React and React DOM. The library requires **React 19**, which the components need in order to render:\
|
|
20
|
+
"markdown": "Install the package along with React and React DOM. The library requires **React 19**, which the components need in order to render:\n\n```bash\nnpm install @vjdesigns/vjdesigns-ui react react-dom\n```\n\nIf your project already uses React, you only need the first package:\n\n```bash\nnpm install @vjdesigns/vjdesigns-ui\n```\n\n### Browser support\n\nThe components support the current and previous major versions of evergreen browsers, with these minimums:\n\n| Browser | Minimum version |\n| --- | --- |\n| Chrome, Edge, and other Chromium browsers | 111 |\n| Firefox | 121 |\n| Safari (macOS and iOS) | 16.2 |\n\nThese are set by the CSS the components rely on: `color-mix()`, container queries, `:has()` (which draws some keyboard focus rings), and the `inert` attribute. Internet Explorer and legacy (non-Chromium) Edge aren't supported.\n\nA few newer features are used only where available, with a fallback elsewhere: `field-sizing` for auto-growing `Textarea` (measured in JavaScript otherwise), the `scrollend` event in `Carousel`, and `hidden=\"until-found\"` for find-in-page in `Accordion` and `Collapsible`.\n\n### Import the styles\n\nThe component styles and shared design tokens ship as a separate stylesheet. Import it **once** at your app's entry point, or the components will render unstyled.\n\n**React:** in `main.tsx` (or `App.tsx`)\n\n```ts\nimport \"@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css\";\n```\n\n**Angular:** add it to the `styles` array in `angular.json`\n\n```json\n\"styles\": [\n \"node_modules/@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css\",\n \"src/styles.css\"\n]\n```\n\n**Vue:** in `main.ts`\n\n```ts\nimport \"@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css\";\n```"
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
23
|
"id": "usage",
|
|
24
24
|
"title": "Usage",
|
|
25
|
-
"markdown": "The components are built with React. You can use them directly in a React project. In Angular or Vue, you mount them inside a small wrapper component, as shown below.\
|
|
25
|
+
"markdown": "The components are built with React. You can use them directly in a React project. In Angular or Vue, you mount them inside a small wrapper component, as shown below.\n\n### React\n\n```tsx\nimport { useState } from \"react\";\nimport { Button, CheckBox } from \"@vjdesigns/vjdesigns-ui\";\n\nexport function SignupForm() {\n const [accepted, setAccepted] = useState(false);\n\n return (\n <form>\n <CheckBox\n label=\"Accept terms\"\n checked={accepted}\n onCheckedChange={setAccepted}\n />\n <Button\n variant=\"solid\"\n tone=\"primary\"\n size=\"md\"\n disabled={!accepted}\n onClick={() => console.log(\"Submitted\")}\n >\n Submit\n </Button>\n </form>\n );\n}\n```\n\n### Next.js (App Router) and React Server Components\n\nThe library works in Server Components. Interactive components (anything with state, effects, or context: `Button`, `DataGrid`, `Modal`, ...) are marked `\"use client\"`, so you can render them from a Server Component like any client component. Utilities (`cx`, `sortRows`, `createBrandPalette`, `getLocaleDirection`, ...) and the locale catalogs have no directive, so you can call or read them on the server too. Every component also renders on the server for the first paint.\n\nPut the providers in a small client file of your own, and render it from the root layout:\n\n```tsx\n// app/providers.tsx\n\"use client\";\nimport { LocaleProvider, ToastProvider } from \"@vjdesigns/vjdesigns-ui\";\nimport es from \"@vjdesigns/vjdesigns-ui/locales/es\";\nimport type { ReactNode } from \"react\";\n\nexport function Providers({ children }: { children: ReactNode }) {\n return (\n <LocaleProvider locale=\"es\" messages={es}>\n <ToastProvider>{children}</ToastProvider>\n </LocaleProvider>\n );\n}\n```\n\n```tsx\n// app/layout.tsx (a Server Component)\nimport \"@vjdesigns/vjdesigns-ui/dist/vjdesigns-ui.css\";\nimport { getLocaleDirection } from \"@vjdesigns/vjdesigns-ui\";\nimport { Providers } from \"./providers\";\n\nexport default function RootLayout({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"es\" dir={getLocaleDirection(\"es\")}>\n <body>\n <Providers>{children}</Providers>\n </body>\n </html>\n );\n}\n```\n\nTwo rules of Server Components to keep in mind:\n\n- **Functions can't be passed from a Server Component to a client one.** That includes event handlers (`onClick`), DataGrid columns with `cell` or `value` functions, and the locale catalogs themselves (their plural messages are functions, which is why `LocaleProvider` goes in the client providers file above). Render those components from your own `\"use client\"` file.\n- **Compound parts can't be reached with a dot from a Server Component** (`Tabs.List`, `Menu.Item`): Next.js reports \"You cannot dot into a client module\". Use them inside a `\"use client\"` file, or use the named exports where they exist (`CardHeader`, `CardBody`, `NavbarBrand`, ...).\n\n### Angular\n\nMake a standalone wrapper that renders the React component into its host element. The wrapper uses `createElement`, so you don't need to change your JSX or TSX settings.\n\n```ts\n// vj-button.component.ts\nimport {\n AfterViewInit,\n Component,\n ElementRef,\n EventEmitter,\n Input,\n OnChanges,\n OnDestroy,\n Output,\n ViewChild,\n} from \"@angular/core\";\nimport { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport {\n Button,\n type ButtonProps,\n type ButtonVariant,\n type Size,\n type Tone,\n} from \"@vjdesigns/vjdesigns-ui\";\n\n// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.\nconst ReactButton = Button as (props: ButtonProps) => ReactElement;\n\n@Component({\n selector: \"vj-button\",\n standalone: true,\n template: `<span #host></span>`,\n})\nexport class VjButtonComponent implements AfterViewInit, OnChanges, OnDestroy {\n @ViewChild(\"host\", { static: true }) host!: ElementRef<HTMLElement>;\n\n @Input() label = \"\";\n @Input() variant: ButtonVariant = \"solid\";\n @Input() tone: Tone = \"primary\";\n @Input() size: Size = \"md\";\n @Input() disabled = false;\n @Output() clicked = new EventEmitter<MouseEvent>();\n\n private root?: Root;\n\n ngAfterViewInit() {\n this.root = createRoot(this.host.nativeElement);\n this.render();\n }\n\n ngOnChanges() {\n this.render();\n }\n\n ngOnDestroy() {\n this.root?.unmount();\n }\n\n private render() {\n this.root?.render(\n createElement(\n ReactButton,\n {\n variant: this.variant,\n tone: this.tone,\n size: this.size,\n disabled: this.disabled,\n onClick: (event: ReactMouseEvent) => this.clicked.emit(event.nativeEvent),\n },\n this.label // the button's text is passed as children\n )\n );\n }\n}\n```\n\nImport the wrapper wherever you need it:\n\n```ts\n// app.component.ts\nimport { Component } from \"@angular/core\";\nimport { VjButtonComponent } from \"./vj-button.component\";\n\n@Component({\n selector: \"app-root\",\n standalone: true,\n imports: [VjButtonComponent],\n template: `<vj-button label=\"Submit\" tone=\"primary\" (clicked)=\"onSubmit()\" />`,\n})\nexport class AppComponent {\n onSubmit() {\n console.log(\"Submitted\");\n }\n}\n```\n\n### Vue 3\n\nMake a wrapper component that mounts the React component when it loads and re-renders it whenever its props change.\n\n```vue\n<!-- VjButton.vue -->\n<script setup lang=\"ts\">\nimport { onBeforeUnmount, onMounted, ref, watch } from \"vue\";\nimport { createElement, type MouseEvent as ReactMouseEvent, type ReactElement } from \"react\";\nimport { createRoot, type Root } from \"react-dom/client\";\nimport {\n Button,\n type ButtonProps,\n type ButtonVariant,\n type Size,\n type Tone,\n} from \"@vjdesigns/vjdesigns-ui\";\n\n// Button has overloaded types (for `href` and `as`). Narrowing it here lets createElement type-check.\nconst ReactButton = Button as (props: ButtonProps) => ReactElement;\n\nconst props = withDefaults(\n defineProps<{\n label: string;\n variant?: ButtonVariant;\n tone?: Tone;\n size?: Size;\n disabled?: boolean;\n }>(),\n { variant: \"solid\", tone: \"primary\", size: \"md\", disabled: false }\n);\n\nconst emit = defineEmits<{ click: [event: MouseEvent] }>();\n\nconst host = ref<HTMLElement | null>(null);\nlet root: Root | undefined;\n\nfunction render() {\n root?.render(\n createElement(\n ReactButton,\n {\n variant: props.variant,\n tone: props.tone,\n size: props.size,\n disabled: props.disabled,\n onClick: (event: ReactMouseEvent) => emit(\"click\", event.nativeEvent),\n },\n props.label // the button's text is passed as children\n )\n );\n}\n\nonMounted(() => {\n root = createRoot(host.value!);\n render();\n});\n\nwatch(() => ({ ...props }), render);\n\nonBeforeUnmount(() => root?.unmount());\n</script>\n\n<template>\n <span ref=\"host\" />\n</template>\n```\n\nUse it like any other Vue component:\n\n```vue\n<script setup lang=\"ts\">\nimport VjButton from \"./VjButton.vue\";\n\nconst onSubmit = () => console.log(\"Submitted\");\n</script>\n\n<template>\n <VjButton label=\"Submit\" tone=\"primary\" @click=\"onSubmit\" />\n</template>\n```\n\n> **Tip:** Wrap `CheckBox` and any other component the same way. Pass its props into `createElement`, and send its callbacks back out as Angular outputs or Vue emits. For `CheckBox`, that means sending `onCheckedChange` back out."
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"id": "theming",
|
|
29
29
|
"title": "Theming",
|
|
30
|
-
"markdown": "Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:\
|
|
30
|
+
"markdown": "Wrap any part of your app in `Theme` to set the color mode, brand palette, and accent for everything inside it:\n\n```tsx\nimport { Theme, Button } from \"@vjdesigns/vjdesigns-ui\";\n\n<Theme mode=\"dark\" brand=\"purple\" fill>\n <Button>Dark, purple button</Button>\n</Theme>\n```\n\n| Prop | Type | Default | Description |\n| --- | --- | --- | --- |\n| `mode` | `\"light\" \\| \"dark\"` | inherited | Color mode for everything inside. |\n| `brand` | `\"black\" \\| \"blue\" \\| \"gold\" \\| \"green\" \\| \"purple\"`, a hex color, or `{ light, dark }` | inherited | Brand palette for buttons, links, focus rings and indicators. |\n| `accent` | `\"brand\" | \"lime\"`, a hex color, or `{ light, dark }` | inherited (the brand's own) | The bright highlight on badges, switches, progress bars, sliders, steppers, and active navigation. |\n| `fill` | `boolean` | `false` | Paints the theme's background and text color on the wrapper. |\n\nOutside React (or to theme the whole page), set the attributes on `<html>` instead:\n\n```html\n<html data-theme=\"dark\" data-brand=\"purple\" data-accent=\"lime\">\n```\n\n### Accent color\n\nThe accent is the energetic highlight: badges, switches, progress bars, sliders, steppers, and the active link in the Navbar. By default it follows the brand, as a bright shade of the brand's own color, so it always fits:\n\n| Brand | Default accent |\n| --- | --- |\n| `blue` (default) | sky blue `#76c7ff` |\n| `purple` | lavender `#c0b0ff` |\n| `gold` | amber `#f5ad5f` |\n| `green` | mint `#72d4ad` |\n| `black` | lime `#c8f031` (black has no hue to build on) |\n| a custom hex | generated from that color |\n\nTo choose a different one:\n\n```tsx\n<Theme accent=\"lime\">…</Theme> // the original bright yellow-green (\"volt\", its former name, still works)\n<Theme accent=\"#ff6b00\">…</Theme> // any color\n<Theme accent=\"brand\">…</Theme> // back to the brand's own, inside an area with another accent\n```\n\nAccents always carry dark text. A color too dark for that is lightened (same hue) just enough to meet WCAG AA, with a warning in development. An accent you set also holds inside nested brands. In CSS, `accentCss(\"name\", \"#ff6b00\")` generates a `[data-accent=\"name\"]` rule, like `brandCss` below.\n\n### Custom brand colors\n\nPass any hex color as `brand` and a full palette is generated for both modes:\n\n```tsx\n<Theme brand=\"#e11d48\">…</Theme>\n<Theme brand={{ light: \"#4338ca\", dark: \"#f472b6\" }}>…</Theme>\n```\n\nEvery generated palette meets WCAG 2.2 AA. A single color is used exactly as given in the mode where it has enough contrast (dark colors in light mode, light colors in dark mode), and the other mode gets a matching shade of the same hue. If a color doesn't have enough contrast (for example, a mid-tone that fails in both modes), its lightness is shifted just enough to pass, and a warning is logged in development.\n\nTo define a brand in CSS instead (for the whole page, applied before any JavaScript runs), generate a stylesheet rule with `brandCss`:\n\n```ts\nimport { brandCss } from \"@vjdesigns/vjdesigns-ui\";\n\nbrandCss(\"acme\", \"#e11d48\"); // '[data-brand=\"acme\"] { --brand-light-primary: … }'\n```\n\nAdd the rule to your stylesheet and use `<html data-brand=\"acme\">`. `createBrandPalette(color)` returns the generated colors as an object, if you need them directly.\n\n### Tailwind CSS\n\nA Tailwind CSS v4 preset turns the design tokens into utilities, so your own layouts match the components. Import it after Tailwind in your CSS, and keep importing the library's stylesheet as usual:\n\n```css\n@import \"tailwindcss\";\n@import \"@vjdesigns/vjdesigns-ui/tailwind.css\";\n```\n\n```tsx\n<section className=\"bg-surface text-text rounded-xl shadow-md p-6\">\n <h2 className=\"font-display text-2xl tracking-tight\">Season stats</h2>\n <p className=\"text-text-muted\">Updated after every game.</p>\n <span className=\"bg-accent text-on-accent rounded-control px-3\">New</span>\n</section>\n```\n\nEvery utility points at a token (`bg-primary` is `var(--color-primary)`), so Tailwind classes follow `Theme`, `data-theme`, `data-brand`, and `data-accent` exactly like the components, with no `dark:` variants needed.\n\n| Group | Utilities |\n| --- | --- |\n| Colors | `bg-`, `text-`, `border-`, `ring-`, … with `bg`, `surface` (`-raised`, `-sunken`, `-hover`, `-active`), `overlay`, `text` (`-muted`, `-disabled`, `-inverse`), `border` (`-strong`, `-input`), `focus-ring`, `link-visited`; and for `primary`, `accent`, `success`, `warning`, `danger`, `info`, `neutral`: the solid color, `-hover`, `-active`, `on-…` (text on the solid), `-subtle`, `-subtle-hover`, `-subtle-text`, `-border`. Opacity modifiers work (`bg-primary/50`). |\n| Charts | `bg-chart-1` to `bg-chart-8`, for fills only, in that order. Slots 3 to 5 are under 3:1 on white, so pair them with a legend, labels, or a data table. |\n| Type | `font-display` (headings, buttons, labels, numbers), `font-body`, `font-mono`; `text-xs` to `text-6xl` (plus `text-md`); `font-regular` to `font-black`; `leading-tight`, `-snug`, `-normal`, `-relaxed`; `tracking-tight`, `-normal`, `-wide`, `-caps` |\n| Shape | `rounded-control` (pill controls), `rounded-field` (text fields), `rounded-xs` to `rounded-2xl`, `rounded-pill` |\n| Depth | `shadow-xs` to `shadow-xl`, `blur-sm`, `blur-lg` |\n| Motion | `ease-spring` (enter and press), `ease-standard`, `ease-in`, `ease-out`; `duration-instant`, `-fast`, `-normal`, `-slow` (0ms under reduced motion) |\n| Sizes | `h-control-sm`, `-md`, `-lg` (and `w-`, `min-h-`, …), `size-target` (the 24px minimum pointer target), `max-w-xs` to `max-w-2xl` and `@xs:` to `@2xl:` container queries |\n| Layers | `z-sticky`, `z-overlay`, `z-modal`, `z-popover`, `z-dropdown`, `z-toast`, `z-tooltip` |\n| Dark mode | `dark:` follows `data-theme=\"dark\"`, not the OS setting. |\n\nTailwind's numeric spacing (`p-4` = 1rem) already matches the 4px token scale, and the breakpoints (`sm:` to `2xl:`) are the same as Tailwind's.\n\nSome Tailwind names change meaning with the preset: `rounded-*`, `shadow-*`, `blur-sm`/`-lg`, `ease-in`/`-out`, `font-mono`, `font-medium` to `font-black`, `leading-*`, and the `text-*` sizes take the library's values (for example, `rounded-md` is 12px and `font-black` is 800). So do the containers: `max-w-md` and `@md:` are 48rem, not Tailwind's 28rem. The library's stylesheet already gives some of these names its own values once it's loaded, even without the preset; the preset keeps the utilities and the container queries consistent.\n\nFor text contrast, use the pairs the components use: `text-text` or `text-text-muted` on `bg-bg`, `bg-surface`, and the other surfaces; `text-on-primary` on `bg-primary` (likewise `on-accent`, `on-success`, …); `text-primary-subtle-text` on `bg-primary-subtle` (likewise for each tone). These pairs meet WCAG 2.2 AA in both themes and every brand. Don't use accent or chart colors for text.\n\nThe preset doesn't change the components, and Tailwind's preflight (its CSS reset) doesn't override them, whichever stylesheet loads first."
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"id": "languages",
|
|
34
34
|
"title": "Languages",
|
|
35
|
-
"markdown": "Components have built-in text: button names like \"Close\" and \"Next page\", screen-reader announcements like \"3 results available\", validation messages, and date formats. Wrap your app in `LocaleProvider` to show all of it in another language:\
|
|
35
|
+
"markdown": "Components have built-in text: button names like \"Close\" and \"Next page\", screen-reader announcements like \"3 results available\", validation messages, and date formats. Wrap your app in `LocaleProvider` to show all of it in another language:\n\n```tsx\nimport { LocaleProvider } from \"@vjdesigns/vjdesigns-ui\";\nimport es from \"@vjdesigns/vjdesigns-ui/locales/es\";\n\n<LocaleProvider locale=\"es\" messages={es}>\n <App />\n</LocaleProvider>\n```\n\n`LocaleProvider` sets:\n\n- **Built-in text** for every component, from `messages`.\n- **Dates and numbers** in the locale's format (`23/10/2026`, `1.234,5`), and plurals that follow the language's rules.\n- **Writing direction**: Arabic, Hebrew, Persian, and Urdu get `dir=\"rtl\"`, and layouts and arrow keys mirror.\n- **`lang`** on its wrapper, so screen readers pronounce the text correctly. Popups (menus, dialogs, tooltips) keep the language of the area that opened them.\n\nEach locale is a separate import, so your app only downloads the languages it uses. Without a `LocaleProvider`, components use English text and the browser's date and number format.\n\nThis library only translates its own built-in text. Text your app passes in, like `<Button>Save</Button>`, is your app's content: translate it with your app's i18n library (react-i18next, FormatJS, and so on).\n\n### What gets translated\n\nThe language is never picked automatically from where the user lives or their browser settings. Your app chooses it by rendering a `LocaleProvider`. For example, with `<LocaleProvider locale=\"de\" messages={de}>`:\n\n| | Translated? |\n| --- | --- |\n| Text your app passes in, like `<Button>Save</Button>` | No: your app translates it |\n| Built-in names, like \"Close\", \"Next page\", \"Clear search\" | Yes: \"Schließen\", \"Nächste Seite\", \"Suche löschen\" |\n| Screen-reader announcements, like \"3 results available\" | Yes: \"3 Ergebnisse verfügbar\" |\n| Validation messages, empty states, file-upload prompts | Yes |\n| Dates and numbers | Yes: \"23.10.2026\", \"4,5\" |\n\nTo follow the user's browser language, pass it yourself: `locale={navigator.language}` together with the matching `messages` (see [Switching language at runtime](#switching-language-at-runtime)).\n\n### Bundled languages\n\n`ar` Arabic · `bn` Bengali · `cs` Czech · `da` Danish · `de` German · `el` Greek · `es` Spanish · `fa` Persian · `fi` Finnish · `fr` French · `he` Hebrew · `hi` Hindi · `hu` Hungarian · `id` Indonesian · `it` Italian · `ja` Japanese · `ko` Korean · `nb` Norwegian Bokmål · `nl` Dutch · `pl` Polish · `pt-BR` Portuguese (Brazil) · `ro` Romanian · `ru` Russian · `sv` Swedish · `th` Thai · `tr` Turkish · `uk` Ukrainian · `ur` Urdu · `vi` Vietnamese · `zh-Hans` Chinese (Simplified) · `zh-Hant` Chinese (Traditional), plus English (the default).\n\nThe translations are machine-generated and haven't been reviewed by native speakers yet. If you find a wrong or awkward phrase, override it (below) and report it so the bundled locale can be fixed. (Working on the library itself? See [Translating built-in text](#translating-built-in-text).)\n\n### Changing a few strings\n\nPass only the strings you want to change. Everything else falls back to the outer provider's language (English at the top):\n\n```tsx\n<LocaleProvider locale=\"en-GB\" messages={{ pagination: { next: \"Onwards\" } }}>\n```\n\nProviders nest, so an inner provider can switch the language for one part of the page. Per-component props such as `clearLabel` or `labels` still win over the provider.\n\n### Other languages\n\nFor a language that isn't bundled, write a complete messages object. TypeScript flags any missing string. Use English as the template:\n\n```ts\nimport { en, plural, type Messages } from \"@vjdesigns/vjdesigns-ui\";\n\nconst p = plural(\"sw\");\nexport const sw: Messages = {\n ...en,\n pagination: { ...en.pagination, next: \"Ukurasa unaofuata\", previous: \"Ukurasa uliopita\" },\n searchInput: {\n ...en.searchInput,\n results: (count) => p(count, { \"=0\": \"Hakuna matokeo\", one: \"Tokeo #\", other: \"Matokeo #\" }),\n },\n // ...\n};\n```\n\n`plural(locale)` picks the right plural form for any language (`#` is the formatted number).\n\n### Switching language at runtime\n\nList the languages your app offers as loaders, so each one is downloaded only when picked:\n\n```tsx\nimport { LocaleProvider, type Messages } from \"@vjdesigns/vjdesigns-ui\";\n\nconst loaders: Record<string, () => Promise<{ default: Messages }>> = {\n es: () => import(\"@vjdesigns/vjdesigns-ui/locales/es\"),\n fr: () => import(\"@vjdesigns/vjdesigns-ui/locales/fr\"),\n ar: () => import(\"@vjdesigns/vjdesigns-ui/locales/ar\"),\n};\n\nfunction App({ lang }: { lang: string }) {\n const [messages, setMessages] = useState<Messages>();\n useEffect(() => {\n const load = loaders[lang];\n if (load) load().then((mod) => setMessages(mod.default));\n else setMessages(undefined); // English\n }, [lang]);\n // Until a language loads, the previous one (or English) shows.\n return <LocaleProvider locale={lang} messages={messages}>…</LocaleProvider>;\n}\n```\n\nFor server rendering, also set `<html lang=\"…\" dir=\"…\">` on the page. `getLocaleDirection(locale)` returns `\"ltr\"` or `\"rtl\"`."
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
"id": "validation",
|
|
39
39
|
"title": "Form validation",
|
|
40
|
-
"markdown": "> **Front-end validation is not security.** It helps people fill in a form correctly, but anyone can turn off JavaScript or send requests straight to your server. Always validate again on the server. The format checks below (`isEmail`, `isIP`, …) are plain functions you can reuse there.\
|
|
40
|
+
"markdown": "> **Front-end validation is not security.** It helps people fill in a form correctly, but anyone can turn off JavaScript or send requests straight to your server. Always validate again on the server. The format checks below (`isEmail`, `isIP`, …) are plain functions you can reuse there.\n\n`useFormValidation` checks a form when it's submitted, using the browser's own rules on each input (`required`, `type=\"email\"`, `minLength`, `pattern`, `min` / `max`) plus any rules you add. Messages follow the current language.\n\n```tsx\nimport {\n useFormValidation, rules, ErrorSummary, Field, Input, PasswordInput, Button,\n} from \"@vjdesigns/vjdesigns-ui\";\n\nfunction SignUp() {\n const form = useFormValidation({\n rules: {\n confirm: rules.matches(\"password\", \"The passwords don't match.\"),\n serverIp: rules.ip(), // IPv4 or IPv6\n },\n // Runs only when everything is valid. Return the server's errors to show them on their fields.\n onValid: async (values) => {\n const response = await api.signUp(values);\n return response.errors; // e.g. { username: \"That username is taken.\" }\n },\n });\n\n return (\n <form {...form.formProps}>\n <ErrorSummary ref={form.summaryRef} errors={form.errorList} />\n <Field label=\"Email\" required error={form.errors.email}>\n <Input name=\"email\" type=\"email\" />\n </Field>\n <Field label=\"Password\" required error={form.errors.password}>\n <PasswordInput name=\"password\" minLength={12} />\n </Field>\n <Field label=\"Confirm password\" required error={form.errors.confirm}>\n <PasswordInput name=\"confirm\" />\n </Field>\n <Field label=\"Server IP\" error={form.errors.serverIp}>\n <Input name=\"serverIp\" />\n </Field>\n <Button type=\"submit\" loading={form.isSubmitting}>Create account</Button>\n </form>\n );\n}\n```\n\nHow it behaves:\n\n- **On submit**, every field is checked. If anything is wrong, the `ErrorSummary` at the top lists the problems and takes focus, so screen readers announce it. Each item links to its field. Without a summary, focus goes to the first invalid field.\n- **Errors are keyed by the field's `name`.** Pass `form.errors.<name>` to each `Field`'s `error`.\n- **After a failed submit**, an error disappears as soon as the field is fixed (while typing), and a field is fully re-checked when you leave it. It doesn't nag while you're still typing.\n- **Server errors** (returned from `onValid`, or set with `form.setErrors({...})`) show on their fields and stay until that field is edited.\n- **Emails** must have a real domain (`name@example.com`). The browser's own check also accepts `name@localhost`.\n\n### Rules and format checks\n\n| Rule | Checks |\n| --- | --- |\n| `rules.required()` | Not empty (for controls without a native `required`) |\n| `rules.email()` | An email address in the usual format, with a top-level domain |\n| `rules.ip()` / `rules.ip({ version: 4 })` / `rules.ip({ version: 6 })` | An IPv4 or IPv6 address |\n| `rules.minLength(n)` / `rules.maxLength(n)` | Length in characters |\n| `rules.pattern(/regex/, \"message\")` | The whole value matches |\n| `rules.matches(\"otherField\")` | Equals another field (confirm password) |\n| your own `(value, { values }) => message` | Anything else |\n\nEach rule takes an optional custom message. The checks behind them are exported for use anywhere, including your server:\n\n- `isEmail(value)`\n- `isIPv4(value)`: four numbers 0–255, no leading zeros\n- `isIPv6(value)`: including `::` shorthand and IPv4 tails like `::ffff:192.168.0.1`\n- `isIP(value, version?)`"
|
|
41
41
|
}
|
|
42
42
|
],
|
|
43
43
|
"components": [
|
|
@@ -15725,6 +15725,238 @@
|
|
|
15725
15725
|
}
|
|
15726
15726
|
]
|
|
15727
15727
|
},
|
|
15728
|
+
{
|
|
15729
|
+
"name": "MobileNav",
|
|
15730
|
+
"category": "navigation",
|
|
15731
|
+
"folder": "MobileNav",
|
|
15732
|
+
"import": "import { MobileNav } from \"@vjdesigns/vjdesigns-ui\";",
|
|
15733
|
+
"description": "A mobile navigation bar: a bottom tab bar, a top bar, or a side rail of\nicon-and-label links. A bubble slides to the current item, with an\nanimated `effect` (floating bubbles by default; also sparkle, confetti,\nglow, jelly, orbit, splash, or none). With reduced motion, the bubble simply\nmoves without the effects.\n\nRenders a `<nav>` landmark with a list of links. The current item has\n`aria-current=\"page\"` and is marked by the bubble's shape and an indicator\nbar, never by color alone. Every item keeps its label as its accessible\nname, even when labels are hidden.",
|
|
15734
|
+
"nativeElement": "nav",
|
|
15735
|
+
"props": [
|
|
15736
|
+
{
|
|
15737
|
+
"name": "children",
|
|
15738
|
+
"type": "ReactNode",
|
|
15739
|
+
"required": false,
|
|
15740
|
+
"description": "`MobileNav.Item`s, usually three to five."
|
|
15741
|
+
},
|
|
15742
|
+
{
|
|
15743
|
+
"name": "placement",
|
|
15744
|
+
"type": "MobileNavPlacement",
|
|
15745
|
+
"required": false,
|
|
15746
|
+
"default": "\"bottom\"",
|
|
15747
|
+
"description": "Edge of the screen the bar sits on: `bottom`, `top`, or a `side` rail."
|
|
15748
|
+
},
|
|
15749
|
+
{
|
|
15750
|
+
"name": "side",
|
|
15751
|
+
"type": "MobileNavSide",
|
|
15752
|
+
"required": false,
|
|
15753
|
+
"default": "\"start\"",
|
|
15754
|
+
"description": "With `placement=\"side\"`, the edge the rail sits on (logical, so it mirrors in RTL)."
|
|
15755
|
+
},
|
|
15756
|
+
{
|
|
15757
|
+
"name": "variant",
|
|
15758
|
+
"type": "MobileNavVariant",
|
|
15759
|
+
"required": false,
|
|
15760
|
+
"default": "\"surface\"",
|
|
15761
|
+
"description": "Visual style. See `MobileNavVariant`."
|
|
15762
|
+
},
|
|
15763
|
+
{
|
|
15764
|
+
"name": "floating",
|
|
15765
|
+
"type": "boolean",
|
|
15766
|
+
"required": false,
|
|
15767
|
+
"default": "false",
|
|
15768
|
+
"description": "Detaches the bar from the edge as a rounded, shadowed island with space around it."
|
|
15769
|
+
},
|
|
15770
|
+
{
|
|
15771
|
+
"name": "position",
|
|
15772
|
+
"type": "MobileNavPosition",
|
|
15773
|
+
"required": false,
|
|
15774
|
+
"default": "\"fixed\"",
|
|
15775
|
+
"description": "`fixed` stays on its edge of the viewport; `sticky` sticks to its edge of\nthe scroll container; `static` stays in the flow."
|
|
15776
|
+
},
|
|
15777
|
+
{
|
|
15778
|
+
"name": "size",
|
|
15779
|
+
"type": "Size",
|
|
15780
|
+
"required": false,
|
|
15781
|
+
"default": "\"md\"",
|
|
15782
|
+
"description": "Bar height (or rail width) and icon size. Bars: sm 56px, md 64px, lg 72px. Rails: sm 64px, md 80px, lg 96px."
|
|
15783
|
+
},
|
|
15784
|
+
{
|
|
15785
|
+
"name": "effect",
|
|
15786
|
+
"type": "MobileNavEffect",
|
|
15787
|
+
"required": false,
|
|
15788
|
+
"default": "\"bubbles\"",
|
|
15789
|
+
"description": "The animated effect when the current item changes: `bubbles`,\n`sparkle`, `confetti`, `glow`, `jelly`, `orbit`, `splash`, or `none` to\nturn it off. See `MobileNavEffect`."
|
|
15790
|
+
},
|
|
15791
|
+
{
|
|
15792
|
+
"name": "activeTone",
|
|
15793
|
+
"type": "MobileNavActiveTone",
|
|
15794
|
+
"required": false,
|
|
15795
|
+
"default": "\"accent\"",
|
|
15796
|
+
"description": "Color of the bubble and indicator behind the current item."
|
|
15797
|
+
},
|
|
15798
|
+
{
|
|
15799
|
+
"name": "labels",
|
|
15800
|
+
"type": "MobileNavLabels",
|
|
15801
|
+
"required": false,
|
|
15802
|
+
"default": "\"always\"",
|
|
15803
|
+
"description": "Which labels are visible: `always`, only the `active` item's, or `never`. Labels are always the items' accessible names."
|
|
15804
|
+
},
|
|
15805
|
+
{
|
|
15806
|
+
"name": "hideAbove",
|
|
15807
|
+
"type": "MobileNavBreakpoint",
|
|
15808
|
+
"required": false,
|
|
15809
|
+
"description": "Hides the bar at this breakpoint and wider, e.g. `\"md\"` to show it only on phones."
|
|
15810
|
+
},
|
|
15811
|
+
{
|
|
15812
|
+
"name": "reserveSpace",
|
|
15813
|
+
"type": "boolean",
|
|
15814
|
+
"required": false,
|
|
15815
|
+
"default": "true",
|
|
15816
|
+
"description": "With `position=\"fixed\"`, keeps focused and scrolled-to content clear of\nthe bar (WCAG 2.4.11): while mounted, sets the matching `scroll-padding`\non `<html>` to the space the bar covers, and `--mobile-nav-offset` on\n`<html>` to the same length, so the page can reserve room for it\n(`body { padding-block-end: var(--mobile-nav-offset, 0px) }` under a\nbottom bar). Both are restored on unmount, and are 0 while hidden by\n`hideAbove`."
|
|
15817
|
+
},
|
|
15818
|
+
{
|
|
15819
|
+
"name": "value",
|
|
15820
|
+
"type": "string",
|
|
15821
|
+
"required": false,
|
|
15822
|
+
"description": "The current item's `value`, when controlled. An item's own `active` prop wins."
|
|
15823
|
+
},
|
|
15824
|
+
{
|
|
15825
|
+
"name": "defaultValue",
|
|
15826
|
+
"type": "string",
|
|
15827
|
+
"required": false,
|
|
15828
|
+
"description": "The initially current item's `value`, when uncontrolled. Selecting an item makes it current."
|
|
15829
|
+
},
|
|
15830
|
+
{
|
|
15831
|
+
"name": "onValueChange",
|
|
15832
|
+
"type": "(value: string) => void",
|
|
15833
|
+
"required": false,
|
|
15834
|
+
"description": "Called with an item's `value` when it's selected."
|
|
15835
|
+
},
|
|
15836
|
+
{
|
|
15837
|
+
"name": "aria-label",
|
|
15838
|
+
"type": "string",
|
|
15839
|
+
"required": false,
|
|
15840
|
+
"default": "\"Main\" (translated)",
|
|
15841
|
+
"description": "Accessible name of the navigation landmark."
|
|
15842
|
+
}
|
|
15843
|
+
],
|
|
15844
|
+
"subcomponents": [
|
|
15845
|
+
{
|
|
15846
|
+
"name": "MobileNav.Item",
|
|
15847
|
+
"exportedAs": "MobileNavItem",
|
|
15848
|
+
"description": "One destination in a `MobileNav`: an icon over a label, in its own `<li>`.\nSelecting it makes it current when the root is uncontrolled (and calls\n`onValueChange`), even if a client-side router prevents the default\nnavigation.",
|
|
15849
|
+
"props": [
|
|
15850
|
+
{
|
|
15851
|
+
"name": "as",
|
|
15852
|
+
"type": "C",
|
|
15853
|
+
"required": false,
|
|
15854
|
+
"default": "\"a\"",
|
|
15855
|
+
"description": "The element or component to render, e.g. your router's `Link`. Use a\nlink for navigation; `\"button\"` suits an action such as opening a sheet."
|
|
15856
|
+
},
|
|
15857
|
+
{
|
|
15858
|
+
"name": "value",
|
|
15859
|
+
"type": "string",
|
|
15860
|
+
"required": false,
|
|
15861
|
+
"description": "Identifies the item for the root's `value` / `defaultValue` / `onValueChange`."
|
|
15862
|
+
},
|
|
15863
|
+
{
|
|
15864
|
+
"name": "active",
|
|
15865
|
+
"type": "boolean",
|
|
15866
|
+
"required": false,
|
|
15867
|
+
"description": "Marks the item as the current page (`aria-current=\"page\"`), whatever\nthe root's `value`. Use it when your router knows the current page."
|
|
15868
|
+
},
|
|
15869
|
+
{
|
|
15870
|
+
"name": "icon",
|
|
15871
|
+
"type": "ReactNode",
|
|
15872
|
+
"required": true,
|
|
15873
|
+
"description": "The icon. Decorative: the label names the item."
|
|
15874
|
+
},
|
|
15875
|
+
{
|
|
15876
|
+
"name": "activeIcon",
|
|
15877
|
+
"type": "ReactNode",
|
|
15878
|
+
"required": false,
|
|
15879
|
+
"description": "A different icon for the current item, e.g. a filled version, as an extra cue besides color."
|
|
15880
|
+
},
|
|
15881
|
+
{
|
|
15882
|
+
"name": "badge",
|
|
15883
|
+
"type": "MobileNavBadgeValue",
|
|
15884
|
+
"required": false,
|
|
15885
|
+
"description": "A count (shown with `Badge` `count`, capped at 99+, hidden at 0) or a\nshort text such as \"New\", on the icon's corner. It's read after the\nlabel (\"Messages 3\")."
|
|
15886
|
+
},
|
|
15887
|
+
{
|
|
15888
|
+
"name": "badgeLabel",
|
|
15889
|
+
"type": "string",
|
|
15890
|
+
"required": false,
|
|
15891
|
+
"description": "Screen-reader text for the badge, e.g. \"3 unread messages\". Replaces the badge text in the accessible name."
|
|
15892
|
+
},
|
|
15893
|
+
{
|
|
15894
|
+
"name": "badgeTone",
|
|
15895
|
+
"type": "Tone",
|
|
15896
|
+
"required": false,
|
|
15897
|
+
"description": "Badge color. By default `accent`, or the bar's colors swapped on the `solid` variant."
|
|
15898
|
+
},
|
|
15899
|
+
{
|
|
15900
|
+
"name": "children",
|
|
15901
|
+
"type": "ReactNode",
|
|
15902
|
+
"required": true,
|
|
15903
|
+
"description": "The label. Always the item's accessible name, even when hidden by `labels`."
|
|
15904
|
+
}
|
|
15905
|
+
]
|
|
15906
|
+
}
|
|
15907
|
+
],
|
|
15908
|
+
"storybook": "Navigation/MobileNav",
|
|
15909
|
+
"stories": [
|
|
15910
|
+
{
|
|
15911
|
+
"name": "Playground",
|
|
15912
|
+
"description": ""
|
|
15913
|
+
},
|
|
15914
|
+
{
|
|
15915
|
+
"name": "Effects",
|
|
15916
|
+
"description": "Every `effect`. Tap the items to play each one. `effect=\"none\"` turns the\neffect off; the bubble still slides. With reduced motion, none play."
|
|
15917
|
+
},
|
|
15918
|
+
{
|
|
15919
|
+
"name": "Placements",
|
|
15920
|
+
"description": "Bottom tab bar, top bar, and a side rail at either edge."
|
|
15921
|
+
},
|
|
15922
|
+
{
|
|
15923
|
+
"name": "Labels",
|
|
15924
|
+
"description": "Labels on every item, only on the current one (it grows into a pill), or icons only."
|
|
15925
|
+
},
|
|
15926
|
+
{
|
|
15927
|
+
"name": "Variants And Tones",
|
|
15928
|
+
"description": "Surface and solid bars in every active tone."
|
|
15929
|
+
},
|
|
15930
|
+
{
|
|
15931
|
+
"name": "Sizes",
|
|
15932
|
+
"description": ""
|
|
15933
|
+
},
|
|
15934
|
+
{
|
|
15935
|
+
"name": "Floating",
|
|
15936
|
+
"description": "A rounded island with space around it, as a bar and as a rail."
|
|
15937
|
+
},
|
|
15938
|
+
{
|
|
15939
|
+
"name": "Active Icons",
|
|
15940
|
+
"description": "`activeIcon` swaps in a filled icon on the current item, an extra cue besides color."
|
|
15941
|
+
},
|
|
15942
|
+
{
|
|
15943
|
+
"name": "Router Controlled",
|
|
15944
|
+
"description": "With a router: each item's `active` says which page is current, and the root holds no state."
|
|
15945
|
+
},
|
|
15946
|
+
{
|
|
15947
|
+
"name": "Long Labels",
|
|
15948
|
+
"description": "Long labels shorten with an ellipsis instead of pushing other items out."
|
|
15949
|
+
},
|
|
15950
|
+
{
|
|
15951
|
+
"name": "Right To Left",
|
|
15952
|
+
"description": "Right-to-left: items run from the right, and a start rail sits on the right."
|
|
15953
|
+
},
|
|
15954
|
+
{
|
|
15955
|
+
"name": "Fixed",
|
|
15956
|
+
"description": "`position=\"fixed\"` (the default in apps): the bar stays on the viewport's\nbottom edge, and `<html>` gets scroll padding and `--mobile-nav-offset`\nso focused content isn't hidden behind it."
|
|
15957
|
+
}
|
|
15958
|
+
]
|
|
15959
|
+
},
|
|
15728
15960
|
{
|
|
15729
15961
|
"name": "Navbar",
|
|
15730
15962
|
"category": "navigation",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";const e=require("../../../hooks/useControllableState.cjs.js"),t=require("../../../hooks/useMergedRef.cjs.js"),n=require("../../../utils/cx.cjs.js"),r=require("../../data-display/Badge/Badge.cjs.js"),i=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),a=require("../../utilities/VisuallyHidden/VisuallyHidden.cjs.js"),o=require("./MobileNav.module.css.cjs.js");let s=require("react"),c=require("react/jsx-runtime");var l={bubbles:6,sparkle:6,confetti:10,glow:1,jelly:0,orbit:4,splash:8,none:0},u={surface:o.default.surface,solid:o.default.solid},d={sm:o.default.sm,md:o.default.md,lg:o.default.lg},f={fixed:o.default.fixed,sticky:o.default.sticky,static:o.default.static},p={accent:o.default.toneAccent,primary:o.default.tonePrimary,neutral:o.default.toneNeutral},m={sm:o.default.hideSm,md:o.default.hideMd,lg:o.default.hideLg},h=(0,s.createContext)(null);function g(r){let{children:a,placement:g=`bottom`,side:_=`start`,variant:v=`surface`,floating:y=!1,position:b=`fixed`,size:x=`md`,activeTone:S=`accent`,effect:C=`bubbles`,labels:w=`always`,hideAbove:T,reserveSpace:E=!0,value:D,defaultValue:O,onValueChange:k,className:A,"aria-label":j,ref:M,...N}=r,P=i.useMessages(),[F,I]=e.useControllableState({value:D,defaultValue:O,onChange:k}),L=(0,s.useRef)(null),R=t.useMergedRef(L,M),z=(0,s.useRef)(null),B=(0,s.useRef)(null),V=(0,s.useRef)(null),[H,U]=(0,s.useState)(0);return(0,s.useLayoutEffect)(()=>{let e=z.current,t=B.current;if(!e||!t)return;let n=e.querySelector(`[aria-current='page'] [data-pill]`),r=()=>{if(!n){t.removeAttribute(`data-visible`);return}let r=e.getBoundingClientRect(),i=n.getBoundingClientRect();t.style.setProperty(`--_x`,`${i.left+i.width/2-n.offsetWidth/2-r.left}px`),t.style.setProperty(`--_y`,`${i.top+i.height/2-n.offsetHeight/2-r.top}px`),t.style.setProperty(`--_w`,`${n.offsetWidth}px`),t.style.setProperty(`--_h`,`${n.offsetHeight}px`),t.setAttribute(`data-visible`,``),e.setAttribute(`data-ready`,``)};if(n!==V.current&&(V.current&&n&&(e.setAttribute(`data-moved`,``),U(e=>e+1)),V.current=n),r(),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(r);return i.observe(e),n&&i.observe(n),()=>i.disconnect()}),(0,s.useEffect)(()=>{let e=L.current;if(!e||b!==`fixed`||!E)return;let t=document.documentElement,n=[`scroll-padding-top`,`scroll-padding-bottom`,`scroll-padding-left`,`scroll-padding-right`,`--mobile-nav-offset`],r=n.map(e=>t.style.getPropertyValue(e)),i=()=>{let n=e.getBoundingClientRect(),r=window.innerWidth,i=window.innerHeight,a=n.width===0&&n.height===0,o,s;g===`bottom`?(o=`scroll-padding-bottom`,s=i-n.top):g===`top`?(o=`scroll-padding-top`,s=n.bottom):n.left+n.width/2<r/2?(o=`scroll-padding-left`,s=n.right):(o=`scroll-padding-right`,s=r-n.left);let c=`${a?0:Math.max(0,Math.round(s))}px`;t.style.setProperty(o,c),t.style.setProperty(`--mobile-nav-offset`,c)};i();let a=typeof ResizeObserver>`u`?null:new ResizeObserver(i);return a?.observe(e),window.addEventListener(`resize`,i),()=>{a?.disconnect(),window.removeEventListener(`resize`,i),n.forEach((e,n)=>{r[n]?t.style.setProperty(e,r[n]):t.style.removeProperty(e)})}},[g,b,E]),(0,c.jsx)(h.Provider,{value:{value:F,select:I,labels:w,variant:v},children:(0,c.jsx)(`nav`,{...N,ref:R,"aria-label":j??P.mobileNav.nav,"data-placement":g,"data-side":g===`side`?_:void 0,"data-labels":w,"data-effect":C,className:n.cx(o.default.root,u[v],d[x],f[b],p[S],y&&o.default.floating,T&&m[T],A),children:(0,c.jsxs)(`div`,{ref:z,className:o.default.track,children:[(0,c.jsxs)(`span`,{ref:B,className:o.default.bubble,"aria-hidden":`true`,children:[(0,c.jsx)(`span`,{className:o.default.bubbleShape},H),(0,c.jsx)(`span`,{className:o.default.indicator}),H>0&&l[C]>0&&(0,c.jsx)(`span`,{className:o.default.burst,children:Array.from({length:l[C]},(e,t)=>(0,c.jsx)(`span`,{className:o.default.particle,style:{"--_i":t,"--_n":l[C]}},t))},`burst-${H}`)]}),(0,c.jsx)(`ul`,{className:o.default.list,children:a})]})})})}var _=e=>e!==void 0&&e!==``&&e!==0;function v(e){let{as:t,value:i,active:l,icon:u,activeIcon:d,badge:f,badgeLabel:p,badgeTone:m,className:g,children:v,onClick:y,"aria-current":b,...x}=e,S=(0,s.useContext)(h);if(!S)throw Error(`MobileNav.Item must be used inside <MobileNav>.`);let C=t??`a`,w=l??(i!==void 0&&S.value===i),T=S.labels===`always`||S.labels===`active`&&w,E=S.variant===`solid`&&m===void 0,D=e=>{y?.(e),i!==void 0&&S.select(i)};return(0,c.jsx)(`li`,{className:o.default.item,children:(0,c.jsx)(C,{...x,"aria-current":w?`page`:b,onClick:D,className:n.cx(o.default.link,w&&o.default.active,g),children:(0,c.jsxs)(`span`,{className:o.default.pill,"data-pill":``,children:[(0,c.jsxs)(`span`,{className:o.default.icon,"aria-hidden":`true`,children:[w&&d!=null?d:u,_(f)&&(0,c.jsx)(`span`,{className:o.default.badge,children:(0,c.jsx)(r.Badge,{size:`sm`,variant:E?`inverse`:`solid`,tone:E?`primary`:m??`accent`,...typeof f==`number`?{count:f}:{children:f}})})]}),T?(0,c.jsx)(`span`,{className:o.default.label,children:v}):(0,c.jsx)(a.VisuallyHidden,{children:v}),_(f)&&(0,c.jsxs)(a.VisuallyHidden,{children:[` `,p??(typeof f==`number`&&f>99?`99+`:String(f))]})]})})})}v.displayName=`MobileNav.Item`,g.Item=v,exports.MobileNav=g,exports.MobileNavItem=v;
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { ComponentPropsWithRef, ElementType, ReactNode } from 'react';
|
|
2
|
+
import { Size, Tone } from '../../../types/common';
|
|
3
|
+
/**
|
|
4
|
+
* Which edge of the screen the bar sits on.
|
|
5
|
+
* - `bottom`: a tab bar along the bottom edge, in thumb reach. The default.
|
|
6
|
+
* - `top`: a bar along the top edge.
|
|
7
|
+
* - `side`: a vertical rail along the `side` edge (start or end, so it
|
|
8
|
+
* mirrors in right-to-left languages).
|
|
9
|
+
*/
|
|
10
|
+
export type MobileNavPlacement = "bottom" | "top" | "side";
|
|
11
|
+
/** Edge the `side` rail sits on. `start` is the left in left-to-right languages. */
|
|
12
|
+
export type MobileNavSide = "start" | "end";
|
|
13
|
+
/**
|
|
14
|
+
* Visual style.
|
|
15
|
+
* - `surface`: the surface color with muted icons. The default.
|
|
16
|
+
* - `solid`: a bold bar in the brand color with on-primary icons.
|
|
17
|
+
*/
|
|
18
|
+
export type MobileNavVariant = "surface" | "solid";
|
|
19
|
+
/**
|
|
20
|
+
* How the bar is positioned.
|
|
21
|
+
* - `fixed`: stays on its edge of the viewport while the page scrolls. The default.
|
|
22
|
+
* - `sticky`: sticks to its edge of the scroll container.
|
|
23
|
+
* - `static`: part of the normal flow (for previews, or your own positioning).
|
|
24
|
+
*/
|
|
25
|
+
export type MobileNavPosition = "fixed" | "sticky" | "static";
|
|
26
|
+
/**
|
|
27
|
+
* Which item labels are visible. Every item keeps its label as its
|
|
28
|
+
* accessible name, whichever you choose.
|
|
29
|
+
* - `always`: every label is shown under its icon. The default.
|
|
30
|
+
* - `active`: only the current item's label is shown.
|
|
31
|
+
* - `never`: icons only. Use icons people know (home, search, profile).
|
|
32
|
+
*/
|
|
33
|
+
export type MobileNavLabels = "always" | "active" | "never";
|
|
34
|
+
/**
|
|
35
|
+
* Color of the bubble behind the current item and its indicator bar.
|
|
36
|
+
* - `accent`: the theme's accent (see `Theme accent`).
|
|
37
|
+
* - `primary`: the brand color, so it follows `Theme brand`.
|
|
38
|
+
* - `neutral`: gray, for a quieter bar.
|
|
39
|
+
* The `solid` variant always uses the brand's darker shade with an on-primary indicator.
|
|
40
|
+
*/
|
|
41
|
+
export type MobileNavActiveTone = "accent" | "primary" | "neutral";
|
|
42
|
+
/**
|
|
43
|
+
* The animated effect that plays when the current item changes. Every effect
|
|
44
|
+
* is decorative, hidden from assistive technology and in Windows High
|
|
45
|
+
* Contrast, and reduced to a plain move with reduced motion.
|
|
46
|
+
* - `bubbles`: the bubble stretches as it slides, the icon pops, and small
|
|
47
|
+
* bubbles float up from it and fade. The default.
|
|
48
|
+
* - `sparkle`: four-pointed stars burst out around the item and twinkle.
|
|
49
|
+
* - `confetti`: little pieces of confetti in the chart colors pop up and tumble down.
|
|
50
|
+
* - `glow`: a soft glow swells around the bubble and fades.
|
|
51
|
+
* - `jelly`: the bubble wobbles like jelly as it lands, and the icon bounces.
|
|
52
|
+
* - `orbit`: dots circle the item once and fade.
|
|
53
|
+
* - `splash`: the bubble dips like something dropped into water, and
|
|
54
|
+
* droplets splash up from it in a fan and fall back.
|
|
55
|
+
* - `none`: no effect; the bubble just slides to the new item.
|
|
56
|
+
*/
|
|
57
|
+
export type MobileNavEffect = "bubbles" | "sparkle" | "confetti" | "glow" | "jelly" | "orbit" | "splash" | "none";
|
|
58
|
+
/** At this breakpoint and wider (sm 640px, md 768px, lg 1024px), the bar is hidden. */
|
|
59
|
+
export type MobileNavBreakpoint = "sm" | "md" | "lg";
|
|
60
|
+
/** A count or short text shown in an item's badge. */
|
|
61
|
+
export type MobileNavBadgeValue = number | string;
|
|
62
|
+
export interface MobileNavProps extends Omit<ComponentPropsWithRef<"nav">, "defaultValue" | "onChange"> {
|
|
63
|
+
/** `MobileNav.Item`s, usually three to five. */
|
|
64
|
+
children?: ReactNode;
|
|
65
|
+
/** Edge of the screen the bar sits on: `bottom`, `top`, or a `side` rail. @default "bottom" */
|
|
66
|
+
placement?: MobileNavPlacement;
|
|
67
|
+
/** With `placement="side"`, the edge the rail sits on (logical, so it mirrors in RTL). @default "start" */
|
|
68
|
+
side?: MobileNavSide;
|
|
69
|
+
/** Visual style. See `MobileNavVariant`. @default "surface" */
|
|
70
|
+
variant?: MobileNavVariant;
|
|
71
|
+
/** Detaches the bar from the edge as a rounded, shadowed island with space around it. @default false */
|
|
72
|
+
floating?: boolean;
|
|
73
|
+
/**
|
|
74
|
+
* `fixed` stays on its edge of the viewport; `sticky` sticks to its edge of
|
|
75
|
+
* the scroll container; `static` stays in the flow. @default "fixed"
|
|
76
|
+
*/
|
|
77
|
+
position?: MobileNavPosition;
|
|
78
|
+
/** Bar height (or rail width) and icon size. Bars: sm 56px, md 64px, lg 72px. Rails: sm 64px, md 80px, lg 96px. @default "md" */
|
|
79
|
+
size?: Size;
|
|
80
|
+
/**
|
|
81
|
+
* The animated effect when the current item changes: `bubbles`,
|
|
82
|
+
* `sparkle`, `confetti`, `glow`, `jelly`, `orbit`, `splash`, or `none` to
|
|
83
|
+
* turn it off. See `MobileNavEffect`. @default "bubbles"
|
|
84
|
+
*/
|
|
85
|
+
effect?: MobileNavEffect;
|
|
86
|
+
/** Color of the bubble and indicator behind the current item. @default "accent" */
|
|
87
|
+
activeTone?: MobileNavActiveTone;
|
|
88
|
+
/** Which labels are visible: `always`, only the `active` item's, or `never`. Labels are always the items' accessible names. @default "always" */
|
|
89
|
+
labels?: MobileNavLabels;
|
|
90
|
+
/** Hides the bar at this breakpoint and wider, e.g. `"md"` to show it only on phones. */
|
|
91
|
+
hideAbove?: MobileNavBreakpoint;
|
|
92
|
+
/**
|
|
93
|
+
* With `position="fixed"`, keeps focused and scrolled-to content clear of
|
|
94
|
+
* the bar (WCAG 2.4.11): while mounted, sets the matching `scroll-padding`
|
|
95
|
+
* on `<html>` to the space the bar covers, and `--mobile-nav-offset` on
|
|
96
|
+
* `<html>` to the same length, so the page can reserve room for it
|
|
97
|
+
* (`body { padding-block-end: var(--mobile-nav-offset, 0px) }` under a
|
|
98
|
+
* bottom bar). Both are restored on unmount, and are 0 while hidden by
|
|
99
|
+
* `hideAbove`. @default true
|
|
100
|
+
*/
|
|
101
|
+
reserveSpace?: boolean;
|
|
102
|
+
/** The current item's `value`, when controlled. An item's own `active` prop wins. */
|
|
103
|
+
value?: string;
|
|
104
|
+
/** The initially current item's `value`, when uncontrolled. Selecting an item makes it current. */
|
|
105
|
+
defaultValue?: string;
|
|
106
|
+
/** Called with an item's `value` when it's selected. */
|
|
107
|
+
onValueChange?: (value: string) => void;
|
|
108
|
+
/** Accessible name of the navigation landmark. @default "Main" (translated) */
|
|
109
|
+
"aria-label"?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* A mobile navigation bar: a bottom tab bar, a top bar, or a side rail of
|
|
113
|
+
* icon-and-label links. A bubble slides to the current item, with an
|
|
114
|
+
* animated `effect` (floating bubbles by default; also sparkle, confetti,
|
|
115
|
+
* glow, jelly, orbit, splash, or none). With reduced motion, the bubble simply
|
|
116
|
+
* moves without the effects.
|
|
117
|
+
*
|
|
118
|
+
* Renders a `<nav>` landmark with a list of links. The current item has
|
|
119
|
+
* `aria-current="page"` and is marked by the bubble's shape and an indicator
|
|
120
|
+
* bar, never by color alone. Every item keeps its label as its accessible
|
|
121
|
+
* name, even when labels are hidden.
|
|
122
|
+
*/
|
|
123
|
+
export declare function MobileNav(props: MobileNavProps): import("react").JSX.Element;
|
|
124
|
+
export declare namespace MobileNav {
|
|
125
|
+
var Item: typeof MobileNavItem;
|
|
126
|
+
}
|
|
127
|
+
interface MobileNavItemOwnProps<C extends ElementType = "a"> {
|
|
128
|
+
/**
|
|
129
|
+
* The element or component to render, e.g. your router's `Link`. Use a
|
|
130
|
+
* link for navigation; `"button"` suits an action such as opening a sheet.
|
|
131
|
+
* @default "a"
|
|
132
|
+
*/
|
|
133
|
+
as?: C;
|
|
134
|
+
/** Identifies the item for the root's `value` / `defaultValue` / `onValueChange`. */
|
|
135
|
+
value?: string;
|
|
136
|
+
/**
|
|
137
|
+
* Marks the item as the current page (`aria-current="page"`), whatever
|
|
138
|
+
* the root's `value`. Use it when your router knows the current page.
|
|
139
|
+
*/
|
|
140
|
+
active?: boolean;
|
|
141
|
+
/** The icon. Decorative: the label names the item. */
|
|
142
|
+
icon: ReactNode;
|
|
143
|
+
/** A different icon for the current item, e.g. a filled version, as an extra cue besides color. */
|
|
144
|
+
activeIcon?: ReactNode;
|
|
145
|
+
/**
|
|
146
|
+
* A count (shown with `Badge` `count`, capped at 99+, hidden at 0) or a
|
|
147
|
+
* short text such as "New", on the icon's corner. It's read after the
|
|
148
|
+
* label ("Messages 3").
|
|
149
|
+
*/
|
|
150
|
+
badge?: MobileNavBadgeValue;
|
|
151
|
+
/** Screen-reader text for the badge, e.g. "3 unread messages". Replaces the badge text in the accessible name. */
|
|
152
|
+
badgeLabel?: string;
|
|
153
|
+
/** Badge color. By default `accent`, or the bar's colors swapped on the `solid` variant. */
|
|
154
|
+
badgeTone?: Tone;
|
|
155
|
+
/** The label. Always the item's accessible name, even when hidden by `labels`. */
|
|
156
|
+
children: ReactNode;
|
|
157
|
+
}
|
|
158
|
+
/** Props for `MobileNav.Item`, typed for the component chosen with `as`. */
|
|
159
|
+
export type MobileNavItemProps<C extends ElementType = "a"> = MobileNavItemOwnProps<C> & Omit<ComponentPropsWithRef<C>, keyof MobileNavItemOwnProps<C>>;
|
|
160
|
+
/**
|
|
161
|
+
* One destination in a `MobileNav`: an icon over a label, in its own `<li>`.
|
|
162
|
+
* Selecting it makes it current when the root is uncontrolled (and calls
|
|
163
|
+
* `onValueChange`), even if a client-side router prevents the default
|
|
164
|
+
* navigation.
|
|
165
|
+
*/
|
|
166
|
+
export declare function MobileNavItem<C extends ElementType = "a">(props: MobileNavItemProps<C>): import("react").JSX.Element;
|
|
167
|
+
export declare namespace MobileNavItem {
|
|
168
|
+
var displayName: string;
|
|
169
|
+
}
|
|
170
|
+
export {};
|