1- import { css , SerializedStyles } from '@emotion/react' ;
1+ /* eslint-disable no-nested-ternary */
2+ import { css } from '@emotion/react' ;
23import { ElementType , HTMLProps } from 'react' ;
34
45type Props = {
56 rebound : number ;
6- as ?: ElementType ;
77 bottomRebound ?: number ;
88 height : number ;
99 bottomHeight ?: number ;
10- primaryColor ?: string ;
1110 position ?: 'top' | 'bottom' | 'both' ;
11+ flip ?: 'top' | 'bottom' | 'both' | 'none' ;
12+ primaryColor ?: string ;
13+ as ?: ElementType ;
1214} ;
1315
1416export function ReboundSection ( {
@@ -19,38 +21,32 @@ export function ReboundSection({
1921 height,
2022 bottomHeight,
2123 primaryColor,
22- position,
24+ position = 'top' ,
25+ flip = 'none' ,
2326 ...props
2427} : Props & HTMLProps < HTMLElement > ) {
2528 const baseStyles = css `
2629 background-color : ${ primaryColor ?? '#000000' } ;
2730 ` ;
28- let styles : SerializedStyles ;
31+ const polygon = [
32+ position === 'top' ? '0 100%' : flip !== 'none' && flip !== 'bottom' ? `0 100%` : `0 calc(100% - ${ bottomHeight ?? height } px)` ,
33+ position === 'top'
34+ ? '0 100%'
35+ : flip !== 'none' && flip !== 'bottom'
36+ ? `${ `${ bottomRebound ?? rebound } %` } calc(100% - ${ bottomHeight ?? height } px)`
37+ : `${ `${ bottomRebound ?? rebound } %` } 100%` ,
38+ position === 'top' ? '100% 100%' : flip !== 'none' && flip !== 'bottom' ? '100% 100%' : `100% calc(100% - ${ bottomHeight ?? height } px)` ,
39+ position === 'bottom' ? '100% 0' : flip !== 'none' && flip !== 'top' ? '100% 0' : `100% ${ height } px` ,
40+ position === 'bottom' ? '100% 0' : flip !== 'none' && flip !== 'top' ? `${ rebound } % ${ height } px` : `${ rebound } % 0` ,
41+ position === 'bottom' ? '0 0' : flip !== 'none' && flip !== 'top' ? `0 0` : `0 ${ height } px` ,
42+ ] ;
43+
44+ const styles = css `
45+ ${ position !== 'top' ? `border-bottom: ${ bottomHeight ?? height } px solid transparent;` : '' }
46+ ${ position !== 'bottom' ? `border-top: ${ height } px solid transparent;` : '' }
47+ clip-path : polygon (${ polygon . join ( ',' ) } );
48+ ` ;
2949
30- if ( position === 'bottom' ) {
31- styles = css `
32- border-bottom : ${ height } px solid transparent;
33- clip-path : polygon (0 0 , 0 calc (100% - ${ height } px), ${ rebound } % 100% , 100% calc (100% - ${ height } px), 100% 0 );
34- ` ;
35- } else if ( position === 'both' ) {
36- styles = css `
37- border-top : ${ height } px solid transparent;
38- border-bottom : ${ bottomHeight ?? height } px solid transparent;
39- clip-path : polygon (
40- 0 ${ height } px,
41- 0 calc (100% - ${ bottomHeight ?? height } px),
42- ${ `${ bottomRebound ?? rebound } %` } 100% ,
43- 100% calc (100% - ${ bottomHeight ?? height } px),
44- 100% ${ height } px,
45- ${ `${ rebound } %` } 0
46- );
47- ` ;
48- } else {
49- styles = css `
50- border-top : ${ height } px solid transparent;
51- clip-path : polygon (0 ${ height } px, 0 100% , 100% 100% , 100% ${ height } px, ${ rebound } % 0 );
52- ` ;
53- }
5450 // eslint-disable-next-line react/jsx-props-no-spreading
5551 return < Section css = { [ baseStyles , styles , externalStyles ] } { ...props } /> ;
5652}
0 commit comments