|
| 1 | +import React from 'react'; |
| 2 | +import styled from 'styled-components'; |
| 3 | +import { Icon } from '@components/icons'; |
| 4 | +import { useStaticQuery, graphql } from 'gatsby'; |
| 5 | +import Img from 'gatsby-image'; |
| 6 | +import { truncate } from '../utils/truncate'; |
| 7 | +const StyledCarouselSection = styled.section` |
| 8 | + margin: 0 auto; |
| 9 | + max-width: 100%; |
| 10 | + padding: 0; |
| 11 | + & ul { |
| 12 | + display: flex; |
| 13 | + flex-wrap: wrap; |
| 14 | + list-style: none; |
| 15 | + justify-content: space-between; |
| 16 | + padding: 0; |
| 17 | + & li { |
| 18 | + border-radius: var(--border-radius); |
| 19 | + border: 2px solid var(--quaternary); |
| 20 | + background-color: transparent; |
| 21 | + height: 18vh; |
| 22 | + width: 150px; |
| 23 | + margin-top: 10px; |
| 24 | + position: relative; |
| 25 | + transition: transform 450ms ease 0s; |
| 26 | + padding: 5px; |
| 27 | + margin-left: 2px; |
| 28 | + white-space: nowrap; |
| 29 | + overflow: hidden; |
| 30 | + @media (max-width: 480px) { |
| 31 | + height: 20vh; |
| 32 | + width: 110px; |
| 33 | + } |
| 34 | +
|
| 35 | + &:hover { |
| 36 | + transform: scale(1.08); |
| 37 | + opacity: 1; |
| 38 | + } |
| 39 | +
|
| 40 | + h3 { |
| 41 | + margin-top: 15px; |
| 42 | + color: var(--quinary); |
| 43 | + font-size: var(--fz-md); |
| 44 | + text-align: center; |
| 45 | +
|
| 46 | + @media (max-width: 480px) { |
| 47 | + font-size: var(--fz-xxs); |
| 48 | + } |
| 49 | + } |
| 50 | +
|
| 51 | + & div { |
| 52 | + text-align: center; |
| 53 | +
|
| 54 | + a { |
| 55 | + padding: 5px; |
| 56 | +
|
| 57 | + svg { |
| 58 | + width: 17px; |
| 59 | + height: 17px; |
| 60 | + } |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | +`; |
| 66 | +function Carousel() { |
| 67 | + const data = useStaticQuery(graphql` |
| 68 | + query { |
| 69 | + courses: allMarkdownRemark( |
| 70 | + filter: { fileAbsolutePath: { regex: "/courses/" } } |
| 71 | + sort: { fields: [frontmatter___date], order: DESC } |
| 72 | + ) { |
| 73 | + edges { |
| 74 | + node { |
| 75 | + frontmatter { |
| 76 | + title |
| 77 | + cover { |
| 78 | + childImageSharp { |
| 79 | + fluid(maxWidth: 100, quality: 100) { |
| 80 | + ...GatsbyImageSharpFluid |
| 81 | + } |
| 82 | + fixed(width: 32, height: 32) { |
| 83 | + ...GatsbyImageSharpFixed |
| 84 | + } |
| 85 | + } |
| 86 | + } |
| 87 | + github |
| 88 | + external |
| 89 | + } |
| 90 | + } |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + `); |
| 95 | + |
| 96 | + const courses = data.courses.edges.filter(({ node }) => node); |
| 97 | + |
| 98 | + return ( |
| 99 | + <> |
| 100 | + <StyledCarouselSection id="container"> |
| 101 | + <ul> |
| 102 | + {courses && |
| 103 | + courses.map(({ node }, i) => { |
| 104 | + const { frontmatter } = node; |
| 105 | + const { external, title, github, cover } = frontmatter; |
| 106 | + return ( |
| 107 | + <li key={i} title={title}> |
| 108 | + <Img |
| 109 | + fixed={cover.childImageSharp.fixed} |
| 110 | + objectFit="cover" |
| 111 | + objectPosition="50% 50%" |
| 112 | + alt={title} |
| 113 | + className="img" |
| 114 | + style={{ |
| 115 | + borderRadius: '50%', |
| 116 | + }} |
| 117 | + /> |
| 118 | + <h3>{truncate(title)}</h3>{' '} |
| 119 | + <div> |
| 120 | + {github && ( |
| 121 | + <a href={github} aria-label="GitHub Link" target="_blank" rel="noreferrer"> |
| 122 | + <Icon name="GitHub" /> |
| 123 | + </a> |
| 124 | + )}{' '} |
| 125 | + <a href={external} aria-label="External Link" target="_blank" rel="noreferrer"> |
| 126 | + <Icon name="External" /> |
| 127 | + </a> |
| 128 | + </div> |
| 129 | + </li> |
| 130 | + ); |
| 131 | + })} |
| 132 | + </ul> |
| 133 | + </StyledCarouselSection> |
| 134 | + </> |
| 135 | + ); |
| 136 | +} |
| 137 | + |
| 138 | +export default Carousel; |
0 commit comments