UNPKG

@crossed/ui

Version:

A universal & performant styling library for React Native, Next.js & React

141 lines (140 loc) 3.47 kB
"use client"; import { jsx } from "react/jsx-runtime"; import { composeStyles, createStyles, inlineStyle, withReactive } from "@crossed/styled"; import { Text } from "../typography/Text"; import { YBox } from "../layout/YBox"; import { Divider as D } from "../layout/Divider"; import { withStaticProperties } from "@crossed/core"; import { cloneElement, forwardRef, isValidElement, memo, useCallback } from "react"; import { Pressable } from "react-native"; const rootStyle = createStyles(({ colors, space }) => ({ default: { base: { backgroundColor: colors.background.secondary, borderRadius: 12 } }, border: { base: { borderWidth: 1, borderColor: colors.border.primary } }, padded: { base: { padding: space.xs } } })); const itemStyles = createStyles((t) => ({ padding: { base: { paddingTop: t.space.xs, paddingBottom: t.space.xs, paddingLeft: t.space.md, paddingRight: t.space.md } }, item: { "base": { display: "flex", flexDirection: "column", // alignItems: 'center', paddingHorizontal: t.space.md, justifyContent: "center", // height: 42, borderWidth: 0, borderRadius: 12 }, ":hover": { backgroundColor: t.colors.background.hover }, ":active": { backgroundColor: t.colors.background.active }, "web": { base: { transition: "all 170ms ease" }, ":focus-visible": { outlineColor: t.colors.border.brand } } } })); const MenuRoot = memo( forwardRef( ({ padded = true, bordered = true, ...props }, ref) => { return /* @__PURE__ */ jsx( YBox, { role: "list", alignItems: "stretch", space: padded ? "xxs" : void 0, ...props, style: composeStyles( rootStyle.default, bordered && rootStyle.border, padded && rootStyle.padded, props.style ), ref } ); } ) ); MenuRoot.displayName = "MenuList"; const MenuDivider = (props) => /* @__PURE__ */ jsx(D, { ...props }); MenuDivider.displayName = "MenuList.Divider"; const MenuItem = withReactive( forwardRef( ({ asChild, style, children, ...props }, ref) => { const styleCallback = useCallback( ({ pressed }) => composeStyles(itemStyles.item, itemStyles.padding, style).rnw({ active: pressed }).style, [style] ); return asChild && isValidElement(children) ? cloneElement(children, { style: styleCallback, role: "listitem" }) : /* @__PURE__ */ jsx(Pressable, { role: "listitem", ...props, style: styleCallback, ref, children }); } ) ); MenuItem.displayName = "MenuList.Item"; const MenuLabel = ({ style, ...props }) => /* @__PURE__ */ jsx( Text, { ...props, style: composeStyles( itemStyles.padding, inlineStyle(() => ({ base: { marginTop: 0 } })), style ) } ); MenuLabel.displayName = "MenuList.Label"; const MenuTitle = (props) => /* @__PURE__ */ jsx(Text, { color: "secondary", ...props }); MenuTitle.displayName = "MenuList.Title"; const MenuList = withStaticProperties(MenuRoot, { Divider: MenuDivider, Item: MenuItem, Label: MenuLabel, Title: MenuTitle }); MenuList.displayName = "MenuList"; export { MenuDivider, MenuItem, MenuLabel, MenuList, MenuTitle }; //# sourceMappingURL=MenuList.js.map