web/src/components/things/SectionList.astro

137 lines · 2667 bytes

  1---
  2import FontAwesome from '@components/form/FontAwesome.svelte';
  3import { slugify } from '../../utils/fetch-data';
  4
  5import type { Section } from '../../types/Service';
  6
  7interface Props {
  8	title: string;
  9	sections: Section[];
 10	bigTitle?: boolean;
 11	headingLevel?: 2 | 3;
 12}
 13
 14const { title, sections, bigTitle, headingLevel = 3 } = Astro.props;
 15const Heading = `h${headingLevel}` as 'h2' | 'h3';
 16---
 17
 18<div class="wrap">
 19	{
 20		bigTitle ? (
 21			<h1>
 22				<FontAwesome iconName={slugify(title)} />
 23				{title}{' '}
 24			</h1>
 25		) : (
 26			<a class="category-title" href={`/${slugify(title)}/`}>
 27				<Heading>{title}</Heading>
 28			</a>
 29		)
 30	}
 31
 32	{
 33		!bigTitle && (
 34			<span class="section-icon">
 35				<FontAwesome iconName={slugify(title)} />
 36			</span>
 37		)
 38	}
 39
 40	<ul>
 41		{
 42			sections.map((section) => (
 43				<li class="section">
 44					<a href={`/${slugify(title)}/${slugify(section.name)}/`}>
 45						<span>{section.name}</span>
 46						<span class="service-count">
 47							({section.services ? section.services.length : 0})
 48						</span>
 49					</a>
 50				</li>
 51			))
 52		}
 53	</ul>
 54</div>
 55
 56<style lang="scss">
 57	@use '../../styles/mixins' as *;
 58	.wrap {
 59		position: relative;
 60		&:hover {
 61			.section-icon :global(svg) {
 62				opacity: 1;
 63				transform: scale(1.2);
 64			}
 65		}
 66	}
 67
 68	h1 {
 69		font-family: var(--font-subtitle);
 70		font-size: var(--text-3xl);
 71		margin: -2rem 0 var(--space-lg) -2rem;
 72		box-shadow: var(--shadow-lg);
 73		border: var(--border-heavy);
 74		background: var(--accent);
 75		color: var(--accent-fg);
 76		width: fit-content;
 77		padding: var(--space-xs) var(--space-sm);
 78		display: flex;
 79		justify-content: center;
 80		gap: var(--space-md);
 81		:global(svg) {
 82			width: 2rem;
 83			height: 2rem;
 84			color: var(--accent-fg);
 85		}
 86	}
 87
 88	.category-title {
 89		text-decoration: none;
 90		color: var(--foreground);
 91		z-index: 2;
 92		position: relative;
 93		h2,
 94		h3 {
 95			font-family: var(--font-subtitle);
 96			font-weight: bold;
 97			margin: 0;
 98			font-size: var(--text-2xl);
 99			@include underline-hover(var(--accent), 3px, 80%);
100		}
101	}
102
103	ul {
104		list-style: circle;
105		padding-left: var(--space-md);
106		li {
107			margin: var(--space-sm) 0;
108			font-size: var(--text-md);
109			a {
110				display: inline-flex;
111				align-items: center;
112				gap: var(--space-xs);
113				min-height: 24px;
114				text-decoration: none;
115				color: var(--foreground);
116				@include underline-hover(var(--accent-3), 2px, 80%, 0.15s);
117			}
118			.service-count {
119				color: var(--accent-3-text);
120			}
121		}
122	}
123
124	.section-icon {
125		position: absolute;
126		right: 0;
127		top: 0;
128		width: fit-content;
129		:global(svg) {
130			width: 2rem;
131			height: 2rem;
132			opacity: var(--opacity-dim);
133			color: var(--accent-3-text);
134			transition: var(--transition-normal);
135		}
136	}
137</style>