@ruby-native/react 0.9.0 → 0.9.1

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.
Files changed (2) hide show
  1. package/index.js +26 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,6 +2,22 @@ import { createElement } from "react"
2
2
 
3
3
  import("@inertiajs/react").then(m => { window.__inertiaRouter = m.router }).catch(() => {})
4
4
 
5
+ function rubyNativePlatform() {
6
+ if (typeof navigator === "undefined") return null
7
+ const ua = navigator.userAgent || ""
8
+ if (ua.includes("Ruby Native iOS")) return "ios"
9
+ if (ua.includes("Ruby Native Android")) return "android"
10
+ return null
11
+ }
12
+
13
+ function resolveIcon(icon, icons) {
14
+ if (icons) {
15
+ const platform = rubyNativePlatform()
16
+ if (platform && icons[platform]) return icons[platform]
17
+ }
18
+ return icon
19
+ }
20
+
5
21
  export function NativeTabs({ enabled = true }) {
6
22
  if (!enabled) return null
7
23
  return createElement("div", { "data-native-tabs": true, hidden: true })
@@ -19,9 +35,10 @@ export function NativeNavbar({ title = "", children }) {
19
35
  return createElement("div", { "data-native-navbar": title, hidden: true }, children)
20
36
  }
21
37
 
22
- export function NativeButton({ position = "trailing", icon, title, href, click, selected, children }) {
38
+ export function NativeButton({ position = "trailing", icon, icons, title, href, click, selected, children }) {
39
+ const resolved = resolveIcon(icon, icons)
23
40
  const props = { "data-native-button": true }
24
- if (icon) props["data-native-icon"] = icon
41
+ if (resolved) props["data-native-icon"] = resolved
25
42
  if (title) props["data-native-title"] = title
26
43
  if (href) props["data-native-href"] = href
27
44
  if (click) props["data-native-click"] = click
@@ -30,18 +47,21 @@ export function NativeButton({ position = "trailing", icon, title, href, click,
30
47
  return createElement("div", props, children)
31
48
  }
32
49
 
33
- export function NativeMenuItem({ title, href, click, icon, selected }) {
50
+ export function NativeMenuItem({ title, href, click, icon, icons, selected }) {
51
+ const resolved = resolveIcon(icon, icons)
34
52
  const props = { "data-native-menu-item": true }
35
53
  if (title) props["data-native-title"] = title
36
54
  if (href) props["data-native-href"] = href
37
55
  if (click) props["data-native-click"] = click
38
- if (icon) props["data-native-icon"] = icon
56
+ if (resolved) props["data-native-icon"] = resolved
39
57
  if (selected) props["data-native-selected"] = ""
40
58
  return createElement("div", props)
41
59
  }
42
60
 
43
- export function NativeFab({ icon, href, click }) {
44
- const props = { "data-native-fab": true, "data-native-icon": icon, hidden: true }
61
+ export function NativeFab({ icon, icons, href, click }) {
62
+ const resolved = resolveIcon(icon, icons)
63
+ if (!resolved) throw new Error("NativeFab requires `icon` or `icons`")
64
+ const props = { "data-native-fab": true, "data-native-icon": resolved, hidden: true }
45
65
  if (href) props["data-native-href"] = href
46
66
  if (click) props["data-native-click"] = click
47
67
  return createElement("div", props)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruby-native/react",
3
- "version": "0.9.0",
3
+ "version": "0.9.1",
4
4
  "description": "React components for Ruby Native",
5
5
  "main": "index.js",
6
6
  "files": ["index.js", "README.md"],