From 75880040260af1ff6c86d167ddc727ef07d51a4c Mon Sep 17 00:00:00 2001 From: Mike Allanson Date: Fri, 2 Feb 2018 22:49:13 +0000 Subject: [PATCH] [www] add search input to home page (#3662) * Experiment adding search input to home page * Prettier * Comment unused imports * Display social icons when viewport is wide enough * Use alternate colours at Hd breakpoint on home page --- www/src/components/navigation.js | 58 ++++++++------ www/src/components/search-form.js | 121 +++++++++++++++++++----------- www/src/components/search-icon.js | 22 ++++++ www/static/search.svg | 1 - 4 files changed, 134 insertions(+), 68 deletions(-) create mode 100644 www/src/components/search-icon.js delete mode 100644 www/static/search.svg diff --git a/www/src/components/navigation.js b/www/src/components/navigation.js index 383e55d27f7dc..25743e2906585 100644 --- a/www/src/components/navigation.js +++ b/www/src/components/navigation.js @@ -1,10 +1,9 @@ import React from "react" import Link from "gatsby-link" -import GithubIcon from "react-icons/lib/go/mark-github" import TwitterIcon from "react-icons/lib/fa/twitter" - -import SearchForm from "../components/search-form" import DiscordIcon from "../components/discord" +import GithubIcon from "react-icons/lib/go/mark-github" +import SearchForm from "../components/search-form" import logo from "../logo.svg" import typography, { rhythm, scale } from "../utils/typography" import presets, { colors } from "../utils/presets" @@ -163,9 +162,11 @@ export default ({ pathname }) => { marginLeft: `auto`, }} > - {!isHomepage && ( - - )} + { > - - - - - - + + + + + + + diff --git a/www/src/components/search-form.js b/www/src/components/search-form.js index 9e3a12f112dd7..c6294e1a2e20d 100644 --- a/www/src/components/search-form.js +++ b/www/src/components/search-form.js @@ -2,11 +2,15 @@ import React, { Component } from "react" import PropTypes from "prop-types" import { navigateTo } from "gatsby-link" import { rhythm } from "../utils/typography" + import presets, { colors } from "../utils/presets" import hex2rgba from "hex2rgba" +import SearchIcon from './search-icon' import { css } from "glamor" +const { curveDefault, speedDefault } = presets.animation + // Override default search result styles (docsearch.css) css.insert(` .algolia-autocomplete .ds-dropdown-menu { @@ -227,7 +231,7 @@ css.insert(` class SearchForm extends Component { constructor() { super() - this.state = { enabled: true } + this.state = { enabled: true, focussed: false } this.autocompleteSelected = this.autocompleteSelected.bind(this) this.focusSearchInput = this.focusSearchInput.bind(this) } @@ -293,12 +297,12 @@ class SearchForm extends Component { } render() { - const { enabled } = this.state - const { styles } = this.props.styles + const { enabled, focussed } = this.state + const { iconStyles, isHomepage } = this.props + return enabled ? (
e.preventDefault()} > - + { - this.searchInput = input - }} - /> + color: colors.gatsby, + paddingTop: rhythm(1 / 8), + paddingRight: rhythm(1 / 4), + paddingBottom: rhythm(1 / 8), + paddingLeft: rhythm(1), + overflow: `hidden`, + width: rhythm(1), + transition: `width ${speedDefault} ${curveDefault}, background-color ${speedDefault} ${curveDefault}`, + ":focus": { + outline: 0, + backgroundColor: colors.ui.light, + borderRadius: presets.radiusLg, + width: rhythm(5), + transition: `width ${speedDefault} ${curveDefault}, background-color ${speedDefault} ${curveDefault}`, + }, + + [presets.Desktop]: { + backgroundColor: !isHomepage && `#fff`, + color: colors.gatsby, + width: !isHomepage && rhythm(5), + ":focus": { + backgroundColor: colors.ui.light, + color: colors.gatsby, + }, + }, + + [presets.Hd]: { + backgroundColor: isHomepage && colors.lilac, + color: isHomepage && colors.ui.light, + width: isHomepage && rhythm(5), + }, + }} + type="search" + placeholder="Search docs" + aria-label="Search docs" + title="Hit 's' to search docs" + onFocus={() => this.setState({ focussed: true })} + onBlur={() => this.setState({ focussed: false })} + ref={input => { + this.searchInput = input + }} + /> + + ) : null } } SearchForm.propTypes = { - styles: PropTypes.object, + isHomepage: PropTypes.bool, + iconStyles: PropTypes.object, } export default SearchForm diff --git a/www/src/components/search-icon.js b/www/src/components/search-icon.js new file mode 100644 index 0000000000000..aa8fd8fcc6df1 --- /dev/null +++ b/www/src/components/search-icon.js @@ -0,0 +1,22 @@ +import React from "react" +import PropTypes from "prop-types" + +const SearchIcon = ({ overrideCSS }) => ( + + {/* Based on the 'search' icon in https://github.com/ionic-team/ionicons */} + + + + +) + +SearchIcon.propTypes = { + overrideCSS: PropTypes.object, +} + +export default SearchIcon diff --git a/www/static/search.svg b/www/static/search.svg deleted file mode 100644 index 0a5e697dd7b26..0000000000000 --- a/www/static/search.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file