@solidrt/components 0.0.50 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +93 -85
- package/README.md +421 -311
- package/demos/README.md +24 -0
- package/demos/assets/icon.png +0 -0
- package/demos/assets/icon.svg +23 -0
- package/demos/package.json +9 -0
- package/demos/src/gallery.tsx +866 -0
- package/demos/tsconfig.json +15 -0
- package/docs/badge.md +10 -0
- package/docs/button.md +21 -0
- package/docs/card.md +11 -0
- package/docs/checkbox.md +9 -0
- package/docs/context-menu.md +17 -0
- package/docs/density.md +13 -0
- package/docs/divider.md +10 -0
- package/docs/field.md +11 -0
- package/docs/focus-nav.md +18 -0
- package/docs/icon.md +13 -0
- package/docs/image.md +21 -0
- package/docs/index.md +13 -0
- package/docs/item.md +25 -0
- package/docs/modal.md +15 -0
- package/docs/nav-shell.md +18 -0
- package/docs/policy.md +21 -0
- package/docs/portal.md +15 -0
- package/docs/pressable.md +17 -0
- package/docs/progress-bar.md +10 -0
- package/docs/qrcode.md +10 -0
- package/docs/radio.md +13 -0
- package/docs/rich-text-document.md +5 -0
- package/docs/rich-text-editor.md +24 -0
- package/docs/safe-area.md +12 -0
- package/docs/scroll-view.md +35 -0
- package/docs/segmented-control.md +13 -0
- package/docs/select.md +15 -0
- package/docs/slider.md +9 -0
- package/docs/spacing.md +7 -0
- package/docs/spinner.md +10 -0
- package/docs/split-view.md +14 -0
- package/docs/switch.md +13 -0
- package/docs/text-input.md +23 -0
- package/docs/text.md +15 -0
- package/docs/theme.md +68 -0
- package/docs/tooltip.md +11 -0
- package/docs/types.md +9 -0
- package/docs/typography.md +5 -0
- package/docs/view.md +14 -0
- package/docs/window.md +15 -0
- package/package.json +8 -4
- package/src/badge.tsx +30 -21
- package/src/button.tsx +50 -32
- package/src/card.tsx +22 -13
- package/src/checkbox.tsx +29 -11
- package/src/context-menu.tsx +14 -9
- package/src/density.tsx +39 -0
- package/src/divider.tsx +11 -4
- package/src/editor-field.tsx +368 -0
- package/src/field.tsx +47 -0
- package/src/icon.tsx +8 -4
- package/src/image.tsx +10 -3
- package/src/index.ts +19 -2
- package/src/item.tsx +121 -0
- package/src/nav-shell.tsx +7 -17
- package/src/policy.ts +9 -12
- package/src/press.ts +37 -8
- package/src/pressable.tsx +15 -3
- package/src/progress-bar.tsx +8 -5
- package/src/qrcode.tsx +7 -5
- package/src/radio.tsx +26 -16
- package/src/rich-text-document.ts +247 -0
- package/src/rich-text-editor.tsx +151 -0
- package/src/scroll-view.tsx +76 -7
- package/src/segmented-control.tsx +33 -19
- package/src/select.tsx +59 -30
- package/src/slider.tsx +32 -6
- package/src/spacing.ts +1 -1
- package/src/spinner.tsx +11 -6
- package/src/split-view.tsx +3 -4
- package/src/switch.tsx +10 -3
- package/src/text-input.tsx +54 -264
- package/src/text.tsx +22 -2
- package/src/theme.ts +220 -81
- package/src/tooltip.tsx +23 -9
- package/src/types.ts +119 -1
- package/src/view.tsx +11 -2
package/README.md
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
<!-- GENERATED FILE, do not edit: edit docs/*.md and the interfaces in src/, then run `bun scripts/build-components-docs.ts`. -->
|
|
2
|
+
|
|
1
3
|
# @solidrt/components
|
|
2
4
|
|
|
3
|
-
A collection of components for [SolidRT](https://github.com/wellawaretech/solidrt) apps.
|
|
5
|
+
A collection of components for [SolidRT](https://github.com/wellawaretech/solidrt) apps, built on the `@solidrt/core` primitives. Optional: an app can be built with core primitives alone, and a component is just a function returning core elements, so you can always drop down underneath.
|
|
4
6
|
|
|
5
7
|
> LLM agents: see [AGENTS.md](./AGENTS.md) for a dense, self-contained quickstart.
|
|
6
8
|
|
|
7
9
|
## Installation
|
|
8
10
|
|
|
9
11
|
```sh
|
|
10
|
-
bun add @solidrt/components
|
|
12
|
+
bun add @solidrt/components # peers: @solidrt/core, @solidjs/signals
|
|
11
13
|
```
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Per-component prose lives in `docs/`, one file per module; the props are the typed, commented interfaces in `src/` (this package ships its source, so your editor shows them on hover). The README is generated from both.
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
## Theming
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
Appearance (colors, spacing, border, font roles) comes from one shared, reactive theme backed by a Solid store: reads are tracked, so switching the theme at runtime recolors the live UI without remounting. Two presets ship, `darkTheme` and `lightTheme` (default dark); `setTheme(preset)` switches, `setTheme(partial)` merges an override one level deep per category. Custom themes are authored with `defineTheme`.
|
|
18
20
|
|
|
19
21
|
```jsx
|
|
20
22
|
import { setTheme, darkTheme, lightTheme } from "@solidrt/components"
|
|
@@ -24,35 +26,79 @@ setTheme(darkTheme) // switch to dark
|
|
|
24
26
|
setTheme({ color: { primary: "#ff2d55" } }) // override one token
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
|
|
29
|
+
### Authoring with defineTheme
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
`defineTheme(definition, scheme?)` resolves a definition into a theme. Any color may be a single value or a `[light, dark]` pair; the `scheme` argument picks the side. Pairs are opt-in per token, and a definition without any needs no scheme at all - modes are a per-theme choice, not a framework requirement (a game ships one look, not two). The built-in presets are one definition resolved twice, so they cannot drift apart.
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
```jsx
|
|
34
|
+
import { defineTheme, setTheme } from "@solidrt/components"
|
|
35
|
+
|
|
36
|
+
let def = {
|
|
37
|
+
color: {
|
|
38
|
+
background: ["#ffffff", "#101014"], // [light, dark]
|
|
39
|
+
primary: "#ff2d55", // same in both
|
|
40
|
+
/* ... every color token ... */
|
|
41
|
+
},
|
|
42
|
+
text: { base: 15, ratio: 1.25 },
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setTheme(defineTheme(def, "dark"))
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
The type scale derives from `text.base` (the body size, default 14) and `text.ratio` (default 1.26): caption sits one step under body, label is body at an emphasized weight, title and heading sit one and two steps above, rounded to whole pixels, with per-role `text.roles` overrides for sizes, line heights, and weights. De-emphasis is a color (`textMuted`), not a size: caption is for small glanceable text (badges, tab labels, timestamps) and stays in the full text color.
|
|
49
|
+
|
|
50
|
+
### Tokens
|
|
51
|
+
|
|
52
|
+
The color tokens are `background` (window fill), `surface` (control/card fill), `surfaceAlt` (subtle raised/track fill), `text`, `textMuted`, `border`, `primary`/`onPrimary`, `secondary`/`onSecondary` (lower-emphasis accent), `danger` (validation/destructive), `scrim` (modal dim), `ring` (the focus ring; defaults to `text` so it stays visible on primary fills), and the feedback pair `overlayHover`/`overlayPressed`: translucent tints components draw OVER a control's own fill, so one token pair gives hover/pressed feedback on every fill color, including caller-set ones. Non-color tokens are `spacing`, `radius`, `borderWidth` (`sm` for borders, `focus` for the ring), `size` (app-wide default extents: `navRail` 72, `navSidebar` 220, `splitViewList` 320, `menuMinWidth` 120, `slider` 200; each overridable per instance through its layout or prop), and `text` (the type scale: `caption`/`label`/`body`/`title`/`heading` roles, each `{ size, lineHeight, weight }`, plus `fontFamily` and `monoFamily` for code).
|
|
53
|
+
|
|
54
|
+
### Spacing
|
|
55
|
+
|
|
56
|
+
Spacing is one base unit: `spacing` in a theme definition is a number (default 4) and the steps are multiples of it (`sm` 1x, `md` 2x, `lg` 4x, `xl` 5x). Components read them through `space()`, which applies the density policy on top, so a theme sets the rhythm and density tightens it. Pass an object (`spacing: { sm, md, lg, xl }`, any subset) to pin individual steps.
|
|
57
|
+
|
|
58
|
+
### Radius
|
|
59
|
+
|
|
60
|
+
Corner radius is set once: `radius` in a theme definition is a single number, the control radius (default 8), and the scale derives from it: `md` is the base (Button, TextInput, RichTextEditor, Select, SegmentedControl, QrCode), `sm` half of it (Checkbox, Item, NavShell items, Select and ContextMenu popups, Tooltip), `lg` one and a half (Card), and `full` the pill (Badge). Set `radius: 0` for a square theme, `radius: 12` for a soft one; buttons and inputs always match. Shapes derived from a control's own height (Switch, Slider, ProgressBar, Radio) are not on the scale. Pass an object (`radius: { sm, md, lg, full }`, any subset) to pin individual steps instead.
|
|
61
|
+
|
|
62
|
+
```jsx
|
|
63
|
+
setTheme({ radius: 4 }) // sm 2, md 4, lg 6
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Per-component overrides
|
|
67
|
+
|
|
68
|
+
`theme.components` restyles a component everywhere without wrapping it: a `StyleProps` object per component name, merged between the component's themed defaults and each instance's `style` prop (instance style still wins).
|
|
32
69
|
|
|
33
|
-
|
|
70
|
+
```jsx
|
|
71
|
+
setTheme({ components: { button: { borderRadius: 999 } } }) // pill buttons app-wide
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Keys: `button`, `card`, `badge`, `switch`, `checkbox`, `radio`, `item`, `select`, `segmentedControl`, `textInput`, `richTextEditor`, `tooltip`, `divider`, `progressBar`, `spinner`.
|
|
75
|
+
|
|
76
|
+
### Icon slots
|
|
77
|
+
|
|
78
|
+
`theme.icons` holds semantic control glyphs as SVG document strings (the same currency as `Icon`): `chevronDown` (the Select trigger) and `check` (the Checkbox mark). Components draw their built-in vector paths by default; a theme that sets a slot swaps that glyph everywhere it appears, and the package still bundles no icon set.
|
|
34
79
|
|
|
35
80
|
```jsx
|
|
36
|
-
import
|
|
81
|
+
import ChevronDown from "lucide-static/icons/chevron-down.svg"
|
|
37
82
|
|
|
38
|
-
|
|
39
|
-
policy.density // control/spacing scale
|
|
83
|
+
setTheme({ icons: { chevronDown: ChevronDown } })
|
|
40
84
|
```
|
|
41
85
|
|
|
42
|
-
`
|
|
86
|
+
API: `theme`, `setTheme`, `defineTheme`, `darkTheme`, `lightTheme`, `Theme`, `ThemeDefinition`, `ThemeColor`, `ThemedComponent`, `TextStyle`, `TextVariant` - typed and commented in [src/theme.ts](./src/theme.ts).
|
|
43
87
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
| `focusRing` | `boolean` | Whether focused controls draw a visible focus indicator. |
|
|
50
|
-
| `textScale` | `number` | Multiplier on type-scale font sizes; defaults to the OS text-scale preference. |
|
|
51
|
-
| `textWeightDelta` | `number` | Weight compensation (in steps of 100) for light-on-dark text on low-DPI displays. |
|
|
52
|
-
| `navigation` | `"bottomTabs" \| "rail" \| "sidebar"` | Recommended nav layout, derived from window size class. |
|
|
53
|
-
| `layout` | `"singlePane" \| "twoPane"` | Recommended single vs. two-pane layout, derived from window size class. |
|
|
88
|
+
## Policies
|
|
89
|
+
|
|
90
|
+
Theme answers "how does it look"; policies answer "how does it behave". `policy` is a second reactive layer derived from the platform facts in `@solidrt/core` (`capabilities`, `env`), so components adapt to touch vs. desktop, window size, and display without every app wiring that logic itself. Reads are reactive like `theme`: a window resize or the first mouse move on a touch-capable device updates every consuming component live.
|
|
91
|
+
|
|
92
|
+
The fields:
|
|
54
93
|
|
|
55
|
-
|
|
94
|
+
- `interaction` (`"touch" | "desktop" | "hybrid"`) - which affordances a component shows (hover states vs. long-press). `Tooltip`, `Select`, and `ContextMenu` fork on it.
|
|
95
|
+
- `density` (`"comfortable" | "compact" | "dense"`) - control/hit-target/spacing scale; drives `densityScale()` (1 / 0.85 / 0.7). A `<Density>` region overrides it per subtree.
|
|
96
|
+
- `motion` (`"normal" | "reduced" | "none"`) - animation intensity.
|
|
97
|
+
- `focusRing` (`boolean`) - whether focused controls draw a visible focus indicator (true when a keyboard or gamepad/remote is present).
|
|
98
|
+
- `textScale` (`number`) - multiplier on type-scale font sizes; defaults to the OS text-scale preference.
|
|
99
|
+
- `textWeightDelta` (`number`) - weight compensation (steps of 100) for light-on-dark text on low-DPI displays.
|
|
100
|
+
- `navigation` (`"bottomTabs" | "rail" | "sidebar"`) - recommended nav layout, derived from the pane count: `sidebar` beside a two-pane layout, `bottomTabs` under a single pane (a side strip spends the width a narrow window is short of). `rail` is never derived; set it for a content-dense two-pane app. `NavShell` follows it.
|
|
101
|
+
- `layout` (`"singlePane" | "twoPane"`) - recommended pane count, derived from the window size class. `SplitView` follows it.
|
|
56
102
|
|
|
57
103
|
```jsx
|
|
58
104
|
setPolicy({ density: "compact" }) // pin a field, overriding the derived value
|
|
@@ -61,35 +107,43 @@ setPolicy({ density: undefined }) // hand it back to the resolver
|
|
|
61
107
|
|
|
62
108
|
`setPolicyResolver((caps) => Policies)` replaces the whole system-derivation function for full custom control; `defaultPolicyResolver` is exported to wrap or extend instead of replacing it outright.
|
|
63
109
|
|
|
64
|
-
`
|
|
110
|
+
API: `policy`, `setPolicy`, `setPolicyResolver`, `defaultPolicyResolver`, `Policies`, `PolicyResolver`, `InteractionPolicy`, `DensityPolicy`, `MotionPolicy`, `NavigationPolicy`, `LayoutPolicy` - typed and commented in [src/policy.ts](./src/policy.ts).
|
|
65
111
|
|
|
66
112
|
## Layout and style
|
|
67
113
|
|
|
68
|
-
Most components group their props into two objects:
|
|
114
|
+
Most components group their props into two objects, split by one rule: `layout` properties feed the layout engine (flexbox/grid, sizing, padding, margin, position - the core `LayoutProps` set) and changing them triggers a relayout; `style` properties are paint-only and never affect layout: `color`, `backgroundColor`, `borderColor`, `borderWidth`, `borderRadius`, `opacity`, and the transform (`x`, `y`, `scale`, `rotate`, `rotateX`/`rotateY` with `perspective`, `originX`/`originY`, `clipRadius`). Event handlers (`onPointerDown`, `onKeyDown`, ...) are top-level props, never inside `layout` or `style`.
|
|
115
|
+
|
|
116
|
+
`StyleProps` is that paint set. `TextLayoutProps` extends `LayoutProps` with the font fields (`fontFamily`, `fontSize`, `lineHeight`, `fontStyle`, `fontWeight`, `textAlign`, `maxLines`) because text shaping affects measurement; note `lineHeight` is a multiplier of `fontSize` (the theme uses 1.3-1.6), not a pixel value. `Option` (`{ value, label }`) is the shared shape of the single-choice controls (`Select`, `SegmentedControl`): shared shapes go through this module so components never import a sibling.
|
|
117
|
+
|
|
118
|
+
`TransitionProps` (`transition`, `onTransitionEnd`) is the third top-level group, in the component's own vocabulary rather than core's: a declaration names the view-level properties (`opacity`, `x`, `y`, `scale*`, `rotate*`, `origin*`, `perspective`, `clipRadius`) and the style ones (`backgroundColor`, `borderColor`, `borderWidth`, `borderRadius`), plus `all`, a shorthand string, and `stagger` - `<Button transition={{ backgroundColor: { duration: 300 }, opacity: "200ms ease-out" }}>`. Core's paint names (`color`, `radius`, `strokeWidth`) are rejected by the types: a component is a root view plus the rects it draws for `style`, and `splitTransition` hands each entry to the node that owns it (the background rect gets `backgroundColor`/`borderRadius`, the stroke rect `borderColor`/`borderWidth`/`borderRadius`, the root view the rest). `onTransitionEnd` reports the component name (`backgroundColor`, not `color`). `Text` adds `color` (its text node), `ScrollView` adds `scrollX`/`scrollY` (its viewport).
|
|
69
119
|
|
|
70
|
-
|
|
71
|
-
- `style` - paint-only properties that never affect layout: `color`, `backgroundColor`, `borderColor`, `borderWidth`, `borderRadius`, and the transform `x`, `y`, `rotate`, `scale`.
|
|
120
|
+
Controls whose paint is their own - `Switch` knob, `Slider` thumb, `Checkbox` mark, `Radio` dot, `ProgressBar` fill, `Spinner`, `Icon`, `QrCode`, and the chrome of `NavShell`, `ContextMenu`, `Field` - animate the view-level entries only for now; their internal parts are not reachable through `transition` yet (okf/backlog/component-transitions-internal-paint.md).
|
|
72
121
|
|
|
73
|
-
|
|
122
|
+
API: `StyleProps`, `TextLayoutProps`, `Option`, `TransitionProps`, `ComponentTransition`, `TransitionViewProp`, `TransitionStyleProp`, `TransitionScrollProp` - typed and commented in [src/types.ts](./src/types.ts).
|
|
74
123
|
|
|
75
|
-
|
|
124
|
+
## Typography helpers
|
|
76
125
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
126
|
+
`typeStyle(variant)` resolves a theme type-scale role (`caption`/`label`/`body`/`title`/`heading`) to font props ready to spread onto a `<text>` or `d-text`: `fontSize` carries `policy.textScale`, and `fontWeight` carries the low-DPI weight compensation. Reactive when called inside a tracked scope, like any theme/policy read. `Text` applies it for you; reach for the helpers when building custom text out of core primitives.
|
|
127
|
+
|
|
128
|
+
The compensation exists because the renderer rasterizes glyphs unhinted and composites in nonlinear sRGB, which thins light-on-dark text on low-DPI displays as glyphs shrink. `typeWeight(weight, size, onDark?)` adds `policy.textWeightDelta` (0 on high-DPI displays) plus one extra step below 16px; dark-on-light text passes through untouched. `lightOnDark(text, fill)` computes the polarity for a known pair of colors (Button uses it for its fills); omitted, the theme's own palette polarity is used.
|
|
129
|
+
|
|
130
|
+
API: `typeStyle`, `typeWeight`, `lightOnDark` - typed and commented in [src/typography.ts](./src/typography.ts).
|
|
131
|
+
|
|
132
|
+
## Spacing
|
|
133
|
+
|
|
134
|
+
`space(token)` is density-scaled spacing: a `theme.spacing` token (`sm`/`md`/`lg`/`xl`) multiplied by the density scale of the nearest `<Density>` region (falling back to the global policy) and rounded to whole pixels. Use it for gaps and paddings that should tighten under `compact`/`dense` density; read `theme.spacing` directly only for distances that must not move with density. Reactive when called inside a tracked scope.
|
|
135
|
+
|
|
136
|
+
```jsx
|
|
137
|
+
<View layout={{ padding: space("md"), gap: space("sm") }} />
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
API: `space` - typed and commented in [src/spacing.ts](./src/spacing.ts).
|
|
87
141
|
|
|
88
142
|
## Components
|
|
89
143
|
|
|
90
144
|
### Window
|
|
91
145
|
|
|
92
|
-
The root surface of an app.
|
|
146
|
+
The root surface of an app: renders a core `<window>`, so `render()` accepts it. Applies `layout` and `style.backgroundColor` only (a window cannot be transformed or bordered), plus `title` and `fullscreen`.
|
|
93
147
|
|
|
94
148
|
```jsx
|
|
95
149
|
import { Window } from "@solidrt/components"
|
|
@@ -103,19 +157,11 @@ function App() {
|
|
|
103
157
|
}
|
|
104
158
|
```
|
|
105
159
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
| Prop | Type | Default | Description |
|
|
109
|
-
| ------------ | ------------- | ------- | ------------------------------------ |
|
|
110
|
-
| `title` | `string` | - | Window title. |
|
|
111
|
-
| `fullscreen` | `boolean` | - | Open fullscreen. |
|
|
112
|
-
| `layout` | `LayoutProps` | - | Layout properties. |
|
|
113
|
-
| `style` | `StyleProps` | - | Only `backgroundColor` is applied. |
|
|
114
|
-
| `children` | `any` | - | Content. |
|
|
160
|
+
API: `Window`, `WindowProps` - typed and commented in [src/window.tsx](./src/window.tsx).
|
|
115
161
|
|
|
116
162
|
### View
|
|
117
163
|
|
|
118
|
-
A general-purpose box. Spreads `layout` onto the underlying view, applies the transform from `style`, and draws a background and/or border when those style props are set.
|
|
164
|
+
A general-purpose box. Spreads `layout` onto the underlying view, applies the transform from `style`, and draws a background and/or border when those style props are set. Takes all pointer event props.
|
|
119
165
|
|
|
120
166
|
```jsx
|
|
121
167
|
import { View } from "@solidrt/components"
|
|
@@ -128,92 +174,68 @@ import { View } from "@solidrt/components"
|
|
|
128
174
|
</View>
|
|
129
175
|
```
|
|
130
176
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
Accepts all pointer event props, plus:
|
|
134
|
-
|
|
135
|
-
| Prop | Type | Description |
|
|
136
|
-
| ---------- | ----------------------------- | --------------------- |
|
|
137
|
-
| `layout` | `LayoutProps` | Layout properties. |
|
|
138
|
-
| `style` | `StyleProps` | Paint properties. |
|
|
139
|
-
| `ref` | `(node: { id: number }) => void` | Node reference. |
|
|
140
|
-
| `children` | `any` | Content. |
|
|
177
|
+
API: `View`, `ViewProps` - typed and commented in [src/view.tsx](./src/view.tsx).
|
|
141
178
|
|
|
142
179
|
### Text
|
|
143
180
|
|
|
144
|
-
|
|
181
|
+
Themed text in a layout box. `variant` picks a typography role from the theme's type scale (`caption`/`label`/`body`/`title`/`heading`, default `body`); `color` picks a semantic theme color (`text`, `textMuted`, `primary`, `onPrimary`, `danger`, default `text`), with `muted` as sugar for `color="textMuted"`. Font fields go in `layout` (they affect measurement) and individually override the role; `style.color` still wins over `color`.
|
|
182
|
+
|
|
183
|
+
Font sizes carry `policy.textScale` (the OS text-size preference) and weights carry the low-DPI light-on-dark compensation; use the core `<text>` primitive for text that must not scale.
|
|
145
184
|
|
|
146
185
|
```jsx
|
|
147
186
|
import { Text } from "@solidrt/components"
|
|
148
187
|
|
|
149
|
-
<Text
|
|
150
|
-
|
|
151
|
-
</Text>
|
|
188
|
+
<Text variant="title">Section</Text>
|
|
189
|
+
<Text muted layout={{ maxLines: 2 }}>Supporting copy that may wrap.</Text>
|
|
190
|
+
<Text layout={{ fontSize: 18 }} style={{ color: "#fff" }}>Custom</Text>
|
|
152
191
|
```
|
|
153
192
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
**Props**
|
|
193
|
+
Note that `lineHeight` is a multiplier of `fontSize` (the theme uses 1.3-1.6), not a pixel value.
|
|
157
194
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
| Prop | Type | Description |
|
|
161
|
-
| ---------- | ----------------------------- | --------------------------------- |
|
|
162
|
-
| `layout` | `TextLayoutProps` | Layout properties plus font fields. |
|
|
163
|
-
| `style` | `StyleProps` | `color` and transform. |
|
|
164
|
-
| `ref` | `(node: { id: number }) => void` | Node reference. |
|
|
165
|
-
| `children` | `any` | Text content. |
|
|
195
|
+
API: `Text`, `TextProps`, `TextColor` - typed and commented in [src/text.tsx](./src/text.tsx).
|
|
166
196
|
|
|
167
197
|
### Image
|
|
168
198
|
|
|
169
|
-
Loads and displays an image from a URL or raw bytes. URL loads are shared
|
|
170
|
-
runtime-wide: mounts of the same URL reuse one fetch and one texture, and the
|
|
171
|
-
bytes are cached on disk (fetched with `cache: "force-cache"` - no freshness
|
|
172
|
-
check, so use versioned URLs for content that changes). The runtime keeps
|
|
173
|
-
concurrent asset fetches polite with a per-host limit; a failed load rejects
|
|
174
|
-
the mounts sharing it and a later remount retries.
|
|
199
|
+
Loads and displays an image from a URL or raw bytes (`src: string | Uint8Array`). URL loads are shared runtime-wide: mounts of the same URL reuse one fetch and one texture, and the bytes are cached on disk (fetched with `cache: "force-cache"` - no freshness check, so use versioned URLs for content that changes). Concurrent asset fetches are kept polite with a per-host limit; a failed load rejects the mounts sharing it and a later remount retries.
|
|
175
200
|
|
|
176
201
|
```jsx
|
|
177
202
|
import { Image } from "@solidrt/components"
|
|
178
203
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
204
|
+
<Image
|
|
205
|
+
src="https://example.com/avatar.png"
|
|
206
|
+
fallback={PLACEHOLDER_PNG}
|
|
207
|
+
layout={{ width: 64, height: 64 }}
|
|
208
|
+
/>
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
With `fit` the image fills whatever box `layout` gives the component - numbers, `pct()`, or flex - and the fit decides how the pixels map into it (CSS object-fit, centered; `"cover"` is the ported-web-hero-image answer). Without `fit`, only numeric layout sizes reach the image; anything else draws at intrinsic size.
|
|
212
|
+
|
|
213
|
+
```jsx
|
|
214
|
+
<Image src={hero} fit="cover" layout={{ width: pct(100), height: 240 }} />
|
|
188
215
|
```
|
|
189
216
|
|
|
190
|
-
|
|
217
|
+
A failing `src` is contained by the component: the `fallback` shows, or the `backgroundColor` placeholder stays; the error does not propagate to an outer `<Errored>` boundary. `onLoad` fires each time a source finishes loading, `onError` when `src` fails.
|
|
191
218
|
|
|
192
|
-
|
|
219
|
+
API: `Image`, `ImageProps` - typed and commented in [src/image.tsx](./src/image.tsx).
|
|
193
220
|
|
|
194
|
-
|
|
195
|
-
| ---------- | ------------------------ | ------------------------------------------------------------------------------------ |
|
|
196
|
-
| `src` | `string \| Uint8Array` | URL to fetch, or raw image bytes to decode |
|
|
197
|
-
| `fit` | `"fill" \| "cover" \| "contain" \| "none" \| "scale-down"` | How the image maps into the box (CSS object-fit, centered) |
|
|
198
|
-
| `fallback` | `string \| Uint8Array` | Source shown when `src` fails; if it also fails, the `backgroundColor` placeholder stays |
|
|
199
|
-
| `onLoad` | `() => void` | Called each time a source finishes loading |
|
|
200
|
-
| `onError` | `(err: unknown) => void` | Called when `src` fails to load or decode |
|
|
221
|
+
### SafeArea
|
|
201
222
|
|
|
202
|
-
|
|
203
|
-
`pct()`, or flex - and the fit decides how the pixels map into it (`"cover"` is
|
|
204
|
-
the ported-web-hero-image answer). Without `fit`, only *numeric* layout sizes
|
|
205
|
-
reach the image; anything else draws at intrinsic size.
|
|
223
|
+
Wraps its children in a view padded clear of system UI intrusions (status bars, home indicators, notches). Top and bottom insets are applied by default; pass `false` to opt out of an edge, or a number to apply the inset with that minimum padding.
|
|
206
224
|
|
|
207
225
|
```jsx
|
|
208
|
-
|
|
226
|
+
import { SafeArea } from "@solidrt/components"
|
|
227
|
+
|
|
228
|
+
<SafeArea top bottom>...</SafeArea> // the default edges
|
|
229
|
+
<SafeArea bottom={false}>...</SafeArea> // top only
|
|
230
|
+
<SafeArea top={16} bottom={16}>...</SafeArea> // insets with a 16px minimum
|
|
231
|
+
<SafeArea top bottom left right>...</SafeArea> // all four edges
|
|
209
232
|
```
|
|
210
233
|
|
|
211
|
-
|
|
212
|
-
shows); it does not propagate to an outer `<Errored>` boundary.
|
|
234
|
+
API: `SafeArea` - typed and commented in [src/safe-area.tsx](./src/safe-area.tsx).
|
|
213
235
|
|
|
214
236
|
### TextInput
|
|
215
237
|
|
|
216
|
-
|
|
238
|
+
Text input, single-line by default; `multiline` wraps at the field's width and edits across lines (Enter inserts a newline, Up/Down move by line; grows with content up to `maxRows` unless `layout.height` fixes the box, and scrolls to the caret). Controlled via `value`/`onInput`, or uncontrolled via `defaultValue`; `onSubmit` fires on Enter (single-line only). Also `placeholder`, `maxLength`, `autoFocus`, `disabled`, `onFocus`/`onBlur`, and `hints` for IME behavior (keyboard type, capitalization, autocorrect - identifier-like fields want `{ capitalize: "none", autocorrect: false }`).
|
|
217
239
|
|
|
218
240
|
```jsx
|
|
219
241
|
import { TextInput } from "@solidrt/components"
|
|
@@ -233,95 +255,86 @@ function NameField() {
|
|
|
233
255
|
}
|
|
234
256
|
```
|
|
235
257
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
| Prop | Type | Default | Description |
|
|
239
|
-
| -------------- | ------------------------- | ------- | ------------------------------------------------------------ |
|
|
240
|
-
| `value` | `string` | - | Controlled value. If omitted, the component is uncontrolled. |
|
|
241
|
-
| `defaultValue` | `string` | `""` | Initial value for uncontrolled use. |
|
|
242
|
-
| `onInput` | `(value: string) => void` | - | Fires on every change. |
|
|
243
|
-
| `onSubmit` | `(value: string) => void` | - | Fires on Enter. |
|
|
244
|
-
| `onFocus` | `() => void` | - | Fires when the field gains focus. |
|
|
245
|
-
| `onBlur` | `() => void` | - | Fires when the field loses focus. |
|
|
246
|
-
| `placeholder` | `string` | - | Shown when value is empty and the field is not focused. |
|
|
247
|
-
| `maxLength` | `number` | - | Truncates input to this length. |
|
|
248
|
-
| `disabled` | `boolean` | `false` | Ignores pointer and key events when true. |
|
|
249
|
-
| `autoFocus` | `boolean` | `false` | Focuses on mount (the on-screen keyboard waits for a tap). |
|
|
250
|
-
| `hints` | `TextInputHints` | - | IME behavior: keyboard type, capitalization, autocorrect. |
|
|
251
|
-
| `layout` | `LayoutProps` | - | Layout properties (e.g. `width`). |
|
|
252
|
-
| `style` | `StyleProps` | - | Overrides theme colors, border, and radius. |
|
|
258
|
+
`style` overrides the themed colors, border, and radius. `autoFocus` focuses on mount (the on-screen keyboard still waits for a tap).
|
|
253
259
|
|
|
254
|
-
|
|
260
|
+
API: `TextInput`, `TextInputProps` - typed and commented in [src/text-input.tsx](./src/text-input.tsx).
|
|
255
261
|
|
|
256
|
-
|
|
262
|
+
### RichTextEditor
|
|
263
|
+
|
|
264
|
+
Edits a rich text `Document` (styled runs, paragraph attributes) in the same field as `TextInput`: always multiline, same caret, keys, wrapping, and scrolling. Controlled via `value`/`onInput`, or uncontrolled via `defaultValue` (start from `plainDocument("")`). Formatting is driven through `editorRef`, which hands you the document buffer - the component ships no toolbar; the app renders its own controls.
|
|
257
265
|
|
|
258
266
|
```jsx
|
|
259
|
-
import {
|
|
267
|
+
import { RichTextEditor, plainDocument } from "@solidrt/components"
|
|
260
268
|
|
|
261
|
-
function
|
|
269
|
+
function Notes() {
|
|
270
|
+
let editor
|
|
262
271
|
return (
|
|
263
|
-
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
272
|
+
<>
|
|
273
|
+
<Button onPress={() => editor.format({ bold: editor.attributes().bold ? null : true })}>B</Button>
|
|
274
|
+
<RichTextEditor
|
|
275
|
+
defaultValue={plainDocument("Start typing...")}
|
|
276
|
+
editorRef={(e) => (editor = e)}
|
|
277
|
+
layout={{ width: 320 }}
|
|
278
|
+
maxRows={10}
|
|
279
|
+
/>
|
|
280
|
+
</>
|
|
268
281
|
)
|
|
269
282
|
}
|
|
270
283
|
```
|
|
271
284
|
|
|
272
|
-
|
|
285
|
+
Drawn attributes - inline: `bold`, `italic`, `underline`, `code` (mono), `color` (a color string), `link` (a URL string: primary color, underlined); block: `heading: 1 | 2 | 3`. Other attributes are carried in the document and ignored by the drawing; font-affecting ones feed the text geometry too, so caret and wrap follow the drawn glyphs. Inline atoms (U+FFFC) render as their placeholder character for now.
|
|
273
286
|
|
|
274
|
-
|
|
275
|
-
// top only
|
|
276
|
-
<SafeArea bottom={false}>
|
|
287
|
+
API: `RichTextEditor`, `RichTextEditorProps` - typed and commented in [src/rich-text-editor.tsx](./src/rich-text-editor.tsx).
|
|
277
288
|
|
|
278
|
-
|
|
279
|
-
<SafeArea top={16} bottom={16}>
|
|
289
|
+
### Document model
|
|
280
290
|
|
|
281
|
-
|
|
282
|
-
<SafeArea top bottom left right>
|
|
283
|
-
```
|
|
291
|
+
The value model behind `RichTextEditor`: a `Document` is `{ text, runs, blocks }` - plain text plus attributed runs (inline formatting) and per-paragraph blocks. `plainDocument(text)` builds one from a string; `createDocumentBuffer(doc)` wraps one in the editing API (`format`, `formatBlock`, `insertAtom`, `attributes`, selection and edits) that `editorRef` hands out. `ATOM` is the inline-atom placeholder character (U+FFFC) for embedded objects.
|
|
284
292
|
|
|
285
|
-
|
|
293
|
+
The shapes (`Document`, `DocumentRun`, `Attributes`, `AttributePatch`, `DocumentBuffer`) are exported so an app can build, inspect, persist, and transform documents outside the editor.
|
|
286
294
|
|
|
287
|
-
|
|
288
|
-
| ---------- | ------------------- | ------- | ------------------------------------------------------ |
|
|
289
|
-
| `top` | `boolean \| number` | `true` | Apply top inset. A number sets the minimum padding. |
|
|
290
|
-
| `bottom` | `boolean \| number` | `true` | Apply bottom inset. A number sets the minimum padding. |
|
|
291
|
-
| `left` | `boolean \| number` | `false` | Apply left inset. A number sets the minimum padding. |
|
|
292
|
-
| `right` | `boolean \| number` | `false` | Apply right inset. A number sets the minimum padding. |
|
|
293
|
-
| `children` | `any` | - | Content to render inside the safe area. |
|
|
295
|
+
API: `createDocumentBuffer`, `plainDocument`, `ATOM`, `Document`, `DocumentRun`, `DocumentBuffer`, `DocumentBufferOptions`, `Attributes`, `AttributePatch` - typed and commented in [src/rich-text-document.ts](./src/rich-text-document.ts).
|
|
294
296
|
|
|
295
297
|
### ScrollView
|
|
296
298
|
|
|
297
|
-
A scrollable region
|
|
299
|
+
A scrollable region; vertical by default, `horizontal` to flip. Both the wheel and dragging scroll the content: the drag activates after a small movement threshold along the scroll axis, also when it starts on a pressable (the press is cancelled and its feedback retracts), and keeps scrolling when the pointer leaves the box. Scrolling glides: the offset springs to each new target (250 ms, critically damped), so a wheel notch never jumps and a burst of notches reads as one motion; a dragging finger is tracked exactly, without the spring. No momentum/fling yet.
|
|
298
300
|
|
|
299
301
|
```jsx
|
|
300
302
|
import { ScrollView, Text } from "@solidrt/components"
|
|
301
303
|
import { For } from "@solidrt/core"
|
|
302
304
|
|
|
303
305
|
<ScrollView layout={{ height: 300 }} style={{ backgroundColor: "#111", borderRadius: 8 }}>
|
|
304
|
-
<For each={items()}>{(item) => <Text
|
|
306
|
+
<For each={items()}>{(item) => <Text>{item}</Text>}</For>
|
|
305
307
|
</ScrollView>
|
|
306
308
|
```
|
|
307
309
|
|
|
308
|
-
|
|
310
|
+
`scrollRef` hands out the scroll handle from `createScroll`: `offset()` and `range()` (the largest reachable offset, refreshed each layout) are reactive; `scrollTo({ x, y, behavior })` and `scrollBy({ x, y, behavior })` clamp to the range, an omitted axis stays put, and `behavior: "instant"` writes without the spring (the web's word; `"auto"` and `"smooth"` are the default motion). Scroll policies are written against it in the app. A transcript that opens at its newest message and then follows growth, without yanking a reader who has scrolled back:
|
|
311
|
+
|
|
312
|
+
```tsx
|
|
313
|
+
let [scroll, setScroll] = createSignal<Scroll>()
|
|
314
|
+
createEffect(
|
|
315
|
+
() => scroll()?.range(),
|
|
316
|
+
(r, prev) =>
|
|
317
|
+
untrack(() => {
|
|
318
|
+
let s = scroll()
|
|
319
|
+
if (!s || !r) return
|
|
320
|
+
if (!prev || prev.y === 0) s.scrollTo({ y: Infinity, behavior: "instant" })
|
|
321
|
+
else if (s.offset().y >= prev.y - 1) s.scrollTo({ y: Infinity })
|
|
322
|
+
}),
|
|
323
|
+
)
|
|
324
|
+
<ScrollView scrollRef={setScroll}>...</ScrollView>
|
|
325
|
+
```
|
|
309
326
|
|
|
310
|
-
|
|
327
|
+
The range changes whenever the content or the viewport changes size. The first fill (nothing was scrollable before it, whether it mounted with the view or arrived a second later) lands instantly, as a chat opens at its end; after that the view follows the end only if it was at the previous end, and the spring makes that follow a glide. The handle arrives once the component has settled, after an effect's first compute, so hold it in a signal (a setter can be passed as the ref) rather than a plain variable, which the effect would find unset and never track. The offset is read untracked: the policy reacts to the range, not to every scroll.
|
|
311
328
|
|
|
312
|
-
|
|
313
|
-
| ------------ | -------------------------------- | -------------------------------------------- |
|
|
314
|
-
| `horizontal` | `boolean` | Scroll the horizontal axis instead of vertical. |
|
|
315
|
-
| `layout` | `LayoutProps` | Layout of the outer box (e.g. `height`). |
|
|
316
|
-
| `style` | `StyleProps` | Background, border, and transform. |
|
|
317
|
-
| `ref` | `(node: { id: number }) => void` | Reference to the outer box. |
|
|
318
|
-
| `children` | `any` | Scrollable content. |
|
|
329
|
+
A `scrollX`/`scrollY` entry in `transition` replaces the default spring: `transition={{ scrollY: { duration: 400, bounce: 0.2 } }}` (keep it a spring rather than a tween, because the wheel retargets mid-flight). The other entries animate the box itself and its background/border as on any component.
|
|
319
330
|
|
|
320
331
|
The underlying geometry primitive `createScroll` is available from `@solidrt/core` for building custom scrollers.
|
|
321
332
|
|
|
333
|
+
API: `ScrollView`, `ScrollViewProps` - typed and commented in [src/scroll-view.tsx](./src/scroll-view.tsx).
|
|
334
|
+
|
|
322
335
|
### Pressable
|
|
323
336
|
|
|
324
|
-
A pressable box
|
|
337
|
+
A pressable box: `onPress` fires on a primary-button press released over the box; a drag out of the box (or a non-primary button) does not fire it, and a drag back in restores the pressed state. `children` and `style` may each be a function of the live `{ pressed, hovered, pending }` state, so the box restyles on press/hover without extra signals - read the state inside the prop or child expression, never eagerly into a local.
|
|
325
338
|
|
|
326
339
|
```jsx
|
|
327
340
|
import { Pressable, Text } from "@solidrt/components"
|
|
@@ -331,49 +344,41 @@ import { Pressable, Text } from "@solidrt/components"
|
|
|
331
344
|
layout={{ padding: 12 }}
|
|
332
345
|
style={(s) => ({ backgroundColor: s.pressed ? "#333" : "#222", borderRadius: 8 })}
|
|
333
346
|
>
|
|
334
|
-
<Text
|
|
347
|
+
<Text>Tap me</Text>
|
|
335
348
|
</Pressable>
|
|
336
349
|
```
|
|
337
350
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
Accepts all pointer event props, plus:
|
|
351
|
+
`disabled` takes no pointer events. When pressables nest, the innermost one wins the press. An `onPress` returning a promise sets `pending` until it settles; presses meanwhile are ignored, so async actions cannot double-fire.
|
|
341
352
|
|
|
342
|
-
|
|
343
|
-
| ---------- | --------------------------------------------------- | -------------------------------------------- |
|
|
344
|
-
| `onPress` | `() => void` | Fires on a completed press. |
|
|
345
|
-
| `disabled` | `boolean` | Takes no pointer events when true. |
|
|
346
|
-
| `layout` | `LayoutProps` | Layout properties. |
|
|
347
|
-
| `style` | `StyleProps \| (state) => StyleProps` | Paint properties, or a function of state. |
|
|
348
|
-
| `children` | `any \| (state) => any` | Content, or a function of state. |
|
|
349
|
-
| `ref` | `(node: { id: number }) => void` | Node reference. |
|
|
353
|
+
API: `Pressable`, `PressableProps`, `PressState` - typed and commented in [src/pressable.tsx](./src/pressable.tsx).
|
|
350
354
|
|
|
351
355
|
### Button
|
|
352
356
|
|
|
353
|
-
|
|
357
|
+
A themed press target over `Pressable`: a padded, centered box with a label. `variant` picks the visual role - `primary` (accent fill, the default), `secondary`, `ghost` (no fill until hover), `danger` (destructive) - with fill, hover tint, and label color from the matching theme tokens; no variant draws a border. `size` (`sm`/`md`/`lg`) pins a minimum width so a row of buttons lines up (a longer label still expands past it); omitted, the button sizes to its content. A string or number child renders as the themed label; any other child renders as-is (an icon, a row, ...).
|
|
354
358
|
|
|
355
359
|
```jsx
|
|
356
360
|
import { Button } from "@solidrt/components"
|
|
357
361
|
|
|
358
|
-
<Button onPress={save}
|
|
362
|
+
<Button onPress={save}>Save</Button>
|
|
363
|
+
<Button variant="ghost" onPress={cancel}>Cancel</Button>
|
|
364
|
+
<Button variant="danger" size="md" onPress={remove}>Delete</Button>
|
|
359
365
|
```
|
|
360
366
|
|
|
361
|
-
|
|
367
|
+
Press feedback is a slight scale; hover feedback is the theme's `overlayHover` tint drawn over the fill (non-touch interaction policies only), so it composes with any background, including a caller-set `style.backgroundColor`. `disabled` mutes the colors and takes no pointer events.
|
|
368
|
+
|
|
369
|
+
An `onPress` returning a promise makes the button an async action: while it is unsettled a centered spinner replaces the label (geometry unchanged, so nothing shifts) and further presses are ignored - a save or submit cannot double-fire.
|
|
362
370
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
| `disabled` | `boolean` | Mutes colors and ignores presses. |
|
|
367
|
-
| `focusable` | `boolean` | Focus-navigation candidacy; defaults to `true`. |
|
|
368
|
-
| `layout` | `LayoutProps` | Overrides padding/sizing. |
|
|
369
|
-
| `style` | `StyleProps` | Overrides background, radius, etc. |
|
|
370
|
-
| `children` | `any` | Label text, or custom content. |
|
|
371
|
+
```jsx
|
|
372
|
+
<Button onPress={async () => { await save() }}>Save</Button>
|
|
373
|
+
```
|
|
371
374
|
|
|
372
|
-
A focused Button (see `createFocusNav`)
|
|
375
|
+
A focused Button (see `createFocusNav`) draws a ring in the theme `ring` color under the `focusRing` policy (text-colored by default so it stays visible on primary-filled buttons) and activates on Enter, Space, or a remote's center key. `focusable` (default true) opts out of focus-navigation candidacy; disabled buttons are never candidates.
|
|
376
|
+
|
|
377
|
+
API: `Button`, `ButtonProps`, `ButtonVariant` - typed and commented in [src/button.tsx](./src/button.tsx).
|
|
373
378
|
|
|
374
379
|
### createFocusNav
|
|
375
380
|
|
|
376
|
-
Focus navigation for pointer-free control (TV remote, keyboard, gamepad), moving focus across the elements declaring `focusable`. Two movement types over the same candidates: spatial (arrow keys, dpad) picks the nearest candidate in the pressed direction by on-screen boxes, and sequential (Tab / Shift+Tab) walks visual reading order - rows top to bottom, left to right - wrapping at the ends. Enter / remote center / gamepad south activates the focused control. Nothing is focused until the first navigation press; pointer input works unchanged throughout.
|
|
381
|
+
Focus navigation for pointer-free control (TV remote, keyboard, gamepad), moving real focus across the elements declaring `focusable`. Two movement types over the same candidates: spatial (arrow keys, dpad) picks the nearest candidate in the pressed direction by on-screen boxes, and sequential (Tab / Shift+Tab) walks visual reading order - rows top to bottom, left to right - wrapping at the ends. Enter / remote center / gamepad south activates the focused control. Nothing is focused until the first navigation press; pointer input works unchanged throughout. Every interactive control (Button, Item, TextInput, RichTextEditor, Checkbox, Radio, Switch, Select and its options, SegmentedControl segments, Slider) is a candidate unless disabled, and draws the theme's `ring` color at `borderWidth.focus` while focused under the `focusRing` policy; the Slider steps its value with the arrow keys.
|
|
377
382
|
|
|
378
383
|
```jsx
|
|
379
384
|
import { createFocusNav } from "@solidrt/components"
|
|
@@ -384,11 +389,17 @@ function App() {
|
|
|
384
389
|
}
|
|
385
390
|
```
|
|
386
391
|
|
|
387
|
-
Attaching `nav.onKeyDown` on the window is what keeps it cooperative: key events bubble from the focused node, so a focused TextInput keeps its arrow keys and navigation only sees what nothing else consumed. Gamepad dpad/south are wired automatically.
|
|
392
|
+
Attaching `nav.onKeyDown` on the window is what keeps it cooperative: key events bubble from the focused node, so a focused TextInput keeps its arrow keys and navigation only sees what nothing else consumed. Gamepad dpad/south are wired automatically.
|
|
393
|
+
|
|
394
|
+
When the focused control disappears (an action replacing it, a screen change), focus lands on the nearest candidate to where it sat as soon as the successor is laid out - the ring follows a Disconnect button into the Connect button that replaces it. A deliberate blur (tapping outside, dismissing the keyboard) stays blurred; the next press resumes at the nearest candidate.
|
|
395
|
+
|
|
396
|
+
An open `Modal` traps navigation inside itself with no extra wiring (topmost wins when stacked); pass `scope: () => nodeOrNull` to trap into some other subtree instead. `move`/`tab`/`activate` are exposed for custom triggers.
|
|
397
|
+
|
|
398
|
+
API: `createFocusNav`, `FocusNavOptions` - typed and commented in [src/focus-nav.ts](./src/focus-nav.ts).
|
|
388
399
|
|
|
389
400
|
### Switch
|
|
390
401
|
|
|
391
|
-
An on/off toggle
|
|
402
|
+
An on/off toggle: the track fills with `primary` when on and `surfaceAlt` when off; the thumb slides across. Controlled via `value`/`onChange`, or uncontrolled via `defaultValue`. Built on `Pressable`, so `disabled` takes no pointer events. `style` overrides the track colors and radius.
|
|
392
403
|
|
|
393
404
|
```jsx
|
|
394
405
|
import { Switch } from "@solidrt/components"
|
|
@@ -400,20 +411,11 @@ function NotifyToggle() {
|
|
|
400
411
|
}
|
|
401
412
|
```
|
|
402
413
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
| Prop | Type | Default | Description |
|
|
406
|
-
| -------------- | ---------------------------- | ------- | ----------------------------------------------- |
|
|
407
|
-
| `value` | `boolean` | - | Controlled state. Omit for uncontrolled. |
|
|
408
|
-
| `defaultValue` | `boolean` | `false` | Initial value for uncontrolled use. |
|
|
409
|
-
| `onChange` | `(value: boolean) => void` | - | Fires with the new value on toggle. |
|
|
410
|
-
| `disabled` | `boolean` | `false` | Takes no pointer events when true. |
|
|
411
|
-
| `layout` | `LayoutProps` | - | Overrides sizing/positioning of the track. |
|
|
412
|
-
| `style` | `StyleProps` | - | Overrides track colors and radius. |
|
|
414
|
+
API: `Switch`, `SwitchProps` - typed and commented in [src/switch.tsx](./src/switch.tsx).
|
|
413
415
|
|
|
414
416
|
### Checkbox
|
|
415
417
|
|
|
416
|
-
A checkbox
|
|
418
|
+
A checkbox: filled with `primary` and a drawn checkmark when checked, an empty bordered box otherwise. Controlled via `checked`/`onChange`, or uncontrolled via `defaultChecked`. The mark is the `theme.icons.check` slot when a theme sets one. `style` overrides the box colors, border, and radius.
|
|
417
419
|
|
|
418
420
|
```jsx
|
|
419
421
|
import { Checkbox } from "@solidrt/components"
|
|
@@ -421,20 +423,11 @@ import { Checkbox } from "@solidrt/components"
|
|
|
421
423
|
<Checkbox checked={agree()} onChange={setAgree} />
|
|
422
424
|
```
|
|
423
425
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
| Prop | Type | Default | Description |
|
|
427
|
-
| ---------------- | --------------------------- | ------- | ------------------------------------------ |
|
|
428
|
-
| `checked` | `boolean` | - | Controlled state. Omit for uncontrolled. |
|
|
429
|
-
| `defaultChecked` | `boolean` | `false` | Initial value for uncontrolled use. |
|
|
430
|
-
| `onChange` | `(checked: boolean) => void`| - | Fires with the new state on toggle. |
|
|
431
|
-
| `disabled` | `boolean` | `false` | Takes no pointer events when true. |
|
|
432
|
-
| `layout` | `LayoutProps` | - | Overrides sizing. |
|
|
433
|
-
| `style` | `StyleProps` | - | Overrides box colors, border, and radius. |
|
|
426
|
+
API: `Checkbox`, `CheckboxProps` - typed and commented in [src/checkbox.tsx](./src/checkbox.tsx).
|
|
434
427
|
|
|
435
428
|
### RadioGroup / Radio
|
|
436
429
|
|
|
437
|
-
A single-selection
|
|
430
|
+
A single-selection pair: `RadioGroup` owns the selected value (controlled via `value`/`onChange`, or uncontrolled via `defaultValue`) and shares it with its `Radio` children; each `Radio` is a ring with an inner dot when selected. A string/number child of `Radio` renders as a themed label beside the ring; anything else as-is. `disabled` on the group disables every option, on a `Radio` just that one.
|
|
438
431
|
|
|
439
432
|
```jsx
|
|
440
433
|
import { RadioGroup, Radio } from "@solidrt/components"
|
|
@@ -446,30 +439,11 @@ import { RadioGroup, Radio } from "@solidrt/components"
|
|
|
446
439
|
</RadioGroup>
|
|
447
440
|
```
|
|
448
441
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
| Prop | Type | Default | Description |
|
|
452
|
-
| -------------- | --------------------------- | ------- | ---------------------------------------- |
|
|
453
|
-
| `value` | `unknown` | - | Controlled selected value. |
|
|
454
|
-
| `defaultValue` | `unknown` | - | Initial selection for uncontrolled use. |
|
|
455
|
-
| `onChange` | `(value: unknown) => void` | - | Fires with the newly selected value. |
|
|
456
|
-
| `disabled` | `boolean` | `false` | Disables every `Radio` in the group. |
|
|
457
|
-
| `layout` | `LayoutProps` | - | Layout of the group container. |
|
|
458
|
-
| `children` | `any` | - | `Radio` elements. |
|
|
459
|
-
|
|
460
|
-
**Radio props**
|
|
461
|
-
|
|
462
|
-
| Prop | Type | Description |
|
|
463
|
-
| ---------- | ------------- | --------------------------------------------------- |
|
|
464
|
-
| `value` | `unknown` | This option's value; selecting it sets the group. |
|
|
465
|
-
| `disabled` | `boolean` | Disables this option (also disabled by the group). |
|
|
466
|
-
| `layout` | `LayoutProps` | Layout of the option row. |
|
|
467
|
-
| `style` | `StyleProps` | Paint properties of the option row. |
|
|
468
|
-
| `children` | `any` | A string/number label, or custom content. |
|
|
442
|
+
API: `RadioGroup`, `Radio`, `RadioGroupProps`, `RadioProps` - typed and commented in [src/radio.tsx](./src/radio.tsx).
|
|
469
443
|
|
|
470
444
|
### Slider
|
|
471
445
|
|
|
472
|
-
A horizontal slider
|
|
446
|
+
A horizontal slider: the groove fills up to the thumb, and pressing or dragging the track sets the value from the pointer position. Controlled via `value`/`onChange` (fires while dragging), or uncontrolled via `defaultValue` (defaults to `min`). `min`/`max` default to 0/100; `step` snaps to an increment, omitted the value is continuous. The drag keeps tracking when the pointer drifts off the track, and an enclosing ScrollView never takes it over.
|
|
473
447
|
|
|
474
448
|
```jsx
|
|
475
449
|
import { Slider } from "@solidrt/components"
|
|
@@ -477,23 +451,11 @@ import { Slider } from "@solidrt/components"
|
|
|
477
451
|
<Slider value={volume()} onChange={setVolume} min={0} max={100} step={1} layout={{ width: 180 }} />
|
|
478
452
|
```
|
|
479
453
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
| Prop | Type | Default | Description |
|
|
483
|
-
| -------------- | -------------------------- | ------- | -------------------------------------------- |
|
|
484
|
-
| `value` | `number` | - | Controlled value. Omit for uncontrolled. |
|
|
485
|
-
| `defaultValue` | `number` | `min` | Initial value for uncontrolled use. |
|
|
486
|
-
| `min` | `number` | `0` | Lower bound. |
|
|
487
|
-
| `max` | `number` | `100` | Upper bound. |
|
|
488
|
-
| `step` | `number` | - | Snap increment. Omit for continuous. |
|
|
489
|
-
| `onChange` | `(value: number) => void` | - | Fires with the new value while dragging. |
|
|
490
|
-
| `disabled` | `boolean` | `false` | Takes no pointer events when true. |
|
|
491
|
-
| `layout` | `LayoutProps` | - | Layout of the track (e.g. `width`). |
|
|
492
|
-
| `style` | `StyleProps` | - | Transform only (`x`/`y`/`rotate`/`scale`). |
|
|
454
|
+
API: `Slider`, `SliderProps` - typed and commented in [src/slider.tsx](./src/slider.tsx).
|
|
493
455
|
|
|
494
456
|
### Card
|
|
495
457
|
|
|
496
|
-
A themed surface container: a padded column box with a `surface` fill, a subtle `border` stroke, and rounded corners
|
|
458
|
+
A themed surface container: a padded column box with a `surface` fill, a subtle `border` stroke, and rounded corners, recoloring live on a theme switch. Pass a `title` for a heading, or lay out the content yourself; override paint via `style`, spacing/sizing via `layout`.
|
|
497
459
|
|
|
498
460
|
```jsx
|
|
499
461
|
import { Card } from "@solidrt/components"
|
|
@@ -503,18 +465,53 @@ import { Card } from "@solidrt/components"
|
|
|
503
465
|
</Card>
|
|
504
466
|
```
|
|
505
467
|
|
|
506
|
-
|
|
468
|
+
API: `Card`, `CardProps` - typed and commented in [src/card.tsx](./src/card.tsx).
|
|
469
|
+
|
|
470
|
+
### Item
|
|
471
|
+
|
|
472
|
+
A list row: `startContent` (icon, avatar, checkbox), a `label` with an optional `description` under it, and `endContent` (badge, timestamp, action) pushed to the end. String/number label and description render as themed body and muted body text; anything else as-is. The dense-data workhorse: rows compose with `<For>` inside a plain column view or `ScrollView` - there is no List wrapper, because a column IS the list. Paddings and gaps are density-scaled, so a `<Density>` region compacts rows wholesale.
|
|
473
|
+
|
|
474
|
+
```jsx
|
|
475
|
+
import { Item, Badge, Icon } from "@solidrt/components"
|
|
476
|
+
import { For } from "@solidrt/core"
|
|
477
|
+
|
|
478
|
+
<view flexDirection="column">
|
|
479
|
+
<For each={issues()}>
|
|
480
|
+
{(issue) => (
|
|
481
|
+
<Item
|
|
482
|
+
startContent={<Icon src={Bug} />}
|
|
483
|
+
label={issue.title}
|
|
484
|
+
description={issue.assignee}
|
|
485
|
+
endContent={<Badge variant="neutral">{issue.id}</Badge>}
|
|
486
|
+
selected={issue.id === current()}
|
|
487
|
+
onPress={() => setCurrent(issue.id)}
|
|
488
|
+
/>
|
|
489
|
+
)}
|
|
490
|
+
</For>
|
|
491
|
+
</view>
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
With `onPress` the row is interactive: hover/pressed overlay tints (no scale - rows sit flush in a list), focusable for spatial navigation, Enter/remote activation, and a focus ring under the `focusRing` policy. An async `onPress` (returning a promise) is not re-fired until it settles. Without `onPress` the row attaches no press recognizer, so controls inside it (a Switch in a settings row) and enclosing pressables receive pointer events untouched; interactivity is decided at mount. `selected` fills the row with `surfaceAlt`; `disabled` dims the row and takes no pointer events. Separate rows with `Divider` where needed.
|
|
495
|
+
|
|
496
|
+
API: `Item`, `ItemProps` - typed and commented in [src/item.tsx](./src/item.tsx).
|
|
507
497
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
498
|
+
### Field
|
|
499
|
+
|
|
500
|
+
A form row: `label` above the control, the control itself (`children`, rendered as-is), and a help or error line below. `error` renders in the danger color and replaces `description` while set. It draws no chrome and does not reach into the control - error styling of the input itself stays the input's `style` prop, no hidden magic. The message line only occupies space while there is one; reserve the space with a constant `description` if the form must not jump when an error appears.
|
|
501
|
+
|
|
502
|
+
```jsx
|
|
503
|
+
import { Field, TextInput } from "@solidrt/components"
|
|
504
|
+
|
|
505
|
+
<Field label="Email" description="Used for receipts only." error={emailError()}>
|
|
506
|
+
<TextInput value={email()} onInput={setEmail} />
|
|
507
|
+
</Field>
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
API: `Field`, `FieldProps` - typed and commented in [src/field.tsx](./src/field.tsx).
|
|
514
511
|
|
|
515
512
|
### Divider
|
|
516
513
|
|
|
517
|
-
A thin rule in the theme `border` color. It stretches across its container on the cross axis: full width inside a column, full height inside a row (pass `orientation="vertical"`).
|
|
514
|
+
A thin rule in the theme `border` color. It stretches across its container on the cross axis: full width inside a column, full height inside a row (pass `orientation="vertical"`). `thickness` defaults to 1px; add spacing with `layout` margins, and override the color via `style.backgroundColor`.
|
|
518
515
|
|
|
519
516
|
```jsx
|
|
520
517
|
import { Divider } from "@solidrt/components"
|
|
@@ -523,37 +520,24 @@ import { Divider } from "@solidrt/components"
|
|
|
523
520
|
<Divider orientation="vertical" />
|
|
524
521
|
```
|
|
525
522
|
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
| Prop | Type | Default | Description |
|
|
529
|
-
| ------------- | ----------------------------- | -------------- | -------------------------------------- |
|
|
530
|
-
| `orientation` | `"horizontal" \| "vertical"` | `"horizontal"` | Rule direction. |
|
|
531
|
-
| `thickness` | `number` | `1` | Line thickness in pixels. |
|
|
532
|
-
| `layout` | `LayoutProps` | - | Layout (e.g. margins for spacing). |
|
|
533
|
-
| `style` | `StyleProps` | - | `backgroundColor` overrides the color. |
|
|
523
|
+
API: `Divider`, `DividerProps` - typed and commented in [src/divider.tsx](./src/divider.tsx).
|
|
534
524
|
|
|
535
525
|
### Badge
|
|
536
526
|
|
|
537
|
-
A small rounded pill for counts, labels, and status.
|
|
527
|
+
A small rounded pill for counts, labels, and status. `variant` picks the role: `primary` (accent fill, the default), `neutral` (subtle surface), `danger`. A string/number child renders as the themed label, anything else as-is (an icon, a dot, ...). Override the fill via `style.backgroundColor` and the label color via `style.color`.
|
|
538
528
|
|
|
539
529
|
```jsx
|
|
540
530
|
import { Badge } from "@solidrt/components"
|
|
541
531
|
|
|
542
532
|
<Badge>New</Badge>
|
|
543
|
-
<Badge
|
|
533
|
+
<Badge variant="danger">Error</Badge>
|
|
544
534
|
```
|
|
545
535
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
| Prop | Type | Default | Description |
|
|
549
|
-
| ---------- | ------------- | ------- | -------------------------------------------------- |
|
|
550
|
-
| `children` | `any` | - | String/number renders as the label; else as-is. |
|
|
551
|
-
| `layout` | `LayoutProps` | - | Box layout (e.g. padding overrides). |
|
|
552
|
-
| `style` | `StyleProps` | - | `backgroundColor` (fill), `color` (label), transform. |
|
|
536
|
+
API: `Badge`, `BadgeProps`, `BadgeVariant` - typed and commented in [src/badge.tsx](./src/badge.tsx).
|
|
553
537
|
|
|
554
538
|
### Spinner
|
|
555
539
|
|
|
556
|
-
An indeterminate spinner: a 270-degree arc that rotates continuously
|
|
540
|
+
An indeterminate spinner: a 270-degree arc that rotates continuously, driven by core `onFrame`, so it participates in demand-driven rendering and stops when unmounted. `size` (diameter, default 24), `thickness` (default 3), `speed` (revolutions per second, default 1). Color comes from the theme `primary`; override via `style.color`.
|
|
557
541
|
|
|
558
542
|
```jsx
|
|
559
543
|
import { Spinner } from "@solidrt/components"
|
|
@@ -562,19 +546,11 @@ import { Spinner } from "@solidrt/components"
|
|
|
562
546
|
<Spinner size={32} thickness={4} speed={1.5} />
|
|
563
547
|
```
|
|
564
548
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
| Prop | Type | Default | Description |
|
|
568
|
-
| ----------- | ------------- | ------- | ---------------------------------- |
|
|
569
|
-
| `size` | `number` | `24` | Overall diameter in pixels. |
|
|
570
|
-
| `thickness` | `number` | `3` | Arc stroke width in pixels. |
|
|
571
|
-
| `speed` | `number` | `1` | Revolutions per second. |
|
|
572
|
-
| `layout` | `LayoutProps` | - | Layout of the box. |
|
|
573
|
-
| `style` | `StyleProps` | - | `color` sets the arc; plus transform. |
|
|
549
|
+
API: `Spinner`, `SpinnerProps` - typed and commented in [src/spinner.tsx](./src/spinner.tsx).
|
|
574
550
|
|
|
575
551
|
### ProgressBar
|
|
576
552
|
|
|
577
|
-
A horizontal progress bar
|
|
553
|
+
A horizontal progress bar: determinate when given a `value` in `[0, 1]` (the fill grows from the left), indeterminate when `value` is undefined (a short segment slides back and forth, driven by core `onFrame`). Track is `surfaceAlt`, fill is `primary`; override via `style.backgroundColor` (track) and `style.color` (fill).
|
|
578
554
|
|
|
579
555
|
```jsx
|
|
580
556
|
import { ProgressBar } from "@solidrt/components"
|
|
@@ -583,17 +559,153 @@ import { ProgressBar } from "@solidrt/components"
|
|
|
583
559
|
<ProgressBar /> // indeterminate
|
|
584
560
|
```
|
|
585
561
|
|
|
586
|
-
|
|
562
|
+
API: `ProgressBar`, `ProgressBarProps` - typed and commented in [src/progress-bar.tsx](./src/progress-bar.tsx).
|
|
563
|
+
|
|
564
|
+
### Portal
|
|
565
|
+
|
|
566
|
+
Renders its child somewhere other than its lexical position: by default at the window root, so overlays (modals, menus, tooltips) escape the clipping and stacking of their surrounding layout; `mount` targets another node captured from a `ref` instead. A thin JSX wrapper over core `createPortal`. The child should be a single element with `position="absolute"`, since it is inserted into the window's flex root. Portals cannot mount during the app's initial render, so gate them behind a signal that starts false.
|
|
567
|
+
|
|
568
|
+
```jsx
|
|
569
|
+
import { Portal } from "@solidrt/components"
|
|
570
|
+
|
|
571
|
+
<Show when={open()}>
|
|
572
|
+
<Portal>
|
|
573
|
+
<view position="absolute" right={16} bottom={16}>
|
|
574
|
+
<Card>Saved</Card>
|
|
575
|
+
</view>
|
|
576
|
+
</Portal>
|
|
577
|
+
</Show>
|
|
578
|
+
```
|
|
579
|
+
|
|
580
|
+
API: `Portal`, `PortalProps` - typed and commented in [src/portal.tsx](./src/portal.tsx).
|
|
581
|
+
|
|
582
|
+
### Modal
|
|
583
|
+
|
|
584
|
+
A centered overlay rendered at the window root via core `createPortal`: it fills the window with a dimming backdrop (theme `scrim`; override via `backdropColor`, `"transparent"` for no dim) and centers `children` on top. Control visibility by mounting/unmounting it, e.g. `<Show when={open()}>`; the gating signal must start false since portals cannot mount during the initial render. Pressing the backdrop calls `onClose` (unless `dismissable` is false), pressing the content does not, and while mounted the modal traps `createFocusNav` inside itself.
|
|
585
|
+
|
|
586
|
+
```jsx
|
|
587
|
+
import { Modal, Card, Button } from "@solidrt/components"
|
|
588
|
+
|
|
589
|
+
<Show when={open()}>
|
|
590
|
+
<Modal onClose={() => setOpen(false)}>
|
|
591
|
+
<Card>
|
|
592
|
+
<Button onPress={() => setOpen(false)}>Close</Button>
|
|
593
|
+
</Card>
|
|
594
|
+
</Modal>
|
|
595
|
+
</Show>
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
API: `Modal`, `ModalProps` - typed and commented in [src/modal.tsx](./src/modal.tsx).
|
|
599
|
+
|
|
600
|
+
### Tooltip
|
|
601
|
+
|
|
602
|
+
A hover-only affordance: under the `desktop`/`hybrid` interaction policies, resting a mouse pointer on the wrapped content shows a bubble near it after `delay` (default 500ms). Under the `touch` policy it never shows, so tooltip content must stay non-essential. The bubble is portal-mounted at the window root, clamped to the window edges, takes no pointer events, and hides on leave and on press. A string/number `content` renders as themed body text; anything else as-is. `placement` picks the side (`"top"`, the default, or `"bottom"`).
|
|
603
|
+
|
|
604
|
+
```jsx
|
|
605
|
+
import { Tooltip, Button } from "@solidrt/components"
|
|
606
|
+
|
|
607
|
+
<Tooltip content="Save (Ctrl+S)">
|
|
608
|
+
<Button onPress={save}>Save</Button>
|
|
609
|
+
</Tooltip>
|
|
610
|
+
```
|
|
611
|
+
|
|
612
|
+
API: `Tooltip`, `TooltipProps` - typed and commented in [src/tooltip.tsx](./src/tooltip.tsx).
|
|
587
613
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
614
|
+
### Select
|
|
615
|
+
|
|
616
|
+
A single-choice picker whose presentation forks on the interaction policy: `desktop`/`hybrid` opens an anchored dropdown under the trigger (flipping above when there is no room), `touch` opens a bottom sheet over a scrim. Same contract either way: `options` is an `Option[]` (`{ value, label }`), controlled via `value`/`onChange` or uncontrolled via `defaultValue`; pressing outside closes without a change. `placeholder` shows in the trigger while nothing is selected. The option list is not scrollable yet, so keep it short. The trigger's chevron is the `theme.icons.chevronDown` slot when a theme sets one.
|
|
617
|
+
|
|
618
|
+
```jsx
|
|
619
|
+
import { Select } from "@solidrt/components"
|
|
620
|
+
|
|
621
|
+
let options = [
|
|
622
|
+
{ value: "s", label: "Small" },
|
|
623
|
+
{ value: "m", label: "Medium" },
|
|
624
|
+
{ value: "l", label: "Large" },
|
|
625
|
+
]
|
|
626
|
+
|
|
627
|
+
<Select options={options} value={size()} onChange={setSize} placeholder="Size" />
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
API: `Select`, `SelectProps` - typed and commented in [src/select.tsx](./src/select.tsx).
|
|
631
|
+
|
|
632
|
+
### SegmentedControl
|
|
633
|
+
|
|
634
|
+
A single-choice row of equal-width segments joined flush: only the control's outermost corners are rounded, hairline dividers separate the segments, and the active segment fills with the theme `primary`. Hovered segments tint with the theme `overlayHover` under non-touch interaction policies. `options` is an `Option[]`; controlled via `value`/`onChange`, or uncontrolled via `defaultValue`. Override the inactive fill via `style.backgroundColor` and the outer radius via `style.borderRadius`.
|
|
635
|
+
|
|
636
|
+
```jsx
|
|
637
|
+
import { SegmentedControl } from "@solidrt/components"
|
|
638
|
+
|
|
639
|
+
<SegmentedControl
|
|
640
|
+
options={[{ value: "day", label: "Day" }, { value: "week", label: "Week" }]}
|
|
641
|
+
value={range()}
|
|
642
|
+
onChange={setRange}
|
|
643
|
+
/>
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
API: `SegmentedControl`, `SegmentedControlProps` - typed and commented in [src/segmented-control.tsx](./src/segmented-control.tsx).
|
|
647
|
+
|
|
648
|
+
### ContextMenu
|
|
649
|
+
|
|
650
|
+
Secondary actions on the wrapped content. The opening gesture follows the physical pointer: right-click for a mouse, long-press (500ms, cancelled by finger travel) for touch. The presentation forks on the interaction policy: `touch` gets a bottom sheet over a scrim, `desktop`/`hybrid` an anchored menu at the pointer that flips up near the bottom edge. `items` is a `ContextMenuItem[]` (`{ label, onSelect?, disabled? }`); pressing outside closes without selecting.
|
|
651
|
+
|
|
652
|
+
```jsx
|
|
653
|
+
import { ContextMenu } from "@solidrt/components"
|
|
654
|
+
|
|
655
|
+
<ContextMenu
|
|
656
|
+
items={[
|
|
657
|
+
{ label: "Rename", onSelect: rename },
|
|
658
|
+
{ label: "Delete", onSelect: remove },
|
|
659
|
+
{ label: "Share", disabled: true },
|
|
660
|
+
]}
|
|
661
|
+
>
|
|
662
|
+
<Card>{file.name}</Card>
|
|
663
|
+
</ContextMenu>
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
API: `ContextMenu`, `ContextMenuProps`, `ContextMenuItem` - typed and commented in [src/context-menu.tsx](./src/context-menu.tsx).
|
|
667
|
+
|
|
668
|
+
### NavShell
|
|
669
|
+
|
|
670
|
+
An app shell that arranges primary navigation around the content per `policy.navigation`: bottom tabs under it (`bottomTabs`), a narrow rail (`rail`), or a wide sidebar (`sidebar`) beside it. The content is a single stable node; switching arrangement only flips the shell's flex direction and remounts the stateless nav strip, so page state survives a resize across a breakpoint. `items` is a `NavItem[]` (`{ value, label, icon? }`; the icon renders above the label in tabs/rail, beside it in the sidebar); controlled via `value`/`onChange`, or uncontrolled via `defaultValue`. Safe areas are the caller's concern: wrap the shell in `SafeArea`.
|
|
671
|
+
|
|
672
|
+
```jsx
|
|
673
|
+
import { NavShell, Icon } from "@solidrt/components"
|
|
674
|
+
|
|
675
|
+
let items = [
|
|
676
|
+
{ value: "home", label: "Home", icon: <Icon src={House} /> },
|
|
677
|
+
{ value: "settings", label: "Settings", icon: <Icon src={Cog} /> },
|
|
678
|
+
]
|
|
679
|
+
|
|
680
|
+
<NavShell items={items} value={page()} onChange={setPage} layout={{ flex: 1 }}>
|
|
681
|
+
<Show when={page() === "home"} fallback={<Settings />}>
|
|
682
|
+
<Home />
|
|
683
|
+
</Show>
|
|
684
|
+
</NavShell>
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
API: `NavShell`, `NavShellProps`, `NavItem` - typed and commented in [src/nav-shell.tsx](./src/nav-shell.tsx).
|
|
688
|
+
|
|
689
|
+
### SplitView
|
|
690
|
+
|
|
691
|
+
A list-detail container driven by `policy.layout`: `twoPane` shows the `list` pane (width `listWidth`, default `theme.size.splitViewList`) beside the `detail` pane, `singlePane` shows one at a time per `showDetail`. Keep pane state (selection, scroll) in the app, not in the panes: crossing a breakpoint re-arranges and can remount them. It draws no chrome and adds no padding; a back affordance in the single-pane detail is the app's to render (fork on `policy.layout`).
|
|
692
|
+
|
|
693
|
+
```jsx
|
|
694
|
+
import { SplitView } from "@solidrt/components"
|
|
695
|
+
|
|
696
|
+
<SplitView
|
|
697
|
+
layout={{ flex: 1 }}
|
|
698
|
+
list={<Inbox onOpen={setSelected} />}
|
|
699
|
+
detail={<Message id={selected()} onBack={() => setSelected(null)} />}
|
|
700
|
+
showDetail={selected() !== null}
|
|
701
|
+
/>
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
API: `SplitView`, `SplitViewProps` - typed and commented in [src/split-view.tsx](./src/split-view.tsx).
|
|
593
705
|
|
|
594
706
|
### QrCode
|
|
595
707
|
|
|
596
|
-
Renders a QR code for `data` out of primitives: same-color modules in a row collapse into one box, drawn on a light quiet-zone panel
|
|
708
|
+
Renders a QR code for `data` out of primitives: same-color modules in a row collapse into one box, drawn on a light quiet-zone panel; the grid recomputes only when `data` or `level` changes. It paints black on white by default (not the theme) so it stays scannable through a theme switch; override `color`/`background` only if the contrast still holds. `moduleSize` (default 6) is pixels per module, `margin` (default 16) the quiet zone (keep it non-zero), `level` the error correction (`L`/`M`/`Q`/`H`, default `M`: higher tolerates more damage but caps data length sooner), `radius` the panel's corner radius.
|
|
597
709
|
|
|
598
710
|
```jsx
|
|
599
711
|
import { QrCode } from "@solidrt/components"
|
|
@@ -602,24 +714,13 @@ import { QrCode } from "@solidrt/components"
|
|
|
602
714
|
<QrCode data={ticket()} moduleSize={8} level="L" />
|
|
603
715
|
```
|
|
604
716
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
| Prop | Type | Default | Description |
|
|
608
|
-
| ------------ | -------------------------- | -------------- | -------------------------------------------------------------- |
|
|
609
|
-
| `data` | `string` | - | The string to encode (URL, pairing ticket, text, ...). |
|
|
610
|
-
| `moduleSize` | `number` | `6` | Pixels per module (the smallest square). |
|
|
611
|
-
| `margin` | `number` | `16` | Quiet-zone padding in pixels around the grid; keep non-zero. |
|
|
612
|
-
| `color` | `string` | `"#000000"` | Dark-module color. |
|
|
613
|
-
| `background` | `string` | `"#ffffff"` | Panel/light-module color. |
|
|
614
|
-
| `level` | `"L" \| "M" \| "Q" \| "H"` | `"M"` | Error-correction level; higher tolerates more damage but caps data length sooner. |
|
|
615
|
-
| `radius` | `number` | `8` | Corner radius of the background panel. |
|
|
616
|
-
| `layout` | `LayoutProps` | - | Layout of the outer box. |
|
|
717
|
+
API: `QrCode`, `QrCodeProps` - typed and commented in [src/qrcode.tsx](./src/qrcode.tsx).
|
|
617
718
|
|
|
618
719
|
### Icon
|
|
619
720
|
|
|
620
|
-
A thin themed wrapper over the core `parseSvg` primitive. `src` is a whole SVG document as a string; the component parses it once (memoized), maps the draws to `<d-path>` in a square `
|
|
721
|
+
A thin themed wrapper over the core `parseSvg` primitive. `src` is a whole SVG document as a string; the component parses it once (memoized), maps the draws to `<d-path>` in a square `designSize`-fitted box (`size`, default 24) and, for monochrome icons that stroke/fill with `currentColor`, recolors it via `color` (default the theme text color). It carries no icon set and no name registry, so any `currentColor` SVG works (Lucide, Feather, Heroicons, ...) and only the icons you import are bundled. Multi-color documents keep their own fills. For a non-square box, use `parseSvg` directly.
|
|
621
722
|
|
|
622
|
-
Icons are just SVG strings
|
|
723
|
+
Icons are just SVG strings: import them as assets (`import House from "lucide-static/icons/house.svg"`, resolved to a string), pull them from a string export, or inline a literal.
|
|
623
724
|
|
|
624
725
|
```jsx
|
|
625
726
|
import { Icon } from "@solidrt/components"
|
|
@@ -629,14 +730,23 @@ import House from "lucide-static/icons/house.svg"
|
|
|
629
730
|
<Icon src={House} size={32} color={theme.color.primary} />
|
|
630
731
|
```
|
|
631
732
|
|
|
632
|
-
|
|
733
|
+
API: `Icon`, `IconProps` - typed and commented in [src/icon.tsx](./src/icon.tsx).
|
|
734
|
+
|
|
735
|
+
### Density
|
|
736
|
+
|
|
737
|
+
`<Density value="compact">` overrides the density policy for its subtree: every density-scaled metric below - `space()`, control sizes (Checkbox, Switch, Radio, Slider), `Item` and `Button` paddings - resolves this value instead of the global `policy.density`. Regions nest; the nearest wins. Use it to tighten a toolbar, a data table, or a sidebar without per-child props.
|
|
738
|
+
|
|
739
|
+
```jsx
|
|
740
|
+
import { Density, Item } from "@solidrt/components"
|
|
741
|
+
|
|
742
|
+
<Density value="dense">
|
|
743
|
+
<For each={rows()}>{(r) => <Item label={r.name} />}</For>
|
|
744
|
+
</Density>
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
`densityScale()` is the reactive multiplier behind it (1 / 0.85 / 0.7 for comfortable/compact/dense): the nearest `<Density>` above the calling scope, falling back to `policy.density`. Call it during component setup or inside JSX/thunks when building custom density-aware components.
|
|
633
748
|
|
|
634
|
-
|
|
635
|
-
| -------- | ------------- | ------------------ | -------------------------------------------------------------- |
|
|
636
|
-
| `src` | `string` | - | The SVG document to draw. |
|
|
637
|
-
| `size` | `number` | `24` | Square box side in pixels. |
|
|
638
|
-
| `color` | `string` | `theme.color.text` | Drives `currentColor`; explicit fills/strokes still win. |
|
|
639
|
-
| `layout` | `LayoutProps` | - | Layout of the box. |
|
|
749
|
+
API: `Density`, `DensityProps`, `densityScale` - typed and commented in [src/density.tsx](./src/density.tsx).
|
|
640
750
|
|
|
641
751
|
## License
|
|
642
752
|
|