@plexui/react-native 0.2.3 → 0.2.5

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.
Files changed (34) hide show
  1. package/dist/es/components/ContextMenu/ContextMenu.js +128 -0
  2. package/dist/es/components/DatePicker/Calendar.js +112 -0
  3. package/dist/es/components/DatePicker/DatePicker.js +335 -0
  4. package/dist/es/components/DatePicker/TimeDial.js +123 -0
  5. package/dist/es/components/DatePicker/Wheel.js +164 -0
  6. package/dist/es/components/DatePicker/dates.js +147 -0
  7. package/dist/es/components/Dialog/Dialog.js +21 -0
  8. package/dist/es/components/Icon/material.js +16 -0
  9. package/dist/es/components/List/List.js +3 -3
  10. package/dist/es/components/Menu/Menu.js +50 -9
  11. package/dist/es/index.js +2 -0
  12. package/dist/types/components/ContextMenu/ContextMenu.d.ts +57 -0
  13. package/dist/types/components/DatePicker/Calendar.d.ts +29 -0
  14. package/dist/types/components/DatePicker/DatePicker.d.ts +57 -0
  15. package/dist/types/components/DatePicker/TimeDial.d.ts +20 -0
  16. package/dist/types/components/DatePicker/Wheel.d.ts +40 -0
  17. package/dist/types/components/DatePicker/dates.d.ts +45 -0
  18. package/dist/types/components/Dialog/Dialog.d.ts +18 -0
  19. package/dist/types/components/Icon/material.d.ts +6 -0
  20. package/dist/types/components/List/List.d.ts +3 -1
  21. package/dist/types/components/Menu/Menu.d.ts +15 -6
  22. package/dist/types/index.d.ts +2 -0
  23. package/package.json +1 -1
  24. package/src/components/ContextMenu/ContextMenu.tsx +164 -0
  25. package/src/components/DatePicker/Calendar.tsx +227 -0
  26. package/src/components/DatePicker/DatePicker.tsx +608 -0
  27. package/src/components/DatePicker/TimeDial.tsx +201 -0
  28. package/src/components/DatePicker/Wheel.tsx +247 -0
  29. package/src/components/DatePicker/dates.ts +161 -0
  30. package/src/components/Dialog/Dialog.tsx +46 -0
  31. package/src/components/Icon/material.ts +18 -0
  32. package/src/components/List/List.tsx +8 -1
  33. package/src/components/Menu/Menu.tsx +67 -7
  34. package/src/index.ts +2 -0
