import React from 'react' import Link from 'next/link' import Category from './interfaces/Category' import '../styl/styl.styl' import { ChevronRight } from 'react-feather' import Router from 'next/router' interface Props { categories?: Category[] onQuery?: (query: string) => void onHeight?: (height: number) => void } interface States { follow?: boolean height?: number } export default class Filters extends React.Component { private aside = undefined private input = undefined constructor(props: Props) { super(props) } setRef = element => { this.aside = element } setInput = element => { this.input = element } onScroll = () => { this.setState({ follow: window.pageYOffset > 217 }) } onKeyDown = (ev: React.KeyboardEvent) => { setTimeout(() => { this.submit() }, 1); } onClick = () => { if (this.input.value !== "") { this.submit() return } this.input.focus() } submit = () => { if (this.props.onQuery) this.props.onQuery(this.input.value) } componentDidMount() { this.onScroll() this.setState({ height: this.aside.clientHeight }) if (this.props.onHeight) this.props.onHeight(this.aside.clientHeight) window.addEventListener('scroll', this.onScroll) } componentWillUnmount() { window.removeEventListener('scroll', this.onScroll) } render() { return ( ) } }