Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/confirm-question-locale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

The confirm question for a named action (`confirm: true` on "Approve", "Suspend" and the like) is now worded by the locale, so Dhivehi reads "{name} {action}؟" instead of an English-ordered title with a Latin "?". Only delete actions add "This can't be undone." below.
5 changes: 5 additions & 0 deletions .changeset/dv-date-fns-locale.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

The Dhivehi date-fns locale now labels "afternoon" and "evening" as PM and "midnight" and "night" as AM, and parses short and narrow weekday names (`parse("އާދި", "EEE", …)`).
5 changes: 5 additions & 0 deletions .changeset/format-currency-english.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`useFormatCurrency` now brings its own English text, so it no longer renders the literal `common.currency` in a build where no other module loaded the `common` strings.
5 changes: 5 additions & 0 deletions .changeset/locale-load-retry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`OnuProvider locale="dv"` now retries a failed Dhivehi chunk load (after 1, 3 and 10 seconds, then when the browser comes back online) instead of staying in English for the rest of the session.
5 changes: 5 additions & 0 deletions .changeset/onu-locale-formatting.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`DataTable` date cells and chart tooltip numbers are now formatted with Onu's locale instead of the browser's, so Dhivehi pages show Dhivehi month names and server and client render the same text.
5 changes: 5 additions & 0 deletions .changeset/thaana-controlled-toggle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

A controlled `useThaanaInput({ enabled })` no longer drifts out of step when the Thaana shortcut is pressed and the parent keeps the value: the field keeps typing Thaana while it shows `dir="rtl"`. `attachThaanaKeyboard`'s `onToggle` now receives the requested state and leaves the change to you (call `setEnabled`); without `onToggle` the shortcut still flips the mode itself.
5 changes: 5 additions & 0 deletions .changeset/thaana-follows-element.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

The Thaana keyboard now attaches to fields that mount later or get replaced, so `CommandPalette thaana` types Thaana and a `TextInput` keeps typing Thaana after an `endAddon` appears. `useThaanaInput(options)` and `useThaanaField(thaana)` now return a callback `ref` to put on the element instead of taking a ref object.
5 changes: 5 additions & 0 deletions .changeset/thaana-multiline-paste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

`paste: "transliterate"` now converts pastes that contain line breaks or tabs, so multi-line Latin text pasted into a Thaana `Textarea` becomes Thaana.
5 changes: 5 additions & 0 deletions .changeset/thaana-select-typeahead.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@javaabu/onu": patch
---

Typing on a closed select with `thaana` now starts the search with the Thaana letter (`ކ`, not `k`).
2 changes: 1 addition & 1 deletion docs/charts/category-chart.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Reduced motion still wins inside `<ChartAnimationProvider animate>`. `useChartAn

## Primitives

The shadcn primitives are exported from the same entry for custom charts: `ChartContainer`, `ChartTooltip`, `ChartTooltipContent` (with an Onu `valueFormatter` prop), `ChartLegend`, `ChartLegendContent`, `ChartStyle` and the `ChartConfig` type. They are not exported from the package root, so `recharts` stays optional.
The shadcn primitives are exported from the same entry for custom charts: `ChartContainer`, `ChartTooltip`, `ChartTooltipContent` (with an Onu `valueFormatter` prop; without it, numbers use Onu's number locale), `ChartLegend`, `ChartLegendContent`, `ChartStyle` and the `ChartConfig` type. They are not exported from the package root, so `recharts` stays optional.

## RTL

Expand Down
2 changes: 1 addition & 1 deletion docs/guides/dhivehi-and-locales.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { dv } from '@javaabu/onu/locales/dv';
Only apps that use Dhivehi download its text (about 15 kB brotli):

- `locale={dv}`, with `dv` imported from `@javaabu/onu/locales/dv`, bundles Dhivehi with your app. The first render is already in Dhivehi. Use this when Dhivehi is the main or a common language.
- `locale="dv"` loads Dhivehi on demand, as a separate chunk, when the provider first needs it. Direction and `lang` switch at once, and strings show in English until the chunk arrives (usually within the first frames). This suits a language switcher in a mostly English app.
- `locale="dv"` loads Dhivehi on demand, as a separate chunk, when the provider first needs it. Direction and `lang` switch at once, and strings show in English until the chunk arrives (usually within the first frames). A failed load is retried after 1, 3 and 10 seconds, then again when the browser comes back online. This suits a language switcher in a mostly English app.
- English needs nothing: leave out `locale` (or pass `"en"`). Each component brings the English text it uses, so a page with a text field does not carry the strings of the data table, the map or the editor.

`import { dv } from '@javaabu/onu'` still works too; it bundles Dhivehi like the `locales/dv` import.
Expand Down
7 changes: 5 additions & 2 deletions docs/guides/thaana-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ Pass your own map with `createKeymap(latinKeys, thaanaCharacters)`.
import { useThaanaInput, attachThaanaKeyboard, transliterate } from '@javaabu/onu/thaana';

function MyField() {
const ref = useRef<HTMLInputElement>(null);
const { enabled, toggle } = useThaanaInput(ref, { keymap: 'phonetic' });
// `ref` is a callback ref: the keyboard follows the element, even one that mounts later.
const { ref, enabled, toggle } = useThaanaInput<HTMLInputElement>({ keymap: 'phonetic' });
return <input ref={ref} dir={enabled ? 'rtl' : 'auto'} lang="dv" />;
}

Expand All @@ -54,6 +54,9 @@ const keyboard = attachThaanaKeyboard(document.querySelector('#name'));
keyboard.setEnabled(false);
keyboard.detach();

// Own the state: with onToggle, Alt+Shift+T asks instead of flipping the mode itself.
const owned = attachThaanaKeyboard(input, { onToggle: (next) => owned.setEnabled(next) });

transliterate('dhivehi'); // "ދހިވެހި"
```

