@simplix-react-ui-kits/site-core 0.1.0 → 0.1.1

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 (112) hide show
  1. package/README.md +4 -3
  2. package/dist/account/index.d.ts +1 -1
  3. package/dist/account/index.js +3 -3
  4. package/dist/action/index.d.ts +59 -3
  5. package/dist/action/index.js +82 -0
  6. package/dist/action/index.js.map +1 -1
  7. package/dist/checkout/index.d.ts +1 -1
  8. package/dist/checkout/index.js +1 -1
  9. package/dist/{chunk-BJUU2WTX.js → chunk-EELJOGWB.js} +12 -5
  10. package/dist/chunk-EELJOGWB.js.map +1 -0
  11. package/dist/{chunk-7K476KMZ.js → chunk-EOTYGKKM.js} +3 -3
  12. package/dist/{chunk-7K476KMZ.js.map → chunk-EOTYGKKM.js.map} +1 -1
  13. package/dist/{chunk-FKC262N4.js → chunk-EWBTUSZY.js} +9 -3
  14. package/dist/chunk-EWBTUSZY.js.map +1 -0
  15. package/dist/{chunk-5TFLOQT6.js → chunk-HRRP6HMF.js} +10 -5
  16. package/dist/chunk-HRRP6HMF.js.map +1 -0
  17. package/dist/{chunk-4KFQ26JW.js → chunk-HZGBIIGN.js} +27 -6
  18. package/dist/chunk-HZGBIIGN.js.map +1 -0
  19. package/dist/{chunk-JJQJFRBI.js → chunk-OWQVRM4W.js} +3 -3
  20. package/dist/{chunk-JJQJFRBI.js.map → chunk-OWQVRM4W.js.map} +1 -1
  21. package/dist/{chunk-6S23FFBB.js → chunk-TGG4ZKPG.js} +3 -3
  22. package/dist/{chunk-6S23FFBB.js.map → chunk-TGG4ZKPG.js.map} +1 -1
  23. package/dist/{chunk-JVMJF5JJ.js → chunk-UF2MDCWB.js} +5 -5
  24. package/dist/chunk-UF2MDCWB.js.map +1 -0
  25. package/dist/{chunk-EG6GE3YS.js → chunk-YXASVWY7.js} +3 -3
  26. package/dist/{chunk-EG6GE3YS.js.map → chunk-YXASVWY7.js.map} +1 -1
  27. package/dist/content/index.d.ts +95 -0
  28. package/dist/content/index.js +85 -0
  29. package/dist/content/index.js.map +1 -0
  30. package/dist/form/index.d.ts +229 -8
  31. package/dist/form/index.js +150 -10
  32. package/dist/form/index.js.map +1 -1
  33. package/dist/help/index.d.ts +1 -1
  34. package/dist/help/index.js +6 -6
  35. package/dist/install/index.d.ts +1 -1
  36. package/dist/install/index.js +4 -4
  37. package/dist/legal/index.d.ts +2 -2
  38. package/dist/legal/index.js +5 -5
  39. package/dist/link/index.d.ts +14 -1
  40. package/dist/link/index.js +8 -1
  41. package/dist/link/index.js.map +1 -1
  42. package/dist/marketing/index.d.ts +1 -1
  43. package/dist/page/index.d.ts +2 -2
  44. package/dist/page/index.js +4 -4
  45. package/dist/pricing/index.d.ts +1 -1
  46. package/dist/pricing/index.js +2 -2
  47. package/dist/shell/index.d.ts +1 -1
  48. package/dist/{site-action-B79fuwMb.d.ts → site-action-CPpf8JZl.d.ts} +1 -1
  49. package/dist/{site-page-Dl0A5T1N.d.ts → site-page-DKcjqh9y.d.ts} +7 -2
  50. package/package.json +10 -3
  51. package/src/action/action-tile.style.ts +63 -0
  52. package/src/action/action-tile.tsx +83 -0
  53. package/src/action/index.ts +11 -0
  54. package/src/content/content.style.ts +72 -0
  55. package/src/content/content.tsx +124 -0
  56. package/src/content/index.ts +12 -0
  57. package/src/form/choices.style.ts +16 -0
  58. package/src/form/choices.tsx +28 -5
  59. package/src/form/country-field.tsx +61 -0
  60. package/src/form/date-time.style.ts +26 -0
  61. package/src/form/date-time.tsx +123 -0
  62. package/src/form/dialog.style.ts +4 -2
  63. package/src/form/errors.tsx +16 -4
  64. package/src/form/form.style.ts +8 -0
  65. package/src/form/index.ts +11 -1
  66. package/src/form/phone-field.tsx +98 -0
  67. package/src/form/select.style.ts +6 -1
  68. package/src/form/select.tsx +13 -3
  69. package/src/form/signature.style.ts +20 -0
  70. package/src/form/signature.tsx +46 -0
  71. package/src/link/index.ts +1 -0
  72. package/src/link/mounted-href.ts +16 -0
  73. package/src/page/site-page.style.ts +13 -4
  74. package/src/page/site-page.tsx +8 -3
  75. package/src/styles/designs/base.css +121 -4
  76. package/templates/app-shell.hbs +5 -4
  77. package/dist/chunk-4KFQ26JW.js.map +0 -1
  78. package/dist/chunk-5TFLOQT6.js.map +0 -1
  79. package/dist/chunk-BJUU2WTX.js.map +0 -1
  80. package/dist/chunk-FKC262N4.js.map +0 -1
  81. package/dist/chunk-JVMJF5JJ.js.map +0 -1
  82. package/src/account/account.test.tsx +0 -186
  83. package/src/action/site-action.test.tsx +0 -154
  84. package/src/auth/auth.test.tsx +0 -132
  85. package/src/checkout/checkout.test.tsx +0 -187
  86. package/src/form/choices-field.test.tsx +0 -20
  87. package/src/form/errors.test.tsx +0 -49
  88. package/src/form/form.test.tsx +0 -275
  89. package/src/form/question-focus.test.ts +0 -182
  90. package/src/form/slider.test.tsx +0 -148
  91. package/src/form/typed-text.test.ts +0 -52
  92. package/src/help/article.test.tsx +0 -189
  93. package/src/help/help.test.tsx +0 -215
  94. package/src/help/screen-sketch.test.tsx +0 -59
  95. package/src/install/install.test.tsx +0 -177
  96. package/src/legal/legal.test.tsx +0 -161
  97. package/src/legal/policy.test.tsx +0 -137
  98. package/src/legal/refund.test.tsx +0 -148
  99. package/src/link/routes-in-page.test.ts +0 -26
  100. package/src/link/site-link.test.ts +0 -10
  101. package/src/marketing/marketing.test.tsx +0 -221
  102. package/src/page/site-failure.test.tsx +0 -65
  103. package/src/page/site-page.test.tsx +0 -109
  104. package/src/page/site-read.test.tsx +0 -41
  105. package/src/pricing/pack-card.test.tsx +0 -107
  106. package/src/pricing/pricing.test.tsx +0 -261
  107. package/src/shell/refusal-page.test.ts +0 -19
  108. package/src/shell/site-scheme-param.test.ts +0 -53
  109. package/src/shell/site-scheme-switch.test.ts +0 -80
  110. package/src/shell/site-scheme.test.ts +0 -149
  111. package/src/shell/site-shell.test.tsx +0 -401
  112. package/src/testing/markup.ts +0 -65
@@ -0,0 +1,26 @@
1
+ import { defineSlotStyle } from "@simplix-react/ui/design";
2
+
3
+ /**
4
+ * The framework's date picker in the site design: its trigger on the control line, in the site's
5
+ * control height, radius and sans face; the line takes the accent while the calendar is open.
6
+ */
7
+ export const siteDateStyle = defineSlotStyle({
8
+ slot: "site-date",
9
+ base:
10
+ "min-w-0 [&_[data-slot=date-picker-trigger]]:h-(--site-control) [&_[data-slot=date-picker-trigger]]:w-full [&_[data-slot=date-picker-trigger]]:rounded-(--site-radius-md) [&_[data-slot=date-picker-trigger]]:border-(--site-control-line) [&_[data-slot=date-picker-trigger]]:bg-(--site-surface) [&_[data-slot=date-picker-trigger]]:font-(family-name:--site-font-sans) [&_[data-slot=date-picker-trigger]]:text-(length:--site-fs-body-pane) [&_[data-slot=date-picker-trigger]]:text-(--site-ink) [&_[data-slot=date-picker-trigger]]:shadow-none [&_[data-slot=date-picker-trigger]]:hover:border-(--site-ink-muted) [&_[data-slot=date-picker-trigger]]:focus-visible:shadow-[var(--site-focus-ring)] [&_[data-slot=date-picker-trigger][data-state=open]]:border-(--site-accent) [&_[data-slot=date-picker-trigger][data-empty=true]]:text-(--site-ink-muted)",
11
+ variants: {},
12
+ defaultVariants: {},
13
+ });
14
+
15
+ /**
16
+ * The framework's time picker in the site design: its row of boxes on the control line, as wide
17
+ * as the column, in the site's control height and radius; the chosen half of the day on the accent.
18
+ * The lists a wide window opens under the boxes are a raised site surface, the held value on the accent.
19
+ */
20
+ export const siteTimeStyle = defineSlotStyle({
21
+ slot: "site-time",
22
+ base:
23
+ "min-w-0 [&>[data-slot=time-select-control]]:w-full [&>[data-slot=time-select-control]]:min-w-max [&_[data-slot=time-select-row]]:h-(--site-control) [&_[data-slot=time-select-row]]:rounded-(--site-radius-md) [&_[data-slot=time-select-row]]:border-(--site-control-line) [&_[data-slot=time-select-row]]:bg-(--site-surface) [&_[data-slot=time-select-row]]:font-(family-name:--site-font-sans) [&_[data-slot=time-select-row]]:text-(--site-ink) [&_[data-slot=time-select-row]]:focus-within:border-(--site-accent) [&_[data-slot=time-spinner-input]]:text-(length:--site-fs-body-pane) [&_[data-slot=time-meridiem]]:border-(--site-control-line) [&_[data-slot=time-meridiem-option]]:text-(length:--site-fs-caption) [&_[data-slot=time-meridiem-option][aria-pressed=true]]:bg-(--site-accent) [&_[data-slot=time-meridiem-option][aria-pressed=true]]:text-(--site-on-accent) [&_[data-slot=time-select-colon]]:border-(--site-control-line) [&_[data-slot=time-select-colon]]:text-(--site-ink-muted) [&_[data-slot=time-spinner-steppers]]:border-(--site-control-line) [&_[data-slot=time-scroll-column]]:rounded-(--site-radius-md) [&_[data-slot=time-scroll-column]]:border-(--site-line) [&_[data-slot=time-scroll-column]]:bg-(--site-surface-raised) [&_[data-slot=time-scroll-column]]:shadow-[var(--site-shadow-float)] [&_[data-slot=time-scroll-option]]:rounded-(--site-radius-sm) [&_[data-slot=time-scroll-option]]:text-(length:--site-fs-body-pane) [&_[data-slot=time-scroll-option]]:text-(--site-ink) [&_[data-slot=time-scroll-option][data-selected=true]]:bg-(--site-accent) [&_[data-slot=time-scroll-option][data-selected=true]]:text-(--site-on-accent)",
24
+ variants: {},
25
+ defaultVariants: {},
26
+ });
@@ -0,0 +1,123 @@
1
+ import { useId, type ReactNode } from "react";
2
+ import { DatePicker, TimePicker, type TimeValue } from "@simplix-react/ui";
3
+ import { slotAttributes } from "@simplix-react/ui/design";
4
+
5
+ import { FormField } from "./fields";
6
+ import { siteDateStyle, siteTimeStyle } from "./date-time.style";
7
+
8
+ /** Props for {@link SiteDateControl}. */
9
+ export interface SiteDateControlProps {
10
+ /** The chosen day, or `null` while there is none. */
11
+ readonly value: Date | null;
12
+ /** Called with the day the reader chose, or with `null` when the choice is cleared. */
13
+ readonly onValueChange: (value: Date | null) => void;
14
+ /** The id of the trigger, which a label names through `htmlFor`. */
15
+ readonly id?: string;
16
+ /** What the trigger says while no day is chosen. */
17
+ readonly placeholder?: string;
18
+ /** The language of the calendar ("ko", "en", "ja"). */
19
+ readonly locale?: string;
20
+ readonly minDate?: Date;
21
+ readonly maxDate?: Date;
22
+ /** Draws the way to take the choice back. */
23
+ readonly clearable?: boolean;
24
+ readonly disabled?: boolean;
25
+ }
26
+
27
+ /**
28
+ * A day chosen from a calendar. The calendar, its keyboard and its focus are the framework date
29
+ * picker's; the kit draws the trigger on the control line.
30
+ */
31
+ export function SiteDateControl({ value, onValueChange, id, placeholder, locale, minDate, maxDate, clearable, disabled }: SiteDateControlProps) {
32
+ return (
33
+ <div {...slotAttributes(siteDateStyle, {})}>
34
+ <DatePicker
35
+ id={id}
36
+ value={value ?? undefined}
37
+ onChange={(day) => onValueChange(day ?? null)}
38
+ placeholder={placeholder}
39
+ locale={locale}
40
+ minDate={minDate}
41
+ maxDate={maxDate}
42
+ clearable={clearable}
43
+ disabled={disabled}
44
+ />
45
+ </div>
46
+ );
47
+ }
48
+
49
+ /** Props for {@link SiteDateField}. */
50
+ export interface SiteDateFieldProps extends Omit<SiteDateControlProps, "id"> {
51
+ /** The field's name over the control. */
52
+ readonly label: ReactNode;
53
+ /** Any note under the control. */
54
+ readonly children?: ReactNode;
55
+ }
56
+
57
+ /** A day under its name: the name names the trigger, and pressing it opens the calendar. */
58
+ export function SiteDateField({ label, children, ...control }: SiteDateFieldProps) {
59
+ return (
60
+ <FormField label={label}>
61
+ <SiteDateControl {...control} />
62
+ {children}
63
+ </FormField>
64
+ );
65
+ }
66
+
67
+ /** Props for {@link SiteTimeControl}. */
68
+ export interface SiteTimeControlProps {
69
+ /** The chosen time of day, or `null` while there is none: the boxes stand empty. */
70
+ readonly value: TimeValue | null;
71
+ /** Called with a whole time after every change. */
72
+ readonly onValueChange: (value: TimeValue) => void;
73
+ /** The id of the element that names the control: its boxes are a group with no single label. */
74
+ readonly labelledBy?: string;
75
+ /** A 12-hour clock with the half of the day beside it; `false` for a 24-hour clock. */
76
+ readonly hour12?: boolean;
77
+ /** The step between the minutes of the list; typing and stepping take any minute. */
78
+ readonly minuteStep?: number;
79
+ readonly minTime?: TimeValue;
80
+ readonly maxTime?: TimeValue;
81
+ readonly disabled?: boolean;
82
+ }
83
+
84
+ /**
85
+ * A time of day typed or stepped in hour and minute boxes. The boxes, their keyboard and their
86
+ * lists are the framework time picker's; the kit draws the row on the control line, as wide as
87
+ * its column and never narrower than what it holds.
88
+ */
89
+ export function SiteTimeControl({ value, onValueChange, labelledBy, hour12, minuteStep, minTime, maxTime, disabled }: SiteTimeControlProps) {
90
+ return (
91
+ <div {...slotAttributes(siteTimeStyle, {})}>
92
+ <TimePicker
93
+ aria-labelledby={labelledBy}
94
+ value={value}
95
+ onChange={onValueChange}
96
+ hour12={hour12}
97
+ minuteStep={minuteStep}
98
+ minTime={minTime}
99
+ maxTime={maxTime}
100
+ disabled={disabled}
101
+ />
102
+ </div>
103
+ );
104
+ }
105
+
106
+ /** Props for {@link SiteTimeField}. */
107
+ export interface SiteTimeFieldProps extends Omit<SiteTimeControlProps, "labelledBy"> {
108
+ /** The field's name over the control, which names its boxes as a group. */
109
+ readonly label: ReactNode;
110
+ /** Any note under the control. */
111
+ readonly children?: ReactNode;
112
+ }
113
+
114
+ /** A time of day under its name. */
115
+ export function SiteTimeField({ label, children, ...control }: SiteTimeFieldProps) {
116
+ const labelId = useId();
117
+ return (
118
+ <FormField as="group" label={<span id={labelId}>{label}</span>}>
119
+ <SiteTimeControl {...control} labelledBy={labelId} />
120
+ {children}
121
+ </FormField>
122
+ );
123
+ }
@@ -2,13 +2,15 @@ import { defineSlotStyle } from "@simplix-react/ui/design";
2
2
 
