maverick-wave-astro 1.27.0 → 1.29.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/components/AllergenLegend.astro +42 -0
- package/components/Allergens.astro +47 -0
- package/components/Bio.astro +115 -0
- package/components/LinkCard.astro +103 -0
- package/components/MenuSheet.astro +99 -0
- package/components/ServiceArea.astro +138 -0
- package/components/Signage.astro +215 -0
- package/components/StoryCards.astro +171 -10
- package/components/ValueList.astro +10 -1
- package/dist/allergens.d.ts +76 -0
- package/dist/allergens.js +36 -0
- package/dist/bio.d.ts +53 -0
- package/dist/bio.js +45 -0
- package/dist/content.d.ts +1 -0
- package/dist/content.js +1 -0
- package/dist/date.d.ts +8 -0
- package/dist/date.js +21 -0
- package/dist/hours.d.ts +14 -0
- package/dist/hours.js +42 -5
- package/dist/service-area.d.ts +13 -0
- package/dist/service-area.js +62 -0
- package/dist/signage.d.ts +66 -0
- package/dist/signage.js +107 -0
- package/dist/story/caption.d.ts +39 -0
- package/dist/story/caption.js +126 -0
- package/dist/story/cards.d.ts +8 -0
- package/dist/story/cards.js +12 -3
- package/dist/werkbank.js +2 -1
- package/package.json +3 -3
- package/schemas/allergens.field.json +41 -0
- package/schemas/bio.schema.json +159 -0
- package/schemas/service-area.schema.json +58 -0
- package/schemas/signage.schema.json +100 -0
- package/schemas/story-blocks.schema.json +11 -0
- package/schemas/story-look.schema.json +24 -0
- package/styles/allergens.css +48 -0
- package/styles/menu-sheet.css +75 -0
- package/styles/service-area.css +31 -0
- package/styles/signage.css +251 -0
- package/styles/story-cards.css +50 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
// What the letters at the dishes mean. Given the allergens of every dish, it
|
|
3
|
+
// names only those that occur; without, all fourteen.
|
|
4
|
+
import '../styles/allergens.css';
|
|
5
|
+
|
|
6
|
+
import { allergenName, ALLERGENS, usedAllergens } from '../dist/allergens.js';
|
|
7
|
+
import { siteLocale } from '../dist/config.js';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
// One list per dish, as the werkbank stores them.
|
|
11
|
+
used?: readonly (readonly string[] | undefined)[];
|
|
12
|
+
// Above the legend, e.g. "Allergene".
|
|
13
|
+
title?: string;
|
|
14
|
+
locale?: string;
|
|
15
|
+
class?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const { used, title, locale = siteLocale, class: className } = Astro.props;
|
|
19
|
+
|
|
20
|
+
const list = used ? usedAllergens(used) : ALLERGENS;
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
{
|
|
24
|
+
list.length > 0 && (
|
|
25
|
+
<div class={className}>
|
|
26
|
+
{title && <p class="mw-text-sm mw-text-bold mw-mb-2">{title}</p>}
|
|
27
|
+
<dl class="mwa-allergen-legend">
|
|
28
|
+
{list.map(allergen => (
|
|
29
|
+
<div>
|
|
30
|
+
<dt>
|
|
31
|
+
<span class="mwa-allergen" aria-hidden="true">
|
|
32
|
+
{allergen.code}
|
|
33
|
+
</span>
|
|
34
|
+
<span class="mw-sr-only">{allergen.code}</span>
|
|
35
|
+
</dt>
|
|
36
|
+
<dd>{allergenName(allergen, locale)}</dd>
|
|
37
|
+
</div>
|
|
38
|
+
))}
|
|
39
|
+
</dl>
|
|
40
|
+
</div>
|
|
41
|
+
)
|
|
42
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The allergens of one dish as letters, read out by name for screen readers.
|
|
3
|
+
// Their meaning stands in the AllergenLegend below the menu.
|
|
4
|
+
import '../styles/allergens.css';
|
|
5
|
+
|
|
6
|
+
import { allergenName, allergensOf } from '../dist/allergens.js';
|
|
7
|
+
import { siteLocale } from '../dist/config.js';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
// Ids of schemas/allergens.field.json, in any order.
|
|
11
|
+
allergens?: readonly string[];
|
|
12
|
+
// The page's language on a site with several.
|
|
13
|
+
locale?: string;
|
|
14
|
+
// Read before the names: "Allergene: Eier, Milch".
|
|
15
|
+
label?: string;
|
|
16
|
+
class?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const {
|
|
20
|
+
allergens,
|
|
21
|
+
locale = siteLocale,
|
|
22
|
+
label = locale.startsWith('de') ? 'Allergene' : 'Allergens',
|
|
23
|
+
class: className,
|
|
24
|
+
} = Astro.props;
|
|
25
|
+
|
|
26
|
+
const list = allergensOf(allergens);
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
{
|
|
30
|
+
list.length > 0 && (
|
|
31
|
+
<span class:list={['mwa-allergens', className]}>
|
|
32
|
+
<span class="mw-sr-only">
|
|
33
|
+
{label}:{' '}
|
|
34
|
+
{list.map(allergen => allergenName(allergen, locale)).join(', ')}
|
|
35
|
+
</span>
|
|
36
|
+
{list.map(allergen => (
|
|
37
|
+
<abbr
|
|
38
|
+
class="mwa-allergen"
|
|
39
|
+
title={allergenName(allergen, locale)}
|
|
40
|
+
aria-hidden="true"
|
|
41
|
+
>
|
|
42
|
+
{allergen.code}
|
|
43
|
+
</abbr>
|
|
44
|
+
))}
|
|
45
|
+
</span>
|
|
46
|
+
)
|
|
47
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The link page behind a profile: who this is, then one card per link with the
|
|
3
|
+
// imprint always last. The only section of its page, under the site's own
|
|
4
|
+
// header with the way back to the start.
|
|
5
|
+
import { bioHref, type BioLink, isUpload } from '../dist/bio.js';
|
|
6
|
+
import { config } from '../dist/config.js';
|
|
7
|
+
import { withBase } from '../dist/path.js';
|
|
8
|
+
import { SOCIAL_ICONS } from '../dist/social.js';
|
|
9
|
+
import LinkCard from './LinkCard.astro';
|
|
10
|
+
import Picture from './Picture.astro';
|
|
11
|
+
import type { SocialLink } from './SocialLinks.astro';
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
name: string;
|
|
15
|
+
// A werkbank upload without extension, or a file from public/ with one
|
|
16
|
+
avatar?: string;
|
|
17
|
+
tagline?: string;
|
|
18
|
+
// What is true today - free places, back from holiday on the 3rd
|
|
19
|
+
status?: string;
|
|
20
|
+
links: readonly BioLink[];
|
|
21
|
+
socials?: readonly SocialLink[];
|
|
22
|
+
linksLabel?: string;
|
|
23
|
+
imprintLabel?: string;
|
|
24
|
+
imprintHref?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const german = config.site.lang.startsWith('de');
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
name,
|
|
31
|
+
avatar,
|
|
32
|
+
tagline,
|
|
33
|
+
status,
|
|
34
|
+
links,
|
|
35
|
+
socials = [],
|
|
36
|
+
linksLabel = 'Links',
|
|
37
|
+
imprintLabel = german ? 'Impressum' : 'Imprint',
|
|
38
|
+
imprintHref = withBase('/impressum'),
|
|
39
|
+
} = Astro.props;
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
<section class="mw-section mw-bio">
|
|
43
|
+
<div class="mw-container">
|
|
44
|
+
<div class="mw-bio-head">
|
|
45
|
+
{
|
|
46
|
+
avatar && (
|
|
47
|
+
<div class="mw-bio-avatar">
|
|
48
|
+
{isUpload(avatar) ? (
|
|
49
|
+
<Picture src={avatar} alt="" sizes="104px" widths={[260]} eager />
|
|
50
|
+
) : (
|
|
51
|
+
<img src={withBase(avatar)} alt="" width="104" height="104" />
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
<h1 class="mw-bio-name">{name}</h1>
|
|
57
|
+
{tagline && <p class="mw-bio-tagline">{tagline}</p>}
|
|
58
|
+
{status && <p class="mw-bio-status">{status}</p>}
|
|
59
|
+
{
|
|
60
|
+
socials.length > 0 && (
|
|
61
|
+
<ul class="mw-bio-socials">
|
|
62
|
+
{socials.map(social => {
|
|
63
|
+
const icon = SOCIAL_ICONS[social.type];
|
|
64
|
+
const external = /^https?:/.test(social.href);
|
|
65
|
+
return (
|
|
66
|
+
<li>
|
|
67
|
+
<a
|
|
68
|
+
class="mw-bio-social"
|
|
69
|
+
href={social.href}
|
|
70
|
+
aria-label={social.label}
|
|
71
|
+
target={external ? '_blank' : undefined}
|
|
72
|
+
rel={external ? 'noopener noreferrer' : undefined}
|
|
73
|
+
>
|
|
74
|
+
<svg
|
|
75
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
76
|
+
viewBox={icon.viewBox}
|
|
77
|
+
width="1em"
|
|
78
|
+
height="1em"
|
|
79
|
+
fill="currentColor"
|
|
80
|
+
aria-hidden="true"
|
|
81
|
+
focusable="false"
|
|
82
|
+
set:html={icon.body}
|
|
83
|
+
/>
|
|
84
|
+
</a>
|
|
85
|
+
</li>
|
|
86
|
+
);
|
|
87
|
+
})}
|
|
88
|
+
</ul>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<nav class="mw-bio-links" aria-label={linksLabel}>
|
|
94
|
+
{
|
|
95
|
+
links.map(link => (
|
|
96
|
+
<>
|
|
97
|
+
{link.heading && <p class="mw-bio-label">{link.heading}</p>}
|
|
98
|
+
<LinkCard
|
|
99
|
+
href={bioHref(link.href)}
|
|
100
|
+
title={link.title}
|
|
101
|
+
subtitle={link.subtitle}
|
|
102
|
+
kicker={link.highlight ? link.kicker : undefined}
|
|
103
|
+
media={link.media}
|
|
104
|
+
icon={link.icon}
|
|
105
|
+
image={link.image}
|
|
106
|
+
featured={link.highlight}
|
|
107
|
+
/>
|
|
108
|
+
</>
|
|
109
|
+
))
|
|
110
|
+
}
|
|
111
|
+
<slot />
|
|
112
|
+
<LinkCard href={imprintHref} title={imprintLabel} quiet />
|
|
113
|
+
</nav>
|
|
114
|
+
</div>
|
|
115
|
+
</section>
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
---
|
|
2
|
+
// One link as a card. In front an icon, a logo or a small photo, or a wide
|
|
3
|
+
// photo above the text; a title alone sits centred, a second line ranges left.
|
|
4
|
+
import {
|
|
5
|
+
isExternal,
|
|
6
|
+
isUpload,
|
|
7
|
+
LINK_ICONS,
|
|
8
|
+
type LinkIcon,
|
|
9
|
+
type LinkMedia,
|
|
10
|
+
} from '../dist/bio.js';
|
|
11
|
+
import { config } from '../dist/config.js';
|
|
12
|
+
import { withBase } from '../dist/path.js';
|
|
13
|
+
import Icon from './Icon.astro';
|
|
14
|
+
import Picture from './Picture.astro';
|
|
15
|
+
|
|
16
|
+
interface Props {
|
|
17
|
+
href: string;
|
|
18
|
+
title: string;
|
|
19
|
+
subtitle?: string;
|
|
20
|
+
kicker?: string;
|
|
21
|
+
media?: LinkMedia;
|
|
22
|
+
icon?: LinkIcon;
|
|
23
|
+
// A werkbank upload without extension, or a file from public/ with one
|
|
24
|
+
image?: string;
|
|
25
|
+
// The one link that matters most - one per page
|
|
26
|
+
featured?: boolean;
|
|
27
|
+
// The imprint at the bottom: flat, still at full contrast
|
|
28
|
+
quiet?: boolean;
|
|
29
|
+
newTabLabel?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const german = config.site.lang.startsWith('de');
|
|
33
|
+
|
|
34
|
+
const {
|
|
35
|
+
href,
|
|
36
|
+
title,
|
|
37
|
+
subtitle,
|
|
38
|
+
kicker,
|
|
39
|
+
media,
|
|
40
|
+
icon,
|
|
41
|
+
image,
|
|
42
|
+
featured = false,
|
|
43
|
+
quiet = false,
|
|
44
|
+
newTabLabel = german ? '(öffnet einen neuen Tab)' : '(opens in a new tab)',
|
|
45
|
+
} = Astro.props;
|
|
46
|
+
|
|
47
|
+
const external = isExternal(href);
|
|
48
|
+
const glyph = media === 'icon' && icon ? LINK_ICONS[icon] : undefined;
|
|
49
|
+
const cover = media === 'cover' ? image : undefined;
|
|
50
|
+
const thumb = media === 'logo' || media === 'photo' ? image : undefined;
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
<a
|
|
54
|
+
class:list={[
|
|
55
|
+
'mw-card mw-card-link',
|
|
56
|
+
featured && 'mw-card-link-featured',
|
|
57
|
+
quiet && 'mw-card-link-quiet',
|
|
58
|
+
]}
|
|
59
|
+
href={href}
|
|
60
|
+
target={external ? '_blank' : undefined}
|
|
61
|
+
rel={external ? 'noopener' : undefined}
|
|
62
|
+
>
|
|
63
|
+
{
|
|
64
|
+
cover && (
|
|
65
|
+
<span class="mw-card-link-cover">
|
|
66
|
+
{isUpload(cover) ? (
|
|
67
|
+
<Picture
|
|
68
|
+
src={cover}
|
|
69
|
+
alt=""
|
|
70
|
+
sizes="(width >= 30rem) 30rem, 100vw"
|
|
71
|
+
widths={[500, 1000]}
|
|
72
|
+
/>
|
|
73
|
+
) : (
|
|
74
|
+
<img src={withBase(cover)} alt="" loading="lazy" />
|
|
75
|
+
)}
|
|
76
|
+
</span>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
{
|
|
80
|
+
glyph && (
|
|
81
|
+
<span class="mw-card-link-media">
|
|
82
|
+
<Icon svg={glyph} size={22} />
|
|
83
|
+
</span>
|
|
84
|
+
)
|
|
85
|
+
}
|
|
86
|
+
{
|
|
87
|
+
thumb && (
|
|
88
|
+
<span class={`mw-card-link-media mw-card-link-media-${media}`}>
|
|
89
|
+
{isUpload(thumb) ? (
|
|
90
|
+
<Picture src={thumb} alt="" sizes="56px" widths={[260]} />
|
|
91
|
+
) : (
|
|
92
|
+
<img src={withBase(thumb)} alt="" loading="lazy" />
|
|
93
|
+
)}
|
|
94
|
+
</span>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
<span class="mw-card-link-body">
|
|
98
|
+
{kicker && <span class="mw-card-link-kicker">{kicker}</span>}
|
|
99
|
+
<span class="mw-card-link-title">{title}</span>
|
|
100
|
+
{subtitle && <span class="mw-card-link-subtitle">{subtitle}</span>}
|
|
101
|
+
{external && <span class="mw-sr-only">{newTabLabel}</span>}
|
|
102
|
+
</span>
|
|
103
|
+
</a>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
// The menu on one page for paper: the browser prints it or saves it as a PDF,
|
|
3
|
+
// no file to keep up to date next to the site. Meant for a page of its own
|
|
4
|
+
// with noIndex, bare in BaseLayout. The button stays off the paper.
|
|
5
|
+
import '../styles/menu-sheet.css';
|
|
6
|
+
|
|
7
|
+
import { config, siteLocale } from '../dist/config.js';
|
|
8
|
+
import AllergenLegend from './AllergenLegend.astro';
|
|
9
|
+
import ValueList from './ValueList.astro';
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
title: string;
|
|
13
|
+
// Under the title, e.g. the name and address of the place.
|
|
14
|
+
subtitle?: string;
|
|
15
|
+
intro?: string;
|
|
16
|
+
groups: readonly {
|
|
17
|
+
title: string;
|
|
18
|
+
items: readonly {
|
|
19
|
+
name: string;
|
|
20
|
+
description?: string;
|
|
21
|
+
// Already formatted, "12,50 €".
|
|
22
|
+
price?: string;
|
|
23
|
+
allergens?: readonly string[];
|
|
24
|
+
}[];
|
|
25
|
+
}[];
|
|
26
|
+
// Below the dishes, e.g. "Alle Preise inklusive Mehrwertsteuer".
|
|
27
|
+
note?: string;
|
|
28
|
+
legendTitle?: string;
|
|
29
|
+
printLabel?: string;
|
|
30
|
+
locale?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const german = config.site.lang.startsWith('de');
|
|
34
|
+
|
|
35
|
+
const {
|
|
36
|
+
title,
|
|
37
|
+
subtitle,
|
|
38
|
+
intro,
|
|
39
|
+
groups,
|
|
40
|
+
note,
|
|
41
|
+
legendTitle = german ? 'Allergene' : 'Allergens',
|
|
42
|
+
printLabel = german
|
|
43
|
+
? 'Drucken oder als PDF speichern'
|
|
44
|
+
: 'Print or save as PDF',
|
|
45
|
+
locale = siteLocale,
|
|
46
|
+
} = Astro.props;
|
|
47
|
+
|
|
48
|
+
const shown = groups.filter(group => group.items.length > 0);
|
|
49
|
+
const used = shown.flatMap(group => group.items.map(item => item.allergens));
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
<div class="mwa-menu-sheet">
|
|
53
|
+
<div class="mwa-menu-sheet-toolbar">
|
|
54
|
+
<button type="button" class="mw-btn mw-btn-primary" data-menu-sheet-print>
|
|
55
|
+
{printLabel}
|
|
56
|
+
</button>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<header class="mwa-menu-sheet-head">
|
|
60
|
+
<h1 class="mwa-menu-sheet-title">{title}</h1>
|
|
61
|
+
{subtitle && <p class="mw-text-muted mw-m-0">{subtitle}</p>}
|
|
62
|
+
{intro && <p class="mwa-menu-sheet-intro">{intro}</p>}
|
|
63
|
+
</header>
|
|
64
|
+
|
|
65
|
+
{
|
|
66
|
+
shown.map(group => (
|
|
67
|
+
<section class="mwa-menu-sheet-group">
|
|
68
|
+
<h2 class="mwa-menu-sheet-group-title">{group.title}</h2>
|
|
69
|
+
<ValueList
|
|
70
|
+
top
|
|
71
|
+
locale={locale}
|
|
72
|
+
items={group.items.map(item => ({
|
|
73
|
+
label: item.name,
|
|
74
|
+
note: item.description,
|
|
75
|
+
allergens: item.allergens,
|
|
76
|
+
value: item.price ?? '',
|
|
77
|
+
}))}
|
|
78
|
+
/>
|
|
79
|
+
</section>
|
|
80
|
+
))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
{note && <p class="mwa-menu-sheet-note">{note}</p>}
|
|
84
|
+
|
|
85
|
+
<AllergenLegend
|
|
86
|
+
class="mwa-menu-sheet-legend"
|
|
87
|
+
used={used}
|
|
88
|
+
title={legendTitle}
|
|
89
|
+
locale={locale}
|
|
90
|
+
/>
|
|
91
|
+
</div>
|
|
92
|
+
|
|
93
|
+
<script>
|
|
94
|
+
for (const button of document.querySelectorAll<HTMLButtonElement>(
|
|
95
|
+
'[data-menu-sheet-print]'
|
|
96
|
+
)) {
|
|
97
|
+
button.addEventListener('click', () => print());
|
|
98
|
+
}
|
|
99
|
+
</script>
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
---
|
|
2
|
+
// "Do you come to me?" answered on the spot: the visitor types a postcode, the
|
|
3
|
+
// page says yes or no - nothing is sent anywhere. The area comes from the
|
|
4
|
+
// werkbank (schemas/service-area.schema.json) as the owner typed it.
|
|
5
|
+
import '../styles/service-area.css';
|
|
6
|
+
|
|
7
|
+
import { config } from '../dist/config.js';
|
|
8
|
+
import { parsePostcodes, serializeRanges } from '../dist/service-area.js';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
postcodes: string;
|
|
12
|
+
inside?: string;
|
|
13
|
+
outside?: string;
|
|
14
|
+
// Below either answer, e.g. "Knapp daneben? Ruf an."
|
|
15
|
+
note?: string;
|
|
16
|
+
label?: string;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
button?: string;
|
|
19
|
+
invalid?: string;
|
|
20
|
+
// One per page is the usual case - a second one needs its own.
|
|
21
|
+
id?: string;
|
|
22
|
+
class?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const german = config.site.lang.startsWith('de');
|
|
26
|
+
|
|
27
|
+
const {
|
|
28
|
+
postcodes,
|
|
29
|
+
inside,
|
|
30
|
+
outside,
|
|
31
|
+
note,
|
|
32
|
+
label = german ? 'Deine Postleitzahl' : 'Your postcode',
|
|
33
|
+
placeholder = german ? 'z. B. 73240' : 'e.g. 73240',
|
|
34
|
+
button = german ? 'Prüfen' : 'Check',
|
|
35
|
+
invalid = german
|
|
36
|
+
? 'Bitte gib eine Postleitzahl mit fünf Ziffern ein.'
|
|
37
|
+
: 'Please enter a postcode with five digits.',
|
|
38
|
+
id = 'mwa-service-area-postcode',
|
|
39
|
+
class: className,
|
|
40
|
+
} = Astro.props;
|
|
41
|
+
|
|
42
|
+
const { ranges, invalid: unread } = parsePostcodes(postcodes);
|
|
43
|
+
if (unread.length > 0) {
|
|
44
|
+
console.warn(`ServiceArea: not a postcode, left out: ${unread.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
<form
|
|
49
|
+
class:list={['mwa-service-area', className]}
|
|
50
|
+
data-service-area={serializeRanges(ranges)}
|
|
51
|
+
data-inside={inside?.trim() ||
|
|
52
|
+
(german ? 'Wir kommen zu dir.' : 'We come to you.')}
|
|
53
|
+
data-outside={outside?.trim() ||
|
|
54
|
+
(german
|
|
55
|
+
? 'Leider außerhalb unseres Gebiets.'
|
|
56
|
+
: 'Sorry, that is outside our area.')}
|
|
57
|
+
data-invalid={invalid}
|
|
58
|
+
novalidate
|
|
59
|
+
>
|
|
60
|
+
<label class="mwa-service-area-label" for={id}>{label}</label>
|
|
61
|
+
<div class="mwa-service-area-row">
|
|
62
|
+
<input
|
|
63
|
+
id={id}
|
|
64
|
+
class="mw-input"
|
|
65
|
+
type="text"
|
|
66
|
+
inputmode="numeric"
|
|
67
|
+
autocomplete="postal-code"
|
|
68
|
+
maxlength="5"
|
|
69
|
+
placeholder={placeholder}
|
|
70
|
+
data-service-area-input
|
|
71
|
+
/>
|
|
72
|
+
<button type="submit" class="mw-btn mw-btn-primary">{button}</button>
|
|
73
|
+
</div>
|
|
74
|
+
<div
|
|
75
|
+
class="mwa-service-area-answer"
|
|
76
|
+
aria-live="polite"
|
|
77
|
+
data-service-area-answer
|
|
78
|
+
>
|
|
79
|
+
</div>
|
|
80
|
+
{
|
|
81
|
+
note?.trim() && (
|
|
82
|
+
<p class="mwa-service-area-note" hidden data-service-area-note>
|
|
83
|
+
{note}
|
|
84
|
+
</p>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
</form>
|
|
88
|
+
|
|
89
|
+
<script>
|
|
90
|
+
import { checkPostcode, readRanges } from '../dist/service-area.js';
|
|
91
|
+
|
|
92
|
+
const TONES = {
|
|
93
|
+
inside: 'mw-alert-success',
|
|
94
|
+
outside: 'mw-alert-warning',
|
|
95
|
+
invalid: 'mw-alert-danger',
|
|
96
|
+
} as const;
|
|
97
|
+
|
|
98
|
+
for (const form of document.querySelectorAll<HTMLFormElement>(
|
|
99
|
+
'[data-service-area]'
|
|
100
|
+
)) {
|
|
101
|
+
const ranges = readRanges(form.dataset.serviceArea ?? '');
|
|
102
|
+
const input = form.querySelector<HTMLInputElement>(
|
|
103
|
+
'[data-service-area-input]'
|
|
104
|
+
);
|
|
105
|
+
const answer = form.querySelector<HTMLElement>(
|
|
106
|
+
'[data-service-area-answer]'
|
|
107
|
+
);
|
|
108
|
+
const note = form.querySelector<HTMLElement>('[data-service-area-note]');
|
|
109
|
+
if (!input || !answer) continue;
|
|
110
|
+
|
|
111
|
+
const show = (complete: boolean) => {
|
|
112
|
+
const value = input.value.trim();
|
|
113
|
+
const result = checkPostcode(ranges, value);
|
|
114
|
+
// While typing, only a full postcode gets an answer - "7" is no mistake yet.
|
|
115
|
+
if (!complete && result === 'invalid') {
|
|
116
|
+
answer.replaceChildren();
|
|
117
|
+
if (note) note.hidden = true;
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const box = document.createElement('div');
|
|
121
|
+
box.className = `mw-alert ${TONES[result]}`;
|
|
122
|
+
const content = document.createElement('div');
|
|
123
|
+
content.className = 'mw-alert-content';
|
|
124
|
+
const text = document.createElement('p');
|
|
125
|
+
text.textContent = form.dataset[result] ?? '';
|
|
126
|
+
content.append(text);
|
|
127
|
+
box.append(content);
|
|
128
|
+
answer.replaceChildren(box);
|
|
129
|
+
if (note) note.hidden = result === 'invalid';
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
input.addEventListener('input', () => show(false));
|
|
133
|
+
form.addEventListener('submit', event => {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
show(true);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
</script>
|