Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

fix(password): remove unnecessary node and use text color #237

Merged
merged 1 commit into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions src/Atoms/Inputs/Password.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,37 @@
// @flow strict
import * as React from 'react'
import styled from 'styled-components'
import styled, { css } from 'styled-components'

import { fontSize, theme } from '../../Tools/interpolation'
import { theme } from '../../Tools/interpolation'
import { Input, type PropsType, type HtmlInputType } from './Input'
import { FarEye, FarEyeSlash } from '../Icons'

const Switch = styled.span`
const iconCss = css`
position: absolute;
right: 1rem;
bottom: 0.5rem;
font-family: ${theme('fontPrimary')};
font-size: ${fontSize('xs')};
font-weight: 600;
bottom: calc(1.35rem - 8px);
user-select: none;
fill: ${theme('inputColor')};

&:hover {
text-decoration: underline;
fill: ${theme('inputColor')};
}
`

const Eye = styled(FarEye)`
${iconCss};
`

const EyeSlash = styled(FarEyeSlash)`
${iconCss};
`

const PasswordInput: React.ComponentType<PropsType> = styled(Input)`
input {
padding-right: 3rem;
}
`

type StateType = {| type: HtmlInputType |}

class Password extends React.Component<PropsType, StateType> {
Expand All @@ -35,7 +43,7 @@ class Password extends React.Component<PropsType, StateType> {
this.state = { type: props.type }
}

handleSwitchClick = () => {
handleIconClick = () => {
this.state.type === 'password'
? this.setState({ type: 'text' })
: this.setState({ type: 'password' })
Expand All @@ -46,14 +54,16 @@ class Password extends React.Component<PropsType, StateType> {
return null
}

return (
<Switch onClick={this.handleSwitchClick}>
{this.state.type === 'password' ? (
<FarEye selectable size="20px" />
) : (
<FarEyeSlash selectable size="20px" />
)}
</Switch>
const props = {
onClick: this.handleIconClick,
selectable: true,
size: '16px',
}

return this.state.type === 'password' ? (
<Eye {...props} />
) : (
<EyeSlash {...props} />
)
}

Expand Down
4 changes: 2 additions & 2 deletions src/Atoms/Inputs/Password.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ describe('Password', () => {
it('should render correctly with switching its type', () => {
const tree = mountWithTheme(<Password />)

tree.find('span').simulate('click')
tree.find('svg').simulate('click')

expect(tree.find(Password)).toMatchSnapshot()

tree.find('span').simulate('click')
tree.find('svg').simulate('click')

expect(tree.find(Password)).toMatchSnapshot()
})
Expand Down
Loading