@ruby-native/react 0.11.1 → 0.12.0
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 +2 -0
- package/index.d.ts +56 -2
- package/index.js +61 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -35,10 +35,12 @@ Each component renders a hidden `data-native-*` signal element that the Ruby Nat
|
|
|
35
35
|
- `NativeTabs` - show the native tab bar
|
|
36
36
|
- `NativePush` - request push notification permission
|
|
37
37
|
- `NativeForm` - mark the current page as a form so back navigation skips it
|
|
38
|
+
- `NativePresentation` - declare that this page lands as a root, with no back button
|
|
38
39
|
- `NativeReview` - ask for an App Store review prompt when the page loads
|
|
39
40
|
- `NativeNavbar` - native navigation bar with title and buttons
|
|
40
41
|
- `NativeButton` - native nav bar button (icon, title, href, or click target)
|
|
41
42
|
- `NativeMenuItem` - item inside a native menu
|
|
43
|
+
- `NativeSegment` - segmented button in the nav bar (iOS only)
|
|
42
44
|
- `NativeShareButton` - native nav bar button that opens the share sheet
|
|
43
45
|
- `NativeShareMenuItem` - menu item that opens the share sheet
|
|
44
46
|
- `NativeSubmitButton` - native "Save" button that submits a form
|
package/index.d.ts
CHANGED
|
@@ -16,10 +16,37 @@ export function NativeTabs({ enabled }: {
|
|
|
16
16
|
* @returns {import("react").ReactElement}
|
|
17
17
|
*/
|
|
18
18
|
export function NativePush(): import("react").ReactElement;
|
|
19
|
+
/**
|
|
20
|
+
* Who is signed in, as an opaque server-computed token (`native_identity_token`
|
|
21
|
+
* shared as an Inertia prop). Render on every page: an empty or missing token
|
|
22
|
+
* means signed out, and the app clears its screens when the value changes.
|
|
23
|
+
* @param {object} props
|
|
24
|
+
* @param {string | null} [props.token]
|
|
25
|
+
* @returns {import("react").ReactElement}
|
|
26
|
+
*/
|
|
27
|
+
export function NativeIdentity({ token }: {
|
|
28
|
+
token?: string | null | undefined;
|
|
29
|
+
}): import("react").ReactElement;
|
|
19
30
|
/**
|
|
20
31
|
* @returns {import("react").ReactElement}
|
|
21
32
|
*/
|
|
22
33
|
export function NativeForm(): import("react").ReactElement;
|
|
34
|
+
/**
|
|
35
|
+
* Declares that this page lands as a root, with nothing behind it and no back
|
|
36
|
+
* affordance.
|
|
37
|
+
*
|
|
38
|
+
* Emits only the element half of `native_presentation_tag`, so Advanced Mode
|
|
39
|
+
* applies it once the page has rendered rather than before the navigation
|
|
40
|
+
* commits. Set the `Native-Presentation` response header from the controller as
|
|
41
|
+
* well to get the earlier path.
|
|
42
|
+
*
|
|
43
|
+
* @param {object} props
|
|
44
|
+
* @param {"root"} [props.intent]
|
|
45
|
+
* @returns {import("react").ReactElement}
|
|
46
|
+
*/
|
|
47
|
+
export function NativePresentation({ intent }?: {
|
|
48
|
+
intent?: "root" | undefined;
|
|
49
|
+
}): import("react").ReactElement;
|
|
23
50
|
/**
|
|
24
51
|
* @returns {import("react").ReactElement}
|
|
25
52
|
*/
|
|
@@ -66,15 +93,33 @@ export function NativeButton({ position, icon, icons, title, href, click, select
|
|
|
66
93
|
* @param {string} [props.icon]
|
|
67
94
|
* @param {NativeIcons} [props.icons]
|
|
68
95
|
* @param {boolean} [props.selected]
|
|
96
|
+
* @param {NativeAction} [props.action]
|
|
69
97
|
* @returns {import("react").ReactElement}
|
|
70
98
|
*/
|
|
71
|
-
export function NativeMenuItem({ title, href, click, icon, icons, selected }: {
|
|
99
|
+
export function NativeMenuItem({ title, href, click, icon, icons, selected, action }: {
|
|
72
100
|
title?: string | undefined;
|
|
73
101
|
href?: string | undefined;
|
|
74
102
|
click?: string | undefined;
|
|
75
103
|
icon?: string | undefined;
|
|
76
104
|
icons?: NativeIcons | undefined;
|
|
77
105
|
selected?: boolean | undefined;
|
|
106
|
+
action?: NativeAction | undefined;
|
|
107
|
+
}): import("react").ReactElement;
|
|
108
|
+
/**
|
|
109
|
+
* A segmented button in the nav bar. Render the same set on each sibling page
|
|
110
|
+
* and mark the current one `selected`. iOS only.
|
|
111
|
+
* @param {object} props
|
|
112
|
+
* @param {string} [props.title]
|
|
113
|
+
* @param {string} [props.href]
|
|
114
|
+
* @param {string} [props.click]
|
|
115
|
+
* @param {boolean} [props.selected]
|
|
116
|
+
* @returns {import("react").ReactElement}
|
|
117
|
+
*/
|
|
118
|
+
export function NativeSegment({ title, href, click, selected }: {
|
|
119
|
+
title?: string | undefined;
|
|
120
|
+
href?: string | undefined;
|
|
121
|
+
click?: string | undefined;
|
|
122
|
+
selected?: boolean | undefined;
|
|
78
123
|
}): import("react").ReactElement;
|
|
79
124
|
/**
|
|
80
125
|
* @param {object} props
|
|
@@ -177,4 +222,13 @@ export type NativeIcons = {
|
|
|
177
222
|
android?: string | undefined;
|
|
178
223
|
};
|
|
179
224
|
export type NativeHapticFeedback = "success" | "warning" | "error" | "impact" | "selection";
|
|
180
|
-
|
|
225
|
+
/**
|
|
226
|
+
* "title" turns the nav-bar title into a dropdown menu. Give the button a
|
|
227
|
+
* `menu` and no icon or label of its own.
|
|
228
|
+
*/
|
|
229
|
+
export type NativeButtonPosition = "leading" | "trailing" | "title";
|
|
230
|
+
/**
|
|
231
|
+
* How a menu item's page lands. "replace" swaps the current history entry,
|
|
232
|
+
* which is what a page switcher wants.
|
|
233
|
+
*/
|
|
234
|
+
export type NativeAction = "push" | "replace";
|
package/index.js
CHANGED
|
@@ -14,7 +14,15 @@ import("@inertiajs/react").then(m => { window.__inertiaRouter = m.router }).catc
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* "title" turns the nav-bar title into a dropdown menu. Give the button a
|
|
18
|
+
* `menu` and no icon or label of its own.
|
|
19
|
+
* @typedef {"leading" | "trailing" | "title"} NativeButtonPosition
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* How a menu item's page lands. "replace" swaps the current history entry,
|
|
24
|
+
* which is what a page switcher wants.
|
|
25
|
+
* @typedef {"push" | "replace"} NativeAction
|
|
18
26
|
*/
|
|
19
27
|
|
|
20
28
|
function rubyNativePlatform() {
|
|
@@ -78,6 +86,18 @@ export function NativePush() {
|
|
|
78
86
|
return createElement("div", { "data-native-push": true, hidden: true })
|
|
79
87
|
}
|
|
80
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Who is signed in, as an opaque server-computed token (`native_identity_token`
|
|
91
|
+
* shared as an Inertia prop). Render on every page: an empty or missing token
|
|
92
|
+
* means signed out, and the app clears its screens when the value changes.
|
|
93
|
+
* @param {object} props
|
|
94
|
+
* @param {string | null} [props.token]
|
|
95
|
+
* @returns {import("react").ReactElement}
|
|
96
|
+
*/
|
|
97
|
+
export function NativeIdentity({ token }) {
|
|
98
|
+
return createElement("div", { "data-native-identity": token ?? "", hidden: true })
|
|
99
|
+
}
|
|
100
|
+
|
|
81
101
|
/**
|
|
82
102
|
* @returns {import("react").ReactElement}
|
|
83
103
|
*/
|
|
@@ -85,6 +105,23 @@ export function NativeForm() {
|
|
|
85
105
|
return createElement("div", { "data-native-form": true, hidden: true })
|
|
86
106
|
}
|
|
87
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Declares that this page lands as a root, with nothing behind it and no back
|
|
110
|
+
* affordance.
|
|
111
|
+
*
|
|
112
|
+
* Emits only the element half of `native_presentation_tag`, so Advanced Mode
|
|
113
|
+
* applies it once the page has rendered rather than before the navigation
|
|
114
|
+
* commits. Set the `Native-Presentation` response header from the controller as
|
|
115
|
+
* well to get the earlier path.
|
|
116
|
+
*
|
|
117
|
+
* @param {object} props
|
|
118
|
+
* @param {"root"} [props.intent]
|
|
119
|
+
* @returns {import("react").ReactElement}
|
|
120
|
+
*/
|
|
121
|
+
export function NativePresentation({ intent = "root" } = {}) {
|
|
122
|
+
return createElement("div", { "data-native-presentation": intent, hidden: true })
|
|
123
|
+
}
|
|
124
|
+
|
|
88
125
|
/**
|
|
89
126
|
* @returns {import("react").ReactElement}
|
|
90
127
|
*/
|
|
@@ -139,9 +176,10 @@ export function NativeButton({ position = "trailing", icon, icons, title, href,
|
|
|
139
176
|
* @param {string} [props.icon]
|
|
140
177
|
* @param {NativeIcons} [props.icons]
|
|
141
178
|
* @param {boolean} [props.selected]
|
|
179
|
+
* @param {NativeAction} [props.action]
|
|
142
180
|
* @returns {import("react").ReactElement}
|
|
143
181
|
*/
|
|
144
|
-
export function NativeMenuItem({ title, href, click, icon, icons, selected }) {
|
|
182
|
+
export function NativeMenuItem({ title, href, click, icon, icons, selected, action }) {
|
|
145
183
|
const resolved = resolveIcon(icon, icons)
|
|
146
184
|
/** @type {Record<string, any>} */
|
|
147
185
|
const props = { "data-native-menu-item": true }
|
|
@@ -150,6 +188,27 @@ export function NativeMenuItem({ title, href, click, icon, icons, selected }) {
|
|
|
150
188
|
if (click) props["data-native-click"] = click
|
|
151
189
|
if (resolved) props["data-native-icon"] = resolved
|
|
152
190
|
if (selected) props["data-native-selected"] = ""
|
|
191
|
+
if (action) props["data-native-action"] = action
|
|
192
|
+
return createElement("div", props)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* A segmented button in the nav bar. Render the same set on each sibling page
|
|
197
|
+
* and mark the current one `selected`. iOS only.
|
|
198
|
+
* @param {object} props
|
|
199
|
+
* @param {string} [props.title]
|
|
200
|
+
* @param {string} [props.href]
|
|
201
|
+
* @param {string} [props.click]
|
|
202
|
+
* @param {boolean} [props.selected]
|
|
203
|
+
* @returns {import("react").ReactElement}
|
|
204
|
+
*/
|
|
205
|
+
export function NativeSegment({ title, href, click, selected }) {
|
|
206
|
+
/** @type {Record<string, any>} */
|
|
207
|
+
const props = { "data-native-segment": "" }
|
|
208
|
+
if (title) props["data-native-title"] = title
|
|
209
|
+
if (href) props["data-native-href"] = href
|
|
210
|
+
if (click) props["data-native-click"] = click
|
|
211
|
+
if (selected) props["data-native-selected"] = ""
|
|
153
212
|
return createElement("div", props)
|
|
154
213
|
}
|
|
155
214
|
|