@sinnstack/ui 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (280) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +373 -0
  3. package/README.md +186 -2
  4. package/docs/blocks.md +364 -0
  5. package/docs/data.md +128 -0
  6. package/docs/motion.md +166 -0
  7. package/docs/primitives.md +510 -0
  8. package/docs/seo.md +187 -0
  9. package/docs/tokens.md +122 -0
  10. package/package.json +141 -3
  11. package/scripts/check-contrast.mjs +180 -0
  12. package/src/blocks/BlockRenderer.astro +54 -0
  13. package/src/blocks/CTABanner.astro +121 -0
  14. package/src/blocks/CTAPair.astro +110 -0
  15. package/src/blocks/CardGrid.astro +167 -0
  16. package/src/blocks/ConsentEmbed.astro +125 -0
  17. package/src/blocks/ConsentManager.astro +147 -0
  18. package/src/blocks/ConsentScript.astro +47 -0
  19. package/src/blocks/ContactCard.astro +164 -0
  20. package/src/blocks/ContactForm.astro +224 -0
  21. package/src/blocks/ErrorPage.astro +242 -0
  22. package/src/blocks/FAQ.astro +135 -0
  23. package/src/blocks/FeatureGrid.astro +148 -0
  24. package/src/blocks/Hero.astro +171 -0
  25. package/src/blocks/HeroCarousel.astro +220 -0
  26. package/src/blocks/HighlightCards.astro +107 -0
  27. package/src/blocks/LocationHours.astro +311 -0
  28. package/src/blocks/LogoCloud.astro +135 -0
  29. package/src/blocks/MaintenancePage.astro +168 -0
  30. package/src/blocks/MediaText.astro +177 -0
  31. package/src/blocks/PageHeader.astro +126 -0
  32. package/src/blocks/ProseSection.astro +98 -0
  33. package/src/blocks/Reviews.astro +194 -0
  34. package/src/blocks/RichText.astro +57 -0
  35. package/src/blocks/StatsBand.astro +117 -0
  36. package/src/blocks/Steps.astro +141 -0
  37. package/src/blocks/Testimonials.astro +144 -0
  38. package/src/blocks/Topbar.astro +158 -0
  39. package/src/blocks/cms/card-grid.ts +80 -0
  40. package/src/blocks/cms/consent.ts +45 -0
  41. package/src/blocks/cms/contact-card.ts +88 -0
  42. package/src/blocks/cms/contact-form.ts +55 -0
  43. package/src/blocks/cms/cta-banner.ts +48 -0
  44. package/src/blocks/cms/cta-pair.ts +63 -0
  45. package/src/blocks/cms/data-base.ts +7 -0
  46. package/src/blocks/cms/data.ts +257 -0
  47. package/src/blocks/cms/faq.ts +70 -0
  48. package/src/blocks/cms/feature-grid.ts +80 -0
  49. package/src/blocks/cms/fixtures.ts +599 -0
  50. package/src/blocks/cms/hero-carousel.ts +80 -0
  51. package/src/blocks/cms/hero.ts +77 -0
  52. package/src/blocks/cms/highlight-cards.ts +76 -0
  53. package/src/blocks/cms/images.ts +38 -0
  54. package/src/blocks/cms/index.ts +87 -0
  55. package/src/blocks/cms/location-hours.ts +149 -0
  56. package/src/blocks/cms/logo-cloud.ts +62 -0
  57. package/src/blocks/cms/media-text.ts +44 -0
  58. package/src/blocks/cms/page-header.ts +49 -0
  59. package/src/blocks/cms/pages.ts +81 -0
  60. package/src/blocks/cms/prose-section.ts +45 -0
  61. package/src/blocks/cms/reviews.ts +101 -0
  62. package/src/blocks/cms/shared.ts +115 -0
  63. package/src/blocks/cms/stats-band.ts +61 -0
  64. package/src/blocks/cms/steps.ts +67 -0
  65. package/src/blocks/cms/testimonials.ts +80 -0
  66. package/src/blocks/cms/topbar.ts +64 -0
  67. package/src/blocks/cms/types.ts +63 -0
  68. package/src/blocks/consent.ts +14 -0
  69. package/src/blocks/icons.ts +47 -0
  70. package/src/blocks/index.ts +42 -0
  71. package/src/blocks/internal/Actions.astro +29 -0
  72. package/src/blocks/internal/BlockHeader.astro +45 -0
  73. package/src/blocks/internal/BlockShell.astro +58 -0
  74. package/src/blocks/internal/CarouselScript.astro +7 -0
  75. package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
  76. package/src/blocks/internal/ConsentManagerScript.astro +7 -0
  77. package/src/blocks/internal/HoursScript.astro +7 -0
  78. package/src/blocks/internal/Placeholder.astro +13 -0
  79. package/src/blocks/internal/RichTextNode.astro +133 -0
  80. package/src/blocks/internal/StandaloneDocument.astro +53 -0
  81. package/src/blocks/internal/tina.ts +19 -0
  82. package/src/blocks/internal/util.ts +23 -0
  83. package/src/blocks/lib/consent.ts +96 -0
  84. package/src/blocks/lib/contact.ts +86 -0
  85. package/src/blocks/lib/error-pages.ts +119 -0
  86. package/src/blocks/lib/faq.ts +37 -0
  87. package/src/blocks/lib/hours.ts +201 -0
  88. package/src/blocks/lib/maintenance.ts +129 -0
  89. package/src/blocks/lib/reviews.ts +22 -0
  90. package/src/blocks/lib/rich-text.ts +143 -0
  91. package/src/blocks/lib/slug.ts +12 -0
  92. package/src/blocks/registry.ts +79 -0
  93. package/src/blocks/scripts/carousel.ts +218 -0
  94. package/src/blocks/scripts/consent-embed.ts +105 -0
  95. package/src/blocks/scripts/consent-manager.ts +112 -0
  96. package/src/blocks/scripts/consent-store.ts +86 -0
  97. package/src/blocks/scripts/error-page.ts +71 -0
  98. package/src/blocks/scripts/hours.ts +106 -0
  99. package/src/blocks/scripts/maintenance.ts +109 -0
  100. package/src/blocks/styles/blocks.css +1320 -0
  101. package/src/blocks/styles/consent.css +102 -0
  102. package/src/blocks/styles/faq.css +28 -0
  103. package/src/blocks/styles/location.css +92 -0
  104. package/src/blocks/styles/prose-section.css +13 -0
  105. package/src/blocks/styles/quotes.css +123 -0
  106. package/src/blocks/styles/rich-text.css +14 -0
  107. package/src/blocks/types.ts +283 -0
  108. package/src/data/ChartAxis.astro +19 -0
  109. package/src/data/ChartContainer.astro +151 -0
  110. package/src/data/ChartLegend.astro +25 -0
  111. package/src/data/ChartSeries.astro +14 -0
  112. package/src/data/ChartTable.astro +17 -0
  113. package/src/data/ChartTooltip.astro +20 -0
  114. package/src/data/Sparkline.astro +55 -0
  115. package/src/data/cms.ts +190 -0
  116. package/src/data/index.ts +10 -0
  117. package/src/data/lib/chart.ts +450 -0
  118. package/src/data/lib/render.ts +219 -0
  119. package/src/data/lib/scale.ts +107 -0
  120. package/src/data/lib/sparkline.ts +117 -0
  121. package/src/data/scripts/chart.ts +324 -0
  122. package/src/data/styles/chart.css +392 -0
  123. package/src/motion/Marquee.astro +90 -0
  124. package/src/motion/MotionProvider.astro +50 -0
  125. package/src/motion/PageTransitions.astro +61 -0
  126. package/src/motion/Parallax.astro +44 -0
  127. package/src/motion/ParallaxLayer.astro +31 -0
  128. package/src/motion/RevealOnScroll.astro +59 -0
  129. package/src/motion/SceneRegistry.astro +38 -0
  130. package/src/motion/ScrollScene.astro +81 -0
  131. package/src/motion/index.ts +12 -0
  132. package/src/motion/integration.ts +48 -0
  133. package/src/motion/runtime/page-transitions.ts +68 -0
  134. package/src/motion/runtime/runtime.ts +180 -0
  135. package/src/motion/runtime/scenes.ts +248 -0
  136. package/src/motion/runtime/types.ts +103 -0
  137. package/src/motion/styles/motion.css +332 -0
  138. package/src/motion/transitions.ts +74 -0
  139. package/src/motion/virtual.d.ts +4 -0
  140. package/src/primitives/Accordion.astro +129 -0
  141. package/src/primitives/Breadcrumbs.astro +50 -0
  142. package/src/primitives/BulletList.astro +69 -0
  143. package/src/primitives/Button.astro +73 -0
  144. package/src/primitives/ButtonGroup.astro +54 -0
  145. package/src/primitives/Callout.astro +137 -0
  146. package/src/primitives/Caption.astro +35 -0
  147. package/src/primitives/Card.astro +72 -0
  148. package/src/primitives/CardContent.astro +24 -0
  149. package/src/primitives/CardFooter.astro +36 -0
  150. package/src/primitives/CardHeader.astro +86 -0
  151. package/src/primitives/Checkbox.astro +38 -0
  152. package/src/primitives/ChoiceGroup.astro +23 -0
  153. package/src/primitives/Cluster.astro +49 -0
  154. package/src/primitives/Container.astro +44 -0
  155. package/src/primitives/DescriptionList.astro +83 -0
  156. package/src/primitives/Dialog.astro +38 -0
  157. package/src/primitives/Disclosure.astro +67 -0
  158. package/src/primitives/Divider.astro +93 -0
  159. package/src/primitives/Drawer.astro +33 -0
  160. package/src/primitives/Fieldset.astro +80 -0
  161. package/src/primitives/Flex.astro +64 -0
  162. package/src/primitives/FocusRing.astro +63 -0
  163. package/src/primitives/FocusTrap.astro +64 -0
  164. package/src/primitives/Footer.astro +155 -0
  165. package/src/primitives/Form.astro +68 -0
  166. package/src/primitives/FormDescription.astro +26 -0
  167. package/src/primitives/FormError.astro +106 -0
  168. package/src/primitives/FormField.astro +72 -0
  169. package/src/primitives/Grid.astro +64 -0
  170. package/src/primitives/Heading.astro +45 -0
  171. package/src/primitives/IconButton.astro +48 -0
  172. package/src/primitives/Image.astro +125 -0
  173. package/src/primitives/Input.astro +84 -0
  174. package/src/primitives/Label.astro +50 -0
  175. package/src/primitives/Link.astro +81 -0
  176. package/src/primitives/LinkButton.astro +66 -0
  177. package/src/primitives/List.astro +39 -0
  178. package/src/primitives/ListItem.astro +178 -0
  179. package/src/primitives/MediaObject.astro +66 -0
  180. package/src/primitives/MetricCard.astro +276 -0
  181. package/src/primitives/NavLink.astro +81 -0
  182. package/src/primitives/NavMenu.astro +109 -0
  183. package/src/primitives/Navbar.astro +197 -0
  184. package/src/primitives/Panel.astro +153 -0
  185. package/src/primitives/Picture.astro +167 -0
  186. package/src/primitives/Popover.astro +95 -0
  187. package/src/primitives/Prose.astro +45 -0
  188. package/src/primitives/Radio.astro +21 -0
  189. package/src/primitives/Rating.astro +135 -0
  190. package/src/primitives/ReducedMotion.astro +90 -0
  191. package/src/primitives/SegmentedControl.astro +132 -0
  192. package/src/primitives/Select.astro +107 -0
  193. package/src/primitives/Sheet.astro +45 -0
  194. package/src/primitives/SkipLink.astro +31 -0
  195. package/src/primitives/Slider.astro +186 -0
  196. package/src/primitives/Spacer.astro +35 -0
  197. package/src/primitives/Stack.astro +51 -0
  198. package/src/primitives/Surface.astro +70 -0
  199. package/src/primitives/Switch.astro +22 -0
  200. package/src/primitives/Table.astro +382 -0
  201. package/src/primitives/Tabs.astro +126 -0
  202. package/src/primitives/Text.astro +56 -0
  203. package/src/primitives/Textarea.astro +73 -0
  204. package/src/primitives/Thumbnail.astro +154 -0
  205. package/src/primitives/Toggle.astro +99 -0
  206. package/src/primitives/Tooltip.astro +50 -0
  207. package/src/primitives/VisuallyHidden.astro +29 -0
  208. package/src/primitives/index.ts +103 -0
  209. package/src/primitives/internal/AccordionScript.astro +7 -0
  210. package/src/primitives/internal/ChoiceField.astro +89 -0
  211. package/src/primitives/internal/FocusTrapScript.astro +8 -0
  212. package/src/primitives/internal/FormValidationScript.astro +10 -0
  213. package/src/primitives/internal/IndeterminateScript.astro +13 -0
  214. package/src/primitives/internal/ModalPanel.astro +114 -0
  215. package/src/primitives/internal/OverlayScript.astro +7 -0
  216. package/src/primitives/internal/ReducedMotionScript.astro +7 -0
  217. package/src/primitives/internal/SliderScript.astro +7 -0
  218. package/src/primitives/internal/SparklineScript.astro +7 -0
  219. package/src/primitives/internal/TableSortScript.astro +7 -0
  220. package/src/primitives/internal/TabsScript.astro +7 -0
  221. package/src/primitives/internal/TooltipScript.astro +7 -0
  222. package/src/primitives/lib/deprecate.ts +47 -0
  223. package/src/primitives/lib/focus-trap.ts +197 -0
  224. package/src/primitives/lib/focus.ts +60 -0
  225. package/src/primitives/lib/image-plan.ts +82 -0
  226. package/src/primitives/lib/image.ts +129 -0
  227. package/src/primitives/lib/motion.ts +68 -0
  228. package/src/primitives/lib/slider.ts +170 -0
  229. package/src/primitives/scripts/accordion.ts +123 -0
  230. package/src/primitives/scripts/form-validation.ts +225 -0
  231. package/src/primitives/scripts/overlay.ts +71 -0
  232. package/src/primitives/scripts/reduced-motion.ts +59 -0
  233. package/src/primitives/scripts/slider.ts +150 -0
  234. package/src/primitives/scripts/sparkline.ts +131 -0
  235. package/src/primitives/scripts/table-sort.ts +68 -0
  236. package/src/primitives/scripts/tabs.ts +151 -0
  237. package/src/primitives/scripts/tooltip.ts +28 -0
  238. package/src/primitives/styles/a11y.css +104 -0
  239. package/src/primitives/styles/accordion.css +53 -0
  240. package/src/primitives/styles/breadcrumbs.css +59 -0
  241. package/src/primitives/styles/bullet-list.css +89 -0
  242. package/src/primitives/styles/button.css +237 -0
  243. package/src/primitives/styles/choice.css +164 -0
  244. package/src/primitives/styles/cluster.css +24 -0
  245. package/src/primitives/styles/container.css +19 -0
  246. package/src/primitives/styles/data.css +849 -0
  247. package/src/primitives/styles/disclosure.css +140 -0
  248. package/src/primitives/styles/divider.css +50 -0
  249. package/src/primitives/styles/flex.css +42 -0
  250. package/src/primitives/styles/form.css +241 -0
  251. package/src/primitives/styles/grid.css +36 -0
  252. package/src/primitives/styles/media.css +247 -0
  253. package/src/primitives/styles/nav.css +792 -0
  254. package/src/primitives/styles/overlay.css +362 -0
  255. package/src/primitives/styles/prose.css +146 -0
  256. package/src/primitives/styles/scale.css +175 -0
  257. package/src/primitives/styles/segmented.css +165 -0
  258. package/src/primitives/styles/slider.css +170 -0
  259. package/src/primitives/styles/spacer.css +17 -0
  260. package/src/primitives/styles/stack.css +25 -0
  261. package/src/primitives/styles/surface.css +403 -0
  262. package/src/primitives/styles/tabs.css +223 -0
  263. package/src/primitives/styles/typography.css +144 -0
  264. package/src/primitives/styles/utilities.css +24 -0
  265. package/src/primitives/types.ts +385 -0
  266. package/src/primitives/utils.ts +254 -0
  267. package/src/seo/JSONLD.astro +35 -0
  268. package/src/seo/SEOHead.astro +47 -0
  269. package/src/seo/cms.ts +80 -0
  270. package/src/seo/index.ts +10 -0
  271. package/src/seo/integration.ts +231 -0
  272. package/src/seo/lib/jsonld.ts +334 -0
  273. package/src/seo/lib/meta.ts +205 -0
  274. package/src/seo/lib/redirects.ts +283 -0
  275. package/src/seo/lib/robots.ts +33 -0
  276. package/src/seo/lib/rss.ts +98 -0
  277. package/src/seo/lib/sitemap.ts +105 -0
  278. package/src/seo/lib/url.ts +68 -0
  279. package/src/tokens/base.css +71 -0
  280. package/src/tokens/tokens.css +210 -0
