UNPKG

@elastic/eui

Version:

Elastic UI Component Library

86 lines (84 loc) 4.3 kB
var _excluded = ["type", "alt", "className", "fullWidth"]; 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; } /* * 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. */ import React from 'react'; import PropTypes from "prop-types"; import classNames from 'classnames'; import { useEuiMemoizedStyles, useEuiTheme } from '../../services'; import { euiIllustrationStyles } from './illustration.styles'; /** * 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. */ import { jsx as ___EmotionJSX } from "@emotion/react"; export var 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 = useEuiTheme(), colorMode = _useEuiTheme.colorMode; var styles = useEuiMemoizedStyles(euiIllustrationStyles); var classes = classNames('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 ___EmotionJSX("span", _extends({ className: classes, css: cssStyles }, a11yProps, rest, { dangerouslySetInnerHTML: { __html: svg } })); }; EuiIllustration.propTypes = { className: PropTypes.string, "aria-label": PropTypes.string, "data-test-subj": PropTypes.string, css: PropTypes.any, /** * The illustration asset to render, typically imported from * `@elastic/eui-illustrations`. */ type: PropTypes.shape({ /** Unique id for the illustration. */id: PropTypes.string.isRequired, /** Human-readable title, used as the default accessible label. */title: PropTypes.string.isRequired, /** Trusted SVG markup for the light color mode. Inlined verbatim — see the interface's security note. */light: PropTypes.string.isRequired, /** Trusted SVG markup for the dark color mode. Inlined verbatim — see the interface's security note. */dark: PropTypes.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.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.bool }; EuiIllustration.displayName = 'EuiIllustration';