UNPKG

@crossed/demo

Version:

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

108 lines (107 loc) 4.03 kB
import { jsx, jsxs } from "react/jsx-runtime"; import { createButton, createList, useButtonGroupCollection, useButtonGroupContext } from "@crossed/primitive"; import { styled } from "@crossed/styled"; import { YBox } from "@crossed/ui"; import { forwardRef } from "react"; import { Pressable, Text, View } from "react-native"; const Root = styled(Pressable, { "className": ["flex flex-col", "px-3 py-1.5"], ":hover": { className: ["bg-neutral-800 cursor-pointer"] }, ":focus": { className: ["z-10"] }, ":disabled": { className: ["bg-neutral-800 opacity-30 cursor-not-allowed"] }, ":active": { className: ["bg-neutral-700"] }, "variants": { grouped: { true: { className: ["rounded-none"] } }, first: { true: { className: ["rounded-l"] } }, last: { true: { className: ["rounded-r"] } }, orientation: { horizontal: { className: [] }, vertical: { className: [] } } }, "compoundVariants": [ { orientation: "vertical", first: true, className: ["rounded-b-none rounded-t"] }, { orientation: "vertical", last: true, className: ["rounded-t-none rounded-b"] } ] }); const Button = createButton({ Text: styled(Text, { className: ["text-white", "text-base"] }), Element: styled(View, { className: ["flex"] }), Group: styled(View, { className: ["flex", "border border-neutral-800 rounded-lg"], defaultVariants: { orientation: "vertical" }, variants: { orientation: { horizontal: { className: ["flex-row"] }, vertical: { className: ["flex-col"] } } } }), Root: forwardRef((props, ref) => { const { grouped, orientation } = useButtonGroupContext(); const getItems = useButtonGroupCollection(); const index = getItems().findIndex(({ id }) => id === props.id); return /* @__PURE__ */ jsx( Root, { grouped, first: index === 0, last: index === getItems().length - 1, orientation, ...props, ref } ); }) }); const List = createList({ Root: (props) => /* @__PURE__ */ jsx(Button.Group, { ...props, orientation: props.orientation ?? "vertical" }), Item: Button, SubTitle: styled(Text, { className: ["text-neutral-500 text-sm"] }), Title: Button.Text, Divider: styled(View, { className: ["border-t border-neutral-800"] }), Label: styled(Text, { className: ["text-neutral-500 text-base font-bold", "px-3 py-1.5"], variants: { danger: { true: { className: ["text-red-800"] } } } }) }); const CreateListPressableDemo = () => { return /* @__PURE__ */ jsx(YBox, { space: "md", children: /* @__PURE__ */ jsxs(List, { children: [ /* @__PURE__ */ jsxs(List.Item, { children: [ /* @__PURE__ */ jsx(List.Title, { children: "Number 1" }), /* @__PURE__ */ jsx(List.SubTitle, { children: "Description Number 1" }) ] }), /* @__PURE__ */ jsxs(List.Item, { children: [ /* @__PURE__ */ jsx(List.Title, { children: "Number 2" }), /* @__PURE__ */ jsx(List.SubTitle, { children: "Description 2" }) ] }), /* @__PURE__ */ jsxs(List.Item, { disabled: true, children: [ /* @__PURE__ */ jsx(List.Title, { children: "Number 3" }), /* @__PURE__ */ jsx(List.SubTitle, { children: "Number 3 have description" }) ] }), /* @__PURE__ */ jsxs(List.Item, { hoverTheme: false, activeTheme: false, focusable: false, children: [ /* @__PURE__ */ jsx(List.Title, { children: "Number 4" }), /* @__PURE__ */ jsx(List.SubTitle, { children: "Number 4 have description" }) ] }), /* @__PURE__ */ jsx(List.Divider, {}), /* @__PURE__ */ jsx(List.Label, { danger: true, children: "Danger zone" }), /* @__PURE__ */ jsxs(List.Item, { hoverTheme: false, activeTheme: false, focusable: false, children: [ /* @__PURE__ */ jsx(List.Title, { children: "Number 5" }), /* @__PURE__ */ jsx(List.SubTitle, { children: "Number 5 have description" }) ] }) ] }) }); }; export { CreateListPressableDemo }; //# sourceMappingURL=pressable.js.map