-
Notifications
You must be signed in to change notification settings - Fork 2
Add image thumbnails to idea list #103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
3489322
501488e
c91eed3
b9050f5
7ed3b01
8e0361f
cd7d620
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import React from "react"; | ||
|
|
||
| import { GatsbyImage, IGatsbyImageData, getImage } from "gatsby-plugin-image"; | ||
|
|
||
| const { imgFill, scale } = require("../style/figure-thumbnail.module.css"); | ||
|
|
||
| interface FigureThumbnailProps { | ||
| figure: { | ||
| url?: string | null; | ||
| file?: { | ||
| childImageSharp?: { | ||
| gatsbyImageData: IGatsbyImageData; | ||
| } | null; | ||
| } | null; | ||
| }; | ||
| className?: string; | ||
| } | ||
|
|
||
| const FigureThumbnail: React.FC<FigureThumbnailProps> = ({ | ||
| className, | ||
| figure, | ||
| }) => { | ||
| const gatsbyImage = figure.file?.childImageSharp | ||
| ? getImage(figure.file.childImageSharp) | ||
| : null; | ||
|
|
||
| if (gatsbyImage) { | ||
| return ( | ||
| <GatsbyImage | ||
| image={gatsbyImage} | ||
| alt="" | ||
| className={className} | ||
| imgClassName={scale} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| if (figure.url) { | ||
| return ( | ||
| <div className={className}> | ||
| <img src={figure.url} alt="" className={imgFill} /> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| return null; | ||
| }; | ||
|
|
||
| export default FigureThumbnail; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import React from "react"; | |
|
|
||
| import { Link, graphql, useStaticQuery } from "gatsby"; | ||
|
|
||
| import FigureThumbnail from "./FigureThumbnail"; | ||
| import { TagPopover } from "./TagPopover"; | ||
|
|
||
| const { | ||
|
|
@@ -11,6 +12,8 @@ const { | |
| listItem, | ||
| tagEyebrow, | ||
| tagSeparator, | ||
| textBlock, | ||
| thumbnail, | ||
| title, | ||
| } = require("../style/idea-roll.module.css"); | ||
|
|
||
|
|
@@ -40,6 +43,22 @@ const IdeaRoll = ({ count }: IdeaRollProps) => { | |
| type | ||
| name | ||
| } | ||
| preliminaryFindings { | ||
|
toloudis marked this conversation as resolved.
|
||
| figures { | ||
| type | ||
| url | ||
| file { | ||
| childImageSharp { | ||
| gatsbyImageData( | ||
| width: 88 | ||
| height: 56 | ||
| layout: FIXED | ||
| quality: 80 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. magic numbers? they seem to be repeated in the css also, so I wonder if they can be factored out into one place somehow. |
||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -55,40 +74,63 @@ const IdeaRoll = ({ count }: IdeaRollProps) => { | |
| return ( | ||
| <> | ||
| <ul className={container}> | ||
| {ideas.map((item) => ( | ||
| <li key={item.id} className={listItem}> | ||
| {item.tags.length > 0 && ( | ||
| <div className={tagEyebrow}> | ||
| {item.tags.map((tag, i) => ( | ||
| <React.Fragment key={tag}> | ||
| {i > 0 && ( | ||
| <span | ||
| className={tagSeparator} | ||
| aria-hidden="true" | ||
| > | ||
| · | ||
| </span> | ||
| )} | ||
| <TagPopover | ||
| tag={tag} | ||
| currentSlug={item.slug} | ||
| className={eyebrowTag} | ||
| /> | ||
| </React.Fragment> | ||
| ))} | ||
| {ideas.map((item) => { | ||
| const firstFigure = | ||
| item.preliminaryFindings?.figures?.[0] ?? null; | ||
|
|
||
| return ( | ||
| <li key={item.id} className={listItem}> | ||
| <div className={textBlock}> | ||
| {item.tags.length > 0 && ( | ||
| <div className={tagEyebrow}> | ||
| {item.tags.map((tag, i) => ( | ||
| <React.Fragment key={tag}> | ||
| {i > 0 && ( | ||
| <span | ||
| className={tagSeparator} | ||
| aria-hidden="true" | ||
| > | ||
| · | ||
| </span> | ||
| )} | ||
| <TagPopover | ||
| tag={tag} | ||
| currentSlug={item.slug} | ||
| className={eyebrowTag} | ||
| /> | ||
| </React.Fragment> | ||
| ))} | ||
| </div> | ||
| )} | ||
| <Link to={item.slug} className={title}> | ||
| {item.title} | ||
| </Link> | ||
| <div className={byline}> | ||
| by{" "} | ||
| {item.authors | ||
| .map((a) => a.name) | ||
| .join(" · ")} | ||
| {item.dataset | ||
| ? ` — ${item.dataset}` | ||
| : " — No public dataset"} | ||
| </div> | ||
| </div> | ||
| )} | ||
| <Link to={item.slug} className={title}> | ||
| {item.title} | ||
| </Link> | ||
| <div className={byline}> | ||
| by {item.authors.map((a) => a.name).join(" · ")} | ||
| {item.dataset | ||
| ? ` — ${item.dataset}` | ||
| : " — No public dataset"} | ||
| </div> | ||
| </li> | ||
| ))} | ||
|
|
||
| {firstFigure && ( | ||
| <Link | ||
| to={item.slug} | ||
| tabIndex={-1} | ||
| aria-hidden="true" | ||
| > | ||
|
meganrm marked this conversation as resolved.
|
||
| <FigureThumbnail | ||
| figure={firstFigure} | ||
| className={thumbnail} | ||
| /> | ||
| </Link> | ||
| )} | ||
| </li> | ||
| ); | ||
| })} | ||
| </ul> | ||
| {count !== undefined && ( | ||
| <div> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| .scale { | ||
| transform: scale(1.2); | ||
| transform-origin: center; | ||
| } | ||
|
|
||
| .imgFill { | ||
| width: 100%; | ||
| height: 100%; | ||
| object-fit: cover; | ||
| object-position: center; | ||
| display: block; | ||
| transform: scale(1.2); | ||
| transform-origin: center; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,20 @@ | |
| .listItem { | ||
| padding: 22px 0; | ||
| border-bottom: 1px solid var(--border-color); | ||
| display: flex; | ||
| align-items: flex-start; | ||
| gap: 14px; | ||
| } | ||
|
|
||
| .listItem:last-child { | ||
| border-bottom: none; | ||
| } | ||
|
|
||
| .textBlock { | ||
| flex: 1; | ||
| min-width: 0; | ||
| } | ||
|
|
||
| .tagEyebrow { | ||
| display: flex; | ||
| align-items: center; | ||
|
|
@@ -64,3 +72,17 @@ | |
| font-weight: 400; | ||
| color: var(--text-secondary-color); | ||
| } | ||
|
|
||
| .thumbnail { | ||
| width: 88px; | ||
| height: 56px; | ||
| border-radius: 28px; | ||
| overflow: hidden; | ||
| flex-shrink: 0; | ||
| display: block; | ||
| box-sizing: border-box; | ||
| box-shadow: | ||
| 0 0 0 1.5px rgba(255, 110, 0, 0.4), | ||
| 0 0 10px 2px rgba(255, 110, 0, 0.2), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these color constants be declared somewhere else as variables? |
||
| 0 2px 8px rgba(0, 0, 0, 0.15); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, Is there a non-sharp child image? (like a blurred thumbnail or something?)