@workday/canvas-kit-react
Version:
The parent module that contains all Workday Canvas Kit React components
110 lines (109 loc) • 4.6 kB
JavaScript
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Graphic = exports.base64Encoded = exports.graphicImageStencil = exports.graphicStencil = exports.graphicStyles = void 0;
const React = __importStar(require("react"));
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: "ojxa17", styles: "box-sizing:border-box;" },
modifiers: {
grow: {
true: { name: "ojxa18", styles: "width:100%;--width-svg-a30d66:100%;" }
}
}
}, "graphic-385fe4");
exports.graphicImageStencil = (0, canvas_kit_styling_1.createStencil)({
vars: {
width: '',
height: '',
},
base: { name: "ojxa19", 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: "ojxa1a", 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 (React.createElement(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,
})) },
React.createElement("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 })));
},
});
;