react-pdf-builder
Version:
Build beautiful PDF documents in React.
66 lines (65 loc) • 3.51 kB
JavaScript
;
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Button = void 0;
const react_1 = __importDefault(require("react"));
const ThemeBuilder_1 = require("../../themes/ThemeBuilder");
const Div_1 = require("../basics/Div");
const ThemedLink_1 = require("../basics/ThemedLink");
const sanitizeChildren_1 = require("../children/sanitizeChildren");
const PDFThemeProvider_1 = require("../theme/PDFThemeProvider");
/**
* Read the [full documentation for Button](https://justinmahar.github.io/react-pdf-builder/?path=/docs/documentation-components-button--docs)
*/
const Button = (_a) => {
var _b, _c;
var { children, className, style } = _a, props = __rest(_a, ["children", "className", "style"]);
const theme = (0, PDFThemeProvider_1.usePDFThemeContext)();
const themeProps = theme === null || theme === void 0 ? void 0 : theme.buttonProps;
const mergedProps = Object.assign(Object.assign({}, themeProps), props);
const styleInnate = {
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center',
};
const swatch = (_b = mergedProps.swatch) !== null && _b !== void 0 ? _b : 'primary';
const styleOverride = {};
if (swatch && swatch !== 'link') {
styleOverride.backgroundColor = ThemeBuilder_1.ThemeBuilder.getSwatchColor(swatch, theme.colorScheme);
styleOverride.color = ThemeBuilder_1.ThemeBuilder.getContrastColor(swatch, theme.colorScheme);
}
else if (swatch === 'link') {
styleOverride.backgroundColor = '#FFFFFF00';
styleOverride.color = (_c = mergedProps.linkColor) !== null && _c !== void 0 ? _c : ThemeBuilder_1.ThemeBuilder.getSwatchColor('blue', theme.colorScheme);
}
if (mergedProps.pill) {
styleOverride.borderRadius = '50%';
}
const hasHref = typeof mergedProps.href !== 'undefined';
const themedChildren = (0, sanitizeChildren_1.sanitizeChildren)(children, hasHref ? { textDecoration: 'no-underline' } : undefined);
const themeClassName = themeProps.className;
const themeClassNameStyles = ThemeBuilder_1.ThemeBuilder.getStylesForClassName(themeClassName, theme.classNames);
const classNameStyles = ThemeBuilder_1.ThemeBuilder.getStylesForClassName(className, theme.classNames);
const buttonElement = (react_1.default.createElement(Div_1.Div, Object.assign({}, mergedProps, { style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, styleInnate), themeClassNameStyles), themeProps === null || themeProps === void 0 ? void 0 : themeProps.style), styleOverride), classNameStyles), style) }), themedChildren));
if (hasHref) {
return react_1.default.createElement(ThemedLink_1.ThemedLink, { href: mergedProps.href }, buttonElement);
}
else {
return buttonElement;
}
};
exports.Button = Button;