Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from 'react'
  2. import iconActionsData from './icon-actions.data'
  3. import iconSocData from './icon-soc.data'
  4. import iconUxData from './icon-ux.data'
  5.  
  6. const data: {
  7.   [index: string]: IIconType
  8. } = {
  9.   ...iconSocData as {[index: string]: IIconType},
  10.   ...iconUxData as {[index: string]: IIconType},
  11.   ...iconActionsData as {[index: string]: IIconType}
  12. }
  13.  
  14. export interface IIconType {
  15.   viewBox?: string,
  16.   width: string,
  17.   height: string,
  18.   paths: string[],
  19.   style?: { [index: string]: string },
  20.   strokeOpacity?: string,
  21.   strokeLinecap?: React.SVGProps<SVGPathElement>['strokeLinecap'],
  22.   strokeLinejoin?: React.SVGProps<SVGPathElement>['strokeLinejoin']
  23. }
  24.  
  25. export interface IIcon {
  26.   icon: keyof typeof data | IconList
  27.   width?: string
  28.   height?: string
  29.   stroke?: string
  30.   fill?: string
  31.   style?: object
  32.   hover?: boolean
  33.   className?: string
  34.   onClick?: () => void,
  35.   tooltip?: string,
  36.   strokeWidth?: string
  37. }
  38.  
  39. class IconComponent extends React.Component<IIcon> {
  40.  
  41.   public getFill(item, i): string {
  42.     const { fill } = this.props
  43.     if (fill) {
  44.       return fill
  45.     } else if (item.fills) {
  46.       return item.fills[i]
  47.     }
  48.     return 'none'
  49.   }
  50.  
  51.   public render() {
  52.     const { icon, stroke, width, height, hover, className, onClick, strokeWidth } = this.props
  53.     let { style } = this.props
  54.     const item = data[icon]
  55.  
  56.     if (!item) {
  57.       console.warn(`Icon "${icon}" doesn't exist!`)
  58.      return null
  59.    }
  60.  
  61.    if (!style && item.style) {
  62.      style = item.style
  63.    }
  64.  
  65.    const tooltip = {}
  66.  
  67.    if (this.props.tooltip) {
  68.      tooltip['data-tip'] = this.props.tooltip
  69.      tooltip['data-place'] = 'left'
  70.      tooltip['data-for'] = 'global-tooltip'
  71.    }
  72.  
  73.    return (
  74.      <div
  75.        className={className}
  76.        onClick={() => onClick && onClick()}
  77.        {...tooltip}
  78.      >
  79.        <svg
  80.          width={width || item.width}
  81.          height={height || item.height}
  82.          viewBox={item.viewBox}
  83.        >
  84.          {hover ?
  85.            <defs>
  86.              <filter id='svgHover' x='0' y='0' width='200%' height='200%'>
  87.                <feGaussianBlur result='blurOut' in='offOut' stdDeviation='1' />
  88.                <feOffset result='offOut' in='SourceGraphic' dx='0' dy='0' />
  89.                <feBlend in='SourceGraphic' in2='blurOut' mode='normal' />
  90.              </filter>
  91.            </defs>
  92.            : ''}
  93.          {item.paths ?
  94.            item.paths.map((el, i) => {
  95.              return (
  96.                <path
  97.                  key={i}
  98.                  style={{ transition: '0.3s', ...style }}
  99.                  fill={this.getFill(item, i)}
  100.                  stroke={stroke || 'none'}
  101.                  strokeWidth={strokeWidth || 'none'}
  102.                  strokeOpacity={stroke && item.strokeOpacity ? item.strokeOpacity : 'none'}
  103.                  strokeLinecap={stroke && item.strokeLinecap ? item.strokeLinecap : undefined}
  104.                  strokeLinejoin={stroke && item.strokeLinejoin ? item.strokeLinejoin : undefined}
  105.                  d={el}
  106.                />
  107.              )
  108.            })
  109.            : ''}
  110.        </svg>
  111.      </div>
  112.    )
  113.  }
  114. }
  115.  
  116. enum IconList {
  117.  // actions
  118.  search = 'search',
  119.  plus = 'plus',
  120.  send = 'send',
  121.  group = 'group',
  122.  check = 'check',
  123.  
  124.  // soc
  125.  vkontakte = 'vkontakte',
  126.  facebook = 'facebook',
  127.  sqFacebook = 'sqFacebook',
  128.  sqOdnoklassniki = 'sqOdnoklassniki',
  129.  sqMailru = 'sqMailru',
  130.  sqVkontakte = 'sqVkontakte',
  131.  
  132.  // ux
  133.  edit = 'edit',
  134.  smallArrow = 'smallArrow',
  135.  outlineStar = 'outlineStar',
  136.  shareAlt = 'shareAlt',
  137.  cross = 'cross',
  138.  comment = 'comment',
  139.  shared = 'shared',
  140.  calendar = 'calendar',
  141.  time = 'time',
  142.  star = 'star',
  143.  list = 'list',
  144.  setting = 'setting',
  145.  filter = 'filter',
  146.  chat = 'chat',
  147.  eye = 'eye',
  148.  upload = 'upload',
  149.  placemark = 'placemark',
  150.  rouble = 'rouble',
  151.  description = 'description',
  152.  img = 'img',
  153.  userPlus = 'userPlus',
  154.  refresh = 'refresh',
  155.  largeBackArrow = 'largeBackArrow',
  156.  smallBackArrow = 'smallBackArrow',
  157.  settings2 = 'settings2',
  158.  addFriend = 'addFriend',
  159.  removeFriend = 'removeFriend',
  160.  notification = 'notification',
  161.  photos = 'photos',
  162.  addPhoto = 'addPhoto',
  163.  angleDown = 'angleDown',
  164.  people = 'people',
  165.  deleteItem = 'deleteItem',
  166.  editPlayer = 'editPlayer',
  167.  ok = 'ok'
  168. }
  169.  
  170. export { IconList }
  171. export default IconComponent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement