1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-06-30 05:31:56 +02:00

search field animation

This commit is contained in:
Matthias Kretschmann 2018-08-27 19:42:09 +02:00
parent 57b21190cb
commit e708904f64
Signed by: m
GPG Key ID: 606EEEF3C479A91F
4 changed files with 57 additions and 27 deletions

View File

@ -54,6 +54,7 @@
"react-modal": "^3.5.1", "react-modal": "^3.5.1",
"react-qr-svg": "^2.1.0", "react-qr-svg": "^2.1.0",
"react-time": "^4.3.0", "react-time": "^4.3.0",
"react-transition-group": "^2.4.0",
"slugify": "^1.3.1", "slugify": "^1.3.1",
"vex-js": "^4.1.0" "vex-js": "^4.1.0"
}, },

View File

@ -22,6 +22,8 @@
///////////////////////////////////// /////////////////////////////////////
.document { .document {
@include transition;
width: 100%; width: 100%;
padding-top: ($spacer * 2); padding-top: ($spacer * 2);
background-color: $page-background-color; background-color: $page-background-color;
@ -36,8 +38,6 @@
} }
@media (min-width: $screen-sm) { @media (min-width: $screen-sm) {
@include transition;
margin-top: $spacer * 2.65; margin-top: $spacer * 2.65;
margin-bottom: $spacer * 20; // height of footer margin-bottom: $spacer * 20; // height of footer
position: relative; position: relative;

View File

@ -1,6 +1,7 @@
import React, { PureComponent, Fragment } from 'react' import React, { PureComponent, Fragment } from 'react'
// import { Link } from 'gatsby' // import { Link } from 'gatsby'
import Helmet from 'react-helmet' import Helmet from 'react-helmet'
import { CSSTransition } from 'react-transition-group'
import Input from '../atoms/Input' import Input from '../atoms/Input'
import SearchIcon from '../svg/MagnifyingGlass' import SearchIcon from '../svg/MagnifyingGlass'
import styles from './Search.module.scss' import styles from './Search.module.scss'
@ -10,9 +11,7 @@ class Search extends PureComponent {
super(props) super(props)
this.state = { this.state = {
searchOpen: false, searchOpen: false
query: '',
results: []
} }
} }
@ -40,22 +39,29 @@ class Search extends PureComponent {
</button> </button>
{this.state.searchOpen && ( {this.state.searchOpen && (
<section className={styles.search}> <CSSTransition
<Input appear={this.state.searchOpen}
autoFocus in={this.state.searchOpen}
type="search" timeout={200}
placeholder="Search everything" classNames={styles}
onBlur={this.toggleSearch} >
value={this.state.query} <section className={styles.search}>
// onChange={this.search} <Input
/> autoFocus
<button type="search"
className={styles.searchInputClose} placeholder="Search everything"
onClick={this.toggleSearch} onBlur={this.toggleSearch}
> // value={this.state.query}
&times; // onChange={this.search}
</button> />
</section> <button
className={styles.searchInputClose}
onClick={this.toggleSearch}
>
&times;
</button>
</section>
</CSSTransition>
)} )}
</Fragment> </Fragment>
) )

View File

@ -38,16 +38,15 @@
right: $spacer / 2; right: $spacer / 2;
top: 0; top: 0;
z-index: 10; z-index: 10;
// transition: transform .3s ease-out;
// transform: translate3d(0, -150%, 0);
// :global(.has-search-open) & {
// transform: translate3d(0, 0, 0);
// }
input { input {
width: 100%; width: 100%;
} }
@media (min-width: $screen-md) {
left: 0;
right: 0;
}
} }
.searchInputClose { .searchInputClose {
@ -55,3 +54,27 @@
right: $spacer / 4; right: $spacer / 4;
top: $spacer / 4; top: $spacer / 4;
} }
.appear,
.enter {
opacity: .01;
transform: translate3d(0, -100px, 0);
&.appearActive,
&.enterActive {
opacity: 1;
transition: 200ms cubic-bezier(.4, 1.72, .61, .7);
transform: translate3d(0, 0, 0);
}
}
.exit {
opacity: 1;
transform: translate3d(0, 0, 0);
&.exitActive {
opacity: .01;
transition: 200ms ease-in;
transform: translate3d(0, -100px, 0);
}
}