@sinnstack/ui 0.0.0-stage → 0.3.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.
- package/CHANGELOG.md +89 -0
- package/LICENSE +373 -0
- package/README.md +188 -2
- package/docs/blocks.md +373 -0
- package/docs/data.md +128 -0
- package/docs/finishes.md +165 -0
- package/docs/motion.md +166 -0
- package/docs/primitives.md +510 -0
- package/docs/seo.md +191 -0
- package/docs/tokens.md +122 -0
- package/package.json +132 -3
- package/scripts/check-contrast.mjs +180 -0
- package/src/blocks/BlockRenderer.astro +60 -0
- package/src/blocks/CTABanner.astro +121 -0
- package/src/blocks/CTAPair.astro +110 -0
- package/src/blocks/CardGrid.astro +167 -0
- package/src/blocks/ConsentEmbed.astro +125 -0
- package/src/blocks/ConsentManager.astro +147 -0
- package/src/blocks/ConsentScript.astro +47 -0
- package/src/blocks/ContactCard.astro +164 -0
- package/src/blocks/ContactForm.astro +224 -0
- package/src/blocks/ErrorPage.astro +242 -0
- package/src/blocks/FAQ.astro +135 -0
- package/src/blocks/FeatureGrid.astro +148 -0
- package/src/blocks/Hero.astro +171 -0
- package/src/blocks/HeroCarousel.astro +220 -0
- package/src/blocks/HighlightCards.astro +107 -0
- package/src/blocks/LocationHours.astro +311 -0
- package/src/blocks/LogoCloud.astro +135 -0
- package/src/blocks/MaintenancePage.astro +173 -0
- package/src/blocks/MediaText.astro +177 -0
- package/src/blocks/PageHeader.astro +126 -0
- package/src/blocks/ProseSection.astro +98 -0
- package/src/blocks/Reviews.astro +194 -0
- package/src/blocks/RichText.astro +58 -0
- package/src/blocks/StatsBand.astro +117 -0
- package/src/blocks/Steps.astro +141 -0
- package/src/blocks/Testimonials.astro +144 -0
- package/src/blocks/Topbar.astro +158 -0
- package/src/blocks/cms/card-grid.ts +48 -0
- package/src/blocks/cms/consent.ts +16 -0
- package/src/blocks/cms/contact-card.ts +46 -0
- package/src/blocks/cms/contact-form.ts +37 -0
- package/src/blocks/cms/cta-banner.ts +27 -0
- package/src/blocks/cms/cta-pair.ts +30 -0
- package/src/blocks/cms/data-base.ts +5 -0
- package/src/blocks/cms/data.ts +257 -0
- package/src/blocks/cms/faq.ts +38 -0
- package/src/blocks/cms/feature-grid.ts +47 -0
- package/src/blocks/cms/fixtures.ts +591 -0
- package/src/blocks/cms/hero-carousel.ts +36 -0
- package/src/blocks/cms/hero.ts +33 -0
- package/src/blocks/cms/highlight-cards.ts +41 -0
- package/src/blocks/cms/images.ts +37 -0
- package/src/blocks/cms/index.ts +59 -0
- package/src/blocks/cms/location-hours.ts +67 -0
- package/src/blocks/cms/logo-cloud.ts +36 -0
- package/src/blocks/cms/media-text.ts +26 -0
- package/src/blocks/cms/page-header.ts +27 -0
- package/src/blocks/cms/pages.ts +35 -0
- package/src/blocks/cms/prose-section.ts +25 -0
- package/src/blocks/cms/reviews.ts +50 -0
- package/src/blocks/cms/schema-dsl.ts +134 -0
- package/src/blocks/cms/schema.ts +794 -0
- package/src/blocks/cms/shared.ts +63 -0
- package/src/blocks/cms/stats-band.ts +35 -0
- package/src/blocks/cms/steps.ts +40 -0
- package/src/blocks/cms/testimonials.ts +46 -0
- package/src/blocks/cms/topbar.ts +27 -0
- package/src/blocks/cms/types.ts +27 -0
- package/src/blocks/consent.ts +14 -0
- package/src/blocks/icons.ts +47 -0
- package/src/blocks/index.ts +42 -0
- package/src/blocks/internal/Actions.astro +35 -0
- package/src/blocks/internal/BlockHeader.astro +45 -0
- package/src/blocks/internal/BlockShell.astro +58 -0
- package/src/blocks/internal/CarouselScript.astro +7 -0
- package/src/blocks/internal/ConsentEmbedScript.astro +7 -0
- package/src/blocks/internal/ConsentManagerScript.astro +7 -0
- package/src/blocks/internal/HoursScript.astro +7 -0
- package/src/blocks/internal/Placeholder.astro +13 -0
- package/src/blocks/internal/RichTextNode.astro +133 -0
- package/src/blocks/internal/StandaloneDocument.astro +53 -0
- package/src/blocks/internal/consent.ts +96 -0
- package/src/blocks/internal/fields.ts +18 -0
- package/src/blocks/internal/registry-contract.ts +67 -0
- package/src/blocks/internal/reviews.ts +22 -0
- package/src/blocks/internal/slug.ts +12 -0
- package/src/blocks/internal/util.ts +23 -0
- package/src/blocks/lib/contact.ts +92 -0
- package/src/blocks/lib/error-pages.ts +119 -0
- package/src/blocks/lib/faq.ts +37 -0
- package/src/blocks/lib/hours.ts +201 -0
- package/src/blocks/lib/maintenance.ts +129 -0
- package/src/blocks/lib/markdown.ts +350 -0
- package/src/blocks/lib/rich-text.ts +132 -0
- package/src/blocks/registry.ts +79 -0
- package/src/blocks/scripts/carousel.ts +218 -0
- package/src/blocks/scripts/consent-embed.ts +105 -0
- package/src/blocks/scripts/consent-manager.ts +112 -0
- package/src/blocks/scripts/consent-store.ts +86 -0
- package/src/blocks/scripts/error-page.ts +71 -0
- package/src/blocks/scripts/hours.ts +107 -0
- package/src/blocks/scripts/maintenance.ts +109 -0
- package/src/blocks/styles/blocks.css +1320 -0
- package/src/blocks/styles/consent.css +102 -0
- package/src/blocks/styles/faq.css +28 -0
- package/src/blocks/styles/location.css +92 -0
- package/src/blocks/styles/prose-section.css +13 -0
- package/src/blocks/styles/quotes.css +123 -0
- package/src/blocks/styles/rich-text.css +14 -0
- package/src/blocks/types.ts +293 -0
- package/src/data/ChartAxis.astro +19 -0
- package/src/data/ChartContainer.astro +152 -0
- package/src/data/ChartLegend.astro +25 -0
- package/src/data/ChartSeries.astro +14 -0
- package/src/data/ChartTable.astro +17 -0
- package/src/data/ChartTooltip.astro +20 -0
- package/src/data/Sparkline.astro +55 -0
- package/src/data/cms.ts +130 -0
- package/src/data/index.ts +10 -0
- package/src/data/internal/scale.ts +107 -0
- package/src/data/lib/chart.ts +459 -0
- package/src/data/lib/render.ts +219 -0
- package/src/data/lib/sparkline.ts +117 -0
- package/src/data/schema.ts +65 -0
- package/src/data/scripts/chart.ts +324 -0
- package/src/data/styles/chart.css +392 -0
- package/src/finishes/aurora.css +75 -0
- package/src/finishes/autumn.css +87 -0
- package/src/finishes/blueprint.css +69 -0
- package/src/finishes/brutalist.css +55 -0
- package/src/finishes/clay.css +48 -0
- package/src/finishes/day-cycle.css +46 -0
- package/src/finishes/fog.css +71 -0
- package/src/finishes/glass.css +149 -0
- package/src/finishes/holographic.css +91 -0
- package/src/finishes/night.css +77 -0
- package/src/finishes/paper.css +58 -0
- package/src/finishes/polished-glass.css +159 -0
- package/src/finishes/rain.css +84 -0
- package/src/finishes/scripts/day-cycle.ts +30 -0
- package/src/finishes/scripts/holographic.ts +37 -0
- package/src/finishes/scripts/spotlight.ts +30 -0
- package/src/finishes/spotlight.css +41 -0
- package/src/finishes/spring.css +80 -0
- package/src/finishes/terminal.css +49 -0
- package/src/motion/Marquee.astro +90 -0
- package/src/motion/MotionProvider.astro +50 -0
- package/src/motion/PageTransitions.astro +61 -0
- package/src/motion/Parallax.astro +44 -0
- package/src/motion/ParallaxLayer.astro +31 -0
- package/src/motion/RevealOnScroll.astro +59 -0
- package/src/motion/SceneRegistry.astro +38 -0
- package/src/motion/ScrollScene.astro +81 -0
- package/src/motion/index.ts +12 -0
- package/src/motion/integration.ts +48 -0
- package/src/motion/runtime/page-transitions.ts +68 -0
- package/src/motion/runtime/runtime.ts +180 -0
- package/src/motion/runtime/scenes.ts +248 -0
- package/src/motion/runtime/types.ts +103 -0
- package/src/motion/styles/motion.css +332 -0
- package/src/motion/transitions.ts +74 -0
- package/src/motion/virtual.d.ts +4 -0
- package/src/primitives/Accordion.astro +129 -0
- package/src/primitives/Breadcrumbs.astro +50 -0
- package/src/primitives/BulletList.astro +69 -0
- package/src/primitives/Button.astro +73 -0
- package/src/primitives/ButtonGroup.astro +54 -0
- package/src/primitives/Callout.astro +137 -0
- package/src/primitives/Caption.astro +35 -0
- package/src/primitives/Card.astro +72 -0
- package/src/primitives/CardContent.astro +24 -0
- package/src/primitives/CardFooter.astro +36 -0
- package/src/primitives/CardHeader.astro +86 -0
- package/src/primitives/Checkbox.astro +38 -0
- package/src/primitives/ChoiceGroup.astro +23 -0
- package/src/primitives/Cluster.astro +49 -0
- package/src/primitives/Container.astro +44 -0
- package/src/primitives/DescriptionList.astro +83 -0
- package/src/primitives/Dialog.astro +38 -0
- package/src/primitives/Disclosure.astro +67 -0
- package/src/primitives/Divider.astro +93 -0
- package/src/primitives/Drawer.astro +33 -0
- package/src/primitives/Fieldset.astro +80 -0
- package/src/primitives/Flex.astro +64 -0
- package/src/primitives/FocusRing.astro +63 -0
- package/src/primitives/FocusTrap.astro +64 -0
- package/src/primitives/Footer.astro +155 -0
- package/src/primitives/Form.astro +68 -0
- package/src/primitives/FormDescription.astro +26 -0
- package/src/primitives/FormError.astro +106 -0
- package/src/primitives/FormField.astro +72 -0
- package/src/primitives/Grid.astro +64 -0
- package/src/primitives/Heading.astro +45 -0
- package/src/primitives/IconButton.astro +48 -0
- package/src/primitives/Image.astro +125 -0
- package/src/primitives/Input.astro +86 -0
- package/src/primitives/Label.astro +50 -0
- package/src/primitives/Link.astro +81 -0
- package/src/primitives/LinkButton.astro +66 -0
- package/src/primitives/List.astro +39 -0
- package/src/primitives/ListItem.astro +178 -0
- package/src/primitives/MediaObject.astro +66 -0
- package/src/primitives/MetricCard.astro +278 -0
- package/src/primitives/NavLink.astro +81 -0
- package/src/primitives/NavMenu.astro +109 -0
- package/src/primitives/Navbar.astro +197 -0
- package/src/primitives/Panel.astro +153 -0
- package/src/primitives/Picture.astro +167 -0
- package/src/primitives/Popover.astro +95 -0
- package/src/primitives/Prose.astro +45 -0
- package/src/primitives/Radio.astro +21 -0
- package/src/primitives/Rating.astro +135 -0
- package/src/primitives/ReducedMotion.astro +90 -0
- package/src/primitives/SegmentedControl.astro +132 -0
- package/src/primitives/Select.astro +109 -0
- package/src/primitives/Sheet.astro +45 -0
- package/src/primitives/SkipLink.astro +31 -0
- package/src/primitives/Slider.astro +186 -0
- package/src/primitives/Spacer.astro +35 -0
- package/src/primitives/Stack.astro +51 -0
- package/src/primitives/Surface.astro +70 -0
- package/src/primitives/Switch.astro +22 -0
- package/src/primitives/Table.astro +382 -0
- package/src/primitives/Tabs.astro +126 -0
- package/src/primitives/Text.astro +56 -0
- package/src/primitives/Textarea.astro +75 -0
- package/src/primitives/Thumbnail.astro +154 -0
- package/src/primitives/Toggle.astro +99 -0
- package/src/primitives/Tooltip.astro +50 -0
- package/src/primitives/VisuallyHidden.astro +29 -0
- package/src/primitives/index.ts +103 -0
- package/src/primitives/internal/AccordionScript.astro +7 -0
- package/src/primitives/internal/ChoiceField.astro +91 -0
- package/src/primitives/internal/FocusTrapScript.astro +8 -0
- package/src/primitives/internal/FormValidationScript.astro +10 -0
- package/src/primitives/internal/IndeterminateScript.astro +13 -0
- package/src/primitives/internal/ModalPanel.astro +114 -0
- package/src/primitives/internal/OverlayScript.astro +7 -0
- package/src/primitives/internal/ReducedMotionScript.astro +7 -0
- package/src/primitives/internal/SliderScript.astro +7 -0
- package/src/primitives/internal/SparklineScript.astro +7 -0
- package/src/primitives/internal/TableSortScript.astro +7 -0
- package/src/primitives/internal/TabsScript.astro +7 -0
- package/src/primitives/internal/TooltipScript.astro +7 -0
- package/src/primitives/internal/image-plan.ts +82 -0
- package/src/primitives/internal/image.ts +129 -0
- package/src/primitives/internal/slider.ts +170 -0
- package/src/primitives/lib/deprecate.ts +47 -0
- package/src/primitives/lib/focus-trap.ts +197 -0
- package/src/primitives/lib/focus.ts +60 -0
- package/src/primitives/lib/motion.ts +68 -0
- package/src/primitives/scripts/accordion.ts +123 -0
- package/src/primitives/scripts/form-validation.ts +225 -0
- package/src/primitives/scripts/overlay.ts +71 -0
- package/src/primitives/scripts/reduced-motion.ts +59 -0
- package/src/primitives/scripts/slider.ts +150 -0
- package/src/primitives/scripts/sparkline.ts +131 -0
- package/src/primitives/scripts/table-sort.ts +68 -0
- package/src/primitives/scripts/tabs.ts +151 -0
- package/src/primitives/scripts/tooltip.ts +28 -0
- package/src/primitives/styles/a11y.css +104 -0
- package/src/primitives/styles/accordion.css +53 -0
- package/src/primitives/styles/breadcrumbs.css +59 -0
- package/src/primitives/styles/bullet-list.css +89 -0
- package/src/primitives/styles/button.css +237 -0
- package/src/primitives/styles/choice.css +164 -0
- package/src/primitives/styles/cluster.css +24 -0
- package/src/primitives/styles/container.css +19 -0
- package/src/primitives/styles/data.css +849 -0
- package/src/primitives/styles/disclosure.css +140 -0
- package/src/primitives/styles/divider.css +50 -0
- package/src/primitives/styles/flex.css +42 -0
- package/src/primitives/styles/form.css +241 -0
- package/src/primitives/styles/grid.css +36 -0
- package/src/primitives/styles/media.css +247 -0
- package/src/primitives/styles/nav.css +792 -0
- package/src/primitives/styles/overlay.css +362 -0
- package/src/primitives/styles/prose.css +146 -0
- package/src/primitives/styles/scale.css +175 -0
- package/src/primitives/styles/segmented.css +165 -0
- package/src/primitives/styles/slider.css +170 -0
- package/src/primitives/styles/spacer.css +17 -0
- package/src/primitives/styles/stack.css +25 -0
- package/src/primitives/styles/surface.css +403 -0
- package/src/primitives/styles/tabs.css +223 -0
- package/src/primitives/styles/typography.css +144 -0
- package/src/primitives/styles/utilities.css +24 -0
- package/src/primitives/types.ts +385 -0
- package/src/primitives/utils.ts +254 -0
- package/src/seo/JSONLD.astro +35 -0
- package/src/seo/SEOHead.astro +47 -0
- package/src/seo/cms.ts +59 -0
- package/src/seo/index.ts +10 -0
- package/src/seo/integration.ts +268 -0
- package/src/seo/internal/url.ts +68 -0
- package/src/seo/lib/jsonld.ts +342 -0
- package/src/seo/lib/meta.ts +205 -0
- package/src/seo/lib/redirects.ts +293 -0
- package/src/seo/lib/robots.ts +33 -0
- package/src/seo/lib/rss.ts +98 -0
- package/src/seo/lib/sitemap.ts +105 -0
- package/src/seo/schema.ts +43 -0
- package/src/tokens/base.css +71 -0
- package/src/tokens/tokens.css +210 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Popover — contextual floating content next to its trigger: a short explanation, a mini
|
|
4
|
+
* form, a menu of links, account details. Non-modal: the page stays usable.
|
|
5
|
+
*
|
|
6
|
+
* Built on the Popover API (`popovertarget`) and CSS anchor positioning, so it needs no
|
|
7
|
+
* JavaScript: it opens next to the trigger and flips to stay on screen. Esc, clicking
|
|
8
|
+
* outside, and the trigger close it. The trigger exposes its expanded state, and Tab moves
|
|
9
|
+
* from the trigger into the popover. Without anchor positioning support it shows as a small
|
|
10
|
+
* centered card.
|
|
11
|
+
*
|
|
12
|
+
* The trigger is rendered for you as a Button: pass `label` and button style props, or put
|
|
13
|
+
* custom trigger content in the `trigger` slot (with `label` as its accessible name for icons).
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* <Popover label="What's a retainer?" variant="ghost" size="s" placement="top">
|
|
17
|
+
* A fixed amount you pay for a covered service, usually at the time of the visit.
|
|
18
|
+
* </Popover>
|
|
19
|
+
* <Popover label="Account" iconOnly variant="ghost" placement="bottom" align="end" contentLabel="Account">
|
|
20
|
+
* <svg slot="trigger" aria-hidden="true">…</svg>
|
|
21
|
+
* <NavMenu orientation="vertical" variant="pill" items={…} />
|
|
22
|
+
* </Popover>
|
|
23
|
+
*/
|
|
24
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
25
|
+
import type { ButtonStyleProps } from './types';
|
|
26
|
+
import { uid } from './utils';
|
|
27
|
+
import './styles/utilities.css';
|
|
28
|
+
import './styles/button.css';
|
|
29
|
+
import './styles/overlay.css';
|
|
30
|
+
|
|
31
|
+
type Props = Omit<HTMLAttributes<'div'>, 'role'> &
|
|
32
|
+
ButtonStyleProps & {
|
|
33
|
+
/** Trigger text (or the accessible name of an icon-only trigger). */
|
|
34
|
+
label: string;
|
|
35
|
+
iconOnly?: boolean;
|
|
36
|
+
placement?: 'bottom' | 'top' | 'start' | 'end';
|
|
37
|
+
align?: 'start' | 'center' | 'end';
|
|
38
|
+
/**
|
|
39
|
+
* `auto` (default): light-dismiss, closes other auto popovers.
|
|
40
|
+
* `manual`: no light dismiss and no Esc; stays open until the trigger is pressed again.
|
|
41
|
+
*/
|
|
42
|
+
mode?: 'auto' | 'manual';
|
|
43
|
+
/** Give the popover a dialog role and this name when it holds interactive content. */
|
|
44
|
+
contentLabel?: string;
|
|
45
|
+
padding?: 'default' | 'none';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const {
|
|
49
|
+
label,
|
|
50
|
+
iconOnly = false,
|
|
51
|
+
variant = 'outline',
|
|
52
|
+
tone = 'neutral',
|
|
53
|
+
size = 'm',
|
|
54
|
+
fullWidth = false,
|
|
55
|
+
placement = 'bottom',
|
|
56
|
+
align = 'center',
|
|
57
|
+
mode = 'auto',
|
|
58
|
+
contentLabel,
|
|
59
|
+
padding = 'default',
|
|
60
|
+
id = uid('sinn-popover'),
|
|
61
|
+
class: className,
|
|
62
|
+
...rest
|
|
63
|
+
} = Astro.props;
|
|
64
|
+
|
|
65
|
+
const hasTriggerSlot = Astro.slots.has('trigger');
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
<button
|
|
69
|
+
type="button"
|
|
70
|
+
class="sinn-button sinn-popover-trigger"
|
|
71
|
+
data-variant={variant}
|
|
72
|
+
data-tone={tone}
|
|
73
|
+
data-size={size}
|
|
74
|
+
data-full-width={fullWidth ? '' : undefined}
|
|
75
|
+
data-icon-only={iconOnly ? '' : undefined}
|
|
76
|
+
popovertarget={id}
|
|
77
|
+
>
|
|
78
|
+
<span class="sinn-button__content">
|
|
79
|
+
{hasTriggerSlot && <slot name="trigger" />}
|
|
80
|
+
{iconOnly ? <span class="sinn-sr-only">{label}</span> : label}
|
|
81
|
+
</span>
|
|
82
|
+
</button>
|
|
83
|
+
<div
|
|
84
|
+
id={id}
|
|
85
|
+
popover={mode}
|
|
86
|
+
class:list={['sinn-popover', className]}
|
|
87
|
+
data-placement={placement}
|
|
88
|
+
data-align={align}
|
|
89
|
+
data-padding={padding === 'none' ? 'none' : undefined}
|
|
90
|
+
role={contentLabel ? 'dialog' : undefined}
|
|
91
|
+
aria-label={contentLabel}
|
|
92
|
+
{...rest}
|
|
93
|
+
>
|
|
94
|
+
<slot />
|
|
95
|
+
</div>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Prose: readable typography for long-form content whose markup you don't control, such as
|
|
4
|
+
* CMS rich text or Markdown (headings, paragraphs, lists, quotes, code, tables, images).
|
|
5
|
+
*
|
|
6
|
+
* - Styles plain elements inside it at zero specificity, so a site can still restyle anything.
|
|
7
|
+
* - Components embedded in the content keep their own look: wrap them in `class="sinn-not-prose"`.
|
|
8
|
+
* - Links are always underlined, as running text needs (WCAG 1.4.1).
|
|
9
|
+
* - `measure` caps the line length at about 65 characters.
|
|
10
|
+
* - For CMS rich text use `RichText` from `@sinnstack/ui/blocks`, which renders inside a Prose
|
|
11
|
+
* and only allows safe elements and URLs.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <Prose measure>
|
|
15
|
+
* <h2>How a project runs</h2>
|
|
16
|
+
* <p>Every site starts with a <a href="/process">two-week discovery</a>…</p>
|
|
17
|
+
* </Prose>
|
|
18
|
+
*/
|
|
19
|
+
import type { HTMLAttributes, HTMLTag } from 'astro/types';
|
|
20
|
+
import './styles/utilities.css';
|
|
21
|
+
import './styles/prose.css';
|
|
22
|
+
|
|
23
|
+
type Props = HTMLAttributes<'div'> & {
|
|
24
|
+
/** Element to render: `div` (default), `article` or `section`. */
|
|
25
|
+
as?: HTMLTag;
|
|
26
|
+
/** Base text size: `s`, `m` (default) or `l`. Headings scale with it. */
|
|
27
|
+
size?: 's' | 'm' | 'l';
|
|
28
|
+
/** Cap line length at a readable measure (~65ch). */
|
|
29
|
+
measure?: boolean;
|
|
30
|
+
/** With `measure`, center the column. */
|
|
31
|
+
align?: 'start' | 'center';
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const { as: Tag = 'div', size = 'm', measure = false, align = 'start', class: className, ...rest } = Astro.props;
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
<Tag
|
|
38
|
+
class:list={['sinn-prose', className]}
|
|
39
|
+
data-size={size === 'm' ? undefined : size}
|
|
40
|
+
data-measure={measure ? '' : undefined}
|
|
41
|
+
data-align={measure && align === 'center' ? 'center' : undefined}
|
|
42
|
+
{...rest}
|
|
43
|
+
>
|
|
44
|
+
<slot />
|
|
45
|
+
</Tag>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Radio — select one option from a group. Native `<input type="radio">`.
|
|
4
|
+
* Radios sharing a `name` form one group; arrow keys move between them natively.
|
|
5
|
+
* Always place them inside a ChoiceGroup so the group has a name (fieldset + legend).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* <ChoiceGroup legend="Contact method">
|
|
9
|
+
* <Radio name="contact" value="email" label="Email" checked />
|
|
10
|
+
* <Radio name="contact" value="phone" label="Phone" />
|
|
11
|
+
* </ChoiceGroup>
|
|
12
|
+
*/
|
|
13
|
+
import ChoiceField from './internal/ChoiceField.astro';
|
|
14
|
+
import type { ChoiceFieldProps } from './types';
|
|
15
|
+
|
|
16
|
+
type Props = ChoiceFieldProps & { name: string };
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
<ChoiceField kind="radio" {...Astro.props}>
|
|
20
|
+
<slot />
|
|
21
|
+
</ChoiceField>
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Rating — displays a score on a star scale, with exact fractional fill (4.3 fills 4.3 stars).
|
|
4
|
+
*
|
|
5
|
+
* - The stars are one SVG with `role="img"` and a full name ("Rated 4.3 out of 5"); the
|
|
6
|
+
* visible number and review count are real text, so the value never depends on the graphic.
|
|
7
|
+
* - Stars have an outline that holds 3:1 against the surface (the gold fill alone wouldn't).
|
|
8
|
+
* - `distribution` adds a breakdown: one row per star level with an aligned bar and share,
|
|
9
|
+
* like review summaries on product and provider pages. Counts are listed highest level first.
|
|
10
|
+
* - Display only. For collecting a rating, use a ChoiceGroup of Radios.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <Rating value={4.3} count={128} />
|
|
14
|
+
* <Rating value={4.6} count={212} distribution={[164, 32, 9, 4, 3]} size="l" />
|
|
15
|
+
*/
|
|
16
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
17
|
+
import { formatValue, pct, uid } from './utils';
|
|
18
|
+
import './styles/scale.css';
|
|
19
|
+
import './styles/utilities.css';
|
|
20
|
+
import './styles/data.css';
|
|
21
|
+
|
|
22
|
+
type Props = HTMLAttributes<'div'> & {
|
|
23
|
+
value: number;
|
|
24
|
+
max?: number;
|
|
25
|
+
/** Number of ratings it's based on. */
|
|
26
|
+
count?: number;
|
|
27
|
+
/** Singular/plural noun for the count. Translate per site. */
|
|
28
|
+
countLabel?: { one: string; other: string };
|
|
29
|
+
/** Link the count (e.g. to the reviews section). */
|
|
30
|
+
countHref?: string;
|
|
31
|
+
showValue?: boolean;
|
|
32
|
+
size?: 's' | 'm' | 'l';
|
|
33
|
+
/** Counts per level, from `max` stars down to 1. */
|
|
34
|
+
distribution?: number[];
|
|
35
|
+
/** Override the accessible name of the stars. */
|
|
36
|
+
label?: string;
|
|
37
|
+
locale?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
value,
|
|
42
|
+
max = 5,
|
|
43
|
+
count,
|
|
44
|
+
countLabel = { one: 'review', other: 'reviews' },
|
|
45
|
+
countHref,
|
|
46
|
+
showValue = true,
|
|
47
|
+
size = 'm',
|
|
48
|
+
distribution,
|
|
49
|
+
label,
|
|
50
|
+
locale = 'en-US',
|
|
51
|
+
class: className,
|
|
52
|
+
...rest
|
|
53
|
+
} = Astro.props;
|
|
54
|
+
|
|
55
|
+
const clamped = Math.min(max, Math.max(0, Number(value) || 0));
|
|
56
|
+
const shown = formatValue(clamped, { kind: 'number', digits: 1 }, locale);
|
|
57
|
+
const STAR = 20;
|
|
58
|
+
const GAP = 3;
|
|
59
|
+
const width = max * STAR + (max - 1) * GAP;
|
|
60
|
+
const full = Math.floor(clamped);
|
|
61
|
+
const clipWidth = full * (STAR + GAP) + (clamped - full) * STAR;
|
|
62
|
+
const clipId = uid('sinn-rating-clip');
|
|
63
|
+
const starPath =
|
|
64
|
+
'M10 1.6l2.47 5.01 5.53.8-4 3.9.94 5.5L10 14.21 5.06 16.81 6 11.31l-4-3.9 5.53-.8z';
|
|
65
|
+
const stars = Array.from({ length: max }, (_, i) => i * (STAR + GAP));
|
|
66
|
+
const plural = new Intl.PluralRules(locale);
|
|
67
|
+
const countText =
|
|
68
|
+
count !== undefined ? `${formatValue(count, 'integer', locale)} ${plural.select(count) === 'one' ? countLabel.one : countLabel.other}` : '';
|
|
69
|
+
const name = label ?? `Rated ${shown} out of ${max}`;
|
|
70
|
+
|
|
71
|
+
const total = distribution?.reduce((a, b) => a + b, 0) ?? 0;
|
|
72
|
+
const dist = (distribution ?? []).map((n, i) => {
|
|
73
|
+
const level = max - i;
|
|
74
|
+
const share = total ? n / total : 0;
|
|
75
|
+
return {
|
|
76
|
+
level,
|
|
77
|
+
n,
|
|
78
|
+
pct: pct(n, total),
|
|
79
|
+
shareText: formatValue(share, { kind: 'percent', digits: 0 }, locale),
|
|
80
|
+
countText: `${formatValue(n, 'integer', locale)} ${plural.select(n) === 'one' ? countLabel.one : countLabel.other}`,
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
const smallStar = 'M10 1.6l2.47 5.01 5.53.8-4 3.9.94 5.5L10 14.21 5.06 16.81 6 11.31l-4-3.9 5.53-.8z';
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
<div class:list={['sinn-rating-block', className]} {...rest}>
|
|
87
|
+
<div class="sinn-rating" data-size={size === 'm' ? undefined : size}>
|
|
88
|
+
<svg class="sinn-rating__stars" viewBox={`-1 -1 ${width + 2} ${STAR + 2}`} role="img" aria-label={name}>
|
|
89
|
+
<defs>
|
|
90
|
+
<clipPath id={clipId}>
|
|
91
|
+
<rect x="-1" y="-1" width={clipWidth + 1} height={STAR + 2} />
|
|
92
|
+
</clipPath>
|
|
93
|
+
</defs>
|
|
94
|
+
<g class="sinn-rating__empty">
|
|
95
|
+
{stars.map((x) => <path d={starPath} transform={`translate(${x} 0)`} />)}
|
|
96
|
+
</g>
|
|
97
|
+
<g class="sinn-rating__filled" clip-path={`url(#${clipId})`}>
|
|
98
|
+
{stars.map((x) => <path d={starPath} transform={`translate(${x} 0)`} />)}
|
|
99
|
+
</g>
|
|
100
|
+
</svg>
|
|
101
|
+
{showValue && <span class="sinn-rating__value" aria-hidden="true">{shown}</span>}
|
|
102
|
+
{
|
|
103
|
+
countText &&
|
|
104
|
+
(countHref ? (
|
|
105
|
+
<a class="sinn-rating__count" href={countHref}>
|
|
106
|
+
{countText}
|
|
107
|
+
</a>
|
|
108
|
+
) : (
|
|
109
|
+
<span class="sinn-rating__count">({countText})</span>
|
|
110
|
+
))
|
|
111
|
+
}
|
|
112
|
+
</div>
|
|
113
|
+
{
|
|
114
|
+
dist.length > 0 && (
|
|
115
|
+
<ul role="list" class="sinn-rating-dist" aria-label="Rating breakdown">
|
|
116
|
+
{dist.map((d) => (
|
|
117
|
+
<li class="sinn-rating-dist__row">
|
|
118
|
+
<span class="sinn-rating-dist__label">
|
|
119
|
+
{d.level}
|
|
120
|
+
<svg viewBox="0 0 20 20" aria-hidden="true" focusable="false">
|
|
121
|
+
<path d={smallStar} class="sinn-rating__filled" />
|
|
122
|
+
</svg>
|
|
123
|
+
<span class="sinn-sr-only">{d.level === 1 ? 'star' : 'stars'}:</span>
|
|
124
|
+
</span>
|
|
125
|
+
<span class="sinn-bar" data-pct={d.pct} aria-hidden="true" />
|
|
126
|
+
<span class="sinn-rating-dist__figure">
|
|
127
|
+
{d.shareText}
|
|
128
|
+
<span class="sinn-sr-only">, {d.countText}</span>
|
|
129
|
+
</span>
|
|
130
|
+
</li>
|
|
131
|
+
))}
|
|
132
|
+
</ul>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
</div>
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* ReducedMotion — wraps moving content (background video, animated illustration, Lottie,
|
|
4
|
+
* marquee, auto-advancing carousel) so it respects the user's reduced-motion preference.
|
|
5
|
+
*
|
|
6
|
+
* - Default slot: the moving version. `still` slot: a static alternative shown instead when
|
|
7
|
+
* motion is reduced (a poster image, a screenshot). Swapped with CSS, so it's right on first
|
|
8
|
+
* paint with no script.
|
|
9
|
+
* - Without a `still` alternative, the motion is paused instead (videos stopped, CSS and Web
|
|
10
|
+
* Animations frozen).
|
|
11
|
+
* - Videos: use `data-autoplay muted playsinline loop` instead of `autoplay`; they start only
|
|
12
|
+
* when motion is allowed, so reduced-motion users never see them begin.
|
|
13
|
+
* - `controls`: a Pause/Play button. Anything that moves for more than 5 seconds needs one
|
|
14
|
+
* (WCAG 2.2.2 Pause, Stop, Hide); a user's pause sticks.
|
|
15
|
+
*
|
|
16
|
+
* The preference is the OS setting, or the site's own switch via <html data-motion="reduce|full">
|
|
17
|
+
* (setMotionPreference from `@sinnstack/ui/primitives/motion`). Library components already follow
|
|
18
|
+
* the same preference through the --sinn-motion-scale and duration tokens.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* <ReducedMotion controls>
|
|
22
|
+
* <video data-autoplay muted playsinline loop preload="none" poster={poster.src} src="/media/hero.mp4" aria-hidden="true"></video>
|
|
23
|
+
* <Image slot="still" src={poster} alt="" layout="full" aspect="21/9" />
|
|
24
|
+
* </ReducedMotion>
|
|
25
|
+
*/
|
|
26
|
+
import type { HTMLAttributes, HTMLTag } from 'astro/types';
|
|
27
|
+
import ReducedMotionScript from './internal/ReducedMotionScript.astro';
|
|
28
|
+
import './styles/utilities.css';
|
|
29
|
+
import './styles/button.css';
|
|
30
|
+
import './styles/a11y.css';
|
|
31
|
+
|
|
32
|
+
type Props = HTMLAttributes<'div'> & {
|
|
33
|
+
as?: HTMLTag;
|
|
34
|
+
/** Show a Pause/Play button for the moving content. */
|
|
35
|
+
controls?: boolean;
|
|
36
|
+
/** Button over the content (bottom corner) or below it. */
|
|
37
|
+
controlsPosition?: 'overlay' | 'below';
|
|
38
|
+
pauseLabel?: string;
|
|
39
|
+
playLabel?: string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
as: Tag = 'div',
|
|
44
|
+
controls = false,
|
|
45
|
+
controlsPosition = 'overlay',
|
|
46
|
+
pauseLabel = 'Pause animation',
|
|
47
|
+
playLabel = 'Play animation',
|
|
48
|
+
class: className,
|
|
49
|
+
...rest
|
|
50
|
+
} = Astro.props;
|
|
51
|
+
|
|
52
|
+
const hasStill = Astro.slots.has('still');
|
|
53
|
+
const toggleAttrs = { 'data-pause-label': pauseLabel, 'data-play-label': playLabel };
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
<Tag
|
|
57
|
+
class:list={['sinn-motion', className]}
|
|
58
|
+
data-sinn-motion
|
|
59
|
+
data-controls={controls && controlsPosition === 'below' ? 'below' : undefined}
|
|
60
|
+
{...rest}
|
|
61
|
+
>
|
|
62
|
+
<div class="sinn-motion__motion"><slot /></div>
|
|
63
|
+
{hasStill && <div class="sinn-motion__still"><slot name="still" /></div>}
|
|
64
|
+
{
|
|
65
|
+
controls && (
|
|
66
|
+
<button
|
|
67
|
+
type="button"
|
|
68
|
+
class="sinn-button sinn-motion__toggle"
|
|
69
|
+
data-variant="soft"
|
|
70
|
+
data-tone="neutral"
|
|
71
|
+
data-size="s"
|
|
72
|
+
aria-pressed="false"
|
|
73
|
+
data-sinn-motion-toggle
|
|
74
|
+
{...toggleAttrs}
|
|
75
|
+
>
|
|
76
|
+
<span class="sinn-button__content">
|
|
77
|
+
<svg class="sinn-motion__toggle-icon-pause" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
|
78
|
+
<rect x="3.5" y="2.5" width="3" height="11" rx="1" />
|
|
79
|
+
<rect x="9.5" y="2.5" width="3" height="11" rx="1" />
|
|
80
|
+
</svg>
|
|
81
|
+
<svg class="sinn-motion__toggle-icon-play" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
|
|
82
|
+
<path d="M4 2.5v11l9-5.5z" />
|
|
83
|
+
</svg>
|
|
84
|
+
<span data-label>{pauseLabel}</span>
|
|
85
|
+
</span>
|
|
86
|
+
</button>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
</Tag>
|
|
90
|
+
<ReducedMotionScript />
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* SegmentedControl — picks one option from a short set (2–5 is best, 8 at most), shown as
|
|
4
|
+
* joined buttons: a view switch, a billing period, a units toggle.
|
|
5
|
+
*
|
|
6
|
+
* It's a fieldset of native radios, so it submits with forms and works with no JavaScript.
|
|
7
|
+
* Arrow keys move the selection, and screen readers announce "radio button, 2 of 3".
|
|
8
|
+
* With `width="equal"` (default) the highlight slides between segments; `fit` sizes
|
|
9
|
+
* each segment to its label.
|
|
10
|
+
*
|
|
11
|
+
* Use Tabs when the choice switches a block of content on the page, ChoiceGroup + Radio
|
|
12
|
+
* for longer or descriptive options, and Switch for on/off.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <SegmentedControl name="billing" label="Billing period" value="monthly"
|
|
16
|
+
* options={[{ value: 'monthly', label: 'Monthly' }, { value: 'yearly', label: 'Yearly' }]} />
|
|
17
|
+
* <SegmentedControl name="view" label="View" hideLabel iconOnly value="grid"
|
|
18
|
+
* options={[{ value: 'list', label: 'List', icon: listSvg }, { value: 'grid', label: 'Grid', icon: gridSvg }]} />
|
|
19
|
+
*/
|
|
20
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
21
|
+
import type { ControlSize, SegmentOption } from './types';
|
|
22
|
+
import { idList, uid } from './utils';
|
|
23
|
+
import FormDescription from './FormDescription.astro';
|
|
24
|
+
import FormError from './FormError.astro';
|
|
25
|
+
import './styles/utilities.css';
|
|
26
|
+
import './styles/typography.css';
|
|
27
|
+
import './styles/form.css';
|
|
28
|
+
import './styles/segmented.css';
|
|
29
|
+
import { renameProp } from './lib/deprecate';
|
|
30
|
+
|
|
31
|
+
type Props = Omit<HTMLAttributes<'fieldset'>, 'onchange'> & {
|
|
32
|
+
/** Form field name shared by the radios. */
|
|
33
|
+
name: string;
|
|
34
|
+
/** The question the options answer. Rendered as the legend. */
|
|
35
|
+
label: string;
|
|
36
|
+
options: ReadonlyArray<SegmentOption | string>;
|
|
37
|
+
/** The selected value. Leave unset for no initial selection (then add `required`). */
|
|
38
|
+
value?: string;
|
|
39
|
+
/** Keep the label for screen readers only (the context must make the choice obvious). */
|
|
40
|
+
hideLabel?: boolean;
|
|
41
|
+
description?: string;
|
|
42
|
+
error?: string;
|
|
43
|
+
required?: boolean;
|
|
44
|
+
disabled?: boolean;
|
|
45
|
+
size?: ControlSize;
|
|
46
|
+
/** `equal`: every segment the same width, highlight slides. `fit`: each sized to its label. */
|
|
47
|
+
width?: 'equal' | 'fit';
|
|
48
|
+
/** Stretch to the container's width (the name Button, ButtonGroup and Tabs use). */
|
|
49
|
+
fullWidth?: boolean;
|
|
50
|
+
/** @deprecated Use `fullWidth`. */
|
|
51
|
+
block?: boolean;
|
|
52
|
+
/** Show icons only; labels stay as the accessible names (and as tooltips via `title`). */
|
|
53
|
+
iconOnly?: boolean;
|
|
54
|
+
/** Associate with a form elsewhere on the page. */
|
|
55
|
+
form?: string;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const {
|
|
59
|
+
name,
|
|
60
|
+
label,
|
|
61
|
+
options: rawOptions,
|
|
62
|
+
value,
|
|
63
|
+
hideLabel = false,
|
|
64
|
+
description,
|
|
65
|
+
error,
|
|
66
|
+
required = false,
|
|
67
|
+
disabled = false,
|
|
68
|
+
size = 'm',
|
|
69
|
+
width = 'equal',
|
|
70
|
+
fullWidth: fullWidthProp,
|
|
71
|
+
block,
|
|
72
|
+
iconOnly = false,
|
|
73
|
+
form,
|
|
74
|
+
id = uid('sinn-segmented'),
|
|
75
|
+
class: className,
|
|
76
|
+
'aria-describedby': describedBy,
|
|
77
|
+
...rest
|
|
78
|
+
} = Astro.props;
|
|
79
|
+
|
|
80
|
+
const fullWidth = renameProp('SegmentedControl', 'fullWidth', fullWidthProp, 'block', block) ?? false;
|
|
81
|
+
const options = rawOptions.map((o) => (typeof o === 'string' ? { value: o, label: o } : o));
|
|
82
|
+
if (import.meta.env?.DEV) {
|
|
83
|
+
if (options.length < 2) console.warn(`[sinn] SegmentedControl "${name}" needs at least 2 options.`);
|
|
84
|
+
if (options.length > 8) console.warn(`[sinn] SegmentedControl "${name}" has ${options.length} options; past 8, use a Select or Radios.`);
|
|
85
|
+
if (value !== undefined && !options.some((o) => o.value === value))
|
|
86
|
+
console.warn(`[sinn] SegmentedControl "${name}": value "${value}" matches no option.`);
|
|
87
|
+
}
|
|
88
|
+
const descId = description ? `${id}-desc` : undefined;
|
|
89
|
+
const errorId = `${id}-error`;
|
|
90
|
+
const count = Math.min(8, Math.max(2, options.length));
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
<fieldset
|
|
94
|
+
id={id}
|
|
95
|
+
class:list={['sinn-segmented', className]}
|
|
96
|
+
data-size={size}
|
|
97
|
+
data-width={width}
|
|
98
|
+
data-full-width={fullWidth ? '' : undefined}
|
|
99
|
+
data-icon-only={iconOnly ? '' : undefined}
|
|
100
|
+
disabled={disabled || undefined}
|
|
101
|
+
aria-describedby={idList(describedBy as string | undefined, descId, error ? errorId : undefined)}
|
|
102
|
+
{...rest}
|
|
103
|
+
>
|
|
104
|
+
<legend class:list={['sinn-type', 'sinn-label', 'sinn-segmented__legend', { 'sinn-sr-only': hideLabel }]} data-size="s">
|
|
105
|
+
{label}{required && <span class="sinn-label__required" aria-hidden="true">*</span>}
|
|
106
|
+
</legend>
|
|
107
|
+
{description && <FormDescription id={descId}>{description}</FormDescription>}
|
|
108
|
+
<div class="sinn-segmented__track" data-count={count}>
|
|
109
|
+
{
|
|
110
|
+
options.map((o) => (
|
|
111
|
+
<label class="sinn-segmented__option" title={iconOnly ? o.label : undefined}>
|
|
112
|
+
<input
|
|
113
|
+
type="radio"
|
|
114
|
+
class="sinn-segmented__input"
|
|
115
|
+
name={name}
|
|
116
|
+
value={o.value}
|
|
117
|
+
checked={o.value === value}
|
|
118
|
+
disabled={o.disabled || undefined}
|
|
119
|
+
required={required || undefined}
|
|
120
|
+
aria-invalid={error ? 'true' : undefined}
|
|
121
|
+
form={form}
|
|
122
|
+
/>
|
|
123
|
+
<span class="sinn-segmented__content">
|
|
124
|
+
{o.icon && <span class="sinn-segmented__icon" aria-hidden="true" set:html={o.icon} />}
|
|
125
|
+
<span class:list={['sinn-segmented__text', { 'sinn-sr-only': iconOnly && o.icon }]}>{o.label}</span>
|
|
126
|
+
</span>
|
|
127
|
+
</label>
|
|
128
|
+
))
|
|
129
|
+
}
|
|
130
|
+
</div>
|
|
131
|
+
<FormError id={errorId} message={error} />
|
|
132
|
+
</fieldset>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Select — choose from a list. Native `<select>`: keyboard, type-ahead, mobile pickers
|
|
4
|
+
* and screen-reader support come from the platform.
|
|
5
|
+
*
|
|
6
|
+
* Options come from `options` (flat or grouped) and/or `<option>` children.
|
|
7
|
+
* `placeholder` adds an empty first option, so `required` triggers "please select".
|
|
8
|
+
* Long or searchable lists (country pickers, 50+ items) belong in the Zag.js combobox
|
|
9
|
+
* from the widgets package, not here.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <Select name="state" label="State" placeholder="Select a state" required
|
|
13
|
+
* options={[{ value: 'TX', label: 'Texas' }, { value: 'OK', label: 'Oklahoma' }]} value="TX" />
|
|
14
|
+
* <Select name="time" label="Preferred time"
|
|
15
|
+
* options={[{ label: 'Morning', options: [{ value: '9', label: '9:00' }] }]} />
|
|
16
|
+
*/
|
|
17
|
+
import type { HTMLAttributes } from 'astro/types';
|
|
18
|
+
import type { ControlSize, FieldContext, FieldProps, SelectOption, SelectOptionGroup } from './types';
|
|
19
|
+
import { uid } from './utils';
|
|
20
|
+
import FormField from './FormField.astro';
|
|
21
|
+
import './styles/utilities.css';
|
|
22
|
+
import './styles/form.css';
|
|
23
|
+
|
|
24
|
+
type Props = Omit<HTMLAttributes<'select'>, 'size' | 'value'> &
|
|
25
|
+
FieldProps & {
|
|
26
|
+
options?: Array<SelectOption | SelectOptionGroup>;
|
|
27
|
+
/** Selected value(s). An array when `multiple`. */
|
|
28
|
+
value?: string | string[];
|
|
29
|
+
/** Text for an empty first option. */
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
size?: ControlSize;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
label,
|
|
36
|
+
description,
|
|
37
|
+
error,
|
|
38
|
+
hideLabel,
|
|
39
|
+
optional,
|
|
40
|
+
messages,
|
|
41
|
+
options = [],
|
|
42
|
+
value,
|
|
43
|
+
placeholder,
|
|
44
|
+
size = 'm',
|
|
45
|
+
multiple = false,
|
|
46
|
+
id: idProp,
|
|
47
|
+
required = false,
|
|
48
|
+
'aria-describedby': describedBy,
|
|
49
|
+
class: className,
|
|
50
|
+
...rest
|
|
51
|
+
} = Astro.props;
|
|
52
|
+
// `??`, not a default: a default only replaces undefined, and id={null} would give "null-error" ids.
|
|
53
|
+
const id = idProp ?? uid('sinn-select');
|
|
54
|
+
|
|
55
|
+
const wrapped = Boolean(label || description || error);
|
|
56
|
+
// `class` goes on the field wrapper, or on the control itself when there is no wrapper.
|
|
57
|
+
const controlClass = wrapped ? undefined : className;
|
|
58
|
+
const isSelected = (v: string) => (Array.isArray(value) ? value.includes(v) : value === v);
|
|
59
|
+
const hasValue = Array.isArray(value) ? value.length > 0 : value !== undefined && value !== '';
|
|
60
|
+
const isGroup = (o: SelectOption | SelectOptionGroup): o is SelectOptionGroup => 'options' in o;
|
|
61
|
+
const extraOptions = Astro.slots.has('default') ? await Astro.slots.render('default') : '';
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
<FormField
|
|
65
|
+
id={id}
|
|
66
|
+
label={label}
|
|
67
|
+
description={description}
|
|
68
|
+
error={error}
|
|
69
|
+
hideLabel={hideLabel}
|
|
70
|
+
optional={optional}
|
|
71
|
+
required={Boolean(required)}
|
|
72
|
+
messages={messages}
|
|
73
|
+
aria-describedby={describedBy as string | undefined}
|
|
74
|
+
class={className}
|
|
75
|
+
>
|
|
76
|
+
{
|
|
77
|
+
(field: FieldContext) => (
|
|
78
|
+
<div
|
|
79
|
+
class:list={['sinn-select', controlClass]}
|
|
80
|
+
data-multiple={multiple ? '' : undefined}
|
|
81
|
+
>
|
|
82
|
+
{/* `multiple={false}` would render multiple="false" (Astro only drops false for its own boolean list), which browsers treat as a multi-select. */}
|
|
83
|
+
<select class="sinn-control" data-size={size} multiple={multiple || undefined} {...field.attrs} {...rest}>
|
|
84
|
+
{placeholder && !multiple && (
|
|
85
|
+
<option value="" disabled selected={!hasValue}>
|
|
86
|
+
{placeholder}
|
|
87
|
+
</option>
|
|
88
|
+
)}
|
|
89
|
+
{options.map((o) =>
|
|
90
|
+
isGroup(o) ? (
|
|
91
|
+
<optgroup label={o.label} disabled={o.disabled}>
|
|
92
|
+
{o.options.map((opt) => (
|
|
93
|
+
<option value={opt.value} disabled={opt.disabled} selected={isSelected(opt.value)}>
|
|
94
|
+
{opt.label}
|
|
95
|
+
</option>
|
|
96
|
+
))}
|
|
97
|
+
</optgroup>
|
|
98
|
+
) : (
|
|
99
|
+
<option value={o.value} disabled={o.disabled} selected={isSelected(o.value)}>
|
|
100
|
+
{o.label}
|
|
101
|
+
</option>
|
|
102
|
+
),
|
|
103
|
+
)}
|
|
104
|
+
<Fragment set:html={extraOptions} />
|
|
105
|
+
</select>
|
|
106
|
+
</div>
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
</FormField>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* Sheet — an overlay panel attached to an edge, bottom by default: mobile action sheets,
|
|
4
|
+
* quick forms, "share" panels. Up to 85% of the viewport height, scrolls inside, and keeps
|
|
5
|
+
* clear of the iPhone home indicator. Modal, like Dialog (same opening and closing rules).
|
|
6
|
+
*
|
|
7
|
+
* Drawer vs Sheet: a Drawer is a full-height side panel for a whole task area; a Sheet is
|
|
8
|
+
* a lighter panel for a short, focused task, typically from the bottom on phones.
|
|
9
|
+
*
|
|
10
|
+
* - `contained`: on screens 48rem and wider, a bottom sheet becomes a centered column
|
|
11
|
+
* instead of spanning the full width.
|
|
12
|
+
* - The grab handle is visual only; drag-to-dismiss would need JS and isn't included.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <Button commandfor="share" command="show-modal" variant="ghost">Share</Button>
|
|
16
|
+
* <Sheet id="share" title="Share this page" contained>…</Sheet>
|
|
17
|
+
*/
|
|
18
|
+
import type { ModalPanelProps } from './types';
|
|
19
|
+
import ModalPanel from './internal/ModalPanel.astro';
|
|
20
|
+
|
|
21
|
+
type Props = Omit<ModalPanelProps, 'size'> & {
|
|
22
|
+
side?: 'bottom' | 'top' | 'start' | 'end';
|
|
23
|
+
/** Side sheets only: width s 24rem · m 32rem · l 48rem. */
|
|
24
|
+
size?: 's' | 'm' | 'l';
|
|
25
|
+
/** Bottom sheet becomes a centered column on wide screens. */
|
|
26
|
+
contained?: boolean;
|
|
27
|
+
/** Show the grab handle (bottom sheets). */
|
|
28
|
+
handle?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const { side = 'bottom', size = 's', contained = false, handle = side === 'bottom', ...rest } = Astro.props;
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
<ModalPanel
|
|
35
|
+
{...rest}
|
|
36
|
+
size={size}
|
|
37
|
+
placement={side}
|
|
38
|
+
handle={handle}
|
|
39
|
+
contained={contained}
|
|
40
|
+
kindClass="sinn-sheet"
|
|
41
|
+
>
|
|
42
|
+
<slot name="header" slot="header" />
|
|
43
|
+
<slot />
|
|
44
|
+
<slot name="footer" slot="footer" />
|
|
45
|
+
</ModalPanel>
|