aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/components/ui/icon.tsx
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-11-12 05:11:10 +0800
committerFabio Berger <me@fabioberger.com>2018-11-12 05:11:10 +0800
commit0391f93490cffdc69f6cb32f11762d174ed04e37 (patch)
tree3a8b30a04de1193aa21e5b84bd572db24979a8bf /packages/instant/src/components/ui/icon.tsx
parent399a7d5fec9af4f3491a77f0c2d46738f3d8ffa7 (diff)
parent397b4e289015f9bb0831c1a0ce6fee601670b487 (diff)
downloaddexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.gz
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.bz2
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.lz
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.xz
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.tar.zst
dexon-sol-tools-0391f93490cffdc69f6cb32f11762d174ed04e37.zip
merge development
Diffstat (limited to 'packages/instant/src/components/ui/icon.tsx')
-rw-r--r--packages/instant/src/components/ui/icon.tsx105
1 files changed, 85 insertions, 20 deletions
diff --git a/packages/instant/src/components/ui/icon.tsx b/packages/instant/src/components/ui/icon.tsx
index 7373c3acd..a88fa87dd 100644
--- a/packages/instant/src/components/ui/icon.tsx
+++ b/packages/instant/src/components/ui/icon.tsx
@@ -1,19 +1,34 @@
+import * as _ from 'lodash';
import * as React from 'react';
-import { ColorOption } from '../../style/theme';
+import { ColorOption, styled, Theme, withTheme } from '../../style/theme';
type svgRule = 'evenodd' | 'nonzero' | 'inherit';
interface IconInfo {
viewBox: string;
+ path: string;
fillRule?: svgRule;
clipRule?: svgRule;
- path: string;
+ strokeOpacity?: number;
+ strokeWidth?: number;
+ strokeLinecap?: 'butt' | 'round' | 'square' | 'inherit';
+ strokeLinejoin?: 'miter' | 'round' | 'bevel' | 'inherit';
}
interface IconInfoMapping {
+ closeX: IconInfo;
failed: IconInfo;
success: IconInfo;
+ chevron: IconInfo;
+ search: IconInfo;
}
const ICONS: IconInfoMapping = {
+ closeX: {
+ viewBox: '0 0 11 11',
+ fillRule: 'evenodd',
+ clipRule: 'evenodd',
+ path:
+ 'M10.45 10.449C10.7539 10.1453 10.7539 9.65282 10.45 9.34909L6.60068 5.49999L10.45 1.65093C10.7538 1.3472 10.7538 0.854765 10.45 0.551038C10.1462 0.24731 9.65378 0.24731 9.34995 0.551038L5.50058 4.40006L1.65024 0.549939C1.34641 0.246212 0.853973 0.246212 0.550262 0.549939C0.246429 0.853667 0.246429 1.34611 0.550262 1.64983L4.40073 5.49995L0.55014 9.35019C0.246307 9.65392 0.246307 10.1464 0.55014 10.4501C0.853851 10.7538 1.34628 10.7538 1.65012 10.4501L5.5007 6.59987L9.35007 10.449C9.6539 10.7527 10.1463 10.7527 10.45 10.449Z',
+ },
failed: {
viewBox: '0 0 34 34',
fillRule: 'evenodd',
@@ -28,31 +43,81 @@ const ICONS: IconInfoMapping = {
path:
'M17 34C26.3887 34 34 26.3888 34 17C34 7.61121 26.3887 0 17 0C7.61133 0 0 7.61121 0 17C0 26.3888 7.61133 34 17 34ZM25.7539 13.0977C26.2969 12.4718 26.2295 11.5244 25.6035 10.9817C24.9775 10.439 24.0303 10.5063 23.4878 11.1323L15.731 20.0771L12.3936 16.7438C11.8071 16.1583 10.8574 16.1589 10.272 16.7451C9.68652 17.3313 9.6875 18.281 10.2734 18.8665L14.75 23.3373L15.8887 24.4746L16.9434 23.2587L25.7539 13.0977Z',
},
+ chevron: {
+ viewBox: '0 0 12 7',
+ path: 'M11 1L6 6L1 1',
+ strokeOpacity: 0.5,
+ strokeWidth: 1.5,
+ strokeLinecap: 'round',
+ strokeLinejoin: 'round',
+ },
+ search: {
+ viewBox: '0 0 14 14',
+ fillRule: 'evenodd',
+ clipRule: 'evenodd',
+ path:
+ 'M8.39404 5.19727C8.39404 6.96289 6.96265 8.39453 5.19702 8.39453C3.4314 8.39453 2 6.96289 2 5.19727C2 3.43164 3.4314 2 5.19702 2C6.96265 2 8.39404 3.43164 8.39404 5.19727ZM8.09668 9.51074C7.26855 10.0684 6.27075 10.3945 5.19702 10.3945C2.3269 10.3945 0 8.06738 0 5.19727C0 2.32715 2.3269 0 5.19702 0C8.06738 0 10.394 2.32715 10.394 5.19727C10.394 6.27051 10.0686 7.26855 9.51074 8.09668L13.6997 12.2861L12.2854 13.7002L8.09668 9.51074Z',
+ },
};
export interface IconProps {
+ className?: string;
width: number;
- height: number;
- color: ColorOption;
+ height?: number;
+ color?: ColorOption;
+ stroke?: ColorOption;
icon: keyof IconInfoMapping;
+ onClick?: (event: React.MouseEvent<HTMLElement>) => void;
+ padding?: string;
+ theme: Theme;
}
-export const Icon: React.SFC<IconProps> = props => {
+const PlainIcon: React.StatelessComponent<IconProps> = props => {
const iconInfo = ICONS[props.icon];
-
+ const colorValue = _.isUndefined(props.color) ? undefined : props.theme[props.color];
+ const strokeValue = _.isUndefined(props.stroke) ? undefined : props.theme[props.stroke];
return (
- <svg
- width={props.width}
- height={props.height}
- viewBox={iconInfo.viewBox}
- fill="none"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- d={iconInfo.path}
- fill={props.color}
- fillRule={iconInfo.fillRule || 'nonzero'}
- clipRule={iconInfo.clipRule || 'nonzero'}
- />
- </svg>
+ <div onClick={props.onClick} className={props.className}>
+ <svg
+ width={props.width}
+ height={props.height}
+ viewBox={iconInfo.viewBox}
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ d={iconInfo.path}
+ fill={colorValue}
+ fillRule={iconInfo.fillRule || 'nonzero'}
+ clipRule={iconInfo.clipRule || 'nonzero'}
+ stroke={strokeValue}
+ strokeOpacity={iconInfo.strokeOpacity}
+ strokeWidth={iconInfo.strokeWidth}
+ strokeLinecap={iconInfo.strokeLinecap}
+ strokeLinejoin={iconInfo.strokeLinejoin}
+ />
+ </svg>
+ </div>
);
};
+
+export const Icon = withTheme(styled(PlainIcon)`
+ && {
+ display: inline-block;
+ ${props => (!_.isUndefined(props.onClick) ? 'cursor: pointer' : '')};
+ transition: opacity 0.5s ease;
+ padding: ${props => props.padding};
+ opacity: ${props => (!_.isUndefined(props.onClick) ? 0.7 : 1)};
+ &:hover {
+ opacity: 1;
+ }
+ &:active {
+ opacity: 1;
+ }
+ }
+`);
+
+Icon.defaultProps = {
+ padding: '0em 0em',
+};
+
+Icon.displayName = 'Icon';