@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
86 lines (85 loc) • 3.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Graphic = exports.base64Encoded = exports.graphicImageStencil = exports.graphicStencil = exports.graphicStyles = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const common_1 = require("@workday/canvas-kit-react/common");
const Svg_1 = require("./Svg");
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
/**
* @deprecated `graphicStyles` will be removed in in a future version as a part of implementation of stencils and new tokens. Consider to use `graphicStencil` instead.
*/
const graphicStyles = ({ width, height, grow }) => {
if (grow) {
return {
width: '100%',
'& svg': {
width: '100%',
height: '100%',
},
};
}
if (width) {
return {
'& svg': {
width,
height: '100%',
},
};
}
else if (height) {
return {
'& svg': {
height,
width: '100%',
},
};
}
return {};
};
exports.graphicStyles = graphicStyles;
/**
* @deprecated `graphicStencil` will be removed in a future version. Use `graphicImageStencil` instead.
*/
exports.graphicStencil = (0, canvas_kit_styling_1.createStencil)({
extends: Svg_1.svgStencil,
base: { name: "3f93cl", styles: "box-sizing:border-box;" },
modifiers: {
grow: {
true: { name: "4fih9w", styles: "width:100%;--width-svg-728c60:100%;" }
}
}
}, "graphic-385fe4");
exports.graphicImageStencil = (0, canvas_kit_styling_1.createStencil)({
vars: {
width: '',
height: '',
},
base: { name: "3fmjm3", styles: "box-sizing:border-box;width:var(--width-graphic-image-8fedc2);height:var(--height-graphic-image-8fedc2);display:inline-block;& [data-part=\"graphic-img\"]{width:var(--width-graphic-image-8fedc2);height:var(--height-graphic-image-8fedc2);max-width:100%;max-height:100%;}" },
modifiers: {
grow: {
true: { name: "1vqy3t", styles: "width:100%;& [data-part=\"graphic-img\"]{width:100%;}" }
}
}
}, "graphic-image-8fedc2");
/**
* Account for nodejs environments. We use `btoa` which is a web api for encoding data and `Buffer` for nodejs environments.
* [`btoa` docs](https://developer.mozilla.org/en-US/docs/Web/API/Window/btoa)
* [`Buffer` docs](https://nodejs.org/api/buffer.html#buffers-and-character-encodings)
*/
const base64Encoded = (str) => {
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
return window.btoa(str);
}
return Buffer.from(str, 'binary').toString('base64');
};
exports.base64Encoded = base64Encoded;
exports.Graphic = (0, common_1.createComponent)('span')({
displayName: 'Graphic',
Component: ({ grow = false, width, height, src, srcset, alt, sizes, ...elemProps }, ref, Element) => {
return ((0, jsx_runtime_1.jsx)(Element, { ref: ref, ...(0, canvas_kit_styling_1.handleCsProp)(elemProps, (0, exports.graphicImageStencil)({
grow,
width: typeof width === 'number' ? (0, canvas_kit_styling_1.px2rem)(width) : width,
height: typeof height === 'number' ? (0, canvas_kit_styling_1.px2rem)(height) : height,
})), children: (0, jsx_runtime_1.jsx)("img", { "data-part": "graphic-img", src: src.svg ? `data:image/svg+xml;base64,${(0, exports.base64Encoded)(src.svg)}` : src.url, sizes: sizes, srcSet: srcset, alt: alt }) }));
},
});