UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

123 lines (120 loc) 4.3 kB
'use client'; import React from 'react'; import { getSize, getFontSize, getRadius } from '../../core/utils/get-size/get-size.mjs'; import { createVarsResolver } from '../../core/styles-api/create-vars-resolver/create-vars-resolver.mjs'; import 'clsx'; import '@mantine/hooks'; import '../../core/MantineProvider/Mantine.context.mjs'; import '../../core/MantineProvider/default-theme.mjs'; import '../../core/MantineProvider/MantineProvider.mjs'; import '../../core/MantineProvider/MantineThemeProvider/MantineThemeProvider.mjs'; import { useProps } from '../../core/MantineProvider/use-props/use-props.mjs'; import { useStyles } from '../../core/styles-api/use-styles/use-styles.mjs'; import { Box } from '../../core/Box/Box.mjs'; import { polymorphicFactory } from '../../core/factory/polymorphic-factory.mjs'; import '../../core/DirectionProvider/DirectionProvider.mjs'; import { Loader } from '../Loader/Loader.mjs'; import { UnstyledButton } from '../UnstyledButton/UnstyledButton.mjs'; import { ButtonGroup } from './ButtonGroup/ButtonGroup.mjs'; import classes from './Button.module.css.mjs'; const defaultProps = {}; const varsResolver = createVarsResolver( (theme, { radius, color, gradient, variant, size, justify, autoContrast }) => { const colors = theme.variantColorResolver({ color: color || theme.primaryColor, theme, gradient, variant: variant || "filled", autoContrast }); return { root: { "--button-justify": justify, "--button-height": getSize(size, "button-height"), "--button-padding-x": getSize(size, "button-padding-x"), "--button-fz": size?.includes("compact") ? getFontSize(size.replace("compact-", "")) : getFontSize(size), "--button-radius": radius === void 0 ? void 0 : getRadius(radius), "--button-bg": color || variant ? colors.background : void 0, "--button-hover": color || variant ? colors.hover : void 0, "--button-color": colors.color, "--button-bd": color || variant ? colors.border : void 0, "--button-hover-color": color || variant ? colors.hoverColor : void 0 } }; } ); const Button = polymorphicFactory((_props, ref) => { const props = useProps("Button", defaultProps, _props); const { style, vars, className, color, disabled, children, leftSection, rightSection, fullWidth, variant, radius, loading, loaderProps, gradient, classNames, styles, unstyled, "data-disabled": dataDisabled, autoContrast, mod, ...others } = props; const getStyles = useStyles({ name: "Button", props, classes, className, style, classNames, styles, unstyled, vars, varsResolver }); const hasLeftSection = !!leftSection; const hasRightSection = !!rightSection; return /* @__PURE__ */ React.createElement( UnstyledButton, { ref, ...getStyles("root", { active: !disabled && !loading && !dataDisabled }), unstyled, variant, disabled: disabled || loading, mod: [ { disabled: disabled || dataDisabled, loading, block: fullWidth, "with-left-section": hasLeftSection, "with-right-section": hasRightSection }, mod ], ...others }, /* @__PURE__ */ React.createElement(Box, { component: "span", ...getStyles("loader"), "aria-hidden": true }, /* @__PURE__ */ React.createElement( Loader, { color: "var(--button-color)", size: "calc(var(--button-height) / 1.8)", ...loaderProps } )), /* @__PURE__ */ React.createElement("span", { ...getStyles("inner") }, leftSection && /* @__PURE__ */ React.createElement(Box, { component: "span", ...getStyles("section"), mod: { position: "left" } }, leftSection), /* @__PURE__ */ React.createElement(Box, { component: "span", mod: { loading }, ...getStyles("label") }, children), rightSection && /* @__PURE__ */ React.createElement(Box, { component: "span", ...getStyles("section"), mod: { position: "right" } }, rightSection)) ); }); Button.classes = classes; Button.displayName = "@mantine/core/Button"; Button.Group = ButtonGroup; export { Button }; //# sourceMappingURL=Button.mjs.map