1
- import { css , SerializedStyles } from '@emotion/react' ;
1
+ /* eslint-disable no-nested-ternary */
2
+ import { css } from '@emotion/react' ;
2
3
import { ElementType , HTMLProps } from 'react' ;
3
4
4
5
type Props = {
5
6
rebound : number ;
6
- as ?: ElementType ;
7
7
bottomRebound ?: number ;
8
8
height : number ;
9
9
bottomHeight ?: number ;
10
- primaryColor ?: string ;
11
10
position ?: 'top' | 'bottom' | 'both' ;
11
+ flip ?: 'top' | 'bottom' | 'both' | 'none' ;
12
+ primaryColor ?: string ;
13
+ as ?: ElementType ;
12
14
} ;
13
15
14
16
export function ReboundSection ( {
@@ -19,38 +21,32 @@ export function ReboundSection({
19
21
height,
20
22
bottomHeight,
21
23
primaryColor,
22
- position,
24
+ position = 'top' ,
25
+ flip = 'none' ,
23
26
...props
24
27
} : Props & HTMLProps < HTMLElement > ) {
25
28
const baseStyles = css `
26
29
background-color : ${ primaryColor ?? '#000000' } ;
27
30
` ;
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
+ ` ;
29
49
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
- }
54
50
// eslint-disable-next-line react/jsx-props-no-spreading
55
51
return < Section css = { [ baseStyles , styles , externalStyles ] } { ...props } /> ;
56
52
}
0 commit comments