@plexui/react-native 0.2.2 → 0.2.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.
@@ -330,6 +330,8 @@ export type ListItemProps = {
330
330
  /** The chevron of a row that opens a page. @default true when the row has `onPress`, no `trailing` and is not `destructive` */
331
331
  disclosure?: boolean
332
332
  onPress?: () => void
333
+ /** A touch and hold on the row (half a second): a ContextMenu around the row sets it. */
334
+ onLongPress?: () => void
333
335
  disabled?: boolean
334
336
  /** A row in red, as a destructive action row. */
335
337
  destructive?: boolean
@@ -363,6 +365,7 @@ export function ListItem({
363
365
  onCheckedChange,
364
366
  disclosure,
365
367
  onPress,
368
+ onLongPress,
366
369
  disabled = false,
367
370
  destructive = false,
368
371
  accessibilityLabel,
@@ -452,7 +455,7 @@ export function ListItem({
452
455
  </RowFrameContext.Provider>
453
456
  )
454
457
  }
455
- if (press) {
458
+ if (press || onLongPress) {
456
459
  // Android's rows press in the list selector: the native ripple on a device, the drawn one on the web
457
460
  const highlight = controlHighlight(theme.scheme)
458
461
  const drawn = theme.isAndroid && !nativeRipple
@@ -472,6 +475,10 @@ export function ListItem({
472
475
  aria-checked={switchRow ? checked : undefined}
473
476
  disabled={disabled}
474
477
  onPress={press}
478
+ onLongPress={onLongPress}
479
+ delayLongPress={onLongPress ? 500 : undefined}
480
+ accessibilityActions={onLongPress ? [{ name: "longpress" }] : undefined}
481
+ onAccessibilityAction={onLongPress ? (event) => event.nativeEvent.actionName === "longpress" && onLongPress() : undefined}
475
482
  onPressIn={drawn ? ripple.start : undefined}
476
483
  onPressOut={drawn ? ripple.end : undefined}
477
484
  android_ripple={nativeRipple ? { color: highlight, foreground: true } : undefined}
@@ -199,7 +199,7 @@ function MenuContent(props: MenuContentProps) {
199
199
  return <MenuSurface {...props} check={hasCheckedItems(props.children)} open={menu.open} anchor={menu.anchor} row={menu.row} header={menu.header} onClose={() => menu.setOpen(false)} />
200
200
  }
201
201
 
202
- function hasCheckedItems(children: ReactNode): boolean {
202
+ export function hasCheckedItems(children: ReactNode): boolean {
203
203
  return Children.toArray(children).some((child) =>
204
204
  isValidElement<{ checked?: boolean; children?: ReactNode }>(child) ? child.props.checked !== undefined || (child.type === Fragment && hasCheckedItems(child.props.children)) : false,
205
205
  )
@@ -219,6 +219,11 @@ type SurfaceProps = MenuContentProps & {
219
219
  row?: MenuRow | null
220
220
  /** Opened from a bar's button: on Android the header menu, in the bar's glass. */
221
221
  header?: boolean
222
+ /**
223
+ * A context menu's touch and hold (ContextMenu): on iOS the screen dims and blurs but the element, drawn again
224
+ * over the dimming as its lifted `preview`, and the menu stands 16 from it, by the third of the screen it is in.
225
+ */
226
+ context?: { preview: ReactNode; radius: number }
222
227
  }
223
228
 
224
229
  /** The floating panel of a menu, placed under its anchor (over it when the screen ends first). */
@@ -228,7 +233,7 @@ export function MenuSurface(props: SurfaceProps) {
228
233
  }
229
234
 
230
235
  /** iOS 26's pop-up menu: glass, a submenu over the menu at its row while the menu steps back. */
231
- function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check = false, multiple = false, cover, children, "aria-label": ariaLabel, testID }: SurfaceProps) {
236
+ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check = false, multiple = false, cover, context, children, "aria-label": ariaLabel, testID }: SurfaceProps) {
232
237
  const theme = useTheme()
233
238
  const insets = useSafeAreaInsets()
234
239
  const window = useWindowDimensions()
@@ -269,9 +274,33 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
269
274
  const below = over ? box.y : box.y + box.height + gap
270
275
  const fitsBelow = below + height <= window.height - bottomEdge
271
276
  const above = over ? box.y + box.height - height : box.y - gap - height
272
- const top = size == null ? -window.height - 1000 : fitsBelow ? below : Math.max(topEdge, above)
277
+ let top = size == null ? -window.height - 1000 : fitsBelow ? below : Math.max(topEdge, above)
278
+ let previewTop = box.y
279
+ if (context) {
280
+ // iOS 27.2 places a context menu by where the element stands (ref-app menus-context): in the left third at its
281
+ // left edge, in the right third at its right edge, else at its centre; 16 under it, or over it when the element
282
+ // is in the lower half and the menu fits there (the web's ContextMenu, contextMenuPreview)
283
+ const centre = box.x + box.width / 2
284
+ left = centre < window.width / 3 ? box.x : centre > (window.width * 2) / 3 ? box.x + box.width - measured : centre - measured / 2
285
+ left = Math.max(margin, Math.min(left, window.width - measured - margin))
286
+ const lift = 16
287
+ const overIt = box.y - lift - height
288
+ const underIt = box.y + box.height + lift
289
+ const lower = box.y + box.height / 2 > window.height / 2
290
+ if (size != null) {
291
+ if (lower && overIt >= topEdge) top = overIt
292
+ else {
293
+ // Where the menu does not fit under the element it lifts the element up with it, as iOS moves the preview, so
294
+ // the menu never covers it
295
+ const overflow = underIt + height - (window.height - bottomEdge)
296
+ previewTop = overflow > 0 ? Math.max(topEdge, box.y - overflow) : box.y
297
+ top = Math.max(topEdge, Math.min(previewTop + box.height + lift, window.height - bottomEdge - height))
298
+ }
299
+ }
300
+ }
273
301
  // The measures are from the screen's left; a phone in a right-to-left layout reads `left` as the start edge
274
- const horizontal = Platform.OS !== "web" && I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL ? { right: left } : { left }
302
+ const swap = Platform.OS !== "web" && I18nManager.isRTL && I18nManager.doLeftAndRightSwapInRTL
303
+ const horizontal = swap ? { right: left } : { left }
275
304
  const maxHeight = window.height - topEdge - bottomEdge
276
305
  const timing = overlayTiming(theme, "menu")
277
306
  const moveTo = (value: Animated.Value, to: number, enter: boolean, done?: () => void) => {
@@ -347,6 +376,36 @@ function IOSMenuSurface({ open, anchor, onClose, align = "start", width, check =
347
376
  <Overlay open={open} onDismiss={onClose} motion="menu" testID={testID}>
348
377
  {(progress, opening) => (
349
378
  <>
379
+ {context ? (
380
+ <>
381
+ {/* The page dims (black at 20%, 50% at night) over a 30px blur on the web; the element stays clear */}
382
+ <Animated.View
383
+ pointerEvents="none"
384
+ style={[
385
+ StyleSheet.absoluteFill,
386
+ { backgroundColor: theme.color("--context-menu-dimming-background", theme.scheme === "dark" ? "rgba(0, 0, 0, 0.5)" : "rgba(0, 0, 0, 0.2)"), opacity: progress },
387
+ web ? ({ backdropFilter: "blur(30px)", WebkitBackdropFilter: "blur(30px)" } as ViewStyle) : null,
388
+ ]}
389
+ />
390
+ <View
391
+ pointerEvents="none"
392
+ style={[
393
+ styles.preview,
394
+ swap ? { right: box.x } : { left: box.x },
395
+ {
396
+ top: previewTop,
397
+ width: box.width,
398
+ height: box.height,
399
+ borderRadius: context.radius,
400
+ backgroundColor: theme.colors.groupedSurface,
401
+ boxShadow: String(theme.token("--context-menu-preview-shadow") ?? "0 0 32px rgba(0, 0, 0, 0.2)"),
402
+ },
403
+ ]}
404
+ >
405
+ {context.preview}
406
+ </View>
407
+ </>
408
+ ) : null}
350
409
  <Animated.View
351
410
  ref={panel as never}
352
411
  // The panel takes the focus of a menu opened by a pointer (the web), with no ring of its own
@@ -996,7 +1055,7 @@ type RowExtras = {
996
1055
  rowRef?: { current: unknown }
997
1056
  }
998
1057
 
999
- function MenuItem(props: MenuItemProps) {
1058
+ export function MenuItem(props: MenuItemProps) {
1000
1059
  return <MenuRow {...props} />
1001
1060
  }
1002
1061
  MenuItem.displayName = "Menu.Item"
@@ -1216,7 +1275,7 @@ MenuSubTrigger.displayName = "Menu.SubTrigger"
1216
1275
  const MenuSubContent: ((props: MenuSubContentProps) => null) & { displayName?: string } = () => null
1217
1276
  MenuSubContent.displayName = "Menu.SubContent"
1218
1277
 
1219
- function MenuSeparator() {
1278
+ export function MenuSeparator() {
1220
1279
  const theme = useTheme()
1221
1280
  const surface = useContext(SurfaceContext)
1222
1281
  // Android parts a popup's groups with an 8dp band: a light gray (#F5F5F5, #262626 at night) in a row's menu, the text
@@ -1245,7 +1304,7 @@ function MenuSeparator() {
1245
1304
  MenuSeparator.displayName = "Menu.Separator"
1246
1305
 
1247
1306
  /** A heading over a group of items. */
1248
- function MenuLabel({ children }: { children: ReactNode }) {
1307
+ export function MenuLabel({ children }: { children: ReactNode }) {
1249
1308
  const theme = useTheme()
1250
1309
  const surface = useContext(SurfaceContext)
1251
1310
  if (theme.isAndroid) {
@@ -1295,6 +1354,7 @@ export const Menu = Object.assign(MenuRoot, {
1295
1354
  })
1296
1355
 
1297
1356
  const styles = StyleSheet.create({
1357
+ preview: { position: "absolute", overflow: "hidden" },
1298
1358
  trigger: { alignSelf: "flex-start" },
1299
1359
  surface: { position: "absolute", outlineWidth: 0, outlineStyle: "none" as "solid" },
1300
1360
  shrink: { flexShrink: 1 },
@@ -201,6 +201,54 @@ function ToolbarGroup({ children, style, ...rest }: ViewProps) {
201
201
  }
202
202
  ToolbarGroup.displayName = "Toolbar.Group"
203
203
 
204
+ export type ToolbarLabelProps = ViewProps & {
205
+ /** The text: a step of a flow ("3 of 10"), a count, a status. Its digits keep one width as it changes. */
206
+ children: ReactNode
207
+ }
208
+
209
+ /**
210
+ * A text in the bar that is not a button: a step of a flow, a count, a status. On iOS it stands in a capsule of the
211
+ * bar's glass as a button would, as SwiftUI draws a Text in a toolbar (iOS 27.2 ref-app tb-status: 48pt in a bottom bar,
212
+ * 15pt Semibold, 8pt from its ends); on Android it is the bar's plain text, 14sp Medium. Read as text, not a control.
213
+ */
214
+ function ToolbarLabel({ children, style, ...rest }: ToolbarLabelProps) {
215
+ const theme = useTheme()
216
+ const item = useContext(BarItemContext)
217
+ const text = (
218
+ <Text
219
+ weight={theme.isAndroid ? "medium" : "semibold"}
220
+ tabularNums
221
+ numberOfLines={1}
222
+ style={theme.isAndroid ? { fontSize: 14, lineHeight: 20 } : { fontSize: theme.length("--toolbar-status-font-size", 15), lineHeight: theme.length("--toolbar-status-line-height", 20) }}
223
+ >
224
+ {children}
225
+ </Text>
226
+ )
227
+ if (theme.isAndroid || !item || item.inGroup) {
228
+ return (
229
+ <View {...rest} style={[styles.slot, styles.label, item ? { minHeight: item.height, paddingHorizontal: theme.isAndroid ? 8 : 0 } : null, style]}>
230
+ {text}
231
+ </View>
232
+ )
233
+ }
234
+ return (
235
+ <Glass
236
+ {...rest}
237
+ elevation={item.raised ? "raised" : "regular"}
238
+ radius={item.height / 2}
239
+ style={[
240
+ styles.slot,
241
+ styles.label,
242
+ { height: item.height, minWidth: item.height, paddingHorizontal: theme.length("--toolbar-status-padding", 8) },
243
+ style,
244
+ ]}
245
+ >
246
+ {text}
247
+ </Glass>
248
+ )
249
+ }
250
+ ToolbarLabel.displayName = "Toolbar.Label"
251
+
204
252
  export type ToolbarTitleProps = {
205
253
  /** The title's text. With `image` it may be left out. */
206
254
  children?: ReactNode
@@ -682,12 +730,14 @@ export const Toolbar = Object.assign(ToolbarRoot, {
682
730
  Group: ToolbarGroup,
683
731
  Trailing: ToolbarTrailing,
684
732
  Row: ToolbarRow,
733
+ Label: ToolbarLabel,
685
734
  })
686
735
 
687
736
  const styles = StyleSheet.create({
688
737
  titleImage: { flexDirection: "row", alignItems: "center" },
689
738
  slot: { flexDirection: "row", alignItems: "center" },
690
739
  trailing: { justifyContent: "flex-end" },
740
+ label: { justifyContent: "center" },
691
741
  content: { justifyContent: "center" },
692
742
  // A filling content stretches its control across (a search field, a block button), as a column would
693
743
  fill: { flex: 1, flexDirection: "column", alignItems: "stretch" },
package/src/index.ts CHANGED
@@ -80,6 +80,7 @@ export { TagInput, type Tag, type TagInputProps } from "./components/TagInput/Ta
80
80
  export { OTPInput, type OTPInputProps } from "./components/OTPInput/OTPInput"
81
81
  export { Select, type SelectOption, type SelectProps } from "./components/Select/Select"
82
82
  export { Menu, type MenuContentProps, type MenuItemProps, type MenuProps } from "./components/Menu/Menu"
83
+ export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps } from "./components/ContextMenu/ContextMenu"
83
84
  export { ActionSheet, type ActionSheetAction, type ActionSheetProps } from "./components/ActionSheet/ActionSheet"
84
85
  export { BottomSheet, type BottomSheetFooterProps, type BottomSheetProps } from "./components/BottomSheet/BottomSheet"
85
86
  export { Dialog, type DialogAction, type DialogProps } from "./components/Dialog/Dialog"