mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-13 15:51:00 +00:00
ba70ad28b8
Arabic runs the app right to left, but margins, paddings, insets, text alignment, borders and corner radii were written for the left side, so icons sat against the wrong edge of their labels, indents and badges pointed the wrong way and amount columns aligned left. They now use the logical forms (ms-, ps-, start-, text-start, marginInlineStart, insetInlineEnd and their CSS equivalents), which are the very same sides in a left to right language. Geometry stays physical on purpose: maps, positions measured from the pointer or a bounding box, time axes, sliders, transforms and print output. Amounts drawn as several spans keep their order in a right to left row, the time picker keeps hours before minutes, and two switches whose thumb slid out of its track in Arabic now move the right way. lint:rtl counts what is still physical per file against a baseline that may only shrink (1512 uses in 370 files before, 319 in 113 now), and CI runs it, so new code reaches for the logical forms.
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { useState, useEffect, useRef } from 'react'
|
|
import { Tooltip } from '../shared/Tooltip'
|
|
|
|
interface EditableCatNameProps {
|
|
name: string
|
|
onRename: (newName: string) => void
|
|
/** The tooltip on the name, e.g. "Rename". */
|
|
renameLabel?: string
|
|
}
|
|
|
|
export function EditableCatName({ name, onRename, renameLabel = 'Click to rename' }: EditableCatNameProps) {
|
|
const [editing, setEditing] = useState(false)
|
|
const [value, setValue] = useState(name)
|
|
const inputRef = useRef(null)
|
|
|
|
useEffect(() => { if (editing && inputRef.current) { inputRef.current.focus(); inputRef.current.select() } }, [editing])
|
|
|
|
const save = () => {
|
|
setEditing(false)
|
|
if (value.trim() && value.trim() !== name) onRename(value.trim())
|
|
else setValue(name)
|
|
}
|
|
|
|
if (editing) {
|
|
return <input ref={inputRef} value={value} onChange={e => setValue(e.target.value)}
|
|
onBlur={save}
|
|
onKeyDown={e => {
|
|
if (e.key === 'Enter') save()
|
|
// Escape only drops the rename; the dialog around it stays open.
|
|
if (e.key === 'Escape') { e.preventDefault(); setValue(name); setEditing(false) }
|
|
}}
|
|
className="min-w-0 flex-1 rounded-[8px] border border-edge bg-surface-input px-2 py-0.5 font-semibold text-content outline-none focus:ring-2 focus:ring-[color:var(--text-primary)]"
|
|
style={{ fontSize: 'calc(13px * var(--fs-scale-body, 1))' }} />
|
|
}
|
|
|
|
return (
|
|
<Tooltip label={renameLabel}>
|
|
<button type="button" onClick={() => { setValue(name); setEditing(true) }}
|
|
className="min-w-0 flex-1 truncate py-0.5 text-start font-semibold text-content hover:underline hover:decoration-edge"
|
|
style={{ fontSize: 'calc(13px * var(--fs-scale-body, 1))' }}>
|
|
{name}
|
|
</button>
|
|
</Tooltip>
|
|
)
|
|
}
|