@ruby-native/react 0.12.0 → 0.12.4
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 +1 -0
- package/index.d.ts +19 -0
- package/index.js +33 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ Each component renders a hidden `data-native-*` signal element that the Ruby Nat
|
|
|
37
37
|
- `NativeForm` - mark the current page as a form so back navigation skips it
|
|
38
38
|
- `NativePresentation` - declare that this page lands as a root, with no back button
|
|
39
39
|
- `NativeReview` - ask for an App Store review prompt when the page loads
|
|
40
|
+
- `NativeToast` - show a transient native toast above all app chrome
|
|
40
41
|
- `NativeNavbar` - native navigation bar with title and buttons
|
|
41
42
|
- `NativeButton` - native nav bar button (icon, title, href, or click target)
|
|
42
43
|
- `NativeMenuItem` - item inside a native menu
|
package/index.d.ts
CHANGED
|
@@ -51,6 +51,25 @@ export function NativePresentation({ intent }?: {
|
|
|
51
51
|
* @returns {import("react").ReactElement}
|
|
52
52
|
*/
|
|
53
53
|
export function NativeReview(): import("react").ReactElement;
|
|
54
|
+
/**
|
|
55
|
+
* A transient native toast shown above all app chrome. The signal is consumed
|
|
56
|
+
* the moment it fires, so a restored page cannot re-toast. Renders nothing
|
|
57
|
+
* visible on the web. The counterpart of the `native_toast_tag` Rails helper.
|
|
58
|
+
* @param {object} props
|
|
59
|
+
* @param {string} [props.message] Nothing renders when blank.
|
|
60
|
+
* @param {string | false} [props.icon] `false` hides the default checkmark.
|
|
61
|
+
* @param {NativeIcons} [props.icons]
|
|
62
|
+
* @param {number} [props.duration]
|
|
63
|
+
* @param {"inverted" | "system"} [props.appearance]
|
|
64
|
+
* @returns {import("react").ReactElement | null}
|
|
65
|
+
*/
|
|
66
|
+
export function NativeToast({ message, icon, icons, duration, appearance }: {
|
|
67
|
+
message?: string | undefined;
|
|
68
|
+
icon?: string | false | undefined;
|
|
69
|
+
icons?: NativeIcons | undefined;
|
|
70
|
+
duration?: number | undefined;
|
|
71
|
+
appearance?: "inverted" | "system" | undefined;
|
|
72
|
+
}): import("react").ReactElement | null;
|
|
54
73
|
/**
|
|
55
74
|
* @param {object} props
|
|
56
75
|
* @param {string} [props.title]
|
package/index.js
CHANGED
|
@@ -129,6 +129,39 @@ export function NativeReview() {
|
|
|
129
129
|
return createElement("div", { "data-native-review": true, hidden: true })
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
+
/**
|
|
133
|
+
* A transient native toast shown above all app chrome. The signal is consumed
|
|
134
|
+
* the moment it fires, so a restored page cannot re-toast. Renders nothing
|
|
135
|
+
* visible on the web. The counterpart of the `native_toast_tag` Rails helper.
|
|
136
|
+
* @param {object} props
|
|
137
|
+
* @param {string} [props.message] Nothing renders when blank.
|
|
138
|
+
* @param {string | false} [props.icon] `false` hides the default checkmark.
|
|
139
|
+
* @param {NativeIcons} [props.icons]
|
|
140
|
+
* @param {number} [props.duration]
|
|
141
|
+
* @param {"inverted" | "system"} [props.appearance]
|
|
142
|
+
* @returns {import("react").ReactElement | null}
|
|
143
|
+
*/
|
|
144
|
+
export function NativeToast({ message, icon, icons, duration = 4, appearance = "inverted" }) {
|
|
145
|
+
if (!message) return null
|
|
146
|
+
/** @type {Record<string, any>} */
|
|
147
|
+
const props = {
|
|
148
|
+
"data-native-toast": "",
|
|
149
|
+
"data-native-toast-message": message,
|
|
150
|
+
"data-native-toast-duration": duration,
|
|
151
|
+
"data-native-toast-appearance": appearance,
|
|
152
|
+
hidden: true
|
|
153
|
+
}
|
|
154
|
+
// An absent icon attribute means "use the default" to the shell (the JS API
|
|
155
|
+
// omits it), so `icon={false}` emits an empty value to mean "none".
|
|
156
|
+
if (icon === false) {
|
|
157
|
+
props["data-native-toast-icon"] = ""
|
|
158
|
+
} else {
|
|
159
|
+
const fallback = rubyNativePlatform() === "android" ? "check_circle" : "checkmark.circle.fill"
|
|
160
|
+
props["data-native-toast-icon"] = resolveIcon(icon, icons) || fallback
|
|
161
|
+
}
|
|
162
|
+
return createElement("div", props)
|
|
163
|
+
}
|
|
164
|
+
|
|
132
165
|
/**
|
|
133
166
|
* @param {object} props
|
|
134
167
|
* @param {string} [props.title]
|