@chakra-ui/button
Version:
A React component that is a base button.
103 lines (100 loc) • 3.52 kB
JavaScript
'use client'
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/button-group.tsx
var button_group_exports = {};
__export(button_group_exports, {
ButtonGroup: () => ButtonGroup
});
module.exports = __toCommonJS(button_group_exports);
var import_system = require("@chakra-ui/system");
var import_shared_utils = require("@chakra-ui/shared-utils");
var import_react = require("react");
// src/button-context.ts
var import_react_context = require("@chakra-ui/react-context");
var [ButtonGroupProvider, useButtonGroup] = (0, import_react_context.createContext)({
strict: false,
name: "ButtonGroupContext"
});
// src/button-group.tsx
var import_jsx_runtime = require("react/jsx-runtime");
var attachedStyles = {
horizontal: {
"> *:first-of-type:not(:last-of-type)": { borderEndRadius: 0 },
"> *:not(:first-of-type):not(:last-of-type)": { borderRadius: 0 },
"> *:not(:first-of-type):last-of-type": { borderStartRadius: 0 }
},
vertical: {
"> *:first-of-type:not(:last-of-type)": { borderBottomRadius: 0 },
"> *:not(:first-of-type):not(:last-of-type)": { borderRadius: 0 },
"> *:not(:first-of-type):last-of-type": { borderTopRadius: 0 }
}
};
var gapStyles = {
horizontal: (spacing) => ({
"& > *:not(style) ~ *:not(style)": { marginStart: spacing }
}),
vertical: (spacing) => ({
"& > *:not(style) ~ *:not(style)": { marginTop: spacing }
})
};
var ButtonGroup = (0, import_system.forwardRef)(
function ButtonGroup2(props, ref) {
const {
size,
colorScheme,
variant,
className,
spacing = "0.5rem",
isAttached,
isDisabled,
orientation = "horizontal",
...rest
} = props;
const _className = (0, import_shared_utils.cx)("chakra-button__group", className);
const context = (0, import_react.useMemo)(
() => ({ size, colorScheme, variant, isDisabled }),
[size, colorScheme, variant, isDisabled]
);
let groupStyles = {
display: "inline-flex",
...isAttached ? attachedStyles[orientation] : gapStyles[orientation](spacing)
};
const isVertical = orientation === "vertical";
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ButtonGroupProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_system.chakra.div,
{
ref,
role: "group",
__css: groupStyles,
className: _className,
"data-attached": isAttached ? "" : void 0,
"data-orientation": orientation,
flexDir: isVertical ? "column" : void 0,
...rest
}
) });
}
);
ButtonGroup.displayName = "ButtonGroup";
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ButtonGroup
});
//# sourceMappingURL=button-group.js.map