3
3
  /**
4
4
  * The framework dialog drawn as a site card over the page: a raised surface with a hairline, the
5
- * float shadow, the content in one column.
5
+ * float shadow, the content in one column. The card states its own place: in the middle of the
6
+ * window and as tall as what it holds at every width. The framework pins a dialog to the four edges
7
+ * of a phone's window, which is the frame of a form; a site's dialog is a short question.
6
8
  */
7
9
  export const siteDialogStyle = defineSlotStyle({
8
10
  slot: "site-dialog",
9
11
  as: "part",
10
12
  base:
11
- "flex max-h-11/12 w-80 max-w-11/12 flex-col gap-3 overflow-y-auto rounded-(--site-radius-2xl) border border-(--site-line) bg-(--site-surface-raised) p-4 font-(family-name:--site-font-sans) text-(length:--site-fs-base) leading-(--site-lh-base) text-(--site-ink) shadow-[var(--site-shadow-float)] outline-none",
13
+ "inset-auto top-1/2 left-1/2 flex h-auto max-h-11/12 w-80 max-w-11/12 -translate-x-1/2 -translate-y-1/2 flex-col gap-3 overflow-y-auto rounded-(--site-radius-2xl) border border-(--site-line) bg-(--site-surface-raised) p-4 font-(family-name:--site-font-sans) text-(length:--site-fs-base) leading-(--site-lh-base) text-(--site-ink) shadow-[var(--site-shadow-float)] outline-none",
12
14
  variants: {},
13
15
  defaultVariants: {},
14
16
  });
