@ruby-native/react 0.13.0 → 0.14.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
@@ -41,6 +41,7 @@ Each component renders a hidden `data-native-*` signal element that the Ruby Nat
41
41
  - `NativeNavbar` - native navigation bar with title and buttons
42
42
  - `NativeButton` - native nav bar button (icon, title, href, or click target)
43
43
  - `NativeMenuItem` - item inside a native menu
44
+ - `NativeMenu` - native menu attached to any element on the page via a CSS selector
44
45
  - `NativeSegment` - segmented button in the nav bar (iOS only)
45
46
  - `NativeShareButton` - native nav bar button that opens the share sheet
46
47
  - `NativeShareMenuItem` - menu item that opens the share sheet
package/index.d.ts CHANGED
@@ -112,18 +112,36 @@ export function NativeButton({ position, icon, icons, title, href, click, select
112
112
  * @param {string} [props.icon]
113
113
  * @param {NativeIcons} [props.icons]
114
114
  * @param {boolean} [props.selected]
115
+ * @param {boolean} [props.destructive] Renders red, for destructive actions.
115
116
  * @param {NativeAction} [props.action]
116
117
  * @returns {import("react").ReactElement}
117
118
  */
118
- export function NativeMenuItem({ title, href, click, icon, icons, selected, action }: {
119
+ export function NativeMenuItem({ title, href, click, icon, icons, selected, destructive, action }: {
119
120
  title?: string | undefined;
120
121
  href?: string | undefined;
121
122
  click?: string | undefined;
122
123
  icon?: string | undefined;
123
124
  icons?: NativeIcons | undefined;
124
125
  selected?: boolean | undefined;
126
+ destructive?: boolean | undefined;
125
127
  action?: NativeAction | undefined;
126
128
  }): import("react").ReactElement;
129
+ /**
130
+ * Attaches a native menu to an element already on the page. `anchor` is a CSS
131
+ * selector for that element; tapping it in the app opens a native menu
132
+ * anchored to it with the `NativeMenuItem` children, and picking one navigates
133
+ * or clicks a web element exactly like a nav bar menu item does. The anchor
134
+ * element stays an ordinary element on the web, so give it its own web
135
+ * behavior there. The counterpart of the `native_menu_tag` Rails helper.
136
+ * @param {object} props
137
+ * @param {string} props.anchor
138
+ * @param {import("react").ReactNode} [props.children]
139
+ * @returns {import("react").ReactElement}
140
+ */
141
+ export function NativeMenu({ anchor, children }: {
142
+ anchor: string;
143
+ children?: import("react").ReactNode;
144
+ }): import("react").ReactElement;
127
145
  /**
128
146
  * A segmented button in the nav bar. Render the same set on each sibling page
129
147
  * and mark the current one `selected`. iOS only.
@@ -178,13 +196,15 @@ export function NativeShareMenuItem({ title, url, icon, icons, selected }: {
178
196
  * @param {NativeIcons} [props.icons]
179
197
  * @param {string} [props.href]
180
198
  * @param {string} [props.click]
199
+ * @param {string} [props.color]
181
200
  * @returns {import("react").ReactElement}
182
201
  */
183
- export function NativeFab({ icon, icons, href, click }: {
202
+ export function NativeFab({ icon, icons, href, click, color }: {
184
203
  icon?: string | undefined;
185
204
  icons?: NativeIcons | undefined;
186
205
  href?: string | undefined;
187
206
  click?: string | undefined;
207
+ color?: string | undefined;
188
208
  }): import("react").ReactElement;
189
209
  /**
190
210
  * @param {object} props
package/index.js CHANGED
@@ -209,10 +209,11 @@ export function NativeButton({ position = "trailing", icon, icons, title, href,
209
209
  * @param {string} [props.icon]
210
210
  * @param {NativeIcons} [props.icons]
211
211
  * @param {boolean} [props.selected]
212
+ * @param {boolean} [props.destructive] Renders red, for destructive actions.
212
213
  * @param {NativeAction} [props.action]
213
214
  * @returns {import("react").ReactElement}
214
215
  */
215
- export function NativeMenuItem({ title, href, click, icon, icons, selected, action }) {
216
+ export function NativeMenuItem({ title, href, click, icon, icons, selected, destructive, action }) {
216
217
  const resolved = resolveIcon(icon, icons)
217
218
  /** @type {Record<string, any>} */
218
219
  const props = { "data-native-menu-item": true }
@@ -221,10 +222,28 @@ export function NativeMenuItem({ title, href, click, icon, icons, selected, acti
221
222
  if (click) props["data-native-click"] = click
222
223
  if (resolved) props["data-native-icon"] = resolved
223
224
  if (selected) props["data-native-selected"] = ""
225
+ if (destructive) props["data-native-destructive"] = ""
224
226
  if (action) props["data-native-action"] = action
225
227
  return createElement("div", props)
226
228
  }
227
229
 
230
+ /**
231
+ * Attaches a native menu to an element already on the page. `anchor` is a CSS
232
+ * selector for that element; tapping it in the app opens a native menu
233
+ * anchored to it with the `NativeMenuItem` children, and picking one navigates
234
+ * or clicks a web element exactly like a nav bar menu item does. The anchor
235
+ * element stays an ordinary element on the web, so give it its own web
236
+ * behavior there. The counterpart of the `native_menu_tag` Rails helper.
237
+ * @param {object} props
238
+ * @param {string} props.anchor
239
+ * @param {import("react").ReactNode} [props.children]
240
+ * @returns {import("react").ReactElement}
241
+ */
242
+ export function NativeMenu({ anchor, children }) {
243
+ if (!anchor || !anchor.trim()) throw new Error("NativeMenu requires an `anchor` CSS selector")
244
+ return createElement("div", { "data-native-menu": "", "data-native-anchor": anchor, hidden: true }, children)
245
+ }
246
+
228
247
  /**
229
248
  * A segmented button in the nav bar. Render the same set on each sibling page
230
249
  * and mark the current one `selected`. iOS only.
@@ -290,15 +309,17 @@ export function NativeShareMenuItem({ title = "Share", url, icon = "square.and.a
290
309
  * @param {NativeIcons} [props.icons]
291
310
  * @param {string} [props.href]
292
311
  * @param {string} [props.click]
312
+ * @param {string} [props.color]
293
313
  * @returns {import("react").ReactElement}
294
314
  */
295
- export function NativeFab({ icon, icons, href, click }) {
315
+ export function NativeFab({ icon, icons, href, click, color }) {
296
316
  const resolved = resolveIcon(icon, icons)
297
317
  if (!resolved) throw new Error("NativeFab requires `icon` or `icons`")
298
318
  /** @type {Record<string, any>} */
299
319
  const props = { "data-native-fab": true, "data-native-icon": resolved, hidden: true }
300
320
  if (href) props["data-native-href"] = href
301
321
  if (click) props["data-native-click"] = click
322
+ if (color) props["data-native-color"] = color
302
323
  return createElement("div", props)
303
324
  }
304
325
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ruby-native/react",
3
- "version": "0.13.0",
3
+ "version": "0.14.2",
4
4
  "description": "React components for Ruby Native",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",