@agimon-ai/po-native-components 0.0.0-alpha.129 → 0.0.0-alpha.130
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/dist/components/Dialog.d.mts.map +1 -1
- package/dist/components/Dialog.mjs +6 -5
- package/dist/components/Dialog.mjs.map +1 -1
- package/dist/components/DropdownMenu.d.mts.map +1 -1
- package/dist/components/DropdownMenu.mjs +11 -11
- package/dist/components/DropdownMenu.mjs.map +1 -1
- package/dist/components/Sheet.d.mts.map +1 -1
- package/dist/components/Sheet.mjs +18 -17
- package/dist/components/Sheet.mjs.map +1 -1
- package/dist/components/SheetFrame.mjs +61 -32
- package/dist/components/SheetFrame.mjs.map +1 -1
- package/dist/components/Tabs.d.mts.map +1 -1
- package/dist/components/Tabs.mjs +6 -5
- package/dist/components/Tabs.mjs.map +1 -1
- package/dist/lib/useControllable.mjs +14 -6
- package/dist/lib/useControllable.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.d.mts","names":[],"sources":["../../src/components/Dialog.tsx"],"mappings":";;;;YAoCY;iBASK;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,SAAS,MAAM,aAAqB,cAAc,YAAY,8BAAW,IAAA;;
|
|
1
|
+
{"version":3,"file":"Dialog.d.mts","names":[],"sources":["../../src/components/Dialog.tsx"],"mappings":";;;;YAoCY;iBASK;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,SAAS,MAAM,aAAqB,cAAc,YAAY,8BAAW,IAAA;;wBAOzE,gBAAgB,YAAY,SAAS,8BAAW,IAAA;;wBAchD,cAAc,YAAY,SAAS,8BAAW,IAAA;iBAa7C;;EAEf,QAAQ;;EAER,QAAQ,UAAU;;EAElB;EACA,WAAW;;wBAGG,gBAAgB,OAAc,OAAO,YAAsB,YAAY,qCAAkB,IAAA;iBA6CxF,wBAAwB,KAAK;EAC5C,WAAW;EACX,QAAQ,UAAU;;iBAGH,0BAA0B;;;;;EAKzC;;EAEA;;wBAGc,eACd,aACA,YACA,OACA,aACG,SACF,oCAAiB,IAAA;wBAcJ,cAAc,UAAU,SAAS,4BAAS,IAAA;wBAI1C,oBAAoB,UAAU,SAAS,4BAAS,IAAA;wBAIhD,aAAa,OAAO,aAAa,SAAS,kCAAe,IAAA;YAQ7D;iBAEK,0BAA0B;;EAEzC,UAAU;;wBAGI,eAAe,SAAmB,OAAO,aAAa,SAAS,oCAAiB,IAAA"}
|
|
@@ -9,7 +9,7 @@ import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
|
9
9
|
import { Easing, Modal, Platform } from "react-native";
|
|
10
10
|
import { Animated } from "react-native-unistyles/components/native/Animated";
|
|
11
11
|
import { withAlpha } from "@agimon-ai/po-web-components/nativeTheme";
|
|
12
|
-
import { createContext, useContext, useEffect, useRef } from "react";
|
|
12
|
+
import { createContext, useContext, useEffect, useMemo, useRef } from "react";
|
|
13
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { Pressable } from "react-native-unistyles/components/native/Pressable";
|
|
15
15
|
|
|
@@ -26,11 +26,12 @@ const DialogContext = createContext({
|
|
|
26
26
|
});
|
|
27
27
|
function Dialog({ open, defaultOpen = false, onOpenChange, children }) {
|
|
28
28
|
const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);
|
|
29
|
+
const value = useMemo(() => ({
|
|
30
|
+
open: current,
|
|
31
|
+
setOpen
|
|
32
|
+
}), [current, setOpen]);
|
|
29
33
|
return /* @__PURE__ */ jsx(DialogContext.Provider, {
|
|
30
|
-
value
|
|
31
|
-
open: current,
|
|
32
|
-
setOpen
|
|
33
|
-
},
|
|
34
|
+
value,
|
|
34
35
|
children
|
|
35
36
|
});
|
|
36
37
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dialog.mjs","names":["withAlpha","createContext","ReactNode","useContext","useEffect","useRef","Easing","Modal","Platform","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","useUnistyles","CloseIcon","fontOf","useControllable","wrapText","Button","ButtonProps","BACKDROP_ALPHA_PERCENT","POP_FROM_SCALE","SCREEN_MARGIN","DialogWidth","DialogState","open","setOpen","DialogContext","undefined","DialogProps","defaultOpen","onOpenChange","children","Dialog","current","DialogTrigger","onPress","props","event","DialogClose","DialogContentProps","width","style","closeLabel","DialogContent","theme","progress","Animated","Value","x1","y1","x2","y2","motion","easing","setValue","timing","toValue","duration","pop","bezier","useNativeDriver","OS","start","_styles","styles","useVariants","root","backdrop","backgroundColor","colors","deep","card","opacity","transform","scale","interpolate","inputRange","outputRange","DialogPartProps","Omit","DialogHeaderProps","dismissible","DialogHeader","header","DialogTitle","title","DialogDescription","description","DialogBody","body","DialogFooterVariant","DialogFooterProps","variant","DialogFooter","_styles2","footer","hint","create","flex","alignItems","justifyContent","padding","position","top","right","bottom","left","maxHeight","overflow","borderRadius","lg","borderWidth","borderColor","border","panel","variants","sm","maxWidth","md","uni__dependencies","flexDirection","gap","spacing","minWidth","borderBottomWidth","borderBottomColor","flexShrink","color","hi","fontFamily","sans","fontSize","xl","lineHeight","letterSpacing","fontWeight","semibold","dim","lineHeightRelaxed","plain","bar","flexWrap","minHeight","borderTopWidth","borderTopColor","paddingHorizontal","paddingVertical","faint"],"sources":["../../src/components/Dialog.tsx"],"sourcesContent":["import { withAlpha } from '@agimon-ai/po-web-components/nativeTheme';\nimport { createContext, type ReactNode, useContext, useEffect, useRef } from 'react';\nimport {\n Animated,\n Easing,\n Modal,\n Platform,\n Pressable,\n type StyleProp,\n Text,\n type TextProps,\n View,\n type ViewProps,\n type ViewStyle,\n} from 'react-native';\nimport { StyleSheet, useUnistyles } from 'react-native-unistyles';\n\nimport { CloseIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\n\n/*\n * The web Dialog as a centred card in an RN Modal: the native shape for a\n * question that blocks, such as a destructive confirmation. Android back and\n * a backdrop tap close it, as Escape and an outside click do on the web.\n */\n\n/** `bg-po-deep/70`. */\nconst BACKDROP_ALPHA_PERCENT = 70;\n/** `animate-po-pop` starts the card slightly small and grows it into place. */\nconst POP_FROM_SCALE = 0.96;\n/** `max-w-[calc(100vw-24px)]`: 12pt clear of each screen edge. */\nconst SCREEN_MARGIN = 12;\n\nexport type DialogWidth = 'sm' | 'md' | 'lg';\n\ninterface DialogState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nconst DialogContext = createContext<DialogState>({ open: false, setOpen: () => undefined });\n\nexport interface DialogProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the dialog keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function Dialog({ open, defaultOpen = false, onOpenChange, children }: DialogProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n return <DialogContext.Provider value={{ open: current, setOpen }}>{children}</DialogContext.Provider>;\n}\n\n/** A Button that opens the enclosing dialog. */\nexport function DialogTrigger({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(DialogContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\n/** A Button that closes the enclosing dialog. */\nexport function DialogClose({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(DialogContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(false);\n }}\n {...props}\n />\n );\n}\n\nexport interface DialogContentProps {\n /** Width preset; `style` may still override. */\n width?: DialogWidth;\n /** Applied to the card, after the preset. */\n style?: StyleProp<ViewStyle>;\n /** What the backdrop announces as its close action. */\n closeLabel?: string;\n children?: ReactNode;\n}\n\nexport function DialogContent({ width = 'md', style, closeLabel = 'close', children }: DialogContentProps) {\n const { open, setOpen } = useContext(DialogContext);\n const { theme } = useUnistyles();\n const progress = useRef(new Animated.Value(0)).current;\n const [x1, y1, x2, y2] = theme.motion.easing;\n useEffect(() => {\n if (!open) return;\n progress.setValue(0);\n Animated.timing(progress, {\n toValue: 1,\n duration: theme.motion.pop,\n easing: Easing.bezier(x1, y1, x2, y2),\n useNativeDriver: Platform.OS !== 'web',\n }).start();\n }, [open, progress, theme.motion.pop, x1, y1, x2, y2]);\n styles.useVariants({ width });\n return (\n <Modal visible={open} transparent animationType=\"fade\" statusBarTranslucent onRequestClose={() => setOpen(false)}>\n <View style={styles.root}>\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={closeLabel}\n onPress={() => setOpen(false)}\n // Alpha mixes are computed in render from useUnistyles(), not in StyleSheet.create: on web Unistyles hands\n // the stylesheet CSS variables, which withAlpha cannot read.\n style={[styles.backdrop, { backgroundColor: withAlpha(theme.colors.deep, BACKDROP_ALPHA_PERCENT) }]}\n />\n <Animated.View\n accessibilityViewIsModal\n style={[\n styles.card,\n style,\n {\n opacity: progress,\n transform: [{ scale: progress.interpolate({ inputRange: [0, 1], outputRange: [POP_FROM_SCALE, 1] }) }],\n },\n ]}\n >\n {children}\n </Animated.View>\n </View>\n </Modal>\n );\n}\n\nexport interface DialogPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\nexport interface DialogHeaderProps extends DialogPartProps {\n /**\n * Show the close control at the right of the strip. Off by default, as on\n * the web: Android back and a backdrop tap already close every dialog.\n */\n dismissible?: boolean;\n /** What the close control announces. */\n closeLabel?: string;\n}\n\nexport function DialogHeader({\n dismissible = false,\n closeLabel = 'close',\n style,\n children,\n ...props\n}: DialogHeaderProps) {\n const { setOpen } = useContext(DialogContext);\n return (\n <View style={[styles.header, style]} {...props}>\n {children}\n {dismissible ? (\n <Button variant=\"ghost\" size=\"icon\" accessibilityLabel={closeLabel} onPress={() => setOpen(false)}>\n <CloseIcon size={12} color=\"faint\" />\n </Button>\n ) : null}\n </View>\n );\n}\n\nexport function DialogTitle({ style, ...props }: TextProps) {\n return <Text accessibilityRole=\"header\" style={[styles.title, style]} {...props} />;\n}\n\nexport function DialogDescription({ style, ...props }: TextProps) {\n return <Text style={[styles.description, style]} {...props} />;\n}\n\nexport function DialogBody({ style, children, ...props }: DialogPartProps) {\n return (\n <View style={[styles.body, style]} {...props}>\n {wrapText(children, styles.description)}\n </View>\n );\n}\n\nexport type DialogFooterVariant = 'plain' | 'bar';\n\nexport interface DialogFooterProps extends DialogPartProps {\n /** `plain`: buttons alone, inside the body's padding. `bar`: the recessed full-width strip with a hint at the left. */\n variant?: DialogFooterVariant;\n}\n\nexport function DialogFooter({ variant = 'plain', style, children, ...props }: DialogFooterProps) {\n styles.useVariants({ footer: variant });\n return (\n <View style={[styles.footer, style]} {...props}>\n {wrapText(children, styles.hint)}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n root: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: SCREEN_MARGIN },\n backdrop: { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 },\n card: {\n width: '100%',\n maxHeight: '100%',\n overflow: 'hidden',\n borderRadius: theme.borderRadius.lg,\n borderWidth: 1,\n borderColor: theme.colors.border,\n backgroundColor: theme.colors.panel,\n variants: {\n width: {\n sm: { maxWidth: 360 },\n md: { maxWidth: 480 },\n lg: { maxWidth: 620 },\n },\n },\n },\n header: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: theme.spacing(3),\n minWidth: 0,\n borderBottomWidth: 1,\n borderBottomColor: theme.colors.border,\n padding: theme.spacing(3),\n },\n title: {\n flexShrink: 1,\n color: theme.colors.hi,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.xl,\n lineHeight: theme.lineHeight.xl,\n letterSpacing: theme.letterSpacing.xl,\n fontWeight: theme.fontWeight.semibold,\n },\n description: {\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n body: { gap: theme.spacing(3), padding: theme.spacing(3) },\n footer: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n variants: {\n footer: {\n plain: { justifyContent: 'flex-end' },\n bar: {\n flexWrap: 'wrap',\n justifyContent: 'space-between',\n minHeight: 34,\n borderTopWidth: 1,\n borderTopColor: theme.colors['border-soft'],\n backgroundColor: theme.colors.deep,\n paddingHorizontal: theme.spacing(3),\n paddingVertical: theme.spacing(1.5),\n },\n },\n },\n },\n hint: {\n color: theme.colors.faint,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize['2xs'],\n lineHeight: theme.lineHeight['2xs'],\n },\n}));\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,MAAMqB,yBAAyB;;AAE/B,MAAMC,iBAAiB;;AAEvB,MAAMC,gBAAgB;AAStB,MAAMK,gBAAgB3B,cAA2B;CAAEyB,MAAM;CAAOC,eAAeE;AAAU,CAAC;AAU1F,SAAgBK,OAAO,EAAER,MAAMK,cAAc,OAAOC,cAAcC,YAAyB;CACzF,MAAM,CAACE,SAASR,WAAWV,gBAAgBS,MAAMK,aAAaC,YAAY;CAC1E,OAAO,oBAAC,cAAc,UAAf;EAAwB,OAAO;GAAEN,MAAMS;GAASR;EAAQ;EAAIM;CAAiC;AACtG;;AAGA,SAAgBG,cAAc,EAAEC,SAAS,GAAGC,SAAsB;CAChE,MAAM,EAAEX,YAAYxB,WAAWyB,aAAa;CAC5C,OACE,oBAAC,QAAD;EACE,UAAUW,UAAU;GAClBF,UAAUE,KAAK;GACfZ,QAAQ,IAAI;EACd;EACA,GAAIW;CAAM;AAGhB;;AAGA,SAAgBE,YAAY,EAAEH,SAAS,GAAGC,SAAsB;CAC9D,MAAM,EAAEX,YAAYxB,WAAWyB,aAAa;CAC5C,OACE,oBAAC,QAAD;EACE,UAAUW,UAAU;GAClBF,UAAUE,KAAK;GACfZ,QAAQ,KAAK;EACf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AAM8F,kBAAkBtB;EAAEG,mBAAA,CAAA,CAAA;CACxC;CACA9B,MAAM;EAAEgC,KAAK7E,MAAM8E,QAAQ,CAAC;EAAGrB,SAASzD,MAAM8E,QAAQ,CAAC;EAACH,mBAAA,CAAA,CAAA;CAAC;CACzDxB,QAAQ;EACNyB,eAAe;EACfrB,YAAY;EACZsB,KAAK7E,MAAM8E,QAAQ,CAAC;EACpBP,UAAU,EACRpB,QAAQ;GACN4C,OAAO,EAAEvC,gBAAgB,WAAW;GACpCwC,KAAK;IACHC,UAAU;IACVzC,gBAAgB;IAChB0C,WAAW;IACXC,gBAAgB;IAChBC,gBAAgBpG,MAAMyB,OAAO;IAC7BD,iBAAiBxB,MAAMyB,OAAOC;IAC9B2E,mBAAmBrG,MAAM8E,QAAQ,CAAC;IAClCwB,iBAAiBtG,MAAM8E,QAAQ,GAAG;GACpC;EACF,EACF;EAACH,mBAAA,CAAA,GAAA,CAAA;CACH;CACAvB,MAAM;EACJ+B,OAAOnF,MAAMyB,OAAO8E;EACpBlB,YAAYnH,OAAO8B,MAAMqF,WAAWC,IAAI;EACxCC,UAAUvF,MAAMuF,SAAS;EACzBE,YAAYzF,MAAMyF,WAAW;EAAMd,mBAAA,CAAA,CAAA;CACrC;AACF,EAAE"}
|
|
1
|
+
{"version":3,"file":"Dialog.mjs","names":["withAlpha","createContext","ReactNode","useContext","useEffect","useMemo","useRef","Easing","Modal","Platform","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","useUnistyles","CloseIcon","fontOf","useControllable","wrapText","Button","ButtonProps","BACKDROP_ALPHA_PERCENT","POP_FROM_SCALE","SCREEN_MARGIN","DialogWidth","DialogState","open","setOpen","DialogContext","undefined","DialogProps","defaultOpen","onOpenChange","children","Dialog","current","value","DialogTrigger","onPress","props","event","DialogClose","DialogContentProps","width","style","closeLabel","DialogContent","theme","progress","Animated","Value","x1","y1","x2","y2","motion","easing","setValue","timing","toValue","duration","pop","bezier","useNativeDriver","OS","start","_styles","styles","useVariants","root","backdrop","backgroundColor","colors","deep","card","opacity","transform","scale","interpolate","inputRange","outputRange","DialogPartProps","Omit","DialogHeaderProps","dismissible","DialogHeader","header","DialogTitle","title","DialogDescription","description","DialogBody","body","DialogFooterVariant","DialogFooterProps","variant","DialogFooter","_styles2","footer","hint","create","flex","alignItems","justifyContent","padding","position","top","right","bottom","left","maxHeight","overflow","borderRadius","lg","borderWidth","borderColor","border","panel","variants","sm","maxWidth","md","uni__dependencies","flexDirection","gap","spacing","minWidth","borderBottomWidth","borderBottomColor","flexShrink","color","hi","fontFamily","sans","fontSize","xl","lineHeight","letterSpacing","fontWeight","semibold","dim","lineHeightRelaxed","plain","bar","flexWrap","minHeight","borderTopWidth","borderTopColor","paddingHorizontal","paddingVertical","faint"],"sources":["../../src/components/Dialog.tsx"],"sourcesContent":["import { withAlpha } from '@agimon-ai/po-web-components/nativeTheme';\nimport { createContext, type ReactNode, useContext, useEffect, useMemo, useRef } from 'react';\nimport {\n Animated,\n Easing,\n Modal,\n Platform,\n Pressable,\n type StyleProp,\n Text,\n type TextProps,\n View,\n type ViewProps,\n type ViewStyle,\n} from 'react-native';\nimport { StyleSheet, useUnistyles } from 'react-native-unistyles';\n\nimport { CloseIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\n\n/*\n * The web Dialog as a centred card in an RN Modal: the native shape for a\n * question that blocks, such as a destructive confirmation. Android back and\n * a backdrop tap close it, as Escape and an outside click do on the web.\n */\n\n/** `bg-po-deep/70`. */\nconst BACKDROP_ALPHA_PERCENT = 70;\n/** `animate-po-pop` starts the card slightly small and grows it into place. */\nconst POP_FROM_SCALE = 0.96;\n/** `max-w-[calc(100vw-24px)]`: 12pt clear of each screen edge. */\nconst SCREEN_MARGIN = 12;\n\nexport type DialogWidth = 'sm' | 'md' | 'lg';\n\ninterface DialogState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nconst DialogContext = createContext<DialogState>({ open: false, setOpen: () => undefined });\n\nexport interface DialogProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the dialog keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function Dialog({ open, defaultOpen = false, onOpenChange, children }: DialogProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n const value = useMemo(() => ({ open: current, setOpen }), [current, setOpen]);\n return <DialogContext.Provider value={value}>{children}</DialogContext.Provider>;\n}\n\n/** A Button that opens the enclosing dialog. */\nexport function DialogTrigger({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(DialogContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\n/** A Button that closes the enclosing dialog. */\nexport function DialogClose({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(DialogContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(false);\n }}\n {...props}\n />\n );\n}\n\nexport interface DialogContentProps {\n /** Width preset; `style` may still override. */\n width?: DialogWidth;\n /** Applied to the card, after the preset. */\n style?: StyleProp<ViewStyle>;\n /** What the backdrop announces as its close action. */\n closeLabel?: string;\n children?: ReactNode;\n}\n\nexport function DialogContent({ width = 'md', style, closeLabel = 'close', children }: DialogContentProps) {\n const { open, setOpen } = useContext(DialogContext);\n const { theme } = useUnistyles();\n const progress = useRef(new Animated.Value(0)).current;\n const [x1, y1, x2, y2] = theme.motion.easing;\n useEffect(() => {\n if (!open) return;\n progress.setValue(0);\n Animated.timing(progress, {\n toValue: 1,\n duration: theme.motion.pop,\n easing: Easing.bezier(x1, y1, x2, y2),\n useNativeDriver: Platform.OS !== 'web',\n }).start();\n }, [open, progress, theme.motion.pop, x1, y1, x2, y2]);\n styles.useVariants({ width });\n return (\n <Modal visible={open} transparent animationType=\"fade\" statusBarTranslucent onRequestClose={() => setOpen(false)}>\n <View style={styles.root}>\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel={closeLabel}\n onPress={() => setOpen(false)}\n // Alpha mixes are computed in render from useUnistyles(), not in StyleSheet.create: on web Unistyles hands\n // the stylesheet CSS variables, which withAlpha cannot read.\n style={[styles.backdrop, { backgroundColor: withAlpha(theme.colors.deep, BACKDROP_ALPHA_PERCENT) }]}\n />\n <Animated.View\n accessibilityViewIsModal\n style={[\n styles.card,\n style,\n {\n opacity: progress,\n transform: [{ scale: progress.interpolate({ inputRange: [0, 1], outputRange: [POP_FROM_SCALE, 1] }) }],\n },\n ]}\n >\n {children}\n </Animated.View>\n </View>\n </Modal>\n );\n}\n\nexport interface DialogPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\nexport interface DialogHeaderProps extends DialogPartProps {\n /**\n * Show the close control at the right of the strip. Off by default, as on\n * the web: Android back and a backdrop tap already close every dialog.\n */\n dismissible?: boolean;\n /** What the close control announces. */\n closeLabel?: string;\n}\n\nexport function DialogHeader({\n dismissible = false,\n closeLabel = 'close',\n style,\n children,\n ...props\n}: DialogHeaderProps) {\n const { setOpen } = useContext(DialogContext);\n return (\n <View style={[styles.header, style]} {...props}>\n {children}\n {dismissible ? (\n <Button variant=\"ghost\" size=\"icon\" accessibilityLabel={closeLabel} onPress={() => setOpen(false)}>\n <CloseIcon size={12} color=\"faint\" />\n </Button>\n ) : null}\n </View>\n );\n}\n\nexport function DialogTitle({ style, ...props }: TextProps) {\n return <Text accessibilityRole=\"header\" style={[styles.title, style]} {...props} />;\n}\n\nexport function DialogDescription({ style, ...props }: TextProps) {\n return <Text style={[styles.description, style]} {...props} />;\n}\n\nexport function DialogBody({ style, children, ...props }: DialogPartProps) {\n return (\n <View style={[styles.body, style]} {...props}>\n {wrapText(children, styles.description)}\n </View>\n );\n}\n\nexport type DialogFooterVariant = 'plain' | 'bar';\n\nexport interface DialogFooterProps extends DialogPartProps {\n /** `plain`: buttons alone, inside the body's padding. `bar`: the recessed full-width strip with a hint at the left. */\n variant?: DialogFooterVariant;\n}\n\nexport function DialogFooter({ variant = 'plain', style, children, ...props }: DialogFooterProps) {\n styles.useVariants({ footer: variant });\n return (\n <View style={[styles.footer, style]} {...props}>\n {wrapText(children, styles.hint)}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n root: { flex: 1, alignItems: 'center', justifyContent: 'center', padding: SCREEN_MARGIN },\n backdrop: { position: 'absolute', top: 0, right: 0, bottom: 0, left: 0 },\n card: {\n width: '100%',\n maxHeight: '100%',\n overflow: 'hidden',\n borderRadius: theme.borderRadius.lg,\n borderWidth: 1,\n borderColor: theme.colors.border,\n backgroundColor: theme.colors.panel,\n variants: {\n width: {\n sm: { maxWidth: 360 },\n md: { maxWidth: 480 },\n lg: { maxWidth: 620 },\n },\n },\n },\n header: {\n flexDirection: 'row',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: theme.spacing(3),\n minWidth: 0,\n borderBottomWidth: 1,\n borderBottomColor: theme.colors.border,\n padding: theme.spacing(3),\n },\n title: {\n flexShrink: 1,\n color: theme.colors.hi,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.xl,\n lineHeight: theme.lineHeight.xl,\n letterSpacing: theme.letterSpacing.xl,\n fontWeight: theme.fontWeight.semibold,\n },\n description: {\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n body: { gap: theme.spacing(3), padding: theme.spacing(3) },\n footer: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n variants: {\n footer: {\n plain: { justifyContent: 'flex-end' },\n bar: {\n flexWrap: 'wrap',\n justifyContent: 'space-between',\n minHeight: 34,\n borderTopWidth: 1,\n borderTopColor: theme.colors['border-soft'],\n backgroundColor: theme.colors.deep,\n paddingHorizontal: theme.spacing(3),\n paddingVertical: theme.spacing(1.5),\n },\n },\n },\n },\n hint: {\n color: theme.colors.faint,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize['2xs'],\n lineHeight: theme.lineHeight['2xs'],\n },\n}));\n"],"mappings":";;;;;;;;;;;;;;;;;AA8BA,MAAMsB,yBAAyB;;AAE/B,MAAMC,iBAAiB;;AAEvB,MAAMC,gBAAgB;AAStB,MAAMK,gBAAgB5B,cAA2B;CAAE0B,MAAM;CAAOC,eAAeE;AAAU,CAAC;AAU1F,SAAgBK,OAAO,EAAER,MAAMK,cAAc,OAAOC,cAAcC,YAAyB;CACzF,MAAM,CAACE,SAASR,WAAWV,gBAAgBS,MAAMK,aAAaC,YAAY;CAC1E,MAAMI,QAAQhC,eAAe;EAAEsB,MAAMS;EAASR;CAAQ,IAAI,CAACQ,SAASR,OAAO,CAAC;CAC5E,OAAO,oBAAC,cAAc,UAAf;EAA+BS;EAAQH;CAAiC;AACjF;;AAGA,SAAgBI,cAAc,EAAEC,SAAS,GAAGC,SAAsB;CAChE,MAAM,EAAEZ,YAAYzB,WAAW0B,aAAa;CAC5C,OACE,oBAAC,QAAD;EACE,UAAUY,UAAU;GAClBF,UAAUE,KAAK;GACfb,QAAQ,IAAI;EACd;EACA,GAAIY;CAAM;AAGhB;;AAGA,SAAgBE,YAAY,EAAEH,SAAS,GAAGC,SAAsB;CAC9D,MAAM,EAAEZ,YAAYzB,WAAW0B,aAAa;CAC5C,OACE,oBAAC,QAAD;EACE,UAAUY,UAAU;GAClBF,UAAUE,KAAK;GACfb,QAAQ,KAAK;EACf;EACA,GAAIY;CAAM;AAGhB;AAYA,SAAgBO,cAAc,EAAEH,QAAQ,MAAMC,OAAOC,aAAa,SAASZ,YAAgC;CACzG,MAAM,EAAEP,MAAMC,YAAYzB,WAAW0B,aAAa;CAClD,MAAM,EAAEmB,UAAUjC,aAAa;CAC/B,MAAMkC,WAAW3C,OAAO,IAAI4C,SAASC,MAAM,CAAC,CAAC,CAAC,CAACf;CAC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BP,UAAU,EACRpB,QAAQ;GACN4C,OAAO,EAAEvC,gBAAgB,WAAW;GACpCwC,KAAK;IACHC,UAAU;IACVzC,gBAAgB;IAChB0C,WAAW;IACXC,gBAAgB;IAChBC,gBAAgBpG,MAAMyB,OAAO;IAC7BD,iBAAiBxB,MAAMyB,OAAOC;IAC9B2E,mBAAmBrG,MAAM8E,QAAQ,CAAC;IAClCwB,iBAAiBtG,MAAM8E,QAAQ,GAAG;GACpC;EACF,EACF;EAACH,mBAAA,CAAA,GAAA,CAAA;CACH;CACAvB,MAAM;EACJ+B,OAAOnF,MAAMyB,OAAO8E;EACpBlB,YAAYpH,OAAO+B,MAAMqF,WAAWC,IAAI;EACxCC,UAAUvF,MAAMuF,SAAS;EACzBE,YAAYzF,MAAMyF,WAAW;EAAMd,mBAAA,CAAA,CAAA;CACrC;AACF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.d.mts","names":[],"sources":["../../src/components/DropdownMenu.tsx"],"mappings":";;;;iBAyCiB;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,eAAe,MAAM,aAAqB,cAAc,YAAY,oCAAiB,IAAA;;
|
|
1
|
+
{"version":3,"file":"DropdownMenu.d.mts","names":[],"sources":["../../src/components/DropdownMenu.tsx"],"mappings":";;;;iBAyCiB;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,eAAe,MAAM,aAAqB,cAAc,YAAY,oCAAiB,IAAA;;wBAOrF,sBAAsB,SAAS,uBAAuB,SAAS,8BAAW,IAAA;iBAczE;EACf,WAAW;;EAEX;;;wBAIc,sBAAsB,UAAU,aAAa,2CAAwB,IAAA;iBAepE,8BAA8B,KAAK;EAClD,WAAW;EACX,QAAQ,UAAU;;;wBAIJ,oBAAoB,aAAa,SAAS,wCAAqB,IAAA;YAInE;iBAEK;EACf,UAAU;;EAEV;EACA;;EAEA;;EAEA,WAAW;EACX,QAAQ,UAAU;;wBA8CJ,iBAAiB,OAAO,wCAAqB,IAAA;iBAI5C,sCAAsC,KAAK;EAC1D;EACA,mBAAmB;;;wBAIL,2BACd,SACA,iBACA,aACG,SACF,gDAA6B,IAAA;iBAef,oCAAoC;EACnD;EACA,iBAAiB;;;wBAIH,yBAAyB,OAAO,eAAe,aAAa,SAAS,8CAA2B,IAAA;iBAU/F,mCAAmC,KAAK;EACvD;;wBAGc,wBAAwB,OAAO,aAAa,SAAS,6CAA0B,IAAA;;wBAkB/E,oBAAoB,OAAO,aAAa,SAAS,4BAAS,IAAA;;wBAU1D,uBAAuB,UAAU,SAAS,4BAAS,IAAA;wBAInD,wBAAwB;EAAW,QAAQ,UAAU;oBAAY,IAAA"}
|
|
@@ -8,7 +8,7 @@ import { SheetFrame } from "./SheetFrame.mjs";
|
|
|
8
8
|
import { View } from "react-native-unistyles/components/native/View";
|
|
9
9
|
import { Text } from "react-native-unistyles/components/native/Text";
|
|
10
10
|
import { StyleSheet } from "react-native-unistyles";
|
|
11
|
-
import { createContext, useContext } from "react";
|
|
11
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
12
12
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Pressable } from "react-native-unistyles/components/native/Pressable";
|
|
14
14
|
|
|
@@ -28,11 +28,12 @@ const RadioContext = createContext({
|
|
|
28
28
|
});
|
|
29
29
|
function DropdownMenu({ open, defaultOpen = false, onOpenChange, children }) {
|
|
30
30
|
const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);
|
|
31
|
+
const value = useMemo(() => ({
|
|
32
|
+
open: current,
|
|
33
|
+
setOpen
|
|
34
|
+
}), [current, setOpen]);
|
|
31
35
|
return /* @__PURE__ */ jsx(MenuContext.Provider, {
|
|
32
|
-
value
|
|
33
|
-
open: current,
|
|
34
|
-
setOpen
|
|
35
|
-
},
|
|
36
|
+
value,
|
|
36
37
|
children
|
|
37
38
|
});
|
|
38
39
|
}
|
|
@@ -53,16 +54,15 @@ function DropdownMenuTrigger({ onPress, accessibilityState, ...props }) {
|
|
|
53
54
|
}
|
|
54
55
|
/** The action list, in a bottom sheet. */
|
|
55
56
|
function DropdownMenuContent({ children, onDismiss }) {
|
|
56
|
-
const
|
|
57
|
+
const menu = useContext(MenuContext);
|
|
58
|
+
const { open, setOpen } = menu;
|
|
59
|
+
const close = useCallback(() => setOpen(false), [setOpen]);
|
|
57
60
|
return /* @__PURE__ */ jsx(SheetFrame, {
|
|
58
61
|
open,
|
|
59
|
-
onClose:
|
|
62
|
+
onClose: close,
|
|
60
63
|
onDismiss,
|
|
61
64
|
children: /* @__PURE__ */ jsx(MenuContext.Provider, {
|
|
62
|
-
value:
|
|
63
|
-
open,
|
|
64
|
-
setOpen
|
|
65
|
-
},
|
|
65
|
+
value: menu,
|
|
66
66
|
children: /* @__PURE__ */ jsx(View, {
|
|
67
67
|
accessibilityRole: "menu",
|
|
68
68
|
style: styles.content,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.mjs","names":["createContext","ReactNode","useContext","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","CheckIcon","fontOf","selectionTick","useControllable","wrapText","Button","ButtonProps","SheetFrame","INDICATOR_GUTTER","MIN_ROW_HEIGHT","DISABLED_OPACITY","RADIO_DOT","MenuState","open","setOpen","MenuContext","undefined","RadioState","value","onValueChange","RadioContext","DropdownMenuProps","defaultOpen","onOpenChange","children","DropdownMenu","current","DropdownMenuTrigger","onPress","accessibilityState","props","expanded","event","DropdownMenuContentProps","onDismiss","DropdownMenuContent","styles","content","DropdownMenuPartProps","Omit","style","DropdownMenuGroup","DropdownMenuItemVariant","DropdownMenuItemProps","variant","indented","disabled","onSelect","ItemRowProps","role","checked","indicator","ItemRow","_styles","useVariants","pressed","item","label","DropdownMenuItem","DropdownMenuCheckboxItemProps","onCheckedChange","DropdownMenuCheckboxItem","DropdownMenuRadioGroupProps","DropdownMenuRadioGroup","DropdownMenuRadioItemProps","DropdownMenuRadioItem","radio","radioDot","DropdownMenuLabel","charAt","toUpperCase","slice","menuLabel","DropdownMenuShortcut","shortcut","DropdownMenuSeparator","separator","create","theme","paddingVertical","spacing","uni__dependencies","flexDirection","alignItems","gap","minHeight","paddingHorizontal","paddingLeft","position","left","width","height","justifyContent","borderRadius","full","backgroundColor","colors","blue","deep","opacity","flexShrink","fontFamily","sans","fontSize","base","lineHeight","variants","default","color","hi","destructive","red","dim","sm","fontWeight","semibold","marginLeft","marginVertical"],"sources":["../../src/components/DropdownMenu.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext } from 'react';\nimport { Pressable, type StyleProp, Text, type TextProps, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CheckIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { selectionTick } from '../lib/haptics';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\nimport { SheetFrame } from './SheetFrame';\n\n/*\n * The web DropdownMenu as an action sheet: the same items rise in a bottom\n * sheet, each a full-width 44pt row, choosing one ticks once and closes the\n * menu, and destructive rows are red.\n *\n * ponytail: submenus are not ported; a native action list nests by opening a\n * second menu from an item.\n */\n\n/** A row that carries a check or bullet keeps a gutter for it, so labels line up whether or not one is set. */\nconst INDICATOR_GUTTER = 28;\nconst MIN_ROW_HEIGHT = 44;\nconst DISABLED_OPACITY = 0.4;\nconst RADIO_DOT = 6;\n\ninterface MenuState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nconst MenuContext = createContext<MenuState>({ open: false, setOpen: () => undefined });\n\ninterface RadioState {\n value: string | undefined;\n onValueChange: ((value: string) => void) | undefined;\n}\n\nconst RadioContext = createContext<RadioState>({ value: undefined, onValueChange: undefined });\n\nexport interface DropdownMenuProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the menu keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function DropdownMenu({ open, defaultOpen = false, onOpenChange, children }: DropdownMenuProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n return <MenuContext.Provider value={{ open: current, setOpen }}>{children}</MenuContext.Provider>;\n}\n\n/** A Button that opens the menu; announces that it opens a menu. */\nexport function DropdownMenuTrigger({ onPress, accessibilityState, ...props }: ButtonProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <Button\n accessibilityState={{ ...accessibilityState, expanded: open }}\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuContentProps {\n children?: ReactNode;\n /** The native sheet has finished dismissing, including its closing animation. */\n onDismiss?: () => void;\n}\n\n/** The action list, in a bottom sheet. */\nexport function DropdownMenuContent({ children, onDismiss }: DropdownMenuContentProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <SheetFrame open={open} onClose={() => setOpen(false)} onDismiss={onDismiss}>\n <MenuContext.Provider value={{ open, setOpen }}>\n <View accessibilityRole=\"menu\" style={styles.content}>\n {children}\n </View>\n </MenuContext.Provider>\n </SheetFrame>\n );\n}\n\nexport interface DropdownMenuPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** A run of items under one label, so the separator between groups is structural. */\nexport function DropdownMenuGroup({ children, ...props }: DropdownMenuPartProps) {\n return <View {...props}>{children}</View>;\n}\n\nexport type DropdownMenuItemVariant = 'default' | 'destructive';\n\nexport interface DropdownMenuItemProps {\n variant?: DropdownMenuItemVariant;\n /** Keep the indicator gutter, so the label lines up with checkbox and radio rows. */\n indented?: boolean;\n disabled?: boolean;\n /** Chosen: the menu ticks, runs this, then closes. */\n onSelect?: () => void;\n /** The label, optionally followed by a DropdownMenuShortcut. */\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\ninterface ItemRowProps extends DropdownMenuItemProps {\n role: 'menuitem' | 'checkbox' | 'radio';\n checked?: boolean;\n indicator?: ReactNode;\n}\n\nfunction ItemRow({\n variant = 'default',\n indented = false,\n disabled = false,\n onSelect,\n role,\n checked,\n indicator,\n children,\n style,\n}: ItemRowProps) {\n const { setOpen } = useContext(MenuContext);\n styles.useVariants({ variant: variant === 'destructive' ? 'destructive' : undefined });\n return (\n <Pressable\n accessibilityRole={role}\n accessibilityState={{ disabled, checked }}\n disabled={disabled}\n onPress={() => {\n selectionTick();\n onSelect?.();\n setOpen(false);\n }}\n style={({ pressed }) => [\n styles.item,\n (indented || indicator !== undefined) && styles.indented,\n pressed && styles.pressed,\n disabled && styles.disabled,\n style,\n ]}\n >\n {indicator !== undefined ? <View style={styles.indicator}>{indicator}</View> : null}\n {wrapText(children, styles.label)}\n </Pressable>\n );\n}\n\nexport function DropdownMenuItem(props: DropdownMenuItemProps) {\n return <ItemRow role=\"menuitem\" {...props} />;\n}\n\nexport interface DropdownMenuCheckboxItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n checked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n}\n\n/** A row that toggles: the check lives in the gutter so the label never shifts. */\nexport function DropdownMenuCheckboxItem({\n checked = false,\n onCheckedChange,\n onSelect,\n ...props\n}: DropdownMenuCheckboxItemProps) {\n return (\n <ItemRow\n role=\"checkbox\"\n checked={checked}\n indicator={checked ? <CheckIcon size={12} color=\"blue\" /> : null}\n onSelect={() => {\n onCheckedChange?.(!checked);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuRadioGroupProps extends DropdownMenuPartProps {\n value?: string;\n onValueChange?: (value: string) => void;\n}\n\n/** The exclusive-choice group; pair it with DropdownMenuRadioItem. */\nexport function DropdownMenuRadioGroup({ value, onValueChange, children, ...props }: DropdownMenuRadioGroupProps) {\n return (\n <RadioContext.Provider value={{ value, onValueChange }}>\n <View accessibilityRole=\"radiogroup\" {...props}>\n {children}\n </View>\n </RadioContext.Provider>\n );\n}\n\nexport interface DropdownMenuRadioItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n value: string;\n}\n\nexport function DropdownMenuRadioItem({ value, onSelect, ...props }: DropdownMenuRadioItemProps) {\n const radio = useContext(RadioContext);\n const checked = radio.value === value;\n return (\n <ItemRow\n role=\"radio\"\n checked={checked}\n indicator={checked ? <View style={styles.radioDot} /> : null}\n onSelect={() => {\n radio.onValueChange?.(value);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\n/** The heading over a run of items, raised to sentence case as the web's `first-letter:uppercase`. */\nexport function DropdownMenuLabel({ style, children, ...props }: TextProps) {\n const label = typeof children === 'string' ? children.charAt(0).toUpperCase() + children.slice(1) : children;\n return (\n <Text accessibilityRole=\"header\" style={[styles.menuLabel, style]} {...props}>\n {label}\n </Text>\n );\n}\n\n/** The keystroke printed at the right of a row; the row supplies the gap. */\nexport function DropdownMenuShortcut({ style, ...props }: TextProps) {\n return <Text style={[styles.shortcut, style]} {...props} />;\n}\n\nexport function DropdownMenuSeparator({ style }: { style?: StyleProp<ViewStyle> }) {\n return <View accessible={false} style={[styles.separator, style]} />;\n}\n\nconst styles = StyleSheet.create((theme) => ({\n content: { paddingVertical: theme.spacing(1) },\n item: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n minHeight: MIN_ROW_HEIGHT,\n paddingHorizontal: theme.spacing(4),\n },\n indented: { paddingLeft: theme.spacing(4) + INDICATOR_GUTTER },\n indicator: {\n position: 'absolute',\n left: theme.spacing(4),\n width: theme.spacing(3),\n height: theme.spacing(3),\n alignItems: 'center',\n justifyContent: 'center',\n },\n radioDot: {\n width: RADIO_DOT,\n height: RADIO_DOT,\n borderRadius: theme.borderRadius.full,\n backgroundColor: theme.colors.blue,\n },\n pressed: { backgroundColor: theme.colors.deep },\n disabled: { opacity: DISABLED_OPACITY },\n label: {\n flexShrink: 1,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.base,\n lineHeight: theme.lineHeight.base,\n variants: {\n variant: {\n default: { color: theme.colors.hi },\n destructive: { color: theme.colors.red },\n },\n },\n },\n menuLabel: {\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(1),\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n fontWeight: theme.fontWeight.semibold,\n },\n shortcut: {\n marginLeft: 'auto',\n flexShrink: 0,\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n separator: { height: 1, marginVertical: theme.spacing(1), backgroundColor: theme.colors['border-soft'] },\n}));\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,MAAMgB,mBAAmB;AACzB,MAAMC,iBAAiB;AACvB,MAAMC,mBAAmB;AACzB,MAAMC,YAAY;AAOlB,MAAMI,cAAcvB,cAAyB;CAAEqB,MAAM;CAAOC,eAAeE;AAAU,CAAC;AAOtF,MAAMI,eAAe5B,cAA0B;CAAE0B,OAAOF;CAAWG,eAAeH;AAAU,CAAC;AAU7F,SAAgBS,aAAa,EAAEZ,MAAMS,cAAc,OAAOC,cAAcC,YAA+B;CACrG,MAAM,CAACE,SAASZ,WAAWX,gBAAgBU,MAAMS,aAAaC,YAAY;CAC1E,OAAO,oBAAC,YAAY,UAAb;EAAsB,OAAO;GAAEV,MAAMa;GAASZ;EAAQ;EAAIU;CAA+B;AAClG;;AAGA,SAAgBG,oBAAoB,EAAEC,SAASC,oBAAoB,GAAGC,SAAsB;CAC1F,MAAM,EAAEjB,MAAMC,YAAYpB,WAAWqB,WAAW;CAChD,OACE,oBAAC,QAAD;EACE,oBAAoB;GAAE,GAAGc;GAAoBE,UAAUlB;EAAK;EAC5D,UAAUmB,UAAU;GAClBJ,UAAUI,KAAK;GACflB,QAAQ,IAAI;EACd;EACA,GAAIgB;CAAM;AAGhB;;AASA,SAAgBK,oBAAoB,EAAEX,UAAUU,aAAuC;CACrF,MA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mBAAmBR,MAAME,QAAQ,CAAC;EAClCD,iBAAiBD,MAAME,QAAQ,CAAC;EAChC4B,OAAO9B,MAAMkB,OAAOgB;EACpBX,YAAYpG,OAAO6E,MAAMuB,WAAWC,IAAI;EACxCC,UAAUzB,MAAMyB,SAASU;EACzBR,YAAY3B,MAAM2B,WAAWQ;EAC7BC,YAAYpC,MAAMoC,WAAWC;EAAQlC,mBAAA,CAAA,CAAA;CACvC;CACAP,UAAU;EACR0C,YAAY;EACZhB,YAAY;EACZQ,OAAO9B,MAAMkB,OAAOgB;EACpBX,YAAYpG,OAAO6E,MAAMuB,WAAWC,IAAI;EACxCC,UAAUzB,MAAMyB,SAASU;EACzBR,YAAY3B,MAAM2B,WAAWQ;EAAEhC,mBAAA,CAAA,CAAA;CACjC;CACAL,WAAW;EAAEe,QAAQ;EAAG0B,gBAAgBvC,MAAME,QAAQ,CAAC;EAAGe,iBAAiBjB,MAAMkB,OAAO;EAAcf,mBAAA,CAAA,CAAA;CAAC;AACzG,EAAE"}
|
|
1
|
+
{"version":3,"file":"DropdownMenu.mjs","names":["createContext","ReactNode","useCallback","useContext","useMemo","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","CheckIcon","fontOf","selectionTick","useControllable","wrapText","Button","ButtonProps","SheetFrame","INDICATOR_GUTTER","MIN_ROW_HEIGHT","DISABLED_OPACITY","RADIO_DOT","MenuState","open","setOpen","MenuContext","undefined","RadioState","value","onValueChange","RadioContext","DropdownMenuProps","defaultOpen","onOpenChange","children","DropdownMenu","current","DropdownMenuTrigger","onPress","accessibilityState","props","expanded","event","DropdownMenuContentProps","onDismiss","DropdownMenuContent","menu","close","styles","content","DropdownMenuPartProps","Omit","style","DropdownMenuGroup","DropdownMenuItemVariant","DropdownMenuItemProps","variant","indented","disabled","onSelect","ItemRowProps","role","checked","indicator","ItemRow","_styles","useVariants","pressed","item","label","DropdownMenuItem","DropdownMenuCheckboxItemProps","onCheckedChange","DropdownMenuCheckboxItem","DropdownMenuRadioGroupProps","DropdownMenuRadioGroup","DropdownMenuRadioItemProps","DropdownMenuRadioItem","radio","radioDot","DropdownMenuLabel","charAt","toUpperCase","slice","menuLabel","DropdownMenuShortcut","shortcut","DropdownMenuSeparator","separator","create","theme","paddingVertical","spacing","uni__dependencies","flexDirection","alignItems","gap","minHeight","paddingHorizontal","paddingLeft","position","left","width","height","justifyContent","borderRadius","full","backgroundColor","colors","blue","deep","opacity","flexShrink","fontFamily","sans","fontSize","base","lineHeight","variants","default","color","hi","destructive","red","dim","sm","fontWeight","semibold","marginLeft","marginVertical"],"sources":["../../src/components/DropdownMenu.tsx"],"sourcesContent":["import { createContext, type ReactNode, useCallback, useContext, useMemo } from 'react';\nimport { Pressable, type StyleProp, Text, type TextProps, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CheckIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { selectionTick } from '../lib/haptics';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\nimport { SheetFrame } from './SheetFrame';\n\n/*\n * The web DropdownMenu as an action sheet: the same items rise in a bottom\n * sheet, each a full-width 44pt row, choosing one ticks once and closes the\n * menu, and destructive rows are red.\n *\n * ponytail: submenus are not ported; a native action list nests by opening a\n * second menu from an item.\n */\n\n/** A row that carries a check or bullet keeps a gutter for it, so labels line up whether or not one is set. */\nconst INDICATOR_GUTTER = 28;\nconst MIN_ROW_HEIGHT = 44;\nconst DISABLED_OPACITY = 0.4;\nconst RADIO_DOT = 6;\n\ninterface MenuState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nconst MenuContext = createContext<MenuState>({ open: false, setOpen: () => undefined });\n\ninterface RadioState {\n value: string | undefined;\n onValueChange: ((value: string) => void) | undefined;\n}\n\nconst RadioContext = createContext<RadioState>({ value: undefined, onValueChange: undefined });\n\nexport interface DropdownMenuProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the menu keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function DropdownMenu({ open, defaultOpen = false, onOpenChange, children }: DropdownMenuProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n const value = useMemo(() => ({ open: current, setOpen }), [current, setOpen]);\n return <MenuContext.Provider value={value}>{children}</MenuContext.Provider>;\n}\n\n/** A Button that opens the menu; announces that it opens a menu. */\nexport function DropdownMenuTrigger({ onPress, accessibilityState, ...props }: ButtonProps) {\n const { open, setOpen } = useContext(MenuContext);\n return (\n <Button\n accessibilityState={{ ...accessibilityState, expanded: open }}\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuContentProps {\n children?: ReactNode;\n /** The native sheet has finished dismissing, including its closing animation. */\n onDismiss?: () => void;\n}\n\n/** The action list, in a bottom sheet. */\nexport function DropdownMenuContent({ children, onDismiss }: DropdownMenuContentProps) {\n const menu = useContext(MenuContext);\n const { open, setOpen } = menu;\n const close = useCallback(() => setOpen(false), [setOpen]);\n return (\n <SheetFrame open={open} onClose={close} onDismiss={onDismiss}>\n <MenuContext.Provider value={menu}>\n <View accessibilityRole=\"menu\" style={styles.content}>\n {children}\n </View>\n </MenuContext.Provider>\n </SheetFrame>\n );\n}\n\nexport interface DropdownMenuPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** A run of items under one label, so the separator between groups is structural. */\nexport function DropdownMenuGroup({ children, ...props }: DropdownMenuPartProps) {\n return <View {...props}>{children}</View>;\n}\n\nexport type DropdownMenuItemVariant = 'default' | 'destructive';\n\nexport interface DropdownMenuItemProps {\n variant?: DropdownMenuItemVariant;\n /** Keep the indicator gutter, so the label lines up with checkbox and radio rows. */\n indented?: boolean;\n disabled?: boolean;\n /** Chosen: the menu ticks, runs this, then closes. */\n onSelect?: () => void;\n /** The label, optionally followed by a DropdownMenuShortcut. */\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\ninterface ItemRowProps extends DropdownMenuItemProps {\n role: 'menuitem' | 'checkbox' | 'radio';\n checked?: boolean;\n indicator?: ReactNode;\n}\n\nfunction ItemRow({\n variant = 'default',\n indented = false,\n disabled = false,\n onSelect,\n role,\n checked,\n indicator,\n children,\n style,\n}: ItemRowProps) {\n const { setOpen } = useContext(MenuContext);\n styles.useVariants({ variant: variant === 'destructive' ? 'destructive' : undefined });\n return (\n <Pressable\n accessibilityRole={role}\n accessibilityState={{ disabled, checked }}\n disabled={disabled}\n onPress={() => {\n selectionTick();\n onSelect?.();\n setOpen(false);\n }}\n style={({ pressed }) => [\n styles.item,\n (indented || indicator !== undefined) && styles.indented,\n pressed && styles.pressed,\n disabled && styles.disabled,\n style,\n ]}\n >\n {indicator !== undefined ? <View style={styles.indicator}>{indicator}</View> : null}\n {wrapText(children, styles.label)}\n </Pressable>\n );\n}\n\nexport function DropdownMenuItem(props: DropdownMenuItemProps) {\n return <ItemRow role=\"menuitem\" {...props} />;\n}\n\nexport interface DropdownMenuCheckboxItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n checked?: boolean;\n onCheckedChange?: (checked: boolean) => void;\n}\n\n/** A row that toggles: the check lives in the gutter so the label never shifts. */\nexport function DropdownMenuCheckboxItem({\n checked = false,\n onCheckedChange,\n onSelect,\n ...props\n}: DropdownMenuCheckboxItemProps) {\n return (\n <ItemRow\n role=\"checkbox\"\n checked={checked}\n indicator={checked ? <CheckIcon size={12} color=\"blue\" /> : null}\n onSelect={() => {\n onCheckedChange?.(!checked);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\nexport interface DropdownMenuRadioGroupProps extends DropdownMenuPartProps {\n value?: string;\n onValueChange?: (value: string) => void;\n}\n\n/** The exclusive-choice group; pair it with DropdownMenuRadioItem. */\nexport function DropdownMenuRadioGroup({ value, onValueChange, children, ...props }: DropdownMenuRadioGroupProps) {\n return (\n <RadioContext.Provider value={{ value, onValueChange }}>\n <View accessibilityRole=\"radiogroup\" {...props}>\n {children}\n </View>\n </RadioContext.Provider>\n );\n}\n\nexport interface DropdownMenuRadioItemProps extends Omit<DropdownMenuItemProps, 'indented'> {\n value: string;\n}\n\nexport function DropdownMenuRadioItem({ value, onSelect, ...props }: DropdownMenuRadioItemProps) {\n const radio = useContext(RadioContext);\n const checked = radio.value === value;\n return (\n <ItemRow\n role=\"radio\"\n checked={checked}\n indicator={checked ? <View style={styles.radioDot} /> : null}\n onSelect={() => {\n radio.onValueChange?.(value);\n onSelect?.();\n }}\n {...props}\n />\n );\n}\n\n/** The heading over a run of items, raised to sentence case as the web's `first-letter:uppercase`. */\nexport function DropdownMenuLabel({ style, children, ...props }: TextProps) {\n const label = typeof children === 'string' ? children.charAt(0).toUpperCase() + children.slice(1) : children;\n return (\n <Text accessibilityRole=\"header\" style={[styles.menuLabel, style]} {...props}>\n {label}\n </Text>\n );\n}\n\n/** The keystroke printed at the right of a row; the row supplies the gap. */\nexport function DropdownMenuShortcut({ style, ...props }: TextProps) {\n return <Text style={[styles.shortcut, style]} {...props} />;\n}\n\nexport function DropdownMenuSeparator({ style }: { style?: StyleProp<ViewStyle> }) {\n return <View accessible={false} style={[styles.separator, style]} />;\n}\n\nconst styles = StyleSheet.create((theme) => ({\n content: { paddingVertical: theme.spacing(1) },\n item: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2),\n minHeight: MIN_ROW_HEIGHT,\n paddingHorizontal: theme.spacing(4),\n },\n indented: { paddingLeft: theme.spacing(4) + INDICATOR_GUTTER },\n indicator: {\n position: 'absolute',\n left: theme.spacing(4),\n width: theme.spacing(3),\n height: theme.spacing(3),\n alignItems: 'center',\n justifyContent: 'center',\n },\n radioDot: {\n width: RADIO_DOT,\n height: RADIO_DOT,\n borderRadius: theme.borderRadius.full,\n backgroundColor: theme.colors.blue,\n },\n pressed: { backgroundColor: theme.colors.deep },\n disabled: { opacity: DISABLED_OPACITY },\n label: {\n flexShrink: 1,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.base,\n lineHeight: theme.lineHeight.base,\n variants: {\n variant: {\n default: { color: theme.colors.hi },\n destructive: { color: theme.colors.red },\n },\n },\n },\n menuLabel: {\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(1),\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n fontWeight: theme.fontWeight.semibold,\n },\n shortcut: {\n marginLeft: 'auto',\n flexShrink: 0,\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n separator: { height: 1, marginVertical: theme.spacing(1), backgroundColor: theme.colors['border-soft'] },\n}));\n"],"mappings":";;;;;;;;;;;;;;;;AAsBA,MAAMkB,mBAAmB;AACzB,MAAMC,iBAAiB;AACvB,MAAMC,mBAAmB;AACzB,MAAMC,YAAY;AAOlB,MAAMI,cAAczB,cAAyB;CAAEuB,MAAM;CAAOC,eAAeE;AAAU,CAAC;AAOtF,MAAMI,eAAe9B,cAA0B;CAAE4B,OAAOF;CAAWG,eAAeH;AAAU,CAAC;AAU7F,SAAgBS,aAAa,EAAEZ,MAAMS,cAAc,OAAOC,cAAcC,YAA+B;CACrG,MAAM,CAACE,SAASZ,WAAWX,gBAAgBU,MAAMS,aAAaC,YAAY;CAC1E,MAAML,QAAQxB,eAAe;EAAEmB,MAAMa;EAASZ;CAAQ,IAAI,CAACY,SAASZ,OAAO,CAAC;CAC5E,OAAO,oBAAC,YAAY,UAAb;EAA6BI;EAAQM;CAA+B;AAC7E;;AAGA,SAAgBG,oBAAoB,EAAEC,SAASC,oBAAoB,GAAGC,SAAsB;CAC1F,MAAM,EAAEjB,MAAMC,YAAYrB,WAAWsB,WAAW;CAChD,OACE,oBAAC,QAAD;EACE,oBAAoB;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UzB,MAAMyB,SAASC;EACzBC,YAAY3B,MAAM2B,WAAWD;EAC7BE,UAAU,EACR9D,SAAS;GACP+D,SAAS,EAAEC,OAAO9B,MAAMkB,OAAOa,GAAG;GAClCC,aAAa,EAAEF,OAAO9B,MAAMkB,OAAOe,IAAI;EACzC,EACF;EAAC9B,mBAAA,CAAA,GAAA,CAAA;CACH;CACAT,WAAW;EACTc,mBAAmBR,MAAME,QAAQ,CAAC;EAClCD,iBAAiBD,MAAME,QAAQ,CAAC;EAChC4B,OAAO9B,MAAMkB,OAAOgB;EACpBX,YAAYtG,OAAO+E,MAAMuB,WAAWC,IAAI;EACxCC,UAAUzB,MAAMyB,SAASU;EACzBR,YAAY3B,MAAM2B,WAAWQ;EAC7BC,YAAYpC,MAAMoC,WAAWC;EAAQlC,mBAAA,CAAA,CAAA;CACvC;CACAP,UAAU;EACR0C,YAAY;EACZhB,YAAY;EACZQ,OAAO9B,MAAMkB,OAAOgB;EACpBX,YAAYtG,OAAO+E,MAAMuB,WAAWC,IAAI;EACxCC,UAAUzB,MAAMyB,SAASU;EACzBR,YAAY3B,MAAM2B,WAAWQ;EAAEhC,mBAAA,CAAA,CAAA;CACjC;CACAL,WAAW;EAAEe,QAAQ;EAAG0B,gBAAgBvC,MAAME,QAAQ,CAAC;EAAGe,iBAAiBjB,MAAMkB,OAAO;EAAcf,mBAAA,CAAA,CAAA;CAAC;AACzG,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sheet.d.mts","names":[],"sources":["../../src/components/Sheet.tsx"],"mappings":";;;;iBAwBiB;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,QAAQ,MAAM,aAAqB,cAAc,YAAY,6BAAU,IAAA;;
|
|
1
|
+
{"version":3,"file":"Sheet.d.mts","names":[],"sources":["../../src/components/Sheet.tsx"],"mappings":";;;;iBAwBiB;;EAEf;EACA;EACA,gBAAgB;EAChB,WAAW;;wBAGG,QAAQ,MAAM,aAAqB,cAAc,YAAY,6BAAU,IAAA;;wBAOvE,eAAe,YAAY,SAAS,8BAAW,IAAA;;wBAc/C,aAAa,YAAY,SAAS,8BAAW,IAAA;iBAa5C;EACf,WAAW;;EAEX,SAAS;;EAET;;EAEA;;EAEA;;;wBAIc,eAAe,UAAU,YAAmB,QAAQ,MAAM,aAAa,oCAAiB,IAAA;iBAsBvF,uBAAuB,KAAK;EAC3C,WAAW;EACX,QAAQ,UAAU;;iBAGH,yBAAyB;;EAExC;;EAEA;;wBAGc,cAAc,aAAoB,YAAsB,OAAO,aAAa,SAAS,mCAAgB,IAAA;wBAoBrG,aAAa,UAAU,SAAS,4BAAS,IAAA;wBAIzC,mBAAmB,UAAU,SAAS,4BAAS,IAAA;;wBAK/C,YAAY,OAAO,aAAa,SAAS,iCAAc,IAAA;wBAQvD,cAAc,OAAO,aAAa,SAAS,iCAAc,IAAA"}
|
|
@@ -7,7 +7,7 @@ import { SheetFrame } from "./SheetFrame.mjs";
|
|
|
7
7
|
import { View } from "react-native-unistyles/components/native/View";
|
|
8
8
|
import { Text } from "react-native-unistyles/components/native/Text";
|
|
9
9
|
import { StyleSheet } from "react-native-unistyles";
|
|
10
|
-
import { createContext, useContext } from "react";
|
|
10
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
11
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
12
12
|
|
|
13
13
|
//#region src/components/Sheet.tsx
|
|
@@ -17,11 +17,12 @@ const SheetContext = createContext({
|
|
|
17
17
|
});
|
|
18
18
|
function Sheet({ open, defaultOpen = false, onOpenChange, children }) {
|
|
19
19
|
const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);
|
|
20
|
+
const value = useMemo(() => ({
|
|
21
|
+
open: current,
|
|
22
|
+
setOpen
|
|
23
|
+
}), [current, setOpen]);
|
|
20
24
|
return /* @__PURE__ */ jsx(SheetContext.Provider, {
|
|
21
|
-
value
|
|
22
|
-
open: current,
|
|
23
|
-
setOpen
|
|
24
|
-
},
|
|
25
|
+
value,
|
|
25
26
|
children
|
|
26
27
|
});
|
|
27
28
|
}
|
|
@@ -50,24 +51,24 @@ function SheetClose({ onPress, ...props }) {
|
|
|
50
51
|
/** The sheet surface. Fields inside it switch to the sheet's own input so the keyboard lifts the sheet. */
|
|
51
52
|
function SheetContent({ children, scrollable = true, footer, keep, onDismiss }) {
|
|
52
53
|
const { open, setOpen } = useContext(SheetContext);
|
|
54
|
+
const value = useMemo(() => ({
|
|
55
|
+
open,
|
|
56
|
+
setOpen
|
|
57
|
+
}), [open, setOpen]);
|
|
58
|
+
const close = useCallback(() => setOpen(false), [setOpen]);
|
|
59
|
+
const pinned = useMemo(() => footer === void 0 ? void 0 : /* @__PURE__ */ jsx(SheetContext.Provider, {
|
|
60
|
+
value,
|
|
61
|
+
children: footer
|
|
62
|
+
}), [footer, value]);
|
|
53
63
|
return /* @__PURE__ */ jsx(SheetFrame, {
|
|
54
64
|
open,
|
|
55
|
-
onClose:
|
|
65
|
+
onClose: close,
|
|
56
66
|
scrollable,
|
|
57
67
|
keep,
|
|
58
68
|
onDismiss,
|
|
59
|
-
...
|
|
60
|
-
value: {
|
|
61
|
-
open,
|
|
62
|
-
setOpen
|
|
63
|
-
},
|
|
64
|
-
children: footer
|
|
65
|
-
}) },
|
|
69
|
+
...pinned === void 0 ? {} : { footer: pinned },
|
|
66
70
|
children: /* @__PURE__ */ jsx(SheetContext.Provider, {
|
|
67
|
-
value
|
|
68
|
-
open,
|
|
69
|
-
setOpen
|
|
70
|
-
},
|
|
71
|
+
value,
|
|
71
72
|
children
|
|
72
73
|
})
|
|
73
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Sheet.mjs","names":["createContext","ReactNode","useContext","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","CloseIcon","fontOf","useControllable","wrapText","Button","ButtonProps","SheetFrame","SheetState","open","setOpen","SheetContext","undefined","SheetProps","defaultOpen","onOpenChange","children","Sheet","current","SheetTrigger","onPress","props","event","SheetClose","SheetContentProps","footer","scrollable","keep","onDismiss","SheetContent","SheetPartProps","Omit","style","SheetHeaderProps","dismissible","closeLabel","SheetHeader","styles","header","close","SheetTitle","title","SheetDescription","description","SheetBody","body","SheetFooter","hint","create","theme","flexDirection","alignItems","gap","spacing","minWidth","height","borderBottomWidth","borderBottomColor","colors","border","paddingHorizontal","uni__dependencies","marginLeft","flexShrink","color","hi","fontFamily","sans","fontSize","lg","lineHeight","fontWeight","semibold","dim","sm","lineHeightRelaxed","paddingVertical","flexWrap","justifyContent","minHeight","borderTopWidth","borderTopColor","backgroundColor","deep","faint"],"sources":["../../src/components/Sheet.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext } from 'react';\nimport { type StyleProp, Text, type TextProps, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CloseIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\nimport { SheetFrame } from './SheetFrame';\n\n/*\n * The web Sheet as a bottom sheet: the native shape for a detail view or a\n * short form over what the reader was looking at. `side` and `width` are\n * dropped; a phone sheet rises from the bottom edge and takes the width.\n */\n\ninterface SheetState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const SheetContext = createContext<SheetState>({ open: false, setOpen: () => undefined });\n\nexport interface SheetProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the sheet keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function Sheet({ open, defaultOpen = false, onOpenChange, children }: SheetProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n return <SheetContext.Provider value={{ open: current, setOpen }}>{children}</SheetContext.Provider>;\n}\n\n/** A Button that opens the enclosing sheet. */\nexport function SheetTrigger({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(SheetContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\n/** A Button that closes the enclosing sheet. */\nexport function SheetClose({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(SheetContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(false);\n }}\n {...props}\n />\n );\n}\n\nexport interface SheetContentProps {\n children?: ReactNode;\n /** Pinned actions outside the scrolling body. The footer carries the bottom safe area. */\n footer?: ReactNode;\n /** False when an embedded SheetList owns vertical scrolling. */\n scrollable?: boolean;\n /** The sheet holds unsaved work: a prompt arriving in the conversation leaves it open with a note. */\n keep?: boolean;\n /** Runs after the native modal is dismissed, including a caller-initiated close. */\n onDismiss?: () => void;\n}\n\n/** The sheet surface. Fields inside it switch to the sheet's own input so the keyboard lifts the sheet. */\nexport function SheetContent({ children, scrollable = true, footer, keep, onDismiss }: SheetContentProps) {\n const { open, setOpen } = useContext(SheetContext);\n return (\n <SheetFrame\n open={open}\n onClose={() => setOpen(false)}\n scrollable={scrollable}\n keep={keep}\n onDismiss={onDismiss}\n {...(footer === undefined\n ? {}\n : { footer: <SheetContext.Provider value={{ open, setOpen }}>{footer}</SheetContext.Provider> })}\n >\n <SheetContext.Provider value={{ open, setOpen }}>{children}</SheetContext.Provider>\n </SheetFrame>\n );\n}\n\nexport interface SheetPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\nexport interface SheetHeaderProps extends SheetPartProps {\n /** Show the close control at the right of the strip. On by default: a sheet is dismissed, not answered. */\n dismissible?: boolean;\n /** What the close control announces. */\n closeLabel?: string;\n}\n\nexport function SheetHeader({ dismissible = true, closeLabel = 'close', style, children, ...props }: SheetHeaderProps) {\n const { setOpen } = useContext(SheetContext);\n return (\n <View style={[styles.header, style]} {...props}>\n {children}\n {dismissible ? (\n <Button\n variant=\"ghost\"\n size=\"icon\"\n accessibilityLabel={closeLabel}\n onPress={() => setOpen(false)}\n style={styles.close}\n >\n <CloseIcon size={12} color=\"faint\" />\n </Button>\n ) : null}\n </View>\n );\n}\n\nexport function SheetTitle({ style, ...props }: TextProps) {\n return <Text accessibilityRole=\"header\" numberOfLines={1} style={[styles.title, style]} {...props} />;\n}\n\nexport function SheetDescription({ style, ...props }: TextProps) {\n return <Text style={[styles.description, style]} {...props} />;\n}\n\n/** The scrolling middle; the sheet itself scrolls, so this only spaces its children. */\nexport function SheetBody({ style, children, ...props }: SheetPartProps) {\n return (\n <View style={[styles.body, style]} {...props}>\n {wrapText(children, styles.description)}\n </View>\n );\n}\n\nexport function SheetFooter({ style, children, ...props }: SheetPartProps) {\n return (\n <View style={[styles.footer, style]} {...props}>\n {wrapText(children, styles.hint)}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n header: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2.5),\n minWidth: 0,\n height: theme.spacing(11),\n borderBottomWidth: 1,\n borderBottomColor: theme.colors.border,\n paddingHorizontal: theme.spacing(4),\n },\n close: { marginLeft: 'auto' },\n title: {\n flexShrink: 1,\n color: theme.colors.hi,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.lg,\n lineHeight: theme.lineHeight.lg,\n fontWeight: theme.fontWeight.semibold,\n },\n description: {\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n body: {\n gap: theme.spacing(3),\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(3),\n },\n footer: {\n flexDirection: 'row',\n flexWrap: 'wrap',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: theme.spacing(2),\n minHeight: 34,\n borderTopWidth: 1,\n borderTopColor: theme.colors['border-soft'],\n backgroundColor: theme.colors.deep,\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(1.5),\n },\n hint: {\n color: theme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AACF,EAAE"}
|
|
1
|
+
{"version":3,"file":"Sheet.mjs","names":["createContext","ReactNode","useCallback","useContext","useMemo","StyleProp","TextProps","ViewProps","ViewStyle","StyleSheet","CloseIcon","fontOf","useControllable","wrapText","Button","ButtonProps","SheetFrame","SheetState","open","setOpen","SheetContext","undefined","SheetProps","defaultOpen","onOpenChange","children","Sheet","current","value","SheetTrigger","onPress","props","event","SheetClose","SheetContentProps","footer","scrollable","keep","onDismiss","SheetContent","close","pinned","SheetPartProps","Omit","style","SheetHeaderProps","dismissible","closeLabel","SheetHeader","styles","header","SheetTitle","title","SheetDescription","description","SheetBody","body","SheetFooter","hint","create","theme","flexDirection","alignItems","gap","spacing","minWidth","height","borderBottomWidth","borderBottomColor","colors","border","paddingHorizontal","uni__dependencies","marginLeft","flexShrink","color","hi","fontFamily","sans","fontSize","lg","lineHeight","fontWeight","semibold","dim","sm","lineHeightRelaxed","paddingVertical","flexWrap","justifyContent","minHeight","borderTopWidth","borderTopColor","backgroundColor","deep","faint"],"sources":["../../src/components/Sheet.tsx"],"sourcesContent":["import { createContext, type ReactNode, useCallback, useContext, useMemo } from 'react';\nimport { type StyleProp, Text, type TextProps, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { CloseIcon } from '../icons/icons';\nimport { fontOf } from '../lib/fonts';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\nimport { Button, type ButtonProps } from './Button';\nimport { SheetFrame } from './SheetFrame';\n\n/*\n * The web Sheet as a bottom sheet: the native shape for a detail view or a\n * short form over what the reader was looking at. `side` and `width` are\n * dropped; a phone sheet rises from the bottom edge and takes the width.\n */\n\ninterface SheetState {\n open: boolean;\n setOpen: (open: boolean) => void;\n}\n\nexport const SheetContext = createContext<SheetState>({ open: false, setOpen: () => undefined });\n\nexport interface SheetProps {\n /** Controlled mode; pair with onOpenChange. Omit it and the sheet keeps its own state. */\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n children?: ReactNode;\n}\n\nexport function Sheet({ open, defaultOpen = false, onOpenChange, children }: SheetProps) {\n const [current, setOpen] = useControllable(open, defaultOpen, onOpenChange);\n const value = useMemo(() => ({ open: current, setOpen }), [current, setOpen]);\n return <SheetContext.Provider value={value}>{children}</SheetContext.Provider>;\n}\n\n/** A Button that opens the enclosing sheet. */\nexport function SheetTrigger({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(SheetContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(true);\n }}\n {...props}\n />\n );\n}\n\n/** A Button that closes the enclosing sheet. */\nexport function SheetClose({ onPress, ...props }: ButtonProps) {\n const { setOpen } = useContext(SheetContext);\n return (\n <Button\n onPress={(event) => {\n onPress?.(event);\n setOpen(false);\n }}\n {...props}\n />\n );\n}\n\nexport interface SheetContentProps {\n children?: ReactNode;\n /** Pinned actions outside the scrolling body. The footer carries the bottom safe area. */\n footer?: ReactNode;\n /** False when an embedded SheetList owns vertical scrolling. */\n scrollable?: boolean;\n /** The sheet holds unsaved work: a prompt arriving in the conversation leaves it open with a note. */\n keep?: boolean;\n /** Runs after the native modal is dismissed, including a caller-initiated close. */\n onDismiss?: () => void;\n}\n\n/** The sheet surface. Fields inside it switch to the sheet's own input so the keyboard lifts the sheet. */\nexport function SheetContent({ children, scrollable = true, footer, keep, onDismiss }: SheetContentProps) {\n const { open, setOpen } = useContext(SheetContext);\n const value = useMemo(() => ({ open, setOpen }), [open, setOpen]);\n const close = useCallback(() => setOpen(false), [setOpen]);\n const pinned = useMemo(\n () => (footer === undefined ? undefined : <SheetContext.Provider value={value}>{footer}</SheetContext.Provider>),\n [footer, value],\n );\n return (\n <SheetFrame\n open={open}\n onClose={close}\n scrollable={scrollable}\n keep={keep}\n onDismiss={onDismiss}\n {...(pinned === undefined ? {} : { footer: pinned })}\n >\n <SheetContext.Provider value={value}>{children}</SheetContext.Provider>\n </SheetFrame>\n );\n}\n\nexport interface SheetPartProps extends Omit<ViewProps, 'children' | 'style'> {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\nexport interface SheetHeaderProps extends SheetPartProps {\n /** Show the close control at the right of the strip. On by default: a sheet is dismissed, not answered. */\n dismissible?: boolean;\n /** What the close control announces. */\n closeLabel?: string;\n}\n\nexport function SheetHeader({ dismissible = true, closeLabel = 'close', style, children, ...props }: SheetHeaderProps) {\n const { setOpen } = useContext(SheetContext);\n return (\n <View style={[styles.header, style]} {...props}>\n {children}\n {dismissible ? (\n <Button\n variant=\"ghost\"\n size=\"icon\"\n accessibilityLabel={closeLabel}\n onPress={() => setOpen(false)}\n style={styles.close}\n >\n <CloseIcon size={12} color=\"faint\" />\n </Button>\n ) : null}\n </View>\n );\n}\n\nexport function SheetTitle({ style, ...props }: TextProps) {\n return <Text accessibilityRole=\"header\" numberOfLines={1} style={[styles.title, style]} {...props} />;\n}\n\nexport function SheetDescription({ style, ...props }: TextProps) {\n return <Text style={[styles.description, style]} {...props} />;\n}\n\n/** The scrolling middle; the sheet itself scrolls, so this only spaces its children. */\nexport function SheetBody({ style, children, ...props }: SheetPartProps) {\n return (\n <View style={[styles.body, style]} {...props}>\n {wrapText(children, styles.description)}\n </View>\n );\n}\n\nexport function SheetFooter({ style, children, ...props }: SheetPartProps) {\n return (\n <View style={[styles.footer, style]} {...props}>\n {wrapText(children, styles.hint)}\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n header: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(2.5),\n minWidth: 0,\n height: theme.spacing(11),\n borderBottomWidth: 1,\n borderBottomColor: theme.colors.border,\n paddingHorizontal: theme.spacing(4),\n },\n close: { marginLeft: 'auto' },\n title: {\n flexShrink: 1,\n color: theme.colors.hi,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.lg,\n lineHeight: theme.lineHeight.lg,\n fontWeight: theme.fontWeight.semibold,\n },\n description: {\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeightRelaxed.sm,\n },\n body: {\n gap: theme.spacing(3),\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(3),\n },\n footer: {\n flexDirection: 'row',\n flexWrap: 'wrap',\n alignItems: 'center',\n justifyContent: 'space-between',\n gap: theme.spacing(2),\n minHeight: 34,\n borderTopWidth: 1,\n borderTopColor: theme.colors['border-soft'],\n backgroundColor: theme.colors.deep,\n paddingHorizontal: theme.spacing(4),\n paddingVertical: theme.spacing(1.5),\n },\n hint: {\n color: theme.colors.faint,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize['2xs'],\n lineHeight: theme.lineHeight['2xs'],\n },\n}));\n"],"mappings":";;;;;;;;;;;;;AAsBA,MAAaoB,eAAepB,cAA0B;CAAEkB,MAAM;CAAOC,eAAeE;AAAU,CAAC;AAU/F,SAAgBK,MAAM,EAAER,MAAMK,cAAc,OAAOC,cAAcC,YAAwB;CACvF,MAAM,CAACE,SAASR,WAAWP,gBAAgBM,MAAMK,aAAaC,YAAY;CAC1E,MAAMI,QAAQxB,eAAe;EAAEc,MAAMS;EAASR;CAAQ,IAAI,CAACQ,SAASR,OAAO,CAAC;CAC5E,OAAO,oBAAC,aAAa,UAAd;EAA8BS;EAAQH;CAAgC;AAC/E;;AAGA,SAAgBI,aAAa,EAAEC,SAAS,GAAGC,SAAsB;CAC/D,MAAM,EAAEZ,YAAYhB,WAAWiB,YAAY;CAC3C,OACE,oBAAC,QAAD;EACE,UAAUY,UAAU;GAClBF,UAAUE,KAAK;GACfb,QAAQ,IAAI;EACd;EACA,GAAIY;CAAM;AAGhB;;AAGA,SAAgBE,WAAW,EAAEH,SAAS,GAAGC,SAAsB;CAC7D,MAAM,EAAEZ,YAAYhB,WAAWiB,YAAY;CAC3C,OACE,oBAAC,QAAD;EACE,UAAUY,UAAU;GAClBF,UAAUE,KAAK;GACfb,QAAQ,KAAK;E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EACpBO,mBAAmBX,MAAMI,QAAQ,CAAC;EAClCuB,iBAAiB3B,MAAMI,QAAQ,CAAC;EAACQ,mBAAA,CAAA,CAAA;CACnC;CACArC,QAAQ;EACN0B,eAAe;EACf2B,UAAU;EACV1B,YAAY;EACZ2B,gBAAgB;EAChB1B,KAAKH,MAAMI,QAAQ,CAAC;EACpB0B,WAAW;EACXC,gBAAgB;EAChBC,gBAAgBhC,MAAMS,OAAO;EAC7BwB,iBAAiBjC,MAAMS,OAAOyB;EAC9BvB,mBAAmBX,MAAMI,QAAQ,CAAC;EAClCuB,iBAAiB3B,MAAMI,QAAQ,GAAG;EAACQ,mBAAA,CAAA,CAAA;CACrC;CACAd,MAAM;EACJiB,OAAOf,MAAMS,OAAO0B;EACpBlB,YAAYlE,OAAOiD,MAAMiB,WAAWC,IAAI;EACxCC,UAAUnB,MAAMmB,SAAS;EACzBE,YAAYrB,MAAMqB,WAAW;EAAMT,mBAAA,CAAA,CAAA;CACrC;AACF,EAAE"}
|
|
@@ -4,7 +4,7 @@ import { Text } from "react-native-unistyles/components/native/Text";
|
|
|
4
4
|
import { StyleSheet, useUnistyles } from "react-native-unistyles";
|
|
5
5
|
import { BackHandler, Keyboard } from "react-native";
|
|
6
6
|
import { withAlpha } from "@agimon-ai/po-web-components/nativeTheme";
|
|
7
|
-
import { useCallback, useContext, useEffect, useRef, useState } from "react";
|
|
7
|
+
import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { InsideSheetContext, dismissSheet, registerSheet, unregisterSheet } from "@agimon-ai/po-native-components/shell";
|
|
10
10
|
import { BottomSheetBackdrop, BottomSheetFooter, BottomSheetModal, BottomSheetScrollView } from "@gorhom/bottom-sheet";
|
|
@@ -13,6 +13,29 @@ import { SafeAreaInsetsContext } from "react-native-safe-area-context";
|
|
|
13
13
|
//#region src/components/SheetFrame.tsx
|
|
14
14
|
/** `bg-po-deep/70`, the overlay every web sheet and dialog draws. */
|
|
15
15
|
const BACKDROP_ALPHA_PERCENT = 70;
|
|
16
|
+
function footerHolder(initial) {
|
|
17
|
+
let footer = initial;
|
|
18
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
19
|
+
return {
|
|
20
|
+
get: () => footer,
|
|
21
|
+
set: (next) => {
|
|
22
|
+
if (next === footer) return;
|
|
23
|
+
footer = next;
|
|
24
|
+
for (const listener of listeners) listener();
|
|
25
|
+
},
|
|
26
|
+
subscribe: (listener) => {
|
|
27
|
+
listeners.add(listener);
|
|
28
|
+
return () => listeners.delete(listener);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function FooterBody({ holder }) {
|
|
33
|
+
const footer = useSyncExternalStore(holder.subscribe, holder.get);
|
|
34
|
+
return /* @__PURE__ */ jsx(InsideSheetContext.Provider, {
|
|
35
|
+
value: true,
|
|
36
|
+
children: footer
|
|
37
|
+
});
|
|
38
|
+
}
|
|
16
39
|
/**
|
|
17
40
|
* The bottom sheet both Sheet and DropdownMenu sit in: a drag handle, sized
|
|
18
41
|
* to its content, closed by dragging down, tapping the backdrop or Android
|
|
@@ -43,6 +66,10 @@ function SheetFrame({ open, onClose, onDismiss, children, scrollable = true, foo
|
|
|
43
66
|
close: () => latest.current.onClose(),
|
|
44
67
|
setNote
|
|
45
68
|
});
|
|
69
|
+
const footers = useRef(void 0);
|
|
70
|
+
footers.current ??= footerHolder(footer);
|
|
71
|
+
const holder = footers.current;
|
|
72
|
+
useLayoutEffect(() => holder.set(footer), [holder, footer]);
|
|
46
73
|
useEffect(() => {
|
|
47
74
|
openRef.current = open;
|
|
48
75
|
if (open && !dismissing.current) {
|
|
@@ -67,11 +94,11 @@ function SheetFrame({ open, onClose, onDismiss, children, scrollable = true, foo
|
|
|
67
94
|
useEffect(() => {
|
|
68
95
|
if (!open) return void 0;
|
|
69
96
|
const subscription = BackHandler.addEventListener("hardwareBackPress", () => {
|
|
70
|
-
onClose();
|
|
97
|
+
latest.current.onClose();
|
|
71
98
|
return true;
|
|
72
99
|
});
|
|
73
100
|
return () => subscription.remove();
|
|
74
|
-
}, [open
|
|
101
|
+
}, [open]);
|
|
75
102
|
const backdropColor = withAlpha(theme.colors.deep, BACKDROP_ALPHA_PERCENT);
|
|
76
103
|
const renderBackdrop = useCallback((props) => /* @__PURE__ */ jsx(BottomSheetBackdrop, {
|
|
77
104
|
...props,
|
|
@@ -81,24 +108,44 @@ function SheetFrame({ open, onClose, onDismiss, children, scrollable = true, foo
|
|
|
81
108
|
pressBehavior: "close",
|
|
82
109
|
style: [props.style, { backgroundColor: backdropColor }]
|
|
83
110
|
}), [backdropColor]);
|
|
111
|
+
const footerInset = insets?.bottom ?? 0;
|
|
84
112
|
const renderFooter = useCallback((props) => /* @__PURE__ */ jsx(BottomSheetFooter, {
|
|
85
113
|
...props,
|
|
86
114
|
children: /* @__PURE__ */ jsx(View, {
|
|
87
115
|
onLayout: (event) => setFooterHeight(event.nativeEvent.layout.height),
|
|
88
116
|
style: {
|
|
89
|
-
paddingBottom:
|
|
117
|
+
paddingBottom: footerInset,
|
|
90
118
|
backgroundColor: theme.colors.rail
|
|
91
119
|
},
|
|
92
|
-
children: /* @__PURE__ */ jsx(
|
|
93
|
-
value: true,
|
|
94
|
-
children: footer
|
|
95
|
-
})
|
|
120
|
+
children: /* @__PURE__ */ jsx(FooterBody, { holder })
|
|
96
121
|
})
|
|
97
122
|
}), [
|
|
98
|
-
|
|
99
|
-
|
|
123
|
+
holder,
|
|
124
|
+
footerInset,
|
|
100
125
|
theme.colors.rail
|
|
101
126
|
]);
|
|
127
|
+
const backgroundStyle = useMemo(() => ({
|
|
128
|
+
backgroundColor: theme.colors.rail,
|
|
129
|
+
borderRadius: theme.borderRadius.lg
|
|
130
|
+
}), [theme.colors.rail, theme.borderRadius.lg]);
|
|
131
|
+
const handleIndicatorStyle = useMemo(() => ({ backgroundColor: theme.colors.border }), [theme.colors.border]);
|
|
132
|
+
const onChange = useCallback((index) => {
|
|
133
|
+
if (index >= 0 && dismissing.current) sheet.current?.dismiss();
|
|
134
|
+
}, []);
|
|
135
|
+
const onSheetDismiss = useCallback(() => {
|
|
136
|
+
const reopen = dismissing.current && openRef.current;
|
|
137
|
+
dismissing.current = false;
|
|
138
|
+
presented.current = false;
|
|
139
|
+
dismissSheet?.(entry.current);
|
|
140
|
+
if (reopen) {
|
|
141
|
+
presented.current = true;
|
|
142
|
+
registerSheet(entry.current);
|
|
143
|
+
sheet.current?.present();
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if (openRef.current) latest.current.onClose();
|
|
147
|
+
latest.current.onDismiss?.();
|
|
148
|
+
}, []);
|
|
102
149
|
return /* @__PURE__ */ jsx(BottomSheetModal, {
|
|
103
150
|
ref: sheet,
|
|
104
151
|
stackBehavior: "push",
|
|
@@ -109,28 +156,10 @@ function SheetFrame({ open, onClose, onDismiss, children, scrollable = true, foo
|
|
|
109
156
|
android_keyboardInputMode: "adjustResize",
|
|
110
157
|
backdropComponent: renderBackdrop,
|
|
111
158
|
...footer === void 0 ? {} : { footerComponent: renderFooter },
|
|
112
|
-
backgroundStyle
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
handleIndicatorStyle: { backgroundColor: theme.colors.border },
|
|
117
|
-
onChange: (index) => {
|
|
118
|
-
if (index >= 0 && dismissing.current) sheet.current?.dismiss();
|
|
119
|
-
},
|
|
120
|
-
onDismiss: () => {
|
|
121
|
-
const reopen = dismissing.current && openRef.current;
|
|
122
|
-
dismissing.current = false;
|
|
123
|
-
presented.current = false;
|
|
124
|
-
dismissSheet?.(entry.current);
|
|
125
|
-
if (reopen) {
|
|
126
|
-
presented.current = true;
|
|
127
|
-
registerSheet(entry.current);
|
|
128
|
-
sheet.current?.present();
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
if (openRef.current) latest.current.onClose();
|
|
132
|
-
latest.current.onDismiss?.();
|
|
133
|
-
},
|
|
159
|
+
backgroundStyle,
|
|
160
|
+
handleIndicatorStyle,
|
|
161
|
+
onChange,
|
|
162
|
+
onDismiss: onSheetDismiss,
|
|
134
163
|
children: scrollable ? /* @__PURE__ */ jsxs(BottomSheetScrollView, {
|
|
135
164
|
keyboardShouldPersistTaps: "handled",
|
|
136
165
|
contentContainerStyle: [styles.content, { paddingBottom: footer === void 0 ? insets?.bottom ?? 0 : footerHeight }],
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SheetFrame.mjs","names":["dismissSheet","InsideSheetContext","OpenSheet","registerSheet","unregisterSheet","withAlpha","BottomSheetBackdrop","BottomSheetBackdropProps","BottomSheetModal","BottomSheetFooter","BottomSheetFooterProps","BottomSheetScrollView","ReactNode","useCallback","useContext","useEffect","useRef","useState","BackHandler","Keyboard","SafeAreaInsetsContext","StyleSheet","useUnistyles","fontOf","BACKDROP_ALPHA_PERCENT","SheetFrameProps","open","onClose","onDismiss","children","footer","scrollable","keep","sheetsYielded","yieldSheets","SheetFrame","theme","insets","sheet","openRef","presented","dismissing","footerHeight","setFooterHeight","note","setNote","latest","current","entry","close","dismiss","present","undefined","subscription","addEventListener","remove","backdropColor","colors","deep","renderBackdrop","props","style","backgroundColor","renderFooter","event","nativeEvent","layout","height","paddingBottom","bottom","rail","top","footerComponent","borderRadius","lg","border","index","reopen","styles","content","SheetNote","create","flexGrow","marginHorizontal","spacing","marginBottom","color","magenta","fontFamily","sans","fontSize","sm","lineHeight","uni__dependencies"],"sources":["../../src/components/SheetFrame.tsx"],"sourcesContent":["import {\n dismissSheet,\n InsideSheetContext,\n type OpenSheet,\n registerSheet,\n unregisterSheet,\n} from '@agimon-ai/po-native-components/shell';\nimport { withAlpha } from '@agimon-ai/po-web-components/nativeTheme';\nimport {\n BottomSheetBackdrop,\n type BottomSheetBackdropProps,\n BottomSheetModal,\n BottomSheetFooter,\n type BottomSheetFooterProps,\n BottomSheetScrollView,\n} from '@gorhom/bottom-sheet';\nimport { type ReactNode, useCallback, useContext, useEffect, useRef, useState } from 'react';\nimport { BackHandler, Keyboard, Text, View } from 'react-native';\nimport { SafeAreaInsetsContext } from 'react-native-safe-area-context';\nimport { StyleSheet, useUnistyles } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\n\n/** `bg-po-deep/70`, the overlay every web sheet and dialog draws. */\nconst BACKDROP_ALPHA_PERCENT = 70;\n\nexport interface SheetFrameProps {\n open: boolean;\n /** The sheet asked to close: a drag down, a backdrop tap or Android back. */\n onClose: () => void;\n onDismiss?: () => void;\n children?: ReactNode;\n footer?: ReactNode;\n /** False when the content supplies its own Gorhom virtualized scroll owner. */\n scrollable?: boolean;\n /** The sheet holds work not yet saved, so a prompt arriving leaves it open with a note instead of closing it. */\n keep?: boolean;\n}\n\nexport { sheetsYielded, yieldSheets } from '@agimon-ai/po-native-components/shell';\n\n/**\n * The bottom sheet both Sheet and DropdownMenu sit in: a drag handle, sized\n * to its content, closed by dragging down, tapping the backdrop or Android\n * back, clear of the safe area and lifted by the keyboard. Private: the public\n * parts keep bottom-sheet types out of the package API.\n */\nexport function SheetFrame({\n open,\n onClose,\n onDismiss,\n children,\n scrollable = true,\n footer,\n keep = false,\n}: SheetFrameProps) {\n const { theme } = useUnistyles();\n const insets = useContext(SafeAreaInsetsContext);\n const sheet = useRef<BottomSheetModal>(null);\n const openRef = useRef(open);\n const presented = useRef(false);\n const dismissing = useRef(false);\n const [footerHeight, setFooterHeight] = useState(0);\n const [note, setNote] = useState<string>();\n const latest = useRef({ keep, onClose, onDismiss });\n latest.current = { keep, onClose, onDismiss };\n const entry = useRef<OpenSheet>({\n keep: () => latest.current.keep,\n close: () => latest.current.onClose(),\n setNote,\n });\n\n useEffect(() => {\n openRef.current = open;\n if (open && !dismissing.current) {\n presented.current = true;\n registerSheet(entry.current);\n // The keyboard of the field behind would cover the sheet; a field inside it focuses after this.\n Keyboard.dismiss();\n sheet.current?.present();\n } else if (!open) {\n unregisterSheet(entry.current);\n setNote(undefined);\n if (presented.current && !dismissing.current) {\n // A new open waits for native dismissal, otherwise its callback closes the new request.\n dismissing.current = true;\n sheet.current?.dismiss();\n }\n }\n }, [open]);\n\n useEffect(\n () => () => {\n openRef.current = false;\n unregisterSheet(entry.current);\n dismissSheet?.(entry.current);\n },\n [],\n );\n\n useEffect(() => {\n if (!open) return undefined;\n const subscription = BackHandler.addEventListener('hardwareBackPress', () => {\n onClose();\n return true;\n });\n return () => subscription.remove();\n }, [open, onClose]);\n\n const backdropColor = withAlpha(theme.colors.deep, BACKDROP_ALPHA_PERCENT);\n const renderBackdrop = useCallback(\n (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n appearsOnIndex={0}\n disappearsOnIndex={-1}\n opacity={1}\n pressBehavior=\"close\"\n style={[props.style, { backgroundColor: backdropColor }]}\n />\n ),\n [backdropColor],\n );\n\n const renderFooter = useCallback(\n (props: BottomSheetFooterProps) => (\n <BottomSheetFooter {...props}>\n <View\n onLayout={(event) => setFooterHeight(event.nativeEvent.layout.height)}\n style={{ paddingBottom: insets?.bottom ?? 0, backgroundColor: theme.colors.rail }}\n >\n <InsideSheetContext.Provider value>{footer}</InsideSheetContext.Provider>\n </View>\n </BottomSheetFooter>\n ),\n [footer, insets?.bottom, theme.colors.rail],\n );\n\n return (\n <BottomSheetModal\n ref={sheet}\n stackBehavior=\"push\"\n enablePanDownToClose\n topInset={insets?.top ?? 0}\n keyboardBehavior=\"interactive\"\n keyboardBlurBehavior=\"restore\"\n android_keyboardInputMode=\"adjustResize\"\n backdropComponent={renderBackdrop}\n {...(footer === undefined ? {} : { footerComponent: renderFooter })}\n backgroundStyle={{ backgroundColor: theme.colors.rail, borderRadius: theme.borderRadius.lg }}\n handleIndicatorStyle={{ backgroundColor: theme.colors.border }}\n onChange={(index) => {\n // present() mounts on the next frame, so an earlier dismiss() may have had nothing to close.\n if (index >= 0 && dismissing.current) sheet.current?.dismiss();\n }}\n // A sheet the caller closed is already shut; only a close the sheet started is reported.\n onDismiss={() => {\n const reopen = dismissing.current && openRef.current;\n dismissing.current = false;\n presented.current = false;\n dismissSheet?.(entry.current);\n if (reopen) {\n presented.current = true;\n registerSheet(entry.current);\n sheet.current?.present();\n return;\n }\n if (openRef.current) latest.current.onClose();\n latest.current.onDismiss?.();\n }}\n >\n {scrollable ? (\n <BottomSheetScrollView\n keyboardShouldPersistTaps=\"handled\"\n contentContainerStyle={[\n styles.content,\n { paddingBottom: footer === undefined ? (insets?.bottom ?? 0) : footerHeight },\n ]}\n >\n {note ? <SheetNote note={note} /> : null}\n <InsideSheetContext.Provider value>{children}</InsideSheetContext.Provider>\n </BottomSheetScrollView>\n ) : (\n <>\n {note ? <SheetNote note={note} /> : null}\n <InsideSheetContext.Provider value>{children}</InsideSheetContext.Provider>\n </>\n )}\n </BottomSheetModal>\n );\n}\n\n/** A gentle rose line: the person is asked something below, never told to hurry. */\nfunction SheetNote({ note }: { note: string }) {\n return (\n <Text style={styles.note} accessibilityRole=\"alert\">\n {note}\n </Text>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n content: { flexGrow: 1 },\n note: {\n marginHorizontal: theme.spacing(4),\n marginBottom: theme.spacing(2),\n color: theme.colors.magenta,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n}));\n"],"mappings":";;;;;;;;;;;;;;AAwBA,MAAMwB,yBAAyB;;;;;;;AAuB/B,SAAgBW,WAAW,EACzBT,MACAC,SACAC,WACAC,UACAE,aAAa,MACbD,QACAE,OAAO,SACW;CAClB,MAAM,EAAEI,UAAUd,aAAa;CAC/B,MAAMe,SAASvB,WAAWM,qBAAqB;CAC/C,MAAMkB,QAAQtB,OAAyB,IAAI;CAC3C,MAAMuB,UAAUvB,OAAOU,IAAI;CAC3B,MAAMc,YAAYxB,OAAO,KAAK;CAC9B,MAAMyB,aAAazB,OAAO,KAAK;CAC/B,MAAM,CAAC0B,cAAcC,mBAAmB1B,SA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OAAOC,SACP,EAAEX,eAAetC,WAAWsB,SAAaf,QAAQgC,UAAU,IAAK3B,aAAa,CAAC;aAJlF,CAOGE,OAAO,oBAAC,WAAD,EAAiBA,KAAK,KAAM,MACpC,oBAAC,mBAAmB,UAApB;IAA6B;IAAOf;GAAsC,EACrD;OAEvB,4CACGe,OAAO,oBAAC,WAAD,EAAiBA,KAAK,KAAM,MACpC,oBAAC,mBAAmB,UAApB;GAA6B;GAAOf;EAAsC,EAC5E;CAEc;AAEtB;;AAGA,SAASmD,UAAU,EAAEpC,QAA0B;CAC7C,OACE,oBAAC,MAAD;EAAM,OAAOkC,OAAOlC;EAAM,mBAAkB;YACzCA;CACG;AAEV;AAEA,MAAMkC,SAASzD,WAAW4D,QAAQ7C,WAAW;CAC3C2C,SAAS,EAAEG,UAAU,EAAE;CACvBtC,MAAM;EACJuC,kBAAkB/C,MAAMgD,QAAQ,CAAC;EACjCC,cAAcjD,MAAMgD,QAAQ,CAAC;EAC7BE,OAAOlD,MAAMqB,OAAO8B;EACpBC,YAAYjE,OAAOa,MAAMoD,WAAWC,IAAI;EACxCC,UAAUtD,MAAMsD,SAASC;EACzBC,YAAYxD,MAAMwD,WAAWD;EAAEE,mBAAA,CAAA,CAAA;CACjC;AACF,EAAE"}
|
|
1
|
+
{"version":3,"file":"SheetFrame.mjs","names":["dismissSheet","InsideSheetContext","OpenSheet","registerSheet","unregisterSheet","withAlpha","BottomSheetBackdrop","BottomSheetBackdropProps","BottomSheetModal","BottomSheetFooter","BottomSheetFooterProps","BottomSheetScrollView","ReactNode","useCallback","useContext","useEffect","useLayoutEffect","useMemo","useRef","useState","useSyncExternalStore","BackHandler","Keyboard","SafeAreaInsetsContext","StyleSheet","useUnistyles","fontOf","BACKDROP_ALPHA_PERCENT","SheetFrameProps","open","onClose","onDismiss","children","footer","scrollable","keep","sheetsYielded","yieldSheets","FooterHolder","get","set","subscribe","listener","footerHolder","initial","listeners","Set","next","add","delete","FooterBody","holder","SheetFrame","theme","insets","sheet","openRef","presented","dismissing","footerHeight","setFooterHeight","note","setNote","latest","current","entry","close","footers","undefined","dismiss","present","subscription","addEventListener","remove","backdropColor","colors","deep","renderBackdrop","props","style","backgroundColor","footerInset","bottom","renderFooter","event","nativeEvent","layout","height","paddingBottom","rail","backgroundStyle","borderRadius","lg","handleIndicatorStyle","border","onChange","index","onSheetDismiss","reopen","top","footerComponent","styles","content","SheetNote","create","flexGrow","marginHorizontal","spacing","marginBottom","color","magenta","fontFamily","sans","fontSize","sm","lineHeight","uni__dependencies"],"sources":["../../src/components/SheetFrame.tsx"],"sourcesContent":["import {\n dismissSheet,\n InsideSheetContext,\n type OpenSheet,\n registerSheet,\n unregisterSheet,\n} from '@agimon-ai/po-native-components/shell';\nimport { withAlpha } from '@agimon-ai/po-web-components/nativeTheme';\nimport {\n BottomSheetBackdrop,\n type BottomSheetBackdropProps,\n BottomSheetModal,\n BottomSheetFooter,\n type BottomSheetFooterProps,\n BottomSheetScrollView,\n} from '@gorhom/bottom-sheet';\nimport {\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n useSyncExternalStore,\n} from 'react';\nimport { BackHandler, Keyboard, Text, View } from 'react-native';\nimport { SafeAreaInsetsContext } from 'react-native-safe-area-context';\nimport { StyleSheet, useUnistyles } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\n\n/** `bg-po-deep/70`, the overlay every web sheet and dialog draws. */\nconst BACKDROP_ALPHA_PERCENT = 70;\n\nexport interface SheetFrameProps {\n open: boolean;\n /** The sheet asked to close: a drag down, a backdrop tap or Android back. */\n onClose: () => void;\n onDismiss?: () => void;\n children?: ReactNode;\n footer?: ReactNode;\n /** False when the content supplies its own Gorhom virtualized scroll owner. */\n scrollable?: boolean;\n /** The sheet holds work not yet saved, so a prompt arriving leaves it open with a note instead of closing it. */\n keep?: boolean;\n}\n\nexport { sheetsYielded, yieldSheets } from '@agimon-ai/po-native-components/shell';\n\n/** The latest footer, read by a footer component whose identity never changes while the sheet lives. */\ninterface FooterHolder {\n get: () => ReactNode;\n set: (footer: ReactNode) => void;\n subscribe: (listener: () => void) => () => void;\n}\n\nfunction footerHolder(initial: ReactNode): FooterHolder {\n let footer = initial;\n const listeners = new Set<() => void>();\n return {\n get: () => footer,\n set: (next) => {\n if (next === footer) return;\n footer = next;\n for (const listener of listeners) listener();\n },\n subscribe: (listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n };\n}\n\nfunction FooterBody({ holder }: { holder: FooterHolder }) {\n const footer = useSyncExternalStore(holder.subscribe, holder.get);\n return <InsideSheetContext.Provider value>{footer}</InsideSheetContext.Provider>;\n}\n\n/**\n * The bottom sheet both Sheet and DropdownMenu sit in: a drag handle, sized\n * to its content, closed by dragging down, tapping the backdrop or Android\n * back, clear of the safe area and lifted by the keyboard. Private: the public\n * parts keep bottom-sheet types out of the package API.\n */\nexport function SheetFrame({\n open,\n onClose,\n onDismiss,\n children,\n scrollable = true,\n footer,\n keep = false,\n}: SheetFrameProps) {\n const { theme } = useUnistyles();\n const insets = useContext(SafeAreaInsetsContext);\n const sheet = useRef<BottomSheetModal>(null);\n const openRef = useRef(open);\n const presented = useRef(false);\n const dismissing = useRef(false);\n const [footerHeight, setFooterHeight] = useState(0);\n const [note, setNote] = useState<string>();\n const latest = useRef({ keep, onClose, onDismiss });\n latest.current = { keep, onClose, onDismiss };\n const entry = useRef<OpenSheet>({\n keep: () => latest.current.keep,\n close: () => latest.current.onClose(),\n setNote,\n });\n // Gorhom takes the footer as a component; a new one each render would remount its fields mid-typing.\n const footers = useRef<FooterHolder>(undefined);\n footers.current ??= footerHolder(footer);\n const holder = footers.current;\n useLayoutEffect(() => holder.set(footer), [holder, footer]);\n\n useEffect(() => {\n openRef.current = open;\n if (open && !dismissing.current) {\n presented.current = true;\n registerSheet(entry.current);\n // The keyboard of the field behind would cover the sheet; a field inside it focuses after this.\n Keyboard.dismiss();\n sheet.current?.present();\n } else if (!open) {\n unregisterSheet(entry.current);\n setNote(undefined);\n if (presented.current && !dismissing.current) {\n // A new open waits for native dismissal, otherwise its callback closes the new request.\n dismissing.current = true;\n sheet.current?.dismiss();\n }\n }\n }, [open]);\n\n useEffect(\n () => () => {\n openRef.current = false;\n unregisterSheet(entry.current);\n dismissSheet?.(entry.current);\n },\n [],\n );\n\n useEffect(() => {\n if (!open) return undefined;\n const subscription = BackHandler.addEventListener('hardwareBackPress', () => {\n latest.current.onClose();\n return true;\n });\n return () => subscription.remove();\n }, [open]);\n\n const backdropColor = withAlpha(theme.colors.deep, BACKDROP_ALPHA_PERCENT);\n const renderBackdrop = useCallback(\n (props: BottomSheetBackdropProps) => (\n <BottomSheetBackdrop\n {...props}\n appearsOnIndex={0}\n disappearsOnIndex={-1}\n opacity={1}\n pressBehavior=\"close\"\n style={[props.style, { backgroundColor: backdropColor }]}\n />\n ),\n [backdropColor],\n );\n\n const footerInset = insets?.bottom ?? 0;\n const renderFooter = useCallback(\n (props: BottomSheetFooterProps) => (\n <BottomSheetFooter {...props}>\n <View\n onLayout={(event) => setFooterHeight(event.nativeEvent.layout.height)}\n style={{ paddingBottom: footerInset, backgroundColor: theme.colors.rail }}\n >\n <FooterBody holder={holder} />\n </View>\n </BottomSheetFooter>\n ),\n [holder, footerInset, theme.colors.rail],\n );\n const backgroundStyle = useMemo(\n () => ({ backgroundColor: theme.colors.rail, borderRadius: theme.borderRadius.lg }),\n [theme.colors.rail, theme.borderRadius.lg],\n );\n const handleIndicatorStyle = useMemo(() => ({ backgroundColor: theme.colors.border }), [theme.colors.border]);\n const onChange = useCallback((index: number) => {\n // present() mounts on the next frame, so an earlier dismiss() may have had nothing to close.\n if (index >= 0 && dismissing.current) sheet.current?.dismiss();\n }, []);\n // A sheet the caller closed is already shut; only a close the sheet started is reported.\n const onSheetDismiss = useCallback(() => {\n const reopen = dismissing.current && openRef.current;\n dismissing.current = false;\n presented.current = false;\n dismissSheet?.(entry.current);\n if (reopen) {\n presented.current = true;\n registerSheet(entry.current);\n sheet.current?.present();\n return;\n }\n if (openRef.current) latest.current.onClose();\n latest.current.onDismiss?.();\n }, []);\n\n return (\n <BottomSheetModal\n ref={sheet}\n stackBehavior=\"push\"\n enablePanDownToClose\n topInset={insets?.top ?? 0}\n keyboardBehavior=\"interactive\"\n keyboardBlurBehavior=\"restore\"\n android_keyboardInputMode=\"adjustResize\"\n backdropComponent={renderBackdrop}\n {...(footer === undefined ? {} : { footerComponent: renderFooter })}\n backgroundStyle={backgroundStyle}\n handleIndicatorStyle={handleIndicatorStyle}\n onChange={onChange}\n onDismiss={onSheetDismiss}\n >\n {scrollable ? (\n <BottomSheetScrollView\n keyboardShouldPersistTaps=\"handled\"\n contentContainerStyle={[\n styles.content,\n { paddingBottom: footer === undefined ? (insets?.bottom ?? 0) : footerHeight },\n ]}\n >\n {note ? <SheetNote note={note} /> : null}\n <InsideSheetContext.Provider value>{children}</InsideSheetContext.Provider>\n </BottomSheetScrollView>\n ) : (\n <>\n {note ? <SheetNote note={note} /> : null}\n <InsideSheetContext.Provider value>{children}</InsideSheetContext.Provider>\n </>\n )}\n </BottomSheetModal>\n );\n}\n\n/** A gentle rose line: the person is asked something below, never told to hurry. */\nfunction SheetNote({ note }: { note: string }) {\n return (\n <Text style={styles.note} accessibilityRole=\"alert\">\n {note}\n </Text>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n content: { flexGrow: 1 },\n note: {\n marginHorizontal: theme.spacing(4),\n marginBottom: theme.spacing(2),\n color: theme.colors.magenta,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n}));\n"],"mappings":";;;;;;;;;;;;;;AAkCA,MAAM2B,yBAAyB;AAwB/B,SAASgB,aAAaC,SAAkC;CACtD,IAAIX,SAASW;CACb,MAAMC,4BAAY,IAAIC,IAAgB;CACtC,OAAO;EACLP,WAAWN;EACXO,MAAMO,SAAS;GACb,IAAIA,SAASd,QAAQ;GACrBA,SAASc;G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AApB;IAA6B;IAAO7B;GAAsC,EACrD;OAEvB,4CACG6B,OAAO,oBAAC,WAAD,EAAiBA,KAAK,KAAM,MACpC,oBAAC,mBAAmB,UAApB;GAA6B;GAAO7B;EAAsC,EAC5E;CAEc;AAEtB;;AAGA,SAASuE,UAAU,EAAE1C,QAA0B;CAC7C,OACE,oBAAC,MAAD;EAAM,OAAOwC,OAAOxC;EAAM,mBAAkB;YACzCA;CACG;AAEV;AAEA,MAAMwC,SAAS7E,WAAWgF,QAAQnD,WAAW;CAC3CiD,SAAS,EAAEG,UAAU,EAAE;CACvB5C,MAAM;EACJ6C,kBAAkBrD,MAAMsD,QAAQ,CAAC;EACjCC,cAAcvD,MAAMsD,QAAQ,CAAC;EAC7BE,OAAOxD,MAAMsB,OAAOmC;EACpBC,YAAYrF,OAAO2B,MAAM0D,WAAWC,IAAI;EACxCC,UAAU5D,MAAM4D,SAASC;EACzBC,YAAY9D,MAAM8D,WAAWD;EAAEE,mBAAA,CAAA,CAAA;CACjC;AACF,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.d.mts","names":[],"sources":["../../src/components/Tabs.tsx"],"mappings":";;;iBA8BiB,kBAAkB,KAAK;;EAEtC;EACA;EACA,iBAAiB;EACjB,WAAW;EACX,QAAQ,UAAU;;wBAGJ,OAAO,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,4BAAS,IAAA;
|
|
1
|
+
{"version":3,"file":"Tabs.d.mts","names":[],"sources":["../../src/components/Tabs.tsx"],"mappings":";;;iBA8BiB,kBAAkB,KAAK;;EAEtC;EACA;EACA,iBAAiB;EACjB,WAAW;EACX,QAAQ,UAAU;;wBAGJ,OAAO,OAAO,cAAc,eAAe,UAAU,UAAU,SAAS,4BAAS,IAAA;iBAgBhF;EACf,WAAW;EACX,QAAQ,UAAU;;;wBAIJ,WAAW,UAAU,SAAS,gCAAa,IAAA;iBAc1C;EACf;EACA;;EAEA,WAAW;EACX;EACA,QAAQ,UAAU;;wBAGJ,cAAc,OAAO,UAAkB,UAAU,oBAAoB,SAAS,mCAAgB,IAAA;iBA2B7F,yBAAyB,KAAK;EAC7C;EACA,WAAW;EACX,QAAQ,UAAU;;;wBAIJ,cAAc,OAAO,UAAU,UAAU,SAAS,mCAAgB,IAAA;iBAUjE;;EAEf;EACA,WAAW;EACX,QAAQ,UAAU;;;wBAIJ,WAAW,QAAQ,UAAU,SAAS,gCAAa,IAAA"}
|
package/dist/components/Tabs.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { useControllable } from "../lib/useControllable.mjs";
|
|
|
5
5
|
import { View } from "react-native-unistyles/components/native/View";
|
|
6
6
|
import { Text } from "react-native-unistyles/components/native/Text";
|
|
7
7
|
import { StyleSheet } from "react-native-unistyles";
|
|
8
|
-
import { createContext, useContext } from "react";
|
|
8
|
+
import { createContext, useContext, useMemo } from "react";
|
|
9
9
|
import { jsx } from "react/jsx-runtime";
|
|
10
10
|
import { Pressable } from "react-native-unistyles/components/native/Pressable";
|
|
11
11
|
import { ScrollView } from "react-native-unistyles/components/native/ScrollView";
|
|
@@ -23,11 +23,12 @@ const TabsContext = createContext({
|
|
|
23
23
|
const TabActiveContext = createContext(false);
|
|
24
24
|
function Tabs({ value, defaultValue, onValueChange, children, style, ...props }) {
|
|
25
25
|
const [current, setValue] = useControllable(value, defaultValue, onValueChange);
|
|
26
|
+
const context = useMemo(() => ({
|
|
27
|
+
value: current,
|
|
28
|
+
setValue
|
|
29
|
+
}), [current, setValue]);
|
|
26
30
|
return /* @__PURE__ */ jsx(TabsContext.Provider, {
|
|
27
|
-
value:
|
|
28
|
-
value: current,
|
|
29
|
-
setValue
|
|
30
|
-
},
|
|
31
|
+
value: context,
|
|
31
32
|
children: /* @__PURE__ */ jsx(View, {
|
|
32
33
|
style: [styles.tabs, style],
|
|
33
34
|
...props,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tabs.mjs","names":["createContext","ReactNode","useContext","StyleProp","ViewProps","ViewStyle","StyleSheet","fontOf","selectionTick","useControllable","wrapText","TAB_HEIGHT","MIN_TAP_TARGET","DISABLED_OPACITY","BADGE_SIZE","TabsState","value","setValue","TabsContext","undefined","TabActiveContext","TabsProps","Omit","defaultValue","onValueChange","children","style","Tabs","props","current","next","styles","tabs","TabsListProps","TabsList","listScroll","list","TabsTriggerProps","disabled","accessibilityLabel","TabsTrigger","active","_styles","useVariants","selected","pressed","tab","label","labelPressed","TabsContentProps","TabsContent","content","contentText","TabBadgeProps","TabBadge","inherited","_styles2","badge","badgeText","create","theme","gap","spacing","uni__dependencies","flexGrow","flexDirection","alignItems","minHeight","minWidth","borderRadius","DEFAULT","paddingHorizontal","paddingVertical","variants","true","backgroundColor","colors","false","panel","opacity","fontFamily","sans","fontSize","base","lineHeight","color","green","fontWeight","semibold","dim","medium","hi","sm","justifyContent","height","full","idle","rail"],"sources":["../../src/components/Tabs.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext } from 'react';\nimport { Pressable, ScrollView, type StyleProp, Text, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\nimport { selectionTick } from '../lib/haptics';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\n\n/*\n * The web Tabs on a horizontal ScrollView: a strip that scrolls when the tabs\n * outgrow the screen, the active tab in a green tint, and a selection tick on\n * each change. The panels swap in place.\n */\n\n/** `min-h-6`, padded to Apple's 44pt tap target by hitSlop. */\nconst TAB_HEIGHT = 24;\nconst MIN_TAP_TARGET = 44;\nconst DISABLED_OPACITY = 0.4;\nconst BADGE_SIZE = 15;\n\ninterface TabsState {\n value: string | undefined;\n setValue: (value: string) => void;\n}\n\nconst TabsContext = createContext<TabsState>({ value: undefined, setValue: () => undefined });\n/** Whether the enclosing trigger is active, so a TabBadge inverts without being told. */\nconst TabActiveContext = createContext(false);\n\nexport interface TabsProps extends Omit<ViewProps, 'children' | 'style'> {\n /** Controlled mode; pair with onValueChange. Omit it and the tabs keep their own state. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\nexport function Tabs({ value, defaultValue, onValueChange, children, style, ...props }: TabsProps) {\n const [current, setValue] = useControllable<string | undefined>(\n value,\n defaultValue,\n onValueChange as ((next: string | undefined) => void) | undefined,\n );\n return (\n <TabsContext.Provider value={{ value: current, setValue }}>\n <View style={[styles.tabs, style]} {...props}>\n {children}\n </View>\n </TabsContext.Provider>\n );\n}\n\nexport interface TabsListProps {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** The tab strip; it scrolls sideways when the tabs outgrow it. */\nexport function TabsList({ children, style }: TabsListProps) {\n return (\n <ScrollView\n horizontal\n showsHorizontalScrollIndicator={false}\n accessibilityRole=\"tablist\"\n style={styles.listScroll}\n contentContainerStyle={[styles.list, style]}\n >\n {children}\n </ScrollView>\n );\n}\n\nexport interface TabsTriggerProps {\n value: string;\n disabled?: boolean;\n /** The label; a bare string is drawn in the tab's type, and a TabBadge may follow it. */\n children?: ReactNode;\n accessibilityLabel?: string;\n style?: StyleProp<ViewStyle>;\n}\n\nexport function TabsTrigger({ value, disabled = false, children, accessibilityLabel, style }: TabsTriggerProps) {\n const tabs = useContext(TabsContext);\n const active = tabs.value === value;\n styles.useVariants({ active });\n return (\n <Pressable\n accessibilityRole=\"tab\"\n accessibilityLabel={accessibilityLabel}\n accessibilityState={{ selected: active, disabled }}\n disabled={disabled}\n hitSlop={(MIN_TAP_TARGET - TAB_HEIGHT) / 2}\n onPress={() => {\n if (active) return;\n selectionTick();\n tabs.setValue(value);\n }}\n style={({ pressed }) => [styles.tab, pressed && !active && styles.pressed, disabled && styles.disabled, style]}\n >\n {({ pressed }) => (\n <TabActiveContext.Provider value={active}>\n {wrapText(children, [styles.label, pressed && !active && styles.labelPressed])}\n </TabActiveContext.Provider>\n )}\n </Pressable>\n );\n}\n\nexport interface TabsContentProps extends Omit<ViewProps, 'children' | 'style'> {\n value: string;\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** The panel for one tab; only the active one renders. */\nexport function TabsContent({ value, children, style, ...props }: TabsContentProps) {\n const tabs = useContext(TabsContext);\n if (tabs.value !== value) return null;\n return (\n <View style={[styles.content, style]} {...props}>\n {wrapText(children, styles.contentText)}\n </View>\n );\n}\n\nexport interface TabBadgeProps {\n /** Defaults to the enclosing tab's state: it inverts on the active tab so it stays readable on the tint. */\n active?: boolean;\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** The count beside a tab's label. */\nexport function TabBadge({ active, children, style }: TabBadgeProps) {\n const inherited = useContext(TabActiveContext);\n styles.useVariants({ badge: (active ?? inherited) ? 'active' : 'idle' });\n return (\n <View style={[styles.badge, style]}>\n <Text style={styles.badgeText}>{children}</Text>\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n tabs: { gap: theme.spacing(2) },\n listScroll: { flexGrow: 0 },\n list: { flexDirection: 'row', alignItems: 'center', gap: theme.spacing(1) },\n tab: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(1.5),\n minHeight: TAB_HEIGHT,\n minWidth: TAB_HEIGHT,\n borderRadius: theme.borderRadius.DEFAULT,\n paddingHorizontal: theme.spacing(2),\n paddingVertical: theme.spacing(1),\n variants: {\n active: {\n true: { backgroundColor: theme.colors['tint-green'] },\n false: {},\n },\n },\n },\n pressed: { backgroundColor: theme.colors.panel },\n disabled: { opacity: DISABLED_OPACITY },\n label: {\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.base,\n lineHeight: theme.lineHeight.base,\n variants: {\n active: {\n true: { color: theme.colors.green, fontWeight: theme.fontWeight.semibold },\n false: { color: theme.colors.dim, fontWeight: theme.fontWeight.medium },\n },\n },\n },\n labelPressed: { color: theme.colors.hi },\n content: { flexGrow: 1, minHeight: 0 },\n contentText: {\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n badge: {\n alignItems: 'center',\n justifyContent: 'center',\n height: BADGE_SIZE,\n minWidth: BADGE_SIZE,\n borderRadius: theme.borderRadius.full,\n paddingHorizontal: theme.spacing(1),\n variants: {\n badge: {\n active: { backgroundColor: theme.colors.green },\n idle: { backgroundColor: theme.colors.panel },\n },\n },\n },\n badgeText: {\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize['2xs'],\n lineHeight: theme.lineHeight['2xs'],\n fontWeight: theme.fontWeight.semibold,\n variants: {\n badge: {\n active: { color: theme.colors.rail },\n idle: { color: theme.colors.dim },\n },\n },\n },\n}));\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAMW,aAAa;AAEnB,MAAME,mBAAmB;AACzB,MAAMC,aAAa;AAOnB,MAAMI,cAAclB,cAAyB;CAAEgB,OAAOG;CAAWF,gBAAgBE;AAAU,CAAC;;AAE5F,MAAMC,mBAAmBpB,cAAc,KAAK;AAW5C,SAAgB2B,KAAK,EAAEX,OAAOO,cAAcC,eAAeC,UAAUC,OAAO,GAAGE,SAAoB;CACjG,MAAM,CAACC,SAASZ,YAAYR,gBAC1BO,OACAO,cACAC,aACF;CACA,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAO;GAAER,OAAOa;GAASZ;EAAS;YACtD,oBAAC,MAAD;GAAM,OAAO,CAACc,OAAOC,MAAMN,KAAK;GAAG,GAAIE;GACpCH;EACG;CACc;AAE1B;;AAQA,SAAgBS,SAAS,EAAET,UAAUC,SAAwB;CAC3D,OACE,oBAAC,YAAD;EACE;EACA,gCAAgC;EAChC,mBAAkB;EAClB,OAAOK,OAAOI;EACd,uBAAuB,CAACJ,OAAOK,MAAMV,KAAK;EAEzCD;CACS;AAEhB;AAWA,SAAgBe,YAAY,EAAExB,OAAOsB,WAAW,OAAOb,UAAUc,oBAAoBb,SAA2B;CAC9G,MAAMM,OAAO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AAYzE,OAAOqD,MAAMoB,WAAWC,IAAI;EACxCC,UAAUtB,MAAMsB,SAASU;EACzBR,YAAYxB,MAAMwB,WAAWQ;EAAE7B,mBAAA,CAAA,CAAA;CACjC;CACAN,OAAO;EACLS,YAAY;EACZ2B,gBAAgB;EAChBC,QAAQhF;EACRsD,UAAUtD;EACVuD,cAAcT,MAAMS,aAAa0B;EACjCxB,mBAAmBX,MAAME,QAAQ,CAAC;EAClCW,UAAU,EACRhB,OAAO;GACLhB,QAAQ,EAAEkC,iBAAiBf,MAAMgB,OAAOU,MAAM;GAC9CU,MAAM,EAAErB,iBAAiBf,MAAMgB,OAAOE,MAAM;EAC9C,EACF;EAACf,mBAAA,CAAA,GAAA,CAAA;CACH;CACAL,WAAW;EACTsB,YAAYzE,OAAOqD,MAAMoB,WAAWC,IAAI;EACxCC,UAAUtB,MAAMsB,SAAS;EACzBE,YAAYxB,MAAMwB,WAAW;EAC7BG,YAAY3B,MAAM2B,WAAWC;EAC7Bf,UAAU,EACRhB,OAAO;GACLhB,QAAQ,EAAE4C,OAAOzB,MAAMgB,OAAOqB,KAAK;GACnCD,MAAM,EAAEX,OAAOzB,MAAMgB,OAAOa,IAAI;EAClC,EACF;EAAC1B,mBAAA,CAAA,GAAA,CAAA;CACH;AACF,EAAE"}
|
|
1
|
+
{"version":3,"file":"Tabs.mjs","names":["createContext","ReactNode","useContext","useMemo","StyleProp","ViewProps","ViewStyle","StyleSheet","fontOf","selectionTick","useControllable","wrapText","TAB_HEIGHT","MIN_TAP_TARGET","DISABLED_OPACITY","BADGE_SIZE","TabsState","value","setValue","TabsContext","undefined","TabActiveContext","TabsProps","Omit","defaultValue","onValueChange","children","style","Tabs","props","current","next","context","styles","tabs","TabsListProps","TabsList","listScroll","list","TabsTriggerProps","disabled","accessibilityLabel","TabsTrigger","active","_styles","useVariants","selected","pressed","tab","label","labelPressed","TabsContentProps","TabsContent","content","contentText","TabBadgeProps","TabBadge","inherited","_styles2","badge","badgeText","create","theme","gap","spacing","uni__dependencies","flexGrow","flexDirection","alignItems","minHeight","minWidth","borderRadius","DEFAULT","paddingHorizontal","paddingVertical","variants","true","backgroundColor","colors","false","panel","opacity","fontFamily","sans","fontSize","base","lineHeight","color","green","fontWeight","semibold","dim","medium","hi","sm","justifyContent","height","full","idle","rail"],"sources":["../../src/components/Tabs.tsx"],"sourcesContent":["import { createContext, type ReactNode, useContext, useMemo } from 'react';\nimport { Pressable, ScrollView, type StyleProp, Text, View, type ViewProps, type ViewStyle } from 'react-native';\nimport { StyleSheet } from 'react-native-unistyles';\n\nimport { fontOf } from '../lib/fonts';\nimport { selectionTick } from '../lib/haptics';\nimport { useControllable } from '../lib/useControllable';\nimport { wrapText } from '../lib/wrapText';\n\n/*\n * The web Tabs on a horizontal ScrollView: a strip that scrolls when the tabs\n * outgrow the screen, the active tab in a green tint, and a selection tick on\n * each change. The panels swap in place.\n */\n\n/** `min-h-6`, padded to Apple's 44pt tap target by hitSlop. */\nconst TAB_HEIGHT = 24;\nconst MIN_TAP_TARGET = 44;\nconst DISABLED_OPACITY = 0.4;\nconst BADGE_SIZE = 15;\n\ninterface TabsState {\n value: string | undefined;\n setValue: (value: string) => void;\n}\n\nconst TabsContext = createContext<TabsState>({ value: undefined, setValue: () => undefined });\n/** Whether the enclosing trigger is active, so a TabBadge inverts without being told. */\nconst TabActiveContext = createContext(false);\n\nexport interface TabsProps extends Omit<ViewProps, 'children' | 'style'> {\n /** Controlled mode; pair with onValueChange. Omit it and the tabs keep their own state. */\n value?: string;\n defaultValue?: string;\n onValueChange?: (value: string) => void;\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\nexport function Tabs({ value, defaultValue, onValueChange, children, style, ...props }: TabsProps) {\n const [current, setValue] = useControllable<string | undefined>(\n value,\n defaultValue,\n onValueChange as ((next: string | undefined) => void) | undefined,\n );\n const context = useMemo(() => ({ value: current, setValue }), [current, setValue]);\n return (\n <TabsContext.Provider value={context}>\n <View style={[styles.tabs, style]} {...props}>\n {children}\n </View>\n </TabsContext.Provider>\n );\n}\n\nexport interface TabsListProps {\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** The tab strip; it scrolls sideways when the tabs outgrow it. */\nexport function TabsList({ children, style }: TabsListProps) {\n return (\n <ScrollView\n horizontal\n showsHorizontalScrollIndicator={false}\n accessibilityRole=\"tablist\"\n style={styles.listScroll}\n contentContainerStyle={[styles.list, style]}\n >\n {children}\n </ScrollView>\n );\n}\n\nexport interface TabsTriggerProps {\n value: string;\n disabled?: boolean;\n /** The label; a bare string is drawn in the tab's type, and a TabBadge may follow it. */\n children?: ReactNode;\n accessibilityLabel?: string;\n style?: StyleProp<ViewStyle>;\n}\n\nexport function TabsTrigger({ value, disabled = false, children, accessibilityLabel, style }: TabsTriggerProps) {\n const tabs = useContext(TabsContext);\n const active = tabs.value === value;\n styles.useVariants({ active });\n return (\n <Pressable\n accessibilityRole=\"tab\"\n accessibilityLabel={accessibilityLabel}\n accessibilityState={{ selected: active, disabled }}\n disabled={disabled}\n hitSlop={(MIN_TAP_TARGET - TAB_HEIGHT) / 2}\n onPress={() => {\n if (active) return;\n selectionTick();\n tabs.setValue(value);\n }}\n style={({ pressed }) => [styles.tab, pressed && !active && styles.pressed, disabled && styles.disabled, style]}\n >\n {({ pressed }) => (\n <TabActiveContext.Provider value={active}>\n {wrapText(children, [styles.label, pressed && !active && styles.labelPressed])}\n </TabActiveContext.Provider>\n )}\n </Pressable>\n );\n}\n\nexport interface TabsContentProps extends Omit<ViewProps, 'children' | 'style'> {\n value: string;\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** The panel for one tab; only the active one renders. */\nexport function TabsContent({ value, children, style, ...props }: TabsContentProps) {\n const tabs = useContext(TabsContext);\n if (tabs.value !== value) return null;\n return (\n <View style={[styles.content, style]} {...props}>\n {wrapText(children, styles.contentText)}\n </View>\n );\n}\n\nexport interface TabBadgeProps {\n /** Defaults to the enclosing tab's state: it inverts on the active tab so it stays readable on the tint. */\n active?: boolean;\n children?: ReactNode;\n style?: StyleProp<ViewStyle>;\n}\n\n/** The count beside a tab's label. */\nexport function TabBadge({ active, children, style }: TabBadgeProps) {\n const inherited = useContext(TabActiveContext);\n styles.useVariants({ badge: (active ?? inherited) ? 'active' : 'idle' });\n return (\n <View style={[styles.badge, style]}>\n <Text style={styles.badgeText}>{children}</Text>\n </View>\n );\n}\n\nconst styles = StyleSheet.create((theme) => ({\n tabs: { gap: theme.spacing(2) },\n listScroll: { flexGrow: 0 },\n list: { flexDirection: 'row', alignItems: 'center', gap: theme.spacing(1) },\n tab: {\n flexDirection: 'row',\n alignItems: 'center',\n gap: theme.spacing(1.5),\n minHeight: TAB_HEIGHT,\n minWidth: TAB_HEIGHT,\n borderRadius: theme.borderRadius.DEFAULT,\n paddingHorizontal: theme.spacing(2),\n paddingVertical: theme.spacing(1),\n variants: {\n active: {\n true: { backgroundColor: theme.colors['tint-green'] },\n false: {},\n },\n },\n },\n pressed: { backgroundColor: theme.colors.panel },\n disabled: { opacity: DISABLED_OPACITY },\n label: {\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.base,\n lineHeight: theme.lineHeight.base,\n variants: {\n active: {\n true: { color: theme.colors.green, fontWeight: theme.fontWeight.semibold },\n false: { color: theme.colors.dim, fontWeight: theme.fontWeight.medium },\n },\n },\n },\n labelPressed: { color: theme.colors.hi },\n content: { flexGrow: 1, minHeight: 0 },\n contentText: {\n color: theme.colors.dim,\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize.sm,\n lineHeight: theme.lineHeight.sm,\n },\n badge: {\n alignItems: 'center',\n justifyContent: 'center',\n height: BADGE_SIZE,\n minWidth: BADGE_SIZE,\n borderRadius: theme.borderRadius.full,\n paddingHorizontal: theme.spacing(1),\n variants: {\n badge: {\n active: { backgroundColor: theme.colors.green },\n idle: { backgroundColor: theme.colors.panel },\n },\n },\n },\n badgeText: {\n fontFamily: fontOf(theme.fontFamily.sans),\n fontSize: theme.fontSize['2xs'],\n lineHeight: theme.lineHeight['2xs'],\n fontWeight: theme.fontWeight.semibold,\n variants: {\n badge: {\n active: { color: theme.colors.rail },\n idle: { color: theme.colors.dim },\n },\n },\n },\n}));\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAMY,aAAa;AAEnB,MAAME,mBAAmB;AACzB,MAAMC,aAAa;AAOnB,MAAMI,cAAcnB,cAAyB;CAAEiB,OAAOG;CAAWF,gBAAgBE;AAAU,CAAC;;AAE5F,MAAMC,mBAAmBrB,cAAc,KAAK;AAW5C,SAAgB4B,KAAK,EAAEX,OAAOO,cAAcC,eAAeC,UAAUC,OAAO,GAAGE,SAAoB;CACjG,MAAM,CAACC,SAASZ,YAAYR,gBAC1BO,OACAO,cACAC,aACF;CACA,MAAMO,UAAU7B,eAAe;EAAEc,OAAOa;EAASZ;CAAS,IAAI,CAACY,SAASZ,QAAQ,CAAC;CACjF,OACE,oBAAC,YAAY,UAAb;EAAsB,OAAOc;YAC3B,oBAAC,MAAD;GAAM,OAAO,CAACC,OAAOC,MAAMP,KAAK;GAAG,GAAIE;GACpCH;EACG;CACc;AAE1B;;AAQA,SAAgBU,SAAS,EAAEV,UAAUC,SAAwB;CAC3D,OACE,oBAAC,YAAD;EACE;EACA,gCAAgC;EAChC,mBAAkB;EAClB,OAAOM,OAAOI;EACd,uBAAuB,CAACJ,OAAOK,MAAMX,KAAK;EAEzCD;CACS;AAEhB;AAWA,SAAgBgB,YAAY,EAAEzB,OAAOuB,WAAW,OAAOd,UAAUe,oBAAoBd,SAA2B;CAC9G,MAAMO,OAAOhC,WAAWiB,WAAW;CACnC,MAAMwB,SAAST,KAAKjB,UAAUA;CAAM,MAAA2B,UAAAX;CAAA;EAAA,MAAAA,SAAAW,QAAAC,YACjB,EAAEF,OAAO,CAAC;EAC7B,OACE,oBAAC,WAAD;GACE,mBAAkB;GACEF;GACpB,oBAAoB;IAAEK,UAAUH;IAAQH;GAAS;GACvCA;GACV,SAAS;GACT,eAAe;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BAAmBX,MAAME,QAAQ,CAAC;EAClCW,UAAU,EACRhB,OAAO;GACLhB,QAAQ,EAAEkC,iBAAiBf,MAAMgB,OAAOU,MAAM;GAC9CU,MAAM,EAAErB,iBAAiBf,MAAMgB,OAAOE,MAAM;EAC9C,EACF;EAACf,mBAAA,CAAA,GAAA,CAAA;CACH;CACAL,WAAW;EACTsB,YAAY1E,OAAOsD,MAAMoB,WAAWC,IAAI;EACxCC,UAAUtB,MAAMsB,SAAS;EACzBE,YAAYxB,MAAMwB,WAAW;EAC7BG,YAAY3B,MAAM2B,WAAWC;EAC7Bf,UAAU,EACRhB,OAAO;GACLhB,QAAQ,EAAE4C,OAAOzB,MAAMgB,OAAOqB,KAAK;GACnCD,MAAM,EAAEX,OAAOzB,MAAMgB,OAAOa,IAAI;EAClC,EACF;EAAC1B,mBAAA,CAAA,GAAA,CAAA;CACH;AACF,EAAE"}
|
|
@@ -1,20 +1,28 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useCallback, useRef, useState } from "react";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/useControllable.ts
|
|
4
4
|
/**
|
|
5
5
|
* Controlled-or-uncontrolled state, the Radix convention every compound
|
|
6
6
|
* component follows: given `value` the caller owns it, otherwise the
|
|
7
7
|
* component keeps its own copy seeded from `defaultValue`. `onChange` fires
|
|
8
|
-
* either way.
|
|
8
|
+
* either way. The setter keeps one identity, so a context carrying it does not
|
|
9
|
+
* re-render its consumers on every render of the owner.
|
|
9
10
|
*/
|
|
10
11
|
function useControllable(value, defaultValue, onChange) {
|
|
11
12
|
const [own, setOwn] = useState(defaultValue);
|
|
12
13
|
const current = value === void 0 ? own : value;
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
onChange
|
|
14
|
+
const latest = useRef({
|
|
15
|
+
value,
|
|
16
|
+
onChange
|
|
17
|
+
});
|
|
18
|
+
latest.current = {
|
|
19
|
+
value,
|
|
20
|
+
onChange
|
|
16
21
|
};
|
|
17
|
-
return [current,
|
|
22
|
+
return [current, useCallback((next) => {
|
|
23
|
+
if (latest.current.value === void 0) setOwn(next);
|
|
24
|
+
latest.current.onChange?.(next);
|
|
25
|
+
}, [])];
|
|
18
26
|
}
|
|
19
27
|
|
|
20
28
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useControllable.mjs","names":[],"sources":["../../src/lib/useControllable.ts"],"sourcesContent":["import { useState } from 'react';\n\n/**\n * Controlled-or-uncontrolled state, the Radix convention every compound\n * component follows: given `value` the caller owns it, otherwise the\n * component keeps its own copy seeded from `defaultValue`. `onChange` fires\n * either way.\n */\nexport function useControllable<T>(\n value: T | undefined,\n defaultValue: T,\n onChange: ((next: T) => void) | undefined,\n): [T, (next: T) => void] {\n const [own, setOwn] = useState(defaultValue);\n const current = value === undefined ? own : value;\n const set = (next: T) => {\n if (value === undefined) setOwn(next);\n onChange?.(next);\n };\n return [current, set];\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useControllable.mjs","names":[],"sources":["../../src/lib/useControllable.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\n/**\n * Controlled-or-uncontrolled state, the Radix convention every compound\n * component follows: given `value` the caller owns it, otherwise the\n * component keeps its own copy seeded from `defaultValue`. `onChange` fires\n * either way. The setter keeps one identity, so a context carrying it does not\n * re-render its consumers on every render of the owner.\n */\nexport function useControllable<T>(\n value: T | undefined,\n defaultValue: T,\n onChange: ((next: T) => void) | undefined,\n): [T, (next: T) => void] {\n const [own, setOwn] = useState(defaultValue);\n const current = value === undefined ? own : value;\n const latest = useRef({ value, onChange });\n latest.current = { value, onChange };\n const set = useCallback((next: T) => {\n if (latest.current.value === undefined) setOwn(next);\n latest.current.onChange?.(next);\n }, []);\n return [current, set];\n}\n"],"mappings":";;;;;;;;;;AASA,SAAgB,gBACd,OACA,cACA,UACwB;CACxB,MAAM,CAAC,KAAK,UAAU,SAAS,YAAY;CAC3C,MAAM,UAAU,UAAU,SAAY,MAAM;CAC5C,MAAM,SAAS,OAAO;EAAE;EAAO;CAAS,CAAC;CACzC,OAAO,UAAU;EAAE;EAAO;CAAS;CAKnC,OAAO,CAAC,SAJI,aAAa,SAAY;EACnC,IAAI,OAAO,QAAQ,UAAU,QAAW,OAAO,IAAI;EACnD,OAAO,QAAQ,WAAW,IAAI;CAChC,GAAG,CAAC,CACe,CAAC;AACtB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agimon-ai/po-native-components",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.130",
|
|
4
4
|
"description": "Shared React Native components for Po and its native plugins: the web component library's look and API on native parts, tuned to the Po palette.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
"access": "public"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@agimon-ai/po-web-components": "0.0.0-alpha.
|
|
52
|
+
"@agimon-ai/po-web-components": "0.0.0-alpha.130"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@agimon-ai/po-build": "0.0.0-alpha.
|
|
56
|
-
"@agimon-ai/po-core": "0.0.0-alpha.
|
|
57
|
-
"@agimon-ai/vibe-lint-plugin-po-web": "0.0.0-alpha.
|
|
55
|
+
"@agimon-ai/po-build": "0.0.0-alpha.130",
|
|
56
|
+
"@agimon-ai/po-core": "0.0.0-alpha.130",
|
|
57
|
+
"@agimon-ai/vibe-lint-plugin-po-web": "0.0.0-alpha.130",
|
|
58
58
|
"@babel/core": "7.29.7",
|
|
59
59
|
"@expo/vector-icons": "15.1.1",
|
|
60
60
|
"@fontsource-variable/ibm-plex-sans": "5.3.0",
|