|
| 1 | +import * as React from 'react'; |
| 2 | +import styled from 'styled-components'; // eslint-disable-line |
| 3 | +import { Toggler } from '@element-motion/dev'; // eslint-disable-line |
| 4 | +import Motion from '../../../Motion'; |
| 5 | +import Noop from '../../Noop'; |
| 6 | +import Target from '../../../FocalTarget'; |
| 7 | +import FocalReveal from '../index'; |
| 8 | + |
| 9 | +type Appearance = 'left' | 'center' | 'right'; |
| 10 | + |
| 11 | +const justifyContentMap = { |
| 12 | + left: 'flex-start', |
| 13 | + center: 'center', |
| 14 | + right: 'flex-end', |
| 15 | +}; |
| 16 | + |
| 17 | +const List = styled.div<{ appearance: Appearance }>` |
| 18 | + display: flex; |
| 19 | + justify-content: ${props => justifyContentMap[props.appearance]}; |
| 20 | +`; |
| 21 | + |
| 22 | +interface ListItemProps { |
| 23 | + height: number; |
| 24 | + width: number; |
| 25 | +} |
| 26 | + |
| 27 | +const ListItem = styled.div<ListItemProps>` |
| 28 | + background-color: #dc143c; |
| 29 | + height: ${props => props.height}px; |
| 30 | + width: ${props => props.width}px; |
| 31 | + position: relative; |
| 32 | + cursor: pointer; |
| 33 | +
|
| 34 | + &:before { |
| 35 | + content: 'click me'; |
| 36 | + text-align: center; |
| 37 | + left: 0; |
| 38 | + right: 0; |
| 39 | + position: absolute; |
| 40 | + color: rgba(255, 255, 255, 0.9); |
| 41 | + font-size: 24px; |
| 42 | + font-family: Roboto, HelveticaNeue, Arial, sans-serif; |
| 43 | + top: 70%; |
| 44 | + } |
| 45 | +
|
| 46 | + &:after { |
| 47 | + content: '😊'; |
| 48 | + position: absolute; |
| 49 | + display: flex; |
| 50 | + align-items: center; |
| 51 | + justify-content: center; |
| 52 | + font-size: 50px; |
| 53 | + top: 0; |
| 54 | + bottom: 0; |
| 55 | + right: 0; |
| 56 | + left: 0; |
| 57 | + pointer-events: none; |
| 58 | + } |
| 59 | +`; |
| 60 | + |
| 61 | +type Orientation = 'horizontal' | 'vertical' | 'both'; |
| 62 | + |
| 63 | +interface TallListItemProps extends ListItemProps { |
| 64 | + orientation: Orientation; |
| 65 | +} |
| 66 | + |
| 67 | +const TallListItem = styled.div<TallListItemProps>` |
| 68 | + display: flex; |
| 69 | + align-items: center; |
| 70 | + background: rgb(210, 215, 225); |
| 71 | + margin: 0 auto; |
| 72 | + height: ${props => |
| 73 | + props.orientation === 'both' || props.orientation === 'vertical' |
| 74 | + ? props.height * 3 |
| 75 | + : props.height}px; |
| 76 | + max-width: ${props => |
| 77 | + props.orientation === 'both' || props.orientation === 'horizontal' |
| 78 | + ? props.width * 3 |
| 79 | + : props.width}px; |
| 80 | +`; |
| 81 | + |
| 82 | +export const build = ( |
| 83 | + width: number, |
| 84 | + height: number, |
| 85 | + orientation: Orientation, |
| 86 | + appearance: Appearance, |
| 87 | + useClipPath = false |
| 88 | +) => ( |
| 89 | + <Toggler> |
| 90 | + {({ shown, toggle }) => ( |
| 91 | + <React.Fragment> |
| 92 | + {shown || ( |
| 93 | + <List appearance={appearance}> |
| 94 | + <Motion name={`reveal-move-${orientation}-${appearance}-${useClipPath}`}> |
| 95 | + <FocalReveal |
| 96 | + childrenTransformX={useClipPath || orientation === 'vertical'} |
| 97 | + childrenTransformY={useClipPath || orientation === 'horizontal'} |
| 98 | + useClipPath={useClipPath} |
| 99 | + > |
| 100 | + {motion => ( |
| 101 | + <ListItem {...motion} onClick={() => toggle()} width={width} height={height} /> |
| 102 | + )} |
| 103 | + </FocalReveal> |
| 104 | + </Motion> |
| 105 | + </List> |
| 106 | + )} |
| 107 | + |
| 108 | + {shown && ( |
| 109 | + <Motion name={`reveal-move-${orientation}-${appearance}-${useClipPath}`}> |
| 110 | + <Noop> |
| 111 | + {motion => ( |
| 112 | + <TallListItem {...motion} width={width} height={height} orientation={orientation}> |
| 113 | + <Target> |
| 114 | + {target => ( |
| 115 | + <ListItem |
| 116 | + width={width} |
| 117 | + height={height} |
| 118 | + onClick={() => toggle()} |
| 119 | + ref={target.ref} |
| 120 | + /> |
| 121 | + )} |
| 122 | + </Target> |
| 123 | + </TallListItem> |
| 124 | + )} |
| 125 | + </Noop> |
| 126 | + </Motion> |
| 127 | + )} |
| 128 | + </React.Fragment> |
| 129 | + )} |
| 130 | + </Toggler> |
| 131 | +); |
0 commit comments