From 70775bc705dd79f35b99eae7f37a0484d176ce22 Mon Sep 17 00:00:00 2001 From: madelinegr Date: Tue, 11 Jun 2019 15:02:45 -0400 Subject: things sort of working with toggle? --- src/client/views/search/SearchBox.tsx | 4 +-- src/client/views/search/ToggleBar.tsx | 58 ++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index 67122b320..836062af6 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -33,7 +33,7 @@ export class SearchBox extends React.Component { @observable private _open: boolean = false; @observable private _resultsOpen: boolean = false; @observable private _results: Doc[] = []; - @observable forceReRender: boolean = false; + @observable filterBoxStatus: boolean = false; @action.bound onChange(e: React.ChangeEvent) { @@ -243,7 +243,7 @@ export class SearchBox extends React.Component {
- +
diff --git a/src/client/views/search/ToggleBar.tsx b/src/client/views/search/ToggleBar.tsx index 5ede368d6..6d721b774 100644 --- a/src/client/views/search/ToggleBar.tsx +++ b/src/client/views/search/ToggleBar.tsx @@ -1,15 +1,14 @@ import * as React from 'react'; import { observer } from 'mobx-react'; -import { observable, action, runInAction } from 'mobx'; +import { observable, action, runInAction, computed } from 'mobx'; import "./SearchBox.scss"; import "./ToggleBar.scss"; import * as anime from 'animejs'; export interface ToggleBarProps { //false = right, true = left - // status: boolean; changeStatus(): void; - // changeStatus(value: boolean): void; + originalStatus: boolean; optionOne: string; optionTwo: string; } @@ -18,21 +17,29 @@ export interface ToggleBarProps { @observer export class ToggleBar extends React.Component{ - @observable _status: boolean = false; - @observable timeline: anime.AnimeTimelineInstance; + @observable _wordStatus: boolean = true; + @observable forwardTimeline: anime.AnimeTimelineInstance; + @observable reverseTimeline: anime.AnimeTimelineInstance; @observable _toggleButton: React.RefObject; + @observable _originalStatus: boolean = this.props.originalStatus; constructor(props: ToggleBarProps) { super(props); this._toggleButton = React.createRef(); - this.timeline = anime.timeline({ + this.forwardTimeline = anime.timeline({ autoplay: false, direction: "reverse" }); + this.reverseTimeline = anime.timeline({ + autoplay: false, + direction: "reverse" + }); + } - componentDidMount = () => { + @computed get totalWidth() { return this.getTotalWidth(); } + getTotalWidth() { let bar = document.getElementById("toggle-bar"); let tog = document.getElementById("toggle-button"); let barwidth = 0; @@ -42,23 +49,46 @@ export class ToggleBar extends React.Component{ togwidth = tog.clientWidth; } let totalWidth = (barwidth - togwidth - 10); + return totalWidth; + } + + componentDidMount = () => { - this.timeline.add({ + let totalWidth = this.totalWidth; + + this.forwardTimeline.add({ targets: this._toggleButton.current, loop: false, translateX: totalWidth, easing: "easeInOutQuad", - duration: 500 + duration: 500, }); + + this.reverseTimeline.add({ + targets: this._toggleButton.current, + loop: false, + translateX: -totalWidth, + easing: "easeInOutQuad", + duration: 500, + }); + } @action.bound onclick() { - // this._status = !this._status; - // this.props.changeStatus(this._status); + console.log(this._originalStatus) + + if (this._originalStatus) { + this.forwardTimeline.play(); + this.forwardTimeline.reverse(); + } + else { + this.reverseTimeline.play(); + this.reverseTimeline.reverse(); + } + + this._wordStatus = !this._wordStatus; this.props.changeStatus(); - this.timeline.play(); - this.timeline.reverse(); } render() { @@ -68,7 +98,7 @@ export class ToggleBar extends React.Component{
{this.props.optionOne}
{this.props.optionTwo}
-
+
-- cgit v1.2.3-70-g09d2