Skip to content
This repository was archived by the owner on Feb 28, 2019. It is now read-only.

Commit 92b0db2

Browse files
author
Stefan Wullems
authored
Merge pull request #4 from exivity/input
Input
2 parents 6b90a6a + c478a41 commit 92b0db2

35 files changed

+1107
-219
lines changed

.storybook/config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import React from 'react'
1+
2+
import * as React from 'react'
23
import { configure } from '@storybook/react'
34
import { addDecorator } from '@storybook/react'
45
import { withThemesProvider } from 'storybook-addon-styled-component-theme'
@@ -7,6 +8,7 @@ import WebfontLoader from '@dr-kobros/react-webfont-loader'
78
import theme from '../src/theme'
89
import { fontConfig } from '../src/fontConfig'
910

11+
1012
const styles = {
1113
display: 'flex',
1214
height: '100%',
@@ -33,6 +35,7 @@ addDecorator(withThemesProvider(themes))
3335
addDecorator(FontLoader)
3436
addDecorator(CenterDecorator)
3537

38+
3639
function loadStories() {
3740
require('../src/stories')
3841
}

jest.config.js

-26
This file was deleted.

package.json

+4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"dependencies": {
66
"@dr-kobros/react-webfont-loader": "^8.0.0",
77
"@storybook/cli": "^5.0.0-rc.3",
8+
"fontfaceobserver": "^2.1.0",
89
"react": "^16.8.2",
910
"react-dom": "^16.8.2",
11+
"react-icons": "^3.4.0",
1012
"react-scripts": "2.1.5",
1113
"storybook-addon-styled-component-theme": "^1.1.1",
1214
"styled-components": "^4.1.3"
@@ -37,7 +39,9 @@
3739
"@types/enzyme": "^3.1.18",
3840
"@types/enzyme-adapter-react-16": "^1.0.4",
3941
"@types/jest": "^24.0.6",
42+
"@types/react-icons": "^3.0.0",
4043
"@types/react-test-renderer": "^16.8.1",
44+
"@types/storybook__addon-actions": "^3.4.2",
4145
"@types/styled-components": "^4.1.10",
4246
"babel-loader": "^8.0.5",
4347
"enzyme": "^3.9.0",
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import * as React from 'react'
2+
3+
import styled from "styled-components";
4+
5+
interface IBaseIconProps {
6+
className?: string
7+
extraClassName?: string
8+
onClick?: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void
9+
icon: JSX.Element
10+
}
11+
12+
const BaseIcon: React.FC<IBaseIconProps> = ({ className, extraClassName, icon, onClick }) => {
13+
return <span className={className + ' ' + extraClassName} onMouseDown={onClick}>{icon}</span>
14+
}
15+
16+
export default styled(BaseIcon)`
17+
cursor: auto;
18+
font-family: ${props => `Material Icons, ${props.theme.global.font}`};
19+
font-weight: normal;
20+
font-style: normal;
21+
font-size: 24px;
22+
23+
line-height: 1;
24+
vertical-align: middle;
25+
26+
text-transform: none;
27+
letter-spacing: normal;
28+
word-wrap: normal;
29+
white-space: nowrap;
30+
direction: ltr;
31+
32+
/* Support for all WebKit browsers. */
33+
-webkit-font-smoothing: antialiased;
34+
35+
/* Support for Safari and Chrome. */
36+
text-rendering: optimizeLegibility;
37+
38+
/* Support for Firefox. */
39+
-moz-osx-font-smoothing: grayscale;
40+
41+
/* Support for IE. */
42+
font-feature-settings: 'liga';
43+
44+
`
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import { shallowWithTheme } from '../../../utils/testing/shallowWithTheme'
3+
import { MdAccountBalanceWallet } from 'react-icons/md'
4+
5+
import Icon from './'
6+
7+
test('renders icon', () => {
8+
const button = shallowWithTheme(<Icon icon={<MdAccountBalanceWallet/>} onClick={() => { return }} />)
9+
expect(button).toMatchSnapshot()
10+
})
11+
12+
test('renders icon with subicon', () => {
13+
const button = shallowWithTheme(<Icon icon={<MdAccountBalanceWallet/>} subIcon={<MdAccountBalanceWallet/>} onClick={() => { return }} />)
14+
expect(button).toMatchSnapshot()
15+
})
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import * as React from 'react'
2+
import styled, { css } from 'styled-components';
3+
import BaseIcon from './BaseIcon';
4+
5+
interface IMainIconProps {
6+
subIcon?: JSX.Element
7+
icon: JSX.Element
8+
className?: string
9+
onClick?: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void
10+
}
11+
12+
const MainIcon: React.FC<IMainIconProps> = ({ icon, className, onClick }) => {
13+
return <BaseIcon extraClassName={className} icon={icon} onClick={onClick} />
14+
}
15+
16+
export default styled(MainIcon)`
17+
${props => props.subIcon && css`
18+
/* Zero out the line-height so that it doesn't
19+
interfere with the positioning that follows */
20+
line-height: 0;
21+
22+
/* Where the magic happens: makes all browsers position
23+
the sup/sup properly, relative to the surrounding text */
24+
position: relative;
25+
26+
/* Note that if you're using Eric Meyer's reset.css, this
27+
is already set and you can remove this rule */
28+
vertical-align: baseline;
29+
30+
/* Move the superscripted text up */
31+
top: -.2em;
32+
33+
font-size: 16px;
34+
`}
35+
${props => !props.children && props.subIcon && css`
36+
width: 16px;
37+
height: 16px;
38+
`}
39+
`
40+

src/components/atoms/Icon/SubIcon.tsx

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as React from 'react'
2+
import styled from 'styled-components';
3+
import BaseIcon from './BaseIcon';
4+
5+
interface ISubIconProps {
6+
icon: JSX.Element
7+
onClick?: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void
8+
className?: string
9+
}
10+
11+
const SubIcon: React.FC<ISubIconProps> = ({ icon, onClick, className }) => {
12+
return <BaseIcon onClick={onClick} icon={icon} extraClassName={className} />
13+
}
14+
15+
export default styled(SubIcon)`
16+
/* Zero out the line-height so that it doesn't
17+
interfere with the positioning that follows */
18+
line-height: 0;
19+
20+
/* Where the magic happens: makes all browsers position
21+
the sup/sup properly, relative to the surrounding text */
22+
position: relative;
23+
24+
/* Note that if you're using Eric Meyer's reset.css, this
25+
is already set and you can remove this rule */
26+
vertical-align: baseline;
27+
28+
/* Move the subscripted text down, but only
29+
half as far down as the superscript moved up */
30+
bottom: -.3em;
31+
margin-left: -.4em;
32+
33+
font-size: 10px;
34+
35+
`

0 commit comments

Comments
 (0)