Skip to content

Commit

Permalink
Typescript support for Search (#660)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdalhaug authored and vnys committed Nov 13, 2020
1 parent a84d525 commit 5bffb64
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('Search', () => {

rerender(<Search value="new" />)

const searchBox = screen.queryByRole('searchbox')
const searchBox = screen.queryByRole('searchbox') as HTMLInputElement

expect(searchBox.value).toEqual('new')
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// @ts-nocheck
import React, { useState, useRef, useEffect } from 'react'
import PropTypes from 'prop-types'
import styled, { css } from 'styled-components'
import { search, close } from '@equinor/eds-icons'
import { search as tokens } from './Search.tokens'
Expand Down Expand Up @@ -29,7 +27,12 @@ const {
},
} = tokens

const Container = styled.span`
type ContainerProps = {
isFocused: boolean
disabled: boolean
}

const Container = styled.span<ContainerProps>`
position: relative;
background: ${background};
width: 100%;
Expand Down Expand Up @@ -121,7 +124,11 @@ const Input = styled.input`
`}
`

const InsideButton = styled.div`
type InsideButtonProps = {
isActive: boolean
}

const InsideButton = styled.div<InsideButtonProps>`
display: flex;
align-items: center;
visibility: hidden;
Expand Down Expand Up @@ -162,17 +169,26 @@ const InsideButton = styled.div`
`}
`

type Props = {
/** Disabled state */
disabled?: boolean
/** Default value for search field */
defaultValue?: string
/** Value for search field */
value?: string
} & React.HTMLAttributes<HTMLInputElement>

export const Search = React.forwardRef(function EdsSearch(
{
onChange,
defaultValue,
defaultValue = '',
value,
className,
disabled,
className = '',
disabled = false,
onBlur,
onFocus,
...rest
},
}: Props,
ref,
) {
const isControlled = typeof value !== 'undefined'
Expand Down Expand Up @@ -237,13 +253,13 @@ export const Search = React.forwardRef(function EdsSearch(
role: 'searchbox',
'aria-label': 'search input',
onBlur: (e) => {
handleBlur(e)
handleBlur()
if (onBlur) {
onBlur(e)
}
},
onFocus: (e) => {
handleFocus(e)
handleFocus()
if (onFocus) {
onFocus(e)
}
Expand Down Expand Up @@ -282,34 +298,4 @@ export const Search = React.forwardRef(function EdsSearch(
)
})

Search.propTypes = {
/** @ignore */
className: PropTypes.string,
/** Placeholder */
placeholder: PropTypes.string,
/** Disabled state */
disabled: PropTypes.bool,
/** onChange handler */
onChange: PropTypes.func,
/** Default value for search field */
defaultValue: PropTypes.string,
/** Value for search field */
value: PropTypes.string,
/** onBlur handler */
onBlur: PropTypes.func,
/** onFocus handler */
onFocus: PropTypes.func,
}

Search.defaultProps = {
className: '',
placeholder: '',
disabled: false,
onChange: undefined,
defaultValue: '',
value: undefined,
onBlur: undefined,
onFocus: undefined,
}

Search.displayName = 'eds-search'
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// @ts-nocheck
export { Search } from './Search'

0 comments on commit 5bffb64

Please sign in to comment.