Expand Down
2 changes: 1 addition & 1 deletion docs/listing-pages/data-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ The table always shows the rows it is given (it never sorts or pages by itself):

Other `<div>` props and `ref` go to the root.

`DataTableColumn<T>`: `id`, `header` (text), `headerContent?`, `accessor?` (key or function), `cell?`, `sortable?`, `hideable?`, `primary?`, `align?`, `numeric?` (tabular figures, end-aligned), `hideOnCards?`, `className?`, `headerClassName?`.
`DataTableColumn<T>`: `id`, `header` (text), `headerContent?`, `accessor?` (key or function), `cell?`, `sortable?`, `hideable?`, `primary?`, `align?`, `numeric?` (tabular figures, end-aligned), `hideOnCards?`, `className?`, `headerClassName?`. Without `cell`, a `Date` value is shown with Onu's locale (`useFormatDate`, "Jan 2, 2026" / "2 ޖެނުއަރީ 2026"), not the browser's.

## Accessibility

Expand Down
2 changes: 1 addition & 1 deletion docs/overlays/action-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const { t } = useTranslation()
<ActionMenu name={user.name} items={trashActions(t, { onRestore, onForceDelete })} />
```

A destructive action (or `confirm: true`) asks "Delete Jane Doe?" for `id: "delete"`, "Permanently delete Jane Doe?" for `id: "force-delete"`, and "{label} Jane Doe?" otherwise, with "This can't be undone." below; `confirm` options replace any part of that. The dialog is styled even without a `ConfirmProvider`.
A destructive action (or `confirm: true`) asks "Delete Jane Doe?" for `id: "delete"`, "Permanently delete Jane Doe?" for `id: "force-delete"`, and "{label} Jane Doe?" otherwise (worded by the locale, so Dhivehi puts the name first and ends with "؟"). Only `id: "delete"` and `id: "force-delete"` add a "can't be undone" warning; `confirm` options replace any part of that. The dialog is styled even without a `ConfirmProvider`.

### `RecordAction`

Expand Down
3 changes: 1 addition & 2 deletions docs/text-inputs/thaana-toggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { ThaanaToggle } from "@javaabu/onu"
import { useThaanaInput } from "@javaabu/onu/thaana"

function MyField() {
const ref = useRef<HTMLInputElement>(null)
const { enabled, toggle } = useThaanaInput(ref)
const { ref, enabled, toggle } = useThaanaInput<HTMLInputElement>()
return (
<div className="gap-2 flex">
<input ref={ref} dir={enabled ? "rtl" : "auto"} />
Expand Down
9 changes: 5 additions & 4 deletions packages/onu/src/components/choice/_combobox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Command as CommandPrimitive } from "cmdk"
import { Icon } from "../../icons/icon"
import { cn } from "../../lib/utils"
import { useTranslation } from "../../providers/onu-provider"
import { transliterate } from "../../thaana/convert"
import { useThaanaField, type ThaanaProp } from "../../thaana/use-thaana-field"
import { Badge } from "../../ui/badge"
import { Button } from "../../ui/button"
Expand Down Expand Up @@ -138,8 +139,7 @@ function SearchField({
className?: string
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>
}) {
const ref = React.useRef<HTMLInputElement>(null)
const { fieldProps } = useThaanaField(ref, thaana)
const { ref, fieldProps } = useThaanaField<HTMLInputElement>(thaana)
return (
<div data-slot="choice-search" className="p-1 pb-0">
<div className="h-8 gap-2 px-2 touch:h-11 flex items-center rounded-lg border border-input/30 bg-input/30">
Expand Down Expand Up @@ -275,9 +275,10 @@ export function ComboboxCore({
e.preventDefault()
setOpen(true)
} else if (e.key.length === 1 && e.key !== " " && !e.ctrlKey && !e.metaKey && !e.altKey) {
// Typing on the closed field starts a search.
// Typing on the closed field starts a search, in Thaana when the search field types Thaana.
e.preventDefault()
onQueryChange(e.key)
const thaanaOn = !!thaana && (typeof thaana !== "object" || thaana.defaultEnabled !== false)
onQueryChange(thaanaOn ? transliterate(e.key, typeof thaana === "object" ? thaana.keymap : undefined) : e.key)
setOpen(true)
} else if ((e.key === "Backspace" || e.key === "Delete") && clearable && !required && selected.length) {
e.preventDefault()
Expand Down
3 changes: 1 addition & 2 deletions packages/onu/src/components/choice/account-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ function SearchInput({
placeholder: string
thaana?: ThaanaProp
}) {
const ref = React.useRef<HTMLInputElement>(null)
const { fieldProps } = useThaanaField(ref, thaana)
const { ref, fieldProps } = useThaanaField<HTMLInputElement>(thaana)
return (
<div className="p-1 pb-0">
<div className="h-8 gap-2 px-2 touch:h-11 flex items-center rounded-lg border border-input/30 bg-input/30">
Expand Down
3 changes: 1 addition & 2 deletions packages/onu/src/components/choice/dual-listbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ function FilterInput({
disabled?: boolean
className?: string
}) {
const ref = React.useRef<HTMLInputElement>(null)
const { fieldProps } = useThaanaField(ref, thaana)
const { ref, fieldProps } = useThaanaField<HTMLInputElement>(thaana)
return (
<div className="relative">
<Icon
Expand Down
18 changes: 18 additions & 0 deletions packages/onu/src/components/choice/searchable-select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ describe("SearchableSelect", () => {
expect(await screen.findByRole("combobox", { name: "Search…" })).toHaveValue("a")
})

it("seeds the search with the Thaana letter when typing on a closed thaana field", async () => {
const user = userEvent.setup()
renderWithOnu(<SearchableSelect aria-label="ރަށް" options={dvIslands} thaana />, { locale: "dv" })
screen.getByRole("combobox", { name: "ރަށް" }).focus()
await user.keyboard("k")
expect(await screen.findByRole("combobox", { name: "ހޯއްދަވާ…" })).toHaveValue("ކ")
})

it("seeds the search with the Latin key when thaana starts off", async () => {
const user = userEvent.setup()
renderWithOnu(<SearchableSelect aria-label="ރަށް" options={dvIslands} thaana={{ defaultEnabled: false }} />, {
locale: "dv",
})
screen.getByRole("combobox", { name: "ރަށް" }).focus()
await user.keyboard("k")
expect(await screen.findByRole("combobox", { name: "ހޯއްދަވާ…" })).toHaveValue("k")
})

it("is controlled and clearable on optional fields", async () => {
function Controlled() {
const [value, setValue] = React.useState<string | null>("male")
Expand Down
10 changes: 8 additions & 2 deletions packages/onu/src/components/inputs/tags-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ export function TagsInput({
const { t } = useTranslation()
const local = React.useRef<HTMLInputElement>(null)
const anchorRef = React.useRef<HTMLDivElement>(null)
const merged = useMergedRef(local, ref)
const [tags, setTags] = useControllableState(valueProp, defaultValue, onValueChange)
const [text, setText] = React.useState("")
const [announce, setAnnounce] = React.useState<string | null>(null)
const { fieldProps, active: thaanaActive, enabled: thaanaOn, toggle } = useThaanaField(local, thaana)
const {
ref: thaanaRef,
fieldProps,
active: thaanaActive,
enabled: thaanaOn,
toggle,
} = useThaanaField<HTMLInputElement>(thaana)
const merged = useMergedRef(local, thaanaRef, ref)
const { name, ...control } = useFormFieldControl({ ...props, disabled: disabledProp })
const disabled = !!control.disabled
const full = max !== undefined && tags.length >= max
Expand Down
8 changes: 8 additions & 0 deletions packages/onu/src/components/inputs/text-input.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ describe("TextInput", () => {
expect(input).toHaveValue("ަހމަދު")
})

it("keeps typing Thaana when an end addon replaces the input node", () => {
const { rerender } = renderWithOnu(<TextInput aria-label="Name" thaana />)
rerender(<TextInput aria-label="Name" thaana endAddon="MVR" />)
const input = screen.getByRole("textbox")
typeThaana(input, "ahmadu")
expect(input).toHaveValue("ަހމަދު")
})

it("toggles Thaana with the toggle button and announces it", async () => {
renderWithOnu(<TextInput aria-label="Name" thaana thaanaToggle />)
const toggle = screen.getByRole("button", { name: /Thaana and Latin/ })
Expand Down
11 changes: 8 additions & 3 deletions packages/onu/src/components/inputs/text-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ export function TextInput({
ref,
...props
}: TextInputProps) {
const local = React.useRef<HTMLInputElement>(null)
const merged = useMergedRef(local, ref)
const latin = props.type === "email" || props.type === "url"
const { fieldProps, active, enabled, toggle } = useThaanaField(local, latin ? undefined : thaana)
const {
ref: thaanaRef,
fieldProps,
active,
enabled,
toggle,
} = useThaanaField<HTMLInputElement>(latin ? undefined : thaana)
const merged = useMergedRef(thaanaRef, ref)
const controlProps = useFormFieldControl(latin ? latinProps(props, urlProtocol) : props)
const showToggle = active && thaanaToggle
const end =
Expand Down
5 changes: 2 additions & 3 deletions packages/onu/src/components/inputs/textarea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export function Textarea({
onChange,
...props
}: TextareaProps) {
const local = React.useRef<HTMLTextAreaElement>(null)
const merged = useMergedRef(local, ref)
const { fieldProps, active, enabled, toggle } = useThaanaField(local, thaana)
const { ref: thaanaRef, fieldProps, active, enabled, toggle } = useThaanaField<HTMLTextAreaElement>(thaana)
const merged = useMergedRef(thaanaRef, ref)
const controlProps = useFormFieldControl(props)
const [typed, setTyped] = React.useState(() => String(props.defaultValue ?? "").length)
const count = props.value !== undefined ? String(props.value).length : typed
Expand Down
14 changes: 14 additions & 0 deletions packages/onu/src/components/listing/data-table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,20 @@ describe("DataTable", () => {
expect(screen.getByRole("columnheader", { name: /Name/ })).toHaveAttribute("aria-sort", "ascending")
})

it("formats dates with Onu's locale, not the browser's", () => {
renderWithOnu(
<DataTable
columns={[
{ id: "name", header: "ނަން" },
{ id: "joined", header: "ތާރީޚު" },
]}
data={[{ id: "a", name: "ޢަލީ", joined: new Date(2026, 0, 2) }]}
/>,
{ locale: "dv" },
)
expect(screen.getAllByText("2 ޖެނުއަރީ 2026").length).toBeGreaterThan(0)
})

it("supports a custom empty state and pagination without a total", () => {
renderWithOnu(<DataTable columns={userColumns} data={[]} empty={<p>Nothing</p>} pagination />)
expect(screen.getByText("Nothing")).toBeInTheDocument()
Expand Down
8 changes: 5 additions & 3 deletions packages/onu/src/components/listing/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { cva, type VariantProps } from "class-variance-authority"

import { useAnnouncer } from "../../a11y/use-announcer"
import { useIsMobile } from "../../hooks/use-mobile"
import { useFormatDate } from "../../i18n/format"
import { Icon } from "../../icons/icon"
import { cn } from "../../lib/utils"
import { useLinkComponent, useTranslation } from "../../providers/onu-provider"
Expand Down Expand Up @@ -143,9 +144,9 @@ function valueOf<T extends RowData>(column: DataTableColumn<T>, row: T): unknown
return row[key]
}

function display(value: unknown): React.ReactNode {
function display(value: unknown, formatDate: (date: Date) => string): React.ReactNode {
if (value === null || value === undefined || value === "") return null
if (value instanceof Date) return value.toLocaleDateString()
if (value instanceof Date) return formatDate(value)
if (typeof value === "string" || typeof value === "number") return value
return String(value)
}
Expand Down Expand Up @@ -190,6 +191,7 @@ export function DataTable<T extends RowData>({
...props
}: DataTableProps<T>) {
const { t } = useTranslation()
const formatDate = useFormatDate()
const Link = useLinkComponent()
const internal = useListingState({ url: false })
const state = stateProp ?? internal
Expand Down Expand Up @@ -291,7 +293,7 @@ export function DataTable<T extends RowData>({
const clickable = !!onRowClick || !!getRowHref

const renderValue = (column: DataTableColumn<T>, row: T) => {
const content = column.cell ? column.cell(row) : display(valueOf(column, row))
const content = column.cell ? column.cell(row) : display(valueOf(column, row), formatDate)
const shown = content ?? <span className="text-muted-foreground">{t("common.emptyValue")}</span>
if (column !== primary) return shown
const href = getRowHref?.(row)
Expand Down
4 changes: 2 additions & 2 deletions packages/onu/src/components/listing/search-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export function SearchBox({
}: SearchBoxProps) {
const { t } = useTranslation()
const local = React.useRef<HTMLInputElement>(null)
const merged = useMergedRef(local, ref)
const { fieldProps } = useThaanaField(local, thaana)
const { ref: thaanaRef, fieldProps } = useThaanaField<HTMLInputElement>(thaana)
const merged = useMergedRef(local, thaanaRef, ref)
const controlProps = useFormFieldControl(props)

const [applied, setApplied] = React.useState(value ?? defaultValue)
Expand Down
13 changes: 10 additions & 3 deletions packages/onu/src/components/overlays/_menu-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ export function needsConfirm(item: MenuActionItem) {
* The question to ask before running an item. With a record `name`, `true`
* (or a `destructive` item) asks "Delete Jane Doe?" (`id: "delete"`),
* "Permanently delete Jane Doe?" (`id: "force-delete"`) or "Approve Jane Doe?"
* (the item's label), and given options are laid over that question.
* (the item's label, worded by the locale's `listing.actionRecordTitle`), and
* given options are laid over that question. Only deletes add "This can't be undone."
*/
export function useConfirmQuestion(name?: string) {
const { t } = useTranslation()
Expand All @@ -167,9 +168,15 @@ export function useConfirmQuestion(name?: string) {
variant: "destructive",
...custom,
}
const action = textOf(item.label)
const isDelete = item.id === "delete"
return {
title: item.id === "delete" ? t("listing.deleteRecordTitle", { name }) : `${textOf(item.label)} ${name}?`,
description: t("listing.deleteRecordDescription"),
title: isDelete
? t("listing.deleteRecordTitle", { name })
: action
? t("listing.actionRecordTitle", { action, name })
: undefined,
description: isDelete ? t("listing.deleteRecordDescription") : undefined,
confirmLabel: item.label,
variant: destructive ? "destructive" : "default",
...custom,
Expand Down
13 changes: 12 additions & 1 deletion packages/onu/src/components/overlays/action-menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,18 @@ describe("ActionMenu with a record name", () => {

await userEvent.click(screen.getByRole("button", { name: "Actions for Form 12" }))
await userEvent.click(await screen.findByRole("menuitem", { name: "Suspend" }))
expect(await screen.findByRole("alertdialog", { name: "Suspend Form 12?" })).toBeInTheDocument()
const suspend = await screen.findByRole("alertdialog", { name: "Suspend Form 12?" })
expect(within(suspend).queryByText("This can't be undone.")).not.toBeInTheDocument()
await userEvent.keyboard("{Escape}")
})

it("words the confirm question in the locale's order", async () => {
renderWithOnu(<ActionMenu name="ފޯމް 12" items={[{ id: "suspend", label: "ހުއްޓާލާ", confirm: true }]} />, {
locale: "dv",
})
await userEvent.click(screen.getAllByRole("button")[0]!)
await userEvent.click(await screen.findByRole("menuitem", { name: "ހުއްޓާލާ" }))
expect(await screen.findByRole("alertdialog", { name: "ފޯމް 12 ހުއްޓާލާ؟" })).toBeInTheDocument()
await userEvent.keyboard("{Escape}")
})

Expand Down
Loading
Loading