From 4a1b0823a3a27244b86a2206df2ba1fc55cc1164 Mon Sep 17 00:00:00 2001 From: Abhas Bhattacharya Date: Mon, 2 Apr 2018 03:49:21 +0530 Subject: [PATCH] Singleday expand-contract implemented --- package.json | 2 + .../SingleDayForecast/Component.css | 39 +++++++++++++++-- .../SingleDayForecast/Component.tsx | 43 ++++++++++++++++--- yarn.lock | 8 ++++ 4 files changed, 82 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index dd714e8..206cf82 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { + "classnames": "^2.2.5", "moment-timezone": "^0.5.14", "open-weather-icons": "^0.0.7", "react": "^16.2.0", @@ -16,6 +17,7 @@ "eject": "react-scripts-ts eject" }, "devDependencies": { + "@types/classnames": "^2.2.3", "@types/jest": "^22.2.2", "@types/moment-timezone": "^0.5.4", "@types/node": "^9.6.0", diff --git a/src/Components/SingleDayForecast/Component.css b/src/Components/SingleDayForecast/Component.css index 76bf7c9..0483a8c 100644 --- a/src/Components/SingleDayForecast/Component.css +++ b/src/Components/SingleDayForecast/Component.css @@ -2,13 +2,15 @@ float: left; width: 20%; height: 100%; - + padding: 0 .5em; - + font-size: 1.25em; } .SingleDayForecast .SingleDayForecast-inner { + position: relative; + width: 100%; height: 100%; @@ -16,14 +18,25 @@ } .SingleDayForecast .summary { - position: relative; + position: absolute; padding: 0 0.5em; padding-bottom: .5em; + top: 0; + left: 0; + width: 100%; height: 40%; + + transition: 1s all; } +.SingleDayForecast.maximize .summary { + top: 45%; + transform: translate(0, -50%); +} + + .SingleDayForecast .summary>* { padding: 0.125em 0; } @@ -80,9 +93,29 @@ background-color: #000; transform: translateX(-50%); + + transition: opacity 1s; +} + +.SingleDayForecast.maximize .summary .bottom-dividor{ + opacity: 0; } .SingleDayForecast .details { + position: absolute; + + top: 40%; + left: 0; + width: 100%; height: 60%; + overflow: auto; + + transition: visibility 0s 1s; +} + +.SingleDayForecast.maximize .details { + visibility: hidden; + + transition: visibility 0s 0s; } \ No newline at end of file diff --git a/src/Components/SingleDayForecast/Component.tsx b/src/Components/SingleDayForecast/Component.tsx index 90e6c0d..ff07027 100644 --- a/src/Components/SingleDayForecast/Component.tsx +++ b/src/Components/SingleDayForecast/Component.tsx @@ -1,4 +1,5 @@ import * as React from 'react'; +import * as classnames from 'classnames'; import './Component.css'; import '../../../node_modules/open-weather-icons/dist/css/open-weather-icons.css'; import { Forecast5DaysSeperated, ForecaseAtInstance, Utils } from '../../Utils'; @@ -11,12 +12,16 @@ export interface SingleDayForecastProps { type numberOrString = number | string; -export class SingleDayForecast extends React.Component { +export class SingleDayForecast extends React.Component { constructor(props: SingleDayForecastProps) { super(props); this.props = props; + this.state = { maximized: true }; + + this.minimizeIfAlreadyMaximized = this.minimizeIfAlreadyMaximized.bind(this); + this.maximizeIfAlreadyMinimized = this.maximizeIfAlreadyMinimized.bind(this); // this.state = { data: undefined }; } @@ -88,14 +93,38 @@ export class SingleDayForecast extends React.Component { return { maximized: !prevState.maximized }; }); + } + + maximizeIfAlreadyMinimized() { + if (!this.state.maximized) { + this.changeMaximize(); + } + } + + minimizeIfAlreadyMaximized() { + if (this.state.maximized) { + this.changeMaximize(); + } + } + render() { const day = Utils.createDateFromEpochInIndiaTZ(this.props.forecastCurrentDay[0].dt); const summary = this.calcSummary(); + const TagNameSingleDay = 'SingleDayForecast'; + return ( -
-
-
+
+
+
@@ -116,7 +145,7 @@ export class SingleDayForecast extends React.Component {summary.avgTemp.toFixed(0)}°C
-
+
@@ -126,7 +155,7 @@ export class SingleDayForecast extends React.Component {summary.avgHumidity.toFixed(0)} %
-
+
@@ -135,7 +164,7 @@ export class SingleDayForecast extends React.Component { return ; })} -
+
); diff --git a/yarn.lock b/yarn.lock index 20dd333..37e0574 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16,6 +16,10 @@ esutils "^2.0.2" js-tokens "^3.0.0" +"@types/classnames@^2.2.3": + version "2.2.3" + resolved "https://registry.yarnpkg.com/@types/classnames/-/classnames-2.2.3.tgz#3f0ff6873da793870e20a260cada55982f38a9e5" + "@types/jest@^22.2.2": version "22.2.2" resolved "https://registry.yarnpkg.com/@types/jest/-/jest-22.2.2.tgz#afe5dacbd00d65325f52da0ed3e76e259629ac9d" @@ -1450,6 +1454,10 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +classnames@^2.2.5: + version "2.2.5" + resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.2.5.tgz#fb3801d453467649ef3603c7d61a02bd129bde6d" + clean-css@4.1.x: version "4.1.11" resolved "https://registry.yarnpkg.com/clean-css/-/clean-css-4.1.11.tgz#2ecdf145aba38f54740f26cefd0ff3e03e125d6a"