欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

React显示文件夹中SVG

程序员文章站 2022-06-28 11:18:05
import React from 'react'; import _ from 'lodash'; import styles from './iconPicker.less'; const requireContext = require.context('annotation/draw/svg ......
import react from 'react';
import _ from 'lodash';
import styles from './iconpicker.less';

const requirecontext = require.context('annotation/draw/svgs/', false, /^\.\/.*\.svg$/);

export default class extends react.purecomponent {
  render() {
    return (
      <ul classname={styles.ul}>
        {_.reduce(
          requirecontext.keys(),
          (pre, cur) => [
            ...pre,
            <li id={cur} key={cur} classname={styles.li}><embed type="image/svg+xml" width={18} height={18} src={requirecontext(cur)} /></li>,
          ],
          []
        )}
      </ul>
    );
  }
}
.ul {
    list-style-type: none;
    border: 1px solid #dedede;
    padding: 0px;
    margin: 4px 0px 4px 0px;
    position: relative;
    display: flow-root;
    .li {
        float: left;
        border: 1px solid #fff;
        line-height: 12px;
        vertical-align: middle;
        margin: 2px;
        padding: 2px;
        &:hover {
            border: 1px solid rgb(3, 189, 202);
            box-shadow:0 0 1px rgb(9, 180, 223);
        }
    }
}