@ruby-native/vue 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.
- package/index.js +27 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,6 +2,22 @@ import { defineComponent, h } from "vue"
|
|
|
2
2
|
|
|
3
3
|
import("@inertiajs/vue3").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 const NativeTabs = defineComponent({
|
|
6
22
|
name: "NativeTabs",
|
|
7
23
|
props: {
|
|
@@ -40,14 +56,16 @@ export const NativeButton = defineComponent({
|
|
|
40
56
|
props: {
|
|
41
57
|
position: { type: String, default: "trailing" },
|
|
42
58
|
icon: String,
|
|
59
|
+
icons: Object,
|
|
43
60
|
title: String,
|
|
44
61
|
href: String,
|
|
45
62
|
click: String,
|
|
46
63
|
selected: { type: Boolean, default: undefined }
|
|
47
64
|
},
|
|
48
65
|
render() {
|
|
66
|
+
const resolved = resolveIcon(this.icon, this.icons)
|
|
49
67
|
const attrs = { "data-native-button": true }
|
|
50
|
-
if (
|
|
68
|
+
if (resolved) attrs["data-native-icon"] = resolved
|
|
51
69
|
if (this.title) attrs["data-native-title"] = this.title
|
|
52
70
|
if (this.href) attrs["data-native-href"] = this.href
|
|
53
71
|
if (this.click) attrs["data-native-click"] = this.click
|
|
@@ -64,14 +82,16 @@ export const NativeMenuItem = defineComponent({
|
|
|
64
82
|
href: String,
|
|
65
83
|
click: String,
|
|
66
84
|
icon: String,
|
|
85
|
+
icons: Object,
|
|
67
86
|
selected: { type: Boolean, default: undefined }
|
|
68
87
|
},
|
|
69
88
|
render() {
|
|
89
|
+
const resolved = resolveIcon(this.icon, this.icons)
|
|
70
90
|
const attrs = { "data-native-menu-item": true }
|
|
71
91
|
if (this.title) attrs["data-native-title"] = this.title
|
|
72
92
|
if (this.href) attrs["data-native-href"] = this.href
|
|
73
93
|
if (this.click) attrs["data-native-click"] = this.click
|
|
74
|
-
if (
|
|
94
|
+
if (resolved) attrs["data-native-icon"] = resolved
|
|
75
95
|
if (this.selected) attrs["data-native-selected"] = ""
|
|
76
96
|
return h("div", attrs)
|
|
77
97
|
}
|
|
@@ -80,12 +100,15 @@ export const NativeMenuItem = defineComponent({
|
|
|
80
100
|
export const NativeFab = defineComponent({
|
|
81
101
|
name: "NativeFab",
|
|
82
102
|
props: {
|
|
83
|
-
icon:
|
|
103
|
+
icon: String,
|
|
104
|
+
icons: Object,
|
|
84
105
|
href: String,
|
|
85
106
|
click: String
|
|
86
107
|
},
|
|
87
108
|
render() {
|
|
88
|
-
const
|
|
109
|
+
const resolved = resolveIcon(this.icon, this.icons)
|
|
110
|
+
if (!resolved) throw new Error("NativeFab requires `icon` or `icons`")
|
|
111
|
+
const attrs = { "data-native-fab": true, "data-native-icon": resolved, hidden: true }
|
|
89
112
|
if (this.href) attrs["data-native-href"] = this.href
|
|
90
113
|
if (this.click) attrs["data-native-click"] = this.click
|
|
91
114
|
return h("div", attrs)
|