UNPKG

@elastic/eui

Version:

Elastic UI Component Library

90 lines (89 loc) 4.14 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.EuiIllustration = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); 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. */ 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 = (0, _objectWithoutProperties2.default)(_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", (0, _extends2.default)({ 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';