UNPKG

@elastic/eui

Version:

Elastic UI Component Library

91 lines (90 loc) 4.71 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EuiIllustration = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _classnames = _interopRequireDefault(require("classnames")); var _services = require("../../services"); var _illustration = require("./illustration.styles"); var _react2 = require("@emotion/react"); var _excluded = ["type", "alt", "className", "fullWidth"]; /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ /** * The data contract for an illustration asset (e.g. an export from `@elastic/eui-illustrations`). * It is declared here so that `@elastic/eui` does not depend on the illustrations package. * The illustrations package can be released independently as long as its assets satisfy this shape. * * @remarks * The `light`/`dark` markup is inlined via `dangerouslySetInnerHTML`. Only pass * trusted, package-authored SVGs — never untrusted or user-supplied markup, as * it would be rendered as-is and could introduce an XSS vulnerability. */ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; } function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; } var EuiIllustration = exports.EuiIllustration = function EuiIllustration(_ref) { var type = _ref.type, alt = _ref.alt, className = _ref.className, _ref$fullWidth = _ref.fullWidth, fullWidth = _ref$fullWidth === void 0 ? true : _ref$fullWidth, rest = _objectWithoutProperties(_ref, _excluded); var _useEuiTheme = (0, _services.useEuiTheme)(), colorMode = _useEuiTheme.colorMode; var styles = (0, _services.useEuiMemoizedStyles)(_illustration.euiIllustrationStyles); var classes = (0, _classnames.default)('euiIllustration', className); var cssStyles = [styles.euiIllustration, fullWidth && styles.fullWidth]; var svg = colorMode === 'DARK' ? type.dark : type.light; var isDecorative = alt === ''; var a11yProps = isDecorative ? { 'aria-hidden': true } : { role: 'img', 'aria-label': alt !== null && alt !== void 0 ? alt : type.title }; return (0, _react2.jsx)("span", _extends({ className: classes, css: cssStyles }, a11yProps, rest, { dangerouslySetInnerHTML: { __html: svg } })); }; EuiIllustration.propTypes = { className: _propTypes.default.string, "aria-label": _propTypes.default.string, "data-test-subj": _propTypes.default.string, css: _propTypes.default.any, /** * The illustration asset to render, typically imported from * `@elastic/eui-illustrations`. */ type: _propTypes.default.shape({ /** Unique id for the illustration. */id: _propTypes.default.string.isRequired, /** Human-readable title, used as the default accessible label. */title: _propTypes.default.string.isRequired, /** Trusted SVG markup for the light color mode. Inlined verbatim — see the interface's security note. */light: _propTypes.default.string.isRequired, /** Trusted SVG markup for the dark color mode. Inlined verbatim — see the interface's security note. */dark: _propTypes.default.string.isRequired }).isRequired, /** * Accessible label for the illustration. Defaults to the illustration's * `title`. Pass an empty string to mark the illustration as decorative. */ alt: _propTypes.default.string, /** * When `true`, stretches the SVG to fill the full width of its container. * When `false`, the SVG maintains its intrinsic width. * Defaults to `true`. */ fullWidth: _propTypes.default.bool }; EuiIllustration.displayName = 'EuiIllustration';