@@ -0,0 +1,57 @@
1
+ import { type ReactElement, type ReactNode } from "react";
2
+ import { type AccessibilityActionEvent, type StyleProp, type ViewStyle } from "react-native";
3
+ import { type MenuContentProps } from "../Menu/Menu";
4
+ /** A touch and hold opens the menu after half a second, as the web's ContextMenu (CONTEXT_MENU_LONG_PRESS). */
5
+ export declare const CONTEXT_MENU_LONG_PRESS = 500;
6
+ export type ContextMenuProps = {
7
+ children: ReactNode;
8
+ /** Holds the menu open or closed. */
9
+ open?: boolean;
10
+ onOpenChange?: (open: boolean) => void;
11
+ };
12
+ /**
13
+ * A menu of actions for an element, opened by a touch and hold (and a right click on the web): on iOS 27 the screen
14
+ * dims and blurs, the element stays clear over it as a lifted preview, and the glass menu stands 16 from it by the
15
+ * third of the screen it is in, over it when it stands in the lower half; on Android Material's popup under the
16
+ * element, the screen dimmed around it. Parts as @plexui/ui: `ContextMenu.Trigger`, `ContextMenu.Content`, and the
17
+ * items of Menu (`ContextMenu.Item`, `ContextMenu.Separator`, `ContextMenu.Label`).
18
+ */
19
+ declare function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenuProps): import("react").JSX.Element;
20
+ declare namespace ContextMenuRoot {
21
+ var displayName: string;
22
+ }
23
+ type Holdable = {
24
+ onLongPress?: (...args: unknown[]) => void;
25
+ onPress?: unknown;
26
+ accessibilityActions?: ReadonlyArray<{
27
+ name: string;
28
+ label?: string;
29
+ }>;
30
+ onAccessibilityAction?: (event: AccessibilityActionEvent) => void;
31
+ };
32
+ /**
33
+ * The element the menu is for: a ListItem, a Pressable, a Button, anything with `onLongPress`. Its own press still
34
+ * runs; a touch and hold opens the menu, and so does a right click on the web. The lifted preview on iOS is the
35
+ * element drawn again from its props, so state the element keeps inside itself is not in it.
36
+ */
37
+ declare function ContextMenuTrigger({ children, style }: {
38
+ children: ReactElement<Holdable>;
39
+ style?: StyleProp<ViewStyle>;
40
+ }): import("react").JSX.Element;
41
+ declare namespace ContextMenuTrigger {
42
+ var displayName: string;
43
+ }
44
+ export type ContextMenuContentProps = Omit<MenuContentProps, "align">;
45
+ /** The menu: Menu's items, 250 wide on iOS. */
46
+ declare function ContextMenuContent(props: ContextMenuContentProps): import("react").JSX.Element;
47
+ declare namespace ContextMenuContent {
48
+ var displayName: string;
49
+ }
50
+ export declare const ContextMenu: typeof ContextMenuRoot & {
51
+ Trigger: typeof ContextMenuTrigger;
52
+ Content: typeof ContextMenuContent;
53
+ Item: typeof import("../Menu/Menu").MenuItem;
54
+ Separator: typeof import("../Menu/Menu").MenuSeparator;
55
+ Label: typeof import("../Menu/Menu").MenuLabel;
56
+ };
57
+ export {};
@@ -0,0 +1,29 @@
1
+ export type CalendarProps = {
2
+ /** The chosen day. */
3
+ value: Date | null;
4
+ /** Called with the day a person taps (its time is midnight). */
5
+ onSelect: (day: Date) => void;
6
+ min?: Date;
7
+ max?: Date;
8
+ locale?: string;
9
+ weekStartsOn: number;
10
+ /** The calendar's width: seven columns across it (44 at the least on iOS). */
11
+ width: number;
12
+ /** Takes no presses (an inline calendar of a disabled picker). */
13
+ disabled?: boolean;
14
+ /** Labels of the month arrows, read by a screen reader. */
15
+ previousLabel?: string;
16
+ nextLabel?: string;
17
+ testID?: string;
18
+ };
19
+ /** iOS: the corner's inset around the grid of a compact picker's calendar (the web's `--calendar-inner-padding`). */
20
+ export declare const IOS_CALENDAR_INSET = 10;
21
+ /**
22
+ * The month grid of DatePicker. On iOS the phone calendar of @plexui/ui (Calendar.module.css under 768px): the month's
23
+ * title Semibold 17 at the row's text inset, the two arrows as 44 targets at the end, the weekdays Semibold 13 in
24
+ * capitals in the tertiary label, the days Regular 17 in 44 cells side by side and row on row, the chosen day white on
25
+ * a 44 circle of the text's color, today a 4 dot under its digits, days out of range at 40%. On Android Material 3's
26
+ * date picker: the month at the start in Medium 14 with the arrows at the end, the weekdays' letters, the days in 40dp
27
+ * circles, the chosen one filled with the primary color and today ringed in it.
28
+ */
29
+ export declare function Calendar({ value, onSelect, min, max, locale, weekStartsOn, width, disabled: off, previousLabel, nextLabel, testID }: CalendarProps): import("react").JSX.Element;
@@ -0,0 +1,57 @@
1
+ import { type StyleProp, type ViewStyle } from "react-native";
2
+ export type DatePickerMode = "date" | "time" | "datetime";
3
+ export type DatePickerDisplay = "compact" | "inline" | "wheels";
4
+ export type DatePickerProps = {
5
+ /** The date and time chosen, `null` for none yet. */
6
+ value: Date | null;
7
+ /** Called with the new date (its time kept when only the day changes, its day when only the time does). */
8
+ onChange: (value: Date) => void;
9
+ /** What is chosen: a day, a time, or both. @default "date" */
10
+ mode?: DatePickerMode;
11
+ /**
12
+ * How it is drawn. `compact`: the value in a capsule on iOS that opens the calendar (or the time's wheels) in a
13
+ * popover, Android's field or row value that opens Material's date (or time) dialog. `inline`: the month's calendar
14
+ * in place. `wheels`: the wheels of iOS, Android's spinners. @default "compact"
15
+ */
16
+ display?: DatePickerDisplay;
17
+ /** The earliest date that can be chosen. */
18
+ min?: Date;
19
+ /** The latest date that can be chosen. */
20
+ max?: Date;
21
+ /** The locale of the names and the formats. @default the device's */
22
+ locale?: string;
23
+ /** The first day of the week, 0 Sunday to 6 Saturday. @default the locale's */
24
+ weekStartsOn?: number;
25
+ /** A 12-hour clock with AM and PM. @default the locale's */
26
+ hour12?: boolean;
27
+ /** Shown while there is no value. @default "Select date" / "Select time" */
28
+ placeholder?: string;
29
+ disabled?: boolean;
30
+ /** The picker's name for a screen reader (a row's label). */
31
+ "aria-label"?: string;
32
+ /** Android: the header of the date dialog. @default "Select date" */
33
+ dateTitle?: string;
34
+ /** Android: the header of the time dialog. @default "Select time" */
35
+ timeTitle?: string;
36
+ /** @default "Cancel" */
37
+ cancelLabel?: string;
38
+ /** @default "OK" */
39
+ okLabel?: string;
40
+ /** The label of the time row under an inline calendar (`mode="datetime"`). @default "Time" */
41
+ timeLabel?: string;
42
+ testID?: string;
43
+ style?: StyleProp<ViewStyle>;
44
+ };
45
+ /**
46
+ * A date and time picker. On iOS UIDatePicker of iOS 27.2: `compact`, the date and the time in two capsules 8 apart
47
+ * (34 tall, 12 in, the secondary soft fill, the text in the accent while open) that open the month's calendar and the
48
+ * time's wheels in the glass popover, at most 32 from the screen's edge; `inline`, the calendar in place (a Time row
49
+ * under it for both); `wheels`, the wheels. On Android Material 3's pickers: the value as a row's value in the accent
50
+ * (or an outlined field with its icon) that opens the date picker dialog (the headline date over the month) or the
51
+ * time picker dial, both applied with OK; `inline` the calendar in place, `wheels` Android's spinners. The value is a
52
+ * plain `Date`; `min` and `max` bound it.
53
+ */
54
+ export declare function DatePicker({ value, onChange, mode, display, min, max, locale, weekStartsOn, hour12, placeholder, disabled, "aria-label": ariaLabel, dateTitle, timeTitle, cancelLabel, okLabel, timeLabel, testID, style, }: DatePickerProps): import("react").JSX.Element;
55
+ export declare namespace DatePicker {
56
+ var displayName: string;
57
+ }
@@ -0,0 +1,20 @@
1
+ export type TimeDialProps = {
2
+ hours: number;
3
+ minutes: number;
4
+ onChange: (hours: number, minutes: number) => void;
5
+ hour12: boolean;
6
+ locale?: string;
7
+ /** The header over the time ("Select time"). */
8
+ title: string;
9
+ hoursLabel?: string;
10
+ minutesLabel?: string;
11
+ testID?: string;
12
+ };
13
+ /**
14
+ * Android's time picker dial (Material 3 TimePicker): "Select time" in Medium 12, the hour and the minute in Regular
15
+ * 57 boxes 96 by 80 (the one being set in the primary container, the other in the highest surface container), AM and
16
+ * PM stacked beside them on a 12-hour clock, and the 256dp dial: a 48dp knob in the primary color on a line from the
17
+ * middle, the numbers 101dp out (a 24-hour clock adds 00 and 13–23 69dp out). A tap or a drag on the dial sets the
18
+ * hour, then it turns to the minutes.
19
+ */
20
+ export declare function TimeDial({ hours, minutes, onChange, hour12, locale, title, hoursLabel, minutesLabel, testID }: TimeDialProps): import("react").JSX.Element;
@@ -0,0 +1,40 @@
1
+ export type WheelItem = {
2
+ label: string;
3
+ disabled?: boolean;
4
+ };
5
+ export type WheelColumn = {
6
+ key: string;
7
+ items: WheelItem[];
8
+ /** The item at the band. */
9
+ index: number;
10
+ onChange: (index: number) => void;
11
+ /** The column's width. */
12
+ width: number;
13
+ /** The column's name, read by a screen reader ("Hours"). */
14
+ label: string;
15
+ /** Where its labels stand in the column. @default "center" */
16
+ align?: "start" | "center" | "end";
17
+ /** The labels' inset from the column's side they stand at. @default 4 */
18
+ inset?: number;
19
+ };
20
+ export type WheelsProps = {
21
+ columns: WheelColumn[];
22
+ /** The wheels' height. @default 202 on iOS (a compact time picker's popover), 144 on Android */
23
+ height?: number;
24
+ /** iOS: the band's inset from the wheels' sides. @default 20 */
25
+ bandInset?: number;
26
+ /** Takes no turns, presses or keys. */
27
+ disabled?: boolean;
28
+ testID?: string;
29
+ };
30
+ /** iOS: a row of UIDatePicker's wheels, 32 apart (the band of iOS 27.2, 32 tall). Android: a NumberPicker's 48dp rows. */
31
+ export declare const IOS_WHEEL_ROW = 32;
32
+ export declare const ANDROID_WHEEL_ROW = 48;
33
+ /**
34
+ * The wheels of a time (or date) picker. On iOS UIDatePicker's `.wheels` as iOS 27.2 draws them in a compact time
35
+ * picker's popover: rows 32 apart in Regular 22, a 32 band of the ink at 7% across the columns 20 in from the sides,
36
+ * the rows on the band in the ink and the others in its 35% gray, turning away like a cylinder's. On Android the
37
+ * spinner mode of its DatePicker and TimePicker: three 48dp rows, the middle one between two lines in the ink, the
38
+ * others faded. A wheel stops on a row; a tap on a row turns it there; VoiceOver and TalkBack turn it one row at a time.
39
+ */
40
+ export declare function Wheels({ columns, height: heightProp, bandInset, disabled, testID }: WheelsProps): import("react").JSX.Element;
@@ -0,0 +1,45 @@
1
+ /** Date helpers of DatePicker: plain `Date`s in the device's time zone, days compared by their calendar date. */
2
+ export declare function sameDay(a: Date | null | undefined, b: Date | null | undefined): boolean;
3
+ export declare function startOfDay(date: Date): Date;
4
+ /** The first day of the month `offset` months from `date`'s. */
5
+ export declare function monthOf(date: Date, offset?: number): Date;
6
+ /** A day lies outside `min`…`max` (compared by calendar day). */
7
+ export declare function dayOutside(day: Date, min?: Date, max?: Date): boolean;
8
+ /** A moment lies outside `min`…`max` (compared to the minute). */
9
+ export declare function timeOutside(date: Date, min?: Date, max?: Date): boolean;
10
+ /** The date kept inside `min`…`max`. */
11
+ export declare function clampDate(date: Date, min?: Date, max?: Date): Date;
12
+ /** The weeks of a month, each of seven days; days of the months around it are `null`. */
13
+ export declare function monthWeeks(month: Date, weekStartsOn: number): (Date | null)[][];
14
+ /** `value` on `day`: its time kept, the start of the day when there is no value yet. */
15
+ export declare function withDay(value: Date | null, day: Date): Date;
16
+ /** `value` at `hours`:`minutes`, today when there is no value yet. */
17
+ export declare function withTime(value: Date | null, hours: number, minutes: number): Date;
18
+ /** The day a week starts on in the locale (0 Sunday … 6 Saturday), from `Intl.Locale`'s week info; Monday without it. */
19
+ export declare function localeWeekStart(locale?: string): number;
20
+ /** The locale reads time on a 12-hour clock. */
21
+ export declare function localeHour12(locale?: string): boolean;
22
+ /** The date as a compact picker shows it: "13 Nov 2026" (iOS) or "Nov 13, 2026", by the locale. */
23
+ export declare function formatDate(date: Date, locale?: string): string;
24
+ /** The time: "09:00", or "9:00 AM" on a 12-hour clock. */
25
+ export declare function formatTime(date: Date, locale: string | undefined, hour12: boolean): string;
26
+ /** The month's title: "November 2026". */
27
+ export declare function formatMonth(month: Date, locale?: string): string;
28
+ /** Android's dialog headline: "Tue, Nov 24". */
29
+ export declare function formatHeadline(date: Date, locale?: string): string;
30
+ /** A day on a date-and-time wheel: "Wed Nov 25". */
31
+ export declare function formatWheelDay(date: Date, locale?: string): string;
32
+ /** A day read out in full: "Tuesday, 24 November 2026". */
33
+ export declare function formatFullDay(date: Date, locale?: string): string;
34
+ /** The weekdays' labels from `weekStartsOn`: "MON" (`short`, iOS) or "M" (`narrow`, Android). */
35
+ export declare function weekdayLabels(locale: string | undefined, weekStartsOn: number, width: "short" | "narrow"): {
36
+ label: string;
37
+ name: string;
38
+ }[];
39
+ /** The month names of the locale, January first. */
40
+ export declare function monthNames(locale?: string): string[];
41
+ /** The order of day, month and year in the locale's dates, for the date wheels. */
42
+ export declare function dateOrder(locale?: string): ("day" | "month" | "year")[];
43
+ /** The locale's day period labels: ["AM", "PM"]. */
44
+ export declare function periodLabels(locale?: string): [string, string];
45
+ export declare const pad2: (value: number) => string;
@@ -57,5 +57,23 @@ export type ChoiceDialogProps = {
57
57
  * Select's picker on Android; not part of the public API.
58
58
  */
59
59
  export declare function ChoiceDialog({ open, onClose, title, cancelLabel, okLabel, onOk, children, listProps, testID }: ChoiceDialogProps): import("react").JSX.Element;
60
+ export type PickerDialogProps = {
61
+ open: boolean;
62
+ onClose: () => void;
63
+ /** Applies the choice and closes the dialog. */
64
+ onOk: () => void;
65
+ cancelLabel: string;
66
+ okLabel: string;
67
+ /** The dialog's name for a screen reader. */
68
+ label?: string;
69
+ /** The picker, across the dialog's whole width (its own header in it). */
70
+ children: ReactNode;
71
+ testID?: string;
72
+ };
73
+ /**
74
+ * Android's picker dialog: the dialog's panel holding a picker of its own (Material 3's date picker or time picker
75
+ * dial), Cancel and OK at the end. DatePicker's dialog on Android; not part of the public API.
76
+ */
77
+ export declare function PickerDialog({ open, onClose, onOk, cancelLabel, okLabel, label, children, testID }: PickerDialogProps): import("react").JSX.Element;
60
78
  /** The background of an Android dialog: white, a dark gray in dark mode. */
61
79
  export declare const androidDialogBackground: (theme: Theme) => string;
@@ -23,3 +23,9 @@ export declare const MaterialCheckSymbol: import("./createIcon").IconComponent;
23
23
  * `abc_ic_ab_back_material` that Settings' toolbar shows); it is mirrored right to left.
24
24
  */
25
25
  export declare const MaterialArrowBack: import("./createIcon").IconComponent;
26
+ /** Material Symbols' chevron_left and chevron_right (24, the outlined weight 400): a month's arrows in the date picker. */
27
+ export declare const MaterialChevronLeft: import("./createIcon").IconComponent;
28
+ export declare const MaterialChevronRight: import("./createIcon").IconComponent;
29
+ /** Material Symbols' calendar_today and schedule (24, outlined weight 400): the trailing icons of a date and a time field. */
30
+ export declare const MaterialCalendarToday: import("./createIcon").IconComponent;
31
+ export declare const MaterialSchedule: import("./createIcon").IconComponent;
@@ -101,6 +101,8 @@ export type ListItemProps = {
101
101
  /** The chevron of a row that opens a page. @default true when the row has `onPress`, no `trailing` and is not `destructive` */
102
102
  disclosure?: boolean;
103
103
  onPress?: () => void;
104
+ /** A touch and hold on the row (half a second): a ContextMenu around the row sets it. */
105
+ onLongPress?: () => void;
104
106
  disabled?: boolean;
105
107
  /** A row in red, as a destructive action row. */
106
108
  destructive?: boolean;
@@ -119,7 +121,7 @@ export type ListItemProps = {
119
121
  * in (a multi-select list); a 1px divider from the text's start to the card's end, none under a row with a tile (a
120
122
  * tiled row draws none).
121
123
  */
122
- export declare function ListItem({ label, description, leading, leadingColor, value, valuePlacement, trailing, error, checked: checkedProp, defaultChecked, onCheckedChange, disclosure, onPress, disabled, destructive, accessibilityLabel, testID, }: ListItemProps): import("react").JSX.Element;
124
+ export declare function ListItem({ label, description, leading, leadingColor, value, valuePlacement, trailing, error, checked: checkedProp, defaultChecked, onCheckedChange, disclosure, onPress, onLongPress, disabled, destructive, accessibilityLabel, testID, }: ListItemProps): import("react").JSX.Element;
123
125
  export type StackedRowProps = {
124
126
  /** The label over the value; none for a row whose placeholder names the field (`hideLabel`). */
125
127
  label?: ReactNode;
@@ -70,6 +70,7 @@ declare function MenuContent(props: MenuContentProps): import("react").JSX.Eleme
70
70
  declare namespace MenuContent {
71
71
  var displayName: string;
72
72
  }
73
+ export declare function hasCheckedItems(children: ReactNode): boolean;
73
74
  type SurfaceProps = MenuContentProps & {
74
75
  open: boolean;
75
76
  anchor: MenuAnchor | null;
@@ -83,6 +84,14 @@ type SurfaceProps = MenuContentProps & {
83
84
  row?: MenuRow | null;
84
85
  /** Opened from a bar's button: on Android the header menu, in the bar's glass. */
85
86
  header?: boolean;
87
+ /**
88
+ * A context menu's touch and hold (ContextMenu): on iOS the screen dims and blurs but the element, drawn again
89
+ * over the dimming as its lifted `preview`, and the menu stands 16 from it, by the third of the screen it is in.
90
+ */
91
+ context?: {
92
+ preview: ReactNode;
93
+ radius: number;
94
+ };
86
95
  };
87
96
  /** The floating panel of a menu, placed under its anchor (over it when the screen ends first). */
88
97
  export declare function MenuSurface(props: SurfaceProps): import("react").JSX.Element;
@@ -104,8 +113,8 @@ export type MenuItemProps = {
104
113
  onSelect?: () => void;
105
114
  testID?: string;
106
115
  };
107
- declare function MenuItem(props: MenuItemProps): import("react").JSX.Element;
108
- declare namespace MenuItem {
116
+ export declare function MenuItem(props: MenuItemProps): import("react").JSX.Element;
117
+ export declare namespace MenuItem {
109
118
  var displayName: string;
110
119
  }
111
120
  export type MenuSubContentProps = {
@@ -134,15 +143,15 @@ declare function MenuSubTrigger({ children, icon, disabled, testID }: MenuSubTri
134
143
  declare namespace MenuSubTrigger {
135
144
  var displayName: string;
136
145
  }
137
- declare function MenuSeparator(): import("react").JSX.Element;
138
- declare namespace MenuSeparator {
146
+ export declare function MenuSeparator(): import("react").JSX.Element;
147
+ export declare namespace MenuSeparator {
139
148
  var displayName: string;
140
149
  }
141
150
  /** A heading over a group of items. */
142
- declare function MenuLabel({ children }: {
151
+ export declare function MenuLabel({ children }: {
143
152
  children: ReactNode;
144
153
  }): import("react").JSX.Element;
145
- declare namespace MenuLabel {
154
+ export declare namespace MenuLabel {
146
155
  var displayName: string;
147
156
  }
148
157
  export declare const Menu: typeof MenuRoot & {
@@ -24,6 +24,8 @@ export { TagInput, type Tag, type TagInputProps } from "./components/TagInput/Ta
24
24
  export { OTPInput, type OTPInputProps } from "./components/OTPInput/OTPInput";
25
25
  export { Select, type SelectOption, type SelectProps } from "./components/Select/Select";
26
26
  export { Menu, type MenuContentProps, type MenuItemProps, type MenuProps } from "./components/Menu/Menu";
27
+ export { ContextMenu, type ContextMenuContentProps, type ContextMenuProps } from "./components/ContextMenu/ContextMenu";
28
+ export { DatePicker, type DatePickerDisplay, type DatePickerMode, type DatePickerProps } from "./components/DatePicker/DatePicker";
27
29
  export { ActionSheet, type ActionSheetAction, type ActionSheetProps } from "./components/ActionSheet/ActionSheet";
28
30
  export { BottomSheet, type BottomSheetFooterProps, type BottomSheetProps } from "./components/BottomSheet/BottomSheet";
29
31
  export { Dialog, type DialogAction, type DialogProps } from "./components/Dialog/Dialog";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/react-native",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Plex UI components for React Native and Expo: iOS 26 and Material 3, on the shared @plexui/styles tokens",
5
5
  "license": "MIT",
6
6
  "homepage": "https://plexui.com",
@@ -0,0 +1,164 @@
1
+ import { cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useRef, useState, type ReactElement, type ReactNode } from "react"
2
+ import { Dimensions, Platform, View, type AccessibilityActionEvent, type StyleProp, type ViewStyle } from "react-native"
3
+ import { useTheme } from "../../theme/ThemeProvider"
4
+ import { Menu, MenuSurface, hasCheckedItems, measure, type MenuAnchor, type MenuContentProps, type Measurable } from "../Menu/Menu"
5
+
6
+ /** A touch and hold opens the menu after half a second, as the web's ContextMenu (CONTEXT_MENU_LONG_PRESS). */
7
+ export const CONTEXT_MENU_LONG_PRESS = 500
8
+
9
+ type ContextMenuState = {
10
+ open: boolean
11
+ setOpen: (next: boolean) => void
12
+ anchor: MenuAnchor | null
13
+ preview: ReactNode
14
+ setTarget: (node: Measurable | null, preview: ReactNode) => void
15
+ }
16
+
17
+ const ContextMenuContext = createContext<ContextMenuState | null>(null)
18
+
19
+ function useContextMenu(part: string) {
20
+ const context = useContext(ContextMenuContext)
21
+ if (!context) throw new Error(`${part} must be inside a ContextMenu`)
22
+ return context
23
+ }
24
+
25
+ export type ContextMenuProps = {
26
+ children: ReactNode
27
+ /** Holds the menu open or closed. */
28
+ open?: boolean
29
+ onOpenChange?: (open: boolean) => void
30
+ }
31
+
32
+ /**
33
+ * A menu of actions for an element, opened by a touch and hold (and a right click on the web): on iOS 27 the screen
34
+ * dims and blurs, the element stays clear over it as a lifted preview, and the glass menu stands 16 from it by the
35
+ * third of the screen it is in, over it when it stands in the lower half; on Android Material's popup under the
36
+ * element, the screen dimmed around it. Parts as @plexui/ui: `ContextMenu.Trigger`, `ContextMenu.Content`, and the
37
+ * items of Menu (`ContextMenu.Item`, `ContextMenu.Separator`, `ContextMenu.Label`).
38
+ */
39
+ function ContextMenuRoot({ children, open: openProp, onOpenChange }: ContextMenuProps) {
40
+ const [own, setOwn] = useState(false)
41
+ const open = openProp ?? own
42
+ const [anchor, setAnchor] = useState<MenuAnchor | null>(null)
43
+ const target = useRef<{ node: Measurable | null; preview: ReactNode }>({ node: null, preview: null })
44
+ const [preview, setPreview] = useState<ReactNode>(null)
45
+ const apply = useCallback(
46
+ (next: boolean) => {
47
+ if (openProp === undefined) setOwn(next)
48
+ onOpenChange?.(next)
49
+ },
50
+ [openProp, onOpenChange],
51
+ )
52
+ const setOpen = apply
53
+ const applyRef = useRef(apply)
54
+ applyRef.current = apply
55
+ // The element is measured as the menu opens, by a touch and hold or by `open`: the menu and its preview stand where
56
+ // it is. Until then nothing is drawn
57
+ useEffect(() => {
58
+ if (!open) {
59
+ setAnchor(null)
60
+ return
61
+ }
62
+ let live = true
63
+ measure(target.current.node, (box) => {
64
+ if (!live) return
65
+ setAnchor(box)
66
+ setPreview(target.current.preview)
67
+ })
68
+ // A turn of the screen moves the element: the menu closes, as iOS dismisses a context menu on rotation
69
+ const sub = Dimensions.addEventListener("change", () => applyRef.current(false))
70
+ return () => {
71
+ live = false
72
+ sub.remove()
73
+ }
74
+ }, [open])
75
+ const setTarget = useCallback((node: Measurable | null, next: ReactNode) => {
76
+ target.current = { node, preview: next }
77
+ }, [])
78
+ return <ContextMenuContext.Provider value={{ open, setOpen, anchor, preview, setTarget }}>{children}</ContextMenuContext.Provider>
79
+ }
80
+ ContextMenuRoot.displayName = "ContextMenu"
81
+
82
+ type Holdable = {
83
+ onLongPress?: (...args: unknown[]) => void
84
+ onPress?: unknown
85
+ accessibilityActions?: ReadonlyArray<{ name: string; label?: string }>
86
+ onAccessibilityAction?: (event: AccessibilityActionEvent) => void
87
+ }
88
+
89
+ /**
90
+ * The element the menu is for: a ListItem, a Pressable, a Button, anything with `onLongPress`. Its own press still
91
+ * runs; a touch and hold opens the menu, and so does a right click on the web. The lifted preview on iOS is the
92
+ * element drawn again from its props, so state the element keeps inside itself is not in it.
93
+ */
94
+ function ContextMenuTrigger({ children, style }: { children: ReactElement<Holdable>; style?: StyleProp<ViewStyle> }) {
95
+ const theme = useTheme()
96
+ const { setOpen, setTarget, open, anchor } = useContextMenu("ContextMenu.Trigger")
97
+ const child = isValidElement<Holdable>(children) ? children : null
98
+ const own = child?.props
99
+ // The element's own long press gets its event, then the menu opens
100
+ const hold = (...args: unknown[]) => {
101
+ own?.onLongPress?.(...args)
102
+ setOpen(true)
103
+ }
104
+ // VoiceOver and TalkBack open it through the element's long-press action (ListItem names it itself)
105
+ const actions = own?.accessibilityActions ?? []
106
+ const a11y = actions.some((action) => action.name === "longpress")
107
+ ? null
108
+ : {
109
+ accessibilityActions: [...actions, { name: "longpress" }],
110
+ onAccessibilityAction: (event: AccessibilityActionEvent) => {
111
+ if (event.nativeEvent.actionName === "longpress") hold()
112
+ else own?.onAccessibilityAction?.(event)
113
+ },
114
+ }
115
+ // The preview is the element drawn again over the dimming, taking no presses
116
+ const preview = child ? cloneElement(child, { onLongPress: undefined, onPress: undefined }) : null
117
+ const web = Platform.OS === "web"
118
+ return (
119
+ <View
120
+ ref={(next: unknown) => setTarget(next as Measurable | null, preview)}
121
+ collapsable={false}
122
+ // On iOS the element hides under its lifted preview while the menu is open, so it is not drawn twice; Android
123
+ // keeps it lit in its place
124
+ style={[{ opacity: open && anchor && !theme.isAndroid ? 0 : 1 }, style]}
125
+ {...(web
126
+ ? {
127
+ onContextMenu: (event: { preventDefault: () => void }) => {
128
+ event.preventDefault()
129
+ setOpen(true)
130
+ },
131
+ }
132
+ : null)}
133
+ >
134
+ {child ? cloneElement(child, { onLongPress: hold, ...a11y }) : children}
135
+ </View>
136
+ )
137
+ }
138
+ ContextMenuTrigger.displayName = "ContextMenu.Trigger"
139
+
140
+ export type ContextMenuContentProps = Omit<MenuContentProps, "align">
141
+
142
+ /** The menu: Menu's items, 250 wide on iOS. */
143
+ function ContextMenuContent(props: ContextMenuContentProps) {
144
+ const theme = useTheme()
145
+ const { open, setOpen, anchor, preview } = useContextMenu("ContextMenu.Content")
146
+ // The preview keeps a row's corners to half its height, else the kit's 30 (--context-menu-preview-radius)
147
+ // Items that say `checked` make a set of options, with the checkmark's column, as in Menu
148
+ const check = hasCheckedItems(props.children)
149
+ const radius = Math.min(theme.length("--context-menu-preview-radius", 30), (anchor?.height ?? 60) / 2)
150
+ if (theme.isAndroid) {
151
+ // Android: Material's popup under the element at its end, the screen dimmed around it
152
+ return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} row={anchor ? { box: anchor, radius: { top: 0, bottom: 0 } } : null} cover={false} onClose={() => setOpen(false)} />
153
+ }
154
+ return <MenuSurface {...props} check={check} open={open && anchor != null} anchor={anchor} context={{ preview, radius }} onClose={() => setOpen(false)} />
155
+ }
156
+ ContextMenuContent.displayName = "ContextMenu.Content"
157
+
158
+ export const ContextMenu = Object.assign(ContextMenuRoot, {
159
+ Trigger: ContextMenuTrigger,
160
+ Content: ContextMenuContent,
161
+ Item: Menu.Item,
162
+ Separator: Menu.Separator,
163
+ Label: Menu.Label,
164
+ })