import type { PluginSurfaceProps } from "@getpaseo/plugin/client"; import { Modal, ScrollView, FlatList, TextInput, copyText, useToast, } from "@getpaseo/plugin/client/ui"; import { useCallback, useMemo, useRef, useState } from "react"; import { Pressable, Text, View, StyleSheet, type StyleProp, type ViewStyle, type TextStyle, type FlatList as NativeFlatList, } from "react-native"; const modes = [ "Form", "Custom inset", "Full bleed", "ScrollView", "FlatList", "Horizontal", ] as const; type Mode = (typeof modes)[number]; const rows = Array.from({ length: 100 }, (_, index) => index + 1); const tabs = ["Overview", "Configuration", "Activity", "Permissions", "System logs"]; const styles = StyleSheet.create({ screen: { flex: 1, padding: 16, gap: 12 }, button: { padding: 12, borderWidth: 1, borderRadius: 6 }, fill: { flex: 1, minHeight: 0 }, customInset: { padding: 8, paddingBottom: 40, gap: 16 }, fullBleed: { padding: 0, gap: 0 }, row: { height: 56, padding: 16, borderBottomWidth: 1 }, form: { gap: 16 }, input: { borderWidth: 1, padding: 12, borderRadius: 6 }, tabs: { flexGrow: 0, flexShrink: 0 }, tab: { padding: 18, minWidth: 160 }, }); export function ModalExamples({ theme }: Pick) { const [mode, setMode] = useState(null); const [input, setInput] = useState(""); const [selected, setSelected] = useState(""); const list = useRef>(null); const toast = useToast(); const color = useMemo(() => ({ color: theme.colors.foreground }), [theme]); const body = useMemo(() => ({ backgroundColor: theme.colors.surface2 }), [theme]); const button = useMemo(() => [styles.button, { borderColor: theme.colors.border }], [theme]); const rowStyle = useMemo(() => [styles.row, { borderColor: theme.colors.border }], [theme]); const inputStyle = useMemo( () => [styles.input, color, { borderColor: theme.colors.border }], [color, theme], ); const copy = useCallback(async () => { try { await copyText("Copied from Paseo"); toast.show("Text copied", { variant: "success" }); } catch { toast.error("Could not copy text. Select the text and use Copy."); } }, [toast]); const row = useCallback( (item: number) => { return ( ); }, [rowStyle, color], ); const renderRow = useCallback(({ item }: { item: number }) => row(item), [row]); const close = useCallback((open: boolean) => { if (!open) setMode(null); }, []); const jumpToEnd = useCallback(() => list.current?.scrollToEnd({ animated: false }), []); const screen = useMemo(() => [styles.screen, body], [body]); let contentStyle: StyleProp = styles.fullBleed; if (mode === "Form") contentStyle = undefined; if (mode === "Custom inset") contentStyle = styles.customInset; const form = ( Paseo clipboard example Copy text Input: {input || "empty"} ); return ( Modal body examples {modes.map((example) => ( key={example} value={example} label={`Open ${example}`} style={button} textStyle={color} onSelect={setMode} /> ))} Selected: {selected || "none"} {mode === "Form" || mode === "Custom inset" ? form : null} {mode === "Full bleed" ? rows.map(row) : null} {mode === "ScrollView" ? ( {rows.map(row)} ) : null} {mode === "FlatList" ? ( <> Jump to last row ) : null} {mode === "Horizontal" ? ( <> {tabs.map((tab) => ( ))} {form} {rows.slice(0, 20).map(row)} ) : null} ); } function getRowLayout(_: unknown, index: number) { return { index, length: 56, offset: index * 56 }; } function ChoiceButton({ value, label, style, textStyle, onSelect, }: { value: Value; label: string; style: StyleProp; textStyle: StyleProp; onSelect(value: Value): void; }) { const select = useCallback(() => onSelect(value), [onSelect, value]); return ( {label} ); }