UNPKG

@codeworker.br/govbr-tw-react

Version:

Biblioteca de componentes React usando Tailwind CSS que implementa o Padrão Digital de Governo.

39 lines (38 loc) 2.76 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import { jsx as _jsx } from "react/jsx-runtime"; import { forwardRef } from "react"; import BASE_CLASSNAMES from "../../config/baseClassNames"; import { cn } from "../../libs/utils"; import { ButtonGroupProvider, useButtonGroupContext } from "./context"; import buttonGroupVariants from "./variants"; export const ButtonGroup = forwardRef((_a, ref) => { var _b, _c; var { className, children, orientation, separated, variant, density, size, disabled, role = "group" } = _a, props = __rest(_a, ["className", "children", "orientation", "separated", "variant", "density", "size", "disabled", "role"]); const parentContext = useButtonGroupContext(); const resolvedOrientation = (_b = orientation !== null && orientation !== void 0 ? orientation : parentContext === null || parentContext === void 0 ? void 0 : parentContext.orientation) !== null && _b !== void 0 ? _b : "horizontal"; const isSeparated = separated !== null && separated !== void 0 ? separated : false; const contextValue = { variant: variant !== null && variant !== void 0 ? variant : parentContext === null || parentContext === void 0 ? void 0 : parentContext.variant, density: density !== null && density !== void 0 ? density : parentContext === null || parentContext === void 0 ? void 0 : parentContext.density, size: size !== null && size !== void 0 ? size : parentContext === null || parentContext === void 0 ? void 0 : parentContext.size, disabled: disabled !== null && disabled !== void 0 ? disabled : parentContext === null || parentContext === void 0 ? void 0 : parentContext.disabled, separated: isSeparated, orientation: resolvedOrientation, level: ((_c = parentContext === null || parentContext === void 0 ? void 0 : parentContext.level) !== null && _c !== void 0 ? _c : 0) + 1, }; return (_jsx(ButtonGroupProvider, { value: contextValue, children: _jsx("div", Object.assign({ ref: ref, role: role, "data-orientation": resolvedOrientation, className: cn(buttonGroupVariants({ orientation: resolvedOrientation, separated: isSeparated, }), BASE_CLASSNAMES.buttonGroup.root, className) }, props, { children: children })) })); }); ButtonGroup.displayName = "ButtonGroup";