mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-05 06:36:34 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
acb897d25b | ||
|
|
7a08b5e3eb | ||
|
|
306168fee5 | ||
|
|
1a8f32014e |
+28
-8
@@ -307,7 +307,7 @@
|
||||
{
|
||||
"name": "react-native",
|
||||
"importNames": ["TextInput"],
|
||||
"message": "Use EditingTextInput from @/components/ui/text-input. Raw TextInput bypasses editing-surface authority and IME safety."
|
||||
"message": "Use FormTextInput from @/components/ui/form-field (or SearchField from @/components/ui/search-field). Raw TextInput bypasses form chrome, editing-surface authority, and IME safety."
|
||||
},
|
||||
{
|
||||
"name": "@tanstack/react-query",
|
||||
@@ -338,7 +338,7 @@
|
||||
{
|
||||
"name": "react-native",
|
||||
"importNames": ["TextInput"],
|
||||
"message": "Use EditingTextInput from @/components/ui/text-input. Raw TextInput bypasses editing-surface authority and IME safety."
|
||||
"message": "Use FormTextInput from @/components/ui/form-field (or SearchField from @/components/ui/search-field). Raw TextInput bypasses form chrome, editing-surface authority, and IME safety."
|
||||
},
|
||||
{
|
||||
"name": "react-native-unistyles",
|
||||
@@ -390,7 +390,7 @@
|
||||
{
|
||||
"name": "react-native",
|
||||
"importNames": ["TextInput"],
|
||||
"message": "Use EditingTextInput from @/components/ui/text-input. Raw TextInput bypasses editing-surface authority and IME safety."
|
||||
"message": "Use FormTextInput from @/components/ui/form-field (or SearchField from @/components/ui/search-field). Raw TextInput bypasses form chrome, editing-surface authority, and IME safety."
|
||||
},
|
||||
{
|
||||
"name": "react-native-unistyles",
|
||||
@@ -431,7 +431,6 @@
|
||||
"packages/app/src/components/realtime-voice-overlay.tsx",
|
||||
"packages/app/src/components/resize-handle.tsx",
|
||||
"packages/app/src/components/rewind/rewind-menu.tsx",
|
||||
"packages/app/src/components/settings-textarea.tsx",
|
||||
"packages/app/src/components/sidebar-callout.tsx",
|
||||
"packages/app/src/components/split-container.tsx",
|
||||
"packages/app/src/components/split-drop-zone.tsx",
|
||||
@@ -457,7 +456,6 @@
|
||||
"packages/app/src/desktop/updates/update-callout-source.tsx",
|
||||
"packages/app/src/git/actions-split-button.tsx",
|
||||
"packages/app/src/hooks/use-web-scrollbar-style.web.ts",
|
||||
"packages/app/src/hosts/host-chooser.tsx",
|
||||
"packages/app/src/screens/open-project-screen.tsx",
|
||||
"packages/app/src/screens/projects-screen.tsx",
|
||||
"packages/app/src/screens/sessions-screen.tsx",
|
||||
@@ -476,7 +474,7 @@
|
||||
{
|
||||
"name": "react-native",
|
||||
"importNames": ["TextInput"],
|
||||
"message": "Use EditingTextInput from @/components/ui/text-input. Raw TextInput bypasses editing-surface authority and IME safety."
|
||||
"message": "Use FormTextInput from @/components/ui/form-field (or SearchField from @/components/ui/search-field). Raw TextInput bypasses form chrome, editing-surface authority, and IME safety."
|
||||
},
|
||||
{
|
||||
"name": "@tanstack/react-query",
|
||||
@@ -506,7 +504,7 @@
|
||||
{
|
||||
"name": "react-native",
|
||||
"importNames": ["TextInput"],
|
||||
"message": "Use EditingTextInput from @/components/ui/text-input. Raw TextInput bypasses editing-surface authority and IME safety."
|
||||
"message": "Use FormTextInput from @/components/ui/form-field (or SearchField from @/components/ui/search-field). Raw TextInput bypasses form chrome, editing-surface authority, and IME safety."
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -525,7 +523,29 @@
|
||||
{
|
||||
"files": ["packages/app/src/**/*.{ts,tsx}"],
|
||||
"rules": {
|
||||
"paseo/no-raw-pressable": "error"
|
||||
"paseo/no-raw-pressable": "error",
|
||||
"paseo/no-raw-text-input": "error"
|
||||
}
|
||||
},
|
||||
// Styled input chrome and focus rings are owned by FormTextInput / SearchField in
|
||||
// components/ui. Only UI primitives, tests, and the small bespoke editor allowlist below may
|
||||
// import raw EditingTextInput directly.
|
||||
{
|
||||
"files": [
|
||||
"packages/app/src/components/ui/**/*.{ts,tsx}",
|
||||
"packages/app/src/**/*.{test,spec}.{ts,tsx}",
|
||||
"packages/app/src/command-center/command-center.tsx",
|
||||
"packages/app/src/components/adaptive-modal-sheet.tsx",
|
||||
"packages/app/src/components/file-explorer-pane.tsx",
|
||||
"packages/app/src/composer/input/input.tsx",
|
||||
"packages/app/src/desktop/browser/pane/index.electron.tsx",
|
||||
"packages/app/src/pane-find/index.tsx",
|
||||
"packages/app/src/plugins/react-native/text-input.tsx",
|
||||
"packages/app/src/terminal/native-renderer/terminal-input.native.tsx",
|
||||
"packages/app/src/workspace-rename/internal/inline-title-field.tsx"
|
||||
],
|
||||
"rules": {
|
||||
"paseo/no-raw-text-input": "off"
|
||||
}
|
||||
},
|
||||
// Press feedback is owned by the primitives in components/ui. Raw pressable burn-down:
|
||||
|
||||
+5
-4
@@ -20,7 +20,7 @@ A semantic element used in three or more places is a primitive. One of a kind is
|
||||
|
||||
Primitives live in `packages/app/src/components/ui/` and `packages/app/src/components/headers/`. Card and row layout live in `packages/app/src/styles/settings.ts`. Section structure lives in `packages/app/src/screens/settings/settings-section.tsx`.
|
||||
|
||||
A pressable styled to look like a button is wrong; the button is `<Button>` (`packages/app/src/components/ui/button.tsx`). A pressable wrapping an icon is wrong; the icon action is `<ToolbarButton>` (`packages/app/src/components/ui/pane-content-toolbar.tsx`), which owns the hitbox, the rounded `interactionHighlight` fill on hover and press, the compact size, and the tooltip. Rows on a menu surface are `<MenuItem>`, or `<ComposerTrackRow>` in a track panel; other rows are `<PressHighlight>` (`packages/app/src/components/ui/press-highlight.tsx`), which owns the pressed feedback: pass the pressed fill as `highlightStyle` and never paint it in your own style. iOS and web paint that fill; Android draws the platform ripple over the content instead, clipped to the row's corners. On native, feedback waits for a short press delay so a scroll that claims the touch shows none. Content that knocks out of the row's surface, such as a badge ring, follows the fill through `onHighlightChange`. A bare `<Text>` styled to look like a section header is wrong; the section header is `<SettingsSection>` (`packages/app/src/components/settings/headings/settings-section.tsx`). A docs link in its header is its `link` prop, which renders `Label ↗` on the title's rail; a ghost button with an arrow is wrong. A custom `Modal` for a confirmation is wrong; the confirmation is `confirmDialog` (`packages/app/src/utils/confirm-dialog.ts`). A hand-rolled overflow menu is wrong; the menu is `<DropdownMenu>` (`packages/app/src/components/ui/dropdown-menu.tsx`). A hand-rolled status pill is wrong; the pill is `<StatusBadge>` (`packages/app/src/components/ui/status-badge.tsx`). A circle pinned over a scrolling surface is wrong; the floating action is `<FloatingActionButton>` (`packages/app/src/components/ui/floating-action-button.tsx`), one per surface, and the surface reserves `FLOATING_ACTION_BUTTON_CLEARANCE` below its content so the button never traps the last row.
|
||||
A pressable styled to look like a button is wrong; the button is `<Button>` (`packages/app/src/components/ui/button.tsx`). A hand-styled text input or textarea is wrong; form fields use `<Field>` and `<FormTextInput>` (`packages/app/src/components/ui/form-field.tsx`), and search inputs use `<SearchField>` (`packages/app/src/components/ui/search-field.tsx`). A pressable wrapping an icon is wrong; the icon action is `<ToolbarButton>` (`packages/app/src/components/ui/pane-content-toolbar.tsx`), which owns the hitbox, the rounded `interactionHighlight` fill on hover and press, the compact size, and the tooltip. Rows on a menu surface are `<MenuItem>`, or `<ComposerTrackRow>` in a track panel; other rows are `<PressHighlight>` (`packages/app/src/components/ui/press-highlight.tsx`), which owns the pressed feedback: pass the pressed fill as `highlightStyle` and never paint it in your own style. iOS and web paint that fill; Android draws the platform ripple over the content instead, clipped to the row's corners. On native, feedback waits for a short press delay so a scroll that claims the touch shows none. Content that knocks out of the row's surface, such as a badge ring, follows the fill through `onHighlightChange`. A bare `<Text>` styled to look like a section header is wrong; the section header is `<SettingsSection>` (`packages/app/src/components/settings/headings/settings-section.tsx`). A docs link in its header is its `link` prop, which renders `Label ↗` on the title's rail; a ghost button with an arrow is wrong. A custom `Modal` for a confirmation is wrong; the confirmation is `confirmDialog` (`packages/app/src/utils/confirm-dialog.ts`). A hand-rolled overflow menu is wrong; the menu is `<DropdownMenu>` (`packages/app/src/components/ui/dropdown-menu.tsx`). A hand-rolled status pill is wrong; the pill is `<StatusBadge>` (`packages/app/src/components/ui/status-badge.tsx`). A circle pinned over a scrolling surface is wrong; the floating action is `<FloatingActionButton>` (`packages/app/src/components/ui/floating-action-button.tsx`), one per surface, and the surface reserves `FLOATING_ACTION_BUTTON_CLEARANCE` below its content so the button never traps the last row.
|
||||
|
||||
Before adding a new component, read `components/ui/`. The primitive usually exists.
|
||||
|
||||
@@ -35,7 +35,7 @@ The authored interface ramp uses a 14px base. New native installs default to 15p
|
||||
Weight has three tiers, applied by role:
|
||||
|
||||
- **Screen titles** — the title in app chrome — use `<ScreenTitle>` (`packages/app/src/components/headers/screen-title.tsx`), which renders `fontSize.base` at weight `400` on compact and `300` on desktop. The New workspace hero is the only larger product title; it uses `fontSize["2xl"]` (`packages/app/src/screens/new-workspace-screen.tsx`).
|
||||
- **Structural labels** use `fontWeight.medium`. This applies to section labels above a stack of rows (`packages/app/src/components/agent-list.tsx:519-523`, `packages/app/src/components/keyboard-shortcuts-dialog.tsx:63-67`), form field labels above an input inside a modal (`packages/app/src/hosts/add-host/internal/add-host-modal.tsx:19-23`, `packages/app/src/hosts/add-host/internal/pair-link-modal.tsx:24-28`), the title at the top of a modal/sheet/dialog (`packages/app/src/components/adaptive-modal-sheet.tsx:90-94`, `packages/app/src/components/ui/combobox.tsx:1607-1611`, `packages/app/src/components/welcome-screen.tsx:48-53`), action button labels in tight components such as the sidebar callout actions (`packages/app/src/components/sidebar-callout.tsx:218-221`), and inline data emphasis on dense metadata rows (`packages/app/src/components/git-diff-pane.tsx:2322-2327`, `packages/app/src/components/file-explorer-pane.tsx:1115-1122`).
|
||||
- **Structural labels** use `fontWeight.medium`. This applies to section labels above a stack of rows (`packages/app/src/components/agent-list.tsx:519-523`, `packages/app/src/components/keyboard-shortcuts-dialog.tsx:63-67`), the title at the top of a modal/sheet/dialog (`packages/app/src/components/adaptive-modal-sheet.tsx:90-94`, `packages/app/src/components/ui/combobox.tsx:1607-1611`, `packages/app/src/components/welcome-screen.tsx:48-53`), action button labels in tight components such as the sidebar callout actions (`packages/app/src/components/sidebar-callout.tsx:218-221`), and inline data emphasis on dense metadata rows (`packages/app/src/components/git-diff-pane.tsx:2322-2327`, `packages/app/src/components/file-explorer-pane.tsx:1115-1122`). Form field labels live in `<Field>` (`packages/app/src/components/ui/form-field.tsx`) and use `fontWeight.normal` in `foregroundMuted`.
|
||||
- **Content** uses `fontWeight.normal`. This applies to settings rows (`packages/app/src/styles/settings.ts`), sidebar primary list-item titles (`packages/app/src/components/sidebar-workspace-list.tsx:2680-2686`, `packages/app/src/components/agent-list.tsx:572-578`), `<StatusBadge>` text (`packages/app/src/components/ui/status-badge.tsx:56-60`), and `<SidebarCallout>` titles (`packages/app/src/components/sidebar-callout.tsx:175-180`).
|
||||
|
||||
The rule, condensed: text that _names_ a surface or a group is `medium`. Text that lives _inside_ a surface or a group is `normal`. Top-of-screen titles are `<ScreenTitle>`, which is lighter still.
|
||||
@@ -96,7 +96,7 @@ A list that is itself the page content — sidebar items in `sidebar-workspace-l
|
||||
|
||||
Pane chrome — the workspace pane header, the file-explorer header, the diff pane header — uses a single bottom border to separate the header from the content (`packages/app/src/components/git-diff-pane.tsx:2328-2331`). One border, no shadow.
|
||||
|
||||
`borderAccent` is reserved for the outline button and resting frames like the composer. Inputs rest at `border` and step to `borderFocus` on focus. Single-thing borders are wrong; a single bordered element is either a card with one row (use the card) or it does not need a border.
|
||||
`borderAccent` is reserved for the outline button, hovered control borders, and resting frames like the composer. Cards and containers use `border`. Bordered inputs (like `MenuTextField` and the composer) step to `borderFocus` on focus; filled `surface2` form controls (`FormTextInput`, `SearchField`, `SelectField`) reserve a 1px transparent border at rest and step to `borderAccent` on hover and `borderFocus` with the `accent` focus ring on focus so state changes never shift geometry. Single-thing borders are wrong; a single bordered element is either a card with one row (use the card) or it does not need a border.
|
||||
|
||||
---
|
||||
|
||||
@@ -266,6 +266,7 @@ New status pills use `<StatusBadge>`. Identity icon badges use `<IdentityIconBad
|
||||
- `fontWeight.medium` on row titles, body text, badge text, or `<SidebarCallout>` titles. Medium is reserved for the structural-label tier described in §3 — section labels, modal/sheet titles, dense metadata emphasis, and tight action labels. Anything else is `normal`. `<ScreenTitle>` is responsive `400/300` and is never overridden.
|
||||
- `<Pressable>` wrapping `<Text>` to make a button. `<Button>` exists.
|
||||
- Importing `Pressable` or a `Touchable*` outside `components/ui/`. A raw pressable has no standard press or hover feedback, so every one drifts. `paseo/no-raw-pressable` reports it; the files on its burn-down list in `.oxlintrc.json` may only leave it.
|
||||
- Importing `EditingTextInput` outside `components/ui/` (or wrapping any text input in `withUnistyles`). Form inputs use `<FormTextInput>` and search inputs use `<SearchField>`; `paseo/no-raw-text-input` enforces this outside the explicit bespoke-editor allowlist. Nested `withUnistyles` drops box styles on web.
|
||||
- Bare `<Text>` for a section header inside settings. `<SettingsSection>` exists.
|
||||
- A muted paragraph between a section header and its card. Section-level explanation is the header's `info` tooltip (§7).
|
||||
- A "Settings" CTA on a detail page. Detail pages are settings; settings is reached from the sidebar, the host entry, or a row's kebab menu.
|
||||
@@ -290,7 +291,7 @@ New status pills use `<StatusBadge>`. Identity icon badges use `<IdentityIconBad
|
||||
| List+detail (compact stack, desktop sidebar+pane) | `packages/app/src/screens/settings-screen.tsx`, `packages/app/src/screens/projects-screen.tsx` |
|
||||
| Detail card+row | `packages/app/src/screens/settings/host-page.tsx`, `packages/app/src/provider-settings/internal/provider-list.tsx` |
|
||||
| Section grouping inside a card list | `packages/app/src/screens/settings/settings-section.tsx` |
|
||||
| Form modal (label + input fields, primary + cancel) | `packages/app/src/hosts/add-host/internal/add-host-modal.tsx`, `packages/app/src/hosts/add-host/internal/pair-link-modal.tsx`, `packages/app/src/components/project-picker-modal.tsx` |
|
||||
| Form modal (label + input fields, primary + cancel) | `packages/app/src/components/schedules/schedule-form-sheet.tsx`, `packages/app/src/hosts/add-host/internal/add-host-modal.tsx`, `packages/app/src/hosts/add-host/internal/pair-link-modal.tsx` |
|
||||
| Destructive confirmation | `confirmDialog` invoked from `packages/app/src/screens/settings/host-page.tsx:541-547` |
|
||||
| Centered hero / first-run | `packages/app/src/components/welcome-screen.tsx` |
|
||||
| Sidebar list (workspaces, hosts) | `packages/app/src/components/sidebar-workspace-list.tsx`, `packages/app/src/components/left-sidebar.tsx` |
|
||||
|
||||
+15
-9
@@ -59,19 +59,25 @@ complete`), keyed off the opened snapshot's serverId. Waiting for data is a
|
||||
|
||||
## Form kit
|
||||
|
||||
- Compose `Field` / `SelectField` / `FormTextInput` / `SegmentedControl` /
|
||||
- Compose `Field` / `SelectField` / `FormTextInput` / `SearchField` / `SegmentedControl` /
|
||||
`Switch` from `components/ui/`. Geometry (heights, padding, radii, focus/hover
|
||||
states) is owned by `components/ui/control-geometry.ts` — controls never
|
||||
declare their own, and screens never nudge global component styles to align
|
||||
a row.
|
||||
- Every text field consumes `EditingTextInput`, directly or through a UI
|
||||
wrapper. The editing surface owns in-progress text; React observes committed
|
||||
edits through `onChangeText`, and programmatic mutations use the input's
|
||||
`replaceText` command. Its props omit `value` and `defaultValue`, web IME
|
||||
candidates stay unpublished until composition commits, and lint rejects raw
|
||||
React Native `TextInput` imports outside the primitive.
|
||||
- The form declares one size for all fields: `sm` on desktop, `md` compact
|
||||
(`useIsCompactFormFactor`).
|
||||
- Use `FormTextInput` for every form field and textarea (`leading`, `trailing`,
|
||||
`clearable`, `revealable` for password visibility, `monospace`,
|
||||
`appearance="flush"` for card-embedded textareas, and `multiline` with
|
||||
`numberOfLines`), and `SearchField` for search inputs. Both build on
|
||||
`EditingTextInput`, which owns in-progress text, web IME composition safety,
|
||||
`resetKey` resets, bottom-sheet adaptation, and a single internal
|
||||
`withUnistyles` wrapper. React observes committed edits through
|
||||
`onChangeText`, and programmatic mutations use `replaceText`. Lint rejects
|
||||
raw React Native `TextInput` imports and raw `EditingTextInput` imports
|
||||
outside `components/ui/` and the small bespoke-editor allowlist.
|
||||
- Omit `size` on ordinary forms and modals so `control-geometry.ts` sizes every
|
||||
control from the sizing gate (`32px` pointer / `44px` touch). Reserve
|
||||
`size="sm"` for tight chrome (toolbars, nested settings rows), and never pick
|
||||
a control size from `useIsCompactFormFactor()` (see `docs/design.md` §4).
|
||||
- Availability hierarchy: a field whose capability doesn't apply is **hidden**
|
||||
(isolation on a non-git project — same gating as New Workspace), not rendered
|
||||
disabled with an explanation. Disabled-with-a-reason `hint` is only for
|
||||
|
||||
@@ -130,7 +130,7 @@ test("creates, renames, copies, and deletes entries through the file explorer",
|
||||
|
||||
await page.getByTestId("files-new-folder").click();
|
||||
await expect(nameInput).toBeVisible();
|
||||
const draftRow = nameInput.locator("xpath=..");
|
||||
const draftRow = page.getByTestId("file-explorer-draft-row");
|
||||
const placeholderColor = await nameInput.evaluate(
|
||||
(input) => getComputedStyle(input, "::placeholder").color,
|
||||
);
|
||||
|
||||
@@ -252,10 +252,12 @@ export async function addDirectHostFromSettings(
|
||||
|
||||
export async function expectAddHostFieldDrawnAsInput(page: Page, testId: string): Promise<void> {
|
||||
const field = page.getByTestId(testId);
|
||||
const frame = page.getByTestId(`${testId}-container`);
|
||||
await expect(field).toBeVisible();
|
||||
await expect(field).toHaveCSS("border-top-width", "1px");
|
||||
await expect(field).not.toHaveCSS("padding-left", "0px");
|
||||
await expect(field).not.toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
|
||||
await expect(frame).toBeVisible();
|
||||
await expect(frame).toHaveCSS("border-top-width", "1px");
|
||||
await expect(frame).not.toHaveCSS("padding-left", "0px");
|
||||
await expect(frame).not.toHaveCSS("background-color", "rgba(0, 0, 0, 0)");
|
||||
}
|
||||
|
||||
function directConnectionModeSegment(page: Page, mode: "Form" | "URI") {
|
||||
|
||||
@@ -105,12 +105,6 @@ import {
|
||||
import { createCommandCenterInteraction, type CommandCenterInteraction } from "./interaction";
|
||||
import { useWorkspaceFileSearch } from "./workspace-file-search";
|
||||
|
||||
const ThemedBottomSheetTextInput = withUnistyles(TextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
const ThemedTextInput = withUnistyles(TextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
const ThemedCheck = withUnistyles(Check, (theme) => ({ color: theme.colors.foreground }));
|
||||
const ThemedChevronRight = withUnistyles(ChevronRight, (theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
@@ -1063,7 +1057,7 @@ export function CommandCenter() {
|
||||
<OverlayLayerProvider layer={modalLayer}>
|
||||
<View style={styles.header} testID="command-center-header">
|
||||
<View style={styles.searchRow}>
|
||||
<ThemedBottomSheetTextInput
|
||||
<TextInput
|
||||
testID="command-center-input"
|
||||
ref={bottomSheetInputRef}
|
||||
initialValue={state.query}
|
||||
@@ -1098,7 +1092,7 @@ export function CommandCenter() {
|
||||
<View ref={setOverlayScope} testID="command-center-panel" style={styles.panel}>
|
||||
<View style={styles.header} testID="command-center-header">
|
||||
<View style={styles.searchRow}>
|
||||
<ThemedTextInput
|
||||
<TextInput
|
||||
testID="command-center-input"
|
||||
ref={state.inputRef}
|
||||
initialValue={state.query}
|
||||
|
||||
@@ -26,8 +26,7 @@ import {
|
||||
import { ScrollView } from "@/components/ui/scroll-view";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { BottomSafeAreaInset } from "@/components/ui/bottom-safe-area-inset";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { AdaptiveTextInput } from "@/components/adaptive-text-input";
|
||||
import { EditingTextInput, type EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { useDismissibleOverlay } from "@/components/ui/overlay-dismissal";
|
||||
import { DismissBackdrop } from "@/components/ui/dismiss-backdrop";
|
||||
import {
|
||||
@@ -38,7 +37,6 @@ import {
|
||||
} from "@/components/ui/icon-button-chrome";
|
||||
import { LoadingSpinner } from "@/components/ui/loading-spinner";
|
||||
import { ToolbarButton } from "@/components/ui/pane-content-toolbar";
|
||||
export { AdaptiveTextInput, type AdaptiveTextInputProps } from "@/components/adaptive-text-input";
|
||||
|
||||
// Horizontal indent token shared by the sheet header (title, back arrow,
|
||||
// leading icon, search input icon) and any row primitive rendered inside the
|
||||
@@ -205,6 +203,8 @@ const styles = StyleSheet.create((theme) => ({
|
||||
paddingVertical: theme.spacing[2],
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
outlineWidth: 0,
|
||||
outlineColor: "transparent",
|
||||
},
|
||||
desktopScrollContainer: {
|
||||
// Grows only when the card has an explicit `desktopHeight`; a content-sized
|
||||
@@ -508,10 +508,9 @@ export function SheetHeaderView({
|
||||
{search ? (
|
||||
<View style={styles.searchRow}>
|
||||
<Search size={theme.iconSize.md} color={theme.colors.foregroundMuted} />
|
||||
<AdaptiveTextInput
|
||||
<EditingTextInput
|
||||
ref={search.inputRef}
|
||||
// @ts-expect-error - outlineStyle is web-only
|
||||
style={[styles.searchInput, isWeb && { outlineStyle: "none" }]}
|
||||
style={styles.searchInput}
|
||||
placeholder={search.placeholder ?? t("common.actions.search")}
|
||||
resetKey={search.resetKey}
|
||||
onChangeText={handleSearchChange}
|
||||
@@ -550,10 +549,9 @@ export function InlineHeaderView({ header }: { header: SheetHeader }) {
|
||||
{header.search ? (
|
||||
<View style={styles.inlineSearchRow}>
|
||||
<Search size={theme.iconSize.sm} color={theme.colors.foregroundMuted} />
|
||||
<AdaptiveTextInput
|
||||
<EditingTextInput
|
||||
ref={header.search.inputRef}
|
||||
// @ts-expect-error - outlineStyle is web-only
|
||||
style={[styles.searchInput, isWeb && { outlineStyle: "none" }]}
|
||||
style={styles.searchInput}
|
||||
placeholder={header.search.placeholder ?? t("common.actions.search")}
|
||||
resetKey={header.search.resetKey}
|
||||
onChangeText={header.search.onChange}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import React, { forwardRef, useCallback, useEffect, useRef } from "react";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { createControlGeometry } from "@/components/ui/control-geometry";
|
||||
import {
|
||||
EditingTextInput,
|
||||
type EditingTextInputHandle,
|
||||
type EditingTextInputProps,
|
||||
} from "@/components/ui/text-input";
|
||||
|
||||
export type AdaptiveTextInputProps = EditingTextInputProps & {
|
||||
initialValue?: string;
|
||||
resetKey?: string | number;
|
||||
};
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
outline: {
|
||||
...createControlGeometry(theme).controlFocusRingColor,
|
||||
},
|
||||
text: {
|
||||
color: theme.colors.foreground,
|
||||
},
|
||||
}));
|
||||
|
||||
const ThemedTextInput = withUnistyles(EditingTextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
|
||||
export const AdaptiveTextInput = forwardRef<EditingTextInputHandle, AdaptiveTextInputProps>(
|
||||
function AdaptiveTextInputInner(props, ref) {
|
||||
const { initialValue, resetKey, style, onChangeText, ...inputProps } = props;
|
||||
const inputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const replacementTextRef = useRef(initialValue ?? "");
|
||||
const previousResetKeyRef = useRef(resetKey);
|
||||
replacementTextRef.current = initialValue ?? "";
|
||||
const setInputRef = useCallback(
|
||||
(handle: EditingTextInputHandle | null) => {
|
||||
inputRef.current = handle;
|
||||
if (typeof ref === "function") ref(handle);
|
||||
else if (ref) ref.current = handle;
|
||||
},
|
||||
[ref],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (resetKey === previousResetKeyRef.current) return;
|
||||
previousResetKeyRef.current = resetKey;
|
||||
inputRef.current?.replaceText(replacementTextRef.current);
|
||||
}, [resetKey]);
|
||||
|
||||
return (
|
||||
<ThemedTextInput
|
||||
{...inputProps}
|
||||
ref={setInputRef}
|
||||
initialValue={initialValue}
|
||||
onChangeText={onChangeText}
|
||||
style={[styles.outline, style, styles.text]}
|
||||
/>
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -257,7 +257,7 @@ function EntryNameInputRow({
|
||||
return (
|
||||
<View style={[workspaceTreeRowStyles.row, { paddingLeft: treeRowPaddingLeft(depth) }]}>
|
||||
<TreeIndentGuides depth={depth} />
|
||||
<View style={styles.entryInfo}>
|
||||
<View style={styles.entryInfo} testID="file-explorer-draft-row">
|
||||
<View style={styles.entryIcon}>
|
||||
{kind === "directory" ? (
|
||||
<TreeChevron expanded={false} />
|
||||
@@ -277,9 +277,9 @@ function EntryNameInputRow({
|
||||
? t("workspace.fileExplorer.draft.folderPlaceholder")
|
||||
: t("workspace.fileExplorer.draft.filePlaceholder")
|
||||
}
|
||||
placeholderTone="extraMuted"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
placeholderTextColor={styles.draftPlaceholder.color}
|
||||
style={styles.draftInput}
|
||||
selectTextOnFocus={Boolean(initialName)}
|
||||
testID="file-explorer-name-input"
|
||||
@@ -1929,13 +1929,17 @@ const styles = StyleSheet.create((theme) => ({
|
||||
},
|
||||
draftInput: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
color: theme.colors.foreground,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderRadius: theme.borderRadius.sm,
|
||||
borderWidth: theme.borderWidth[1],
|
||||
borderColor: theme.colors.borderAccent,
|
||||
fontSize: theme.fontSize.base,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
},
|
||||
draftPlaceholder: {
|
||||
color: theme.colors.foregroundExtraMuted,
|
||||
paddingHorizontal: theme.spacing[1.5],
|
||||
outlineWidth: 0,
|
||||
outlineColor: "transparent",
|
||||
},
|
||||
previewHeaderText: {
|
||||
flex: 1,
|
||||
|
||||
@@ -15,8 +15,8 @@ import { useTranslation } from "react-i18next";
|
||||
import type { PendingPermission } from "@/types/shared";
|
||||
import type { AgentPermissionResponse } from "@getpaseo/protocol/agent-types";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { EditingTextInput as TextInput } from "@/components/ui/text-input";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input/types";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { ScrollableCodeSurface } from "@/components/ui/scrollable-code-surface";
|
||||
import { MarkdownRenderer } from "@/components/markdown/renderer";
|
||||
import {
|
||||
@@ -310,40 +310,17 @@ function QuestionOtherInput({
|
||||
onChange,
|
||||
onSubmit,
|
||||
}: QuestionOtherInputProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const handleChange = useCallback(
|
||||
(text: string) => {
|
||||
onChange(qIndex, text);
|
||||
},
|
||||
[onChange, qIndex],
|
||||
);
|
||||
const otherInputStyle = useMemo(
|
||||
() =>
|
||||
[
|
||||
styles.otherInput,
|
||||
{
|
||||
borderColor: value.length > 0 ? theme.colors.borderAccent : theme.colors.border,
|
||||
color: theme.colors.foreground,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
IS_WEB ? { outlineStyle: "none", outlineWidth: 0, outlineColor: "transparent" } : null,
|
||||
] as const,
|
||||
[
|
||||
value.length,
|
||||
theme.colors.borderAccent,
|
||||
theme.colors.border,
|
||||
theme.colors.foreground,
|
||||
theme.colors.surface2,
|
||||
],
|
||||
);
|
||||
return (
|
||||
<TextInput
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
// @ts-expect-error - outlineStyle is web-only
|
||||
style={otherInputStyle}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
placeholder={placeholder}
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
initialValue={value}
|
||||
onChangeText={handleChange}
|
||||
onSubmitEditing={onSubmit}
|
||||
@@ -747,13 +724,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
height: 8,
|
||||
borderRadius: 999,
|
||||
},
|
||||
otherInput: {
|
||||
borderWidth: 1,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
paddingVertical: theme.spacing[3],
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
actionsContainer: {
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
|
||||
@@ -68,41 +68,61 @@ vi.mock("@/components/adaptive-modal-sheet", async () => {
|
||||
children,
|
||||
);
|
||||
};
|
||||
// Mirrors production AdaptiveTextInput: native-owned input seeded by
|
||||
// initialValue, remounted (via key) when resetKey changes so the new
|
||||
// initialValue takes effect.
|
||||
const AdaptiveTextInput = ReactModule.forwardRef<HTMLInputElement, Record<string, unknown>>(
|
||||
(props, ref) => {
|
||||
const p = props as {
|
||||
initialValue?: string;
|
||||
defaultValue?: string;
|
||||
editable?: boolean;
|
||||
maxLength?: number;
|
||||
testID?: string;
|
||||
onChangeText?: (next: string) => void;
|
||||
onSubmitEditing?: () => void;
|
||||
};
|
||||
adaptiveInputState.latestProps = {
|
||||
onChangeText: p.onChangeText,
|
||||
onSubmitEditing: p.onSubmitEditing,
|
||||
};
|
||||
return ReactModule.createElement("input", {
|
||||
ref,
|
||||
defaultValue: p.initialValue ?? p.defaultValue ?? "",
|
||||
disabled: p.editable === false,
|
||||
maxLength: p.maxLength,
|
||||
"data-testid": p.testID,
|
||||
onChange: (e: { target: { value: string } }) => p.onChangeText?.(e.target.value),
|
||||
onKeyDown: (e: { key: string; preventDefault: () => void }) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
p.onSubmitEditing?.();
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
return { AdaptiveModalSheet, AdaptiveTextInput };
|
||||
return { AdaptiveModalSheet };
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/form-field", async () => {
|
||||
const ReactModule = await import("react");
|
||||
const FormTextInput = ReactModule.forwardRef<unknown, Record<string, unknown>>((props, ref) => {
|
||||
const p = props as {
|
||||
initialValue?: string;
|
||||
defaultValue?: string;
|
||||
editable?: boolean;
|
||||
maxLength?: number;
|
||||
testID?: string;
|
||||
onChangeText?: (next: string) => void;
|
||||
onSubmitEditing?: () => void;
|
||||
};
|
||||
const inputRef = ReactModule.useRef<HTMLInputElement | null>(null);
|
||||
ReactModule.useImperativeHandle(ref, () => ({
|
||||
focus: () => inputRef.current?.focus(),
|
||||
blur: () => inputRef.current?.blur(),
|
||||
isFocused: () => document.activeElement === inputRef.current,
|
||||
getText: () => inputRef.current?.value ?? "",
|
||||
replaceText: (text: string, selection?: { start: number; end: number }) => {
|
||||
if (inputRef.current) {
|
||||
inputRef.current.value = text;
|
||||
if (selection) inputRef.current.setSelectionRange(selection.start, selection.end);
|
||||
}
|
||||
},
|
||||
setSelection: (selection: { start: number; end: number }) => {
|
||||
inputRef.current?.setSelectionRange(selection.start, selection.end);
|
||||
},
|
||||
reset: () => {
|
||||
if (inputRef.current) inputRef.current.value = "";
|
||||
},
|
||||
getNativeRef: () => inputRef.current,
|
||||
}));
|
||||
adaptiveInputState.latestProps = {
|
||||
onChangeText: p.onChangeText,
|
||||
onSubmitEditing: p.onSubmitEditing,
|
||||
};
|
||||
return ReactModule.createElement("input", {
|
||||
ref: inputRef,
|
||||
defaultValue: p.initialValue ?? p.defaultValue ?? "",
|
||||
disabled: p.editable === false,
|
||||
maxLength: p.maxLength,
|
||||
"data-testid": p.testID,
|
||||
onChange: (e: { target: { value: string } }) => p.onChangeText?.(e.target.value),
|
||||
onKeyDown: (e: { key: string; preventDefault: () => void }) => {
|
||||
if (e.key === "Enter") {
|
||||
e.preventDefault();
|
||||
p.onSubmitEditing?.();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
return { FormTextInput };
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/button", async () => {
|
||||
|
||||
@@ -2,13 +2,9 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Text, View } from "react-native";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
AdaptiveModalSheet,
|
||||
AdaptiveTextInput,
|
||||
type SheetHeader,
|
||||
} from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
|
||||
export interface AdaptiveRenameModalProps {
|
||||
@@ -56,10 +52,8 @@ export function AdaptiveRenameModal({
|
||||
const node = inputRef.current;
|
||||
if (!node) return;
|
||||
node.focus();
|
||||
if (isWeb && node instanceof HTMLInputElement) {
|
||||
node.setSelectionRange(0, length);
|
||||
} else if (!isWeb && length > 0) {
|
||||
node.replaceText(node.getText(), { start: 0, end: length });
|
||||
if (length > 0) {
|
||||
node.setSelection({ start: 0, end: length });
|
||||
}
|
||||
}, 50);
|
||||
return () => clearTimeout(timeout);
|
||||
@@ -124,7 +118,7 @@ export function AdaptiveRenameModal({
|
||||
testID={testID}
|
||||
>
|
||||
<View style={styles.body}>
|
||||
<AdaptiveTextInput
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
initialValue={initialValue}
|
||||
onChangeText={handleChange}
|
||||
@@ -134,7 +128,7 @@ export function AdaptiveRenameModal({
|
||||
editable={!isPending}
|
||||
maxLength={maxLength}
|
||||
onSubmitEditing={handleSubmitVoid}
|
||||
style={styles.input}
|
||||
invalid={error !== null}
|
||||
testID={inputTestID}
|
||||
/>
|
||||
{error ? (
|
||||
@@ -172,19 +166,9 @@ const styles = StyleSheet.create((theme) => ({
|
||||
gap: theme.spacing[3],
|
||||
paddingBottom: theme.spacing[2],
|
||||
},
|
||||
input: {
|
||||
backgroundColor: theme.colors.surface0,
|
||||
color: theme.colors.foreground,
|
||||
paddingVertical: theme.spacing[3],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
borderRadius: theme.borderRadius.md,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
errorText: {
|
||||
color: theme.colors.palette.red[300],
|
||||
fontSize: theme.fontSize.base,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
import type { StyleProp, TextStyle } from "react-native";
|
||||
import { useMemo } from "react";
|
||||
import { View } from "react-native";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { settingsStyles } from "@/styles/settings";
|
||||
import { EditingTextInput as TextInput } from "@/components/ui/text-input";
|
||||
|
||||
interface SettingsTextAreaProps {
|
||||
accessibilityLabel: string;
|
||||
value: string;
|
||||
onChangeText: (text: string) => void;
|
||||
placeholder?: string;
|
||||
testID?: string;
|
||||
style?: StyleProp<TextStyle>;
|
||||
}
|
||||
|
||||
export function SettingsTextArea({
|
||||
accessibilityLabel,
|
||||
value,
|
||||
onChangeText,
|
||||
placeholder,
|
||||
testID,
|
||||
style,
|
||||
}: SettingsTextAreaProps) {
|
||||
const { theme } = useUnistyles();
|
||||
const inputStyle = useMemo(() => [styles.input, style], [style]);
|
||||
|
||||
return (
|
||||
<TextInput
|
||||
testID={testID}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
multiline
|
||||
initialValue={value}
|
||||
onChangeText={onChangeText}
|
||||
placeholder={placeholder}
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={inputStyle}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export function SettingsTextAreaCard(props: SettingsTextAreaProps) {
|
||||
return (
|
||||
<View style={settingsStyles.card}>
|
||||
<SettingsTextArea {...props} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
input: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
paddingVertical: theme.spacing[3],
|
||||
paddingHorizontal: theme.spacing[4],
|
||||
minHeight: 96,
|
||||
textAlignVertical: "top",
|
||||
},
|
||||
}));
|
||||
@@ -26,7 +26,7 @@ import {
|
||||
} from "react-native";
|
||||
import { createPortal } from "react-dom";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { EditingTextInput, type EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { useRetainedPanelActive } from "@/components/retained-panel";
|
||||
@@ -55,7 +55,6 @@ import {
|
||||
useIsolatedBottomSheetVisibility,
|
||||
} from "./isolated-bottom-sheet-modal";
|
||||
import {
|
||||
AdaptiveTextInput,
|
||||
InlineHeaderView,
|
||||
SheetHeaderView,
|
||||
type SheetHeader,
|
||||
@@ -212,7 +211,6 @@ export function SearchInput({
|
||||
useBottomSheetInput: _useBottomSheetInput = false,
|
||||
resetKey,
|
||||
}: SearchInputProps): ReactElement {
|
||||
const { theme } = useUnistyles();
|
||||
const inputRef = useRef<EditingTextInputHandle>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -227,12 +225,10 @@ export function SearchInput({
|
||||
return (
|
||||
<View style={styles.searchInputContainer}>
|
||||
<DensityIcon icon={Search} size="md" color="foregroundMuted" />
|
||||
<AdaptiveTextInput
|
||||
<EditingTextInput
|
||||
ref={inputRef}
|
||||
// @ts-expect-error - outlineStyle is web-only
|
||||
style={[styles.searchInput, IS_WEB && { outlineStyle: "none" }]}
|
||||
style={styles.searchInput}
|
||||
placeholder={placeholder}
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
resetKey={resetKey}
|
||||
onChangeText={onChangeText}
|
||||
autoCapitalize="none"
|
||||
@@ -1893,6 +1889,8 @@ const styles = StyleSheet.create((theme) => ({
|
||||
paddingVertical: theme.spacing[3],
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
outlineWidth: 0,
|
||||
outlineColor: "transparent",
|
||||
},
|
||||
comboboxItem: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -43,6 +43,7 @@ const theme = {
|
||||
colors: {
|
||||
accent: "#20744A",
|
||||
borderAccent: "#2F3534",
|
||||
borderFocus: "#424645",
|
||||
},
|
||||
fontSize: {
|
||||
xs: 10,
|
||||
@@ -200,7 +201,7 @@ describe("control geometry", () => {
|
||||
borderColor: "#2F3534",
|
||||
});
|
||||
expect(geometry.controlActive).toEqual({
|
||||
borderColor: "#2F3534",
|
||||
borderColor: "#424645",
|
||||
outlineColor: "#20744A",
|
||||
outlineOffset: 1,
|
||||
outlineStyle: "solid",
|
||||
@@ -249,6 +250,19 @@ describe("control geometry", () => {
|
||||
borderWidth * 2,
|
||||
).toBe(geometry.fieldControlMd.minHeight[layout]);
|
||||
}
|
||||
|
||||
// Inline actions (clear, password reveal) take the full touch target on touch without
|
||||
// adding height beyond the field's text line box.
|
||||
expect(geometry.fieldInlineActionMd.width).toEqual({ xs: TOUCH_TARGET, md: 24 });
|
||||
expect(geometry.fieldInlineActionMd.height).toEqual({ xs: TOUCH_TARGET, md: 24 });
|
||||
expect(
|
||||
geometry.fieldInlineActionMd.height.xs + geometry.fieldInlineActionMd.marginVertical.xs * 2,
|
||||
).toBe(geometry.fieldTextMd.lineHeight);
|
||||
expect(geometry.fieldInlineActionSm.width).toEqual({ xs: 32, md: 20 });
|
||||
expect(geometry.fieldInlineActionSm.height).toEqual({ xs: 32, md: 20 });
|
||||
expect(
|
||||
geometry.fieldInlineActionSm.height.xs + geometry.fieldInlineActionSm.marginVertical.xs * 2,
|
||||
).toBe(geometry.fieldTextSm.lineHeight);
|
||||
});
|
||||
|
||||
it("keeps segmented controls in an inset pill track sized to match buttons", () => {
|
||||
|
||||
@@ -403,6 +403,29 @@ export function createControlGeometry(theme: Theme) {
|
||||
fontSize: theme.fontSize.base,
|
||||
lineHeight: fieldTextMdLineHeight,
|
||||
};
|
||||
// Inline field actions (clear, password reveal) keep the icon small while growing their touch
|
||||
// target to the control's full height and pulling vertical overhang into the field's padding so
|
||||
// the field height never changes (docs/design.md §8).
|
||||
const fieldInlineActionSmSize = bySizing({ touch: CONTROL_SIZES.sm.touch, pointer: 20 });
|
||||
const fieldInlineActionMdSize = bySizing({ touch: CONTROL_SIZES.md.touch, pointer: 24 });
|
||||
const fieldInlineActionSm = {
|
||||
width: fieldInlineActionSmSize,
|
||||
height: fieldInlineActionSmSize,
|
||||
marginVertical: mapLayout(
|
||||
fieldInlineActionSmSize,
|
||||
(target) => -(target - fieldTextSmLineHeight) / 2,
|
||||
),
|
||||
marginRight: bySizing({ touch: -theme.spacing[2], pointer: -theme.spacing[0.5] }),
|
||||
};
|
||||
const fieldInlineActionMd = {
|
||||
width: fieldInlineActionMdSize,
|
||||
height: fieldInlineActionMdSize,
|
||||
marginVertical: mapLayout(
|
||||
fieldInlineActionMdSize,
|
||||
(target) => -(target - fieldTextMdLineHeight) / 2,
|
||||
),
|
||||
marginRight: bySizing({ touch: -theme.spacing[3], pointer: -theme.spacing[1] }),
|
||||
};
|
||||
const alert = createAlertGeometry(theme);
|
||||
|
||||
return {
|
||||
@@ -436,6 +459,8 @@ export function createControlGeometry(theme: Theme) {
|
||||
},
|
||||
fieldControlSm,
|
||||
fieldControlMd,
|
||||
fieldInlineActionSm,
|
||||
fieldInlineActionMd,
|
||||
fieldTextSm,
|
||||
fieldTextMd,
|
||||
controlRest: {
|
||||
@@ -448,7 +473,7 @@ export function createControlGeometry(theme: Theme) {
|
||||
borderColor: theme.colors.borderAccent,
|
||||
},
|
||||
controlActive: {
|
||||
borderColor: theme.colors.borderAccent,
|
||||
borderColor: theme.colors.borderFocus,
|
||||
outlineColor: theme.colors.accent,
|
||||
outlineOffset: CONTROL_FOCUS_RING_OFFSET,
|
||||
outlineStyle: "solid" as const,
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
import React, { act, createRef, useCallback, useState } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { FormTextInput } from "./form-field";
|
||||
import { SearchField } from "./search-field";
|
||||
import type { EditingTextInputHandle } from "./text-input";
|
||||
|
||||
interface MountedSurface {
|
||||
root: Root;
|
||||
container: HTMLDivElement;
|
||||
}
|
||||
|
||||
const mounted: MountedSurface[] = [];
|
||||
|
||||
function mount(element: React.ReactElement): HTMLDivElement {
|
||||
const container = document.createElement("div");
|
||||
document.body.appendChild(container);
|
||||
const root = createRoot(container);
|
||||
act(() => {
|
||||
root.render(element);
|
||||
});
|
||||
mounted.push({ root, container });
|
||||
return container;
|
||||
}
|
||||
|
||||
function typeText(input: HTMLInputElement | HTMLTextAreaElement, value: string): void {
|
||||
const proto =
|
||||
input instanceof HTMLTextAreaElement
|
||||
? HTMLTextAreaElement.prototype
|
||||
: HTMLInputElement.prototype;
|
||||
const setter = Object.getOwnPropertyDescriptor(proto, "value")?.set;
|
||||
if (!setter) throw new Error("Expected native value setter");
|
||||
setter.call(input, value);
|
||||
input.dispatchEvent(new InputEvent("input", { bubbles: true, data: value }));
|
||||
}
|
||||
|
||||
function clickElement(element: Element | null): void {
|
||||
if (!element) throw new Error("Expected element to click");
|
||||
act(() => {
|
||||
element.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
||||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const item of mounted.splice(0)) {
|
||||
act(() => item.root.unmount());
|
||||
item.container.remove();
|
||||
}
|
||||
});
|
||||
|
||||
describe("FormTextInput", () => {
|
||||
it("focuses the inner input when the outer frame is pressed, skips the frame in tab order, and suppresses inner outline", () => {
|
||||
const container = mount(
|
||||
<>
|
||||
<FormTextInput testID="host" placeholder="Host" />
|
||||
<FormTextInput testID="port" placeholder="Port" />
|
||||
</>,
|
||||
);
|
||||
const frame = container.querySelector<HTMLElement>('[data-testid="host-container"]');
|
||||
const hostInput = container.querySelector<HTMLInputElement>('[data-testid="host"]');
|
||||
const portInput = container.querySelector<HTMLInputElement>('[data-testid="port"]');
|
||||
if (!frame || !hostInput || !portInput) throw new Error("Expected frame and inputs");
|
||||
|
||||
expect(frame.tabIndex).toBe(-1);
|
||||
const sequentialTabStops = Array.from(
|
||||
container.querySelectorAll<HTMLElement>('input, [tabindex="0"]'),
|
||||
);
|
||||
expect(sequentialTabStops).toEqual([hostInput, portInput]);
|
||||
expect(getComputedStyle(hostInput).outlineWidth).toBe("0px");
|
||||
expect(document.activeElement).not.toBe(hostInput);
|
||||
|
||||
clickElement(frame);
|
||||
expect(document.activeElement).toBe(hostInput);
|
||||
});
|
||||
|
||||
it("supports inline clearable affordance and stays synced with imperative replaceText", () => {
|
||||
const onChangeText = vi.fn();
|
||||
const onClear = vi.fn();
|
||||
const inputRef = createRef<EditingTextInputHandle>();
|
||||
const container = mount(
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
testID="query"
|
||||
clearable
|
||||
clearTestID="query-clear"
|
||||
onChangeText={onChangeText}
|
||||
onClear={onClear}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(container.querySelector('[data-testid="query-clear"]')).toBeNull();
|
||||
const input = container.querySelector<HTMLInputElement>('[data-testid="query"]');
|
||||
if (!input) throw new Error("Expected input");
|
||||
|
||||
act(() => {
|
||||
typeText(input, "claude");
|
||||
});
|
||||
const clearButton = container.querySelector('[data-testid="query-clear"]');
|
||||
expect(clearButton).not.toBeNull();
|
||||
|
||||
clickElement(clearButton);
|
||||
expect(input.value).toBe("");
|
||||
expect(onChangeText).toHaveBeenLastCalledWith("");
|
||||
expect(onClear).toHaveBeenCalledOnce();
|
||||
expect(container.querySelector('[data-testid="query-clear"]')).toBeNull();
|
||||
|
||||
act(() => {
|
||||
inputRef.current?.replaceText("sonnet");
|
||||
});
|
||||
expect(container.querySelector('[data-testid="query-clear"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
it("toggles secureTextEntry via revealable without external wrappers", () => {
|
||||
const container = mount(
|
||||
<FormTextInput
|
||||
testID="secret"
|
||||
secureTextEntry
|
||||
revealable
|
||||
revealTestID="secret-toggle"
|
||||
revealAccessibilityLabel="Show password"
|
||||
hideAccessibilityLabel="Hide password"
|
||||
/>,
|
||||
);
|
||||
const input = container.querySelector<HTMLInputElement>('[data-testid="secret"]');
|
||||
const toggle = container.querySelector('[data-testid="secret-toggle"]');
|
||||
if (!input || !toggle) throw new Error("Expected password input and reveal toggle");
|
||||
|
||||
expect(input.type).toBe("password");
|
||||
expect(toggle.getAttribute("aria-label")).toBe("Show password");
|
||||
|
||||
clickElement(toggle);
|
||||
expect(input.type).toBe("text");
|
||||
expect(toggle.getAttribute("aria-label")).toBe("Hide password");
|
||||
|
||||
clickElement(toggle);
|
||||
expect(input.type).toBe("password");
|
||||
});
|
||||
|
||||
it("renders flush multiline textareas with top alignment and monospace when requested", () => {
|
||||
const container = mount(
|
||||
<FormTextInput
|
||||
testID="script-cmd"
|
||||
appearance="flush"
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
monospace
|
||||
/>,
|
||||
);
|
||||
const frame = container.querySelector<HTMLElement>('[data-testid="script-cmd-container"]');
|
||||
const textarea = container.querySelector<HTMLTextAreaElement>('[data-testid="script-cmd"]');
|
||||
if (!frame || !textarea) throw new Error("Expected flush textarea");
|
||||
|
||||
expect(getComputedStyle(frame).borderTopWidth).toBe("0px");
|
||||
expect(getComputedStyle(textarea).outlineWidth).toBe("0px");
|
||||
expect(getComputedStyle(textarea).fontFamily).toContain("monospace");
|
||||
});
|
||||
});
|
||||
|
||||
function SearchHarness() {
|
||||
const [value, setValue] = useState("");
|
||||
const handleChange = useCallback((next: string) => setValue(next), []);
|
||||
return (
|
||||
<SearchField
|
||||
value={value}
|
||||
onChangeText={handleChange}
|
||||
placeholder="Search models..."
|
||||
clearAccessibilityLabel="Clear search"
|
||||
clearOnEscape
|
||||
testID="models-search"
|
||||
clearTestID="models-search-clear"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
describe("SearchField", () => {
|
||||
it("shares FormTextInput chrome, clears via button, and clears on Escape", () => {
|
||||
const container = mount(<SearchHarness />);
|
||||
const input = container.querySelector<HTMLInputElement>('[data-testid="models-search"]');
|
||||
const frame = container.querySelector('[data-testid="models-search-container"]');
|
||||
if (!input || !frame) throw new Error("Expected SearchField input and container");
|
||||
|
||||
expect(getComputedStyle(input).outlineWidth).toBe("0px");
|
||||
|
||||
act(() => {
|
||||
typeText(input, "opus");
|
||||
});
|
||||
const clearButton = container.querySelector('[data-testid="models-search-clear"]');
|
||||
expect(clearButton).not.toBeNull();
|
||||
|
||||
clickElement(clearButton);
|
||||
expect(input.value).toBe("");
|
||||
expect(container.querySelector('[data-testid="models-search-clear"]')).toBeNull();
|
||||
|
||||
act(() => {
|
||||
typeText(input, "haiku");
|
||||
});
|
||||
act(() => {
|
||||
input.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
||||
});
|
||||
expect(input.value).toBe("");
|
||||
});
|
||||
});
|
||||
@@ -1,9 +1,11 @@
|
||||
import {
|
||||
forwardRef,
|
||||
useCallback,
|
||||
useEffect,
|
||||
useImperativeHandle,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
type ForwardedRef,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import {
|
||||
@@ -11,46 +13,72 @@ import {
|
||||
StyleSheet as RNStyleSheet,
|
||||
Text,
|
||||
View,
|
||||
type GestureResponderEvent,
|
||||
type PressableStateCallbackType,
|
||||
type StyleProp,
|
||||
type TextStyle,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { AdaptiveTextInput, type AdaptiveTextInputProps } from "@/components/adaptive-modal-sheet";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { Eye, EyeOff, X } from "lucide-react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import {
|
||||
EditingTextInput,
|
||||
type EditingTextInputHandle,
|
||||
type EditingTextInputProps,
|
||||
} from "@/components/ui/text-input";
|
||||
import {
|
||||
controlIconSize,
|
||||
createControlGeometry,
|
||||
resolveControlInteractionStyles,
|
||||
type ControlSize,
|
||||
} from "@/components/ui/control-geometry";
|
||||
import { useContainedControlSize } from "@/components/ui/control-size";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
|
||||
const FIELD_CHROME = { sm: "chromeSm", md: "chromeMd" } as const satisfies Record<
|
||||
ControlSize,
|
||||
string
|
||||
>;
|
||||
const FIELD_MULTILINE_CHROME = {
|
||||
sm: "chromeMultilineSm",
|
||||
md: "chromeMultilineMd",
|
||||
const FIELD_INLINE_ACTION = {
|
||||
sm: "inlineActionSm",
|
||||
md: "inlineActionMd",
|
||||
} as const satisfies Record<ControlSize, string>;
|
||||
const FIELD_TEXT = { sm: "inputSm", md: "inputMd" } as const satisfies Record<ControlSize, string>;
|
||||
const DEFAULT_MULTILINE_LINES = 3;
|
||||
|
||||
interface FieldProps {
|
||||
const ThemedX = withUnistyles(X);
|
||||
const ThemedEye = withUnistyles(Eye);
|
||||
const ThemedEyeOff = withUnistyles(EyeOff);
|
||||
const mutedIconMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
|
||||
|
||||
export interface FieldProps {
|
||||
label: string;
|
||||
children: ReactNode;
|
||||
trailing?: ReactNode;
|
||||
hint?: string;
|
||||
error?: string | null;
|
||||
testID?: string;
|
||||
errorTestID?: string;
|
||||
}
|
||||
|
||||
export function Field({ label, children, trailing, hint, error, testID }: FieldProps) {
|
||||
export function Field({
|
||||
label,
|
||||
children,
|
||||
trailing,
|
||||
hint,
|
||||
error,
|
||||
testID,
|
||||
errorTestID: errorTestIDProp,
|
||||
}: FieldProps) {
|
||||
const hintTestID = useMemo(() => (testID ? `${testID}-hint` : undefined), [testID]);
|
||||
const errorTestID = useMemo(() => (testID ? `${testID}-error` : undefined), [testID]);
|
||||
const errorTestID = useMemo(
|
||||
() => errorTestIDProp ?? (testID ? `${testID}-error` : undefined),
|
||||
[errorTestIDProp, testID],
|
||||
);
|
||||
const subtext = useMemo(() => {
|
||||
if (error) {
|
||||
return (
|
||||
<Text numberOfLines={1} style={styles.errorText} testID={errorTestID}>
|
||||
<Text style={styles.errorText} testID={errorTestID}>
|
||||
{error}
|
||||
</Text>
|
||||
);
|
||||
@@ -77,13 +105,46 @@ export function Field({ label, children, trailing, hint, error, testID }: FieldP
|
||||
);
|
||||
}
|
||||
|
||||
type FormTextInputProps = AdaptiveTextInputProps & {
|
||||
export interface FormTextInputProps extends EditingTextInputProps {
|
||||
size?: ControlSize;
|
||||
/**
|
||||
* `default` draws the surface2 field frame; `flush` embeds seamlessly inside a card
|
||||
* without a nested border or outer focus ring.
|
||||
*/
|
||||
appearance?: "default" | "flush";
|
||||
/** A glyph inside the field before the text, such as a search icon. */
|
||||
leading?: ReactNode;
|
||||
/** An element inside the field after the text (and after any built-in clear/reveal button). */
|
||||
trailing?: ReactNode;
|
||||
/** Render the input text in the theme's monospace font family. */
|
||||
monospace?: boolean;
|
||||
/** Show an inline clear button whenever the field contains text. */
|
||||
clearable?: boolean;
|
||||
clearAccessibilityLabel?: string;
|
||||
clearTestID?: string;
|
||||
onClear?: () => void;
|
||||
/**
|
||||
* Show an inline eye/eye-off visibility toggle for a `secureTextEntry` field.
|
||||
* Uses internal state by default, or `revealed` + `onRevealedChange` when controlled.
|
||||
*/
|
||||
revealable?: boolean;
|
||||
revealed?: boolean;
|
||||
onRevealedChange?: (revealed: boolean) => void;
|
||||
revealAccessibilityLabel?: string;
|
||||
hideAccessibilityLabel?: string;
|
||||
revealTestID?: string;
|
||||
/**
|
||||
* Optional Unistyles-tracked frame style applied directly to the outer field container without
|
||||
* flattening. Prefer this (with `inputStyle`) over `style` when overriding theme-dependent colors.
|
||||
*/
|
||||
frameStyle?: StyleProp<ViewStyle>;
|
||||
/**
|
||||
* Optional Unistyles-tracked text style applied directly to the inner editor without flattening.
|
||||
*/
|
||||
inputStyle?: EditingTextInputProps["style"];
|
||||
/** The value is rejected; the border and focus ring turn to the danger color. */
|
||||
invalid?: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
type FlatFormTextInputStyle = ViewStyle & TextStyle;
|
||||
|
||||
@@ -92,7 +153,7 @@ interface SplitFormTextInputStyle {
|
||||
inputStyle?: TextStyle;
|
||||
}
|
||||
|
||||
function splitFormTextInputStyle(style: AdaptiveTextInputProps["style"]): SplitFormTextInputStyle {
|
||||
function splitFormTextInputStyle(style: EditingTextInputProps["style"]): SplitFormTextInputStyle {
|
||||
const flattened = RNStyleSheet.flatten(style) as FlatFormTextInputStyle | undefined;
|
||||
if (!flattened) {
|
||||
return {};
|
||||
@@ -160,102 +221,412 @@ function stripUnistylesMetadata<TStyle extends object>(style: TStyle): TStyle {
|
||||
return cleanStyle as TStyle;
|
||||
}
|
||||
|
||||
function assignTextInputRef(
|
||||
forwardedRef: ForwardedRef<EditingTextInputHandle>,
|
||||
node: EditingTextInputHandle | null,
|
||||
): void {
|
||||
if (typeof forwardedRef === "function") {
|
||||
forwardedRef(node);
|
||||
return;
|
||||
interface InlineActionButtonProps {
|
||||
size: ControlSize;
|
||||
onPress: (event: GestureResponderEvent) => void;
|
||||
disabled: boolean;
|
||||
accessibilityLabel: string;
|
||||
testID?: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
function InlineActionButton({
|
||||
size,
|
||||
onPress,
|
||||
disabled,
|
||||
accessibilityLabel,
|
||||
testID,
|
||||
children,
|
||||
}: InlineActionButtonProps) {
|
||||
const buttonStyle = useCallback(
|
||||
({ hovered = false, pressed }: PressableStateCallbackType & { hovered?: boolean }) => [
|
||||
formInputStyles.inlineAction,
|
||||
formInputStyles[FIELD_INLINE_ACTION[size]],
|
||||
!disabled && (hovered || pressed) ? formInputStyles.inlineActionHighlight : null,
|
||||
],
|
||||
[disabled, size],
|
||||
);
|
||||
return (
|
||||
<Pressable
|
||||
onPress={onPress}
|
||||
disabled={disabled}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
style={buttonStyle}
|
||||
testID={testID}
|
||||
>
|
||||
{children}
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
function resolveMultilineChromeStyle(
|
||||
appearance: "default" | "flush",
|
||||
size: ControlSize,
|
||||
lines: number,
|
||||
) {
|
||||
if (appearance === "flush") {
|
||||
return formInputStyles.chromeFlushMultiline(lines);
|
||||
}
|
||||
if (forwardedRef) {
|
||||
forwardedRef.current = node;
|
||||
return size === "sm"
|
||||
? formInputStyles.chromeMultilineSm(lines)
|
||||
: formInputStyles.chromeMultilineMd(lines);
|
||||
}
|
||||
|
||||
function resolveInteractionChromeStyle(options: {
|
||||
appearance: "default" | "flush";
|
||||
hovered: boolean;
|
||||
focused: boolean;
|
||||
disabled: boolean;
|
||||
invalid: boolean;
|
||||
}) {
|
||||
if (options.appearance === "flush") {
|
||||
return [
|
||||
options.focused && !options.disabled ? formInputStyles.chromeFlushFocused : null,
|
||||
options.disabled ? formInputStyles.controlDisabled : null,
|
||||
];
|
||||
}
|
||||
return [
|
||||
resolveControlInteractionStyles(
|
||||
{
|
||||
controlRest: formInputStyles.controlRest,
|
||||
controlHover: formInputStyles.controlHover,
|
||||
controlActive: formInputStyles.controlActive,
|
||||
controlDisabled: formInputStyles.controlDisabled,
|
||||
},
|
||||
{
|
||||
hovered: options.hovered,
|
||||
focused: options.focused,
|
||||
disabled: options.disabled,
|
||||
},
|
||||
),
|
||||
options.invalid ? formInputStyles.controlInvalid : null,
|
||||
];
|
||||
}
|
||||
|
||||
interface TrailingActionsProps {
|
||||
size: ControlSize;
|
||||
showClear: boolean;
|
||||
revealable: boolean;
|
||||
isRevealed: boolean;
|
||||
isDisabled: boolean;
|
||||
iconSize: number;
|
||||
clearAccessibilityLabel: string;
|
||||
clearTestID?: string;
|
||||
onClear: (event: GestureResponderEvent) => void;
|
||||
revealAccessibilityLabel: string;
|
||||
hideAccessibilityLabel: string;
|
||||
revealTestID?: string;
|
||||
onToggleReveal: (event: GestureResponderEvent) => void;
|
||||
trailing?: ReactNode;
|
||||
}
|
||||
|
||||
function FormInputTrailingActions({
|
||||
size,
|
||||
showClear,
|
||||
revealable,
|
||||
isRevealed,
|
||||
isDisabled,
|
||||
iconSize,
|
||||
clearAccessibilityLabel,
|
||||
clearTestID,
|
||||
onClear,
|
||||
revealAccessibilityLabel,
|
||||
hideAccessibilityLabel,
|
||||
revealTestID,
|
||||
onToggleReveal,
|
||||
trailing,
|
||||
}: TrailingActionsProps) {
|
||||
return (
|
||||
<>
|
||||
{showClear ? (
|
||||
<InlineActionButton
|
||||
size={size}
|
||||
onPress={onClear}
|
||||
disabled={isDisabled}
|
||||
accessibilityLabel={clearAccessibilityLabel}
|
||||
testID={clearTestID}
|
||||
>
|
||||
<ThemedX size={iconSize} uniProps={mutedIconMapping} />
|
||||
</InlineActionButton>
|
||||
) : null}
|
||||
{revealable ? (
|
||||
<InlineActionButton
|
||||
size={size}
|
||||
onPress={onToggleReveal}
|
||||
disabled={isDisabled}
|
||||
accessibilityLabel={isRevealed ? hideAccessibilityLabel : revealAccessibilityLabel}
|
||||
testID={revealTestID}
|
||||
>
|
||||
{isRevealed ? (
|
||||
<ThemedEyeOff size={iconSize} uniProps={mutedIconMapping} />
|
||||
) : (
|
||||
<ThemedEye size={iconSize} uniProps={mutedIconMapping} />
|
||||
)}
|
||||
</InlineActionButton>
|
||||
) : null}
|
||||
{trailing}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function resolveSecureTextEntry(
|
||||
revealable: boolean,
|
||||
secureTextEntry: boolean | undefined,
|
||||
isRevealed: boolean,
|
||||
): boolean | undefined {
|
||||
if (!revealable) return secureTextEntry;
|
||||
return secureTextEntry !== false && !isRevealed;
|
||||
}
|
||||
|
||||
function buildChromeStyle(options: {
|
||||
appearance: "default" | "flush";
|
||||
size: ControlSize;
|
||||
multiline: boolean;
|
||||
multilineLines: number;
|
||||
hovered: boolean;
|
||||
focused: boolean;
|
||||
disabled: boolean;
|
||||
invalid: boolean;
|
||||
override?: ViewStyle;
|
||||
frameStyle?: StyleProp<ViewStyle>;
|
||||
}) {
|
||||
const { appearance, size, multiline, multilineLines, override, frameStyle } = options;
|
||||
const chromeSizeStyle =
|
||||
appearance === "flush" ? formInputStyles.chromeFlush : formInputStyles[FIELD_CHROME[size]];
|
||||
const chromeMultilineStyle = multiline
|
||||
? resolveMultilineChromeStyle(appearance, size, multilineLines)
|
||||
: null;
|
||||
return [
|
||||
formInputStyles.chrome,
|
||||
appearance === "default" ? formInputStyles.chromeDefault : null,
|
||||
chromeSizeStyle,
|
||||
chromeMultilineStyle,
|
||||
multiline ? formInputStyles.chromeMultilineLayout : null,
|
||||
...resolveInteractionChromeStyle(options),
|
||||
override,
|
||||
frameStyle,
|
||||
];
|
||||
}
|
||||
|
||||
export const FormTextInput = forwardRef<EditingTextInputHandle, FormTextInputProps>(
|
||||
function FormTextInput(
|
||||
{ size: sizeProp, leading, invalid = false, style, onFocus, onBlur, editable, ...props },
|
||||
{
|
||||
size: sizeProp,
|
||||
appearance = "default",
|
||||
leading,
|
||||
trailing,
|
||||
monospace = false,
|
||||
clearable = false,
|
||||
clearAccessibilityLabel = "Clear",
|
||||
clearTestID,
|
||||
onClear,
|
||||
revealable = false,
|
||||
revealed: revealedProp,
|
||||
onRevealedChange,
|
||||
revealAccessibilityLabel = "Show password",
|
||||
hideAccessibilityLabel = "Hide password",
|
||||
revealTestID,
|
||||
frameStyle,
|
||||
inputStyle: inputStyleProp,
|
||||
invalid = false,
|
||||
style,
|
||||
initialValue,
|
||||
resetKey,
|
||||
onChangeText,
|
||||
onFocus,
|
||||
onBlur,
|
||||
editable,
|
||||
secureTextEntry,
|
||||
multiline,
|
||||
numberOfLines,
|
||||
textAlignVertical,
|
||||
testID,
|
||||
...props
|
||||
},
|
||||
ref,
|
||||
) {
|
||||
const [focused, setFocused] = useState(false);
|
||||
const [hovered, setHovered] = useState(false);
|
||||
const [hasText, setHasText] = useState(() => (initialValue ?? "").length > 0);
|
||||
const [internalRevealed, setInternalRevealed] = useState(false);
|
||||
const inputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const previousResetKeyRef = useRef(resetKey);
|
||||
const initialValueRef = useRef(initialValue);
|
||||
initialValueRef.current = initialValue;
|
||||
|
||||
const containedSize = useContainedControlSize();
|
||||
const size = sizeProp ?? containedSize ?? "md";
|
||||
const isDisabled = editable === false;
|
||||
const chromeSizeStyle = formInputStyles[FIELD_CHROME[size]];
|
||||
const chromeMultilineStyle = props.multiline
|
||||
? formInputStyles[FIELD_MULTILINE_CHROME[size]]
|
||||
: null;
|
||||
const inputSizeStyle = formInputStyles[FIELD_TEXT[size]];
|
||||
const splitStyle = useMemo(() => splitFormTextInputStyle(style), [style]);
|
||||
const setInputRef = useCallback(
|
||||
(node: EditingTextInputHandle | null) => {
|
||||
assignTextInputRef(ref, node);
|
||||
},
|
||||
[ref],
|
||||
const isRevealed = revealedProp ?? internalRevealed;
|
||||
const isMultiline = Boolean(multiline);
|
||||
const multilineLines = numberOfLines ?? DEFAULT_MULTILINE_LINES;
|
||||
|
||||
useEffect(() => {
|
||||
if (resetKey === previousResetKeyRef.current) return;
|
||||
previousResetKeyRef.current = resetKey;
|
||||
setHasText((initialValueRef.current ?? "").length > 0);
|
||||
if (revealedProp === undefined) {
|
||||
setInternalRevealed(false);
|
||||
}
|
||||
}, [resetKey, revealedProp]);
|
||||
|
||||
useImperativeHandle(
|
||||
ref,
|
||||
() => ({
|
||||
focus: () => inputRef.current?.focus(),
|
||||
blur: () => inputRef.current?.blur(),
|
||||
isFocused: () => inputRef.current?.isFocused() ?? false,
|
||||
getText: () => inputRef.current?.getText() ?? "",
|
||||
replaceText: (nextText, selection) => {
|
||||
setHasText(nextText.length > 0);
|
||||
inputRef.current?.replaceText(nextText, selection);
|
||||
},
|
||||
setSelection: (selection) => inputRef.current?.setSelection(selection),
|
||||
reset: () => {
|
||||
setHasText(false);
|
||||
inputRef.current?.reset();
|
||||
},
|
||||
getNativeRef: () => inputRef.current?.getNativeRef() ?? null,
|
||||
}),
|
||||
[],
|
||||
);
|
||||
const handleFocus = useCallback<NonNullable<AdaptiveTextInputProps["onFocus"]>>(
|
||||
|
||||
const handleChangeText = useCallback(
|
||||
(nextText: string) => {
|
||||
setHasText(nextText.length > 0);
|
||||
onChangeText?.(nextText);
|
||||
},
|
||||
[onChangeText],
|
||||
);
|
||||
const handleFocus = useCallback<NonNullable<EditingTextInputProps["onFocus"]>>(
|
||||
(event) => {
|
||||
setFocused(true);
|
||||
onFocus?.(event);
|
||||
},
|
||||
[onFocus],
|
||||
);
|
||||
const handleBlur = useCallback<NonNullable<AdaptiveTextInputProps["onBlur"]>>(
|
||||
const handleBlur = useCallback<NonNullable<EditingTextInputProps["onBlur"]>>(
|
||||
(event) => {
|
||||
setFocused(false);
|
||||
onBlur?.(event);
|
||||
},
|
||||
[onBlur],
|
||||
);
|
||||
const handlePointerEnter = useCallback(() => setHovered(true), []);
|
||||
const handlePointerLeave = useCallback(() => setHovered(false), []);
|
||||
const handleFramePress = useCallback(() => {
|
||||
if (!isDisabled) inputRef.current?.focus();
|
||||
}, [isDisabled]);
|
||||
const handleClear = useCallback(
|
||||
(event: GestureResponderEvent) => {
|
||||
event.stopPropagation();
|
||||
inputRef.current?.replaceText("");
|
||||
setHasText(false);
|
||||
onChangeText?.("");
|
||||
onClear?.();
|
||||
},
|
||||
[onChangeText, onClear],
|
||||
);
|
||||
const handleToggleReveal = useCallback(
|
||||
(event: GestureResponderEvent) => {
|
||||
event.stopPropagation();
|
||||
const next = !isRevealed;
|
||||
if (revealedProp === undefined) {
|
||||
setInternalRevealed(next);
|
||||
}
|
||||
onRevealedChange?.(next);
|
||||
},
|
||||
[isRevealed, onRevealedChange, revealedProp],
|
||||
);
|
||||
|
||||
const splitStyle = useMemo(() => splitFormTextInputStyle(style), [style]);
|
||||
const inputSizeStyle = formInputStyles[FIELD_TEXT[size]];
|
||||
const inputStyle = useMemo(
|
||||
() => [formInputStyles.input, inputSizeStyle, splitStyle.inputStyle],
|
||||
[inputSizeStyle, splitStyle.inputStyle],
|
||||
) as AdaptiveTextInputProps["style"];
|
||||
const chromeStyle = useCallback(
|
||||
({ hovered = false }: PressableStateCallbackType & { hovered?: boolean }) => [
|
||||
formInputStyles.chrome,
|
||||
chromeSizeStyle,
|
||||
chromeMultilineStyle,
|
||||
leading ? formInputStyles.chromeWithLeading : null,
|
||||
resolveControlInteractionStyles(
|
||||
{
|
||||
controlRest: formInputStyles.controlRest,
|
||||
controlHover: formInputStyles.controlHover,
|
||||
controlActive: formInputStyles.controlActive,
|
||||
controlDisabled: formInputStyles.controlDisabled,
|
||||
},
|
||||
{
|
||||
hovered,
|
||||
focused,
|
||||
disabled: isDisabled,
|
||||
},
|
||||
),
|
||||
invalid ? formInputStyles.controlInvalid : null,
|
||||
splitStyle.chromeStyle,
|
||||
() => [
|
||||
formInputStyles.input,
|
||||
inputSizeStyle,
|
||||
isMultiline ? formInputStyles.inputMultiline : null,
|
||||
monospace ? formInputStyles.inputMonospace : null,
|
||||
splitStyle.inputStyle,
|
||||
inputStyleProp,
|
||||
],
|
||||
[inputSizeStyle, inputStyleProp, isMultiline, monospace, splitStyle.inputStyle],
|
||||
) as EditingTextInputProps["style"];
|
||||
|
||||
const chromeStyle = useMemo(
|
||||
() =>
|
||||
buildChromeStyle({
|
||||
appearance,
|
||||
size,
|
||||
multiline: isMultiline,
|
||||
multilineLines,
|
||||
hovered,
|
||||
focused,
|
||||
disabled: isDisabled,
|
||||
invalid,
|
||||
override: splitStyle.chromeStyle,
|
||||
frameStyle,
|
||||
}),
|
||||
[
|
||||
chromeMultilineStyle,
|
||||
chromeSizeStyle,
|
||||
appearance,
|
||||
focused,
|
||||
frameStyle,
|
||||
hovered,
|
||||
invalid,
|
||||
isDisabled,
|
||||
leading,
|
||||
isMultiline,
|
||||
multilineLines,
|
||||
size,
|
||||
splitStyle.chromeStyle,
|
||||
],
|
||||
);
|
||||
|
||||
return (
|
||||
<Pressable disabled={isDisabled} style={chromeStyle}>
|
||||
<Pressable
|
||||
accessible={false}
|
||||
focusable={false}
|
||||
tabIndex={-1}
|
||||
disabled={isDisabled}
|
||||
onPress={handleFramePress}
|
||||
onPointerEnter={isDisabled ? undefined : handlePointerEnter}
|
||||
onPointerLeave={handlePointerLeave}
|
||||
style={chromeStyle}
|
||||
testID={testID ? `${testID}-container` : undefined}
|
||||
>
|
||||
{leading}
|
||||
<AdaptiveTextInput
|
||||
ref={setInputRef}
|
||||
<EditingTextInput
|
||||
ref={inputRef}
|
||||
initialValue={initialValue}
|
||||
resetKey={resetKey}
|
||||
editable={editable}
|
||||
multiline={multiline}
|
||||
numberOfLines={numberOfLines}
|
||||
secureTextEntry={resolveSecureTextEntry(revealable, secureTextEntry, isRevealed)}
|
||||
textAlignVertical={textAlignVertical ?? (isMultiline ? "top" : undefined)}
|
||||
testID={testID}
|
||||
{...props}
|
||||
onChangeText={handleChangeText}
|
||||
onBlur={handleBlur}
|
||||
onFocus={handleFocus}
|
||||
style={inputStyle}
|
||||
/>
|
||||
<FormInputTrailingActions
|
||||
size={size}
|
||||
showClear={clearable && hasText && !isDisabled}
|
||||
revealable={revealable}
|
||||
isRevealed={isRevealed}
|
||||
isDisabled={isDisabled}
|
||||
iconSize={controlIconSize[size]}
|
||||
clearAccessibilityLabel={clearAccessibilityLabel}
|
||||
clearTestID={clearTestID}
|
||||
onClear={handleClear}
|
||||
revealAccessibilityLabel={revealAccessibilityLabel}
|
||||
hideAccessibilityLabel={hideAccessibilityLabel}
|
||||
revealTestID={revealTestID}
|
||||
onToggleReveal={handleToggleReveal}
|
||||
trailing={trailing}
|
||||
/>
|
||||
</Pressable>
|
||||
);
|
||||
},
|
||||
@@ -292,28 +663,49 @@ const styles = StyleSheet.create((theme) => ({
|
||||
|
||||
const formInputStyles = StyleSheet.create((theme) => {
|
||||
const geometry = createControlGeometry(theme);
|
||||
const borderWidth = theme.borderWidth[1];
|
||||
|
||||
return {
|
||||
chrome: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
chromeWithLeading: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
chromeDefault: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
chromeFlush: {
|
||||
backgroundColor: "transparent",
|
||||
borderWidth: 0,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
paddingHorizontal: theme.spacing[4],
|
||||
paddingVertical: theme.spacing[3],
|
||||
outlineWidth: 0,
|
||||
outlineColor: "transparent",
|
||||
},
|
||||
chromeFlushFocused: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
chromeFlushMultiline: (lines: number) => ({
|
||||
minHeight: geometry.fieldTextMd.lineHeight * lines + theme.spacing[3] * 2,
|
||||
}),
|
||||
chromeSm: {
|
||||
...geometry.fieldControlSm,
|
||||
},
|
||||
chromeMd: {
|
||||
...geometry.fieldControlMd,
|
||||
},
|
||||
chromeMultilineSm: {
|
||||
chromeMultilineLayout: {
|
||||
alignItems: "stretch",
|
||||
},
|
||||
chromeMultilineSm: (lines: number) => ({
|
||||
paddingVertical: theme.spacing[2],
|
||||
},
|
||||
chromeMultilineMd: {
|
||||
minHeight: geometry.fieldTextSm.lineHeight * lines + theme.spacing[2] * 2 + borderWidth * 2,
|
||||
}),
|
||||
chromeMultilineMd: (lines: number) => ({
|
||||
paddingVertical: theme.spacing[3],
|
||||
},
|
||||
minHeight: geometry.fieldTextMd.lineHeight * lines + theme.spacing[3] * 2 + borderWidth * 2,
|
||||
}),
|
||||
controlRest: {
|
||||
...geometry.controlRest,
|
||||
},
|
||||
@@ -331,6 +723,21 @@ const formInputStyles = StyleSheet.create((theme) => {
|
||||
borderColor: theme.colors.palette.red[300],
|
||||
outlineColor: theme.colors.palette.red[300],
|
||||
},
|
||||
inlineAction: {
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
flexShrink: 0,
|
||||
borderRadius: theme.borderRadius.md,
|
||||
},
|
||||
inlineActionHighlight: {
|
||||
backgroundColor: theme.colors.interactionHighlight,
|
||||
},
|
||||
inlineActionSm: {
|
||||
...geometry.fieldInlineActionSm,
|
||||
},
|
||||
inlineActionMd: {
|
||||
...geometry.fieldInlineActionMd,
|
||||
},
|
||||
input: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
@@ -340,6 +747,13 @@ const formInputStyles = StyleSheet.create((theme) => {
|
||||
outlineColor: "transparent",
|
||||
outlineWidth: 0,
|
||||
},
|
||||
inputMultiline: {
|
||||
alignSelf: "stretch",
|
||||
textAlignVertical: "top",
|
||||
},
|
||||
inputMonospace: {
|
||||
fontFamily: theme.fontFamily.mono,
|
||||
},
|
||||
inputSm: {
|
||||
...geometry.fieldTextSm,
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { Check, CheckCircle } from "lucide-react-native";
|
||||
import { AdaptiveTextInput } from "@/components/adaptive-modal-sheet";
|
||||
import { EditingTextInput } from "@/components/ui/text-input";
|
||||
import { LoadingSpinner } from "@/components/ui/loading-spinner";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
@@ -172,7 +172,7 @@ export function menuRowContentInset(theme: Theme): number {
|
||||
* (12pt padding, 32pt tall) and lands its text 4pt inside the labels above it, which is exactly
|
||||
* the misalignment a menu makes obvious.
|
||||
*
|
||||
* `AdaptiveTextInput` underneath, so a compact sheet gets `BottomSheetTextInput` and the keyboard
|
||||
* `EditingTextInput` underneath, so a compact sheet gets `BottomSheetTextInput` and the keyboard
|
||||
* moves the sheet rather than covering it. That also means the compact presentation has to be a
|
||||
* sheet: `BottomSheetTextInput` outside a sheet has no context to read.
|
||||
*/
|
||||
@@ -202,7 +202,7 @@ export function MenuTextField({
|
||||
const fieldStyle = useMemo(() => [styles.field, focused ? styles.fieldFocused : null], [focused]);
|
||||
return (
|
||||
<View style={fieldStyle}>
|
||||
<AdaptiveTextInput
|
||||
<EditingTextInput
|
||||
initialValue={initialValue}
|
||||
onChangeText={onChangeText}
|
||||
onFocus={handleFocus}
|
||||
@@ -583,6 +583,8 @@ const styles = StyleSheet.create((theme) => ({
|
||||
lineHeight: MENU_ITEM_LINE_HEIGHT,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: 0,
|
||||
outlineWidth: 0,
|
||||
outlineColor: "transparent",
|
||||
},
|
||||
itemHovered: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
import { useCallback, useEffect, useRef, useState, type ReactElement } from "react";
|
||||
import {
|
||||
Pressable,
|
||||
View,
|
||||
type NativeSyntheticEvent,
|
||||
type TextInputKeyPressEventData,
|
||||
} from "react-native";
|
||||
import { Search, X } from "lucide-react-native";
|
||||
import { forwardRef, useCallback, useEffect, useMemo, useRef } from "react";
|
||||
import { View, type NativeSyntheticEvent, type TextInputKeyPressEventData } from "react-native";
|
||||
import { Search } from "lucide-react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { ICON_SIZE, type Theme } from "@/styles/theme";
|
||||
import {
|
||||
EditingTextInput as TextInput,
|
||||
type EditingTextInputHandle,
|
||||
} from "@/components/ui/text-input";
|
||||
import { CONTROL_HEIGHTS } from "@/components/ui/control-geometry";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
|
||||
const ThemedSearch = withUnistyles(Search);
|
||||
const ThemedX = withUnistyles(X);
|
||||
const ThemedTextInput = withUnistyles(TextInput, (theme: Theme) => ({
|
||||
// Placeholders sit at foregroundMuted and no dimmer — see docs/design.md §14.
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
selectionColor: theme.colors.foreground,
|
||||
}));
|
||||
|
||||
const mutedColorMapping = (theme: Theme) => ({ color: theme.colors.foregroundMuted });
|
||||
|
||||
export interface SearchFieldProps {
|
||||
@@ -47,115 +32,95 @@ export interface SearchFieldProps {
|
||||
}
|
||||
|
||||
/**
|
||||
* The standalone search box that leads a screen's filter rail. Its chrome is
|
||||
* the host filter pill's, so the two sit on the same rail and read as one row
|
||||
* of controls; only the border colour moves on focus, which keeps the leading
|
||||
* icon from shifting. It owns its own clear affordance — a caller rendering its
|
||||
* own X has been handed the wrong component.
|
||||
* The standalone search box that leads a screen's filter rail. Built on `FormTextInput` so search
|
||||
* and form inputs share one chrome, hover, focus-ring, and clear-affordance contract.
|
||||
*/
|
||||
export function SearchField({
|
||||
value,
|
||||
onChangeText,
|
||||
placeholder,
|
||||
accessibilityLabel,
|
||||
clearAccessibilityLabel,
|
||||
fullWidth = false,
|
||||
size = "md",
|
||||
variant = "default",
|
||||
clearOnEscape = false,
|
||||
testID,
|
||||
clearTestID,
|
||||
}: SearchFieldProps): ReactElement {
|
||||
const [isFocused, setIsFocused] = useState(false);
|
||||
const inputRef = useRef<EditingTextInputHandle>(null);
|
||||
const handleFocus = useCallback(() => setIsFocused(true), []);
|
||||
const handleBlur = useCallback(() => setIsFocused(false), []);
|
||||
const handleClear = useCallback(() => {
|
||||
inputRef.current?.replaceText("");
|
||||
onChangeText("");
|
||||
}, [onChangeText]);
|
||||
const handleKeyPress = useCallback(
|
||||
(event: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
|
||||
if (event.nativeEvent.key === "Escape") handleClear();
|
||||
export const SearchField = forwardRef<EditingTextInputHandle, SearchFieldProps>(
|
||||
function SearchField(
|
||||
{
|
||||
value,
|
||||
onChangeText,
|
||||
placeholder,
|
||||
accessibilityLabel,
|
||||
clearAccessibilityLabel,
|
||||
fullWidth = false,
|
||||
size = "md",
|
||||
variant = "default",
|
||||
clearOnEscape = false,
|
||||
testID,
|
||||
clearTestID,
|
||||
},
|
||||
[handleClear],
|
||||
);
|
||||
// The input owns its text, so an owner emptying `value` has to empty it too.
|
||||
useEffect(() => {
|
||||
if (value === "" && inputRef.current?.getText()) inputRef.current.replaceText("");
|
||||
}, [value]);
|
||||
const small = size === "sm";
|
||||
const card = variant === "card";
|
||||
const leadingIcon = <ThemedSearch size={ICON_SIZE.sm} uniProps={mutedColorMapping} />;
|
||||
ref,
|
||||
) {
|
||||
const inputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const setInputRef = useCallback(
|
||||
(handle: EditingTextInputHandle | null) => {
|
||||
inputRef.current = handle;
|
||||
if (typeof ref === "function") ref(handle);
|
||||
else if (ref) ref.current = handle;
|
||||
},
|
||||
[ref],
|
||||
);
|
||||
const handleClear = useCallback(() => {
|
||||
inputRef.current?.replaceText("");
|
||||
onChangeText("");
|
||||
}, [onChangeText]);
|
||||
const handleKeyPress = useCallback(
|
||||
(event: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
|
||||
if (event.nativeEvent.key === "Escape") handleClear();
|
||||
},
|
||||
[handleClear],
|
||||
);
|
||||
// The input owns its text, so an owner emptying `value` has to empty it too.
|
||||
useEffect(() => {
|
||||
if (value === "" && inputRef.current?.getText()) inputRef.current.replaceText("");
|
||||
}, [value]);
|
||||
|
||||
return (
|
||||
<View
|
||||
testID={testID ? `${testID}-container` : undefined}
|
||||
style={[
|
||||
styles.field,
|
||||
small && styles.fieldSmall,
|
||||
card && styles.fieldCard,
|
||||
fullWidth && styles.fieldFullWidth,
|
||||
isFocused && styles.fieldFocused,
|
||||
]}
|
||||
>
|
||||
{card ? <View style={styles.leadingSlot}>{leadingIcon}</View> : leadingIcon}
|
||||
<ThemedTextInput
|
||||
const card = variant === "card";
|
||||
const leading = useMemo(() => {
|
||||
const icon = <ThemedSearch size={ICON_SIZE.sm} uniProps={mutedColorMapping} />;
|
||||
return card ? <View style={styles.leadingSlot}>{icon}</View> : icon;
|
||||
}, [card]);
|
||||
const fieldStyle = useMemo(
|
||||
() => [styles.field, fullWidth && styles.fieldFullWidth, card && styles.fieldCard],
|
||||
[card, fullWidth],
|
||||
);
|
||||
|
||||
return (
|
||||
<FormTextInput
|
||||
ref={setInputRef}
|
||||
testID={testID}
|
||||
ref={inputRef}
|
||||
size={size}
|
||||
initialValue={value}
|
||||
onChangeText={onChangeText}
|
||||
onFocus={handleFocus}
|
||||
onBlur={handleBlur}
|
||||
placeholder={placeholder}
|
||||
accessibilityLabel={accessibilityLabel ?? placeholder}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
returnKeyType="search"
|
||||
onKeyPress={clearOnEscape ? handleKeyPress : undefined}
|
||||
style={[styles.input, small && styles.inputSmall]}
|
||||
leading={leading}
|
||||
clearable
|
||||
clearAccessibilityLabel={clearAccessibilityLabel}
|
||||
clearTestID={clearTestID}
|
||||
frameStyle={fieldStyle}
|
||||
/>
|
||||
{value.length > 0 ? (
|
||||
<Pressable
|
||||
testID={clearTestID}
|
||||
onPress={handleClear}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={clearAccessibilityLabel}
|
||||
hitSlop={8}
|
||||
style={card ? styles.clearSlot : undefined}
|
||||
>
|
||||
<ThemedX size={ICON_SIZE.sm} uniProps={mutedColorMapping} />
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
const SEARCH_FIELD_MAX_WIDTH = 420;
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
field: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
maxWidth: SEARCH_FIELD_MAX_WIDTH,
|
||||
paddingVertical: theme.spacing[1.5],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
borderRadius: theme.borderRadius.md,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
borderWidth: theme.borderWidth[1],
|
||||
borderColor: theme.colors.border,
|
||||
},
|
||||
fieldSmall: {
|
||||
height: CONTROL_HEIGHTS.sm,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: theme.spacing[1.5],
|
||||
},
|
||||
fieldCard: {
|
||||
// Matches a collapsed SettingsCard row: 44pt inner row height + 1px top/bottom border = 46pt.
|
||||
height: 46,
|
||||
minHeight: 46,
|
||||
paddingVertical: 0,
|
||||
paddingHorizontal: { xs: theme.spacing[4], md: theme.spacing[3] },
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
@@ -165,33 +130,7 @@ const styles = StyleSheet.create((theme) => ({
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
clearSlot: {
|
||||
width: ICON_SIZE.sm,
|
||||
height: ICON_SIZE.sm,
|
||||
marginRight: -theme.spacing[1],
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
},
|
||||
fieldFullWidth: {
|
||||
maxWidth: "100%",
|
||||
},
|
||||
fieldFocused: {
|
||||
borderColor: theme.colors.borderFocus,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
input: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
padding: 0,
|
||||
minHeight: 20,
|
||||
// The browser's focus ring would sit inside the field's own focus border.
|
||||
// `outlineWidth` is typed on ViewStyle since RN 0.81 and is a no-op on
|
||||
// native, so this needs neither a cast nor a platform branch.
|
||||
outlineWidth: 0,
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
inputSmall: {
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export { EditingTextInput } from "./text-input";
|
||||
export type { EditingTextInputHandle, EditingTextInputProps } from "./types";
|
||||
@@ -0,0 +1,70 @@
|
||||
import { forwardRef, useCallback, useEffect, useRef } from "react";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import { EditingTextInput as RawEditingTextInput } from "./text-input";
|
||||
import type { EditingTextInputHandle, EditingTextInputProps } from "./types";
|
||||
|
||||
export type { EditingTextInputHandle, EditingTextInputProps } from "./types";
|
||||
|
||||
// Single internal `withUnistyles` wrapper so callers never double-wrap an input
|
||||
// (nested `withUnistyles` emits nested `display: contents` wrappers on web and drops box styles).
|
||||
// Reading `theme.fontSize` also subscribes the leaf to numeric typography updates on web without
|
||||
// remounting the editing surface.
|
||||
const MutedEditingTextInput = withUnistyles(RawEditingTextInput, (theme: Theme) => {
|
||||
void theme.fontSize;
|
||||
return {
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
};
|
||||
});
|
||||
|
||||
const ExtraMutedEditingTextInput = withUnistyles(RawEditingTextInput, (theme: Theme) => {
|
||||
void theme.fontSize;
|
||||
return {
|
||||
placeholderTextColor: theme.colors.foregroundExtraMuted,
|
||||
};
|
||||
});
|
||||
|
||||
export const EditingTextInput = forwardRef<EditingTextInputHandle, EditingTextInputProps>(
|
||||
function EditingTextInput(
|
||||
{ initialValue, resetKey, placeholderTone = "muted", style, ...inputProps },
|
||||
ref,
|
||||
) {
|
||||
const inputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const replacementTextRef = useRef(initialValue ?? "");
|
||||
const previousResetKeyRef = useRef(resetKey);
|
||||
replacementTextRef.current = initialValue ?? "";
|
||||
|
||||
const setInputRef = useCallback(
|
||||
(handle: EditingTextInputHandle | null) => {
|
||||
inputRef.current = handle;
|
||||
if (typeof ref === "function") ref(handle);
|
||||
else if (ref) ref.current = handle;
|
||||
},
|
||||
[ref],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (resetKey === previousResetKeyRef.current) return;
|
||||
previousResetKeyRef.current = resetKey;
|
||||
inputRef.current?.replaceText(replacementTextRef.current);
|
||||
}, [resetKey]);
|
||||
|
||||
const ThemedInput =
|
||||
placeholderTone === "extraMuted" ? ExtraMutedEditingTextInput : MutedEditingTextInput;
|
||||
|
||||
return (
|
||||
<ThemedInput
|
||||
{...inputProps}
|
||||
ref={setInputRef}
|
||||
initialValue={initialValue}
|
||||
style={[styles.text, style]}
|
||||
/>
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
text: {
|
||||
color: theme.colors.foreground,
|
||||
},
|
||||
}));
|
||||
+32
-6
@@ -1,7 +1,7 @@
|
||||
import React, { act, useCallback, useState } from "react";
|
||||
import { createRoot, type Root } from "react-dom/client";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { AdaptiveTextInput } from "./adaptive-text-input";
|
||||
import { EditingTextInput } from "./index";
|
||||
|
||||
interface MountedInput {
|
||||
root: Root;
|
||||
@@ -11,8 +11,16 @@ interface MountedInput {
|
||||
|
||||
const mountedInputs: MountedInput[] = [];
|
||||
|
||||
function SchedulePromptHarness({ changes }: { changes: string[] }) {
|
||||
const [prompt, setPrompt] = useState("");
|
||||
function SchedulePromptHarness({
|
||||
changes,
|
||||
resetKey = "a",
|
||||
initialValue = "",
|
||||
}: {
|
||||
changes: string[];
|
||||
resetKey?: string;
|
||||
initialValue?: string;
|
||||
}) {
|
||||
const [prompt, setPrompt] = useState(initialValue);
|
||||
const handleChangeText = useCallback(
|
||||
(text: string) => {
|
||||
changes.push(text);
|
||||
@@ -21,8 +29,9 @@ function SchedulePromptHarness({ changes }: { changes: string[] }) {
|
||||
[changes],
|
||||
);
|
||||
return (
|
||||
<AdaptiveTextInput
|
||||
initialValue={prompt}
|
||||
<EditingTextInput
|
||||
initialValue={resetKey === "a" ? prompt : initialValue}
|
||||
resetKey={resetKey}
|
||||
multiline
|
||||
onChangeText={handleChangeText}
|
||||
testID="schedule-prompt-input"
|
||||
@@ -63,7 +72,7 @@ afterEach(() => {
|
||||
}
|
||||
});
|
||||
|
||||
describe("AdaptiveTextInput web IME composition", () => {
|
||||
describe("EditingTextInput web IME composition and resetKey", () => {
|
||||
it("keeps the candidate editing-surface owned until composition commits", () => {
|
||||
const changes: string[] = [];
|
||||
const { textarea } = mountSchedulePrompt(changes);
|
||||
@@ -84,4 +93,21 @@ describe("AdaptiveTextInput web IME composition", () => {
|
||||
expect(textarea.value).toBe("你");
|
||||
expect(changes).toEqual(["你"]);
|
||||
});
|
||||
|
||||
it("resets the editing buffer to initialValue when resetKey changes", () => {
|
||||
const changes: string[] = [];
|
||||
const mounted = mountSchedulePrompt(changes);
|
||||
|
||||
act(() => {
|
||||
typeFromIme(mounted.textarea, "draft");
|
||||
});
|
||||
expect(mounted.textarea.value).toBe("draft");
|
||||
|
||||
act(() => {
|
||||
mounted.root.render(
|
||||
<SchedulePromptHarness changes={changes} resetKey="b" initialValue="fresh" />,
|
||||
);
|
||||
});
|
||||
expect(mounted.textarea.value).toBe("fresh");
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,10 @@ export interface EditingTextInputProps extends Omit<
|
||||
"defaultValue" | "onChangeText" | "value"
|
||||
> {
|
||||
initialValue?: string;
|
||||
/** Changing this key resets the editor buffer to the current `initialValue`. */
|
||||
resetKey?: string | number;
|
||||
/** Default is `foregroundMuted`; `extraMuted` is reserved for the composer's empty placeholder. */
|
||||
placeholderTone?: "muted" | "extraMuted";
|
||||
onChangeText?: (text: string) => void;
|
||||
onPasteImages?: (files: readonly NativePastedFile[]) => void;
|
||||
onPasteError?: (message: string) => void;
|
||||
|
||||
@@ -97,10 +97,6 @@ import {
|
||||
type EditingTextInputHandle as ComposerTextInputHandle,
|
||||
type EditingTextInputProps,
|
||||
} from "@/components/ui/text-input";
|
||||
|
||||
const ComposerTextInput = withUnistyles(EditingTextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundExtraMuted,
|
||||
}));
|
||||
import {
|
||||
resolveSendTooltipLabel,
|
||||
resolveSubmitAccessibilityHint,
|
||||
@@ -796,10 +792,11 @@ function ComposerTextSurface(props: ComposerTextSurfaceProps): React.ReactElemen
|
||||
{`${measurementText}\u200b`}
|
||||
</Text>
|
||||
) : null}
|
||||
<ComposerTextInput
|
||||
<EditingTextInput
|
||||
ref={props.textInputRef}
|
||||
dataSet={COMPOSER_INPUT_DATASET}
|
||||
initialValue={props.value}
|
||||
placeholderTone="extraMuted"
|
||||
onChangeText={handleTextChange}
|
||||
placeholder={props.placeholder}
|
||||
accessibilityLabel={props.accessibilityLabel}
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
EditingTextInput as TextInput,
|
||||
type EditingTextInputHandle,
|
||||
} from "@/components/ui/text-input";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import {
|
||||
ArrowLeft,
|
||||
ArrowRight,
|
||||
@@ -1802,7 +1803,6 @@ export function BrowserPane({
|
||||
onFocus={handleUrlBarFocus}
|
||||
onSubmitEditing={handleNavigateDraftUrl}
|
||||
placeholder={t("workspace.browser.controls.enterUrl")}
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
ref={urlInputRef}
|
||||
style={urlInputStyle}
|
||||
initialValue={draftUrl}
|
||||
@@ -1971,14 +1971,13 @@ function BrowserElementAnnotationCard({
|
||||
<Text numberOfLines={1} style={styles.annotationElement}>
|
||||
{elementLabel}
|
||||
</Text>
|
||||
<ThemedAnnotationInput
|
||||
<FormTextInput
|
||||
accessibilityLabel={t("workspace.browser.annotate.placeholder")}
|
||||
autoFocus
|
||||
multiline
|
||||
numberOfLines={3}
|
||||
onChangeText={setComment}
|
||||
placeholder={t("workspace.browser.annotate.placeholder")}
|
||||
style={styles.annotationInput}
|
||||
uniProps={annotationInputMapping}
|
||||
initialValue={comment}
|
||||
/>
|
||||
<View style={styles.annotationActions}>
|
||||
@@ -2021,13 +2020,9 @@ function useElementBounds(element: HTMLElement | null): ViewStyle | null {
|
||||
}
|
||||
|
||||
const ThemedCloseIcon = withUnistyles(X);
|
||||
const ThemedAnnotationInput = withUnistyles(TextInput);
|
||||
const iconForegroundMutedMapping = (theme: { colors: { foregroundMuted: string } }) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
});
|
||||
const annotationInputMapping = (theme: { colors: { foregroundMuted: string } }) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
});
|
||||
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
container: {
|
||||
@@ -2181,18 +2176,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
marginBottom: theme.spacing[2],
|
||||
},
|
||||
annotationInput: {
|
||||
minHeight: 64,
|
||||
fontSize: theme.fontSize.base,
|
||||
color: theme.colors.foreground,
|
||||
borderRadius: theme.borderRadius.md,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
paddingHorizontal: theme.spacing[2],
|
||||
paddingVertical: theme.spacing[2],
|
||||
textAlignVertical: "top",
|
||||
},
|
||||
annotationActions: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
|
||||
@@ -2,7 +2,6 @@ import { useCallback, useMemo, useState, useSyncExternalStore } from "react";
|
||||
import { View } from "react-native";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import type { TFunction } from "i18next";
|
||||
import { Eye, EyeOff } from "lucide-react-native";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { DaemonRpcError } from "@getpaseo/client";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
@@ -165,36 +164,27 @@ function PasswordInputField({
|
||||
|
||||
return (
|
||||
<Field label={label} error={error} testID={`${testID}-field`}>
|
||||
<View style={styles.passwordRow}>
|
||||
<View style={styles.passwordInputWrap}>
|
||||
<FormTextInput
|
||||
initialValue={initialValue}
|
||||
onChangeText={onChangeText}
|
||||
onSubmitEditing={onSubmitEditing}
|
||||
secureTextEntry={!showPassword}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
autoComplete="off"
|
||||
autoFocus={autoFocus}
|
||||
editable={!disabled}
|
||||
invalid={Boolean(error)}
|
||||
size={size}
|
||||
returnKeyType={returnKeyType}
|
||||
testID={testID}
|
||||
/>
|
||||
</View>
|
||||
<Button
|
||||
variant="outline"
|
||||
size={size}
|
||||
leftIcon={showPassword ? EyeOff : Eye}
|
||||
onPress={onToggleShow}
|
||||
disabled={disabled}
|
||||
accessibilityLabel={
|
||||
showPassword ? t("devices.password.hide") : t("devices.password.show")
|
||||
}
|
||||
testID={`${testID}-toggle`}
|
||||
/>
|
||||
</View>
|
||||
<FormTextInput
|
||||
initialValue={initialValue}
|
||||
onChangeText={onChangeText}
|
||||
onSubmitEditing={onSubmitEditing}
|
||||
secureTextEntry
|
||||
revealable
|
||||
revealed={showPassword}
|
||||
onRevealedChange={onToggleShow}
|
||||
revealAccessibilityLabel={t("devices.password.show")}
|
||||
hideAccessibilityLabel={t("devices.password.hide")}
|
||||
revealTestID={`${testID}-toggle`}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
autoComplete="off"
|
||||
autoFocus={autoFocus}
|
||||
editable={!disabled}
|
||||
invalid={Boolean(error)}
|
||||
size={size}
|
||||
returnKeyType={returnKeyType}
|
||||
testID={testID}
|
||||
/>
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
@@ -504,15 +494,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
form: {
|
||||
gap: theme.spacing[4],
|
||||
},
|
||||
passwordRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
passwordInputWrap: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
|
||||
@@ -17,10 +17,8 @@ import { useDaemonConfig } from "@/hooks/use-daemon-config";
|
||||
import { useHostRuntimeClient, useHostRuntimeSnapshot } from "@/runtime/host-runtime";
|
||||
import { useSessionStore, type DaemonServerInfo } from "@/stores/session-store";
|
||||
import type { Theme } from "@/styles/theme";
|
||||
import {
|
||||
EditingTextInput as TextInput,
|
||||
type EditingTextInputHandle,
|
||||
} from "@/components/ui/text-input";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
|
||||
const RELAY_DOCS_URL = "https://paseo.sh/docs/security";
|
||||
export const CONNECTIVITY_DOCS_URL = "https://paseo.sh/docs/connectivity";
|
||||
@@ -278,16 +276,16 @@ function PairingOffer(props: PairDeviceBodyProps & { offer: { url: string } }) {
|
||||
<PairingQr svg={props.qrSvg} isError={props.qrError} />
|
||||
</View>
|
||||
<View style={styles.linkRow}>
|
||||
<View style={styles.inputWrapper}>
|
||||
<TextInput
|
||||
ref={inputRef}
|
||||
style={styles.linkInput}
|
||||
initialValue={props.offer.url}
|
||||
readOnly
|
||||
selectTextOnFocus
|
||||
accessibilityLabel={t("pairing.link.label")}
|
||||
/>
|
||||
</View>
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
frameStyle={styles.linkFrame}
|
||||
inputStyle={styles.linkInput}
|
||||
initialValue={props.offer.url}
|
||||
readOnly
|
||||
monospace
|
||||
selectTextOnFocus
|
||||
accessibilityLabel={t("pairing.link.label")}
|
||||
/>
|
||||
<Button variant="outline" leftIcon={props.copied ? Check : Copy} onPress={props.onCopy}>
|
||||
{props.copied ? t("pairing.device.copied") : t("pairing.device.copy")}
|
||||
</Button>
|
||||
@@ -428,22 +426,14 @@ const styles = StyleSheet.create((theme) => ({
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
inputWrapper: {
|
||||
linkFrame: {
|
||||
flex: 1,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
overflow: "hidden",
|
||||
minWidth: 0,
|
||||
},
|
||||
linkInput: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontFamily: theme.fontFamily.mono,
|
||||
fontSize: theme.fontSize.sm,
|
||||
paddingVertical: theme.spacing[2],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
outlineStyle: "none",
|
||||
} as object,
|
||||
},
|
||||
hint: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.sm,
|
||||
|
||||
@@ -13,16 +13,13 @@ import {
|
||||
} from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { Check, Eye, EyeOff, Form, Link, Link2 } from "lucide-react-native";
|
||||
import { Check, Form, Link, Link2 } from "lucide-react-native";
|
||||
import type { HostProfile } from "@/types/host-connection";
|
||||
import { useHosts, useHostMutations } from "@/runtime/host-runtime";
|
||||
import { buildConnectionFailureCopy } from "@/components/connection-failure-copy";
|
||||
import {
|
||||
AdaptiveModalSheet,
|
||||
AdaptiveTextInput,
|
||||
type SheetHeader,
|
||||
} from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
import { SegmentedControl, type SegmentedControlOption } from "@/components/ui/segmented-control";
|
||||
import { getIsElectron, isWeb } from "@/constants/platform";
|
||||
import {
|
||||
@@ -78,23 +75,11 @@ const styles = StyleSheet.create((theme) => ({
|
||||
modeBody: {
|
||||
gap: theme.spacing[4],
|
||||
},
|
||||
field: {
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
label: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.base,
|
||||
fontWeight: theme.fontWeight.medium,
|
||||
},
|
||||
input: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
paddingHorizontal: theme.spacing[4],
|
||||
paddingVertical: theme.spacing[3],
|
||||
color: theme.colors.foreground,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
},
|
||||
portRow: {
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
@@ -106,25 +91,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
portField: {
|
||||
width: 112,
|
||||
},
|
||||
passwordRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
passwordInput: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
iconButton: {
|
||||
width: 44,
|
||||
height: 44,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
},
|
||||
checkboxRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
@@ -508,7 +474,6 @@ function DirectFormFields({
|
||||
onChange: (next: DirectConnectionInput) => void;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
|
||||
const hostInputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const portInputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const passwordInputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
@@ -516,9 +481,6 @@ function DirectFormFields({
|
||||
const hostSelectionRef = useRef<TextSelection | null>(null);
|
||||
const portSelectionRef = useRef<TextSelection | null>(null);
|
||||
const suppressedPasteRef = useRef<{ field: "host" | "port"; text: string } | null>(null);
|
||||
const hostFieldStyle = useMemo(() => [styles.field, styles.hostField], []);
|
||||
const portFieldStyle = useMemo(() => [styles.field, styles.portField], []);
|
||||
const passwordInputStyle = useMemo(() => [styles.input, styles.passwordInput], []);
|
||||
const checkboxStyle = useMemo(
|
||||
() => [styles.checkbox, input.useTls ? styles.checkboxChecked : null],
|
||||
[input.useTls],
|
||||
@@ -711,58 +673,53 @@ function DirectFormFields({
|
||||
onChange(next);
|
||||
}, [input, isSaving, onChange, syncFormInputs]);
|
||||
const tlsCheckboxKeyProps = useCheckboxSpaceKey(handleToggleUseTls, isSaving);
|
||||
const handleTogglePasswordVisibility = useCallback(() => {
|
||||
setIsPasswordVisible((current) => !current);
|
||||
}, []);
|
||||
|
||||
const PasswordIcon = isPasswordVisible ? ThemedEyeOff : ThemedEye;
|
||||
|
||||
return (
|
||||
<>
|
||||
<View style={styles.portRow}>
|
||||
<View style={hostFieldStyle}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.host")}</Text>
|
||||
<AdaptiveTextInput
|
||||
ref={hostInputRef}
|
||||
testID="direct-host-input"
|
||||
nativeID="direct-host-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.host")}
|
||||
initialValue={input.host}
|
||||
onChangeText={handleHostChange}
|
||||
onSelectionChange={handleHostSelectionChange}
|
||||
onFocus={fieldEvents.onFocus}
|
||||
onBlur={handleHostBlur}
|
||||
autoFocus={fieldEvents.autoFocus}
|
||||
placeholder="localhost"
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
editable={!isSaving}
|
||||
returnKeyType="next"
|
||||
/>
|
||||
<View style={styles.hostField}>
|
||||
<Field label={t("pairing.direct.fields.host")}>
|
||||
<FormTextInput
|
||||
ref={hostInputRef}
|
||||
testID="direct-host-input"
|
||||
nativeID="direct-host-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.host")}
|
||||
initialValue={input.host}
|
||||
onChangeText={handleHostChange}
|
||||
onSelectionChange={handleHostSelectionChange}
|
||||
onFocus={fieldEvents.onFocus}
|
||||
onBlur={handleHostBlur}
|
||||
autoFocus={fieldEvents.autoFocus}
|
||||
placeholder="localhost"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
editable={!isSaving}
|
||||
returnKeyType="next"
|
||||
/>
|
||||
</Field>
|
||||
</View>
|
||||
<View style={portFieldStyle}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.port")}</Text>
|
||||
<AdaptiveTextInput
|
||||
ref={portInputRef}
|
||||
testID="direct-port-input"
|
||||
nativeID="direct-port-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.port")}
|
||||
initialValue={input.port}
|
||||
onChangeText={handlePortChange}
|
||||
onSelectionChange={handlePortSelectionChange}
|
||||
onFocus={fieldEvents.onFocus}
|
||||
onBlur={fieldEvents.onBlur}
|
||||
placeholder="6767"
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="number-pad"
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={fieldEvents.onSubmit}
|
||||
/>
|
||||
<View style={styles.portField}>
|
||||
<Field label={t("pairing.direct.fields.port")}>
|
||||
<FormTextInput
|
||||
ref={portInputRef}
|
||||
testID="direct-port-input"
|
||||
nativeID="direct-port-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.port")}
|
||||
initialValue={input.port}
|
||||
onChangeText={handlePortChange}
|
||||
onSelectionChange={handlePortSelectionChange}
|
||||
onFocus={fieldEvents.onFocus}
|
||||
onBlur={fieldEvents.onBlur}
|
||||
placeholder="6767"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="number-pad"
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={fieldEvents.onSubmit}
|
||||
/>
|
||||
</Field>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
@@ -788,43 +745,29 @@ function DirectFormFields({
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.useSsl")}</Text>
|
||||
</PressHighlight>
|
||||
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.password")}</Text>
|
||||
<View style={styles.passwordRow}>
|
||||
<AdaptiveTextInput
|
||||
ref={passwordInputRef}
|
||||
testID="direct-password-input"
|
||||
nativeID="direct-password-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.password")}
|
||||
initialValue={input.password}
|
||||
onChangeText={handlePasswordChange}
|
||||
onFocus={fieldEvents.onFocus}
|
||||
onBlur={fieldEvents.onBlur}
|
||||
placeholder={t("pairing.direct.fields.optional")}
|
||||
style={passwordInputStyle}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
secureTextEntry={!isPasswordVisible}
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={fieldEvents.onSubmit}
|
||||
/>
|
||||
<PressHighlight
|
||||
style={styles.iconButton}
|
||||
onPress={handleTogglePasswordVisibility}
|
||||
disabled={isSaving}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={
|
||||
isPasswordVisible
|
||||
? t("pairing.direct.passwordVisibility.hide")
|
||||
: t("pairing.direct.passwordVisibility.show")
|
||||
}
|
||||
testID="direct-password-visibility-toggle"
|
||||
>
|
||||
<PasswordIcon size={18} />
|
||||
</PressHighlight>
|
||||
</View>
|
||||
</View>
|
||||
<Field label={t("pairing.direct.fields.password")}>
|
||||
<FormTextInput
|
||||
ref={passwordInputRef}
|
||||
testID="direct-password-input"
|
||||
nativeID="direct-password-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.password")}
|
||||
initialValue={input.password}
|
||||
onChangeText={handlePasswordChange}
|
||||
onFocus={fieldEvents.onFocus}
|
||||
onBlur={fieldEvents.onBlur}
|
||||
placeholder={t("pairing.direct.fields.optional")}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
secureTextEntry
|
||||
revealable
|
||||
revealAccessibilityLabel={t("pairing.direct.passwordVisibility.show")}
|
||||
hideAccessibilityLabel={t("pairing.direct.passwordVisibility.hide")}
|
||||
revealTestID="direct-password-visibility-toggle"
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={fieldEvents.onSubmit}
|
||||
/>
|
||||
</Field>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -852,9 +795,8 @@ function DirectUriFields({
|
||||
|
||||
return (
|
||||
<>
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>{t("pairing.direct.fields.connectionUri")}</Text>
|
||||
<AdaptiveTextInput
|
||||
<Field label={t("pairing.direct.fields.connectionUri")}>
|
||||
<FormTextInput
|
||||
testID="direct-host-uri-input"
|
||||
nativeID="direct-host-uri-input"
|
||||
accessibilityLabel={t("pairing.direct.fields.connectionUri")}
|
||||
@@ -864,7 +806,6 @@ function DirectUriFields({
|
||||
onBlur={fieldEvents.onBlur}
|
||||
autoFocus={fieldEvents.autoFocus}
|
||||
placeholder="tcp://localhost:6767?ssl=true"
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
@@ -872,14 +813,11 @@ function DirectUriFields({
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={fieldEvents.onSubmit}
|
||||
/>
|
||||
</View>
|
||||
</Field>
|
||||
|
||||
{input.prompt ? (
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>
|
||||
{t("pairing.hostPassword.title", { host: input.prompt.host })}
|
||||
</Text>
|
||||
<AdaptiveTextInput
|
||||
<Field label={t("pairing.hostPassword.title", { host: input.prompt.host })}>
|
||||
<FormTextInput
|
||||
testID="direct-uri-password-input"
|
||||
accessibilityLabel={t("pairing.hostPassword.label")}
|
||||
placeholder={t("pairing.hostPassword.label")}
|
||||
@@ -889,14 +827,16 @@ function DirectUriFields({
|
||||
onBlur={fieldEvents.onBlur}
|
||||
autoFocus
|
||||
secureTextEntry
|
||||
revealable
|
||||
revealAccessibilityLabel={t("pairing.direct.passwordVisibility.show")}
|
||||
hideAccessibilityLabel={t("pairing.direct.passwordVisibility.hide")}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={fieldEvents.onSubmit}
|
||||
style={styles.input}
|
||||
/>
|
||||
</View>
|
||||
</Field>
|
||||
) : null}
|
||||
</>
|
||||
);
|
||||
@@ -905,7 +845,3 @@ function DirectUriFields({
|
||||
const ThemedLink2 = withUnistyles(Link2, (theme) => ({ color: theme.colors.accentForeground }));
|
||||
|
||||
const ThemedCheck = withUnistyles(Check, (theme) => ({ color: theme.colors.accentForeground }));
|
||||
|
||||
const ThemedEye = withUnistyles(Eye, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
|
||||
const ThemedEyeOff = withUnistyles(EyeOff, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
import { PressHighlight } from "@/components/ui/press-highlight";
|
||||
import { useCallback, useMemo, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Text,
|
||||
View,
|
||||
type PressableStateCallbackType,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
import { Text, View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { Eye, EyeOff, Terminal } from "lucide-react-native";
|
||||
import { Terminal } from "lucide-react-native";
|
||||
import { parseSshTransportUri } from "@getpaseo/protocol/ssh-transport";
|
||||
import type { HostProfile } from "@/types/host-connection";
|
||||
import { useHostMutations, useHosts } from "@/runtime/host-runtime";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
import {
|
||||
CONTROL_HEIGHTS,
|
||||
createControlGeometry,
|
||||
resolveControlInteractionStyles,
|
||||
} from "@/components/ui/control-geometry";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { getIsElectron, isWeb } from "@/constants/platform";
|
||||
import { resolveHostRefusal, type HostRefusalPresentation } from "@/hosts/host-refusal";
|
||||
@@ -32,56 +20,18 @@ import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-moda
|
||||
|
||||
const FLEX_ONE_STYLE = { flex: 1 } as const;
|
||||
const ThemedTerminal = withUnistyles(Terminal);
|
||||
const ThemedEye = withUnistyles(Eye, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
const ThemedEyeOff = withUnistyles(EyeOff, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
|
||||
const styles = StyleSheet.create((theme) => {
|
||||
const geometry = createControlGeometry(theme);
|
||||
return {
|
||||
helper: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
passwordRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
alignSelf: "stretch",
|
||||
width: "100%",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
passwordInputWrap: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
// Boxed adornment next to the field: same height and radius as the field
|
||||
// chrome, and the shared interaction phases.
|
||||
iconButton: {
|
||||
minHeight: CONTROL_HEIGHTS.md,
|
||||
width: CONTROL_HEIGHTS.md,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
controlRest: {
|
||||
...geometry.controlRest,
|
||||
},
|
||||
controlHover: {
|
||||
...geometry.controlHover,
|
||||
},
|
||||
controlActive: {
|
||||
...geometry.controlActive,
|
||||
},
|
||||
controlDisabled: {
|
||||
...geometry.controlDisabled,
|
||||
},
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
marginTop: theme.spacing[2],
|
||||
},
|
||||
};
|
||||
});
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
helper: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
marginTop: theme.spacing[2],
|
||||
},
|
||||
}));
|
||||
|
||||
export interface AddRemoteSshHostModalProps {
|
||||
visible: boolean;
|
||||
@@ -200,31 +150,6 @@ export function AddRemoteSshHostModal({
|
||||
const handlePasswordChange = useCallback((value: string) => {
|
||||
passwordRef.current = value;
|
||||
}, []);
|
||||
const handleTogglePasswordVisibility = useCallback(() => {
|
||||
setIsPasswordVisible((currentlyVisible) => !currentlyVisible);
|
||||
}, []);
|
||||
const iconButtonStyle = useCallback(
|
||||
(
|
||||
state: PressableStateCallbackType & { hovered?: boolean; focused?: boolean },
|
||||
): StyleProp<ViewStyle> => [
|
||||
styles.iconButton,
|
||||
resolveControlInteractionStyles(
|
||||
{
|
||||
controlRest: styles.controlRest,
|
||||
controlHover: styles.controlHover,
|
||||
controlActive: styles.controlActive,
|
||||
controlDisabled: styles.controlDisabled,
|
||||
},
|
||||
{
|
||||
hovered: state.hovered,
|
||||
pressed: state.pressed,
|
||||
focused: state.focused,
|
||||
disabled: isSaving,
|
||||
},
|
||||
),
|
||||
],
|
||||
[isSaving],
|
||||
);
|
||||
const handleSubmit = useCallback(() => void handleSave(), [handleSave]);
|
||||
|
||||
return (
|
||||
@@ -255,38 +180,26 @@ export function AddRemoteSshHostModal({
|
||||
/>
|
||||
</Field>
|
||||
<Field label={t("pairing.remoteSsh.fields.password")} testID="remote-ssh-password">
|
||||
<View style={styles.passwordRow}>
|
||||
<View style={styles.passwordInputWrap}>
|
||||
<FormTextInput
|
||||
ref={passwordInputRef}
|
||||
testID="remote-ssh-password-input"
|
||||
accessibilityLabel={t("pairing.remoteSsh.fields.password")}
|
||||
initialValue=""
|
||||
onChangeText={handlePasswordChange}
|
||||
placeholder={t("pairing.remoteSsh.fields.optional")}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
secureTextEntry={!isPasswordVisible}
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={handleSubmit}
|
||||
/>
|
||||
</View>
|
||||
<PressHighlight
|
||||
style={iconButtonStyle}
|
||||
onPress={handleTogglePasswordVisibility}
|
||||
disabled={isSaving}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={
|
||||
isPasswordVisible
|
||||
? t("pairing.remoteSsh.passwordVisibility.hide")
|
||||
: t("pairing.remoteSsh.passwordVisibility.show")
|
||||
}
|
||||
testID="remote-ssh-password-visibility-toggle"
|
||||
>
|
||||
{isPasswordVisible ? <ThemedEyeOff size={18} /> : <ThemedEye size={18} />}
|
||||
</PressHighlight>
|
||||
</View>
|
||||
<FormTextInput
|
||||
ref={passwordInputRef}
|
||||
testID="remote-ssh-password-input"
|
||||
accessibilityLabel={t("pairing.remoteSsh.fields.password")}
|
||||
initialValue=""
|
||||
onChangeText={handlePasswordChange}
|
||||
placeholder={t("pairing.remoteSsh.fields.optional")}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
secureTextEntry
|
||||
revealable
|
||||
revealed={isPasswordVisible}
|
||||
onRevealedChange={setIsPasswordVisible}
|
||||
revealAccessibilityLabel={t("pairing.remoteSsh.passwordVisibility.show")}
|
||||
hideAccessibilityLabel={t("pairing.remoteSsh.passwordVisibility.hide")}
|
||||
revealTestID="remote-ssh-password-visibility-toggle"
|
||||
editable={!isSaving}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={handleSubmit}
|
||||
/>
|
||||
</Field>
|
||||
{refusalPresentation ? (
|
||||
<HostRefusalInlineAlert presentation={refusalPresentation} testID="remote-ssh-refusal" />
|
||||
|
||||
@@ -7,11 +7,7 @@ import { Link } from "lucide-react-native";
|
||||
import type { HostProfile } from "@/types/host-connection";
|
||||
import { useHosts, useHostMutations, type PasswordRequiredPairing } from "@/runtime/host-runtime";
|
||||
import { uriHostLabel } from "./direct-connection";
|
||||
import {
|
||||
AdaptiveModalSheet,
|
||||
AdaptiveTextInput,
|
||||
type SheetHeader,
|
||||
} from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { getIsElectron, isWeb } from "@/constants/platform";
|
||||
import {
|
||||
isPasswordRefusal,
|
||||
@@ -22,6 +18,7 @@ import { HostRefusalInlineAlert } from "@/hosts/host-refusal-body";
|
||||
import { getConnectionHelloRejection } from "@/utils/test-daemon-connection";
|
||||
import { PairingTargetTracker } from "@/components/pair-link-credentials";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
|
||||
const FLEX_ONE_STYLE = { flex: 1 } as const;
|
||||
@@ -35,27 +32,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
field: {
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
label: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.base,
|
||||
fontWeight: theme.fontWeight.medium,
|
||||
},
|
||||
input: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
paddingHorizontal: theme.spacing[4],
|
||||
paddingVertical: theme.spacing[3],
|
||||
color: theme.colors.foreground,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
},
|
||||
error: {
|
||||
color: theme.colors.destructive,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
actions: {
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
@@ -224,9 +200,8 @@ function PairLinkModalContent({
|
||||
>
|
||||
<Text style={styles.helper}>{t("pairing.link.helper")}</Text>
|
||||
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>{t("pairing.link.label")}</Text>
|
||||
<AdaptiveTextInput
|
||||
<Field label={t("pairing.link.label")} error={errorMessage || null}>
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
initialValue={initialUrl}
|
||||
testID="pair-link-input"
|
||||
@@ -234,24 +209,22 @@ function PairLinkModalContent({
|
||||
accessibilityLabel={t("pairing.link.label")}
|
||||
onChangeText={handleChangeOfferUrl}
|
||||
placeholder="https://app.paseo.sh/#offer=..."
|
||||
style={styles.input}
|
||||
autoFocus
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
keyboardType="url"
|
||||
invalid={errorMessage.length > 0}
|
||||
/>
|
||||
{errorMessage ? <Text style={styles.error}>{errorMessage}</Text> : null}
|
||||
{refusalPresentation ? (
|
||||
<HostRefusalInlineAlert presentation={refusalPresentation} testID="pair-link-refusal" />
|
||||
) : null}
|
||||
</View>
|
||||
</Field>
|
||||
{refusalPresentation ? (
|
||||
<HostRefusalInlineAlert presentation={refusalPresentation} testID="pair-link-refusal" />
|
||||
) : null}
|
||||
|
||||
{needsPassword ? (
|
||||
<View style={styles.field}>
|
||||
<Text style={styles.label}>
|
||||
{t("pairing.hostPassword.title", { host: parsedHostLabel(offerUrlRef.current) })}
|
||||
</Text>
|
||||
<AdaptiveTextInput
|
||||
<Field
|
||||
label={t("pairing.hostPassword.title", { host: parsedHostLabel(offerUrlRef.current) })}
|
||||
>
|
||||
<FormTextInput
|
||||
testID="pair-link-password-input"
|
||||
resetKey={`pair-link-password-${passwordResetKey}`}
|
||||
accessibilityLabel={t("pairing.hostPassword.label")}
|
||||
@@ -259,9 +232,11 @@ function PairLinkModalContent({
|
||||
onChangeText={setPassword}
|
||||
autoFocus
|
||||
secureTextEntry
|
||||
style={styles.input}
|
||||
revealable
|
||||
revealAccessibilityLabel={t("pairing.direct.passwordVisibility.show")}
|
||||
hideAccessibilityLabel={t("pairing.direct.passwordVisibility.hide")}
|
||||
/>
|
||||
</View>
|
||||
</Field>
|
||||
) : null}
|
||||
|
||||
<View style={styles.actions}>
|
||||
|
||||
@@ -3,12 +3,10 @@ import { useAddHost } from "@/hosts/add-host";
|
||||
import { Modal } from "@/components/ui/modal";
|
||||
import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { Pressable, ScrollView, Text, View, type PressableStateCallbackType } from "react-native";
|
||||
import {
|
||||
EditingTextInput as TextInput,
|
||||
type EditingTextInputHandle,
|
||||
} from "@/components/ui/text-input";
|
||||
import { SearchField } from "@/components/ui/search-field";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { create } from "zustand";
|
||||
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { HostStatusDot } from "@/components/host-status-dot";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { useLocalDaemonServerId } from "@/hooks/use-is-local-daemon";
|
||||
@@ -153,7 +151,6 @@ function HostChooserRow({
|
||||
}
|
||||
|
||||
export function HostChooserModal() {
|
||||
const { theme } = useUnistyles();
|
||||
const hosts = useHosts();
|
||||
const request = useHostChooserStore((state) => state.request);
|
||||
const close = useHostChooserStore((state) => state.close);
|
||||
@@ -260,17 +257,17 @@ export function HostChooserModal() {
|
||||
<View ref={setOverlayScope} style={styles.panel}>
|
||||
<View style={styles.header}>
|
||||
<Text style={styles.title}>{request.title}</Text>
|
||||
<TextInput
|
||||
ref={inputRef}
|
||||
initialValue={query}
|
||||
onChangeText={handleQueryChange}
|
||||
placeholder="Search hosts..."
|
||||
placeholderTextColor={theme.colors.foregroundMuted}
|
||||
style={styles.input}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
testID="host-chooser-search"
|
||||
/>
|
||||
<View style={styles.searchRow}>
|
||||
<SearchField
|
||||
ref={inputRef}
|
||||
value={query}
|
||||
onChangeText={handleQueryChange}
|
||||
placeholder="Search hosts..."
|
||||
clearAccessibilityLabel="Clear search"
|
||||
fullWidth
|
||||
testID="host-chooser-search"
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
<ScrollView
|
||||
style={styles.results}
|
||||
@@ -333,12 +330,9 @@ const styles = StyleSheet.create((theme) => ({
|
||||
fontSize: theme.fontSize.base,
|
||||
fontWeight: theme.fontWeight.medium,
|
||||
},
|
||||
input: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
padding: 0,
|
||||
outlineStyle: "none",
|
||||
} as object,
|
||||
searchRow: {
|
||||
flexDirection: "row",
|
||||
},
|
||||
results: {
|
||||
maxHeight: 420,
|
||||
},
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
import { useCallback, useMemo, useReducer, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Text,
|
||||
View,
|
||||
type PressableStateCallbackType,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
import { AlertTriangle, Eye, EyeOff } from "lucide-react-native";
|
||||
import { Text, View } from "react-native";
|
||||
import { AlertTriangle } from "lucide-react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import type { DaemonHelloRejection } from "@getpaseo/client/internal/daemon-client";
|
||||
import {
|
||||
@@ -18,14 +12,8 @@ import {
|
||||
import { Alert as InlineAlert } from "@/components/ui/alert";
|
||||
import { HeaderToggleButton } from "@/components/headers/header-toggle-button";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
CONTROL_HEIGHTS,
|
||||
createControlGeometry,
|
||||
resolveControlInteractionStyles,
|
||||
} from "@/components/ui/control-geometry";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
import { iconButtonChromeGlyphSize } from "@/components/ui/icon-button-chrome";
|
||||
import { PressHighlight } from "@/components/ui/press-highlight";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { getIsElectron, isWeb } from "@/constants/platform";
|
||||
import {
|
||||
@@ -58,8 +46,6 @@ import type { ShortcutKey } from "@/utils/format-shortcut";
|
||||
|
||||
const FLEX_ONE_STYLE = { flex: 1 } as const;
|
||||
const NO_SHORTCUT: ShortcutKey[] = [];
|
||||
const ThemedEye = withUnistyles(Eye, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
const ThemedEyeOff = withUnistyles(EyeOff, (theme) => ({ color: theme.colors.foregroundMuted }));
|
||||
const ThemedAlertTriangle = withUnistyles(AlertTriangle, (theme) => ({
|
||||
color: theme.colors.destructive,
|
||||
}));
|
||||
@@ -471,141 +457,65 @@ function HostRefusalPasswordField({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const iconButtonStyle = useCallback(
|
||||
(
|
||||
state: PressableStateCallbackType & { hovered?: boolean; focused?: boolean },
|
||||
): StyleProp<ViewStyle> => [
|
||||
styles.iconButton,
|
||||
controlSize === "sm" ? styles.iconButtonSm : styles.iconButtonMd,
|
||||
resolveControlInteractionStyles(
|
||||
{
|
||||
controlRest: styles.controlRest,
|
||||
controlHover: styles.controlHover,
|
||||
controlActive: styles.controlActive,
|
||||
controlDisabled: styles.controlDisabled,
|
||||
},
|
||||
{
|
||||
hovered: state.hovered,
|
||||
pressed: state.pressed,
|
||||
focused: state.focused,
|
||||
disabled: isSubmitting,
|
||||
},
|
||||
),
|
||||
],
|
||||
[controlSize, isSubmitting],
|
||||
);
|
||||
|
||||
return (
|
||||
<Field
|
||||
label={t("hostRefusal.passwordSheet.label")}
|
||||
error={errorMessage}
|
||||
testID="host-password-field"
|
||||
>
|
||||
<View style={styles.passwordRow}>
|
||||
<View style={styles.passwordInputWrap}>
|
||||
<FormTextInput
|
||||
testID="host-password-input"
|
||||
nativeID="host-password-input"
|
||||
size={controlSize}
|
||||
resetKey={`host-password-${serverId}-${resetCount}`}
|
||||
initialValue=""
|
||||
accessibilityLabel={t("hostRefusal.passwordSheet.label")}
|
||||
placeholder={t("hostRefusal.passwordSheet.placeholder")}
|
||||
onChangeText={onChangeText}
|
||||
autoFocus
|
||||
secureTextEntry={!isPasswordVisible}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
editable={!isSubmitting}
|
||||
invalid={errorMessage !== null}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={onSubmit}
|
||||
/>
|
||||
</View>
|
||||
<PressHighlight
|
||||
style={iconButtonStyle}
|
||||
onPress={onToggleVisibility}
|
||||
disabled={isSubmitting}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={
|
||||
isPasswordVisible
|
||||
? t("pairing.direct.passwordVisibility.hide")
|
||||
: t("pairing.direct.passwordVisibility.show")
|
||||
}
|
||||
testID="host-password-visibility-toggle"
|
||||
>
|
||||
{isPasswordVisible ? <ThemedEyeOff size={18} /> : <ThemedEye size={18} />}
|
||||
</PressHighlight>
|
||||
</View>
|
||||
<FormTextInput
|
||||
testID="host-password-input"
|
||||
nativeID="host-password-input"
|
||||
size={controlSize}
|
||||
resetKey={`host-password-${serverId}-${resetCount}`}
|
||||
initialValue=""
|
||||
accessibilityLabel={t("hostRefusal.passwordSheet.label")}
|
||||
placeholder={t("hostRefusal.passwordSheet.placeholder")}
|
||||
onChangeText={onChangeText}
|
||||
autoFocus
|
||||
secureTextEntry
|
||||
revealable
|
||||
revealed={isPasswordVisible}
|
||||
onRevealedChange={onToggleVisibility}
|
||||
revealAccessibilityLabel={t("pairing.direct.passwordVisibility.show")}
|
||||
hideAccessibilityLabel={t("pairing.direct.passwordVisibility.hide")}
|
||||
revealTestID="host-password-visibility-toggle"
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
editable={!isSubmitting}
|
||||
invalid={errorMessage !== null}
|
||||
returnKeyType="done"
|
||||
onSubmitEditing={onSubmit}
|
||||
/>
|
||||
</Field>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create((theme) => {
|
||||
const geometry = createControlGeometry(theme);
|
||||
return {
|
||||
content: {
|
||||
gap: theme.spacing[4],
|
||||
},
|
||||
description: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.base,
|
||||
lineHeight: Math.round(theme.fontSize.base * 1.45),
|
||||
},
|
||||
hostMessageCard: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
paddingVertical: theme.spacing[3],
|
||||
},
|
||||
hostMessage: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.sm,
|
||||
lineHeight: Math.round(theme.fontSize.sm * 1.45),
|
||||
},
|
||||
passwordRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
alignSelf: "stretch",
|
||||
width: "100%",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
passwordInputWrap: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
},
|
||||
iconButton: {
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
iconButtonSm: {
|
||||
minHeight: CONTROL_HEIGHTS.sm,
|
||||
width: CONTROL_HEIGHTS.sm,
|
||||
},
|
||||
iconButtonMd: {
|
||||
minHeight: CONTROL_HEIGHTS.md,
|
||||
width: CONTROL_HEIGHTS.md,
|
||||
},
|
||||
controlRest: {
|
||||
...geometry.controlRest,
|
||||
},
|
||||
controlHover: {
|
||||
...geometry.controlHover,
|
||||
},
|
||||
controlActive: {
|
||||
...geometry.controlActive,
|
||||
},
|
||||
controlDisabled: {
|
||||
...geometry.controlDisabled,
|
||||
},
|
||||
footer: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
},
|
||||
};
|
||||
});
|
||||
const styles = StyleSheet.create((theme) => ({
|
||||
content: {
|
||||
gap: theme.spacing[4],
|
||||
},
|
||||
description: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.base,
|
||||
lineHeight: Math.round(theme.fontSize.base * 1.45),
|
||||
},
|
||||
hostMessageCard: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
paddingVertical: theme.spacing[3],
|
||||
},
|
||||
hostMessage: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.sm,
|
||||
lineHeight: Math.round(theme.fontSize.sm * 1.45),
|
||||
},
|
||||
footer: {
|
||||
flex: 1,
|
||||
flexDirection: "row",
|
||||
gap: theme.spacing[3],
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -43,9 +43,6 @@ export function findShortcutPlatform(): FindShortcutPlatform {
|
||||
return { isMac: getShortcutOs() === "mac" };
|
||||
}
|
||||
|
||||
const TextInput = withUnistyles(EditingTextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
const ArrowUpIcon = withUnistyles(ArrowUp, mutedIconColorMapping);
|
||||
const ArrowDownIcon = withUnistyles(ArrowDown, mutedIconColorMapping);
|
||||
const CloseIcon = withUnistyles(X, mutedIconColorMapping);
|
||||
@@ -113,7 +110,7 @@ const FindField = forwardRef<
|
||||
);
|
||||
return (
|
||||
<View style={fieldStyle}>
|
||||
<TextInput
|
||||
<EditingTextInput
|
||||
ref={ref}
|
||||
autoFocus={autoFocus}
|
||||
initialValue={initialValue}
|
||||
|
||||
@@ -6,20 +6,16 @@ import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import type { AgentModelDefinition } from "@getpaseo/protocol/agent-types";
|
||||
import type { ProviderProfileModel } from "@getpaseo/protocol/provider-config";
|
||||
import { compareMatchScores, scoreTextFields } from "@getpaseo/protocol/search/text-match";
|
||||
import {
|
||||
AdaptiveModalSheet,
|
||||
AdaptiveTextInput,
|
||||
type SheetHeader,
|
||||
} from "@/components/adaptive-modal-sheet";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { SettingsRow, SettingsSection } from "@/components/settings";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { CheckboxRow } from "@/components/ui/checkbox";
|
||||
import { bySizing, TOUCH_TARGET } from "@/components/ui/control-geometry";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
import { IndependentScrollBoundary } from "@/components/ui/independent-scroll-boundary";
|
||||
import { ToolbarButton, paneContentToolbarIconSize } from "@/components/ui/pane-content-toolbar";
|
||||
import { SearchField } from "@/components/ui/search-field";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
import { useDaemonConfig } from "@/hooks/use-daemon-config";
|
||||
import { useHostFeature } from "@/runtime/host-features";
|
||||
import { CODE_SURFACE_DATASET } from "@/styles/code-surface";
|
||||
@@ -36,9 +32,6 @@ import { useShownModelsEditor, type ShownModelsEditor } from "./use-shown-models
|
||||
|
||||
const ThemedTrash = withUnistyles(Trash2);
|
||||
const destructiveColorMapping = (theme: Theme) => ({ color: theme.colors.destructive });
|
||||
const ThemedTextInput = withUnistyles(AdaptiveTextInput, (theme: Theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
|
||||
function rankModels<T>(items: T[], query: string, fields: (item: T) => string[]): T[] {
|
||||
if (!query) return items;
|
||||
@@ -467,20 +460,20 @@ function AddCustomModelSheet({
|
||||
testID="add-custom-model-sheet"
|
||||
>
|
||||
<View style={styles.formGroup}>
|
||||
<Text style={styles.formLabel}>{t("settings.providers.models.modelId")}</Text>
|
||||
<ThemedTextInput
|
||||
initialValue={input}
|
||||
resetKey={`add-custom-${visible}`}
|
||||
onChangeText={setInput}
|
||||
onSubmitEditing={handleAdd}
|
||||
placeholder={t("settings.providers.models.modelIdPlaceholder")}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
returnKeyType="done"
|
||||
// @ts-expect-error - outlineStyle is web-only
|
||||
style={[styles.formInput, isWeb && { outlineStyle: "none" }]}
|
||||
/>
|
||||
{error ? <Text style={styles.errorText}>{error}</Text> : null}
|
||||
<Field label={t("settings.providers.models.modelId")} error={error}>
|
||||
<FormTextInput
|
||||
initialValue={input}
|
||||
resetKey={`add-custom-${visible}`}
|
||||
onChangeText={setInput}
|
||||
onSubmitEditing={handleAdd}
|
||||
placeholder={t("settings.providers.models.modelIdPlaceholder")}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
returnKeyType="done"
|
||||
invalid={error !== null}
|
||||
testID="add-custom-model-input"
|
||||
/>
|
||||
</Field>
|
||||
<View style={styles.formActions}>
|
||||
<Button variant="secondary" onPress={onClose} disabled={saving}>
|
||||
{t("common.actions.cancel")}
|
||||
@@ -551,25 +544,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
formGroup: {
|
||||
gap: theme.spacing[3],
|
||||
},
|
||||
formLabel: {
|
||||
fontSize: theme.fontSize.base,
|
||||
fontWeight: theme.fontWeight.medium,
|
||||
color: theme.colors.foreground,
|
||||
},
|
||||
formInput: {
|
||||
backgroundColor: theme.colors.surface2,
|
||||
borderRadius: theme.borderRadius.lg,
|
||||
paddingHorizontal: theme.spacing[4],
|
||||
paddingVertical: theme.spacing[3],
|
||||
color: theme.colors.foreground,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
errorText: {
|
||||
fontSize: theme.fontSize.sm,
|
||||
color: theme.colors.destructive,
|
||||
},
|
||||
formActions: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
|
||||
@@ -13,17 +13,14 @@ import {
|
||||
Pressable,
|
||||
type PressableStateCallbackType,
|
||||
Text,
|
||||
type TextStyle,
|
||||
View,
|
||||
type StyleProp,
|
||||
type ViewStyle,
|
||||
} from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
EditingTextInput as TextInput,
|
||||
type EditingTextInputHandle,
|
||||
} from "@/components/ui/text-input";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { createReviewEditorScope } from "./editor";
|
||||
import { isWeb } from "@/constants/platform";
|
||||
@@ -407,7 +404,6 @@ export function InlineReviewEditor({
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const inputRef = useRef<EditingTextInputHandle | null>(null);
|
||||
const [isFocused, setIsFocused] = useState(false);
|
||||
const trimmedBody = body.trim();
|
||||
const canSave = trimmedBody.length > 0;
|
||||
|
||||
@@ -415,12 +411,6 @@ export function InlineReviewEditor({
|
||||
inputRef.current?.focus();
|
||||
}, []);
|
||||
|
||||
const handleFocus = useCallback(() => {
|
||||
setIsFocused(true);
|
||||
}, []);
|
||||
const handleBlur = useCallback(() => {
|
||||
setIsFocused(false);
|
||||
}, []);
|
||||
const handleSave = useCallback(() => onSave(trimmedBody), [onSave, trimmedBody]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -457,25 +447,18 @@ export function InlineReviewEditor({
|
||||
};
|
||||
}, [canSave, handleSave, onCancel]);
|
||||
|
||||
const inputStyle = useMemo<StyleProp<TextStyle>>(
|
||||
() => [styles.editorInput, isFocused && styles.editorInputFocused],
|
||||
[isFocused],
|
||||
);
|
||||
|
||||
return (
|
||||
<View style={styles.editorBlock} testID={testID}>
|
||||
<TextInput
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
accessibilityLabel={t("review.comment.label")}
|
||||
testID={testID ? `${testID}-input` : undefined}
|
||||
placeholder={t("review.comment.placeholder")}
|
||||
placeholderTextColor={styles.placeholderColor.color}
|
||||
multiline
|
||||
initialValue={body}
|
||||
onChangeText={onChangeBody}
|
||||
onFocus={handleFocus}
|
||||
onBlur={handleBlur}
|
||||
style={inputStyle}
|
||||
frameStyle={styles.editorFrame}
|
||||
inputStyle={styles.editorInput}
|
||||
/>
|
||||
<View style={styles.editorActions}>
|
||||
<Button
|
||||
@@ -538,9 +521,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
zIndex: 10,
|
||||
elevation: 10,
|
||||
},
|
||||
placeholderColor: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
threadContainer: {
|
||||
flex: 1,
|
||||
minWidth: 0,
|
||||
@@ -602,28 +582,14 @@ const styles = StyleSheet.create((theme) => ({
|
||||
paddingVertical: theme.spacing[3],
|
||||
gap: theme.spacing[3],
|
||||
},
|
||||
editorInput: {
|
||||
editorFrame: {
|
||||
flex: 1,
|
||||
minHeight: 0,
|
||||
color: theme.colors.foreground,
|
||||
backgroundColor: theme.colors.surface1,
|
||||
borderWidth: theme.borderWidth[1],
|
||||
borderColor: theme.colors.border,
|
||||
borderRadius: theme.borderRadius.md,
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
paddingVertical: theme.spacing[2],
|
||||
},
|
||||
editorInput: {
|
||||
fontSize: theme.fontSize.content,
|
||||
lineHeight: theme.fontSize.content * 1.4,
|
||||
textAlignVertical: "top",
|
||||
...(isWeb
|
||||
? {
|
||||
outlineWidth: 0,
|
||||
outlineColor: "transparent",
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
editorInputFocused: {
|
||||
borderColor: theme.colors.accent,
|
||||
},
|
||||
editorActions: {
|
||||
flexDirection: "row",
|
||||
|
||||
@@ -25,13 +25,12 @@ import { LoadingSpinner } from "@/components/ui/loading-spinner";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { ProjectEditSheet } from "@/components/project-edit-sheet";
|
||||
import { EditingTextInput as TextInput } from "@/components/ui/text-input";
|
||||
import { SettingsTextAreaCard } from "@/components/settings-textarea";
|
||||
import { Field, FormTextInput } from "@/components/ui/form-field";
|
||||
import { SettingsGroup } from "@/components/settings/headings/settings-group";
|
||||
import { SettingsSection } from "@/components/settings/headings/settings-section";
|
||||
import type { PageTitleParent } from "@/components/page-layout";
|
||||
import { useIsCompactFormFactor } from "@/constants/layout";
|
||||
import { SettingsDetailHeader } from "@/components/settings";
|
||||
import { SettingsCard, SettingsDetailHeader } from "@/components/settings";
|
||||
import { settingsStyles } from "@/styles/settings";
|
||||
import { useProjects } from "@/hooks/use-projects";
|
||||
import type { ProjectEditFormSnapshot } from "@/projects/edit-form";
|
||||
@@ -698,13 +697,18 @@ function ProjectConfigForm({
|
||||
description={t("settings.project.worktree.uncommittedDescription")}
|
||||
/>
|
||||
) : null}
|
||||
<SettingsTextAreaCard
|
||||
testID="worktree-setup-input"
|
||||
accessibilityLabel={t("settings.project.worktree.setupAccessibility")}
|
||||
value={draft.setupText}
|
||||
onChangeText={handleSetupChange}
|
||||
placeholder="npm install"
|
||||
/>
|
||||
<SettingsCard>
|
||||
<FormTextInput
|
||||
appearance="flush"
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
testID="worktree-setup-input"
|
||||
accessibilityLabel={t("settings.project.worktree.setupAccessibility")}
|
||||
initialValue={draft.setupText}
|
||||
onChangeText={handleSetupChange}
|
||||
placeholder="npm install"
|
||||
/>
|
||||
</SettingsCard>
|
||||
</SettingsSection>
|
||||
|
||||
<SettingsSection
|
||||
@@ -713,13 +717,18 @@ function ProjectConfigForm({
|
||||
link={teardownDocsLink}
|
||||
flush
|
||||
>
|
||||
<SettingsTextAreaCard
|
||||
testID="worktree-teardown-input"
|
||||
accessibilityLabel={t("settings.project.worktree.teardownAccessibility")}
|
||||
value={draft.teardownText}
|
||||
onChangeText={handleTeardownChange}
|
||||
placeholder="docker compose down"
|
||||
/>
|
||||
<SettingsCard>
|
||||
<FormTextInput
|
||||
appearance="flush"
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
testID="worktree-teardown-input"
|
||||
accessibilityLabel={t("settings.project.worktree.teardownAccessibility")}
|
||||
initialValue={draft.teardownText}
|
||||
onChangeText={handleTeardownChange}
|
||||
placeholder="docker compose down"
|
||||
/>
|
||||
</SettingsCard>
|
||||
</SettingsSection>
|
||||
</SettingsGroup>
|
||||
|
||||
@@ -868,13 +877,18 @@ function MetadataPromptSection({ promptKey, value, onChange, flush }: MetadataPr
|
||||
);
|
||||
return (
|
||||
<SettingsSection title={title} testID={meta.sectionTestID} flush={flush}>
|
||||
<SettingsTextAreaCard
|
||||
testID={meta.inputTestID}
|
||||
accessibilityLabel={title}
|
||||
value={value}
|
||||
onChangeText={handleChange}
|
||||
placeholder={t(meta.placeholderKey)}
|
||||
/>
|
||||
<SettingsCard>
|
||||
<FormTextInput
|
||||
appearance="flush"
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
testID={meta.inputTestID}
|
||||
accessibilityLabel={title}
|
||||
initialValue={value}
|
||||
onChangeText={handleChange}
|
||||
placeholder={t(meta.placeholderKey)}
|
||||
/>
|
||||
</SettingsCard>
|
||||
</SettingsSection>
|
||||
);
|
||||
}
|
||||
@@ -1026,43 +1040,39 @@ function ScriptEditModal({ script, onChange, onCancel, onSave }: ScriptEditModal
|
||||
testID="script-edit-modal"
|
||||
desktopMaxWidth={560}
|
||||
>
|
||||
<View style={styles.modalSection}>
|
||||
<Text style={styles.modalLabel}>{t("settings.project.scripts.name")}</Text>
|
||||
<TextInput
|
||||
<Field
|
||||
label={t("settings.project.scripts.name")}
|
||||
error={showNameError ? validation.nameError : null}
|
||||
errorTestID="script-edit-name-error"
|
||||
>
|
||||
<FormTextInput
|
||||
testID="script-edit-name"
|
||||
accessibilityLabel={t("settings.project.scripts.nameAccessibility")}
|
||||
initialValue={script.name}
|
||||
onChangeText={handleNameChange}
|
||||
onBlur={handleNameBlur}
|
||||
placeholder="dev"
|
||||
placeholderTextColor={styles.placeholderColor.color}
|
||||
style={styles.modalInput}
|
||||
invalid={Boolean(showNameError)}
|
||||
/>
|
||||
{showNameError ? (
|
||||
<Text testID="script-edit-name-error" style={styles.fieldError}>
|
||||
{validation.nameError}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
<View style={styles.modalSection}>
|
||||
<Text style={styles.modalLabel}>{t("settings.project.scripts.command")}</Text>
|
||||
<TextInput
|
||||
</Field>
|
||||
<Field
|
||||
label={t("settings.project.scripts.command")}
|
||||
error={showCommandError ? validation.commandError : null}
|
||||
errorTestID="script-edit-command-error"
|
||||
>
|
||||
<FormTextInput
|
||||
testID="script-edit-command"
|
||||
accessibilityLabel={t("settings.project.scripts.commandAccessibility")}
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
monospace
|
||||
initialValue={script.commandText}
|
||||
onChangeText={handleCommandChange}
|
||||
onBlur={handleCommandBlur}
|
||||
placeholder="npm run dev"
|
||||
placeholderTextColor={styles.placeholderColor.color}
|
||||
style={styles.modalMultilineInput}
|
||||
invalid={Boolean(showCommandError)}
|
||||
/>
|
||||
{showCommandError ? (
|
||||
<Text testID="script-edit-command-error" style={styles.fieldError}>
|
||||
{validation.commandError}
|
||||
</Text>
|
||||
) : null}
|
||||
</View>
|
||||
</Field>
|
||||
<View style={styles.modalSection}>
|
||||
<View style={styles.serviceToggleRow}>
|
||||
<View style={styles.serviceToggleText}>
|
||||
@@ -1159,42 +1169,12 @@ const styles = StyleSheet.create((theme) => ({
|
||||
modalSection: {
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
modalLabel: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
modalInput: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
paddingVertical: theme.spacing[2],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
borderRadius: theme.borderRadius.md,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
},
|
||||
modalMultilineInput: {
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
paddingVertical: theme.spacing[2],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
borderRadius: theme.borderRadius.md,
|
||||
borderWidth: 1,
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
minHeight: 100,
|
||||
textAlignVertical: "top",
|
||||
},
|
||||
modalFooter: {
|
||||
flexDirection: "row",
|
||||
justifyContent: "flex-end",
|
||||
gap: theme.spacing[2],
|
||||
marginTop: theme.spacing[2],
|
||||
},
|
||||
fieldError: {
|
||||
color: theme.colors.palette.red[300],
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
serviceToggleRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
@@ -1214,9 +1194,6 @@ const styles = StyleSheet.create((theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.sm,
|
||||
},
|
||||
placeholderColor: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
chevronColor: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import type { TFunction } from "i18next";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { View } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import {
|
||||
SYNTAX_THEME_OPTIONS,
|
||||
type SyntaxThemeId,
|
||||
@@ -13,8 +13,9 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem } from "@/component
|
||||
import { DropdownTrigger } from "@/components/ui/dropdown-trigger";
|
||||
import { SettingsSection } from "@/components/settings/headings/settings-section";
|
||||
import { ThemePicker } from "@/appearance/theme-picker";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import { EditingTextInput, type EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import type { EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
import {
|
||||
MAX_CODE_FONT_SIZE,
|
||||
MAX_CONTENT_FONT_SIZE,
|
||||
@@ -33,12 +34,6 @@ import { isNative } from "@/constants/platform";
|
||||
import { settingsStyles } from "@/styles/settings";
|
||||
import { AppearancePreview } from "./appearance-preview";
|
||||
|
||||
// Subscribe the input leaf to numeric theme changes without resetting its editing state.
|
||||
const TextInput = withUnistyles(EditingTextInput, (theme) => {
|
||||
void theme.fontSize;
|
||||
return {};
|
||||
});
|
||||
|
||||
// Platform default stacks can be the bare native tokens ("normal"/"monospace");
|
||||
// those read as a bug, so show a human label in the placeholder instead.
|
||||
const BARE_DEFAULT_STACKS: ReadonlySet<string> = new Set(["normal", "monospace"]);
|
||||
@@ -102,18 +97,18 @@ function FontFamilyRow({
|
||||
<Text style={settingsStyles.rowTitle}>{title}</Text>
|
||||
<Text style={settingsStyles.rowHint}>{hint}</Text>
|
||||
</View>
|
||||
<TextInput
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
initialValue={draft}
|
||||
onChangeText={onChangeDraft}
|
||||
onBlur={handleCommit}
|
||||
onSubmitEditing={handleCommit}
|
||||
placeholder={placeholder}
|
||||
placeholderTextColor={styles.placeholderColor.color}
|
||||
autoCapitalize="none"
|
||||
autoCorrect={false}
|
||||
spellCheck={false}
|
||||
style={styles.fontFamilyInput}
|
||||
frameStyle={styles.fontFamilyFrame}
|
||||
inputStyle={styles.fontFamilyInput}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
</View>
|
||||
@@ -152,7 +147,7 @@ function FontSizeRow({
|
||||
<Text style={settingsStyles.rowHint}>{hint}</Text>
|
||||
</View>
|
||||
<View style={styles.sizeField}>
|
||||
<TextInput
|
||||
<FormTextInput
|
||||
ref={inputRef}
|
||||
initialValue={draft}
|
||||
onChangeText={onChangeDraft}
|
||||
@@ -161,7 +156,8 @@ function FontSizeRow({
|
||||
keyboardType="number-pad"
|
||||
inputMode="numeric"
|
||||
selectTextOnFocus
|
||||
style={styles.sizeInput}
|
||||
frameStyle={styles.sizeFrame}
|
||||
inputStyle={styles.sizeInput}
|
||||
accessibilityLabel={accessibilityLabel}
|
||||
/>
|
||||
<Text style={styles.unit}>px</Text>
|
||||
@@ -501,19 +497,12 @@ const styles = StyleSheet.create((theme) => ({
|
||||
themeCard: {
|
||||
padding: theme.spacing[3],
|
||||
},
|
||||
fontFamilyInput: {
|
||||
fontFamilyFrame: {
|
||||
flexGrow: 1,
|
||||
flexShrink: 1,
|
||||
maxWidth: 280,
|
||||
minHeight: 36,
|
||||
paddingVertical: theme.spacing[2],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
borderRadius: theme.borderRadius.md,
|
||||
borderWidth: theme.borderWidth[1],
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
fontFamilyInput: {
|
||||
textAlign: "left",
|
||||
},
|
||||
sizeField: {
|
||||
@@ -521,17 +510,10 @@ const styles = StyleSheet.create((theme) => ({
|
||||
alignItems: "center",
|
||||
gap: theme.spacing[2],
|
||||
},
|
||||
sizeInput: {
|
||||
sizeFrame: {
|
||||
width: 64,
|
||||
minHeight: 36,
|
||||
paddingVertical: theme.spacing[2],
|
||||
paddingHorizontal: theme.spacing[3],
|
||||
borderRadius: theme.borderRadius.md,
|
||||
borderWidth: theme.borderWidth[1],
|
||||
borderColor: theme.colors.border,
|
||||
backgroundColor: theme.colors.surface2,
|
||||
color: theme.colors.foreground,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
sizeInput: {
|
||||
textAlign: "right",
|
||||
},
|
||||
contentWidthRow: {
|
||||
@@ -543,7 +525,4 @@ const styles = StyleSheet.create((theme) => ({
|
||||
color: theme.colors.foregroundMuted,
|
||||
fontSize: theme.fontSize.base,
|
||||
},
|
||||
placeholderColor: {
|
||||
color: theme.colors.foregroundMuted,
|
||||
},
|
||||
}));
|
||||
|
||||
@@ -26,7 +26,7 @@ import { AgentSkillsSection } from "@/agent-skills";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { PageLayout } from "@/components/page-layout";
|
||||
import { SettingsCard, SettingsRow, SettingsSection } from "@/components/settings";
|
||||
import { SettingsTextAreaCard } from "@/components/settings-textarea";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import { Alert as InlineAlert } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { StatusBadge, type StatusBadgeVariant } from "@/components/ui/status-badge";
|
||||
@@ -931,10 +931,12 @@ function AppendSystemPromptRow({ serverId }: { serverId: string }) {
|
||||
testID="host-page-append-system-prompt-sheet"
|
||||
desktopMaxWidth={560}
|
||||
>
|
||||
<SettingsTextAreaCard
|
||||
<FormTextInput
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
testID="host-page-append-system-prompt-input"
|
||||
accessibilityLabel={t("settings.host.orchestration.systemPrompt.accessibilityLabel")}
|
||||
value={draft}
|
||||
initialValue={draft}
|
||||
onChangeText={setDraft}
|
||||
placeholder={t("settings.host.orchestration.systemPrompt.placeholder")}
|
||||
/>
|
||||
|
||||
@@ -4,7 +4,7 @@ import { useMutation } from "@tanstack/react-query";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { AdaptiveModalSheet, type SheetHeader } from "@/components/adaptive-modal-sheet";
|
||||
import { SettingsTextAreaCard } from "@/components/settings-textarea";
|
||||
import { FormTextInput } from "@/components/ui/form-field";
|
||||
import { SettingsInfoTip, SettingsRow } from "@/components/settings";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Switch } from "@/components/ui/switch";
|
||||
@@ -144,10 +144,12 @@ function ResumePromptSheet({
|
||||
testID="host-page-restart-recovery-sheet"
|
||||
desktopMaxWidth={560}
|
||||
>
|
||||
<SettingsTextAreaCard
|
||||
<FormTextInput
|
||||
multiline
|
||||
numberOfLines={4}
|
||||
testID="host-page-restart-recovery-prompt-input"
|
||||
accessibilityLabel={t("settings.host.agents.resumeOnStartup.prompt")}
|
||||
value={draft}
|
||||
initialValue={draft}
|
||||
onChangeText={setDraft}
|
||||
placeholder={DEFAULT_RESUME_PROMPT}
|
||||
/>
|
||||
|
||||
@@ -6,7 +6,8 @@ import { TerminalProfileEditModal, type ProfileDraft } from "./terminal-profile-
|
||||
|
||||
const { theme } = vi.hoisted(() => ({
|
||||
theme: {
|
||||
spacing: { 2: 8, 3: 12, 4: 16, 6: 24 },
|
||||
spacing: { 0.5: 2, 1: 4, 2: 8, 3: 12, 4: 16, 6: 24 },
|
||||
fontFamily: { mono: "monospace" },
|
||||
fontSize: { sm: 13, base: 15, xs: 11 },
|
||||
fontWeight: { medium: 500 },
|
||||
borderRadius: { md: 6, lg: 8, xl: 12 },
|
||||
@@ -19,6 +20,8 @@ const { theme } = vi.hoisted(() => ({
|
||||
border: "#555",
|
||||
accent: "#0a84ff",
|
||||
borderAccent: "#555",
|
||||
borderFocus: "#777",
|
||||
interactionHighlight: "rgba(255, 255, 255, 0.08)",
|
||||
palette: { red: { 300: "#f87171" } },
|
||||
},
|
||||
},
|
||||
@@ -29,6 +32,7 @@ vi.mock("react-native-unistyles", () => ({
|
||||
create: (factory: unknown) => (typeof factory === "function" ? factory(theme) : factory),
|
||||
},
|
||||
useUnistyles: () => ({ theme }),
|
||||
withUnistyles: <T,>(component: T) => component,
|
||||
}));
|
||||
|
||||
vi.mock("@/constants/platform", () => ({
|
||||
@@ -77,7 +81,12 @@ vi.mock("@/components/adaptive-modal-sheet", async () => {
|
||||
children,
|
||||
);
|
||||
};
|
||||
const AdaptiveTextInput = ReactModule.forwardRef<HTMLInputElement, Record<string, unknown>>(
|
||||
return { AdaptiveModalSheet };
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/text-input", async () => {
|
||||
const ReactModule = await import("react");
|
||||
const EditingTextInput = ReactModule.forwardRef<HTMLInputElement, Record<string, unknown>>(
|
||||
(props, ref) => {
|
||||
const p = props as {
|
||||
initialValue?: string;
|
||||
@@ -108,7 +117,7 @@ vi.mock("@/components/adaptive-modal-sheet", async () => {
|
||||
});
|
||||
},
|
||||
);
|
||||
return { AdaptiveModalSheet, AdaptiveTextInput };
|
||||
return { EditingTextInput };
|
||||
});
|
||||
|
||||
vi.mock("@/components/ui/button", async () => {
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
import { useCallback, useEffect, useRef } from "react";
|
||||
import type { NativeSyntheticEvent, TextInputKeyPressEventData } from "react-native";
|
||||
import { StyleSheet, withUnistyles } from "react-native-unistyles";
|
||||
import { StyleSheet } from "react-native-unistyles";
|
||||
import { EditingTextInput, type EditingTextInputHandle } from "@/components/ui/text-input";
|
||||
|
||||
const ThemedTextInput = withUnistyles(EditingTextInput, (theme) => ({
|
||||
placeholderTextColor: theme.colors.foregroundMuted,
|
||||
}));
|
||||
|
||||
export interface InlineTitleFieldProps {
|
||||
initialValue: string;
|
||||
placeholder: string;
|
||||
@@ -78,7 +74,7 @@ export function InlineTitleField({
|
||||
);
|
||||
|
||||
return (
|
||||
<ThemedTextInput
|
||||
<EditingTextInput
|
||||
ref={inputRef}
|
||||
initialValue={initialValue}
|
||||
placeholder={placeholder}
|
||||
|
||||
@@ -16,6 +16,37 @@ export const NO_RAW_PRESSABLE_MESSAGE =
|
||||
"ComposerTrackRow; other rows use PressHighlight (@/components/ui/press-highlight); labelled " +
|
||||
"buttons use Button. See docs/design.md §2.";
|
||||
|
||||
const RAW_TEXT_INPUT_NAMES = new Set(["EditingTextInput", "SheetAwareTextInput"]);
|
||||
const RAW_TEXT_INPUT_SOURCE_RE = /(?:^|\/)components\/ui\/text-input(?:\/|$)/;
|
||||
|
||||
export const NO_RAW_TEXT_INPUT_MESSAGE =
|
||||
"A raw EditingTextInput has no form chrome, focus ring, or inner outline suppression. Use " +
|
||||
"FormTextInput (@/components/ui/form-field) for forms and textareas, or SearchField " +
|
||||
"(@/components/ui/search-field) for search inputs. See docs/forms.md and docs/design.md §2.";
|
||||
|
||||
const noRawTextInput = {
|
||||
create(context) {
|
||||
return {
|
||||
ImportDeclaration(node) {
|
||||
if (node.importKind === "type" || !RAW_TEXT_INPUT_SOURCE_RE.test(node.source.value)) {
|
||||
return;
|
||||
}
|
||||
for (const specifier of node.specifiers) {
|
||||
if (specifier.type === "ImportNamespaceSpecifier") {
|
||||
context.report({ node: specifier, message: NO_RAW_TEXT_INPUT_MESSAGE });
|
||||
} else if (
|
||||
specifier.type === "ImportSpecifier" &&
|
||||
specifier.importKind !== "type" &&
|
||||
RAW_TEXT_INPUT_NAMES.has(specifier.imported.name)
|
||||
) {
|
||||
context.report({ node: specifier, message: NO_RAW_TEXT_INPUT_MESSAGE });
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
const noRawPressable = {
|
||||
create(context) {
|
||||
return {
|
||||
@@ -158,6 +189,7 @@ export default {
|
||||
meta: { name: "paseo" },
|
||||
rules: {
|
||||
"no-raw-pressable": noRawPressable,
|
||||
"no-raw-text-input": noRawTextInput,
|
||||
"no-sync-io": noSyncIo,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -59,6 +59,71 @@ test("press primitives and pressable types are allowed", () => {
|
||||
assert.equal(result.failed, false, result.output);
|
||||
});
|
||||
|
||||
test("raw EditingTextInput value imports are reported", () => {
|
||||
const result = lint(
|
||||
'import { EditingTextInput } from "@/components/ui/text-input";\nexport { EditingTextInput };\n',
|
||||
"paseo/no-raw-text-input",
|
||||
);
|
||||
assert.equal(result.failed, true);
|
||||
assert.match(result.output, /no-raw-text-input/);
|
||||
assert.match(result.output, /FormTextInput/);
|
||||
});
|
||||
|
||||
test("aliased, namespace, and SheetAwareTextInput imports are reported", () => {
|
||||
const aliased = lint(
|
||||
'import { EditingTextInput as TextInput } from "@/components/ui/text-input";\nexport { TextInput };\n',
|
||||
"paseo/no-raw-text-input",
|
||||
);
|
||||
assert.equal(aliased.failed, true);
|
||||
assert.match(aliased.output, /no-raw-text-input/);
|
||||
|
||||
const namespace = lint(
|
||||
'import * as Inputs from "@/components/ui/text-input";\nexport { Inputs };\n',
|
||||
"paseo/no-raw-text-input",
|
||||
);
|
||||
assert.equal(namespace.failed, true);
|
||||
assert.match(namespace.output, /no-raw-text-input/);
|
||||
|
||||
const sheetAware = lint(
|
||||
'import { SheetAwareTextInput } from "@/components/ui/text-input/sheet-aware";\nexport { SheetAwareTextInput };\n',
|
||||
"paseo/no-raw-text-input",
|
||||
);
|
||||
assert.equal(sheetAware.failed, true);
|
||||
assert.match(sheetAware.output, /no-raw-text-input/);
|
||||
});
|
||||
|
||||
test("type-only EditingTextInputHandle imports and FormTextInput imports are allowed", () => {
|
||||
const result = lint(
|
||||
'import type { EditingTextInputHandle } from "@/components/ui/text-input";\n' +
|
||||
'import { type EditingTextInputProps } from "@/components/ui/text-input";\n' +
|
||||
'import { FormTextInput } from "@/components/ui/form-field";\n' +
|
||||
"export type Handle = EditingTextInputHandle;\nexport type Props = EditingTextInputProps;\nexport { FormTextInput };\n",
|
||||
"paseo/no-raw-text-input",
|
||||
);
|
||||
assert.equal(result.failed, false, result.output);
|
||||
});
|
||||
|
||||
test("repository config enforces no-raw-text-input outside components/ui and bespoke allowlist", () => {
|
||||
const config = readFileSync(path.join(repoRoot, ".oxlintrc.json"), "utf8").replace(
|
||||
'"./scripts/oxlint/paseo-plugin.mjs"',
|
||||
JSON.stringify(pluginPath),
|
||||
);
|
||||
const source =
|
||||
'import { EditingTextInput } from "@/components/ui/text-input";\nexport { EditingTextInput };\n';
|
||||
const rejected = lintWithConfig(source, config, "packages/app/src/screens/probe-form.tsx");
|
||||
assert.equal(rejected.failed, true, rejected.output);
|
||||
assert.match(rejected.output, /no-raw-text-input/);
|
||||
|
||||
for (const filename of [
|
||||
"packages/app/src/components/ui/probe-field.tsx",
|
||||
"packages/app/src/composer/input/input.tsx",
|
||||
"packages/app/src/screens/probe-form.test.tsx",
|
||||
]) {
|
||||
const allowed = lintWithConfig(source, config, filename);
|
||||
assert.equal(allowed.failed, false, allowed.output);
|
||||
}
|
||||
});
|
||||
|
||||
for (const source of [
|
||||
'import { readFileSync as read } from "node:fs"; export { read };',
|
||||
'import { execSync } from "child_process"; export { execSync };',
|
||||
|
||||
Reference in New Issue
Block a user