import React, { useContext } from 'react' import styled from 'styled-components' import { CssVars, SearchContext } from './context' const Icon = styled.svg` position: relative; right: 10px; margin-left: 5px; cursor: pointer; display: var(${CssVars.cancelButtonDisplay}); ` type Props = { width?: number; height?: number; setCleared: (clear: boolean) => void } const CancelIcon = ({ width = 17, height = 17, setCleared }: Props) => { const { term, setActiveChannel, activeChannel } = useContext(SearchContext) return term || activeChannel ? ( { e.stopPropagation() e.preventDefault() setCleared(true) setActiveChannel(undefined) }} > ) : null } CancelIcon.className = 'giphy-search-bar-cancel' export default CancelIcon