@@ -26,8 +26,11 @@ export interface SiteErrorsCopy {
26
26
  readonly titles: Readonly<Record<SiteErrorKind, string>>;
27
27
  /** What a server not answering means for the reader (try again in a moment). */
28
28
  readonly unavailable: string;
29
- /** What is said when the failure carries no sentence of its own. */
30
- readonly fallback: string;
29
+ /**
30
+ * What is said when the failure carries no sentence of its own: one sentence, or the sentence for
31
+ * the failure (a product that words each error code the server sends).
32
+ */
33
+ readonly fallback: string | ((event: SiteErrorEvent) => string);
31
34
  /** Closes the failure shown. */
32
35
  readonly close: string;
33
36
  /** Closes every failure waiting, with how many there are. */
@@ -44,6 +47,15 @@ export interface SiteErrorView {
44
47
  readonly closeAll?: string;
45
48
  }
46
49
 
50
+ /**
51
+ * The reason a refused field carries, led by what the server calls the field. A server with no
52
+ * label for a field hands its key back in the label's place: a key is no label, and the reason then
53
+ * stands alone.
54
+ */
55
+ function fieldReason(field: NonNullable<SiteErrorEvent["validationErrors"]>[number]): string {
56
+ return field.label && field.label !== field.field ? `${field.label}: ${field.message}` : field.message;
57
+ }
58
+
47
59
  /**
48
60
  * What the dialog says about the first waiting failure, or undefined when none waits: titled by its
49
61
  * kind, the server's own sentence (which names the rule that refused the request, so it leads), then
@@ -55,8 +67,8 @@ export function siteErrorView(errors: readonly SiteErrorEvent[], copy: SiteError
55
67
  const kind = siteErrorKind(current);
56
68
  return {
57
69
  title: copy.titles[kind],
58
- description: kind === "gateway" ? copy.unavailable : current.message || copy.fallback,
59
- fields: kind === "gateway" ? [] : (current.validationErrors ?? []).map((field) => field.message),
70
+ description: kind === "gateway" ? copy.unavailable : current.message || (typeof copy.fallback === "function" ? copy.fallback(current) : copy.fallback),
71
+ fields: kind === "gateway" ? [] : (current.validationErrors ?? []).map(fieldReason),
60
72
  ...(errors.length > 1 ? { closeAll: copy.closeAll(errors.length) } : {}),
61
73
  };
62
74
  }
@@ -37,3 +37,11 @@ export const siteCodeCellStyle = defineSlotStyle({
37
37
  },
38
38
  defaultVariants: { invalid: false },
39
39
  });
40
+
41
+ /** A stored phone number for reading, kept on one line. */
42
+ export const sitePhoneTextStyle = defineSlotStyle({
43
+ slot: "site-phone-text",
44
+ base: "whitespace-nowrap tabular-nums",
45
+ variants: {},
46
+ defaultVariants: {},
47
+ });
package/src/form/index.ts CHANGED
@@ -2,7 +2,17 @@ export { FieldInline, FieldNote, FieldRow, FormField, SiteInput, SiteTextarea }
2
2
  export type { FieldInlineProps, FieldNoteProps, FieldRowProps, FormFieldProps, SiteInputProps, SiteTextareaProps } from "./fields";
3
3
  export { RadioCards, SiteCheckbox, SiteSwitch } from "./choices";
4
4
  export type { RadioCardOption, RadioCardsProps, SiteCheckboxProps, SiteSwitchProps } from "./choices";
5
+ export { SiteDateControl, SiteDateField, SiteTimeControl, SiteTimeField } from "./date-time";
6
+ export type { SiteDateControlProps, SiteDateFieldProps, SiteTimeControlProps, SiteTimeFieldProps } from "./date-time";
7
+ export { siteDateStyle, siteTimeStyle } from "./date-time.style";
5
8
  export { SiteSelect } from "./select";
9
+ export { SiteSignature, SiteSignatureImage } from "./signature";
10
+ export type { SiteSignatureImageProps, SiteSignatureProps } from "./signature";
11
+ export { siteSignatureImageStyle, siteSignatureStyle } from "./signature.style";
12
+ export { phoneCountryLabel, SitePhoneControl, SitePhoneField, SitePhoneText } from "./phone-field";
13
+ export type { SitePhoneControlProps, SitePhoneFieldProps, SitePhoneTextProps } from "./phone-field";
14
+ export { countryOfBrowserZone, countrySelectOptions, SiteCountryControl, SiteCountryField } from "./country-field";
15
+ export type { SiteCountryControlProps, SiteCountryFieldProps } from "./country-field";
6
16
  export type { SiteSelectOption, SiteSelectProps } from "./select";
7
17
  export { CodeField } from "./code-field";
8
18
  export type { CodeFieldProps } from "./code-field";
@@ -20,4 +30,4 @@ export { SiteSlider, SLIDER_PAGE_STEPS, sliderKeyTarget, sliderShare, sliderSnap
20
30
  export type { SiteSliderName, SiteSliderProps, SiteSliderRange } from "./slider";
21
31
  // The code row and cell looks, for a product whose code field posts its own form field (a sign-in
22
32
  // server page) and spreads them on its own cells with `partAttributes`.
23
- export { siteCodeCellStyle, siteCodeStyle } from "./form.style";
33
+ export { siteCodeCellStyle, siteCodeStyle, sitePhoneTextStyle } from "./form.style";
@@ -0,0 +1,98 @@
1
+ import type { ReactNode } from "react";
2
+ import { usePhoneNumber, type PhoneCountryOption, type PhoneNumberState } from "@simplix-react/ui";
3
+ import { slotAttributes } from "@simplix-react/ui/design";
4
+
5
+ import { FieldInline, SiteInput } from "./fields";
6
+ import { sitePhoneTextStyle } from "./form.style";
7
+ import { SiteSelect } from "./select";
8
+
9
+ /** A country as the calling-code list writes it: the code, then the country's name. */
10
+ export function phoneCountryLabel(option: Pick<PhoneCountryOption, "callingCode" | "localName">): string {
11
+ return `+${option.callingCode} ${option.localName}`;
12
+ }
13
+
14
+ /** Props for {@link SitePhoneControl}. */
15
+ export interface SitePhoneControlProps {
16
+ /** The number being written: its country, its national text and the ways to change them. */
17
+ readonly state: Pick<PhoneNumberState, "options" | "country" | "national" | "setCountry" | "setNational">;
18
+ /** The accessible name of the calling-code select ("Country calling code"). */
19
+ readonly countryLabel: string;
20
+ /** The accessible name of the number field, where no visible name stands over it. */
21
+ readonly numberLabel?: string;
22
+ readonly placeholder?: string;
23
+ /** The number is refused: the field takes the bad colour and reports `aria-invalid`. */
24
+ readonly invalid?: boolean;
25
+ readonly disabled?: boolean;
26
+ }
27
+
28
+ /**
29
+ * A phone number as two controls on one line: the calling code of a country, and the number in
30
+ * that country's own form. The trigger shows the code alone; the list names each country after
31
+ * its code.
32
+ */
33
+ export function SitePhoneControl({ state, countryLabel, numberLabel, placeholder, invalid = false, disabled = false }: SitePhoneControlProps) {
34
+ return (
35
+ <FieldInline>
36
+ <SiteSelect
37
+ label={countryLabel}
38
+ placeholder="+"
39
+ value={state.country ?? null}
40
+ options={state.options.map((option) => ({ value: option.code, label: phoneCountryLabel(option), short: `+${option.callingCode}` }))}
41
+ onValueChange={state.setCountry}
42
+ disabled={disabled}
43
+ fit
44
+ />
45
+ <SiteInput
46
+ type="tel"
47
+ inputMode="tel"
48
+ autoComplete="tel-national"
49
+ aria-label={numberLabel}
50
+ value={state.national}
51
+ onValueChange={state.setNational}
52
+ placeholder={placeholder}
53
+ invalid={invalid}
54
+ disabled={disabled}
55
+ />
56
+ </FieldInline>
57
+ );
58
+ }
59
+
60
+ /** Props for {@link SitePhoneField}. */
61
+ export interface SitePhoneFieldProps extends Omit<SitePhoneControlProps, "state"> {
62
+ /** The number as E.164 (`+821012345678`), or an empty string. */
63
+ readonly value: string;
64
+ /** Called with the E.164 number after every edit, or with `""` once the digits are gone. */
65
+ readonly onValueChange: (value: string) => void;
66
+ /** ISO 3166-1 alpha-2 country the field starts from while the value carries none. */
67
+ readonly defaultCountry?: string;
68
+ }
69
+
70
+ /**
71
+ * A phone number kept as E.164: the framework's phone number state (its countries, its formatting
72
+ * as the reader types) drawn in the site design. It stands in a `FormField as="group"`, which
73
+ * names the two controls together.
74
+ */
75
+ export function SitePhoneField({ value, onValueChange, defaultCountry, ...control }: SitePhoneFieldProps) {
76
+ const state = usePhoneNumber({ value, onChange: onValueChange, defaultCountry });
77
+ return <SitePhoneControl state={state} {...control} />;
78
+ }
79
+
80
+ const NOTHING = () => {};
81
+
82
+ /** Props for {@link SitePhoneText}. */
83
+ export interface SitePhoneTextProps {
84
+ /** The number as E.164 (`+821012345678`). */
85
+ readonly value: string | null | undefined;
86
+ /** What stands in its place while there is none. */
87
+ readonly empty?: ReactNode;
88
+ }
89
+
90
+ /**
91
+ * A stored phone number for reading, in the form written across countries (`+82 10 1234 5678`),
92
+ * kept on one line. Until the phone library has loaded it shows the value as it is stored.
93
+ */
94
+ export function SitePhoneText({ value, empty = null }: SitePhoneTextProps) {
95
+ const state = usePhoneNumber({ value: value ?? "", onChange: NOTHING });
96
+ if (value === null || value === undefined || value === "") return <>{empty}</>;
97
+ return <span {...slotAttributes(sitePhoneTextStyle, {})}>{state.international}</span>;
98
+ }
@@ -18,8 +18,13 @@ export const siteSelectStyle = defineSlotStyle({
18
18
  true: "w-full",
19
19
  false: "w-auto",
20
20
  },
21
+ // Beside another control in a row: the trigger keeps the width of its words, and the other control gives.
22
+ fit: {
23
+ true: "shrink-0",
24
+ false: "",
25
+ },
21
26
  },
22
- defaultVariants: { size: "md", block: false },
27
+ defaultVariants: { size: "md", block: false, fit: false },
23
28
  });
