@solidrt/components 0.0.4 → 0.0.5

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 CHANGED
@@ -24,7 +24,7 @@ import { SafeArea } from "@solidrt/components"
24
24
  function App() {
25
25
  return (
26
26
  <window>
27
- <SafeArea>
27
+ <SafeArea top bottom>
28
28
  <text>Content clear of system UI</text>
29
29
  </SafeArea>
30
30
  </window>
@@ -32,13 +32,28 @@ function App() {
32
32
  }
33
33
  ```
34
34
 
35
+ Top and bottom insets are applied by default. Pass `false` to opt out of an edge, or a number to apply the inset with a minimum padding.
36
+
37
+ ```jsx
38
+ // top only
39
+ <SafeArea bottom={false}>
40
+
41
+ // apply top and bottom insets, with a minimum of 16px each
42
+ <SafeArea top={16} bottom={16}>
43
+
44
+ // all four edges
45
+ <SafeArea top bottom left right>
46
+ ```
47
+
35
48
  **Props**
36
49
 
37
- | Prop | Type | Default | Description |
38
- | ---------- | -------------------------------------------- | ------------------- | -------------------------------------------------------------- |
39
- | `edges` | `("top" \| "bottom" \| "left" \| "right")[]` | `["top", "bottom"]` | Which edges to apply safe area insets on |
40
- | `minimum` | `number` | `0` | Minimum padding applied even if the safe area inset is smaller |
41
- | `children` | `any` | - | Content to render inside the safe area |
50
+ | Prop | Type | Default | Description |
51
+ | ---------- | ------------------- | ------- | --------------------------------------------------- |
52
+ | `top` | `boolean \| number` | `true` | Apply top inset. A number sets the minimum padding. |
53
+ | `bottom` | `boolean \| number` | `true` | Apply bottom inset. A number sets the minimum padding. |
54
+ | `left` | `boolean \| number` | `false` | Apply left inset. A number sets the minimum padding. |
55
+ | `right` | `boolean \| number` | `false` | Apply right inset. A number sets the minimum padding. |
56
+ | `children` | `any` | - | Content to render inside the safe area. |
42
57
 
43
58
  ### TextInput
44
59
 
@@ -78,6 +93,26 @@ function NameField() {
78
93
  | `autoFocus` | `boolean` | `false` | Focuses on mount |
79
94
  | `width` | `number \| "auto" \| "N%"` | - | Field width |
80
95
 
96
+ ### Image
97
+
98
+ Loads and displays an image from a URL or raw bytes.
99
+
100
+ ```jsx
101
+ import { Image } from "@solidrt/components"
102
+
103
+ function Avatar() {
104
+ return <Image src="https://example.com/avatar.png" width={64} height={64} />
105
+ }
106
+ ```
107
+
108
+ **Props**
109
+
110
+ Accepts all layout, transform, and pointer event props, plus:
111
+
112
+ | Prop | Type | Description |
113
+ | ----- | ---------------------- | -------------------------------------------- |
114
+ | `src` | `string \| Uint8Array` | URL to fetch, or raw image bytes to decode |
115
+
81
116
  ## License
82
117
 
83
118
  MIT. Copyright (c) 2026 Antoine van Wel.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidrt/components",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "license": "MIT",
5
5
  "author": "Antoine van Wel",
6
6
  "type": "module",
@@ -15,6 +15,6 @@
15
15
  ],
16
16
  "peerDependencies": {
17
17
  "@solidjs/signals": "2.0.0-beta.13",
18
- "@solidrt/core": "0.0.4"
18
+ "@solidrt/core": "0.0.5"
19
19
  }
20
20
  }
package/src/image.tsx ADDED
@@ -0,0 +1,66 @@
1
+ import { createSignal, onCleanup } from "@solidjs/signals"
2
+ import { decodeImage, createTexture } from "@solidrt/core/gpu"
3
+ import type { LayoutProps, TransformProps, PointerProps } from "@solidrt/core"
4
+
5
+ export interface ImageProps extends LayoutProps, TransformProps, PointerProps {
6
+ src: string | Uint8Array
7
+ }
8
+
9
+ //TODO onLoad, onError
10
+ //TODO release texture in onCleanup
11
+ //TODO forward all LayoutProps (currently only the common subset)
12
+ export function Image(props: ImageProps) {
13
+ let [res] = createSignal(async () => {
14
+ let bytes: Uint8Array
15
+ if (typeof props.src === "string") {
16
+ let response = await fetch(props.src)
17
+ bytes = await response.bytes()
18
+ } else {
19
+ bytes = props.src
20
+ }
21
+ let { data, width, height } = decodeImage(bytes)
22
+ let id = createTexture(data, width, height)
23
+ return { id, width, height }
24
+ })
25
+
26
+ let src = () => res()?.id
27
+
28
+ onCleanup(() => {
29
+ //TODO release texture
30
+ })
31
+
32
+ return (
33
+ <view
34
+ width={props.width}
35
+ height={props.height}
36
+ flex={props.flex}
37
+ flexGrow={props.flexGrow}
38
+ flexShrink={props.flexShrink}
39
+ alignSelf={props.alignSelf}
40
+ margin={props.margin}
41
+ marginTop={props.marginTop}
42
+ marginBottom={props.marginBottom}
43
+ marginLeft={props.marginLeft}
44
+ marginRight={props.marginRight}
45
+ padding={props.padding}
46
+ position={props.position}
47
+ top={props.top}
48
+ right={props.right}
49
+ bottom={props.bottom}
50
+ left={props.left}
51
+ x={props.x}
52
+ y={props.y}
53
+ scale={props.scale}
54
+ rotate={props.rotate}
55
+ onPointerEnter={props.onPointerEnter}
56
+ onPointerLeave={props.onPointerLeave}
57
+ onPointerDown={props.onPointerDown}
58
+ onPointerUp={props.onPointerUp}
59
+ onPointerMove={props.onPointerMove}
60
+ onWheel={props.onWheel}
61
+ pointerEvents={props.pointerEvents}
62
+ >
63
+ <texture src={src()} />
64
+ </view>
65
+ )
66
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { Image, type ImageProps } from "./image"
1
2
  export { SafeArea } from "./safe-area"
2
3
  export { TextInput, type TextInputProps } from "./text-input"
3
4
  export { theme, setTheme, type Theme } from "./theme"
package/src/safe-area.tsx CHANGED
@@ -2,8 +2,10 @@ import { createSignal } from "@solidjs/signals"
2
2
  import { onResize } from "@solidrt/core"
3
3
 
4
4
  export function SafeArea(props: {
5
- edges?: ("top" | "bottom" | "left" | "right")[]
6
- minimum?: number
5
+ top?: boolean | number
6
+ bottom?: boolean | number
7
+ left?: boolean | number
8
+ right?: boolean | number
7
9
  children?: any
8
10
  }) {
9
11
  let [insets, setInsets] = createSignal({ top: 0, bottom: 0, left: 0, right: 0 })
@@ -15,9 +17,13 @@ export function SafeArea(props: {
15
17
  right: width - safeArea.right,
16
18
  })
17
19
  })
18
- let has = (e: string) => (props.edges ?? ["top", "bottom"]).includes(e as any)
19
- let pad = (edge: "top" | "bottom" | "left" | "right") =>
20
- has(edge) ? Math.max(insets()[edge], props.minimum ?? 0) : 0
20
+ let pad = (edge: "top" | "bottom" | "left" | "right") => {
21
+ let defaultOn = edge === "top" || edge === "bottom"
22
+ let p = props[edge] ?? defaultOn
23
+ if (p === false) return 0
24
+ if (p === true) return insets()[edge]
25
+ return Math.max(insets()[edge], p as number)
26
+ }
21
27
  return (
22
28
  <view
23
29
  flex={1}