Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | 157x 157x 157x 157x 1115x 1115x 2x 2x 1x 1x 1x 1115x 157x 157x 157x 157x 157x | import _ from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import { lucidClassNames } from '../../util/style-helpers'; import { StandardProps, Overwrite } from '../../util/component-types'; const cx = lucidClassNames.bind('&-Icon'); const { any, string, number, bool, func, oneOf, oneOfType } = PropTypes; export enum Color { 'neutral-dark' = 'neutral-dark', 'neutral-light' = 'neutral-light', primary = 'primary', white = 'white', success = 'success', warning = 'warning', 'secondary-one' = 'secondary-one', 'secondary-two' = 'secondary-two', 'secondary-three' = 'secondary-three', } export interface IIconPropsRaw extends StandardProps { /** Size variations of the icons. `size` directly effects height and width but the developer should also be conscious of the relationship with `viewBox`. */ size?: number; /** Size handles width and height, whereas `width` can manually override the width that would be set by size. */ width?: number | string; /** Size handles width and height, whereas `height` can manually override the height that would be set by size. */ height?: number | string; /** `viewBox` is very important for SVGs. You can think of `viewBox` as the "artboard" for our SVG while `size` is the presented height and width. */ viewBox?: string; /** Any valid SVG aspect ratio. */ aspectRatio?: string; /** Adds styling that makes the icon appear clickable. */ isClickable?: boolean; /** Adds styling that makes the icon appear disabled. Also forces isClickable to be false. */ isDisabled?: boolean; /** Called when the user clicks the `Icon`. */ onClick?: ({ event, props, }: { event: React.MouseEvent; props: IIconProps; }) => void; /** Called when the user clicks an active, clickable `Icon`. */ onSelect?: ({ event, props, }: { event: React.MouseEvent; props: IIconProps; }) => void; /** Sets the color of the Icon. May not be applicable for icons that are tied to specific colors (e.g. DangerIcon). */ color?: keyof typeof Color; } export type IIconProps = Overwrite< React.HTMLProps<SVGSVGElement>, IIconPropsRaw >; const defaultProps = { size: 16, aspectRatio: 'xMidYMid meet', viewBox: '0 0 16 16', isDisabled: false, isClickable: false, color: Color.primary, onClick: _.noop, onSelect: _.noop, }; export const Icon = (props: IIconProps): React.ReactElement => { const { className, children, color, size, width, height, viewBox, aspectRatio, isClickable, isDisabled, onClick, onSelect, ...passThroughs } = props; const svgRef = React.createRef<SVGSVGElement>(); function handleClick(event: React.MouseEvent): void { onClick && onClick({ event, props: props }); if (isClickable && !isDisabled) { onSelect && onSelect({ event, props: props }); if (svgRef.current) { svgRef.current.focus(); } } } return ( <svg width={width ? width : size} height={height ? height : size} viewBox={viewBox} preserveAspectRatio={aspectRatio} {...(passThroughs as any)} className={cx( '&', { [`&-color-${color}`]: true, '&-is-clickable': !isDisabled && isClickable, '&-is-disabled': isDisabled, }, className )} ref={svgRef} onClick={handleClick} > {children} </svg> ); }; Icon.displayName = 'Icon'; Icon.defaultProps = defaultProps; Icon.peek = { description: `A basic \`svg\` icon. Any props that are not explicitly called out below will be passed through to the native \`svg\` component.`, categories: ['visual design', 'icons'], }; export const propTypes = { /** Classes that are appended to the component defaults. This prop is run through the \`classnames\` library. */ className: any, /** Size variations of the icons. \`size\` directly effects height and width but the developer should also be conscious of the relationship with \`viewBox\`. */ size: number, /** Size handles width and height, whereas \`width\` can manually override the width that would be set by size. */ width: oneOfType([number, string]), /** Size handles width and height, whereas \`height\` can manually override the height that would be set by size. */ height: oneOfType([number, string]), /** \`viewBox\` is very important for SVGs. You can think of \`viewBox\` as the "artboard" for our SVG while \`size\` is the presented height and width. */ viewBox: string, /** Any valid SVG aspect ratio. */ aspectRatio: string, /** Adds styling that makes the icon appear clickable. */ isClickable: bool, /** Adds styling that makes the icon appear disabled. Also forces isClickable to be false. */ isDisabled: bool, /** Called when the user clicks the \`Icon\`. Signature: \`({event, props}) => {}\` */ onClick: func, /** Called when the user clicks an active, clickable \`Icon\`. Signature: \`({event, props}) => {}\` */ onSelect: func, /** Any valid React children. */ children: any, /** Sets the color of the Icon. May not be applicable for icons that are tied to specific colors (e.g. DangerIcon). */ color: oneOf(_.values(Color)), }; export interface IIconWithDirectionProps extends IIconProps { direction?: 'up' | 'down' | 'left' | 'right'; } Icon.propTypes = propTypes; export default Icon; |