24
29
 
25
30
  /** The value the trigger shows; cut with an ellipsis where it is longer than the trigger. */
@@ -8,6 +8,11 @@ export interface SiteSelectOption<T extends string> {
8
8
  readonly value: T;
9
9
  /** The option's words, in the list and on the trigger once chosen. */
10
10
  readonly label: string;
11
+ /**
12
+ * What the trigger shows once the option is chosen, where the list's words are longer than the
13
+ * trigger has room for (a calling code beside a number, where the list also names the country).
14
+ */
15
+ readonly short?: string;
11
16
  readonly disabled?: boolean;
12
17
  }
13
18
 
@@ -23,6 +28,11 @@ export interface SiteSelectProps<T extends string> {
23
28
  readonly size?: "md" | "sm";
24
29
  /** Stretches the trigger over its column. */
25
30
  readonly block?: boolean;
31
+ /**
32
+ * Keeps the trigger as wide as its words in a row it shares with another control (a calling code
33
+ * beside its number), so the row's other control gives the width and the value is not cut.
34
+ */
35
+ readonly fit?: boolean;
26
36
  readonly disabled?: boolean;
27
37
  }
28
38
 
@@ -32,7 +42,7 @@ export interface SiteSelectProps<T extends string> {
32
42
  * The trigger shows the chosen option's words itself, so it reads the same before and after the
33
43
  * page hydrates.
34
44
  */
35
- export function SiteSelect<T extends string>({ options, value, onValueChange, label, placeholder, size, block = false, disabled = false }: SiteSelectProps<T>) {
45
+ export function SiteSelect<T extends string>({ options, value, onValueChange, label, placeholder, size, block = false, fit = false, disabled = false }: SiteSelectProps<T>) {
36
46
  const chosen = options.find((option) => option.value === value);
37
47
  return (
38
48
  <Select
@@ -43,9 +53,9 @@ export function SiteSelect<T extends string>({ options, value, onValueChange, la
43
53
  if (picked !== undefined) onValueChange(picked.value);
44
54
  }}
45
55
  >
46
- <SelectTrigger {...partAttributes(siteSelectStyle, { size, block })} aria-label={label}>
56
+ <SelectTrigger {...partAttributes(siteSelectStyle, { size, block, fit })} aria-label={label}>
47
57
  <SelectValue {...slotAttributes(siteSelectValueStyle, { placeholder: chosen === undefined })} placeholder={placeholder}>
48
- {chosen?.label}
58
+ {chosen?.short ?? chosen?.label}
49
59
  </SelectValue>
50
60
  </SelectTrigger>
51
61
  <SelectContent {...partAttributes(siteSelectMenuStyle, {})}>
@@ -0,0 +1,20 @@
1
+ import { defineSlotStyle } from "@simplix-react/ui/design";
2
+
3
+ /** The frame a signature is written in. */
4
+ export const siteSignatureStyle = defineSlotStyle({
5
+ slot: "site-signature",
6
+ base: "min-w-0 overflow-hidden rounded-(--site-radius-md) border border-(--site-control-line) bg-(--site-surface)",
7
+ variants: {},
8
+ defaultVariants: {},
9
+ });
10
+
11
+ /**
12
+ * A signature that was given: its picture across the frame. The picture carries its own paper (the
13
+ * pad fills a white ground before it draws), so the frame adds no ground of its own.
14
+ */
15
+ export const siteSignatureImageStyle = defineSlotStyle({
16
+ slot: "site-signature-image",
17
+ base: "min-w-0 overflow-hidden rounded-(--site-radius-md) border border-(--site-line) [&>img]:block [&>img]:h-auto [&>img]:w-full",
18
+ variants: {},
19
+ defaultVariants: {},
20
+ });
@@ -0,0 +1,46 @@
1
+ import { SignaturePad } from "@simplix-react/ui";
2
+ import { slotAttributes } from "@simplix-react/ui/design";
3
+
4
+ import { siteSignatureImageStyle, siteSignatureStyle } from "./signature.style";
5
+
6
+ /** Props for {@link SiteSignature}. */
7
+ export interface SiteSignatureProps {
8
+ /** `drawn` is written by hand on the pad; `typed` draws {@link typedName} as the signature. */
9
+ readonly mode: "drawn" | "typed";
10
+ /** The name drawn as the signature in the `typed` mode. */
11
+ readonly typedName?: string;
12
+ /** Called with the signature as a PNG data address, or with `null` while there is none. */
13
+ readonly onValueChange?: (dataUrl: string | null) => void;
14
+ readonly disabled?: boolean;
15
+ /** The frame's accessible name ("Signature"). */
16
+ readonly label: string;
17
+ }
18
+
19
+ /**
20
+ * A signature written by hand or drawn from a typed name: the framework's signature pad (its
21
+ * canvas, its pointer handling and the picture it gives) in a site frame.
22
+ */
23
+ export function SiteSignature({ mode, typedName, onValueChange, disabled, label }: SiteSignatureProps) {
24
+ return (
25
+ <div {...slotAttributes(siteSignatureStyle, {})} role="group" aria-label={label}>
26
+ <SignaturePad mode={mode} typedName={typedName} onChange={onValueChange} disabled={disabled} />
27
+ </div>
28
+ );
29
+ }
30
+
31
+ /** Props for {@link SiteSignatureImage}. */
32
+ export interface SiteSignatureImageProps {
33
+ /** The address of the signature's picture. */
34
+ readonly src: string;
35
+ /** What the picture is, for a reader who does not see it ("My signature"). */
36
+ readonly alt: string;
37
+ }
38
+
39
+ /** A signature that was given, for reading: its picture across a site frame. */
40
+ export function SiteSignatureImage({ src, alt }: SiteSignatureImageProps) {
41
+ return (
42
+ <div {...slotAttributes(siteSignatureImageStyle, {})}>
43
+ <img src={src} alt={alt} />
44
+ </div>
45
+ );
46
+ }
package/src/link/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { PlainSiteLink, SiteLink, SiteLinkProvider, useSiteLink } from "./site-link";
2
+ export { mountedHref } from "./mounted-href";
2
3
  export { routesInPage } from "./routes-in-page";
3
4
  export type { SitePress, SitePressedAnchor } from "./routes-in-page";
4
5
  export type { SiteLinkComponent, SiteLinkProps, SiteLinkProviderProps } from "./site-link";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The address an anchor carries for a page of a site the server mounts under a path. The site's
3
+ * parts name a page by its path in the site (`/pricing`), which is what the router is moved by; the
4
+ * anchor has to carry the path the browser opens, so the page opens in a new tab and is copied as a
5
+ * link that works. A path of the site is led by the mount; another origin's address, an address
6
+ * relative to the page and a fragment are the browser's as given.
7
+ *
8
+ * @param href the address a site part names
9
+ * @param mount the path the site is served under (`/`, or `/portal/visitor` with or without a closing slash)
10
+ * @returns the address for the anchor
11
+ */
12
+ export function mountedHref(href: string, mount: string): string {
13
+ if (!href.startsWith("/") || href.startsWith("//")) return href;
14
+ const base = mount.replace(/\/+$/, "");
15
+ return base === "" ? href : `${base}${href}`;
16
+ }
@@ -8,8 +8,15 @@ import { defineSlotStyle } from "@simplix-react/ui/design";
8
8
  */
9
9
  export const sitePageStyle = defineSlotStyle({
10
10
  slot: "site-page",
11
- base: "mx-auto flex w-full min-w-0 max-w-(--site-page-wide) flex-col px-6 @max-page-narrow/page:px-4",
11
+ base: "mx-auto flex w-full min-w-0 flex-col px-6 @max-page-narrow/page:px-4",
12
12
  variants: {
13
+ // How wide the column grows: the wide tier for a page of sections, a narrower tier for a page
14
+ // that is one column of fields or rows on every window (a flow made for a phone).
15
+ width: {
16
+ wide: "max-w-(--site-page-wide)",
17
+ medium: "max-w-(--site-page-medium)",
18
+ narrow: "max-w-(--site-page-narrow)",
19
+ },
13
20
  rhythm: {
14
21
  page: "gap-5 py-8 @max-page-narrow/page:py-5",
15
22
  spaced: "gap-6 py-8",
@@ -18,7 +25,7 @@ export const sitePageStyle = defineSlotStyle({
18
25
  done: "items-center gap-5 py-16 text-center @max-page-narrow/page:py-5",
19
26
  },
20
27
  },
21
- defaultVariants: { rhythm: "page" },
28
+ defaultVariants: { rhythm: "page", width: "wide" },
22
29
  });
23
30
 
24
31
  /** The page's head: an optional eyebrow, the title and the lede. */
@@ -218,12 +225,14 @@ export const siteBadgeStyle = defineSlotStyle({
218
225
  * An action written as a link inside text. `link` is the accent's words, underlined under the pointer
219
226
  * (another step, a document); `inline` stays underlined and takes the soft ground under the pointer,
220
227
  * inside a sentence of muted words; `muted` is underlined muted words that darken under the pointer
221
- * (a way back, a view of a document beside a consent).
228
+ * (a way back, a view of a document beside a consent). The words are as small as the text they stand
229
+ * in, so the area that takes a press is widened under them to the smallest target a finger hits,
230
+ * centred on the words and drawn as nothing.
222
231
  */
223
232
  export const siteTextActionStyle = defineSlotStyle({
224
233
  slot: "site-text-action",
225
234
  base:
226
- "cursor-pointer rounded-(--site-radius-xs) border-0 bg-transparent p-0 text-left font-(family-name:--site-font-sans) underline-offset-2 outline-none transition-colors duration-(--site-duration-fast) ease-(--site-ease) focus-visible:shadow-[var(--site-focus-ring)] disabled:cursor-not-allowed disabled:text-(--site-ink-muted) disabled:no-underline",
235
+ "relative cursor-pointer rounded-(--site-radius-xs) border-0 bg-transparent p-0 text-left font-(family-name:--site-font-sans) underline-offset-2 outline-none transition-colors duration-(--site-duration-fast) ease-(--site-ease) focus-visible:shadow-[var(--site-focus-ring)] disabled:cursor-not-allowed disabled:text-(--site-ink-muted) disabled:no-underline after:absolute after:top-1/2 after:left-1/2 after:h-full after:min-h-6 after:w-full after:min-w-6 after:-translate-x-1/2 after:-translate-y-1/2 after:content-['']",
227
236
  variants: {
228
237
  kind: {
229
238
  link: "font-(--site-fw-strong) text-(--site-accent-text) no-underline hover:underline",
@@ -26,12 +26,17 @@ export interface SitePageProps {
26
26
  * centres a page that says a step is finished; `page` is every other page.
27
27
  */
28
28
  readonly rhythm?: "page" | "spaced" | "open" | "steps" | "done";
29
+ /**
30
+ * How wide the column grows: `wide` for a page of sections, `medium` or `narrow` for a page that
31
+ * stays one column of fields or rows on every window (a form, a flow made for a phone).
32
+ */
33
+ readonly width?: "wide" | "medium" | "narrow";
29
34
  readonly children: ReactNode;
30
35
  }
31
36
 
32
- /** The page column: centred, as wide as the wide tier at most, its regions one gap apart. */
33
- export function SitePage({ rhythm, children }: SitePageProps) {
34
- return <div {...slotAttributes(sitePageStyle, { rhythm })}>{children}</div>;
37
+ /** The page column: centred, as wide as its tier at most (the wide tier unless told), its regions one gap apart. */
38
+ export function SitePage({ rhythm, width, children }: SitePageProps) {
39
+ return <div {...slotAttributes(sitePageStyle, { rhythm, width })}>{children}</div>;
35
40
  }
36
41
 
37
42
  /** Props for {@link SitePageHead}. */