|
| 1 | +import React from 'react'; |
| 2 | +import propTypes from 'prop-types'; |
| 3 | +import styled from 'styled-components'; |
| 4 | + |
| 5 | +import { StyledCutout } from '../Cutout/Cutout'; |
| 6 | + |
| 7 | +const Wrapper = styled.div` |
| 8 | + position: relative; |
| 9 | + display: inline-block; |
| 10 | + padding-bottom: 26px; |
| 11 | +`; |
| 12 | + |
| 13 | +const Inner = styled.div` |
| 14 | + position: relative; |
| 15 | +`; |
| 16 | + |
| 17 | +const Monitor = styled.div` |
| 18 | + position: relative; |
| 19 | + z-index: 1; |
| 20 | + box-sizing: border-box; |
| 21 | + width: 195px; |
| 22 | + height: 155px; |
| 23 | + padding: 12px; |
| 24 | + background: ${({ theme }) => theme.material}; |
| 25 | + border-top: 4px solid ${({ theme }) => theme.borderLightest}; |
| 26 | + border-left: 4px solid ${({ theme }) => theme.borderLightest}; |
| 27 | + border-bottom: 4px solid ${({ theme }) => theme.borderDark}; |
| 28 | + border-right: 4px solid ${({ theme }) => theme.borderDark}; |
| 29 | +
|
| 30 | + outline: 1px dotted ${({ theme }) => theme.material}; |
| 31 | + outline-offset: -3px; |
| 32 | + &:before { |
| 33 | + content: ''; |
| 34 | + position: absolute; |
| 35 | + left: 0; |
| 36 | + top: 0; |
| 37 | + width: 100%; |
| 38 | + height: 100%; |
| 39 | + outline: 1px dotted ${({ theme }) => theme.material}; |
| 40 | + } |
| 41 | + box-shadow: 1px 1px 0 1px ${({ theme }) => theme.borderDarkest}; |
| 42 | +
|
| 43 | + &:after { |
| 44 | + content: ''; |
| 45 | + display: inline-block; |
| 46 | + position: absolute; |
| 47 | + bottom: 4px; |
| 48 | + right: 12px; |
| 49 | + width: 10px; |
| 50 | + border-top: 2px solid #4d9046; |
| 51 | + border-bottom: 2px solid #07ff00; |
| 52 | + } |
| 53 | +`; |
| 54 | + |
| 55 | +const Background = styled(StyledCutout).attrs(() => ({ |
| 56 | + 'data-testid': 'background' |
| 57 | +}))` |
| 58 | + width: 100%; |
| 59 | + height: 100%; |
| 60 | +`; |
| 61 | + |
| 62 | +const Stand = styled.div` |
| 63 | + box-sizing: border-box; |
| 64 | + position: absolute; |
| 65 | + top: calc(100% + 2px); |
| 66 | + left: 50%; |
| 67 | + transform: translateX(-50%); |
| 68 | + height: 10px; |
| 69 | + width: 50%; |
| 70 | + background: ${({ theme }) => theme.material}; |
| 71 | + border-left: 2px solid ${({ theme }) => theme.borderLightest}; |
| 72 | + border-bottom: 2px solid ${({ theme }) => theme.borderDarkest}; |
| 73 | + border-right: 2px solid ${({ theme }) => theme.borderDarkest}; |
| 74 | + box-shadow: inset 0px 0px 0px 2px ${({ theme }) => theme.borderDark}; |
| 75 | +
|
| 76 | + &:before { |
| 77 | + content: ''; |
| 78 | + position: absolute; |
| 79 | + top: calc(100% + 2px); |
| 80 | + left: 50%; |
| 81 | + transform: translateX(-50%); |
| 82 | + width: 80%; |
| 83 | + height: 8px; |
| 84 | + background: ${({ theme }) => theme.material}; |
| 85 | + border-left: 2px solid ${({ theme }) => theme.borderLightest}; |
| 86 | + border-right: 2px solid ${({ theme }) => theme.borderDarkest}; |
| 87 | + box-shadow: inset 0px 0px 0px 2px ${({ theme }) => theme.borderDark}; |
| 88 | + } |
| 89 | + &:after { |
| 90 | + content: ''; |
| 91 | + position: absolute; |
| 92 | + top: calc(100% + 8px); |
| 93 | + left: 50%; |
| 94 | + transform: translateX(-50%); |
| 95 | + width: 150%; |
| 96 | + height: 4px; |
| 97 | + background: ${({ theme }) => theme.material}; |
| 98 | + border: 2px solid ${({ theme }) => theme.borderDark}; |
| 99 | + border-bottom: none; |
| 100 | + box-shadow: inset 1px 1px 0px 1px ${({ theme }) => theme.borderLightest}, |
| 101 | + 1px 1px 0 1px ${({ theme }) => theme.borderDarkest}; |
| 102 | + } |
| 103 | +`; |
| 104 | + |
| 105 | +const Desktop = React.forwardRef(function Desktop(props, ref) { |
| 106 | + const { backgroundStyles, children, ...otherProps } = props; |
| 107 | + |
| 108 | + return ( |
| 109 | + <Wrapper ref={ref} {...otherProps}> |
| 110 | + <Inner> |
| 111 | + <Monitor> |
| 112 | + <Background style={backgroundStyles}>{children}</Background> |
| 113 | + </Monitor> |
| 114 | + <Stand /> |
| 115 | + </Inner> |
| 116 | + </Wrapper> |
| 117 | + ); |
| 118 | +}); |
| 119 | + |
| 120 | +Desktop.defaultProps = { |
| 121 | + backgroundStyles: null |
| 122 | +}; |
| 123 | + |
| 124 | +Desktop.propTypes = { |
| 125 | + backgroundStyles: propTypes.object, |
| 126 | + // eslint-disable-next-line react/require-default-props |
| 127 | + children: propTypes.node |
| 128 | +}; |
| 129 | + |
| 130 | +export default Desktop; |
0 commit comments