From 61263dc23b0202e5b8dd50d30d78983880ee25f5 Mon Sep 17 00:00:00 2001 From: Viktor Bersch Date: Mon, 5 Aug 2019 12:28:52 +0200 Subject: [PATCH 1/5] WIP: transform FilterBar to FC --- .../src/components/FilterBar/FilterBar.jss.ts | 15 +++- .../main/src/components/FilterBar/index.tsx | 77 +++++++++++-------- 2 files changed, 57 insertions(+), 35 deletions(-) diff --git a/packages/main/src/components/FilterBar/FilterBar.jss.ts b/packages/main/src/components/FilterBar/FilterBar.jss.ts index 85b0e56211f..d015ebb3ad0 100644 --- a/packages/main/src/components/FilterBar/FilterBar.jss.ts +++ b/packages/main/src/components/FilterBar/FilterBar.jss.ts @@ -28,7 +28,20 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => { flexWrap: 'wrap', paddingTop: '1rem', paddingBottom: '1rem', - background: parameters.sapUiObjectHeaderBackground + background: parameters.sapUiObjectHeaderBackground, + transition: 'max-height 0.2s, opacity 0.2s ease-in' + // overflow: 'hidden' + // '& > *': { + // marginBottom: '10px' + // } + }, + filterAreaClosed: { + maxHeight: '0', + opacity: 0 + }, + filterAreaOpen: { + maxHeight: '500px', + opacity: 1 }, '@media (max-width: 599px)': { filterArea: { diff --git a/packages/main/src/components/FilterBar/index.tsx b/packages/main/src/components/FilterBar/index.tsx index d77fff8a866..fed11aaf9ba 100644 --- a/packages/main/src/components/FilterBar/index.tsx +++ b/packages/main/src/components/FilterBar/index.tsx @@ -1,10 +1,12 @@ -import { withStyles } from '@ui5/webcomponents-react-base'; -import React, { PureComponent, ReactNode, ReactNodeArray } from 'react'; +import React, { FC, forwardRef, ReactNode, ReactNodeArray, RefObject, useCallback, useState } from 'react'; import { ClassProps } from '../../interfaces/ClassProps'; import { CommonProps } from '../../interfaces/CommonProps'; import { Button } from '../../lib/Button'; import { ButtonDesign } from '../../lib/ButtonDesign'; import styles from './FilterBar.jss'; +import { createUseStyles } from 'react-jss'; +import { JSSTheme } from '../../interfaces/JSSTheme'; +import { StyleClassHelper } from '@ui5/webcomponents-react-base'; export interface FilterBarPropTypes extends CommonProps { renderVariants?: () => JSX.Element; @@ -14,37 +16,44 @@ export interface FilterBarPropTypes extends CommonProps { interface FilterBarInternalProps extends FilterBarPropTypes, ClassProps {} -@withStyles(styles) -export class FilterBar extends PureComponent { - static defaultProps = { - children: '', - displayOnly: true - }; - - state = { - showFilters: true - }; - - handleHideFilterBar = () => { - this.setState({ showFilters: !this.state.showFilters }); - }; - - render() { - const { children, classes, renderVariants, renderSearch, innerRef } = this.props as FilterBarInternalProps; - - return ( -
-
- {renderVariants && renderVariants()} - {renderSearch &&
{renderSearch()}
} -
- -
+const useStyles = createUseStyles>(styles, { name: 'FilterBar' }); + +const FilterBar: FC = forwardRef((props: FilterBarPropTypes, ref: RefObject) => { + const { children, renderVariants, renderSearch } = props as FilterBarInternalProps; + const [showFilters, setShowFilters] = useState(true); + + const classes = useStyles(); + + const handleHideFilterBar = useCallback(() => { + setShowFilters(!showFilters); + }, [showFilters]); + + const filterAreaClasses = StyleClassHelper.of(classes.filterArea); + if (showFilters) { + filterAreaClasses.put(classes.filterAreaOpen); + } else { + filterAreaClasses.put(classes.filterAreaClosed); + } + + return ( +
+
+ {renderVariants && renderVariants()} + {renderSearch &&
{renderSearch()}
} +
+
- {this.state.showFilters &&
{children}
}
- ); - } -} +
{children}
+
+ ); +}); + +FilterBar.defaultProps = { + children: '' +}; + +FilterBar.displayName = 'FilterBar'; +export { FilterBar }; From 04e761aebbd50c4caddd67528ec908cf8bed33f0 Mon Sep 17 00:00:00 2001 From: Viktor Bersch Date: Mon, 5 Aug 2019 13:33:13 +0200 Subject: [PATCH 2/5] fix(FilterBar): add vertical margin between FilterItems --- .../src/components/FilterBar/FilterBar.jss.ts | 34 +------------------ .../components/FilterItem/FilterItem.jss.ts | 3 +- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/packages/main/src/components/FilterBar/FilterBar.jss.ts b/packages/main/src/components/FilterBar/FilterBar.jss.ts index d015ebb3ad0..dda5654e32a 100644 --- a/packages/main/src/components/FilterBar/FilterBar.jss.ts +++ b/packages/main/src/components/FilterBar/FilterBar.jss.ts @@ -29,11 +29,7 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => { paddingTop: '1rem', paddingBottom: '1rem', background: parameters.sapUiObjectHeaderBackground, - transition: 'max-height 0.2s, opacity 0.2s ease-in' - // overflow: 'hidden' - // '& > *': { - // marginBottom: '10px' - // } + transition: 'max-height 0.2s ease-out, opacity 0.2s ease-in' }, filterAreaClosed: { maxHeight: '0', @@ -43,34 +39,6 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => { maxHeight: '500px', opacity: 1 }, - '@media (max-width: 599px)': { - filterArea: { - columnCount: 3, - columnGap: '0.5rem', - rowGap: '0.5rem' - } - }, - '@media (min-width: 600px) and (max-width: 1023px)': { - filterArea: { - columnCount: 8, - columnGap: '1rem', - rowGap: '1rem' - } - }, - '@media (min-width: 1024px) and (max-width: 1439px)': { - filterArea: { - columnCount: 12, - columnGap: '1rem', - rowGap: '1rem' - } - }, - '@media (min-width: 1440px)': { - filterArea: { - columnCount: 16, - columnGap: '1rem', - rowGap: '1rem' - } - }, headerRowRight: { display: 'flex', justifyContent: 'flex-end', diff --git a/packages/main/src/components/FilterItem/FilterItem.jss.ts b/packages/main/src/components/FilterItem/FilterItem.jss.ts index 8a8cd285123..54d6a0560b6 100644 --- a/packages/main/src/components/FilterItem/FilterItem.jss.ts +++ b/packages/main/src/components/FilterItem/FilterItem.jss.ts @@ -2,7 +2,8 @@ const styles = { filterItem: { minWidth: '10rem', height: 'fit-content', - marginRight: '0.5rem' + marginRight: '1rem', + marginBottom: '1rem' }, innerFilterItemContainer: { display: 'flex', From 10c59c11ed4590fa79f859ff1e538d5c0ebe8d7a Mon Sep 17 00:00:00 2001 From: Viktor Bersch Date: Mon, 5 Aug 2019 13:36:20 +0200 Subject: [PATCH 3/5] WIP: update tests --- .../__karma_snapshots__/AnalyticalTable.md | 572 ++++++--------- .../main/__karma_snapshots__/FilterBar.md | 654 +++++++++--------- 2 files changed, 540 insertions(+), 686 deletions(-) diff --git a/packages/main/__karma_snapshots__/AnalyticalTable.md b/packages/main/__karma_snapshots__/AnalyticalTable.md index 197685b5af7..6e386884e28 100644 --- a/packages/main/__karma_snapshots__/AnalyticalTable.md +++ b/packages/main/__karma_snapshots__/AnalyticalTable.md @@ -20,7 +20,7 @@
- +
@@ -153,11 +153,9 @@
-
- - Friend Age - -
+ + Friend Age +
@@ -256,38 +254,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -300,38 +290,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -344,38 +326,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -388,38 +362,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -432,38 +398,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -476,38 +434,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -520,38 +470,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -564,38 +506,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -607,8 +541,8 @@
- - + +
- +
@@ -806,11 +740,9 @@
-
- - Friend Age - -
+ + Friend Age +
@@ -881,38 +813,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -925,38 +849,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -969,38 +885,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1013,38 +921,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1057,38 +957,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1101,38 +993,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1145,38 +1029,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1189,38 +1065,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1233,38 +1101,30 @@
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
- - -   - - + +   +
@@ -1276,8 +1136,8 @@
- - + +