@@ -0,0 +1,154 @@
1
+ ---
2
+ /**
3
+ * Thumbnail — a compact media preview: gallery strips, attachments, playlist items,
4
+ * product variants, recent uploads.
5
+ *
6
+ * - Images are generated at the thumbnail's exact size with 1x/2x densities and cropped square
7
+ * (or `aspect`), lazy-loaded.
8
+ * - `kind="video"` adds a play badge and an optional `duration` ("4:12").
9
+ * - `kind="file"` with no `src` shows a document tile with the `fileType` ("PDF", "DOCX").
10
+ * - `more={5}` covers it with "+5" (the last tile of a truncated gallery).
11
+ * - With `href` it's a link; with `button` a button (e.g. to open a lightbox). Then `label`
12
+ * is required and becomes its accessible name; the image itself is marked decorative.
13
+ * `current` marks the selected one in a strip.
14
+ *
15
+ * @example
16
+ * <Thumbnail src={photo} alt="Studio meeting room, window view" size="l" />
17
+ * <Thumbnail src={poster} kind="video" duration="4:12" href="/videos/intake" label="Watch: what to expect at intake (4 minutes)" />
18
+ * <Thumbnail kind="file" fileType="PDF" href="/forms/consent.pdf" label="Consent form (PDF, 220 KB)" />
19
+ */
20
+ import type { HTMLAttributes } from 'astro/types';
21
+ import type { Aspect } from './lib/image-plan';
22
+ import { buildImageSet, type ImageSource } from './lib/image';
23
+ import './styles/utilities.css';
24
+ import './styles/media.css';
25
+
26
+ type Size = 'xs' | 's' | 'm' | 'l' | 'xl';
27
+ const PX: Record<Size, number> = { xs: 40, s: 48, m: 64, l: 96, xl: 128 };
28
+
29
+ type Props = Omit<HTMLAttributes<'span'>, 'role'> & {
30
+ src?: ImageSource;
31
+ /** Alt text for a non-interactive image thumbnail. */
32
+ alt?: string;
33
+ size?: Size;
34
+ shape?: 'rounded' | 'circle' | 'square';
35
+ aspect?: Extract<Aspect, '1/1' | '4/3' | '16/9' | '3/4'>;
36
+ kind?: 'image' | 'video' | 'file';
37
+ duration?: string;
38
+ fileType?: string;
39
+ more?: number;
40
+ /** Remote images: real size. */
41
+ width?: number;
42
+ height?: number;
43
+ href?: string;
44
+ /** Render as a <button> (e.g. to open a lightbox via commandfor). */
45
+ button?: boolean;
46
+ /** Accessible name when it's a link or button. */
47
+ label?: string;
48
+ current?: boolean;
49
+ commandfor?: string;
50
+ command?: string;
51
+ };
52
+
53
+ const {
54
+ src,
55
+ alt = '',
56
+ size = 'm',
57
+ shape = 'rounded',
58
+ aspect = '1/1',
59
+ kind = 'image',
60
+ duration,
61
+ fileType,
62
+ more,
63
+ width,
64
+ height,
65
+ href,
66
+ button = false,
67
+ label,
68
+ current = false,
69
+ commandfor,
70
+ command,
71
+ class: className,
72
+ ...rest
73
+ } = Astro.props;
74
+
75
+ const interactive = Boolean(href || button);
76
+ if (interactive && !label) throw new Error('<Thumbnail> needs a `label` when it is a link or button.');
77
+
78
+ const px = PX[size];
79
+ const [aw, ah] = aspect.split('/').map(Number);
80
+ const box = { w: Math.round(px * (aw >= ah ? aw / ah : 1)), h: Math.round(px * (ah > aw ? ah / aw : 1)) };
81
+ const img = src
82
+ ? await buildImageSet({
83
+ src,
84
+ width: typeof src === 'string' ? width : box.w,
85
+ height: typeof src === 'string' ? height : undefined,
86
+ displayWidth: box.w,
87
+ layout: 'fixed',
88
+ aspect,
89
+ format: 'webp',
90
+ })
91
+ : undefined;
92
+
93
+ const Tag = href ? 'a' : button ? 'button' : 'span';
94
+ const ext = fileType?.toLowerCase();
95
+ const invokerAttrs = button && commandfor ? { commandfor, command: command ?? 'show-modal' } : {};
96
+ ---
97
+
98
+ <Tag
99
+ class:list={['sinn-thumb', className]}
100
+ href={href}
101
+ type={button ? 'button' : undefined}
102
+ aria-current={current ? 'true' : undefined}
103
+ data-size={size === 'm' ? undefined : size}
104
+ data-shape={shape === 'rounded' ? undefined : shape}
105
+ data-aspect={aspect === '1/1' ? undefined : aspect}
106
+ data-kind={kind === 'image' ? undefined : kind}
107
+ data-file={ext}
108
+ role={!interactive && img && alt ? 'img' : undefined}
109
+ {...(!interactive && img && alt ? { 'aria-label': alt } : {})}
110
+ {...invokerAttrs}
111
+ {...rest}
112
+ >
113
+ {
114
+ img && (
115
+ <img
116
+ src={img.src}
117
+ srcset={img.srcset}
118
+ width={img.width}
119
+ height={img.height}
120
+ alt=""
121
+ loading="lazy"
122
+ decoding="async"
123
+ />
124
+ )
125
+ }
126
+ {
127
+ !img && kind === 'file' && (
128
+ <span class="sinn-thumb__file" aria-hidden="true">
129
+ <svg viewBox="0 0 24 28" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linejoin="round">
130
+ <path d="M4 2h11l5 5v18a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z" />
131
+ <path d="M15 2v5h5" />
132
+ </svg>
133
+ {fileType && <span class="sinn-thumb__ext">{fileType}</span>}
134
+ </span>
135
+ )
136
+ }
137
+ {
138
+ kind === 'video' && !more && (
139
+ <span class="sinn-thumb__play" aria-hidden="true">
140
+ <svg viewBox="0 0 16 16" fill="currentColor"><path d="M4 2.5v11l9-5.5z" /></svg>
141
+ </span>
142
+ )
143
+ }
144
+ {kind === 'video' && duration && !more && <span class="sinn-thumb__badge" aria-hidden="true">{duration}</span>}
145
+ {
146
+ typeof more === 'number' && more > 0 && (
147
+ <span class="sinn-thumb__more" aria-hidden="true">+{more}</span>
148
+ )
149
+ }
150
+ {/* The link/button's name is real (visually hidden) text, not aria-label: the visible "+5" and
151
+ "4:12" badges aren't part of the name, and an aria-label that leaves out visible text fails
152
+ WCAG 2.5.3 Label in Name checks. */}
153
+ {interactive && label && <span class="sinn-sr-only">{label}</span>}
154
+ </Tag>
@@ -0,0 +1,99 @@
1
+ ---
2
+ /**
3
+ * Toggle — a button that switches between pressed and not pressed (`aria-pressed`).
4
+ * For toolbar-style options: Bold, Grid view, Mute. For settings that read as
5
+ * on/off ("Email notifications"), use Switch instead.
6
+ *
7
+ * Interactivity: one shared, delegated click handler (~300 B, loaded once per page)
8
+ * flips `aria-pressed` and dispatches a `sinn-toggle-change` CustomEvent
9
+ * (bubbles, composed; detail: { pressed, value }).
10
+ * Without JavaScript the toggle renders in its initial state but doesn't change.
11
+ *
12
+ * Forms: pass `name` (and optionally `value`) to submit `name=value` while pressed.
13
+ * Icon-only: pass `label` and put only an icon in the slot.
14
+ *
15
+ * @example
16
+ * <Toggle name="bold" label="Bold"><BoldIcon aria-hidden="true" /></Toggle>
17
+ * <Toggle pressed>Show archived</Toggle>
18
+ */
19
+ import type { HTMLAttributes } from 'astro/types';
20
+ import type { ButtonTone, ControlSize } from './types';
21
+ import './styles/utilities.css';
22
+ import './styles/button.css';
23
+
24
+ type Props = Omit<HTMLAttributes<'button'>, 'type' | 'aria-pressed'> & {
25
+ pressed?: boolean;
26
+ variant?: 'ghost' | 'outline' | 'soft';
27
+ tone?: ButtonTone;
28
+ size?: ControlSize;
29
+ /** Form field name; submitted only while pressed. */
30
+ name?: string;
31
+ value?: string;
32
+ /** Accessible name for icon-only toggles (rendered as visually hidden text). */
33
+ label?: string;
34
+ };
35
+
36
+ const {
37
+ pressed = false,
38
+ variant = 'outline',
39
+ tone = 'neutral',
40
+ size = 'm',
41
+ name,
42
+ value = 'on',
43
+ label,
44
+ class: className,
45
+ ...rest
46
+ } = Astro.props;
47
+
48
+ const iconOnly = Boolean(label);
49
+ ---
50
+
51
+ <button
52
+ type="button"
53
+ class:list={['sinn-button', 'sinn-toggle', className]}
54
+ data-variant={variant}
55
+ data-tone={tone}
56
+ data-size={size}
57
+ data-icon-only={iconOnly ? '' : undefined}
58
+ data-sinn-toggle
59
+ aria-pressed={pressed ? 'true' : 'false'}
60
+ {...rest}
61
+ >
62
+ <span class="sinn-button__content">
63
+ <slot name="icon-start" />
64
+ <slot />
65
+ {label && <span class="sinn-sr-only">{label}</span>}
66
+ <slot name="icon-end" />
67
+ </span>
68
+ {name && <input type="hidden" name={name} value={value} disabled={!pressed} />}
69
+ </button>
70
+
71
+ <script>
72
+ import type { SinnToggleChangeDetail } from './types';
73
+
74
+ // Delegated, so it covers toggles added later (e.g. by a server island) and registers once.
75
+ const flag = '__sinnToggleBound';
76
+ const w = window as unknown as Record<string, boolean>;
77
+ if (!w[flag]) {
78
+ w[flag] = true;
79
+ document.addEventListener('click', (event) => {
80
+ const target = event.target as Element | null;
81
+ const button = target?.closest?.('button[data-sinn-toggle]');
82
+ if (!(button instanceof HTMLButtonElement) || button.disabled) return;
83
+
84
+ const pressed = button.getAttribute('aria-pressed') !== 'true';
85
+ button.setAttribute('aria-pressed', String(pressed));
86
+
87
+ const input = button.querySelector<HTMLInputElement>('input[type="hidden"]');
88
+ if (input) input.disabled = !pressed;
89
+
90
+ button.dispatchEvent(
91
+ new CustomEvent<SinnToggleChangeDetail>('sinn-toggle-change', {
92
+ bubbles: true,
93
+ composed: true,
94
+ detail: { pressed, value: input?.value },
95
+ }),
96
+ );
97
+ });
98
+ }
99
+ </script>
@@ -0,0 +1,50 @@
1
+ ---
2
+ /**
3
+ * Tooltip — brief text about an element, shown on hover (after ~350 ms) and on keyboard focus.
4
+ *
5
+ * Meets WCAG 1.4.13: the pointer can move onto the bubble without it closing (hoverable),
6
+ * it stays while hovered or focused (persistent), and Esc hides it (dismissible; ~300 B script).
7
+ *
8
+ * Wire it to its trigger with a function child: spread `tip.attrs` onto the element, so it
9
+ * gets `aria-describedby` (default) or `aria-labelledby` (`type="label"`, for icon-only
10
+ * buttons whose name *is* the tooltip text).
11
+ *
12
+ * Rules of thumb:
13
+ * - Never put essential information only in a tooltip: touch screens have no hover.
14
+ * - The trigger must be focusable (a button or link), or keyboard users can't reach it.
15
+ * - Plain text only. For links or buttons, use Popover.
16
+ *
17
+ * @example
18
+ * <Tooltip text="Download as PDF">
19
+ * {(tip) => <IconButton label="Download" {...tip.attrs}><DownloadIcon aria-hidden="true" /></IconButton>}
20
+ * </Tooltip>
21
+ */
22
+ import type { TooltipContext } from './types';
23
+ import { uid } from './utils';
24
+ import TooltipScript from './internal/TooltipScript.astro';
25
+ import './styles/utilities.css';
26
+ import './styles/overlay.css';
27
+
28
+ type Props = {
29
+ text: string;
30
+ placement?: 'top' | 'bottom' | 'start' | 'end';
31
+ /** `description` adds context to a named control; `label` names an otherwise unnamed one. */
32
+ type?: 'description' | 'label';
33
+ id?: string;
34
+ class?: string;
35
+ };
36
+
37
+ const { text, placement = 'top', type = 'description', id = uid('sinn-tooltip'), class: className } = Astro.props;
38
+
39
+ const tip: TooltipContext = {
40
+ id,
41
+ attrs: type === 'label' ? { 'aria-labelledby': id } : { 'aria-describedby': id },
42
+ };
43
+ const trigger = await Astro.slots.render('default', [tip]);
44
+ ---
45
+
46
+ <span class:list={['sinn-tooltip', className]} data-placement={placement}>
47
+ <Fragment set:html={trigger} />
48
+ <span id={id} role="tooltip" class="sinn-tooltip__bubble">{text}</span>
49
+ </span>
50
+ <TooltipScript />
@@ -0,0 +1,29 @@
1
+ ---
2
+ /**
3
+ * VisuallyHidden — content for screen readers and other assistive tech, not for the eye:
4
+ * extra context on repeated links ("Read more <VisuallyHidden>about hosting</VisuallyHidden>"),
5
+ * a heading for a section that's obvious visually, or a status that's shown with color.
6
+ *
7
+ * Unlike `display: none` / `hidden`, the content stays in the accessibility tree and is read.
8
+ * `focusable` makes it appear while it (or something inside it) has focus, for skip links
9
+ * and "Back to top" style controls.
10
+ *
11
+ * Don't use it to hide interactive controls from sighted users, or to stuff keywords.
12
+ *
13
+ * @example
14
+ * <Link href="/services/hosting">Read more<VisuallyHidden> about hosting</VisuallyHidden></Link>
15
+ * <VisuallyHidden as="h2">Search results</VisuallyHidden>
16
+ */
17
+ import type { HTMLAttributes, HTMLTag } from 'astro/types';
18
+ import './styles/utilities.css';
19
+ import './styles/a11y.css';
20
+
21
+ type Props = HTMLAttributes<'span'> & {
22
+ as?: HTMLTag;
23
+ focusable?: boolean;
24
+ };
25
+
26
+ const { as: Tag = 'span', focusable = false, class: className, ...rest } = Astro.props;
27
+ ---
28
+
29
+ <Tag class:list={[focusable ? 'sinn-sr-only-focusable' : 'sinn-sr-only', className]} {...rest}><slot /></Tag>
@@ -0,0 +1,103 @@
1
+ // Pure re-exports, no side effects. Deep imports (`@sinnstack/ui/primitives/Stack.astro`) also work.
2
+
3
+ // Layout
4
+ export { default as Container } from './Container.astro';
5
+ export { default as Stack } from './Stack.astro';
6
+ export { default as Cluster } from './Cluster.astro';
7
+ export { default as Flex } from './Flex.astro';
8
+ export { default as Grid } from './Grid.astro';
9
+ export { default as Spacer } from './Spacer.astro';
10
+ export { default as Divider } from './Divider.astro';
11
+
12
+ // Typography
13
+ export { default as Text } from './Text.astro';
14
+ export { default as Heading } from './Heading.astro';
15
+ export { default as Prose } from './Prose.astro';
16
+ export { default as Link } from './Link.astro';
17
+ export { default as Label } from './Label.astro';
18
+ export { default as Caption } from './Caption.astro';
19
+
20
+ // Actions
21
+ export { default as Button } from './Button.astro';
22
+ export { default as LinkButton } from './LinkButton.astro';
23
+ export { default as IconButton } from './IconButton.astro';
24
+ export { default as ButtonGroup } from './ButtonGroup.astro';
25
+ export { default as Toggle } from './Toggle.astro';
26
+
27
+ // Choice controls
28
+ export { default as Checkbox } from './Checkbox.astro';
29
+ export { default as Radio } from './Radio.astro';
30
+ export { default as Switch } from './Switch.astro';
31
+ export { default as ChoiceGroup } from './ChoiceGroup.astro';
32
+
33
+ // Forms
34
+ export { default as Form } from './Form.astro';
35
+ export { default as FormField } from './FormField.astro';
36
+ export { default as Input } from './Input.astro';
37
+ export { default as Textarea } from './Textarea.astro';
38
+ export { default as Select } from './Select.astro';
39
+ export { default as Fieldset } from './Fieldset.astro';
40
+ export { default as FormDescription } from './FormDescription.astro';
41
+ export { default as FormError } from './FormError.astro';
42
+
43
+ // Surfaces & content
44
+ export { default as Surface } from './Surface.astro';
45
+ export { default as Card } from './Card.astro';
46
+ export { default as CardHeader } from './CardHeader.astro';
47
+ export { default as CardContent } from './CardContent.astro';
48
+ export { default as CardFooter } from './CardFooter.astro';
49
+ export { default as Panel } from './Panel.astro';
50
+ export { default as Callout } from './Callout.astro';
51
+
52
+ // Navigation
53
+ export { default as SkipLink } from './SkipLink.astro';
54
+ export { default as NavLink } from './NavLink.astro';
55
+ export { default as NavMenu } from './NavMenu.astro';
56
+ export { default as Breadcrumbs } from './Breadcrumbs.astro';
57
+ export { default as Navbar } from './Navbar.astro';
58
+ export { default as Footer } from './Footer.astro';
59
+
60
+ // Overlays
61
+ export { default as Dialog } from './Dialog.astro';
62
+ export { default as Drawer } from './Drawer.astro';
63
+ export { default as Sheet } from './Sheet.astro';
64
+ export { default as Popover } from './Popover.astro';
65
+ export { default as Tooltip } from './Tooltip.astro';
66
+
67
+ // Disclosure & selection
68
+ export { default as SegmentedControl } from './SegmentedControl.astro';
69
+ export { default as Slider } from './Slider.astro';
70
+ export { default as Disclosure } from './Disclosure.astro';
71
+ export { default as Accordion } from './Accordion.astro';
72
+ export { default as Tabs } from './Tabs.astro';
73
+ export { sliderModel } from './lib/slider';
74
+ export type { SliderInput, SliderMarkInput, SliderModel } from './lib/slider';
75
+
76
+ // Data display
77
+ export { default as List } from './List.astro';
78
+ export { default as BulletList } from './BulletList.astro';
79
+ export { default as ListItem } from './ListItem.astro';
80
+ export { default as DescriptionList } from './DescriptionList.astro';
81
+ export { default as Table } from './Table.astro';
82
+ export { default as Rating } from './Rating.astro';
83
+ export { default as MetricCard } from './MetricCard.astro';
84
+
85
+ // Media
86
+ export { default as Image } from './Image.astro';
87
+ export { default as Picture } from './Picture.astro';
88
+ export { default as Thumbnail } from './Thumbnail.astro';
89
+ export { default as MediaObject } from './MediaObject.astro';
90
+ export type { Aspect, ImageLayout } from './lib/image-plan';
91
+ export type { ImageFormat, ImageQuality, ImageSource, PictureSource } from './lib/image';
92
+
93
+ // Accessibility utilities
94
+ export { default as VisuallyHidden } from './VisuallyHidden.astro';
95
+ export { default as FocusRing } from './FocusRing.astro';
96
+ export { default as FocusTrap } from './FocusTrap.astro';
97
+ export { default as ReducedMotion } from './ReducedMotion.astro';
98
+ export type { SinnFocusTrapElement } from './lib/focus-trap';
99
+ export type { MotionPreference } from './lib/motion';
100
+
101
+ export type * from './types';
102
+ export { SPACE, MEASURE } from './types';
103
+ export { formatValue } from './utils';
@@ -0,0 +1,7 @@
1
+ ---
2
+ /** @internal Loaded once per page that renders an Accordion. ~1 KB: show/hide all, arrow keys between headers, deep links, print. */
3
+ ---
4
+
5
+ <script>
6
+ import '../scripts/accordion';
7
+ </script>
@@ -0,0 +1,89 @@
1
+ ---
2
+ /**
3
+ * @internal Shared markup for Checkbox, Radio and Switch:
4
+ * a native input, its <label>, an optional description and an error message, all wired
5
+ * up with aria-describedby. `class` goes on the wrapper; every other attribute goes on the <input>.
6
+ *
7
+ * Checkboxes and switches get their own (hidden-while-empty) error element so inline
8
+ * validation can show "You must accept the terms". Radios don't: their error belongs to
9
+ * the enclosing Fieldset, where the validation script looks for it.
10
+ */
11
+ import type { ChoiceFieldProps } from '../types';
12
+ import { fieldContext, uid } from '../utils';
13
+ import FormError from '../FormError.astro';
14
+ import '../styles/utilities.css';
15
+ import '../styles/choice.css';
16
+ import '../styles/form.css';
17
+
18
+ type Props = ChoiceFieldProps & {
19
+ kind: 'checkbox' | 'radio' | 'switch';
20
+ /** @internal */
21
+ extraInputAttrs?: Record<string, string | undefined>;
22
+ };
23
+
24
+ const {
25
+ kind,
26
+ extraInputAttrs = {},
27
+ label,
28
+ description,
29
+ error,
30
+ invalid = false,
31
+ messages,
32
+ size = 'm',
33
+ labelPosition = 'end',
34
+ id = uid(`sinn-${kind}`),
35
+ required = false,
36
+ class: className,
37
+ 'aria-describedby': describedBy,
38
+ ...rest
39
+ } = Astro.props;
40
+
41
+ const hasErrorElement = kind !== 'radio';
42
+ const field = fieldContext({
43
+ id,
44
+ description,
45
+ error,
46
+ required: Boolean(required),
47
+ messages,
48
+ describedBy: describedBy as string | undefined,
49
+ hasErrorElement,
50
+ });
51
+ const isInvalid = field.invalid || invalid;
52
+ // Merge into one object so no attribute is rendered twice.
53
+ const inputAttrs = {
54
+ ...field.attrs,
55
+ 'aria-invalid': isInvalid ? 'true' : undefined,
56
+ ...extraInputAttrs,
57
+ ...rest,
58
+ };
59
+ const hasLabel = Boolean(label) || Astro.slots.has('default');
60
+ ---
61
+
62
+ <div
63
+ class:list={['sinn-choice', className]}
64
+ data-size={size}
65
+ data-label-position={labelPosition === 'start' ? 'start' : undefined}
66
+ >
67
+ <input
68
+ type={kind === 'radio' ? 'radio' : 'checkbox'}
69
+ role={kind === 'switch' ? 'switch' : undefined}
70
+ class={`sinn-${kind}`}
71
+ {...inputAttrs}
72
+ />
73
+ {
74
+ hasLabel && (
75
+ <div class="sinn-choice__text">
76
+ <label for={id} class="sinn-choice__label">
77
+ {label}
78
+ <slot />
79
+ </label>
80
+ {description && (
81
+ <span id={field.descriptionId} class="sinn-choice__description">
82
+ {description}
83
+ </span>
84
+ )}
85
+ {hasErrorElement && <FormError id={field.errorId} message={error} />}
86
+ </div>
87
+ )
88
+ }
89
+ </div>
@@ -0,0 +1,8 @@
1
+ ---
2
+ /** @internal Defines <sinn-focus-trap>. Loaded once per page that renders a FocusTrap. ~1.5 KB. */
3
+ ---
4
+
5
+ <script>
6
+ import { defineFocusTrap } from '../lib/focus-trap';
7
+ defineFocusTrap();
8
+ </script>
@@ -0,0 +1,10 @@
1
+ ---
2
+ /**
3
+ * @internal Rendered by Form only when validate="inline". Astro 5 renders a component's
4
+ * script only when that component is rendered, so pages without inline forms ship nothing.
5
+ */
6
+ ---
7
+
8
+ <script>
9
+ import '../scripts/form-validation';
10
+ </script>
@@ -0,0 +1,13 @@
1
+ ---
2
+ /** @internal Rendered by Checkbox only when `indeterminate` is set, so other pages ship no script. */
3
+ ---
4
+
5
+ <script>
6
+ const apply = () => {
7
+ for (const el of document.querySelectorAll<HTMLInputElement>('input[data-indeterminate]')) {
8
+ el.indeterminate = true;
9
+ }
10
+ };
11
+ apply();
12
+ document.addEventListener('astro:page-load', apply);
13
+ </script>