@atelic-action/ui 8.4.0 → 8.6.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/README.md +65 -5
- package/dist/lib/contactLinks.d.ts +31 -0
- package/dist/lib/contactLinks.js +55 -0
- package/dist/scripts/check-contacts.d.ts +17 -0
- package/dist/scripts/check-contacts.js +162 -0
- package/package.json +10 -13
- package/src/chrome/Footer.tsx +4 -3
- package/src/chrome/SiteHeader.tsx +7 -6
- package/src/chrome/SiteMenu.tsx +11 -9
- package/src/chrome/StickyCTABar.tsx +5 -3
- package/src/components/GateLogin.tsx +2 -1
- package/src/components/MultiSelect.tsx +225 -0
- package/src/components/index.ts +1 -0
- package/src/lib/contactForm.ts +184 -0
- package/src/lib/contactLinks.ts +57 -0
- package/src/lib/googlePlaces.ts +392 -0
- package/src/lib/latestOnly.ts +47 -0
- package/src/primitives/AddressSearch.tsx +440 -0
- package/src/primitives/EmailLink.tsx +55 -0
- package/src/primitives/ExpandableText.tsx +161 -0
- package/src/primitives/GoogleMapsAttribution.tsx +14 -0
- package/src/primitives/PhoneLink.tsx +73 -0
- package/src/primitives/index.ts +18 -0
- package/src/scripts/check-base-path.ts +15 -0
- package/src/scripts/check-contacts.ts +177 -0
- package/src/sections/ContactForm.tsx +685 -87
- package/src/sections/ContactInfoCard.tsx +20 -5
- package/src/sections/ContactSection.tsx +72 -0
- package/src/sections/InfoRows.tsx +103 -0
- package/src/sections/LocationSection.tsx +5 -2
- package/src/sections/Locations.tsx +3 -2
- package/src/sections/PageHero.tsx +22 -5
- package/src/sections/index.ts +24 -1
- package/src/styles/components.css +123 -0
- package/src/styles/defaults.css +42 -1
- package/src/styles/fields.css +33 -0
- package/src/styles/primitives.css +172 -0
- package/src/styles/sections.css +350 -19
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type AnchorHTMLAttributes, isValidElement, type ReactNode } from "react";
|
|
2
|
+
import { dialable, toE164 } from "../lib/contactLinks";
|
|
3
|
+
import type { Phone } from "../types";
|
|
4
|
+
|
|
5
|
+
export interface PhoneLinkProps
|
|
6
|
+
extends Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "target" | "children"> {
|
|
7
|
+
/**
|
|
8
|
+
* The number: the site's phone (`e164` and `display`), or a number as a
|
|
9
|
+
* visitor typed it, which is read into E.164 (`toE164`).
|
|
10
|
+
*/
|
|
11
|
+
phone: Pick<Phone, "e164" | "display"> | string;
|
|
12
|
+
/** The visible words; the number as displayed, or as typed, when left out. */
|
|
13
|
+
children?: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const warned = new Set<string>();
|
|
17
|
+
|
|
18
|
+
/** Says once, in development only, that a number was left unlinked. */
|
|
19
|
+
function warnOnce(number: string) {
|
|
20
|
+
if (!import.meta.env?.DEV || warned.has(number)) return;
|
|
21
|
+
warned.add(number);
|
|
22
|
+
console.warn(`[atelic-ui] "${number}" is not a number to dial; it is shown without a tel: link.`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Whether a value holds a digit to dial. */
|
|
26
|
+
const hasDigits = (value: string) => /\d/.test(value);
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The `tel:` href for a number, the one place it is built. A configured
|
|
30
|
+
* phone links its `e164` exactly as given, as every link drew it before
|
|
31
|
+
* 8.5.0: the browser is never stricter than it was, and a loose `e164` is
|
|
32
|
+
* the build guard's to catch (`contactProblems`). A typed number is read
|
|
33
|
+
* into E.164 (`toE164`), or failing that dials what a dialer can take
|
|
34
|
+
* (`dialable`: the digits, a typed + kept, an extension dropped). Either
|
|
35
|
+
* with no digit at all has no href (8.6.0), so nothing draws a call that
|
|
36
|
+
* dials nothing.
|
|
37
|
+
*/
|
|
38
|
+
export function phoneHref(phone: Pick<Phone, "e164"> | string): string | undefined {
|
|
39
|
+
if (typeof phone !== "string") {
|
|
40
|
+
return hasDigits(phone.e164 ?? "") ? `tel:${phone.e164}` : undefined;
|
|
41
|
+
}
|
|
42
|
+
const number = toE164(phone) ?? dialable(phone);
|
|
43
|
+
return number ? `tel:${number}` : undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The words a node shows, gathered through its elements; an icon alone shows none. */
|
|
47
|
+
function textOf(node: ReactNode): string {
|
|
48
|
+
if (typeof node === "string" || typeof node === "number") return String(node);
|
|
49
|
+
if (Array.isArray(node)) return node.map(textOf).join("");
|
|
50
|
+
if (isValidElement<{ children?: ReactNode }>(node)) return textOf(node.props.children);
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* A phone number as a link that dials it (Component Rules 17), the one way
|
|
56
|
+
* the package draws one. It never opens a new tab (Component Rules 12). Its
|
|
57
|
+
* href is `phoneHref`'s. A number with no digit to dial is shown as plain
|
|
58
|
+
* words rather than a dead link, with a warning in development, and as
|
|
59
|
+
* nothing at all when it has no words to show (an icon alone).
|
|
60
|
+
*/
|
|
61
|
+
export function PhoneLink({ phone, children, className, ...anchor }: PhoneLinkProps) {
|
|
62
|
+
const href = phoneHref(phone);
|
|
63
|
+
const words = children ?? (typeof phone === "string" ? phone : phone.display);
|
|
64
|
+
if (!href) {
|
|
65
|
+
warnOnce(typeof phone === "string" ? phone : phone.e164);
|
|
66
|
+
return textOf(words).trim() ? <span className={className}>{words}</span> : null;
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
<a className={className} href={href} {...anchor}>
|
|
70
|
+
{words}
|
|
71
|
+
</a>
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/primitives/index.ts
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
|
+
export { EMAIL_PATTERN, isE164, isEmail, toE164 } from "../lib/contactLinks";
|
|
2
|
+
export {
|
|
3
|
+
type AddressComponent,
|
|
4
|
+
addressFromComponents,
|
|
5
|
+
type GooglePlacesOptions,
|
|
6
|
+
googlePlacesProvider,
|
|
7
|
+
} from "../lib/googlePlaces";
|
|
8
|
+
export {
|
|
9
|
+
type AddressParts,
|
|
10
|
+
type AddressProvider,
|
|
11
|
+
AddressSearch,
|
|
12
|
+
type AddressSearchProps,
|
|
13
|
+
type AddressSuggestion,
|
|
14
|
+
} from "./AddressSearch";
|
|
1
15
|
export { Bubble, type BubbleProps } from "./Bubble";
|
|
2
16
|
export { Button, type ButtonProps } from "./Button";
|
|
3
17
|
export { type CallToActionProps, PrimaryButton, SecondaryButton } from "./CallToAction";
|
|
4
18
|
export { Chip, type ChipProps } from "./Chip";
|
|
19
|
+
export { EmailLink, type EmailLinkProps, emailHref } from "./EmailLink";
|
|
20
|
+
export { ExpandableText, type ExpandableTextProps } from "./ExpandableText";
|
|
5
21
|
export { Eyebrow, type EyebrowProps } from "./Eyebrow";
|
|
22
|
+
export { GoogleMapsAttribution } from "./GoogleMapsAttribution";
|
|
6
23
|
export { ImageFrame, type ImageFrameProps } from "./ImageFrame";
|
|
7
24
|
export { Lead, type LeadProps } from "./Lead";
|
|
25
|
+
export { PhoneLink, type PhoneLinkProps, phoneHref } from "./PhoneLink";
|
|
8
26
|
export { type ProseBlock, ProseBlocks, type ProseBlocksProps } from "./ProseBlocks";
|
|
9
27
|
export { QuoteCard, type QuoteCardProps } from "./QuoteCard";
|
|
10
28
|
export { SectionHeading, type SectionHeadingProps } from "./SectionHeading";
|
|
@@ -9,6 +9,10 @@
|
|
|
9
9
|
* override, but vercel.json still describes the committed config, so a
|
|
10
10
|
* rewrite mismatch only warns, except on Vercel, where it would ship.
|
|
11
11
|
*
|
|
12
|
+
* It checks the config's phone numbers and email addresses first
|
|
13
|
+
* (`contactProblems`, ./check-contacts.ts), since this is the build step
|
|
14
|
+
* that reads the config.
|
|
15
|
+
*
|
|
12
16
|
* Usage: atelic-check-base-path (from the site's root)
|
|
13
17
|
* Exits 1 on any problem.
|
|
14
18
|
*/
|
|
@@ -23,6 +27,7 @@ import {
|
|
|
23
27
|
unbasedRefs,
|
|
24
28
|
} from "../lib/basePathAudit";
|
|
25
29
|
import { normalizeBasePath } from "../routing/basePath";
|
|
30
|
+
import { contactProblems } from "./check-contacts";
|
|
26
31
|
import { SITE_CONFIG, siteConfigPath } from "./site-config";
|
|
27
32
|
|
|
28
33
|
/** Where the build writes the pages, from the site's root. */
|
|
@@ -101,6 +106,16 @@ export async function main(cwd: string = process.cwd()): Promise<void> {
|
|
|
101
106
|
const { site } = (await import(pathToFileURL(configPath).href)) as {
|
|
102
107
|
site?: { basePath?: string };
|
|
103
108
|
};
|
|
109
|
+
// Every number and address the config gives the package to link: a dead
|
|
110
|
+
// call link ships on every page, so it stops the build here (8.5.0).
|
|
111
|
+
const contacts = contactProblems(site);
|
|
112
|
+
if (contacts.length > 0) {
|
|
113
|
+
for (const problem of contacts) console.error(`[contacts] ${problem}`);
|
|
114
|
+
console.error(
|
|
115
|
+
`[contacts] ${contacts.length} problem${contacts.length === 1 ? "" : "s"} in ${SITE_CONFIG}`,
|
|
116
|
+
);
|
|
117
|
+
process.exit(1);
|
|
118
|
+
}
|
|
104
119
|
const root = resolve(cwd, BUILD_ROOT);
|
|
105
120
|
if (!existsSync(root)) {
|
|
106
121
|
console.error(`[base-path] no ${BUILD_ROOT} in ${cwd}. Build the site first.`);
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The build time check on a site's phone numbers and email addresses: every
|
|
3
|
+
* number the package draws as a link has an `e164` that is a real number
|
|
4
|
+
* for its country, and a `display` that reads as the same number; every
|
|
5
|
+
* address matches the form's pattern. A number that fails ships as a dead or
|
|
6
|
+
* wrong call link on every page, so the build stops and names the field.
|
|
7
|
+
*
|
|
8
|
+
* Google's numbering plan (`libphonenumber-js`, its complete `max` metadata)
|
|
9
|
+
* runs here and in tests only, never in a page: nothing a page bundles
|
|
10
|
+
* imports this file (tst/phone-library-stays-out.test.ts holds that). The
|
|
11
|
+
* browser keeps its light check (`toE164`, `src/lib/contactLinks.ts`).
|
|
12
|
+
*
|
|
13
|
+
* It is sure of what it judges: phones by their shape (an `e164` beside a
|
|
14
|
+
* `display`), addresses only at the config's known paths, and `tel:` and
|
|
15
|
+
* `mailto:` hrefs anywhere, so a site's words are never mistaken for a
|
|
16
|
+
* contact and a valid site never fails.
|
|
17
|
+
*
|
|
18
|
+
* `atelic-check-base-path`, a marketing site's last build step and the one
|
|
19
|
+
* that already reads its config, runs `contactProblems` over the `site`
|
|
20
|
+
* export. A site passing numbers as props outside its config (a contact
|
|
21
|
+
* card's `phones`) calls the same function from its own test:
|
|
22
|
+
*
|
|
23
|
+
* import { contactProblems } from "@atelic-action/ui/scripts/contacts";
|
|
24
|
+
* expect(contactProblems({ phones })).toEqual([]);
|
|
25
|
+
*/
|
|
26
|
+
import parsePhoneNumber, {
|
|
27
|
+
type CountryCode,
|
|
28
|
+
isSupportedCountry,
|
|
29
|
+
type PhoneNumber,
|
|
30
|
+
} from "libphonenumber-js/max";
|
|
31
|
+
import { isEmail } from "../lib/contactLinks.js";
|
|
32
|
+
|
|
33
|
+
/** A number read against a country, or undefined when it is not one; never throws. */
|
|
34
|
+
function parse(text: string, country: CountryCode): PhoneNumber | undefined {
|
|
35
|
+
try {
|
|
36
|
+
return parsePhoneNumber(text, country);
|
|
37
|
+
} catch {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The country a number written without its + is read against: the
|
|
44
|
+
* config's own (`address.country`, a two letter code), else the US, where
|
|
45
|
+
* every site so far does business.
|
|
46
|
+
*/
|
|
47
|
+
function countryOf(value: unknown): CountryCode {
|
|
48
|
+
const country = isRecord(value) && isRecord(value.address) ? value.address.country : undefined;
|
|
49
|
+
const code = typeof country === "string" ? country.trim().toUpperCase() : "";
|
|
50
|
+
return isSupportedCountry(code) ? code : "US";
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The problem with one number, or null when it is sound. */
|
|
54
|
+
function phoneProblem(e164: string, display: string, country: CountryCode): string | null {
|
|
55
|
+
const number = e164.startsWith("+") ? parse(e164, country) : undefined;
|
|
56
|
+
if (!number?.isValid() || number.number !== e164) {
|
|
57
|
+
return `e164 "${e164}" is not a valid number in E.164 (a + and the country code, digits only)`;
|
|
58
|
+
}
|
|
59
|
+
const shown = parse(display, number.country ?? country);
|
|
60
|
+
if (shown?.number !== e164) {
|
|
61
|
+
return `display "${display}" does not read as ${e164}`;
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
67
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The config's known email addresses, by path from the walk's root (a
|
|
71
|
+
* `SiteConfig` or an `ArtifactConfig`). A string is judged as an address
|
|
72
|
+
* only here or as a `mailto:` href, never by its key's name alone, so words
|
|
73
|
+
* such as a label reading "Email" are left alone.
|
|
74
|
+
*/
|
|
75
|
+
const EMAIL_PATHS = new Set([
|
|
76
|
+
"email",
|
|
77
|
+
"gate.contactEmail",
|
|
78
|
+
"contactEmail",
|
|
79
|
+
"analytics.identify.email",
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* A `tel:` href's number, decoded, with RFC 3966's visual separators (- .
|
|
84
|
+
* ( ) and spaces) and any parameters (";ext=12") taken out.
|
|
85
|
+
*/
|
|
86
|
+
const telNumber = (href: string) =>
|
|
87
|
+
decoded(href.slice("tel:".length))
|
|
88
|
+
.split(";")[0]
|
|
89
|
+
?.replace(/[-.()\s]/g, "") ?? "";
|
|
90
|
+
|
|
91
|
+
/** A percent encoded address, decoded; one too malformed to decode, as given. */
|
|
92
|
+
function decoded(address: string): string {
|
|
93
|
+
try {
|
|
94
|
+
return decodeURIComponent(address);
|
|
95
|
+
} catch {
|
|
96
|
+
return address;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Every problem with the numbers and addresses in `value`, each naming its
|
|
102
|
+
* field (`site.header.phones[1].display`), empty when all is sound. Judges
|
|
103
|
+
* only what it is sure is a contact:
|
|
104
|
+
*
|
|
105
|
+
* - a phone is any object holding a string `e164` and `display` (the
|
|
106
|
+
* package's `Phone`, `HeaderPhone`, `ContactPhone`) or `phoneE164` and
|
|
107
|
+
* `phoneDisplay` (a `Locations` entry), wherever it sits: the number must
|
|
108
|
+
* be valid in E.164 for its country and the display must read as it;
|
|
109
|
+
* - an address is a string at one of the config's known address paths
|
|
110
|
+
* (`email`, `gate.contactEmail`, `analytics.identify.email`);
|
|
111
|
+
* - a `tel:` href must reduce, separators aside, to a valid number, and a
|
|
112
|
+
* `mailto:` href must write to an address.
|
|
113
|
+
*
|
|
114
|
+
* A value seen twice (a config that refers to itself) is walked once.
|
|
115
|
+
*/
|
|
116
|
+
export function contactProblems(value: unknown, path = "site"): string[] {
|
|
117
|
+
return walk(value, path, "", new WeakSet(), countryOf(value));
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function walk(
|
|
121
|
+
value: unknown,
|
|
122
|
+
path: string,
|
|
123
|
+
at: string,
|
|
124
|
+
seen: WeakSet<object>,
|
|
125
|
+
country: CountryCode,
|
|
126
|
+
): string[] {
|
|
127
|
+
if (typeof value === "object" && value !== null) {
|
|
128
|
+
if (seen.has(value)) return [];
|
|
129
|
+
seen.add(value);
|
|
130
|
+
}
|
|
131
|
+
if (Array.isArray(value)) {
|
|
132
|
+
return value.flatMap((item, index) => walk(item, `${path}[${index}]`, at, seen, country));
|
|
133
|
+
}
|
|
134
|
+
// A React element (words a config may hold as JSX) is copy, never a contact.
|
|
135
|
+
if (!isRecord(value) || "$$typeof" in value) return [];
|
|
136
|
+
const problems: string[] = [];
|
|
137
|
+
for (const [e164Key, displayKey] of [
|
|
138
|
+
["e164", "display"],
|
|
139
|
+
["phoneE164", "phoneDisplay"],
|
|
140
|
+
] as const) {
|
|
141
|
+
const e164 = value[e164Key];
|
|
142
|
+
const display = value[displayKey];
|
|
143
|
+
if (typeof e164 === "string" && typeof display === "string") {
|
|
144
|
+
const problem = phoneProblem(e164, display, country);
|
|
145
|
+
if (problem) problems.push(`${path}: ${problem}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const [key, item] of Object.entries(value)) {
|
|
149
|
+
const field = `${path}.${key}`;
|
|
150
|
+
const where = at ? `${at}.${key}` : key;
|
|
151
|
+
if (typeof item !== "string") {
|
|
152
|
+
// An array keeps its parent's place: header.phones[0] is under header.phones.
|
|
153
|
+
problems.push(...walk(item, field, where, seen, country));
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
// An empty address is none (a site without a public one), not a bad one.
|
|
157
|
+
if (EMAIL_PATHS.has(where) && item.trim() && !isEmail(item)) {
|
|
158
|
+
problems.push(`${field}: "${item}" is not an email address`);
|
|
159
|
+
}
|
|
160
|
+
if (item.startsWith("tel:")) {
|
|
161
|
+
// A national number (no +) is read against the config's country, as a
|
|
162
|
+
// dialer reads it; only one that is not a plausible number fails.
|
|
163
|
+
const number = parse(telNumber(item), country);
|
|
164
|
+
if (!number?.isPossible()) problems.push(`${field}: "${item}" does not dial a number`);
|
|
165
|
+
}
|
|
166
|
+
if (item.startsWith("mailto:")) {
|
|
167
|
+
// RFC 6068: one address or several, comma separated, before the query,
|
|
168
|
+
// or in its to= when nothing comes before it.
|
|
169
|
+
const [head = "", query = ""] = item.slice("mailto:".length).split("?");
|
|
170
|
+
const to = decoded(head) || (new URLSearchParams(query).get("to") ?? "");
|
|
171
|
+
if (!to.split(",").every((address) => isEmail(address))) {
|
|
172
|
+
problems.push(`${field}: "${item}" does not write to an address`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return problems;
|
|
177
|
+
}
|