|
| 1 | +import { PropsWithChildren } from 'react'; |
| 2 | +import { IterableElement } from 'type-fest'; |
| 3 | +import { css, Theme, useTheme } from '@emotion/react'; |
| 4 | +import { Markup } from 'interweave'; |
| 5 | +import { DividedSection } from '../components/DividedSection'; |
| 6 | +import { Sprite, SpriteProps } from '../components/Sprite'; |
| 7 | + |
| 8 | +const sectionStyle = (theme: Theme) => css` |
| 9 | + position: relative; |
| 10 | + z-index: 0; |
| 11 | + overflow: hidden; |
| 12 | +
|
| 13 | + &:nth-of-type(odd) { |
| 14 | + background-color: ${theme.whiteColor}; |
| 15 | + > svg { |
| 16 | + fill: ${theme.backgroundColor}; |
| 17 | + right: 0; |
| 18 | + left: unset; |
| 19 | + } |
| 20 | + } |
| 21 | +
|
| 22 | + > svg { |
| 23 | + position: absolute; |
| 24 | + top: 0; |
| 25 | + left: 0; |
| 26 | + height: 90%; |
| 27 | + width: auto; |
| 28 | + fill: ${theme.whiteColor}; |
| 29 | + opacity: 0.5; |
| 30 | + z-index: -1; |
| 31 | + } |
| 32 | +
|
| 33 | + &:last-of-type + svg { |
| 34 | + display: none; |
| 35 | + } |
| 36 | +`; |
| 37 | + |
| 38 | +const skillStyles = (isWhiteSection: boolean) => (theme: Theme) => |
| 39 | + css` |
| 40 | + padding: ${theme.gutter}; |
| 41 | + list-style: none; |
| 42 | + display: flex; |
| 43 | + gap: ${theme.gutter}; |
| 44 | +
|
| 45 | + background-color: ${isWhiteSection ? theme.backgroundColor : theme.whiteColor}; |
| 46 | +
|
| 47 | + &:not(:last-child) { |
| 48 | + margin-bottom: ${theme.gutter}; |
| 49 | + } |
| 50 | +
|
| 51 | + --offset-size: 10rem; |
| 52 | +
|
| 53 | + &:nth-of-type(even) { |
| 54 | + margin-left: var(--offset-size); |
| 55 | + flex-direction: row-reverse; |
| 56 | + } |
| 57 | +
|
| 58 | + &:nth-of-type(odd) { |
| 59 | + margin-right: var(--offset-size); |
| 60 | + } |
| 61 | +
|
| 62 | + > div { |
| 63 | + flex: 1; |
| 64 | +
|
| 65 | + h3 { |
| 66 | + margin-top: 0; |
| 67 | + } |
| 68 | + } |
| 69 | +
|
| 70 | + svg { |
| 71 | + width: var(--offset-size); |
| 72 | + height: auto; |
| 73 | + fill: ${isWhiteSection ? theme.whiteColor : theme.backgroundColor}; |
| 74 | + } |
| 75 | + `; |
| 76 | + |
| 77 | +type StrengthsDetailSectionProps = { |
| 78 | + strength: IterableElement<Queries.StrengthsPageQuery['strengths']['nodes']>; |
| 79 | + index: number; |
| 80 | +}; |
| 81 | + |
| 82 | +export function StrengthsDetailSection({ strength, index }: StrengthsDetailSectionProps) { |
| 83 | + const theme = useTheme(); |
| 84 | + |
| 85 | + const isWhiteSection = index % 2 === 1; |
| 86 | + |
| 87 | + return ( |
| 88 | + <DividedSection upperColor={theme.whiteColor} lowerColor={theme.whiteColor} flipVertically={isWhiteSection} css={sectionStyle}> |
| 89 | + <Sprite name={strength.frontmatter?.sprite as SpriteProps['name']} /> |
| 90 | + |
| 91 | + <ul> |
| 92 | + {strength.frontmatter?.skills?.map(skill => ( |
| 93 | + <li css={skillStyles(isWhiteSection)}> |
| 94 | + <Sprite name={skill?.childMarkdownRemark?.frontmatter?.sprite as SpriteProps['name']} /> |
| 95 | + <div> |
| 96 | + <h3>{skill?.childMarkdownRemark?.frontmatter?.title}</h3> |
| 97 | + <Markup content={skill?.childMarkdownRemark?.html} /> |
| 98 | + </div> |
| 99 | + </li> |
| 100 | + ))} |
| 101 | + </ul> |
| 102 | + </DividedSection> |
| 103 | + ); |
| 104 | +} |
0 commit comments