@solidrt/components 0.0.36 → 0.0.38
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/README.md +10 -0
- package/package.json +2 -2
- package/src/image.tsx +30 -11
- package/src/pressable.tsx +2 -1
- package/src/text-input.tsx +3 -3
package/README.md
CHANGED
|
@@ -194,10 +194,20 @@ Accepts `layout`, `style`, and all pointer event props, plus:
|
|
|
194
194
|
| Prop | Type | Description |
|
|
195
195
|
| ---------- | ------------------------ | ------------------------------------------------------------------------------------ |
|
|
196
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) |
|
|
197
198
|
| `fallback` | `string \| Uint8Array` | Source shown when `src` fails; if it also fails, the `backgroundColor` placeholder stays |
|
|
198
199
|
| `onLoad` | `() => void` | Called each time a source finishes loading |
|
|
199
200
|
| `onError` | `(err: unknown) => void` | Called when `src` fails to load or decode |
|
|
200
201
|
|
|
202
|
+
With `fit` the image fills whatever box `layout` gives the component - numbers,
|
|
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.
|
|
206
|
+
|
|
207
|
+
```jsx
|
|
208
|
+
<Image src={hero} fit="cover" layout={{ width: pct(100), height: 240 }} />
|
|
209
|
+
```
|
|
210
|
+
|
|
201
211
|
A failing `src` is contained by the component (the fallback or placeholder
|
|
202
212
|
shows); it does not propagate to an outer `<Errored>` boundary.
|
|
203
213
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidrt/components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Antoine van Wel",
|
|
6
6
|
"type": "module",
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"@solidjs/signals": "2.0.0-beta.20",
|
|
21
|
-
"@solidrt/core": "0.0.
|
|
21
|
+
"@solidrt/core": "0.0.38"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/src/image.tsx
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import { createImage, createEffect, Loading, Errored } from "@solidrt/core"
|
|
2
|
-
import type { ImageSource, LayoutProps, PointerProps } from "@solidrt/core"
|
|
1
|
+
import { createImage, createEffect, Loading, Errored, pct } from "@solidrt/core"
|
|
2
|
+
import type { ImageSource, LayoutProps, Pct, PointerProps, TextureProps } from "@solidrt/core"
|
|
3
3
|
import type { StyleProps } from "./types"
|
|
4
4
|
|
|
5
5
|
export interface ImageProps extends PointerProps {
|
|
6
6
|
src: string | Uint8Array
|
|
7
|
+
/**
|
|
8
|
+
* How the image maps into the Image's box (CSS object-fit): "fill"
|
|
9
|
+
* stretches, "cover"/"none" crop, "contain"/"scale-down" letterbox,
|
|
10
|
+
* everything centered. Requires the Image to have a box: give `layout` a
|
|
11
|
+
* size in any form (numbers, `pct()`, flex). Without `fit` the image keeps
|
|
12
|
+
* its legacy sizing: numeric layout sizes are honored, anything else draws
|
|
13
|
+
* at intrinsic size.
|
|
14
|
+
*/
|
|
15
|
+
fit?: TextureProps["fit"]
|
|
7
16
|
/** Image source to show when `src` fails to load. If this also fails, only
|
|
8
17
|
* the `backgroundColor` placeholder remains. */
|
|
9
18
|
fallback?: ImageSource
|
|
@@ -22,11 +31,16 @@ export interface ImageProps extends PointerProps {
|
|
|
22
31
|
// keeps a broken fallback from escaping: the placeholder stays instead.
|
|
23
32
|
// Both fallbacks here take the error argument: an arity >= 1 fallback tells
|
|
24
33
|
// <Errored> the error is handled, so dev builds do not console.error it.
|
|
25
|
-
function FallbackTexture(props: {
|
|
34
|
+
function FallbackTexture(props: {
|
|
35
|
+
src: ImageSource
|
|
36
|
+
fit?: TextureProps["fit"]
|
|
37
|
+
width?: number | Pct
|
|
38
|
+
height?: number | Pct
|
|
39
|
+
}) {
|
|
26
40
|
let tex = createImage(() => props.src)
|
|
27
41
|
return (
|
|
28
42
|
<Errored fallback={(_err: unknown) => null}>
|
|
29
|
-
<texture src={tex()} width={props.width} height={props.height} />
|
|
43
|
+
<texture src={tex()} fit={props.fit} width={props.width} height={props.height} />
|
|
30
44
|
</Errored>
|
|
31
45
|
)
|
|
32
46
|
}
|
|
@@ -47,11 +61,14 @@ export function Image(props: ImageProps) {
|
|
|
47
61
|
error: (err: unknown) => props.onError?.(err),
|
|
48
62
|
})
|
|
49
63
|
|
|
50
|
-
// A texture sizes from its own width/height (not the box around it)
|
|
51
|
-
//
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
// A texture sizes from its own width/height (not the box around it). With
|
|
65
|
+
// `fit` the texture simply fills the Image's box and the fit maps the pixels
|
|
66
|
+
// into it. Without it, legacy sizing: numeric layout dimensions are
|
|
67
|
+
// forwarded, and omitting height lets the texture follow the image's
|
|
68
|
+
// intrinsic aspect ratio.
|
|
69
|
+
let texW = () => (props.fit != null ? pct(100) : typeof props.layout?.width === "number" ? props.layout.width : undefined)
|
|
70
|
+
let texH = () =>
|
|
71
|
+
props.fit != null ? pct(100) : typeof props.layout?.height === "number" ? props.layout.height : undefined
|
|
55
72
|
|
|
56
73
|
return (
|
|
57
74
|
<view
|
|
@@ -82,10 +99,12 @@ export function Image(props: ImageProps) {
|
|
|
82
99
|
<Loading fallback={null}>
|
|
83
100
|
<Errored
|
|
84
101
|
fallback={(_err: unknown) =>
|
|
85
|
-
props.fallback != null ?
|
|
102
|
+
props.fallback != null ? (
|
|
103
|
+
<FallbackTexture src={props.fallback} fit={props.fit} width={texW()} height={texH()} />
|
|
104
|
+
) : null
|
|
86
105
|
}
|
|
87
106
|
>
|
|
88
|
-
<texture src={src()} width={texW()} height={texH()} />
|
|
107
|
+
<texture src={src()} fit={props.fit} width={texW()} height={texH()} />
|
|
89
108
|
</Errored>
|
|
90
109
|
</Loading>
|
|
91
110
|
{hasBorder() ? (
|
package/src/pressable.tsx
CHANGED
|
@@ -30,7 +30,8 @@ export function Pressable(props: PressableProps) {
|
|
|
30
30
|
// zero-arg functions.
|
|
31
31
|
let resolved = children(() => props.children)
|
|
32
32
|
let kids = () => {
|
|
33
|
-
|
|
33
|
+
// children()'s return type erases the render-prop variant, hence the any.
|
|
34
|
+
let c = resolved() as any
|
|
34
35
|
return typeof c === "function" ? c(press.state()) : c
|
|
35
36
|
}
|
|
36
37
|
|
package/src/text-input.tsx
CHANGED
|
@@ -96,10 +96,10 @@ export function TextInput(props: TextInputProps) {
|
|
|
96
96
|
} else if (e.key === "Delete") {
|
|
97
97
|
buffer.deleteForward()
|
|
98
98
|
setCaretOn(true)
|
|
99
|
-
} else if (e.key === "
|
|
99
|
+
} else if (e.key === "ArrowLeft") {
|
|
100
100
|
buffer.move("left")
|
|
101
101
|
setCaretOn(true)
|
|
102
|
-
} else if (e.key === "
|
|
102
|
+
} else if (e.key === "ArrowRight") {
|
|
103
103
|
buffer.move("right")
|
|
104
104
|
setCaretOn(true)
|
|
105
105
|
} else if (e.key === "Home") {
|
|
@@ -108,7 +108,7 @@ export function TextInput(props: TextInputProps) {
|
|
|
108
108
|
} else if (e.key === "End") {
|
|
109
109
|
buffer.move("end")
|
|
110
110
|
setCaretOn(true)
|
|
111
|
-
} else if (e.key === "
|
|
111
|
+
} else if (e.key === "Enter") {
|
|
112
112
|
props.onSubmit?.(value())
|
|
113
113
|
setFocus(null)
|
|
114
114
|
} else if (e.key === "Escape") {
|