@ruby-native/react 0.11.1 → 0.11.2

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
@@ -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
@@ -20,6 +20,22 @@ export function NativePush(): import("react").ReactElement;
20
20
  * @returns {import("react").ReactElement}
21
21
  */
22
22
  export function NativeForm(): import("react").ReactElement;
23
+ /**
24
+ * Declares that this page lands as a root, with nothing behind it and no back
25
+ * affordance.
26
+ *
27
+ * Emits only the element half of `native_presentation_tag`, so Advanced Mode
28
+ * applies it once the page has rendered rather than before the navigation
29
+ * commits. Set the `Native-Presentation` response header from the controller as
30
+ * well to get the earlier path.
31
+ *
32
+ * @param {object} props
33
+ * @param {"root"} [props.intent]
34
+ * @returns {import("react").ReactElement}
35
+ */
36
+ export function NativePresentation({ intent }?: {
37
+ intent?: "root" | undefined;
38
+ }): import("react").ReactElement;
23
39
  /**
24
40
  * @returns {import("react").ReactElement}
25
41
  */
@@ -66,15 +82,33 @@ export function NativeButton({ position, icon, icons, title, href, click, select
66
82
  * @param {string} [props.icon]
67
83
  * @param {NativeIcons} [props.icons]
68
84
  * @param {boolean} [props.selected]
85
+ * @param {NativeAction} [props.action]
69
86
  * @returns {import("react").ReactElement}
70
87
  */
71
- export function NativeMenuItem({ title, href, click, icon, icons, selected }: {
88
+ export function NativeMenuItem({ title, href, click, icon, icons, selected, action }: {
72
89
  title?: string | undefined;
73
90
  href?: string | undefined;
74
91
  click?: string | undefined;
75
92
  icon?: string | undefined;
76
93
  icons?: NativeIcons | undefined;
77
94
  selected?: boolean | undefined;
95
+ action?: NativeAction | undefined;
96
+ }): import("react").ReactElement;
97
+ /**
98
+ * A segmented button in the nav bar. Render the same set on each sibling page
99
+ * and mark the current one `selected`. iOS only.
100
+ * @param {object} props
101
+ * @param {string} [props.title]
102
+ * @param {string} [props.href]
103
+ * @param {string} [props.click]
104
+ * @param {boolean} [props.selected]
105
+ * @returns {import("react").ReactElement}
106
+ */
107
+ export function NativeSegment({ title, href, click, selected }: {
108
+ title?: string | undefined;
109
+ href?: string | undefined;
110
+ click?: string | undefined;
111
+ selected?: boolean | undefined;
78
112
  }): import("react").ReactElement;
79
113
  /**
80
114
  * @param {object} props
@@ -177,4 +211,13 @@ export type NativeIcons = {
177
211
  android?: string | undefined;
178
212
  };
179
213
  export type NativeHapticFeedback = "success" | "warning" | "error" | "impact" | "selection";
180
- export type NativeButtonPosition = "leading" | "trailing";
214
+ /**
215
+ * "title" turns the nav-bar title into a dropdown menu. Give the button a
216
+ * `menu` and no icon or label of its own.
217
+ */
218
+ export type NativeButtonPosition = "leading" | "trailing" | "title";
219
+ /**
220
+ * How a menu item's page lands. "replace" swaps the current history entry,
221
+ * which is what a page switcher wants.
222
+ */
223
+ 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
- * @typedef {"leading" | "trailing"} NativeButtonPosition
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() {
@@ -85,6 +93,23 @@ export function NativeForm() {
85
93
  return createElement("div", { "data-native-form": true, hidden: true })
86
94
  }
87
95
 
96
+ /**
97
+ * Declares that this page lands as a root, with nothing behind it and no back
98
+ * affordance.
99
+ *
100
+ * Emits only the element half of `native_presentation_tag`, so Advanced Mode
101
+ * applies it once the page has rendered rather than before the navigation
102
+ * commits. Set the `Native-Presentation` response header from the controller as
103
+ * well to get the earlier path.
104
+ *
105
+ * @param {object} props
106
+ * @param {"root"} [props.intent]
107
+ * @returns {import("react").ReactElement}
108
+ */
109
+ export function NativePresentation({ intent = "root" } = {}) {
110
+ return createElement("div", { "data-native-presentation": intent, hidden: true })
111
+ }
112
+
88
113
  /**
89
114
  * @returns {import("react").ReactElement}
90
115
  */
@@ -139,9 +164,10 @@ export function NativeButton({ position = "trailing", icon, icons, title, href,
139
164
  * @param {string} [props.icon]
140
165
  * @param {NativeIcons} [props.icons]
141
166
  * @param {boolean} [props.selected]
167
+ * @param {NativeAction} [props.action]
142
168
  * @returns {import("react").ReactElement}
143
169
  */
144
- export function NativeMenuItem({ title, href, click, icon, icons, selected }) {
170
+ export function NativeMenuItem({ title, href, click, icon, icons, selected, action }) {
145
171
  const resolved = resolveIcon(icon, icons)
146
172
  /** @type {Record<string, any>} */
147
173
  const props = { "data-native-menu-item": true }
@@ -150,6 +176,27 @@ export function NativeMenuItem({ title, href, click, icon, icons, selected }) {
150
176
  if (click) props["data-native-click"] = click
151
177
  if (resolved) props["data-native-icon"] = resolved
152
178
  if (selected) props["data-native-selected"] = ""
179
+ if (action) props["data-native-action"] = action
180
+ return createElement("div", props)
181
+ }
182
+
183
+ /**
184
+ * A segmented button in the nav bar. Render the same set on each sibling page
185
+ * and mark the current one `selected`. iOS only.
186
+ * @param {object} props
187
+ * @param {string} [props.title]
188
+ * @param {string} [props.href]
189
+ * @param {string} [props.click]
190
+ * @param {boolean} [props.selected]
191
+ * @returns {import("react").ReactElement}
192
+ */
193
+ export function NativeSegment({ title, href, click, selected }) {
194
+ /** @type {Record<string, any>} */
195
+ const props = { "data-native-segment": "" }
196
+ if (title) props["data-native-title"] = title
197
+ if (href) props["data-native-href"] = href
198
+ if (click) props["data-native-click"] = click
199
+ if (selected) props["data-native-selected"] = ""
153
200
  return createElement("div", props)
154
201
  }
155
202
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruby-native/react",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
4
4
  "description": "React components for Ruby Native",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",