Skip to content

Commit

Permalink
Merge pull request #56 from brklntmhwk/55-create-card-component
Browse files Browse the repository at this point in the history
feat(ui): 🆕 create a card component and the remark plugin
  • Loading branch information
brklntmhwk authored Sep 10, 2024
2 parents 4f418e2 + c54f5d5 commit 0c2ca11
Show file tree
Hide file tree
Showing 60 changed files with 602 additions and 92 deletions.
2 changes: 1 addition & 1 deletion .frontmatter/database/mediaDb.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"assets":{"images":{}},"src":{"assets":{"images":{}}}}
{"assets":{"images":{}},"src":{"assets":{"images":{}},"components":{"card":{}},"content":{"page":{"en":{}}}}}
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"files.associations": {
"*.mdx": "markdown"
},
"frontMatter.content.autoUpdateDate": true
"frontMatter.content.autoUpdateDate": true,
}
2 changes: 2 additions & 0 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
oEmbedTransformer,
youTubeTransformer,
} from './src/plugins/transformers';
import remarkCard from './src/plugins/remark-card';

// https://astro.build/config
export default defineConfig({
Expand Down Expand Up @@ -111,6 +112,7 @@ export default defineConfig({
remarkGfm,
remarkAstroImageAssets,
remarkCallout,
remarkCard,
remarkFootnote,
remarkLineBreaks,
[
Expand Down
Binary file added src/assets/images/anki-icon.webp
Binary file not shown.
Binary file added src/assets/images/asrock-b650e-pg-itx-wifi.webp
Binary file not shown.
Binary file added src/assets/images/audio-technica-ath-r70x.webp
Binary file not shown.
Binary file added src/assets/images/cloudflare-logo.webp
Binary file not shown.
Binary file added src/assets/images/corsair-sf750.avif
Binary file not shown.
Binary file added src/assets/images/crucial-ddr5-pro_.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/davinci-resolve-icon.webp
Binary file not shown.
Binary file added src/assets/images/docker-logo-blue.webp
Binary file not shown.
Binary file added src/assets/images/dr-10l_pro.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/drafts-icon.webp
Binary file not shown.
Binary file not shown.
Binary file added src/assets/images/goodnotes-icon.webp
Binary file not shown.
Binary file added src/assets/images/ipad-pro-13inch-spaceblack.webp
Binary file not shown.
Binary file added src/assets/images/iphone-15-black.webp
Binary file not shown.
Binary file added src/assets/images/kindle-icon.webp
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/lian-li-a4-h2o.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/mac-studio-m2.webp
Binary file not shown.
Binary file added src/assets/images/motu-digital-performer-11.webp
Binary file not shown.
Binary file added src/assets/images/neovim-icon.webp
Binary file not shown.
Binary file added src/assets/images/ni-maschine-mk3.webp
Binary file not shown.
Binary file added src/assets/images/nixos-icon.webp
Binary file not shown.
Binary file added src/assets/images/nzxt-kraken-240-black.avif
Binary file not shown.
Binary file added src/assets/images/obsidian-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/portacapture-x8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/rme-babyface-pro-fs.webp
Binary file not shown.
Binary file added src/assets/images/ryzen-5-7600x.avif
Binary file not shown.
Binary file not shown.
Binary file added src/assets/images/sony-ilce-6700.webp
Binary file not shown.
Binary file added src/assets/images/spotify-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/totalmix-fx.webp
Binary file not shown.
Binary file added src/assets/images/vscode-icon.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/working-copy-icon.avif
Binary file not shown.
8 changes: 4 additions & 4 deletions src/components/BlogList/BlogList.astro
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const { entries, taxonomies } = Astro.props;

return (
<li class="entry-item fade-in-up">
<article class="pokemon-border">
<article class="double-border">
<a
class="blog-title"
href={translatePath(
Expand Down Expand Up @@ -93,14 +93,14 @@ const { entries, taxonomies } = Astro.props;
display: flex;
flex-direction: column;
gap: 0.825rem;
&:hover {
background-color: var(--bg-hover);
}
.blog-title {
color: var(--fg);
font-size: 1.485rem;
font-weight: 700;
line-height: 1.325;
&:hover {
background-color: var(--bg-hover);
}
@media (min-width: 640px) {
font-size: 1.585rem;
}
Expand Down
67 changes: 67 additions & 0 deletions src/components/Card/Card.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
import {
type CardBorderType,
type ComponentCardProps,
type ElementCardProps,
isElementCard,
isValidBorderType,
} from './card';
type Props = ComponentCardProps | ElementCardProps;
let cardBorderType: CardBorderType = 'solid';
let isAnimated = false;
if (isElementCard(Astro.props)) {
const { 'data-border-type': dataBorderType } = Astro.props;
if (isValidBorderType(dataBorderType)) {
cardBorderType = dataBorderType;
}
} else {
const { borderType, isAnimated: animation } = Astro.props;
cardBorderType = borderType;
isAnimated = animation;
}
---

<div class:list={["card", `${cardBorderType}-border`, { "fade-in-up": isAnimated }]}>
<slot name="image" />
<slot name="content" />
</div>
<style>
.card {
background-color: var(--bg);
max-width: 100%;
height: 15rem;
display: flex;
flex-direction: column;
gap: 0.525rem;
break-inside: avoid;
&:hover {
background-color: var(--bg-hover);
}
& :global(.card-image) {
max-height: 8.75rem;
min-height: 6.75rem;
padding: 0.25rem;
display: flex;
justify-content: center;
& :global(img) {
object-fit: contain;
width: 100%;
height: 100%;
}
}
& :global(.card-content) {
font-size: 0.925rem;
padding: 0.175rem 0.325rem;
overflow-y: auto;
}
@media (min-width: 320px) {
max-width: 18rem;
}
@media (min-width: 1280px) {
max-width: 20rem;
}
}
</style>
25 changes: 25 additions & 0 deletions src/components/Card/CardGrid.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
---

<div class="card-grid">
<slot />
</div>
<style>
.card-grid {
display: grid;
align-items: flex-start;
grid-template-columns: repeat(auto-fit, minmax(7.875rem, 1fr));
grid-auto-flow: row dense;
gap: 1.5rem;
@media (min-width: 640px) {
grid-template-columns: repeat(auto-fit, minmax(9.675rem, 1fr));
}
@media (min-width: 768px) {
grid-template-columns: repeat(3, 1fr);
}
@media (min-width: 1280px) {
grid-template-columns: repeat(4, 1fr);
}
}
</style>
18 changes: 18 additions & 0 deletions src/components/Card/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const cardBorderTypes = ['pixel', 'double', 'solid'] as const;

export type CardBorderType = (typeof cardBorderTypes)[number];

export type ElementCardProps = {
'data-border-type': string;
};

export type ComponentCardProps = {
borderType: CardBorderType;
isAnimated: boolean;
};

export const isElementCard = (props: object): props is ElementCardProps =>
Object.hasOwn(props, 'data-border-type');

export const isValidBorderType = (type: string): type is CardBorderType =>
cardBorderTypes.some((borderType) => borderType === type);
2 changes: 2 additions & 0 deletions src/components/Card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Card } from './Card.astro';
export { default as CardGrid } from './CardGrid.astro';
2 changes: 1 addition & 1 deletion src/components/ContactForm/SubmitButton/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type Props = {

export const SubmitButton: Component<Props> = (props) => {
return (
<Button type="submit" class={`pokemon-border ${submitButton}`}>
<Button type="submit" class={`double-border ${submitButton}`}>
{props.label}
</Button>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/ContactForm/TextField/TextField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const TextField: Component<Props> = (props) => {
<Show
when={props.type === 'hidden'}
fallback={
<div class="pokemon-border">
<div class="double-border">
<Kobalte.Input
{...inputProps}
type={props.type}
Expand All @@ -65,7 +65,7 @@ export const TextField: Component<Props> = (props) => {
</Show>
}
>
<div class="pokemon-border">
<div class="double-border">
<Kobalte.TextArea {...inputProps} class={textField} />
</div>
</Show>
Expand Down
3 changes: 3 additions & 0 deletions src/components/Navigation/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ const t = await getEntry('i18n', `${locale}/translation`);
<NavLink href={translatePath('/about')}
>{t.data.nav.nav_links.about}</NavLink
>
<NavLink href={translatePath('/tools')}
>{t.data.nav.nav_links.tools}</NavLink
>
</div>
<div class="icon-links" slot="outside-drawer">
<Modal
Expand Down
24 changes: 3 additions & 21 deletions src/components/PhotoGallery/PhotoGallery.astro
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
import { getEntry } from 'astro:content';
import { CardGrid } from '@/components/Card';
import { ACCOUNT_ID, UNSPLASH_BASE_URL } from '@/lib/consts';
import { getPhotographer } from '@/lib/unsplash/contents';
import type { UnsplashPhotoData } from '@/lib/unsplash/types';
Expand All @@ -17,14 +18,14 @@ const username = await getPhotographer();
---

<div class="photo-gallery-wrapper">
<section class="photo-gallery">
<CardGrid>
{
photos &&
photos.results.map((photo, i) => (
<PhotoGalleryItem {photo} order={i + 1} />
))
}
</section>
</CardGrid>
<aside>
<p>
{t.data.photo_gallery.credit_label}
Expand Down Expand Up @@ -58,24 +59,5 @@ const username = await getPhotographer();
}
}
}
.photo-gallery {
display: grid;
align-items: flex-start;
grid-template-columns: repeat(auto-fit, minmax(7.875rem, 1fr));
grid-auto-flow: row dense;
gap: 1.5rem;
@media (min-width: 640px) {
grid-template-columns: repeat(auto-fit, minmax(9.675rem, 1fr));
}
@media (min-width: 768px) {
grid-template-columns: repeat(3, 1fr);
}
@media (min-width: 1024px) {
grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 1280px) {
grid-template-columns: repeat(3, 1fr);
}
}
}
</style>
80 changes: 35 additions & 45 deletions src/components/PhotoGallery/PhotoGalleryItem.astro
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
import { Image } from 'astro:assets';
import { getEntry } from 'astro:content';
import { Card } from '@/components/Card';
import { ProfileIcon } from '@/components/ProfileIcon';
import type { UnsplashPhoto } from '@/lib/unsplash/types';
import { getTimeDiff } from '@/utils/get-time-diff';
Expand Down Expand Up @@ -30,75 +31,64 @@ const createdAt = new Date(created_at);
const dateDiff = getTimeDiff(createdAt, locale);
---

<div class="photo-gallery-item pixel-border fade-in-up">
<Card borderType="pixel" isAnimated>
<a
aria-label={`${t.data.photo_gallery_item.photo_label}${order}`}
href={`${links.html}?utm_source=${toSnakeCase(meta.data.site.title)}&utm_medium=referral`}
slot="image"
>
<figure class="photo">
<Image
src={`${urls.raw}&auto=format&w=640&q=70`}
alt={alt_description || description || ''}
width={width}
height={height}
format="avif"
loading="lazy"
/>
<figcaption>{alt_description || description}</figcaption>
</figure>
<Image
class="photo"
src={`${urls.raw}&auto=format&w=640&q=70`}
alt={alt_description || description || ''}
width={width}
height={height}
format="avif"
loading="lazy"
/>
</a>
<section class="photo-metadata">
<section slot="content" class="photo-metadata">
<div class="photographer">
<ProfileIcon
alt={photo.user.username}
src={photo.user.profile_image.small}
size={20}
/>
<span>{user.username}</span>
<span>{user.last_name}</span>
</div>
<span class="photo-date">
{dateDiff}
</span>
</section>
</div>
</Card>
<style>
.photo-gallery-item {
.photo {
width: 100%;
max-height: 10.875rem;
object-fit: cover;
}
.photo-metadata {
font-size: 0.685rem;
display: flex;
flex-direction: column;
gap: 0.375rem;
break-inside: avoid;
.photo {
margin: 0 auto;
figcaption {
display: none;
}
}
.photo-metadata {
font-size: 0.685rem;
align-items: center;
flex-wrap: wrap;
justify-content: space-between;
gap: 0.5rem;
padding: 0.175rem 0.225rem 0.225rem 0.225rem;
.photographer {
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: space-between;
gap: 0.5rem;
padding: 0.175rem 0.225rem 0.225rem 0.225rem;
.photographer {
display: flex;
align-items: center;
gap: 0.375rem;
@media (min-width: 768px) {
gap: 0.5rem;
}
}
.photo-date {
margin-left: 0.5rem;
}
gap: 0.375rem;
@media (min-width: 768px) {
font-size: 0.85rem;
padding: 0.375rem 0.5rem 0.5rem 0.5rem;
gap: 0.5rem;
}
}
.photo-date {
margin-left: 0.5rem;
}
@media (min-width: 768px) {
margin-bottom: 1.5rem;
font-size: 0.85rem;
padding: 0.375rem 0.5rem 0.5rem 0.5rem;
}
}
</style>
2 changes: 1 addition & 1 deletion src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const Search: Component<Props> = (props) => {
return (
<div class={searchWrapper}>
<form onsubmit={handleSubmit}>
<div class={`${searchInputWrapper} pokemon-border`}>
<div class={`${searchInputWrapper} double-border`}>
<SearchIcon label={props.t.button_label} width={22} height={22} />
<input
id="search-window"
Expand Down
1 change: 0 additions & 1 deletion src/components/elements/Figure/Image.astro
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const {
margin: 0 auto;
max-height: 100%;
aspect-ratio: var(--aspectRatio);

& :global(img) {
object-fit: contain;
color: transparent;
Expand Down
Loading

0 comments on commit 0c2ca11

Please sign in to comment.