-
Notifications
You must be signed in to change notification settings - Fork 1.3k
(feat) Img component #39214
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: jen.gilbert/astro-base
Are you sure you want to change the base?
(feat) Img component #39214
Changes from all commits
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,60 @@ | ||
| --- | ||
| import ImgController from "./ImgController"; | ||
| import ImgVideo from "./ImgVideo"; | ||
| import { IMAGES_URL } from "@config/images"; | ||
|
|
||
| interface Props { | ||
| src: string; | ||
| alt?: string; | ||
| caption?: string; | ||
| width?: string; | ||
| height?: string; | ||
| widthPercent?: number; | ||
| video?: boolean; | ||
| inline?: boolean; | ||
| popup?: boolean; | ||
| } | ||
|
|
||
| const { | ||
| src, | ||
| alt, | ||
| caption, | ||
| width, | ||
| height, | ||
| widthPercent, | ||
| video = false, | ||
| inline = false, | ||
| popup = true, | ||
| } = Astro.props; | ||
|
|
||
| const imageUrl = `${IMAGES_URL}/images/${src}`; | ||
|
|
||
| const srcset = `${imageUrl}?auto=format&fit=max&w=850 1x, ${imageUrl}?auto=format&fit=max&w=850&dpr=2 2x`; | ||
| const popupHref = `${imageUrl}?fit=max&auto=format`; | ||
| --- | ||
|
|
||
| { | ||
| video ? ( | ||
| <ImgVideo | ||
| client:idle | ||
| imageUrl={imageUrl} | ||
| width={width} | ||
| height={height} | ||
| widthPercent={widthPercent} | ||
| /> | ||
| ) : ( | ||
| <ImgController | ||
| client:idle | ||
| imageUrl={imageUrl} | ||
| srcset={srcset} | ||
| popupHref={popupHref} | ||
| alt={alt} | ||
| caption={caption} | ||
| width={width} | ||
| height={height} | ||
| widthPercent={widthPercent} | ||
| inline={inline} | ||
| popup={popup} | ||
| /> | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| .img__figure { | ||
| margin: 0 0 1rem; | ||
| } | ||
|
|
||
| .img__image { | ||
| max-width: 100%; | ||
| height: auto; | ||
| /* matches Hugo's $ddgray (#d6d6d6); no equivalent design token exists yet */ | ||
| border: 1px solid #d6d6d6; | ||
|
Collaborator
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. You would still use a |
||
| } | ||
|
|
||
| .img__link--popup { | ||
| cursor: zoom-in; | ||
| } | ||
|
|
||
| /* Ported from hugo/layouts/partials/global-modals/global-modals.html + | ||
| hugo/assets/scripts/components/global-modals.js (Bootstrap 5 Modal). */ | ||
|
|
||
| .img-lightbox__overlay { | ||
| position: fixed; | ||
| inset: 0; | ||
| background: var(--hugo-modal-overlay); | ||
| z-index: 1100; | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .img-lightbox__overlay[hidden] { | ||
| display: none; | ||
| } | ||
|
|
||
| .img-lightbox__dialog { | ||
| position: relative; | ||
| display: flex; | ||
| flex-direction: column; | ||
| align-items: center; | ||
| justify-content: center; | ||
| max-width: 90vw; | ||
| max-height: 90vh; | ||
| } | ||
|
|
||
| .img-lightbox__spinner, | ||
| .img-lightbox__spinner::after { | ||
| border-radius: 50%; | ||
| width: 5em; | ||
| height: 5em; | ||
| } | ||
|
|
||
| .img-lightbox__spinner { | ||
| font-size: 10px; | ||
| position: relative; | ||
| text-indent: -9999em; | ||
| border-top: 0.55em solid rgba(234, 234, 234, 0.5); | ||
|
Collaborator
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. I won't keep commenting on it, but we're generally trying to avoid hard-coded colors in the CSS, even if it means we have to create a new token to avoid it (but often a reasonable alternative already exists in the tokens). This element is not required to match Hugo exactly, so don't worry about that |
||
| border-right: 0.55em solid rgba(234, 234, 234, 0.5); | ||
| border-bottom: 0.55em solid rgba(234, 234, 234, 0.5); | ||
| border-left: 0.55em solid #ffffff; | ||
| transform: translateZ(0); | ||
| animation: img-lightbox-spin 1.1s infinite linear; | ||
| } | ||
|
|
||
| @keyframes img-lightbox-spin { | ||
| 0% { | ||
| transform: rotate(0deg); | ||
| } | ||
| 100% { | ||
| transform: rotate(360deg); | ||
| } | ||
| } | ||
|
|
||
| .img-lightbox__image { | ||
| max-width: 90vw; | ||
| max-height: 90vh; | ||
| object-fit: contain; | ||
| } | ||
|
|
||
| .img-lightbox__caption { | ||
| color: #ffffff; | ||
|
Collaborator
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 probably use a token to support dark mode later |
||
| text-align: center; | ||
| margin: 0.5rem 0 0; | ||
| } | ||
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.
I've seen a few flavors of these props, they can probably be rolled into one shared type?