UNPKG

@crossed/demo

Version:

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

103 lines (102 loc) 3.35 kB
import { jsx, jsxs } from "react/jsx-runtime"; import { createButton, useButtonGroupCollection, useButtonGroupContext } from "@crossed/primitive"; import { styled } from "@crossed/styled"; import { UilBitcoinCircle, YBox } from "@crossed/ui"; import { Pressable, Text, View } from "react-native"; import { forwardRef } from "react"; const Group = styled(View, { className: ["flex"], variants: { orientation: { horizontal: { className: ["flex-row"] }, vertical: { className: ["flex-col"] } } }, defaultVariants: { orientation: "horizontal" } }); const Root = styled(Pressable, { "className": [ "flex flex-row items-center gap-2", "bg-blue-500", "rounded", "px-3 py-2" ], ":hover": { className: ["bg-blue-400"] }, ":focus": { className: ["z-10"] }, "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-none rounded-t"] }, { orientation: "vertical", last: true, className: ["rounded-none rounded-b"] } ] }); const TextButton = styled(Text, { className: ["text-white", "text-base"] }); const Element = styled(View, { className: ["flex"] }); const Button = createButton({ Group, 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 } ); }), Text: TextButton, Element }); const CreateButtonGroupDemo = () => { return /* @__PURE__ */ jsxs(YBox, { className: "gap-4 items-center", children: [ /* @__PURE__ */ jsxs(Button.Group, { orientation: "horizontal", children: [ /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }), /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }), /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }) ] }), /* @__PURE__ */ jsxs(Button.Group, { orientation: "vertical", children: [ /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }), /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }), /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }) ] }), /* @__PURE__ */ jsx(Button, { children: /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) }), /* @__PURE__ */ jsxs(Button, { children: [ /* @__PURE__ */ jsx(Button.Element, { children: /* @__PURE__ */ jsx(UilBitcoinCircle, {}) }), /* @__PURE__ */ jsx(Button.Text, { children: "text button" }) ] }) ] }); }; export { CreateButtonGroupDemo }; //# sourceMappingURL=group.js.map