justin.deal/src/components/common/ServiceCard.astro

308 lines
7.3 KiB
Plaintext
Raw Normal View History

2025-04-27 20:43:15 -07:00
---
/**
* ServiceCard component displays a service with an icon and name
* @component
* @example
* ```astro
* <ServiceCard
* name="Gitea"
* href="https://code.justin.deal"
* img="https://cdn.jsdelivr.net/gh/selfhst/icons/svg/gitea.svg"
* alt="Gitea"
* />
* ```
*/
interface Props {
/**
* The name of the service to display
*/
name: string;
/**
* The URL to link to when the service card is clicked
*/
href: string;
/**
* The URL of the service icon
*/
img: string;
/**
* Alternative text for the service icon
*/
alt: string;
}
2025-04-27 20:43:15 -07:00
const { name, href, img, alt } = Astro.props;
---
<a
href={href}
2025-05-03 14:06:52 -07:00
class="service-card zag-interactive flex items-center transition-all duration-300"
2025-04-27 20:43:15 -07:00
target="_blank"
rel="noopener noreferrer"
aria-label={`Open ${name} in a new tab`}
2025-04-27 20:43:15 -07:00
>
<div class="service-icon-container flex-shrink-0 relative">
<div class="service-icon-background absolute inset-0 rounded-full opacity-0 transition-all duration-300"></div>
<img
src={img}
alt={alt}
class="service-icon w-16 h-16 transition-all duration-300 relative z-10"
loading="lazy"
decoding="async"
/>
</div>
<p class="service-name mt-2 text-center transition-all duration-300">{name}</p>
<!-- QR code for print view only -->
<div class="print-qr-code">
<div class="qr-placeholder"></div>
<span class="qr-url">{href}</span>
</div>
2025-04-27 20:43:15 -07:00
</a>
<style>
/* Default (grid) view */
.service-card {
flex-direction: column;
justify-content: center;
}
/* List view adjustments applied via JS */
:global(.view-mode-list) .service-card {
flex-direction: row;
justify-content: flex-start;
padding: 0.5rem;
border-radius: 0.375rem;
}
:global(.view-mode-list) .service-name {
margin-top: 0;
margin-left: 1rem;
text-align: left;
}
2025-05-03 13:35:55 -07:00
/* Display mode styles */
/* Default display mode (both) */
.service-icon-container, .service-name {
display: block;
}
/* Image only mode */
:global(.display-image-only) .service-name {
display: none;
}
:global(.display-image-only) .service-icon-container {
display: flex;
justify-content: center;
align-items: center;
}
/* Name only mode */
:global(.display-name-only) .service-icon-container {
display: none;
}
:global(.display-name-only) .service-name {
display: block;
margin-top: 0;
font-size: 1.1rem;
}
/* Adjust list view for different display modes */
:global(.view-mode-list.display-name-only) .service-card {
padding: 0.75rem 1rem;
}
:global(.view-mode-list.display-image-only) .service-card {
justify-content: center;
padding: 0.5rem;
}
/* Icon size adjustments with CSS variables for fine-grained control */
:global(#app-list) {
--icon-scale: 2; /* Default medium size */
--icon-base-size: 1rem;
}
.service-icon {
width: calc(var(--icon-base-size) * var(--icon-scale) * 2);
height: calc(var(--icon-base-size) * var(--icon-scale) * 2);
}
/* Fallback discrete sizes for browsers that don't support calc */
:global(.icon-size-small) .service-icon {
width: 2rem;
height: 2rem;
}
:global(.icon-size-medium) .service-icon {
width: 4rem;
height: 4rem;
}
:global(.icon-size-large) .service-icon {
width: 6rem;
height: 6rem;
}
2025-05-03 14:06:52 -07:00
/* Enhanced hover effects */
.service-card {
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
2025-05-03 14:06:52 -07:00
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border: 2px solid transparent;
background-color: var(--color-zag-bg);
border-radius: 0.5rem;
overflow: hidden;
position: relative;
will-change: transform, box-shadow, border-color;
2025-05-03 14:06:52 -07:00
}
.service-card::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(135deg, transparent 0%, var(--color-zag-accent) 300%);
opacity: 0;
transition: opacity 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
2025-05-03 14:06:52 -07:00
z-index: -1;
}
/* Enhanced micro-interactions */
.service-card:hover {
transform: translateY(-4px) scale(1.02);
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
2025-05-03 14:06:52 -07:00
border-color: var(--color-zag-accent);
background-color: var(--color-zag-bg-hover);
z-index: 10;
}
.service-card:hover::before {
opacity: 0.15;
}
.service-card:active {
transform: translateY(-2px) scale(0.98);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
transition: all 0.1s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.service-icon-container {
position: relative;
transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.service-icon-background {
background: radial-gradient(circle, var(--color-zag-accent) 0%, transparent 70%);
transform: scale(0.8);
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.service-card:hover .service-icon-container {
transform: translateY(-2px);
2025-05-03 14:06:52 -07:00
}
.service-card:hover .service-icon {
transform: scale(1.1) rotate(2deg);
filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.1));
}
.service-card:hover .service-icon-background {
opacity: 0.2;
transform: scale(1.5);
}
.service-card:hover .service-name {
transform: translateY(2px);
font-weight: 500;
}
:global(.view-mode-list) .service-card:hover {
transform: translateX(4px) scale(1.01);
}
:global(.view-mode-list) .service-card:active {
transform: translateX(2px) scale(0.99);
2025-05-03 14:06:52 -07:00
}
/* Dark mode adjustments */
:global(.dark) .service-card {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
:global(.dark) .service-card:hover {
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
}
/* Print-specific styles */
.print-qr-code {
display: none;
}
@media print {
.service-card {
break-inside: avoid;
page-break-inside: avoid;
box-shadow: none !important;
border: 1px solid #ddd !important;
transform: none !important;
background: white !important;
color: black !important;
display: flex;
flex-direction: row !important;
align-items: center;
padding: 1rem;
margin-bottom: 0.5rem;
}
.service-icon {
width: 2rem !important;
height: 2rem !important;
margin-right: 1rem;
}
.service-name {
margin: 0 !important;
font-weight: bold !important;
font-size: 1rem !important;
flex: 1;
text-align: left !important;
}
.print-qr-code {
display: flex;
flex-direction: column;
align-items: center;
margin-left: auto;
width: 4rem;
}
.qr-placeholder {
width: 4rem;
height: 4rem;
border: 1px solid #ddd;
margin-bottom: 0.25rem;
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='1' d='M4 4h4v4H4zM16 4h4v4h-4zM4 16h4v4H4zM12 12h4v4h-4zM8 8h8v8H8z'/%3E%3C/svg%3E");
background-repeat: no-repeat;
background-position: center;
background-size: contain;
}
.qr-url {
font-size: 0.6rem;
word-break: break-all;
text-align: center;
max-width: 4rem;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
</style>