@sdxc/kit 2026.11.27 → 2026.11.29
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.jsonl +189 -0
- package/dist/pkg/catalog.js +1 -0
- package/dist/scaffold/render.js +2 -2
- package/package.json +2 -2
- package/registry/ui/anchor-heading.json +19 -0
- package/registry/ui/autocomplete.json +3 -3
- package/registry/ui/banner.json +3 -3
- package/registry/ui/button.json +3 -3
- package/registry/ui/callout.json +16 -0
- package/registry/ui/checkbox.json +2 -2
- package/registry/ui/code-block.json +18 -0
- package/registry/ui/confirm.json +3 -3
- package/registry/ui/copy-button.json +14 -0
- package/registry/ui/date-field.json +4 -7
- package/registry/ui/date-picker.json +3 -5
- package/registry/ui/date-range-picker.json +2 -3
- package/registry/ui/dialog-dismiss.json +2 -2
- package/registry/ui/field-parts.json +30 -0
- package/registry/ui/filter-links.json +16 -0
- package/registry/ui/form.json +3 -3
- package/registry/ui/listbox.json +2 -2
- package/registry/ui/media-grid.json +3 -3
- package/registry/ui/pager.json +16 -0
- package/registry/ui/property-list.json +3 -3
- package/registry/ui/radio-group.json +2 -2
- package/registry/ui/range-calendar.json +2 -2
- package/registry/ui/range-months.json +3 -3
- package/registry/ui/rating-input.json +3 -3
- package/registry/ui/rating.json +3 -3
- package/registry/ui/review-card.json +3 -3
- package/registry/ui/search-field.json +6 -3
- package/registry/ui/section-bar.json +3 -3
- package/registry/ui/sidebar.json +2 -2
- package/registry/ui/table-of-contents.json +17 -0
- package/registry/ui/text-field.json +5 -9
- package/registry/ui/time-field.json +4 -7
- package/registry/ui/timeline.json +3 -3
- package/registry/ui/typeset.json +2 -2
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "radio-group",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.29",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"RadioGroup"
|
|
7
7
|
],
|
|
8
8
|
"source": {
|
|
9
9
|
"path": "radio-group.tsx",
|
|
10
|
-
"content": "/**\n * A set of mutually exclusive options built from native `<input\n * type=\"radio\">` controls sharing one grouping name, rendered as a\n * `role=\"radiogroup\"` host wrapping a run of {@link RadioGroup.Radio}\n * instances. Each option pairs a visually hidden native input — carrying\n * every focus, keyboard, and form-submission semantic the platform already\n * provides — with a styled visual indicator that reads the input's own\n * `:checked` and `:focus-visible` states through sibling selectors.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, pseudoContent, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, flexRow, gap, items, justify, relative, shrink } from \"@sdxc/u/layout\";\nimport { bs, is } from \"@sdxc/u/size\";\nimport { after, precededBy, when } from \"@sdxc/u/state\";\nimport { scale } from \"@sdxc/u/transform\";\nimport { text } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\n/**\n * `role=\"radiogroup\"` applied through {@link attrs} unless a consumer\n * supplies its own `role`, announcing the host as a radio group landmark to\n * assistive technology.\n */\nconst DEFAULT_ROLE = \"radiogroup\";\n\n/**\n * Default {@link RadioGroup.Props} orientation, applied when `orientation`\n * is omitted, laying options out in a single column.\n */\nconst DEFAULT_ORIENTATION: RadioGroup.Orientation = \"vertical\";\n\n/**\n * Prop types for {@link RadioGroup} and its {@link RadioGroup.Radio}\n * compound part.\n */\nexport namespace RadioGroup {\n\t/**\n\t * Axis a group's options lay out along: a single column, or a single row.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Value {@link RadioGroup} stores in component context so every\n\t * {@link RadioGroup.Radio} nested inside shares the same native grouping\n\t * name without a consumer repeating it on each option.\n\t */\n\texport interface Context {\n\t\t/** Shared `name` every {@link RadioGroup.Radio} reads unless it sets its own. */\n\t\tname: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link RadioGroup}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Native grouping name shared by every {@link RadioGroup.Radio} nested\n\t\t * inside. Defaults to the group's own {@link Handle.id | stable\n\t\t * instance id} so options group correctly without a consumer setting one.\n\t\t */\n\t\tname?: string;\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n\n\t/**\n\t * Props accepted by {@link RadioGroup.Radio}.\n\t */\n\texport interface RadioProps extends Omit<TagProps<\"label\">, \"children\"> {\n\t\t/** Value submitted with the enclosing form when this option is selected. */\n\t\tvalue: string;\n\t\t/**\n\t\t * Native grouping name for this option's underlying input. Defaults to\n\t\t * the name provided by the nearest ancestor {@link RadioGroup} — set\n\t\t * this only to opt a single option out of its group's shared name.\n\t\t */\n\t\tname?: string;\n\t\t/** Whether this option starts selected, for a form that leaves selection tracking to the browser. */\n\t\tdefaultChecked?: boolean;\n\t\t/** Whether this option is selected, for a form that tracks selection itself. */\n\t\tchecked?: boolean;\n\t\t/** Whether this option is inert and excluded from the group's tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the enclosing native radio group as requiring one option selected. */\n\t\trequired?: boolean;\n\t\t/** The option's visible label text, associated with the input by native nesting. */\n\t\tchildren?: RemixNode;\n\t
|
|
10
|
+
"content": "/**\n * A set of mutually exclusive options built from native `<input\n * type=\"radio\">` controls sharing one grouping name, rendered as a\n * `role=\"radiogroup\"` host wrapping a run of {@link RadioGroup.Radio}\n * instances. Each option pairs a visually hidden native input — carrying\n * every focus, keyboard, and form-submission semantic the platform already\n * provides — with a styled visual indicator that reads the input's own\n * `:checked` and `:focus-visible` states through sibling selectors.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { bg, border, fg, outline } from \"@sdxc/u/color\";\nimport { opacity, rounded, transition } from \"@sdxc/u/effects\";\nimport { cursor, pseudoContent, mergeMix } from \"@sdxc/u/general\";\nimport { flex, flexCol, flexRow, gap, items, justify, relative, shrink } from \"@sdxc/u/layout\";\nimport { bs, is } from \"@sdxc/u/size\";\nimport { after, precededBy, when } from \"@sdxc/u/state\";\nimport { scale } from \"@sdxc/u/transform\";\nimport { text } from \"@sdxc/u/typography\";\nimport { attrs } from \"remix/component\";\n\n/**\n * `role=\"radiogroup\"` applied through {@link attrs} unless a consumer\n * supplies its own `role`, announcing the host as a radio group landmark to\n * assistive technology.\n */\nconst DEFAULT_ROLE = \"radiogroup\";\n\n/**\n * Default {@link RadioGroup.Props} orientation, applied when `orientation`\n * is omitted, laying options out in a single column.\n */\nconst DEFAULT_ORIENTATION: RadioGroup.Orientation = \"vertical\";\n\n/**\n * Prop types for {@link RadioGroup} and its {@link RadioGroup.Radio}\n * compound part.\n */\nexport namespace RadioGroup {\n\t/**\n\t * Axis a group's options lay out along: a single column, or a single row.\n\t */\n\texport type Orientation = \"horizontal\" | \"vertical\";\n\n\t/**\n\t * Value {@link RadioGroup} stores in component context so every\n\t * {@link RadioGroup.Radio} nested inside shares the same native grouping\n\t * name without a consumer repeating it on each option.\n\t */\n\texport interface Context {\n\t\t/** Shared `name` every {@link RadioGroup.Radio} reads unless it sets its own. */\n\t\tname: string;\n\t}\n\n\t/**\n\t * Props accepted by {@link RadioGroup}.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/**\n\t\t * Native grouping name shared by every {@link RadioGroup.Radio} nested\n\t\t * inside. Defaults to the group's own {@link Handle.id | stable\n\t\t * instance id} so options group correctly without a consumer setting one.\n\t\t */\n\t\tname?: string;\n\t\t/** Layout axis. Defaults to {@link DEFAULT_ORIENTATION}. */\n\t\torientation?: Orientation;\n\t}\n\n\t/**\n\t * Props accepted by {@link RadioGroup.Radio}.\n\t */\n\texport interface RadioProps extends Omit<TagProps<\"label\">, \"children\"> {\n\t\t/** Value submitted with the enclosing form when this option is selected. */\n\t\tvalue: string;\n\t\t/**\n\t\t * Native grouping name for this option's underlying input. Defaults to\n\t\t * the name provided by the nearest ancestor {@link RadioGroup} — set\n\t\t * this only to opt a single option out of its group's shared name.\n\t\t */\n\t\tname?: string;\n\t\t/** Whether this option starts selected, for a form that leaves selection tracking to the browser. */\n\t\tdefaultChecked?: boolean;\n\t\t/** Whether this option is selected, for a form that tracks selection itself. */\n\t\tchecked?: boolean;\n\t\t/** Whether this option is inert and excluded from the group's tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks the enclosing native radio group as requiring one option selected. */\n\t\trequired?: boolean;\n\t\t/** The option's visible label text, associated with the input by native nesting. */\n\t\tchildren?: RemixNode;\n\t}\n}\n\n/**\n * Renders the group host: a `role=\"radiogroup\"` `<div>` laying its\n * {@link RadioGroup.Radio} options in a column, or a row when\n * `orientation` is `\"horizontal\"`, giving every option a shared, stable `name`.\n *\n * @param handle Runtime handle carrying the host `<div>`'s props and providing {@link RadioGroup.Context}.\n * @returns The render function producing the group's markup.\n * @example\n * <RadioGroup aria-label={t(\"shipping.method\")}>\n * \t<RadioGroup.Radio value=\"standard\">{t(\"shipping.standard\")}</RadioGroup.Radio>\n * \t<RadioGroup.Radio value=\"express\">{t(\"shipping.express\")}</RadioGroup.Radio>\n * </RadioGroup>\n * @example\n * <RadioGroup aria-label={t(\"size.label\")} orientation=\"horizontal\">\n * \t<RadioGroup.Radio value=\"sm\">{t(\"size.small\")}</RadioGroup.Radio>\n * \t<RadioGroup.Radio value=\"md\">{t(\"size.medium\")}</RadioGroup.Radio>\n * \t<RadioGroup.Radio value=\"lg\">{t(\"size.large\")}</RadioGroup.Radio>\n * </RadioGroup>\n */\nexport function RadioGroup(handle: Handle<RadioGroup.Props, RadioGroup.Context>) {\n\treturn () => {\n\t\tlet { name, orientation, mix, ...rest } = handle.props;\n\t\tlet resolvedName = name ?? handle.id;\n\t\tlet resolvedOrientation = orientation ?? DEFAULT_ORIENTATION;\n\n\t\thandle.context.set({ name: resolvedName });\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\tdata-orientation={resolvedOrientation}\n\t\t\t\taria-orientation={resolvedOrientation}\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tattrs({ role: DEFAULT_ROLE }),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tflexCol(),\n\t\t\t\t\t\twhen('&[data-orientation=\"horizontal\"]', flexRow()),\n\t\t\t\t\t\tgap(\"0.5rem\"),\n\t\t\t\t\t\twhen('&[data-orientation=\"horizontal\"]', gap(\"1rem\")),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n}\n\n/**\n * Renders a single option: a `<label>` pairing a hidden native `<input type=\"radio\">` with\n * an indicator driven by its checked, focus and disabled state. `--ui-radio-size` and\n * `--ui-radio-mark-size` size the indicator; `mix` styles the label.\n *\n * @param handle Runtime handle carrying the host `<label>`'s props.\n * @returns The render function producing the option's markup.\n * @example\n * <RadioGroup.Radio value=\"dog\">{t(\"pet.dog\")}</RadioGroup.Radio>\n * @example\n * <RadioGroup.Radio value=\"cat\" defaultChecked>{t(\"pet.cat\")}</RadioGroup.Radio>\n * @example\n * <RadioGroup.Radio value=\"hamster\" disabled>{t(\"pet.hamster\")}</RadioGroup.Radio>\n */\nRadioGroup.Radio = function RadioGroupRadio(handle: Handle<RadioGroup.RadioProps>) {\n\treturn () => {\n\t\tlet { value, name, checked, defaultChecked, disabled, required, children, mix, ...rest } =\n\t\t\thandle.props;\n\t\tlet context = handle.context.get(RadioGroup);\n\t\tlet resolvedName = name ?? context.name;\n\n\t\treturn (\n\t\t\t<label\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tcursor(\"default\"),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\ttext(\"sm\"),\n\t\t\t\t\t\twhen(\"&:has(input:disabled)\", [cursor(\"not-allowed\"), opacity(50)]),\n\t\t\t\t\t\tgap(\"0.5rem\"),\n\t\t\t\t\t\tfg(\"neutral.emphasis\"),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<input\n\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\tid={handle.id}\n\t\t\t\t\tvalue={value}\n\t\t\t\t\tname={resolvedName}\n\t\t\t\t\tchecked={checked}\n\t\t\t\t\tdefaultChecked={defaultChecked}\n\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\trequired={required}\n\t\t\t\t\tmix={[visuallyHidden()]}\n\t\t\t\t/>\n\t\t\t\t<span\n\t\t\t\t\tdata-slot=\"indicator\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\trelative(),\n\t\t\t\t\t\tflex(),\n\t\t\t\t\t\tshrink(),\n\t\t\t\t\t\titems(\"center\"),\n\t\t\t\t\t\tjustify(\"center\"),\n\t\t\t\t\t\tis(\"var(--ui-radio-size, 1.25rem)\"),\n\t\t\t\t\t\tbs(\"var(--ui-radio-size, 1.25rem)\"),\n\t\t\t\t\t\tafter([\n\t\t\t\t\t\t\tis(\"var(--ui-radio-mark-size, 0.625rem)\"),\n\t\t\t\t\t\t\tbs(\"var(--ui-radio-mark-size, 0.625rem)\"),\n\t\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\t\tbg(\"brand.onSolid\"),\n\t\t\t\t\t\t\ttransition(\"transform\"),\n\t\t\t\t\t\t\tpseudoContent('\"\"'),\n\t\t\t\t\t\t\tscale(0),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\trounded(\"full\"),\n\t\t\t\t\t\tborder({ color: \"neutral.strong\", width: 2 }),\n\t\t\t\t\t\tbg(\"neutral.tint\"),\n\t\t\t\t\t\ttransition(\"background-color, border-color\"),\n\t\t\t\t\t\tprecededBy(\"input:checked\", after(scale(1))),\n\t\t\t\t\t\tprecededBy(\"input:checked\", [border(\"brand.solid\"), bg(\"brand.solid\")]),\n\t\t\t\t\t\tprecededBy(\"input:focus-visible\", outline({ color: \"brand.ring\", offset: 2 })),\n\t\t\t\t\t]}\n\t\t\t\t/>\n\t\t\t\t{children}\n\t\t\t</label>\n\t\t);\n\t};\n};\n"
|
|
11
11
|
},
|
|
12
12
|
"test": null
|
|
13
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "range-calendar",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.29",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"calendar",
|
|
6
6
|
"input"
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "range-calendar.tsx",
|
|
13
|
-
"content": "/**\n * A calendar surface for choosing a start and end date as one connected\n * range, sharing every header, grid, and row part with {@link Calendar} and\n * layering range position on top of its day cell. Used bare, with no\n * composed children, it renders a pair of native `<input type=\"date\">`\n * fields instead — start and end, each independently keyboard-operable —\n * ready for the `calendarKeys()`/`rangePreview()` mixins a consumer attaches\n * to turn the composed grid into a live, drag- or arrow-key-extended range.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, fg } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { flex, gap, items } from \"@sdxc/u/layout\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Input } from \"@sdxc/ui/input\";\n\n/** Semantic color role {@link RangeCalendar}'s bare fallback pair falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: RangeCalendar.Color = \"neutral\";\n\n/**\n * Prop types for {@link RangeCalendar} and its compound parts. Every part\n * but {@link RangeCalendar.Cell} aliases {@link Calendar}'s matching part,\n * sharing its header, grid, and row markup.\n */\nexport namespace RangeCalendar {\n\t/**\n\t * Semantic color role for the bare fallback pair's keyboard focus rings,\n\t * mapped to `--ui-*` variables like {@link Calendar.Color}. The composed\n\t * grid's day cells always use fixed semantic roles, regardless of this value.\n\t */\n\texport type Color = Calendar.Color;\n\n\t/**\n\t * Per-part styling for the bare fallback pair's two internally composed\n\t * inputs, layered after each input's own built-in styling. Style the\n\t * composed grid's parts through {@link Calendar}'s own compound parts.\n\t */\n\texport interface PartsProps {\n\t\t/** Styling for the bare fallback's start-date input, rendered through {@link Input}. */\n\t\tstart?: TagProps<\"input\">[\"mix\"];\n\t\t/** Styling for the bare fallback's end-date input, rendered through {@link Input}. */\n\t\tend?: TagProps<\"input\">[\"mix\"];\n\t}\n\n\t/**\n\t * Props accepted by {@link RangeCalendar}. Composing\n\t * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n\t * renders the visual month surface; omitting `children` renders a bare native `<input type=\"date\">` pair from the fields below.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback pair's focus rings. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback's start-date input. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback's end-date input. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the bare fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the bare fallback pair's inputs required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the bare fallback pair's inputs, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Accessible label for the bare fallback pair's start-date input. Read only when `children` is unset. */\n\t\tstartLabel?: string;\n\t\t/** Accessible label for the bare fallback pair's end-date input. Read only when `children` is unset. */\n\t\tendLabel?: string;\n\t\t/** Per-part styling for the bare fallback pair's internally composed inputs. */\n\t\tparts?: PartsProps;\n\t}\n\n\t/** Every prop {@link Calendar.HeaderProps} accepts, unchanged. */\n\texport interface HeaderProps extends Calendar.HeaderProps {}\n\n\t/** Every prop {@link Calendar.PreviousButtonProps} accepts, unchanged. */\n\texport interface PreviousButtonProps extends Calendar.PreviousButtonProps {}\n\n\t/** Every prop {@link Calendar.NextButtonProps} accepts, unchanged. */\n\texport interface NextButtonProps extends Calendar.NextButtonProps {}\n\n\t/** Every prop {@link Calendar.HeadingProps} accepts, unchanged. */\n\texport interface HeadingProps extends Calendar.HeadingProps {}\n\n\t/** Every prop {@link Calendar.GridProps} accepts, unchanged. */\n\texport interface GridProps extends Calendar.GridProps {}\n\n\t/** Every prop {@link Calendar.GridHeaderProps} accepts, unchanged. */\n\texport interface GridHeaderProps extends Calendar.GridHeaderProps {}\n\n\t/** Every prop {@link Calendar.RowProps} accepts, unchanged. */\n\texport interface RowProps extends Calendar.RowProps {}\n\n\t/** Every prop {@link Calendar.HeaderCellProps} accepts, unchanged. */\n\texport interface HeaderCellProps extends Calendar.HeaderCellProps {}\n\n\t/** Every prop {@link Calendar.GridBodyProps} accepts, unchanged. */\n\texport interface GridBodyProps extends Calendar.GridBodyProps {}\n\n\t/**\n\t * Every prop {@link Calendar.CellProps} accepts, unchanged. Set\n\t * `data-selection-start` on the range's first day, `data-selection-end`\n\t * on its last, and `aria-selected=\"true\"` alone on the days between — each read straight off what the consumer sets on this instance.\n\t */\n\texport interface CellProps extends Calendar.CellProps {}\n}\n\n/**\n * Renders {@link RangeCalendar}'s root through {@link Calendar}. Composing\n * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n * renders the visual month surface; omitting `children` renders a bare, script-free native `<input type=\"date\">` pair from this instance's own fields.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the range calendar's markup.\n * @example\n * <RangeCalendar startLabel={t(\"form.stay.checkIn\")} endLabel={t(\"form.stay.checkOut\")} startName=\"checkIn\" endName=\"checkOut\" />\n * @example\n * <RangeCalendar aria-label={t(\"calendar.label\")}>\n * \t<RangeCalendar.Header>\n * \t\t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t\t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</RangeCalendar.Header>\n * \t<RangeCalendar.Grid aria-label={monthLabel}>\n * \t\t<RangeCalendar.GridHeader>\n * \t\t\t<RangeCalendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<RangeCalendar.HeaderCell key={day}>{day}</RangeCalendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</RangeCalendar.Row>\n * \t\t</RangeCalendar.GridHeader>\n * \t\t<RangeCalendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<RangeCalendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<RangeCalendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.inRange ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-start={day.iso === range.start ? \"\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-end={day.iso === range.end ? \"\" : undefined}\n * \t\t\t\t\t\t>\n * \t\t\t\t\t\t\t{day.label}\n * \t\t\t\t\t\t</RangeCalendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</RangeCalendar.Row>\n * \t\t\t))}\n * \t\t</RangeCalendar.GridBody>\n * \t</RangeCalendar.Grid>\n * </RangeCalendar>\n */\nexport function RangeCalendar(handle: Handle<RangeCalendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tstartLabel,\n\t\t\tendLabel,\n\t\t\tparts,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\tif (import.meta.env?.DEV && !children) {\n\t\t\tif (!startLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs a \"startLabel\" describing the range\\'s start for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!endLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs an \"endLabel\" describing the range\\'s end for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<Calendar {...rest} mix={mix}>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-slot=\"fields\"\n\t\t\t\t\t\tmix={[attrs({ role: \"group\" }), flex(), items(\"center\"), gap(\"0.5rem\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"start-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={startName}\n\t\t\t\t\t\t\tvalue={startValue}\n\t\t\t\t\t\t\tdefaultValue={startDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={startLabel}\n\t\t\t\t\t\t\tmix={parts?.start}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"end-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={endName}\n\t\t\t\t\t\t\tvalue={endValue}\n\t\t\t\t\t\t\tdefaultValue={endDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={endLabel}\n\t\t\t\t\t\t\tmix={parts?.end}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t</Calendar>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link RangeCalendar.HeaderProps.children} as the nav row: identical\n * to {@link Calendar.Header}, since {@link RangeCalendar} reuses\n * {@link Calendar}'s grid markup for its own header.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the nav row's markup.\n * @example\n * <RangeCalendar.Header>\n * \t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * </RangeCalendar.Header>\n */\nRangeCalendar.Header = Calendar.Header;\n\n/**\n * Renders a control standing for \"show the previous month\": identical to\n * {@link Calendar.PreviousButton}.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nRangeCalendar.PreviousButton = Calendar.PreviousButton;\n\n/**\n * Renders a control standing for \"show the following month\": identical to\n * {@link Calendar.NextButton}.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nRangeCalendar.NextButton = Calendar.NextButton;\n\n/**\n * Renders the calendar's visible month/year caption: identical to\n * {@link Calendar.Heading}.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the caption's markup.\n * @example\n * <RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n */\nRangeCalendar.Heading = Calendar.Heading;\n\n/**\n * Renders the day grid's native `<table>` host: identical to\n * {@link Calendar.Grid}.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <RangeCalendar.Grid aria-label={monthLabel}>\n * \t<RangeCalendar.GridHeader>...</RangeCalendar.GridHeader>\n * \t<RangeCalendar.GridBody>...</RangeCalendar.GridBody>\n * </RangeCalendar.Grid>\n */\nRangeCalendar.Grid = Calendar.Grid;\n\n/**\n * Renders the grid's `<thead>` host: identical to {@link Calendar.GridHeader}.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <RangeCalendar.GridHeader>\n * \t<RangeCalendar.Row>\n * \t\t<RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n * \t</RangeCalendar.Row>\n * </RangeCalendar.GridHeader>\n */\nRangeCalendar.GridHeader = Calendar.GridHeader;\n\n/**\n * Renders a native `<tr>` host: identical to {@link Calendar.Row}. Composes\n * a row of {@link RangeCalendar.HeaderCell} inside\n * {@link RangeCalendar.GridHeader}, or a week's row of {@link RangeCalendar.Cell} inside {@link RangeCalendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <RangeCalendar.Row>\n * \t<RangeCalendar.Cell>{day.label}</RangeCalendar.Cell>\n * </RangeCalendar.Row>\n */\nRangeCalendar.Row = Calendar.Row;\n\n/**\n * Renders a weekday abbreviation: identical to {@link Calendar.HeaderCell}.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the weekday header's markup.\n * @example\n * <RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n */\nRangeCalendar.HeaderCell = Calendar.HeaderCell;\n\n/**\n * Renders the grid's `<tbody>` host: identical to {@link Calendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <RangeCalendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<RangeCalendar.Row key={week[0].iso}>...</RangeCalendar.Row>\n * \t))}\n * </RangeCalendar.GridBody>\n */\nRangeCalendar.GridBody = Calendar.GridBody;\n\n/**\n * Renders one calendar day for {@link RangeCalendar}, building on\n * {@link Calendar.Cell}. `data-selection-start`/`data-selection-end`\n * square off each end's outer corners so the range reads as one unbroken bar, driven by whatever state the consumer sets for the `calendarKeys()`/`rangePreview()` mixins.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the day's markup.\n * @example\n * <RangeCalendar.Cell data-selection-start=\"\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell aria-selected=\"true\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell data-selection-end=\"\">{day.label}</RangeCalendar.Cell>\n */\nRangeCalendar.Cell = function RangeCalendarCell(handle: Handle<RangeCalendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Calendar.Cell\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A day is the range's opening, its closing, both at once, or one of the days\n\t\t\t\t\t\t * between. The four are written under selectors that match one apiece, so each\n\t\t\t\t\t\t * day keeps its own shape however the cascade orders the set.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-selection-start]:not([data-selection-end])\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[data-selection-end]:not([data-selection-start])\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A range of one day opens and closes on itself, so it reads as a single day.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-selection-start][data-selection-end]\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[aria-selected=\"true\"]:not([data-selection-start]):not([data-selection-end])', [\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The days between carry the range across the row, so the band reads as one\n\t\t\t\t\t\t\t * run at a glance while the two ends stay the strongest thing in the month.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tbg(\"brand.bg-tint-hover\"),\n\t\t\t\t\t\t\tfg(\"brand.emphasis\"),\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
13
|
+
"content": "/**\n * A calendar surface for choosing a start and end date as one connected\n * range, sharing every header, grid, and row part with {@link Calendar} and\n * layering range position on top of its day cell. Used bare, with no\n * composed children, it renders a pair of native `<input type=\"date\">`\n * fields instead — start and end, each independently keyboard-operable —\n * ready for the `calendarKeys()`/`rangePreview()` mixins a consumer attaches\n * to turn the composed grid into a live, drag- or arrow-key-extended range.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps } from \"remix/component\";\n\nimport { bg, fg } from \"@sdxc/u/color\";\nimport { roundedCorner } from \"@sdxc/u/effects\";\nimport { mergeMix } from \"@sdxc/u/general\";\nimport { flex, gap, items } from \"@sdxc/u/layout\";\nimport { when } from \"@sdxc/u/state\";\nimport { attrs } from \"remix/component\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Input } from \"@sdxc/ui/input\";\n\n/** Semantic color role {@link RangeCalendar}'s bare fallback pair falls back to when `color` is omitted. */\nconst DEFAULT_COLOR: RangeCalendar.Color = \"neutral\";\n\n/**\n * Prop types for {@link RangeCalendar} and its compound parts. Every part\n * but {@link RangeCalendar.Cell} aliases {@link Calendar}'s matching part,\n * sharing its header, grid, and row markup.\n */\nexport namespace RangeCalendar {\n\t/**\n\t * Semantic color role for the bare fallback pair's keyboard focus rings,\n\t * mapped to `--ui-*` variables like {@link Calendar.Color}. The composed\n\t * grid's day cells always use fixed semantic roles, regardless of this value.\n\t */\n\texport type Color = Calendar.Color;\n\n\t/**\n\t * Props accepted by {@link RangeCalendar}. Composing\n\t * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n\t * renders the visual month surface; omitting `children` renders a bare native `<input type=\"date\">` pair from the fields below,\n\t * which `[data-slot=\"start-input\"]` and `[data-slot=\"end-input\"]` selectors on `mix` reach.\n\t */\n\texport interface Props extends TagProps<\"div\"> {\n\t\t/** Semantic color role for the bare fallback pair's focus rings. Defaults to {@link DEFAULT_COLOR}. */\n\t\tcolor?: Color;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback's start-date input. */\n\t\tstartName?: string;\n\t\t/** Native `name` submitted with an enclosing form, read only by the bare fallback's end-date input. */\n\t\tendName?: string;\n\t\t/** Current start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tstartValue?: string;\n\t\t/** Current end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair a consumer tracks itself. */\n\t\tendValue?: string;\n\t\t/** Initial start-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tstartDefaultValue?: string;\n\t\t/** Initial end-of-range value, in `YYYY-MM-DD` form, for a bare fallback pair left to the platform's own uncontrolled state. */\n\t\tendDefaultValue?: string;\n\t\t/** Earliest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmin?: string;\n\t\t/** Latest accepted date, in `YYYY-MM-DD` form, read by both of the bare fallback pair's inputs. */\n\t\tmax?: string;\n\t\t/** Granularity, in days, both of the bare fallback pair's values must fall on. */\n\t\tstep?: number;\n\t\t/** Marks both of the bare fallback pair's inputs required for their enclosing form. */\n\t\trequired?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs inert and excluded from the tab order. */\n\t\tdisabled?: boolean;\n\t\t/** Marks both of the bare fallback pair's inputs' values fixed, while keeping them focusable and included in form submission. */\n\t\treadOnly?: boolean;\n\t\t/** Native autofill hint for both of the bare fallback pair's inputs, e.g. `\"bday\"`. */\n\t\tautoComplete?: string;\n\t\t/** Accessible label for the bare fallback pair's start-date input. Read only when `children` is unset. */\n\t\tstartLabel?: string;\n\t\t/** Accessible label for the bare fallback pair's end-date input. Read only when `children` is unset. */\n\t\tendLabel?: string;\n\t}\n\n\t/** Every prop {@link Calendar.HeaderProps} accepts, unchanged. */\n\texport interface HeaderProps extends Calendar.HeaderProps {}\n\n\t/** Every prop {@link Calendar.PreviousButtonProps} accepts, unchanged. */\n\texport interface PreviousButtonProps extends Calendar.PreviousButtonProps {}\n\n\t/** Every prop {@link Calendar.NextButtonProps} accepts, unchanged. */\n\texport interface NextButtonProps extends Calendar.NextButtonProps {}\n\n\t/** Every prop {@link Calendar.HeadingProps} accepts, unchanged. */\n\texport interface HeadingProps extends Calendar.HeadingProps {}\n\n\t/** Every prop {@link Calendar.GridProps} accepts, unchanged. */\n\texport interface GridProps extends Calendar.GridProps {}\n\n\t/** Every prop {@link Calendar.GridHeaderProps} accepts, unchanged. */\n\texport interface GridHeaderProps extends Calendar.GridHeaderProps {}\n\n\t/** Every prop {@link Calendar.RowProps} accepts, unchanged. */\n\texport interface RowProps extends Calendar.RowProps {}\n\n\t/** Every prop {@link Calendar.HeaderCellProps} accepts, unchanged. */\n\texport interface HeaderCellProps extends Calendar.HeaderCellProps {}\n\n\t/** Every prop {@link Calendar.GridBodyProps} accepts, unchanged. */\n\texport interface GridBodyProps extends Calendar.GridBodyProps {}\n\n\t/**\n\t * Every prop {@link Calendar.CellProps} accepts, unchanged. Set\n\t * `data-selection-start` on the range's first day, `data-selection-end`\n\t * on its last, and `aria-selected=\"true\"` alone on the days between — each read straight off what the consumer sets on this instance.\n\t */\n\texport interface CellProps extends Calendar.CellProps {}\n}\n\n/**\n * Renders {@link RangeCalendar}'s root through {@link Calendar}. Composing\n * {@link RangeCalendar.Header} and {@link RangeCalendar.Grid} as `children`\n * renders the visual month surface; omitting `children` renders a bare, script-free native `<input type=\"date\">` pair from this instance's own fields.\n *\n * @param handle Runtime handle carrying the root element's props.\n * @returns The render function producing the range calendar's markup.\n * @example\n * <RangeCalendar startLabel={t(\"form.stay.checkIn\")} endLabel={t(\"form.stay.checkOut\")} startName=\"checkIn\" endName=\"checkOut\" />\n * @example\n * <RangeCalendar aria-label={t(\"calendar.label\")}>\n * \t<RangeCalendar.Header>\n * \t\t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t\t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t\t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * \t</RangeCalendar.Header>\n * \t<RangeCalendar.Grid aria-label={monthLabel}>\n * \t\t<RangeCalendar.GridHeader>\n * \t\t\t<RangeCalendar.Row>\n * \t\t\t\t{weekdayLabels.map((day) => (\n * \t\t\t\t\t<RangeCalendar.HeaderCell key={day}>{day}</RangeCalendar.HeaderCell>\n * \t\t\t\t))}\n * \t\t\t</RangeCalendar.Row>\n * \t\t</RangeCalendar.GridHeader>\n * \t\t<RangeCalendar.GridBody>\n * \t\t\t{weeks.map((week) => (\n * \t\t\t\t<RangeCalendar.Row key={week[0].iso}>\n * \t\t\t\t\t{week.map((day) => (\n * \t\t\t\t\t\t<RangeCalendar.Cell\n * \t\t\t\t\t\t\tkey={day.iso}\n * \t\t\t\t\t\t\taria-selected={day.inRange ? \"true\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-start={day.iso === range.start ? \"\" : undefined}\n * \t\t\t\t\t\t\tdata-selection-end={day.iso === range.end ? \"\" : undefined}\n * \t\t\t\t\t\t>\n * \t\t\t\t\t\t\t{day.label}\n * \t\t\t\t\t\t</RangeCalendar.Cell>\n * \t\t\t\t\t))}\n * \t\t\t\t</RangeCalendar.Row>\n * \t\t\t))}\n * \t\t</RangeCalendar.GridBody>\n * \t</RangeCalendar.Grid>\n * </RangeCalendar>\n */\nexport function RangeCalendar(handle: Handle<RangeCalendar.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tcolor,\n\t\t\tstartName,\n\t\t\tendName,\n\t\t\tstartValue,\n\t\t\tendValue,\n\t\t\tstartDefaultValue,\n\t\t\tendDefaultValue,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tstep,\n\t\t\trequired,\n\t\t\tdisabled,\n\t\t\treadOnly,\n\t\t\tautoComplete,\n\t\t\tstartLabel,\n\t\t\tendLabel,\n\t\t\tchildren,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet resolvedColor = color ?? DEFAULT_COLOR;\n\n\t\tif (import.meta.env?.DEV && !children) {\n\t\t\tif (!startLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs a \"startLabel\" describing the range\\'s start for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!endLabel) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'RangeCalendar: falling back to a plain \"input type=date\" pair needs an \"endLabel\" describing the range\\'s end for assistive technology.',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (\n\t\t\t<Calendar {...rest} mix={mix}>\n\t\t\t\t{children ?? (\n\t\t\t\t\t<div\n\t\t\t\t\t\tdata-slot=\"fields\"\n\t\t\t\t\t\tmix={[attrs({ role: \"group\" }), flex(), items(\"center\"), gap(\"0.5rem\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"start-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={startName}\n\t\t\t\t\t\t\tvalue={startValue}\n\t\t\t\t\t\t\tdefaultValue={startDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={startLabel}\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<Input\n\t\t\t\t\t\t\ttype=\"date\"\n\t\t\t\t\t\t\tdata-slot=\"end-input\"\n\t\t\t\t\t\t\tcolor={resolvedColor}\n\t\t\t\t\t\t\tname={endName}\n\t\t\t\t\t\t\tvalue={endValue}\n\t\t\t\t\t\t\tdefaultValue={endDefaultValue}\n\t\t\t\t\t\t\tmin={min}\n\t\t\t\t\t\t\tmax={max}\n\t\t\t\t\t\t\tstep={step}\n\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\tdisabled={disabled}\n\t\t\t\t\t\t\treadOnly={readOnly}\n\t\t\t\t\t\t\tautoComplete={autoComplete}\n\t\t\t\t\t\t\taria-label={endLabel}\n\t\t\t\t\t\t/>\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t</Calendar>\n\t\t);\n\t};\n}\n\n/**\n * Renders {@link RangeCalendar.HeaderProps.children} as the nav row: identical\n * to {@link Calendar.Header}, since {@link RangeCalendar} reuses\n * {@link Calendar}'s grid markup for its own header.\n *\n * @param handle Runtime handle carrying the host `<header>`'s props.\n * @returns The render function producing the nav row's markup.\n * @example\n * <RangeCalendar.Header>\n * \t<RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n * \t<RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n * \t<RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n * </RangeCalendar.Header>\n */\nRangeCalendar.Header = Calendar.Header;\n\n/**\n * Renders a control standing for \"show the previous month\": identical to\n * {@link Calendar.PreviousButton}.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <RangeCalendar.PreviousButton aria-label={t(\"calendar.previous\")} />\n */\nRangeCalendar.PreviousButton = Calendar.PreviousButton;\n\n/**\n * Renders a control standing for \"show the following month\": identical to\n * {@link Calendar.NextButton}.\n *\n * @param handle Runtime handle carrying the host `<button>`'s props.\n * @returns The render function producing the control's markup.\n * @example\n * <RangeCalendar.NextButton aria-label={t(\"calendar.next\")} />\n */\nRangeCalendar.NextButton = Calendar.NextButton;\n\n/**\n * Renders the calendar's visible month/year caption: identical to\n * {@link Calendar.Heading}.\n *\n * @param handle Runtime handle carrying the host heading element's props.\n * @returns The render function producing the caption's markup.\n * @example\n * <RangeCalendar.Heading>{monthLabel}</RangeCalendar.Heading>\n */\nRangeCalendar.Heading = Calendar.Heading;\n\n/**\n * Renders the day grid's native `<table>` host: identical to\n * {@link Calendar.Grid}.\n *\n * @param handle Runtime handle carrying the host `<table>`'s props.\n * @returns The render function producing the grid's markup.\n * @example\n * <RangeCalendar.Grid aria-label={monthLabel}>\n * \t<RangeCalendar.GridHeader>...</RangeCalendar.GridHeader>\n * \t<RangeCalendar.GridBody>...</RangeCalendar.GridBody>\n * </RangeCalendar.Grid>\n */\nRangeCalendar.Grid = Calendar.Grid;\n\n/**\n * Renders the grid's `<thead>` host: identical to {@link Calendar.GridHeader}.\n *\n * @param handle Runtime handle carrying the host `<thead>`'s props.\n * @returns The render function producing the header section's markup.\n * @example\n * <RangeCalendar.GridHeader>\n * \t<RangeCalendar.Row>\n * \t\t<RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n * \t</RangeCalendar.Row>\n * </RangeCalendar.GridHeader>\n */\nRangeCalendar.GridHeader = Calendar.GridHeader;\n\n/**\n * Renders a native `<tr>` host: identical to {@link Calendar.Row}. Composes\n * a row of {@link RangeCalendar.HeaderCell} inside\n * {@link RangeCalendar.GridHeader}, or a week's row of {@link RangeCalendar.Cell} inside {@link RangeCalendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tr>`'s props.\n * @returns The render function producing the row's markup.\n * @example\n * <RangeCalendar.Row>\n * \t<RangeCalendar.Cell>{day.label}</RangeCalendar.Cell>\n * </RangeCalendar.Row>\n */\nRangeCalendar.Row = Calendar.Row;\n\n/**\n * Renders a weekday abbreviation: identical to {@link Calendar.HeaderCell}.\n *\n * @param handle Runtime handle carrying the host `<th>`'s props.\n * @returns The render function producing the weekday header's markup.\n * @example\n * <RangeCalendar.HeaderCell>{t(\"calendar.weekdays.sun\")}</RangeCalendar.HeaderCell>\n */\nRangeCalendar.HeaderCell = Calendar.HeaderCell;\n\n/**\n * Renders the grid's `<tbody>` host: identical to {@link Calendar.GridBody}.\n *\n * @param handle Runtime handle carrying the host `<tbody>`'s props.\n * @returns The render function producing the body section's markup.\n * @example\n * <RangeCalendar.GridBody>\n * \t{weeks.map((week) => (\n * \t\t<RangeCalendar.Row key={week[0].iso}>...</RangeCalendar.Row>\n * \t))}\n * </RangeCalendar.GridBody>\n */\nRangeCalendar.GridBody = Calendar.GridBody;\n\n/**\n * Renders one calendar day for {@link RangeCalendar}, building on\n * {@link Calendar.Cell}. `data-selection-start`/`data-selection-end`\n * square off each end's outer corners so the range reads as one unbroken bar, driven by whatever state the consumer sets for the `calendarKeys()`/`rangePreview()` mixins.\n *\n * @param handle Runtime handle carrying the host `<td>`'s props.\n * @returns The render function producing the day's markup.\n * @example\n * <RangeCalendar.Cell data-selection-start=\"\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell aria-selected=\"true\">{day.label}</RangeCalendar.Cell>\n * @example\n * <RangeCalendar.Cell data-selection-end=\"\">{day.label}</RangeCalendar.Cell>\n */\nRangeCalendar.Cell = function RangeCalendarCell(handle: Handle<RangeCalendar.CellProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\n\t\treturn (\n\t\t\t<Calendar.Cell\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A day is the range's opening, its closing, both at once, or one of the days\n\t\t\t\t\t\t * between. The four are written under selectors that match one apiece, so each\n\t\t\t\t\t\t * day keeps its own shape however the cascade orders the set.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-selection-start]:not([data-selection-end])\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen(\"&[data-selection-end]:not([data-selection-start])\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\t/**\n\t\t\t\t\t\t * A range of one day opens and closes on itself, so it reads as a single day.\n\t\t\t\t\t\t */\n\t\t\t\t\t\twhen(\"&[data-selection-start][data-selection-end]\", [\n\t\t\t\t\t\t\tbg(\"brand.solid\"),\n\t\t\t\t\t\t\tfg(\"brand.onSolid\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t\twhen('&[aria-selected=\"true\"]:not([data-selection-start]):not([data-selection-end])', [\n\t\t\t\t\t\t\t/**\n\t\t\t\t\t\t\t * The days between carry the range across the row, so the band reads as one\n\t\t\t\t\t\t\t * run at a glance while the two ends stay the strongest thing in the month.\n\t\t\t\t\t\t\t */\n\t\t\t\t\t\t\tbg(\"brand.bg-tint-hover\"),\n\t\t\t\t\t\t\tfg(\"brand.emphasis\"),\n\t\t\t\t\t\t\troundedCorner(\"start-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"start-end\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-start\", \"none\"),\n\t\t\t\t\t\t\troundedCorner(\"end-end\", \"none\"),\n\t\t\t\t\t\t]),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
14
14
|
},
|
|
15
15
|
"test": null
|
|
16
16
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "range-months",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.29",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"calendar",
|
|
6
6
|
"heading"
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
],
|
|
11
11
|
"source": {
|
|
12
12
|
"path": "range-months.tsx",
|
|
13
|
-
"content": "/**\n * A server-rendered run of consecutive month grids for picking a stay's check-in and check-out,\n * or a single date. Every selectable day is a link the caller builds, so picking works without\n * script; a CSS-only band previews the range under the pointer once a start is chosen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { borderSpacing } from \"@sdxc/u/layout\";\n\nimport type { DaySelection, RangePosition } from \"@sdxc/ui/utils\";\n\nimport { CALENDAR_DAY_DATE_ATTRIBUTE } from \"@sdxc/ui/mixins\";\nimport {\n\tdayTime,\n\tfirstUnavailableAfter,\n\tmonthWeeks,\n\tnextSelection,\n\trangePosition,\n\tshiftMonth,\n\tweekdayTime,\n} from \"@sdxc/ui/utils\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Heading } from \"@sdxc/ui/heading\";\n\n/** How many months show when `months` is unset: a stay's two ends usually fit across two. */\nconst DEFAULT_MONTHS = 2;\n\n/** The first weekday column when `weekStartsOn` is unset: Sunday. */\nconst DEFAULT_WEEK_STARTS_ON = 0;\n\n/** The custom property every day cell sizes from: 40px, or the 44px touch target on a coarse pointer. */\nconst CELL = \"var(--ui-range-months-cell)\";\n\n/** The previous and next links' size: 32px, or the touch target on a coarse pointer. */\nconst NAV = \"max(2rem, var(--ui-target-size, 0px))\";\n\n/** The band colour for the days between the two ends of a chosen or previewed range. */\nconst BAND = \"var(--ui-brand-bg-tint-hover)\";\n\n/** The lighter band a pending range previews toward the hovered or focused day. */\nconst PREVIEW = \"var(--ui-brand-bg-tint)\";\n\n/** Matches a day cell the pointer or keyboard focus is on. */\nconst ACTIVE = \":is(:hover, :focus-within)\";\n\n/** Prop types for {@link RangeMonths}. */\nexport namespace RangeMonths {\n\t/** What a link asks the page to show next: the selection it makes and the first month on view. */\n\texport interface Next {\n\t\t/** First day of the range, or the picked day in single mode, `YYYY-MM-DD`. */\n\t\tstart?: string;\n\t\t/** Last day of the range, `YYYY-MM-DD`; absent while only a start is chosen. */\n\t\tend?: string;\n\t\t/** First month on view, `YYYY-MM`. */\n\t\tmonth: string;\n\t}\n\n\t/** Words read to assistive technology, in the page's language. */\n\texport interface Labels {\n\t\t/** Name of the previous-month link, e.g. \"Previous month\". */\n\t\tprevious: string;\n\t\t/** Name of the next-month link, e.g. \"Next month\". */\n\t\tnext: string;\n\t\t/** Appended to the start day's name, e.g. \"check-in\". */\n\t\tstart?: string;\n\t\t/** Appended to the end day's name, e.g. \"check-out\". */\n\t\tend?: string;\n\t\t/** Appended to the picked day's name in single mode. */\n\t\tselected?: string;\n\t}\n\n\t/** Every native `<div>` attribute, plus the months, selection and links to draw. */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** First month shown, `YYYY-MM`. */\n\t\tmonth: string;\n\t\t/** How many consecutive months to show, side by side while they fit and one per row below. Defaults to {@link DEFAULT_MONTHS}. */\n\t\tmonths?: number;\n\t\t/** Chosen start day (the picked day in single mode), `YYYY-MM-DD`. */\n\t\tstart?: string;\n\t\t/** Chosen end day, `YYYY-MM-DD`; read in range mode only. */\n\t\tend?: string;\n\t\t/** Picks one day: a day link carries `start` alone and no band is drawn. */\n\t\tsingle?: boolean;\n\t\t/** Today, `YYYY-MM-DD`, passed in so the server and the browser draw the same marker. */\n\t\ttoday?: string;\n\t\t/** Earliest selectable day, `YYYY-MM-DD`; also hides the previous link before its month. */\n\t\tmin?: string;\n\t\t/** Latest selectable day, `YYYY-MM-DD`; also hides the next link from its month on. */\n\t\tmax?: string;\n\t\t/** Days already taken: drawn struck through, never a link, and never crossed by a range. */\n\t\tisUnavailable?: (date: string) => boolean;\n\t\t/**\n\t\t * Counts each day as a night, as a stay calendar does: the first taken day after a pending\n\t\t * start still links as its end, since checking out that morning leaves the night free.\n\t\t */\n\t\tnights?: boolean;\n\t\t/** Builds the URL of every day and month link from what that link selects. */\n\t\thref: (next: Next) => string;\n\t\t/** A small line under each day's number, such as the nightly price or event dots. */\n\t\tdayNote?: (date: string) => RemixNode;\n\t\t/** First weekday column, 0 for Sunday through 6 for Saturday. Defaults to {@link DEFAULT_WEEK_STARTS_ON}. */\n\t\tweekStartsOn?: number;\n\t\t/** BCP 47 locale for the month, weekday and day names; pass it so server and browser agree. */\n\t\tlocale?: string;\n\t\t/** Names the whole calendar, e.g. \"Stay dates\". */\n\t\tlabel: string;\n\t\t/** Level of each month's heading; resolved from the surrounding heading scope when unset. */\n\t\theadingLevel?: Heading.Level;\n\t\t/** Words read to assistive technology. */\n\t\tlabels: Labels;\n\t}\n}\n\n/**\n * Renders `months` month grids from `month`, each day a link to `href`'s URL for the selection\n * a click makes: with no start, or both ends set, the day becomes a new start; with only a start,\n * a later day becomes the end and an earlier or equal one the new start. Single mode links each day\n * as `{ start: day }`. Unavailable days, days outside `min`–`max`, and, while a start waits for its\n * end, days past the first unavailable day after it render as plain text.\n *\n * @example\n * <RangeMonths\n * \tlabel={t(\"stay.dates\")}\n * \tlabels={{ previous: t(\"calendar.previous\"), next: t(\"calendar.next\"), start: t(\"stay.checkIn\"), end: t(\"stay.checkOut\") }}\n * \tlocale={locale}\n * \tmonth=\"2026-03\"\n * \tstart={query.checkIn}\n * \tend={query.checkOut}\n * \ttoday=\"2026-03-02\"\n * \tmin=\"2026-03-02\"\n * \tisUnavailable={(date) => booked.has(date)}\n * \tdayNote={(date) => `$${prices[date]}`}\n * \thref={(next) => `?${new URLSearchParams({ ...next })}`}\n * />\n * @example\n * <RangeMonths single months={1} label={t(\"jump\")} labels={labels} month=\"2026-03\" start={day} today={today} href={({ start, month }) => `/day/${start ?? month}`} />\n */\nexport function RangeMonths(handle: Handle<RangeMonths.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tmonth,\n\t\t\tmonths,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tsingle = false,\n\t\t\ttoday,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tisUnavailable,\n\t\t\tnights = false,\n\t\t\thref,\n\t\t\tdayNote,\n\t\t\tweekStartsOn,\n\t\t\tlocale,\n\t\t\tlabel,\n\t\t\theadingLevel,\n\t\t\tlabels,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet firstWeekday = weekStartsOn ?? DEFAULT_WEEK_STARTS_ON;\n\t\tlet shown = Array.from({ length: Math.max(1, months ?? DEFAULT_MONTHS) }, (_, index) =>\n\t\t\tshiftMonth(month, index),\n\t\t);\n\t\tlet lastShown = shown[shown.length - 1] ?? month;\n\t\tlet selection: DaySelection = { start, end: single ? undefined : end, single };\n\t\tlet block =\n\t\t\t!single && start !== undefined && end === undefined\n\t\t\t\t? firstUnavailableAfter(start, `${lastShown}-31`, isUnavailable)\n\t\t\t\t: undefined;\n\t\tlet previousMonth = shiftMonth(month, -1);\n\t\tlet showPrevious = min === undefined || previousMonth >= min.slice(0, 7);\n\t\tlet showNext = max === undefined || lastShown < max.slice(0, 7);\n\t\tlet monthName = new Intl.DateTimeFormat(locale, {\n\t\t\tmonth: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\ttimeZone: \"UTC\",\n\t\t});\n\t\tlet dayName = new Intl.DateTimeFormat(locale, { dateStyle: \"full\", timeZone: \"UTC\" });\n\t\tlet weekdayName = new Intl.DateTimeFormat(locale, { weekday: \"short\", timeZone: \"UTC\" });\n\t\tlet weekdays = Array.from({ length: 7 }, (_, index) =>\n\t\t\tweekdayName.format(weekdayTime(firstWeekday, index)),\n\t\t);\n\n\t\t/** The URL a day link points at, following the click rules in {@link RangeMonths}. */\n\t\tfunction dayHref(date: string): string {\n\t\t\treturn href(withMonth(nextSelection(date, selection), month));\n\t\t}\n\n\t\t/** Whether a click on `date` may produce a selection at all. */\n\t\tfunction isSelectable(date: string): boolean {\n\t\t\tif (min !== undefined && date < min) return false;\n\t\t\tif (max !== undefined && date > max) return false;\n\t\t\tif (nights && date === block) return true;\n\t\t\tif (isUnavailable?.(date)) return false;\n\t\t\treturn block === undefined || date < block;\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={label}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"range-months\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-range-months-cell\": \"max(2.5rem, var(--ui-target-size, 0px))\",\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tfontVariantNumeric: \"tabular-nums\",\n\t\t\t\t\t\t\t[`& [data-pending]${ACTIVE}, & td[data-pending]:has(~ td[data-pending]${ACTIVE}), & tr:has(~ tr td[data-pending]${ACTIVE}) td[data-pending], & [data-slot=range-months-month]:has(~ [data-slot=range-months-month] td[data-pending]${ACTIVE}) td[data-pending]`]:\n\t\t\t\t\t\t\t\t{ backgroundColor: PREVIEW },\n\t\t\t\t\t\t\t[`&:has(td[data-pending]${ACTIVE}) td[data-range=only]:not(:last-child)`]: {\n\t\t\t\t\t\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${PREVIEW} 50%)`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[`&:has(td[data-pending]${ACTIVE}) td[data-range=only]:not(:last-child):dir(rtl)`]: {\n\t\t\t\t\t\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${PREVIEW} 50%)`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{showPrevious ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href(withMonth({ start, end: selection.end }, previousMonth))}\n\t\t\t\t\t\taria-label={labels.previous}\n\t\t\t\t\t\tdata-slot=\"range-months-previous\"\n\t\t\t\t\t\tmix={[navLinkStyle(\"start\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ChevronLeftIcon aria-hidden=\"true\" />\n\t\t\t\t\t</a>\n\t\t\t\t) : null}\n\t\t\t\t{showNext ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href(withMonth({ start, end: selection.end }, shiftMonth(month, 1)))}\n\t\t\t\t\t\taria-label={labels.next}\n\t\t\t\t\t\tdata-slot=\"range-months-next\"\n\t\t\t\t\t\tmix={[navLinkStyle(\"end\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ChevronRightIcon aria-hidden=\"true\" />\n\t\t\t\t\t</a>\n\t\t\t\t) : null}\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"range-months-months\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\tgridTemplateColumns: `repeat(auto-fit, minmax(min(100%, calc(7 * ${CELL})), calc(7 * ${CELL})))`,\n\t\t\t\t\t\t\tjustifyContent: \"start\",\n\t\t\t\t\t\t\tcolumnGap: \"2rem\",\n\t\t\t\t\t\t\trowGap: \"1.5rem\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{shown.map((key) => {\n\t\t\t\t\t\tlet monthLabel = monthName.format(dayTime(key));\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<section key={key} data-slot=\"range-months-month\" data-month={key}>\n\t\t\t\t\t\t\t\t<Calendar.Header\n\t\t\t\t\t\t\t\t\tmix={[raw({ minBlockSize: NAV, marginBlockEnd: \"0.5rem\", paddingInline: NAV })]}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Calendar.Heading level={headingLevel}>{monthLabel}</Calendar.Heading>\n\t\t\t\t\t\t\t\t</Calendar.Header>\n\t\t\t\t\t\t\t\t<Calendar.Grid\n\t\t\t\t\t\t\t\t\taria-label={monthLabel}\n\t\t\t\t\t\t\t\t\tmix={[borderSpacing(\"0\"), raw({ inlineSize: \"100%\", tableLayout: \"fixed\" })]}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Calendar.GridHeader>\n\t\t\t\t\t\t\t\t\t\t<Calendar.Row>\n\t\t\t\t\t\t\t\t\t\t\t{weekdays.map((weekday) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<Calendar.HeaderCell key={weekday}>{weekday}</Calendar.HeaderCell>\n\t\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t\t</Calendar.Row>\n\t\t\t\t\t\t\t\t\t</Calendar.GridHeader>\n\t\t\t\t\t\t\t\t\t<Calendar.GridBody>\n\t\t\t\t\t\t\t\t\t\t{monthWeeks(key, firstWeekday).map((week, row) => (\n\t\t\t\t\t\t\t\t\t\t\t<Calendar.Row key={`${key}-${row}`}>\n\t\t\t\t\t\t\t\t\t\t\t\t{week.map((date, column) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (date === null) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td key={`${key}-${row}-${column}`} data-slot=\"range-months-blank\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet position = rangePosition(date, selection);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet unavailable = isUnavailable?.(date) ?? false;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet selectable = isSelectable(date);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet pending =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tselectable &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t!single &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstart !== undefined &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tend === undefined &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate > start;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet note = dayNote === undefined ? undefined : dayNote(date);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet stateLabel = dayStateLabel(position, single, labels);\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey={date}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-slot=\"range-months-day\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-range={position}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-pending={pending ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-unavailable={unavailable ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taria-disabled={selectable ? undefined : \"true\"}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmix={[dayCellStyle()]}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<RangeMonthsDay\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate={date}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thref={selectable ? dayHref(date) : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstateLabel === undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t? dayName.format(dayTime(date))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t: `${dayName.format(dayTime(date))}, ${stateLabel}`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttoday={date === today}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnote={note}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thasNotes={dayNote !== undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t\t</Calendar.Row>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</Calendar.GridBody>\n\t\t\t\t\t\t\t\t</Calendar.Grid>\n\t\t\t\t\t\t\t</section>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/** Props of {@link RangeMonthsDay}. */\ninterface RangeMonthsDayProps {\n\t/** The day, `YYYY-MM-DD`; exposed on the focusable element for `calendarKeys()`. */\n\tdate: string;\n\t/** Where a click goes; absent for a day that cannot be picked. */\n\thref?: string;\n\t/** The day's full spoken name, with its selection state. */\n\tlabel: string;\n\t/** Marks the day with `aria-current=\"date\"`. */\n\ttoday: boolean;\n\t/** The caller's note under the number. */\n\tnote: RemixNode;\n\t/** Reserves the note line on every day, so rows keep one height. */\n\thasNotes: boolean;\n}\n\n/**\n * One day's content: a link when it can be picked, otherwise plain text, each holding the day\n * number and, when the calendar carries notes, the note line under it.\n */\nfunction RangeMonthsDay(handle: Handle<RangeMonthsDayProps>) {\n\treturn () => {\n\t\tlet { date, href, label, today, note, hasNotes } = handle.props;\n\t\tlet content = (\n\t\t\t<>\n\t\t\t\t<span data-slot=\"range-months-number\">{Number(date.slice(8, 10))}</span>\n\t\t\t\t{hasNotes ? (\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-slot=\"range-months-note\"\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tminBlockSize: \"1em\",\n\t\t\t\t\t\t\t\tfontSize: \"0.625rem\",\n\t\t\t\t\t\t\t\tlineHeight: \"1\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t\t\t\t\"[data-range=start] &, [data-range=end] &, [data-range=only] &\": {\n\t\t\t\t\t\t\t\t\tcolor: \"inherit\",\n\t\t\t\t\t\t\t\t\topacity: \"0.85\",\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t{note}\n\t\t\t\t\t</span>\n\t\t\t\t) : null}\n\t\t\t</>\n\t\t);\n\t\tlet attributes = {\n\t\t\t[CALENDAR_DAY_DATE_ATTRIBUTE]: date,\n\t\t\t\"aria-current\": today ? (\"date\" as const) : undefined,\n\t\t\t\"data-today\": today ? \"\" : undefined,\n\t\t};\n\t\tif (href === undefined) {\n\t\t\treturn (\n\t\t\t\t<span {...attributes} data-slot=\"range-months-day-text\" mix={[dayContentStyle()]}>\n\t\t\t\t\t{content}\n\t\t\t\t</span>\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\t<a {...attributes} href={href} aria-label={label} mix={[dayContentStyle()]}>\n\t\t\t\t{content}\n\t\t\t</a>\n\t\t);\n\t};\n}\n\n/** Adds the first month on view to a selection, leaving out the ends that are unset. */\nfunction withMonth(selection: Omit<RangeMonths.Next, \"month\">, month: string): RangeMonths.Next {\n\tlet next: RangeMonths.Next = { month };\n\tif (selection.start !== undefined) next.start = selection.start;\n\tif (selection.end !== undefined) next.end = selection.end;\n\treturn next;\n}\n\n/** The selection state appended to a day's spoken name, when the caller supplied its word. */\nfunction dayStateLabel(\n\tposition: RangePosition | undefined,\n\tsingle: boolean,\n\twords: RangeMonths.Labels,\n): string | undefined {\n\tif (position === \"only\") return single ? words.selected : words.start;\n\tif (position === \"start\") return words.start;\n\tif (position === \"end\") return words.end;\n\treturn undefined;\n}\n\n/**\n * A day's `<td>`: the band behind a chosen range, squared where it runs on and rounded where it\n * meets a week's edge, with the two ends' cells half-filled toward the days between.\n */\nfunction dayCellStyle() {\n\treturn raw({\n\t\tpadding: \"0\",\n\t\ttextAlign: \"center\",\n\t\tverticalAlign: \"middle\",\n\t\t\"&[data-range=middle]\": { backgroundColor: BAND },\n\t\t\"&[data-range=middle]:first-child\": {\n\t\t\tborderStartStartRadius: \"9999px\",\n\t\t\tborderEndStartRadius: \"9999px\",\n\t\t},\n\t\t\"&[data-range=middle]:last-child\": {\n\t\t\tborderStartEndRadius: \"9999px\",\n\t\t\tborderEndEndRadius: \"9999px\",\n\t\t},\n\t\t\"&[data-range=start]:not(:last-child)\": {\n\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=end]:not(:first-child)\": {\n\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=start]:not(:last-child):dir(rtl)\": {\n\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=end]:not(:first-child):dir(rtl)\": {\n\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t});\n}\n\n/**\n * A day's link or text: a round target at least {@link CELL} tall, solid at either end of the\n * range, muted and struck through when taken, faded when outside `min`–`max`, underlined for today.\n */\nfunction dayContentStyle() {\n\treturn raw({\n\t\tdisplay: \"grid\",\n\t\tplaceContent: \"center\",\n\t\tjustifyItems: \"center\",\n\t\tgap: \"0.125rem\",\n\t\tinlineSize: \"100%\",\n\t\tminBlockSize: CELL,\n\t\tpaddingBlock: \"0.25rem\",\n\t\tborderRadius: \"9999px\",\n\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\tfontSize: \"0.875rem\",\n\t\tlineHeight: \"1.1\",\n\t\ttextDecoration: \"none\",\n\t\toutlineOffset: \"-2px\",\n\t\t\"&:is(a):hover\": { backgroundColor: \"var(--ui-neutral-bg-tint-hover)\" },\n\t\t\"&:is(a):focus-visible\": { outline: \"2px solid var(--ui-brand-ring)\" },\n\t\t\"[data-range=middle] &\": { color: \"var(--ui-brand-fg-emphasis)\" },\n\t\t\"[data-range=middle] &:is(a):hover, [data-pending] &:is(a):hover\": {\n\t\t\tbackgroundColor: \"var(--ui-brand-bg-tint-pressed)\",\n\t\t},\n\t\t\"[data-range=start] &:is(a), [data-range=end] &:is(a), [data-range=only] &:is(a), [data-range=only] &\":\n\t\t\t{\n\t\t\t\tbackgroundColor: \"var(--ui-brand-bg-solid)\",\n\t\t\t\tcolor: \"var(--ui-brand-fg-on-solid)\",\n\t\t\t},\n\t\t\"[aria-disabled=true] &\": { color: \"var(--ui-neutral-fg-muted)\", opacity: \"0.45\" },\n\t\t\"[data-unavailable] &\": { opacity: \"1\" },\n\t\t\"[data-unavailable] & [data-slot=range-months-number]\": { textDecoration: \"line-through\" },\n\t\t\"&[data-today] [data-slot=range-months-number]\": {\n\t\t\tfontWeight: \"700\",\n\t\t\ttextDecorationLine: \"underline\",\n\t\t\ttextDecorationThickness: \"2px\",\n\t\t\ttextUnderlineOffset: \"3px\",\n\t\t},\n\t\t\"[data-unavailable] &[data-today] [data-slot=range-months-number]\": {\n\t\t\ttextDecorationLine: \"underline line-through\",\n\t\t},\n\t});\n}\n\n/**\n * A previous or next link: a round chevron button pinned to the heading row's `side`, so the\n * pair flanks the first month's heading however the months wrap.\n */\nfunction navLinkStyle(side: \"start\" | \"end\") {\n\treturn raw({\n\t\tposition: \"absolute\",\n\t\tinsetBlockStart: \"0\",\n\t\tinsetInlineStart: side === \"start\" ? \"0\" : \"auto\",\n\t\tinsetInlineEnd: side === \"end\" ? \"0\" : \"auto\",\n\t\tzIndex: \"1\",\n\t\tdisplay: \"grid\",\n\t\tplaceItems: \"center\",\n\t\tinlineSize: NAV,\n\t\tblockSize: NAV,\n\t\tborderRadius: \"9999px\",\n\t\tcolor: \"var(--ui-neutral-fg)\",\n\t\t\"&:hover\": { backgroundColor: \"var(--ui-neutral-bg-tint-hover)\" },\n\t\t\"&:focus-visible\": { outline: \"2px solid var(--ui-brand-ring)\", outlineOffset: \"2px\" },\n\t\t\"& svg\": { inlineSize: \"1rem\", blockSize: \"1rem\" },\n\t\t\"&:dir(rtl) svg\": { scale: \"-1 1\" },\n\t});\n}\n"
|
|
13
|
+
"content": "/**\n * A server-rendered run of consecutive month grids for picking a stay's check-in and check-out,\n * or a single date. Every selectable day is a link the caller builds, so picking works without\n * script; a CSS-only band previews the range under the pointer once a start is chosen.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { ChevronLeftIcon, ChevronRightIcon } from \"@sdxc/icons\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\nimport { borderSpacing } from \"@sdxc/u/layout\";\n\nimport type { DaySelection, RangePosition } from \"@sdxc/ui/utils\";\n\nimport { CALENDAR_DAY_DATE_ATTRIBUTE } from \"@sdxc/ui/mixins\";\nimport {\n\tdayTime,\n\tfirstUnavailableAfter,\n\tmonthWeeks,\n\tnextSelection,\n\trangePosition,\n\tshiftMonth,\n\tweekdayTime,\n} from \"@sdxc/ui/utils\";\n\nimport { Calendar } from \"@sdxc/ui/calendar\";\nimport { Heading } from \"@sdxc/ui/heading\";\n\n/** How many months show when `months` is unset: a stay's two ends usually fit across two. */\nconst DEFAULT_MONTHS = 2;\n\n/** The first weekday column when `weekStartsOn` is unset: Sunday. */\nconst DEFAULT_WEEK_STARTS_ON = 0;\n\n/** The custom property every day cell sizes from: 40px, or the 44px touch target on a coarse pointer. */\nconst CELL = \"var(--ui-range-months-cell)\";\n\n/** The previous and next links' size: 32px, or the touch target on a coarse pointer. */\nconst NAV = \"max(2rem, var(--ui-target-size, 0px))\";\n\n/** The band colour for the days between the two ends of a chosen or previewed range. */\nconst BAND = \"var(--ui-brand-bg-tint-hover)\";\n\n/** The lighter band a pending range previews toward the hovered or focused day. */\nconst PREVIEW = \"var(--ui-brand-bg-tint)\";\n\n/** Matches a day cell the pointer or keyboard focus is on. */\nconst ACTIVE = \":is(:hover, :focus-within)\";\n\n/** Prop types for {@link RangeMonths}. */\nexport namespace RangeMonths {\n\t/** What a link asks the page to show next: the selection it makes and the first month on view. */\n\texport interface Next {\n\t\t/** First day of the range, or the picked day in single mode, `YYYY-MM-DD`. */\n\t\tstart?: string;\n\t\t/** Last day of the range, `YYYY-MM-DD`; absent while only a start is chosen. */\n\t\tend?: string;\n\t\t/** First month on view, `YYYY-MM`. */\n\t\tmonth: string;\n\t}\n\n\t/** Words read to assistive technology, in the page's language. */\n\texport interface Labels {\n\t\t/** Name of the previous-month link, e.g. \"Previous month\". */\n\t\tprevious: string;\n\t\t/** Name of the next-month link, e.g. \"Next month\". */\n\t\tnext: string;\n\t\t/** Appended to the start day's name, e.g. \"check-in\". */\n\t\tstart?: string;\n\t\t/** Appended to the end day's name, e.g. \"check-out\". */\n\t\tend?: string;\n\t\t/** Appended to the picked day's name in single mode. */\n\t\tselected?: string;\n\t}\n\n\t/** Every native `<div>` attribute, plus the months, selection and links to draw. */\n\texport interface Props extends Omit<TagProps<\"div\">, \"children\"> {\n\t\t/** First month shown, `YYYY-MM`. */\n\t\tmonth: string;\n\t\t/** How many consecutive months to show, side by side while they fit and one per row below. Defaults to {@link DEFAULT_MONTHS}. */\n\t\tmonths?: number;\n\t\t/** Chosen start day (the picked day in single mode), `YYYY-MM-DD`. */\n\t\tstart?: string;\n\t\t/** Chosen end day, `YYYY-MM-DD`; read in range mode only. */\n\t\tend?: string;\n\t\t/** Picks one day: a day link carries `start` alone and no band is drawn. */\n\t\tsingle?: boolean;\n\t\t/** Today, `YYYY-MM-DD`, passed in so the server and the browser draw the same marker. */\n\t\ttoday?: string;\n\t\t/** Earliest selectable day, `YYYY-MM-DD`; also hides the previous link before its month. */\n\t\tmin?: string;\n\t\t/** Latest selectable day, `YYYY-MM-DD`; also hides the next link from its month on. */\n\t\tmax?: string;\n\t\t/** Days already taken: drawn struck through, never a link, and never crossed by a range. */\n\t\tisUnavailable?: (date: string) => boolean;\n\t\t/**\n\t\t * Counts each day as a night, as a stay calendar does: the first taken day after a pending\n\t\t * start still links as its end, since checking out that morning leaves the night free.\n\t\t */\n\t\tnights?: boolean;\n\t\t/** Builds the URL of every day and month link from what that link selects. */\n\t\thref: (next: Next) => string;\n\t\t/**\n\t\t * Draws each day's {@link RangeMonths.Note}, a small line under its number such as the\n\t\t * nightly price or event dots; a day it returns nothing for keeps an empty line, so rows\n\t\t * hold one height.\n\t\t */\n\t\tdayNote?: (date: string) => RemixNode;\n\t\t/** First weekday column, 0 for Sunday through 6 for Saturday. Defaults to {@link DEFAULT_WEEK_STARTS_ON}. */\n\t\tweekStartsOn?: number;\n\t\t/** BCP 47 locale for the month, weekday and day names; pass it so server and browser agree. */\n\t\tlocale?: string;\n\t\t/** Names the whole calendar, e.g. \"Stay dates\". */\n\t\tlabel: string;\n\t\t/** Level of each month's heading; resolved from the surrounding heading scope when unset. */\n\t\theadingLevel?: Heading.Level;\n\t\t/** Words read to assistive technology. */\n\t\tlabels: Labels;\n\t}\n\n\t/** Every native `<span>` attribute. */\n\texport interface NoteProps extends TagProps<\"span\"> {}\n}\n\n/**\n * Renders `months` month grids from `month`, each day a link to `href`'s URL for the selection\n * a click makes: with no start, or both ends set, the day becomes a new start; with only a start,\n * a later day becomes the end and an earlier or equal one the new start. Single mode links each day\n * as `{ start: day }`. Unavailable days, days outside `min`–`max`, and, while a start waits for its\n * end, days past the first unavailable day after it render as plain text.\n *\n * @example\n * <RangeMonths\n * \tlabel={t(\"stay.dates\")}\n * \tlabels={{ previous: t(\"calendar.previous\"), next: t(\"calendar.next\"), start: t(\"stay.checkIn\"), end: t(\"stay.checkOut\") }}\n * \tlocale={locale}\n * \tmonth=\"2026-03\"\n * \tstart={query.checkIn}\n * \tend={query.checkOut}\n * \ttoday=\"2026-03-02\"\n * \tmin=\"2026-03-02\"\n * \tisUnavailable={(date) => booked.has(date)}\n * \tdayNote={(date) => <RangeMonths.Note>{prices[date]}</RangeMonths.Note>}\n * \thref={(next) => `?${new URLSearchParams({ ...next })}`}\n * />\n * @example\n * <RangeMonths single months={1} label={t(\"jump\")} labels={labels} month=\"2026-03\" start={day} today={today} href={({ start, month }) => `/day/${start ?? month}`} />\n */\nexport function RangeMonths(handle: Handle<RangeMonths.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tmonth,\n\t\t\tmonths,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tsingle = false,\n\t\t\ttoday,\n\t\t\tmin,\n\t\t\tmax,\n\t\t\tisUnavailable,\n\t\t\tnights = false,\n\t\t\thref,\n\t\t\tdayNote,\n\t\t\tweekStartsOn,\n\t\t\tlocale,\n\t\t\tlabel,\n\t\t\theadingLevel,\n\t\t\tlabels,\n\t\t\tmix,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet firstWeekday = weekStartsOn ?? DEFAULT_WEEK_STARTS_ON;\n\t\tlet shown = Array.from({ length: Math.max(1, months ?? DEFAULT_MONTHS) }, (_, index) =>\n\t\t\tshiftMonth(month, index),\n\t\t);\n\t\tlet lastShown = shown[shown.length - 1] ?? month;\n\t\tlet selection: DaySelection = { start, end: single ? undefined : end, single };\n\t\tlet block =\n\t\t\t!single && start !== undefined && end === undefined\n\t\t\t\t? firstUnavailableAfter(start, `${lastShown}-31`, isUnavailable)\n\t\t\t\t: undefined;\n\t\tlet previousMonth = shiftMonth(month, -1);\n\t\tlet showPrevious = min === undefined || previousMonth >= min.slice(0, 7);\n\t\tlet showNext = max === undefined || lastShown < max.slice(0, 7);\n\t\tlet monthName = new Intl.DateTimeFormat(locale, {\n\t\t\tmonth: \"long\",\n\t\t\tyear: \"numeric\",\n\t\t\ttimeZone: \"UTC\",\n\t\t});\n\t\tlet dayName = new Intl.DateTimeFormat(locale, { dateStyle: \"full\", timeZone: \"UTC\" });\n\t\tlet weekdayName = new Intl.DateTimeFormat(locale, { weekday: \"short\", timeZone: \"UTC\" });\n\t\tlet weekdays = Array.from({ length: 7 }, (_, index) =>\n\t\t\tweekdayName.format(weekdayTime(firstWeekday, index)),\n\t\t);\n\n\t\t/** The URL a day link points at, following the click rules in {@link RangeMonths}. */\n\t\tfunction dayHref(date: string): string {\n\t\t\treturn href(withMonth(nextSelection(date, selection), month));\n\t\t}\n\n\t\t/** Whether a click on `date` may produce a selection at all. */\n\t\tfunction isSelectable(date: string): boolean {\n\t\t\tif (min !== undefined && date < min) return false;\n\t\t\tif (max !== undefined && date > max) return false;\n\t\t\tif (nights && date === block) return true;\n\t\t\tif (isUnavailable?.(date)) return false;\n\t\t\treturn block === undefined || date < block;\n\t\t}\n\n\t\treturn (\n\t\t\t<div\n\t\t\t\trole=\"group\"\n\t\t\t\taria-label={label}\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"range-months\"\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\"--ui-range-months-cell\": \"max(2.5rem, var(--ui-target-size, 0px))\",\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tfontVariantNumeric: \"tabular-nums\",\n\t\t\t\t\t\t\t[`& [data-pending]${ACTIVE}, & td[data-pending]:has(~ td[data-pending]${ACTIVE}), & tr:has(~ tr td[data-pending]${ACTIVE}) td[data-pending], & [data-slot=range-months-month]:has(~ [data-slot=range-months-month] td[data-pending]${ACTIVE}) td[data-pending]`]:\n\t\t\t\t\t\t\t\t{ backgroundColor: PREVIEW },\n\t\t\t\t\t\t\t[`&:has(td[data-pending]${ACTIVE}) td[data-range=only]:not(:last-child)`]: {\n\t\t\t\t\t\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${PREVIEW} 50%)`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t[`&:has(td[data-pending]${ACTIVE}) td[data-range=only]:not(:last-child):dir(rtl)`]: {\n\t\t\t\t\t\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${PREVIEW} 50%)`,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t{showPrevious ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href(withMonth({ start, end: selection.end }, previousMonth))}\n\t\t\t\t\t\taria-label={labels.previous}\n\t\t\t\t\t\tdata-slot=\"range-months-previous\"\n\t\t\t\t\t\tmix={[navLinkStyle(\"start\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ChevronLeftIcon aria-hidden=\"true\" />\n\t\t\t\t\t</a>\n\t\t\t\t) : null}\n\t\t\t\t{showNext ? (\n\t\t\t\t\t<a\n\t\t\t\t\t\thref={href(withMonth({ start, end: selection.end }, shiftMonth(month, 1)))}\n\t\t\t\t\t\taria-label={labels.next}\n\t\t\t\t\t\tdata-slot=\"range-months-next\"\n\t\t\t\t\t\tmix={[navLinkStyle(\"end\")]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ChevronRightIcon aria-hidden=\"true\" />\n\t\t\t\t\t</a>\n\t\t\t\t) : null}\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"range-months-months\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\tgridTemplateColumns: `repeat(auto-fit, minmax(min(100%, calc(7 * ${CELL})), calc(7 * ${CELL})))`,\n\t\t\t\t\t\t\tjustifyContent: \"start\",\n\t\t\t\t\t\t\tcolumnGap: \"2rem\",\n\t\t\t\t\t\t\trowGap: \"1.5rem\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{shown.map((key) => {\n\t\t\t\t\t\tlet monthLabel = monthName.format(dayTime(key));\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<section key={key} data-slot=\"range-months-month\" data-month={key}>\n\t\t\t\t\t\t\t\t<Calendar.Header\n\t\t\t\t\t\t\t\t\tmix={[raw({ minBlockSize: NAV, marginBlockEnd: \"0.5rem\", paddingInline: NAV })]}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Calendar.Heading level={headingLevel}>{monthLabel}</Calendar.Heading>\n\t\t\t\t\t\t\t\t</Calendar.Header>\n\t\t\t\t\t\t\t\t<Calendar.Grid\n\t\t\t\t\t\t\t\t\taria-label={monthLabel}\n\t\t\t\t\t\t\t\t\tmix={[borderSpacing(\"0\"), raw({ inlineSize: \"100%\", tableLayout: \"fixed\" })]}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<Calendar.GridHeader>\n\t\t\t\t\t\t\t\t\t\t<Calendar.Row>\n\t\t\t\t\t\t\t\t\t\t\t{weekdays.map((weekday) => (\n\t\t\t\t\t\t\t\t\t\t\t\t<Calendar.HeaderCell key={weekday}>{weekday}</Calendar.HeaderCell>\n\t\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t\t</Calendar.Row>\n\t\t\t\t\t\t\t\t\t</Calendar.GridHeader>\n\t\t\t\t\t\t\t\t\t<Calendar.GridBody>\n\t\t\t\t\t\t\t\t\t\t{monthWeeks(key, firstWeekday).map((week, row) => (\n\t\t\t\t\t\t\t\t\t\t\t<Calendar.Row key={`${key}-${row}`}>\n\t\t\t\t\t\t\t\t\t\t\t\t{week.map((date, column) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (date === null) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td key={`${key}-${row}-${column}`} data-slot=\"range-months-blank\" />\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet position = rangePosition(date, selection);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet unavailable = isUnavailable?.(date) ?? false;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet selectable = isSelectable(date);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet pending =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tselectable &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t!single &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstart !== undefined &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tend === undefined &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate > start;\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet note =\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdayNote === undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t: (dayNote(date) ?? <RangeMonths.Note />);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet stateLabel = dayStateLabel(position, single, labels);\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t<td\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tkey={date}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-slot=\"range-months-day\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-range={position}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-pending={pending ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdata-unavailable={unavailable ? \"\" : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\taria-disabled={selectable ? undefined : \"true\"}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tmix={[dayCellStyle()]}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<RangeMonthsDay\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tdate={date}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thref={selectable ? dayHref(date) : undefined}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tlabel={\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstateLabel === undefined\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t? dayName.format(dayTime(date))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t: `${dayName.format(dayTime(date))}, ${stateLabel}`\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttoday={date === today}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tnote={note}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t</td>\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t})}\n\t\t\t\t\t\t\t\t\t\t\t</Calendar.Row>\n\t\t\t\t\t\t\t\t\t\t))}\n\t\t\t\t\t\t\t\t\t</Calendar.GridBody>\n\t\t\t\t\t\t\t\t</Calendar.Grid>\n\t\t\t\t\t\t\t</section>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t);\n\t};\n}\n\n/** Props of {@link RangeMonthsDay}. */\ninterface RangeMonthsDayProps {\n\t/** The day, `YYYY-MM-DD`; exposed on the focusable element for `calendarKeys()`. */\n\tdate: string;\n\t/** Where a click goes; absent for a day that cannot be picked. */\n\thref?: string;\n\t/** The day's full spoken name, with its selection state. */\n\tlabel: string;\n\t/** Marks the day with `aria-current=\"date\"`. */\n\ttoday: boolean;\n\t/** The caller's {@link RangeMonths.Note}, or an empty one holding the line; absent without notes. */\n\tnote: RemixNode;\n}\n\n/**\n * One day's content: a link when it can be picked, otherwise plain text, each holding the day\n * number and, when the calendar carries notes, the note line under it.\n */\nfunction RangeMonthsDay(handle: Handle<RangeMonthsDayProps>) {\n\treturn () => {\n\t\tlet { date, href, label, today, note } = handle.props;\n\t\tlet content = (\n\t\t\t<>\n\t\t\t\t<span data-slot=\"range-months-number\">{Number(date.slice(8, 10))}</span>\n\t\t\t\t{note}\n\t\t\t</>\n\t\t);\n\t\tlet attributes = {\n\t\t\t[CALENDAR_DAY_DATE_ATTRIBUTE]: date,\n\t\t\t\"aria-current\": today ? (\"date\" as const) : undefined,\n\t\t\t\"data-today\": today ? \"\" : undefined,\n\t\t};\n\t\tif (href === undefined) {\n\t\t\treturn (\n\t\t\t\t<span {...attributes} data-slot=\"range-months-day-text\" mix={[dayContentStyle()]}>\n\t\t\t\t\t{content}\n\t\t\t\t</span>\n\t\t\t);\n\t\t}\n\t\treturn (\n\t\t\t<a {...attributes} href={href} aria-label={label} mix={[dayContentStyle()]}>\n\t\t\t\t{content}\n\t\t\t</a>\n\t\t);\n\t};\n}\n\n/**\n * A small line under a day's number, such as the nightly price or event dots; muted, and in the\n * selection's own colour on a range's ends. Return one from `dayNote`.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the note.\n * @example <RangeMonths.Note>€120</RangeMonths.Note>\n */\nRangeMonths.Note = function RangeMonthsNote(handle: Handle<RangeMonths.NoteProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"range-months-note\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tminBlockSize: \"1em\",\n\t\t\t\t\t\t\tfontSize: \"0.625rem\",\n\t\t\t\t\t\t\tlineHeight: \"1\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t\t\t\"[data-range=start] &, [data-range=end] &, [data-range=only] &\": {\n\t\t\t\t\t\t\t\tcolor: \"inherit\",\n\t\t\t\t\t\t\t\topacity: \"0.85\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n\n/** Adds the first month on view to a selection, leaving out the ends that are unset. */\nfunction withMonth(selection: Omit<RangeMonths.Next, \"month\">, month: string): RangeMonths.Next {\n\tlet next: RangeMonths.Next = { month };\n\tif (selection.start !== undefined) next.start = selection.start;\n\tif (selection.end !== undefined) next.end = selection.end;\n\treturn next;\n}\n\n/** The selection state appended to a day's spoken name, when the caller supplied its word. */\nfunction dayStateLabel(\n\tposition: RangePosition | undefined,\n\tsingle: boolean,\n\twords: RangeMonths.Labels,\n): string | undefined {\n\tif (position === \"only\") return single ? words.selected : words.start;\n\tif (position === \"start\") return words.start;\n\tif (position === \"end\") return words.end;\n\treturn undefined;\n}\n\n/**\n * A day's `<td>`: the band behind a chosen range, squared where it runs on and rounded where it\n * meets a week's edge, with the two ends' cells half-filled toward the days between.\n */\nfunction dayCellStyle() {\n\treturn raw({\n\t\tpadding: \"0\",\n\t\ttextAlign: \"center\",\n\t\tverticalAlign: \"middle\",\n\t\t\"&[data-range=middle]\": { backgroundColor: BAND },\n\t\t\"&[data-range=middle]:first-child\": {\n\t\t\tborderStartStartRadius: \"9999px\",\n\t\t\tborderEndStartRadius: \"9999px\",\n\t\t},\n\t\t\"&[data-range=middle]:last-child\": {\n\t\t\tborderStartEndRadius: \"9999px\",\n\t\t\tborderEndEndRadius: \"9999px\",\n\t\t},\n\t\t\"&[data-range=start]:not(:last-child)\": {\n\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=end]:not(:first-child)\": {\n\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=start]:not(:last-child):dir(rtl)\": {\n\t\t\tbackground: `linear-gradient(to left, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t\t\"&[data-range=end]:not(:first-child):dir(rtl)\": {\n\t\t\tbackground: `linear-gradient(to right, transparent 50%, ${BAND} 50%)`,\n\t\t},\n\t});\n}\n\n/**\n * A day's link or text: a round target at least {@link CELL} tall, solid at either end of the\n * range, muted and struck through when taken, faded when outside `min`–`max`, underlined for today.\n */\nfunction dayContentStyle() {\n\treturn raw({\n\t\tdisplay: \"grid\",\n\t\tplaceContent: \"center\",\n\t\tjustifyItems: \"center\",\n\t\tgap: \"0.125rem\",\n\t\tinlineSize: \"100%\",\n\t\tminBlockSize: CELL,\n\t\tpaddingBlock: \"0.25rem\",\n\t\tborderRadius: \"9999px\",\n\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\tfontSize: \"0.875rem\",\n\t\tlineHeight: \"1.1\",\n\t\ttextDecoration: \"none\",\n\t\toutlineOffset: \"-2px\",\n\t\t\"&:is(a):hover\": { backgroundColor: \"var(--ui-neutral-bg-tint-hover)\" },\n\t\t\"&:is(a):focus-visible\": { outline: \"2px solid var(--ui-brand-ring)\" },\n\t\t\"[data-range=middle] &\": { color: \"var(--ui-brand-fg-emphasis)\" },\n\t\t\"[data-range=middle] &:is(a):hover, [data-pending] &:is(a):hover\": {\n\t\t\tbackgroundColor: \"var(--ui-brand-bg-tint-pressed)\",\n\t\t},\n\t\t\"[data-range=start] &:is(a), [data-range=end] &:is(a), [data-range=only] &:is(a), [data-range=only] &\":\n\t\t\t{\n\t\t\t\tbackgroundColor: \"var(--ui-brand-bg-solid)\",\n\t\t\t\tcolor: \"var(--ui-brand-fg-on-solid)\",\n\t\t\t},\n\t\t\"[aria-disabled=true] &\": { color: \"var(--ui-neutral-fg-muted)\", opacity: \"0.45\" },\n\t\t\"[data-unavailable] &\": { opacity: \"1\" },\n\t\t\"[data-unavailable] & [data-slot=range-months-number]\": { textDecoration: \"line-through\" },\n\t\t\"&[data-today] [data-slot=range-months-number]\": {\n\t\t\tfontWeight: \"700\",\n\t\t\ttextDecorationLine: \"underline\",\n\t\t\ttextDecorationThickness: \"2px\",\n\t\t\ttextUnderlineOffset: \"3px\",\n\t\t},\n\t\t\"[data-unavailable] &[data-today] [data-slot=range-months-number]\": {\n\t\t\ttextDecorationLine: \"underline line-through\",\n\t\t},\n\t});\n}\n\n/**\n * A previous or next link: a round chevron button pinned to the heading row's `side`, so the\n * pair flanks the first month's heading however the months wrap.\n */\nfunction navLinkStyle(side: \"start\" | \"end\") {\n\treturn raw({\n\t\tposition: \"absolute\",\n\t\tinsetBlockStart: \"0\",\n\t\tinsetInlineStart: side === \"start\" ? \"0\" : \"auto\",\n\t\tinsetInlineEnd: side === \"end\" ? \"0\" : \"auto\",\n\t\tzIndex: \"1\",\n\t\tdisplay: \"grid\",\n\t\tplaceItems: \"center\",\n\t\tinlineSize: NAV,\n\t\tblockSize: NAV,\n\t\tborderRadius: \"9999px\",\n\t\tcolor: \"var(--ui-neutral-fg)\",\n\t\t\"&:hover\": { backgroundColor: \"var(--ui-neutral-bg-tint-hover)\" },\n\t\t\"&:focus-visible\": { outline: \"2px solid var(--ui-brand-ring)\", outlineOffset: \"2px\" },\n\t\t\"& svg\": { inlineSize: \"1rem\", blockSize: \"1rem\" },\n\t\t\"&:dir(rtl) svg\": { scale: \"-1 1\" },\n\t});\n}\n"
|
|
14
14
|
},
|
|
15
15
|
"test": {
|
|
16
16
|
"path": "range-months.browser.test.tsx",
|
|
17
|
-
"content": "/**\n * Renders `RangeMonths` in a real browser: the weeks and weekday columns each month lays out, the\n * link every day carries in each selection state, the days that are never links, the band a\n * range draws, and a single month fitting a 320px phone without scrolling sideways.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { RangeMonths } from \"@sdxc/ui/range-months\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The words read to assistive technology. */\nconst LABELS: RangeMonths.Labels = {\n\tprevious: \"Previous month\",\n\tnext: \"Next month\",\n\tstart: \"check-in\",\n\tend: \"check-out\",\n};\n\n/** The tokens the band and the ends read, which an app's palette would otherwise supply. */\nconst TOKENS = {\n\t\"--ui-brand-bg-solid\": \"rgb(30, 90, 200)\",\n\t\"--ui-brand-fg-on-solid\": \"rgb(255, 255, 255)\",\n\t\"--ui-brand-bg-tint-hover\": \"rgb(220, 230, 250)\",\n\t\"--ui-brand-bg-tint\": \"rgb(240, 244, 252)\",\n};\n\n/** Encodes a link's selection as a query string, so a test reads back what a click selects. */\nfunction href(next: RangeMonths.Next): string {\n\treturn `/stay?${new URLSearchParams({ ...next })}`;\n}\n\n/** Mounts a calendar `width` pixels wide with `props` over a March 2026 default and returns its root. */\nfunction mount(props: Partial<RangeMonths.Props> = {}, width = 800): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tfor (let [name, value] of Object.entries(TOKENS)) host.style.setProperty(name, value);\n\tdocument.body.appendChild(host);\n\trender(\n\t\t<RangeMonths\n\t\t\tlabel=\"Stay dates\"\n\t\t\tlabels={LABELS}\n\t\t\tlocale=\"en-US\"\n\t\t\tmonth=\"2026-03\"\n\t\t\thref={href}\n\t\t\t{...props}\n\t\t/>,\n\t\t{\n\t\t\tcontainer: host,\n\t\t},\n\t);\n\treturn host.querySelector<HTMLElement>(\"[data-slot=range-months]\")!;\n}\n\n/** The query a day's link carries, or `null` when the day is not a link. */\nfunction linkOf(root: HTMLElement, date: string): string | null {\n\tlet link = root.querySelector(`a[data-date=\"${date}\"]`);\n\treturn link === null ? null : link.getAttribute(\"href\")!.replace(\"/stay?\", \"\");\n}\n\n/** A day's `<td>`. */\nfunction cellOf(root: HTMLElement, date: string): HTMLElement {\n\treturn root.querySelector<HTMLElement>(`[data-date=\"${date}\"]`)!.closest(\"td\")!;\n}\n\nafterEach(() => {\n\tdocument.body.replaceChildren();\n});\n\ndescribe(\"RangeMonths\", () => {\n\ttest(\"lays out each month's weeks with every day once\", () => {\n\t\tlet root = mount({ months: 2 });\n\t\tlet months = root.querySelectorAll(\"[data-slot=range-months-month]\");\n\t\texpect(months).toHaveLength(2);\n\t\texpect(months[0]?.querySelectorAll(\"tbody tr\")).toHaveLength(5);\n\t\texpect(months[0]?.querySelectorAll(\"[data-date]\")).toHaveLength(31);\n\t\texpect(months[1]?.querySelectorAll(\"[data-date]\")).toHaveLength(30);\n\t\texpect(months[0]?.querySelector(\"table\")?.getAttribute(\"aria-label\")).toBe(\"March 2026\");\n\t\texpect(months[1]?.querySelector(\"h2, h3, h4, h5, h6, h1\")?.textContent).toBe(\"April 2026\");\n\t\tlet firstRow = [...months[0]!.querySelectorAll(\"tbody tr:first-child td\")];\n\t\texpect(firstRow.findIndex((cell) => cell.querySelector(\"[data-date]\") !== null)).toBe(0);\n\t});\n\n\ttest(\"orders the weekday columns from weekStartsOn\", () => {\n\t\tlet sunday = mount({ months: 1 });\n\t\texpect([...sunday.querySelectorAll(\"th\")].map((cell) => cell.textContent)).toEqual([\n\t\t\t\"Sun\",\n\t\t\t\"Mon\",\n\t\t\t\"Tue\",\n\t\t\t\"Wed\",\n\t\t\t\"Thu\",\n\t\t\t\"Fri\",\n\t\t\t\"Sat\",\n\t\t]);\n\t\tdocument.body.replaceChildren();\n\t\tlet monday = mount({ months: 1, weekStartsOn: 1 });\n\t\texpect(monday.querySelector(\"th\")?.textContent).toBe(\"Mon\");\n\t\texpect(monday.querySelectorAll(\"tbody tr:first-child td\")[6]?.textContent).toBe(\"1\");\n\t});\n\n\ttest(\"links each day to a new start when nothing is chosen\", () => {\n\t\tlet root = mount();\n\t\texpect(linkOf(root, \"2026-03-10\")).toBe(\"month=2026-03&start=2026-03-10\");\n\t});\n\n\ttest(\"links a later day to the end and an earlier one to a new start once a start is chosen\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\" });\n\t\texpect(linkOf(root, \"2026-03-14\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-14\");\n\t\texpect(linkOf(root, \"2026-03-08\")).toBe(\"month=2026-03&start=2026-03-08\");\n\t\texpect(linkOf(root, \"2026-03-10\")).toBe(\"month=2026-03&start=2026-03-10\");\n\t});\n\n\ttest(\"restarts at the clicked day once both ends are chosen\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\", end: \"2026-03-14\" });\n\t\texpect(linkOf(root, \"2026-03-20\")).toBe(\"month=2026-03&start=2026-03-20\");\n\t});\n\n\ttest(\"links each day as the start alone in single mode, with no band\", () => {\n\t\tlet root = mount({ single: true, start: \"2026-03-10\", end: \"2026-03-14\" });\n\t\texpect(linkOf(root, \"2026-03-20\")).toBe(\"month=2026-03&start=2026-03-20\");\n\t\texpect(cellOf(root, \"2026-03-10\").dataset.range).toBe(\"only\");\n\t\texpect(cellOf(root, \"2026-03-12\").dataset.range).toBeUndefined();\n\t});\n\n\ttest(\"keeps the selection on the month links and hides previous before min's month\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\", end: \"2026-03-14\", min: \"2026-03-05\" });\n\t\texpect(root.querySelector(\"[data-slot=range-months-previous]\")).toBeNull();\n\t\texpect(root.querySelector(\"[data-slot=range-months-next]\")?.getAttribute(\"href\")).toBe(\n\t\t\t\"/stay?month=2026-04&start=2026-03-10&end=2026-03-14\",\n\t\t);\n\t\tdocument.body.replaceChildren();\n\t\tlet later = mount({ month: \"2026-04\", min: \"2026-03-05\", max: \"2026-05-20\" });\n\t\texpect(later.querySelector(\"[data-slot=range-months-previous]\")?.getAttribute(\"href\")).toBe(\n\t\t\t\"/stay?month=2026-03\",\n\t\t);\n\t\texpect(later.querySelector(\"[data-slot=range-months-next]\")).toBeNull();\n\t});\n\n\ttest(\"draws unavailable days and days before min as text, not links\", () => {\n\t\tlet root = mount({\n\t\t\tmin: \"2026-03-05\",\n\t\t\tisUnavailable: (date) => date === \"2026-03-12\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-04\")).toBeNull();\n\t\texpect(cellOf(root, \"2026-03-04\").getAttribute(\"aria-disabled\")).toBe(\"true\");\n\t\texpect(linkOf(root, \"2026-03-12\")).toBeNull();\n\t\texpect(cellOf(root, \"2026-03-12\").hasAttribute(\"data-unavailable\")).toBe(true);\n\t\tlet number = cellOf(root, \"2026-03-12\").querySelector(\"[data-slot=range-months-number]\")!;\n\t\texpect(getComputedStyle(number).textDecorationLine).toContain(\"line-through\");\n\t\texpect(linkOf(root, \"2026-03-05\")).not.toBeNull();\n\t});\n\n\ttest(\"ends a pending range before the first unavailable day after its start\", () => {\n\t\tlet root = mount({\n\t\t\tstart: \"2026-03-10\",\n\t\t\tisUnavailable: (date) => date === \"2026-03-15\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-14\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-14\");\n\t\texpect(cellOf(root, \"2026-03-14\").hasAttribute(\"data-pending\")).toBe(true);\n\t\texpect(linkOf(root, \"2026-03-16\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-04-02\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-03-05\")).toBe(\"month=2026-03&start=2026-03-05\");\n\t});\n\n\ttest(\"in a nights calendar, ends a pending range on the first taken day after its start\", () => {\n\t\tlet root = mount({\n\t\t\tstart: \"2026-03-10\",\n\t\t\tnights: true,\n\t\t\tisUnavailable: (date) => date === \"2026-03-15\" || date === \"2026-03-16\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-15\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-15\");\n\t\texpect(cellOf(root, \"2026-03-15\").hasAttribute(\"data-pending\")).toBe(true);\n\t\texpect(linkOf(root, \"2026-03-16\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-03-17\")).toBeNull();\n\t});\n\n\ttest(\"marks today with aria-current\", () => {\n\t\tlet root = mount({ today: \"2026-03-18\" });\n\t\texpect(root.querySelector(\"[aria-current=date]\")?.getAttribute(\"data-date\")).toBe(\"2026-03-18\");\n\t\texpect(root.querySelectorAll(\"[aria-current]\")).toHaveLength(1);\n\t});\n\n\ttest(\"draws a chosen range as one band from its start to its end\", () => {\n\t\tlet root = mount({ start: \"2026-03-30\", end: \"2026-04-03\" });\n\t\texpect(cellOf(root, \"2026-03-30\").dataset.range).toBe(\"start\");\n\t\texpect(cellOf(root, \"2026-03-31\").dataset.range).toBe(\"middle\");\n\t\texpect(cellOf(root, \"2026-04-02\").dataset.range).toBe(\"middle\");\n\t\texpect(cellOf(root, \"2026-04-03\").dataset.range).toBe(\"end\");\n\t\texpect(cellOf(root, \"2026-03-29\").dataset.range).toBeUndefined();\n\t\texpect(root.querySelector('a[data-date=\"2026-03-30\"]')?.getAttribute(\"aria-label\")).toBe(\n\t\t\t\"Monday, March 30, 2026, check-in\",\n\t\t);\n\t\tlet start = cellOf(root, \"2026-03-30\").getBoundingClientRect();\n\t\tlet next = cellOf(root, \"2026-03-31\").getBoundingClientRect();\n\t\texpect(next.left - start.right).toBe(0);\n\t\tlet solid = getComputedStyle(root.querySelector('a[data-date=\"2026-03-30\"]')!).backgroundColor;\n\t\tlet plain = getComputedStyle(root.querySelector('a[data-date=\"2026-03-20\"]')!).backgroundColor;\n\t\texpect(solid).toBe(\"rgb(30, 90, 200)\");\n\t\texpect(plain).not.toBe(solid);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-31\")).backgroundColor).toBe(\"rgb(220, 230, 250)\");\n\t});\n\n\ttest(\"puts the caller's note under each day\", () => {\n\t\tlet root = mount({ months: 1, dayNote: (date) => `$${Number(date.slice(8))}0` });\n\t\texpect(\n\t\t\troot.querySelector('[data-date=\"2026-03-07\"] [data-slot=range-months-note]')?.textContent,\n\t\t).toBe(\"$70\");\n\t});\n\n\ttest(\"fits one month inside a 320px phone without scrolling sideways\", () => {\n\t\tlet root = mount({ months: 1, dayNote: () => \"$120\" }, 320);\n\t\texpect(root.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(root.getBoundingClientRect().width).toBeLessThanOrEqual(320);\n\t\tlet day = root.querySelector('a[data-date=\"2026-03-10\"]')!.getBoundingClientRect();\n\t\texpect(day.width).toBeGreaterThanOrEqual(40);\n\t\texpect(day.height).toBeGreaterThanOrEqual(40);\n\t});\n\n\ttest(\"sets two months side by side when wide and one per row when narrow\", () => {\n\t\tlet tops = (root: HTMLElement) =>\n\t\t\tnew Set(\n\t\t\t\t[...root.querySelectorAll(\"[data-slot=range-months-month]\")].map((month) =>\n\t\t\t\t\tMath.round(month.getBoundingClientRect().top),\n\t\t\t\t),\n\t\t\t).size;\n\t\texpect(tops(mount({}, 800))).toBe(1);\n\t\tdocument.body.replaceChildren();\n\t\texpect(tops(mount({}, 400))).toBe(2);\n\t});\n\n\ttest(\"previews the pending range up to the hovered day across rows\", async () => {\n\t\tlet root = mount({ start: \"2026-03-05\" });\n\t\tlet preview = \"rgb(240, 244, 252)\";\n\t\tawait userEvent.hover(root.querySelector('a[data-date=\"2026-03-10\"]')!);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-06\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-09\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-10\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-11\")).backgroundColor).not.toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-04\")).backgroundColor).not.toBe(preview);\n\t});\n});\n"
|
|
17
|
+
"content": "/**\n * Renders `RangeMonths` in a real browser: the weeks and weekday columns each month lays out, the\n * link every day carries in each selection state, the days that are never links, the band a\n * range draws, and a single month fitting a 320px phone without scrolling sideways.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport { render } from \"remix/component/test\";\nimport { afterEach, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { RangeMonths } from \"@sdxc/ui/range-months\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The words read to assistive technology. */\nconst LABELS: RangeMonths.Labels = {\n\tprevious: \"Previous month\",\n\tnext: \"Next month\",\n\tstart: \"check-in\",\n\tend: \"check-out\",\n};\n\n/** The tokens the band and the ends read, which an app's palette would otherwise supply. */\nconst TOKENS = {\n\t\"--ui-brand-bg-solid\": \"rgb(30, 90, 200)\",\n\t\"--ui-brand-fg-on-solid\": \"rgb(255, 255, 255)\",\n\t\"--ui-brand-bg-tint-hover\": \"rgb(220, 230, 250)\",\n\t\"--ui-brand-bg-tint\": \"rgb(240, 244, 252)\",\n};\n\n/** Encodes a link's selection as a query string, so a test reads back what a click selects. */\nfunction href(next: RangeMonths.Next): string {\n\treturn `/stay?${new URLSearchParams({ ...next })}`;\n}\n\n/** Mounts a calendar `width` pixels wide with `props` over a March 2026 default and returns its root. */\nfunction mount(props: Partial<RangeMonths.Props> = {}, width = 800): HTMLElement {\n\tlet host = document.createElement(\"div\");\n\thost.style.width = `${width}px`;\n\tfor (let [name, value] of Object.entries(TOKENS)) host.style.setProperty(name, value);\n\tdocument.body.appendChild(host);\n\trender(\n\t\t<RangeMonths\n\t\t\tlabel=\"Stay dates\"\n\t\t\tlabels={LABELS}\n\t\t\tlocale=\"en-US\"\n\t\t\tmonth=\"2026-03\"\n\t\t\thref={href}\n\t\t\t{...props}\n\t\t/>,\n\t\t{\n\t\t\tcontainer: host,\n\t\t},\n\t);\n\treturn host.querySelector<HTMLElement>(\"[data-slot=range-months]\")!;\n}\n\n/** The query a day's link carries, or `null` when the day is not a link. */\nfunction linkOf(root: HTMLElement, date: string): string | null {\n\tlet link = root.querySelector(`a[data-date=\"${date}\"]`);\n\treturn link === null ? null : link.getAttribute(\"href\")!.replace(\"/stay?\", \"\");\n}\n\n/** A day's `<td>`. */\nfunction cellOf(root: HTMLElement, date: string): HTMLElement {\n\treturn root.querySelector<HTMLElement>(`[data-date=\"${date}\"]`)!.closest(\"td\")!;\n}\n\nafterEach(() => {\n\tdocument.body.replaceChildren();\n});\n\ndescribe(\"RangeMonths\", () => {\n\ttest(\"lays out each month's weeks with every day once\", () => {\n\t\tlet root = mount({ months: 2 });\n\t\tlet months = root.querySelectorAll(\"[data-slot=range-months-month]\");\n\t\texpect(months).toHaveLength(2);\n\t\texpect(months[0]?.querySelectorAll(\"tbody tr\")).toHaveLength(5);\n\t\texpect(months[0]?.querySelectorAll(\"[data-date]\")).toHaveLength(31);\n\t\texpect(months[1]?.querySelectorAll(\"[data-date]\")).toHaveLength(30);\n\t\texpect(months[0]?.querySelector(\"table\")?.getAttribute(\"aria-label\")).toBe(\"March 2026\");\n\t\texpect(months[1]?.querySelector(\"h2, h3, h4, h5, h6, h1\")?.textContent).toBe(\"April 2026\");\n\t\tlet firstRow = [...months[0]!.querySelectorAll(\"tbody tr:first-child td\")];\n\t\texpect(firstRow.findIndex((cell) => cell.querySelector(\"[data-date]\") !== null)).toBe(0);\n\t});\n\n\ttest(\"orders the weekday columns from weekStartsOn\", () => {\n\t\tlet sunday = mount({ months: 1 });\n\t\texpect([...sunday.querySelectorAll(\"th\")].map((cell) => cell.textContent)).toEqual([\n\t\t\t\"Sun\",\n\t\t\t\"Mon\",\n\t\t\t\"Tue\",\n\t\t\t\"Wed\",\n\t\t\t\"Thu\",\n\t\t\t\"Fri\",\n\t\t\t\"Sat\",\n\t\t]);\n\t\tdocument.body.replaceChildren();\n\t\tlet monday = mount({ months: 1, weekStartsOn: 1 });\n\t\texpect(monday.querySelector(\"th\")?.textContent).toBe(\"Mon\");\n\t\texpect(monday.querySelectorAll(\"tbody tr:first-child td\")[6]?.textContent).toBe(\"1\");\n\t});\n\n\ttest(\"links each day to a new start when nothing is chosen\", () => {\n\t\tlet root = mount();\n\t\texpect(linkOf(root, \"2026-03-10\")).toBe(\"month=2026-03&start=2026-03-10\");\n\t});\n\n\ttest(\"links a later day to the end and an earlier one to a new start once a start is chosen\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\" });\n\t\texpect(linkOf(root, \"2026-03-14\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-14\");\n\t\texpect(linkOf(root, \"2026-03-08\")).toBe(\"month=2026-03&start=2026-03-08\");\n\t\texpect(linkOf(root, \"2026-03-10\")).toBe(\"month=2026-03&start=2026-03-10\");\n\t});\n\n\ttest(\"restarts at the clicked day once both ends are chosen\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\", end: \"2026-03-14\" });\n\t\texpect(linkOf(root, \"2026-03-20\")).toBe(\"month=2026-03&start=2026-03-20\");\n\t});\n\n\ttest(\"links each day as the start alone in single mode, with no band\", () => {\n\t\tlet root = mount({ single: true, start: \"2026-03-10\", end: \"2026-03-14\" });\n\t\texpect(linkOf(root, \"2026-03-20\")).toBe(\"month=2026-03&start=2026-03-20\");\n\t\texpect(cellOf(root, \"2026-03-10\").dataset.range).toBe(\"only\");\n\t\texpect(cellOf(root, \"2026-03-12\").dataset.range).toBeUndefined();\n\t});\n\n\ttest(\"keeps the selection on the month links and hides previous before min's month\", () => {\n\t\tlet root = mount({ start: \"2026-03-10\", end: \"2026-03-14\", min: \"2026-03-05\" });\n\t\texpect(root.querySelector(\"[data-slot=range-months-previous]\")).toBeNull();\n\t\texpect(root.querySelector(\"[data-slot=range-months-next]\")?.getAttribute(\"href\")).toBe(\n\t\t\t\"/stay?month=2026-04&start=2026-03-10&end=2026-03-14\",\n\t\t);\n\t\tdocument.body.replaceChildren();\n\t\tlet later = mount({ month: \"2026-04\", min: \"2026-03-05\", max: \"2026-05-20\" });\n\t\texpect(later.querySelector(\"[data-slot=range-months-previous]\")?.getAttribute(\"href\")).toBe(\n\t\t\t\"/stay?month=2026-03\",\n\t\t);\n\t\texpect(later.querySelector(\"[data-slot=range-months-next]\")).toBeNull();\n\t});\n\n\ttest(\"draws unavailable days and days before min as text, not links\", () => {\n\t\tlet root = mount({\n\t\t\tmin: \"2026-03-05\",\n\t\t\tisUnavailable: (date) => date === \"2026-03-12\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-04\")).toBeNull();\n\t\texpect(cellOf(root, \"2026-03-04\").getAttribute(\"aria-disabled\")).toBe(\"true\");\n\t\texpect(linkOf(root, \"2026-03-12\")).toBeNull();\n\t\texpect(cellOf(root, \"2026-03-12\").hasAttribute(\"data-unavailable\")).toBe(true);\n\t\tlet number = cellOf(root, \"2026-03-12\").querySelector(\"[data-slot=range-months-number]\")!;\n\t\texpect(getComputedStyle(number).textDecorationLine).toContain(\"line-through\");\n\t\texpect(linkOf(root, \"2026-03-05\")).not.toBeNull();\n\t});\n\n\ttest(\"ends a pending range before the first unavailable day after its start\", () => {\n\t\tlet root = mount({\n\t\t\tstart: \"2026-03-10\",\n\t\t\tisUnavailable: (date) => date === \"2026-03-15\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-14\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-14\");\n\t\texpect(cellOf(root, \"2026-03-14\").hasAttribute(\"data-pending\")).toBe(true);\n\t\texpect(linkOf(root, \"2026-03-16\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-04-02\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-03-05\")).toBe(\"month=2026-03&start=2026-03-05\");\n\t});\n\n\ttest(\"in a nights calendar, ends a pending range on the first taken day after its start\", () => {\n\t\tlet root = mount({\n\t\t\tstart: \"2026-03-10\",\n\t\t\tnights: true,\n\t\t\tisUnavailable: (date) => date === \"2026-03-15\" || date === \"2026-03-16\",\n\t\t});\n\t\texpect(linkOf(root, \"2026-03-15\")).toBe(\"month=2026-03&start=2026-03-10&end=2026-03-15\");\n\t\texpect(cellOf(root, \"2026-03-15\").hasAttribute(\"data-pending\")).toBe(true);\n\t\texpect(linkOf(root, \"2026-03-16\")).toBeNull();\n\t\texpect(linkOf(root, \"2026-03-17\")).toBeNull();\n\t});\n\n\ttest(\"marks today with aria-current\", () => {\n\t\tlet root = mount({ today: \"2026-03-18\" });\n\t\texpect(root.querySelector(\"[aria-current=date]\")?.getAttribute(\"data-date\")).toBe(\"2026-03-18\");\n\t\texpect(root.querySelectorAll(\"[aria-current]\")).toHaveLength(1);\n\t});\n\n\ttest(\"draws a chosen range as one band from its start to its end\", () => {\n\t\tlet root = mount({ start: \"2026-03-30\", end: \"2026-04-03\" });\n\t\texpect(cellOf(root, \"2026-03-30\").dataset.range).toBe(\"start\");\n\t\texpect(cellOf(root, \"2026-03-31\").dataset.range).toBe(\"middle\");\n\t\texpect(cellOf(root, \"2026-04-02\").dataset.range).toBe(\"middle\");\n\t\texpect(cellOf(root, \"2026-04-03\").dataset.range).toBe(\"end\");\n\t\texpect(cellOf(root, \"2026-03-29\").dataset.range).toBeUndefined();\n\t\texpect(root.querySelector('a[data-date=\"2026-03-30\"]')?.getAttribute(\"aria-label\")).toBe(\n\t\t\t\"Monday, March 30, 2026, check-in\",\n\t\t);\n\t\tlet start = cellOf(root, \"2026-03-30\").getBoundingClientRect();\n\t\tlet next = cellOf(root, \"2026-03-31\").getBoundingClientRect();\n\t\texpect(next.left - start.right).toBe(0);\n\t\tlet solid = getComputedStyle(root.querySelector('a[data-date=\"2026-03-30\"]')!).backgroundColor;\n\t\tlet plain = getComputedStyle(root.querySelector('a[data-date=\"2026-03-20\"]')!).backgroundColor;\n\t\texpect(solid).toBe(\"rgb(30, 90, 200)\");\n\t\texpect(plain).not.toBe(solid);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-31\")).backgroundColor).toBe(\"rgb(220, 230, 250)\");\n\t});\n\n\ttest(\"puts the caller's note under each day\", () => {\n\t\tlet root = mount({\n\t\t\tmonths: 1,\n\t\t\tdayNote: (date) => <RangeMonths.Note>{`$${Number(date.slice(8))}0`}</RangeMonths.Note>,\n\t\t});\n\t\texpect(\n\t\t\troot.querySelector('[data-date=\"2026-03-07\"] [data-slot=range-months-note]')?.textContent,\n\t\t).toBe(\"$70\");\n\t});\n\n\ttest(\"fits one month inside a 320px phone without scrolling sideways\", () => {\n\t\tlet root = mount({ months: 1, dayNote: () => <RangeMonths.Note>$120</RangeMonths.Note> }, 320);\n\t\texpect(root.scrollWidth).toBeLessThanOrEqual(320);\n\t\texpect(root.getBoundingClientRect().width).toBeLessThanOrEqual(320);\n\t\tlet day = root.querySelector('a[data-date=\"2026-03-10\"]')!.getBoundingClientRect();\n\t\texpect(day.width).toBeGreaterThanOrEqual(40);\n\t\texpect(day.height).toBeGreaterThanOrEqual(40);\n\t});\n\n\ttest(\"sets two months side by side when wide and one per row when narrow\", () => {\n\t\tlet tops = (root: HTMLElement) =>\n\t\t\tnew Set(\n\t\t\t\t[...root.querySelectorAll(\"[data-slot=range-months-month]\")].map((month) =>\n\t\t\t\t\tMath.round(month.getBoundingClientRect().top),\n\t\t\t\t),\n\t\t\t).size;\n\t\texpect(tops(mount({}, 800))).toBe(1);\n\t\tdocument.body.replaceChildren();\n\t\texpect(tops(mount({}, 400))).toBe(2);\n\t});\n\n\ttest(\"previews the pending range up to the hovered day across rows\", async () => {\n\t\tlet root = mount({ start: \"2026-03-05\" });\n\t\tlet preview = \"rgb(240, 244, 252)\";\n\t\tawait userEvent.hover(root.querySelector('a[data-date=\"2026-03-10\"]')!);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-06\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-09\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-10\")).backgroundColor).toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-11\")).backgroundColor).not.toBe(preview);\n\t\texpect(getComputedStyle(cellOf(root, \"2026-03-04\")).backgroundColor).not.toBe(preview);\n\t});\n});\n"
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rating-input",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.29",
|
|
4
4
|
"dependencies": [
|
|
5
5
|
"rating"
|
|
6
6
|
],
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
],
|
|
10
10
|
"source": {
|
|
11
11
|
"path": "rating-input.tsx",
|
|
12
|
-
"content": "/**\n * A star picker for a review form: a fieldset of native radios drawn as stars, where the\n * picked star and every one before it fill, and hovering previews a score. It posts a plain\n * number, the arrow keys move between stars, and it works with no script at all.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\nimport { STAR_PATH } from \"@sdxc/ui/rating\";\n\n/** Painted on a filled star. */\nconst FILLED = \"var(--ui-rating-color, var(--ui-warning-bg-solid))\";\n\n/** Painted on a star past the score. */\nconst EMPTY = \"var(--ui-neutral-border-strong, var(--ui-neutral-border))\";\n\n/** Prop types for {@link RatingInput}. */\nexport namespace RatingInput {\n\t/** Props accepted by {@link RatingInput}; the host is a `<fieldset>`. */\n\texport interface Props extends Omit<TagProps<\"fieldset\">, \"
|
|
12
|
+
"content": "/**\n * A star picker for a review form: a fieldset of native radios drawn as stars, where the\n * picked star and every one before it fill, and hovering previews a score. It posts a plain\n * number, the arrow keys move between stars, and it works with no script at all.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { visuallyHidden } from \"@sdxc/u/a11y\";\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\nimport { STAR_PATH } from \"@sdxc/ui/rating\";\n\n/** Painted on a filled star. */\nconst FILLED = \"var(--ui-rating-color, var(--ui-warning-bg-solid))\";\n\n/** Painted on a star past the score. */\nconst EMPTY = \"var(--ui-neutral-border-strong, var(--ui-neutral-border))\";\n\n/** Prop types for {@link RatingInput} and its parts. */\nexport namespace RatingInput {\n\t/** Props accepted by {@link RatingInput}; the host is a `<fieldset>`. */\n\texport interface Props extends Omit<TagProps<\"fieldset\">, \"name\"> {\n\t\t/** A {@link RatingInput.Legend} asking the question the stars answer. */\n\t\tchildren?: RemixNode;\n\t\t/** The field the score posts as. */\n\t\tname: string;\n\t\t/** The score picked now, from 1 to the number of labels. */\n\t\tvalue?: number;\n\t\trequired?: boolean;\n\t\t/** One name per star, lowest first, such as \"1 star — Poor\"; their count sets the scale. */\n\t\tlabels: string[];\n\t}\n\n\t/** Every native `<legend>` attribute. */\n\texport interface LegendProps extends TagProps<\"legend\"> {}\n}\n\n/**\n * Renders its {@link RatingInput.Legend}, then one radio and its star label per entry of `labels`, in score order so the native\n * arrow keys step up and down the scale. A star fills when its own radio or any later one is\n * checked, and hovering a star fills it and every earlier one in place of the checked score.\n *\n * @example\n * <RatingInput name=\"rating\" required labels={[\"1 star — Poor\", \"2 stars — Fair\", \"3 stars — Good\", \"4 stars — Great\", \"5 stars — Excellent\"]}>\n * \t<RatingInput.Legend>Your rating</RatingInput.Legend>\n * </RatingInput>\n */\nexport function RatingInput(handle: Handle<RatingInput.Props>) {\n\treturn () => {\n\t\tlet { children, id, labels, mix, name, required, value, ...rest } = handle.props;\n\t\tlet base = id ?? handle.id;\n\t\treturn (\n\t\t\t<fieldset\n\t\t\t\t{...rest}\n\t\t\t\tid={id}\n\t\t\t\tdata-slot=\"rating-input\"\n\t\t\t\tmix={mergeMix([raw({ margin: \"0\", padding: \"0\", border: \"0\", minInlineSize: \"0\" })], mix)}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t\t<div\n\t\t\t\t\tdata-slot=\"rating-input-stars\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\tgap: \"0.125rem\",\n\t\t\t\t\t\t\t\"& label\": {\n\t\t\t\t\t\t\t\tdisplay: \"grid\",\n\t\t\t\t\t\t\t\tplaceItems: \"center\",\n\t\t\t\t\t\t\t\tinlineSize: \"2.75rem\",\n\t\t\t\t\t\t\t\tblockSize: \"2.75rem\",\n\t\t\t\t\t\t\t\tborderRadius: \"0.5rem\",\n\t\t\t\t\t\t\t\tcolor: EMPTY,\n\t\t\t\t\t\t\t\tcursor: \"pointer\",\n\t\t\t\t\t\t\t\ttransition: \"color 120ms ease, transform 120ms ease\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& svg\": { inlineSize: \"1.75rem\", blockSize: \"1.75rem\" },\n\t\t\t\t\t\t\t\"& input:checked + label, & label:has(~ input:checked)\": { color: FILLED },\n\t\t\t\t\t\t\t\"&:has(label:hover) label\": { color: EMPTY },\n\t\t\t\t\t\t\t\"&:has(label:hover) label:hover, &:has(label:hover) label:has(~ label:hover)\": {\n\t\t\t\t\t\t\t\tcolor: FILLED,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& input:focus-visible + label\": {\n\t\t\t\t\t\t\t\toutline: \"2px solid var(--ui-brand-ring)\",\n\t\t\t\t\t\t\t\toutlineOffset: \"-2px\",\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\"& input:disabled + label\": { cursor: \"not-allowed\", opacity: \"0.5\" },\n\t\t\t\t\t\t\t\"@media (prefers-reduced-motion: reduce)\": { \"& label\": { transition: \"none\" } },\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t{labels.map((label, index) => {\n\t\t\t\t\t\tlet score = index + 1;\n\t\t\t\t\t\tlet inputId = `${base}-${score}`;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<input\n\t\t\t\t\t\t\t\t\ttype=\"radio\"\n\t\t\t\t\t\t\t\t\tid={inputId}\n\t\t\t\t\t\t\t\t\tname={name}\n\t\t\t\t\t\t\t\t\tvalue={String(score)}\n\t\t\t\t\t\t\t\t\tdefaultChecked={value === score}\n\t\t\t\t\t\t\t\t\trequired={required}\n\t\t\t\t\t\t\t\t\tmix={[visuallyHidden()]}\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t<label htmlFor={inputId} title={label} data-score={String(score)}>\n\t\t\t\t\t\t\t\t\t<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\">\n\t\t\t\t\t\t\t\t\t\t<path d={STAR_PATH} fill=\"currentColor\" />\n\t\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t\t\t<span mix={[visuallyHidden()]}>{label}</span>\n\t\t\t\t\t\t\t\t</label>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t);\n\t\t\t\t\t})}\n\t\t\t\t</div>\n\t\t\t</fieldset>\n\t\t);\n\t};\n}\n\n/**\n * The question the stars answer, such as \"Your rating\", which names the group.\n *\n * @param handle Runtime handle carrying the host `<legend>`'s props.\n * @returns The render function producing the legend.\n */\nRatingInput.Legend = function RatingInputLegend(handle: Handle<RatingInput.LegendProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<legend\n\t\t\t\tdata-slot=\"rating-input-legend\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tpadding: \"0\",\n\t\t\t\t\t\t\tmarginBlockEnd: \"0.5rem\",\n\t\t\t\t\t\t\tfontSize: \"0.875rem\",\n\t\t\t\t\t\t\tfontWeight: \"600\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-emphasis)\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
13
13
|
},
|
|
14
14
|
"test": {
|
|
15
15
|
"path": "rating-input.browser.test.tsx",
|
|
16
|
-
"content": "/**\n * Holds the star picker to its contract in a real browser: one radio per label in score\n * order, the picked star and every earlier one filled, hovering previewing a score, and the\n * arrow keys stepping along the scale.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterAll, afterEach, beforeAll, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { RatingInput } from \"@sdxc/ui/rating-input\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** One name per star. */\nconst LABELS = [\n\t\"1 star — Poor\",\n\t\"2 stars — Fair\",\n\t\"3 stars — Good\",\n\t\"4 stars — Great\",\n\t\"5 stars — Excellent\",\n];\n\n/** The palette steps the stars paint with, which an app defines and a test stands in for. */\nconst PALETTE = {\n\t\"--ui-color-warning-600\": \"rgb(217, 119, 6)\",\n\t\"--ui-color-neutral-600\": \"rgb(82, 82, 91)\",\n\t\"--ui-color-neutral-400\": \"rgb(161, 161, 170)\",\n};\n\nlet mounted: RenderResult | undefined;\n\nbeforeAll(() => {\n\tfor (let [name, value] of Object.entries(PALETTE)) {\n\t\tdocument.documentElement.style.setProperty(name, value);\n\t}\n});\n\nafterAll(() => {\n\tfor (let name of Object.keys(PALETTE)) document.documentElement.style.removeProperty(name);\n});\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\n/** Each star's painted colour, lowest first. */\nfunction colors(root: HTMLElement): string[] {\n\treturn [...root.querySelectorAll<HTMLElement>(\"label\")].map(\n\t\t(label) => getComputedStyle(label).color,\n\t);\n}\n\n/** Which stars read as filled, lowest first, against the colour of the last star. */\nfunction filled(root: HTMLElement, empty: string): boolean[] {\n\treturn colors(root).map((color) => color !== empty);\n}\n\n/** Waits until a check passes, for a colour that eases between stars. */\nasync function until(check: () => boolean, timeout = 1000): Promise<void> {\n\tlet start = performance.now();\n\twhile (!check()) {\n\t\tif (performance.now() - start > timeout) throw new Error(\"timed out\");\n\t\tawait new Promise((resolve) => setTimeout(resolve, 20));\n\t}\n}\n\n/** Whether the stars read filled exactly as `expected`, lowest first. */\nfunction reads(root: HTMLElement, empty: string, expected: boolean[]): boolean {\n\treturn filled(root, empty).join() === expected.join();\n}\n\ndescribe(\"RatingInput\", () => {\n\ttest(\"renders one named radio per label in score order inside a fieldset\", () => {\n\t\tmounted = render(<RatingInput name=\"rating\"
|
|
16
|
+
"content": "/**\n * Holds the star picker to its contract in a real browser: one radio per label in score\n * order, the picked star and every earlier one filled, hovering previewing a score, and the\n * arrow keys stepping along the scale.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterAll, afterEach, beforeAll, describe, expect, test } from \"vitest\";\nimport { userEvent } from \"vitest/browser\";\n\nimport { RatingInput } from \"@sdxc/ui/rating-input\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** One name per star. */\nconst LABELS = [\n\t\"1 star — Poor\",\n\t\"2 stars — Fair\",\n\t\"3 stars — Good\",\n\t\"4 stars — Great\",\n\t\"5 stars — Excellent\",\n];\n\n/** The palette steps the stars paint with, which an app defines and a test stands in for. */\nconst PALETTE = {\n\t\"--ui-color-warning-600\": \"rgb(217, 119, 6)\",\n\t\"--ui-color-neutral-600\": \"rgb(82, 82, 91)\",\n\t\"--ui-color-neutral-400\": \"rgb(161, 161, 170)\",\n};\n\nlet mounted: RenderResult | undefined;\n\nbeforeAll(() => {\n\tfor (let [name, value] of Object.entries(PALETTE)) {\n\t\tdocument.documentElement.style.setProperty(name, value);\n\t}\n});\n\nafterAll(() => {\n\tfor (let name of Object.keys(PALETTE)) document.documentElement.style.removeProperty(name);\n});\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\n/** Each star's painted colour, lowest first. */\nfunction colors(root: HTMLElement): string[] {\n\treturn [...root.querySelectorAll<HTMLElement>(\"label\")].map(\n\t\t(label) => getComputedStyle(label).color,\n\t);\n}\n\n/** Which stars read as filled, lowest first, against the colour of the last star. */\nfunction filled(root: HTMLElement, empty: string): boolean[] {\n\treturn colors(root).map((color) => color !== empty);\n}\n\n/** Waits until a check passes, for a colour that eases between stars. */\nasync function until(check: () => boolean, timeout = 1000): Promise<void> {\n\tlet start = performance.now();\n\twhile (!check()) {\n\t\tif (performance.now() - start > timeout) throw new Error(\"timed out\");\n\t\tawait new Promise((resolve) => setTimeout(resolve, 20));\n\t}\n}\n\n/** Whether the stars read filled exactly as `expected`, lowest first. */\nfunction reads(root: HTMLElement, empty: string, expected: boolean[]): boolean {\n\treturn filled(root, empty).join() === expected.join();\n}\n\ndescribe(\"RatingInput\", () => {\n\ttest(\"renders one named radio per label in score order inside a fieldset\", () => {\n\t\tmounted = render(\n\t\t\t<RatingInput name=\"rating\" required labels={LABELS}>\n\t\t\t\t<RatingInput.Legend>Your rating</RatingInput.Legend>\n\t\t\t</RatingInput>,\n\t\t);\n\t\tlet fieldset = mounted.container.querySelector(\"fieldset\")!;\n\t\texpect(fieldset.querySelector(\"legend\")!.textContent).toBe(\"Your rating\");\n\t\tlet radios = [...fieldset.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]')];\n\t\texpect(radios.map((radio) => radio.value)).toEqual([\"1\", \"2\", \"3\", \"4\", \"5\"]);\n\t\texpect(radios.every((radio) => radio.name === \"rating\" && radio.required)).toBe(true);\n\t\texpect(radios[2]!.labels![0]!.textContent).toBe(\"3 stars — Good\");\n\t});\n\n\ttest(\"fills the picked star and every earlier one, and previews on hover\", async () => {\n\t\tmounted = render(\n\t\t\t<RatingInput name=\"rating\" value={2} labels={LABELS}>\n\t\t\t\t<RatingInput.Legend>Your rating</RatingInput.Legend>\n\t\t\t</RatingInput>,\n\t\t);\n\t\tlet root = mounted.container;\n\t\tlet empty = colors(root)[4]!;\n\t\texpect(filled(root, empty)).toEqual([true, true, false, false, false]);\n\t\tlet labels = root.querySelectorAll<HTMLElement>(\"label\");\n\t\tawait userEvent.click(labels[3]!);\n\t\texpect(root.querySelector<HTMLInputElement>(\"input:checked\")!.value).toBe(\"4\");\n\t\tawait until(() => reads(root, empty, [true, true, true, true, false]));\n\t\tawait userEvent.hover(labels[0]!);\n\t\tawait until(() => reads(root, empty, [true, false, false, false, false]));\n\t\tawait userEvent.unhover(labels[0]!);\n\t\tawait until(() => reads(root, empty, [true, true, true, true, false]));\n\t});\n\n\ttest(\"steps up the scale with the arrow keys\", async () => {\n\t\tmounted = render(\n\t\t\t<RatingInput name=\"rating\" value={3} labels={LABELS}>\n\t\t\t\t<RatingInput.Legend>Your rating</RatingInput.Legend>\n\t\t\t</RatingInput>,\n\t\t);\n\t\tlet checked = mounted.container.querySelector<HTMLInputElement>(\"input:checked\")!;\n\t\tchecked.focus();\n\t\tawait userEvent.keyboard(\"{ArrowRight}\");\n\t\texpect(mounted.container.querySelector<HTMLInputElement>(\"input:checked\")!.value).toBe(\"4\");\n\t});\n});\n"
|
|
17
17
|
}
|
|
18
18
|
}
|
package/registry/ui/rating.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rating",
|
|
3
|
-
"changedIn": "2026.11.
|
|
3
|
+
"changedIn": "2026.11.29",
|
|
4
4
|
"dependencies": [],
|
|
5
5
|
"exports": [
|
|
6
6
|
"STAR_PATH",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
],
|
|
9
9
|
"source": {
|
|
10
10
|
"path": "rating.tsx",
|
|
11
|
-
"content": "/**\n * A score out of a few stars, read at a glance: a muted row of stars with a filled row laid\n * over it and clipped to the score's share, so 4.3 shows the fourth star whole and a third of\n * the fifth. Assistive tech reads one sentence instead of five pictures.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\n/** The outline of a five-pointed star in a 24 × 24 box. */\nexport const STAR_PATH =\n\t\"M12 2.5l2.94 5.96 6.56.95-4.75 4.63 1.12 6.54L12 17.5l-5.87 3.08 1.12-6.54L2.5 9.41l6.56-.95L12 2.5z\";\n\n/** Top of the scale when `max` is left out. */\nconst DEFAULT_MAX = 5;\n\n/** Edge of one star, by size. */\nconst STAR_SIZE = { sm: \"0.875rem\", md: \"1.125rem\" } as const;\n\n/** Prop types for {@link Rating}. */\nexport namespace Rating {\n\t/** Props accepted by {@link Rating}; the host is a `<span>`. */\n\texport interface Props extends
|
|
11
|
+
"content": "/**\n * A score out of a few stars, read at a glance: a muted row of stars with a filled row laid\n * over it and clipped to the score's share, so 4.3 shows the fourth star whole and a third of\n * the fifth. Assistive tech reads one sentence instead of five pictures.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type { Handle, Props as TagProps, RemixNode } from \"remix/component\";\n\nimport { mergeMix, raw } from \"@sdxc/u/general\";\n\n/** The outline of a five-pointed star in a 24 × 24 box. */\nexport const STAR_PATH =\n\t\"M12 2.5l2.94 5.96 6.56.95-4.75 4.63 1.12 6.54L12 17.5l-5.87 3.08 1.12-6.54L2.5 9.41l6.56-.95L12 2.5z\";\n\n/** Top of the scale when `max` is left out. */\nconst DEFAULT_MAX = 5;\n\n/** Edge of one star, by size. */\nconst STAR_SIZE = { sm: \"0.875rem\", md: \"1.125rem\" } as const;\n\n/** Prop types for {@link Rating} and its parts. */\nexport namespace Rating {\n\t/** Props accepted by {@link Rating}; the host is a `<span>`. */\n\texport interface Props extends TagProps<\"span\"> {\n\t\t/** A {@link Rating.Count} after the stars. */\n\t\tchildren?: RemixNode;\n\t\t/** The score, fractional, between 0 and `max`; a value outside is held to the scale. */\n\t\tvalue: number;\n\t\t/** @default 5 */\n\t\tmax?: number;\n\t\t/** @default \"md\" */\n\t\tsize?: \"sm\" | \"md\";\n\t\t/** What assistive tech reads; `{value}` and `{max}` fill in. @default \"{value} out of {max} stars\" */\n\t\tlabel?: string;\n\t}\n\n\t/** Every native `<span>` attribute. */\n\texport interface CountProps extends TagProps<\"span\"> {}\n}\n\n/** A row of `count` stars painted in the current colour. */\nfunction Stars(handle: Handle<{ count: number }>) {\n\treturn () => (\n\t\t<>\n\t\t\t{Array.from({ length: handle.props.count }, () => (\n\t\t\t\t<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\">\n\t\t\t\t\t<path d={STAR_PATH} fill=\"currentColor\" />\n\t\t\t\t</svg>\n\t\t\t))}\n\t\t</>\n\t);\n}\n\n/**\n * Renders the stars as one `role=\"img\"` whose name states the score, followed by any parts given,\n * such as a {@link Rating.Count}.\n * Stars take `--ui-rating-color` (the warning tone by default) and empty ones the border tone,\n * so a theme recolours every rating at once.\n *\n * @example <Rating value={4.3}><Rating.Count>(128)</Rating.Count></Rating>\n * @example <Rating value={5} size=\"sm\" label=\"Rated {value} of {max}\" />\n */\nexport function Rating(handle: Handle<Rating.Props>) {\n\treturn () => {\n\t\tlet {\n\t\t\tchildren,\n\t\t\tlabel = \"{value} out of {max} stars\",\n\t\t\tmax = DEFAULT_MAX,\n\t\t\tmix,\n\t\t\tsize = \"md\",\n\t\t\tvalue,\n\t\t\t...rest\n\t\t} = handle.props;\n\t\tlet score = Math.min(Math.max(value, 0), max);\n\t\tlet share = max > 0 ? (score / max) * 100 : 0;\n\t\tlet spoken = label\n\t\t\t.replace(\"{value}\", String(Math.round(score * 10) / 10))\n\t\t\t.replace(\"{max}\", String(max));\n\t\tlet star = STAR_SIZE[size];\n\t\treturn (\n\t\t\t<span\n\t\t\t\t{...rest}\n\t\t\t\tdata-slot=\"rating\"\n\t\t\t\tdata-size={size}\n\t\t\t\tmix={mergeMix(\n\t\t\t\t\t[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\talignItems: \"center\",\n\t\t\t\t\t\t\tgap: \"0.375rem\",\n\t\t\t\t\t\t\tfontSize: size === \"sm\" ? \"0.8125rem\" : \"0.875rem\",\n\t\t\t\t\t\t\tlineHeight: \"1\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-fg-muted)\",\n\t\t\t\t\t\t\tverticalAlign: \"middle\",\n\t\t\t\t\t\t}),\n\t\t\t\t\t],\n\t\t\t\t\tmix,\n\t\t\t\t)}\n\t\t\t>\n\t\t\t\t<span\n\t\t\t\t\trole=\"img\"\n\t\t\t\t\taria-label={spoken}\n\t\t\t\t\tdata-slot=\"rating-stars\"\n\t\t\t\t\tmix={[\n\t\t\t\t\t\traw({\n\t\t\t\t\t\t\tposition: \"relative\",\n\t\t\t\t\t\t\tdisplay: \"inline-flex\",\n\t\t\t\t\t\t\tflex: \"none\",\n\t\t\t\t\t\t\tcolor: \"var(--ui-neutral-border-strong, var(--ui-neutral-border))\",\n\t\t\t\t\t\t\t\"& svg\": {\n\t\t\t\t\t\t\t\tdisplay: \"block\",\n\t\t\t\t\t\t\t\tflex: \"none\",\n\t\t\t\t\t\t\t\tinlineSize: star,\n\t\t\t\t\t\t\t\tblockSize: star,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}),\n\t\t\t\t\t]}\n\t\t\t\t>\n\t\t\t\t\t<Stars count={max} />\n\t\t\t\t\t<span\n\t\t\t\t\t\tdata-slot=\"rating-fill\"\n\t\t\t\t\t\tstyle={{ inlineSize: `${Math.round(share * 100) / 100}%` }}\n\t\t\t\t\t\tmix={[\n\t\t\t\t\t\t\traw({\n\t\t\t\t\t\t\t\tposition: \"absolute\",\n\t\t\t\t\t\t\t\tinsetBlock: \"0\",\n\t\t\t\t\t\t\t\tinsetInlineStart: \"0\",\n\t\t\t\t\t\t\t\tdisplay: \"flex\",\n\t\t\t\t\t\t\t\toverflow: \"clip\",\n\t\t\t\t\t\t\t\twhiteSpace: \"nowrap\",\n\t\t\t\t\t\t\t\tcolor: \"var(--ui-rating-color, var(--ui-warning-bg-solid))\",\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t]}\n\t\t\t\t\t>\n\t\t\t\t\t\t<Stars count={max} />\n\t\t\t\t\t</span>\n\t\t\t\t</span>\n\t\t\t\t{children}\n\t\t\t</span>\n\t\t);\n\t};\n}\n\n/**\n * How many ratings the score averages, after the stars in tabular figures: \"(128)\", \"128\n * reviews\" or a link to them.\n *\n * @param handle Runtime handle carrying the host `<span>`'s props.\n * @returns The render function producing the count.\n * @example <Rating.Count>(128)</Rating.Count>\n */\nRating.Count = function RatingCount(handle: Handle<Rating.CountProps>) {\n\treturn () => {\n\t\tlet { mix, ...rest } = handle.props;\n\t\treturn (\n\t\t\t<span\n\t\t\t\tdata-slot=\"rating-count\"\n\t\t\t\t{...rest}\n\t\t\t\tmix={mergeMix([raw({ fontVariantNumeric: \"tabular-nums\" })], mix)}\n\t\t\t/>\n\t\t);\n\t};\n};\n"
|
|
12
12
|
},
|
|
13
13
|
"test": {
|
|
14
14
|
"path": "rating.browser.test.tsx",
|
|
15
|
-
"content": "/**\n * Holds the star rating to its contract in a real browser: the filled row covers the score's\n * share, the score is read as one sentence held to the scale, and the count follows the stars.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterAll, afterEach, beforeAll, describe, expect, test } from \"vitest\";\n\nimport { Rating } from \"@sdxc/ui/rating\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The palette steps the stars paint with, which an app defines and a test stands in for. */\nconst PALETTE = {\n\t\"--ui-color-warning-600\": \"rgb(217, 119, 6)\",\n\t\"--ui-color-neutral-600\": \"rgb(82, 82, 91)\",\n\t\"--ui-color-neutral-400\": \"rgb(161, 161, 170)\",\n};\n\nlet mounted: RenderResult | undefined;\n\nbeforeAll(() => {\n\tfor (let [name, value] of Object.entries(PALETTE)) {\n\t\tdocument.documentElement.style.setProperty(name, value);\n\t}\n});\n\nafterAll(() => {\n\tfor (let name of Object.keys(PALETTE)) document.documentElement.style.removeProperty(name);\n});\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\ndescribe(\"Rating\", () => {\n\ttest(\"fills the score's share of the stars and reads it as one sentence\", () => {\n\t\tmounted = render(<Rating value={4.3}
|
|
15
|
+
"content": "/**\n * Holds the star rating to its contract in a real browser: the filled row covers the score's\n * share, the score is read as one sentence held to the scale, and the count follows the stars.\n *\n * @author [Sergio Xalambrí](https://sergiodxa.com)\n * @copyright Sergio Xalambrí 2026\n */\n\nimport type {} from \"@vitest/browser-playwright\";\nimport type { RenderResult } from \"remix/component/test\";\n\nimport { render } from \"remix/component/test\";\nimport { afterAll, afterEach, beforeAll, describe, expect, test } from \"vitest\";\n\nimport { Rating } from \"@sdxc/ui/rating\";\n\nimport \"@sdxc/ui/reset.css\";\nimport \"@sdxc/u/theme.css\";\nimport \"@sdxc/ui/theme.css\";\n\n/** The palette steps the stars paint with, which an app defines and a test stands in for. */\nconst PALETTE = {\n\t\"--ui-color-warning-600\": \"rgb(217, 119, 6)\",\n\t\"--ui-color-neutral-600\": \"rgb(82, 82, 91)\",\n\t\"--ui-color-neutral-400\": \"rgb(161, 161, 170)\",\n};\n\nlet mounted: RenderResult | undefined;\n\nbeforeAll(() => {\n\tfor (let [name, value] of Object.entries(PALETTE)) {\n\t\tdocument.documentElement.style.setProperty(name, value);\n\t}\n});\n\nafterAll(() => {\n\tfor (let name of Object.keys(PALETTE)) document.documentElement.style.removeProperty(name);\n});\n\nafterEach(() => {\n\tmounted?.cleanup();\n\tmounted = undefined;\n});\n\ndescribe(\"Rating\", () => {\n\ttest(\"fills the score's share of the stars and reads it as one sentence\", () => {\n\t\tmounted = render(\n\t\t\t<Rating value={4.3}>\n\t\t\t\t<Rating.Count>(128)</Rating.Count>\n\t\t\t</Rating>,\n\t\t);\n\t\tlet stars = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-stars\"]')!;\n\t\tlet fill = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-fill\"]')!;\n\t\texpect(stars.getAttribute(\"role\")).toBe(\"img\");\n\t\texpect(stars.getAttribute(\"aria-label\")).toBe(\"4.3 out of 5 stars\");\n\t\texpect(stars.querySelectorAll(\":scope > svg\")).toHaveLength(5);\n\t\tlet share = fill.getBoundingClientRect().width / stars.getBoundingClientRect().width;\n\t\texpect(share).toBeCloseTo(0.86, 2);\n\t\texpect(getComputedStyle(fill).color).not.toBe(getComputedStyle(stars).color);\n\t\texpect(mounted.container.querySelector('[data-slot=\"rating-count\"]')!.textContent).toBe(\n\t\t\t\"(128)\",\n\t\t);\n\t});\n\n\ttest(\"holds a score to the scale, names it in the caller's words and takes a count in words\", () => {\n\t\tmounted = render(\n\t\t\t<Rating value={7} max={4} size=\"sm\" label=\"Rated {value} of {max}\">\n\t\t\t\t<Rating.Count>12 reviews</Rating.Count>\n\t\t\t</Rating>,\n\t\t);\n\t\tlet fill = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-fill\"]')!;\n\t\tlet stars = mounted.container.querySelector<HTMLElement>('[data-slot=\"rating-stars\"]')!;\n\t\texpect(stars.getAttribute(\"aria-label\")).toBe(\"Rated 4 of 4\");\n\t\texpect(fill.getBoundingClientRect().width).toBeCloseTo(stars.getBoundingClientRect().width, 0);\n\t\texpect(mounted.container.textContent).toBe(\"12 reviews\");\n\t});\n\n\ttest(\"leaves the count out when none is given\", () => {\n\t\tmounted = render(<Rating value={0} />);\n\t\texpect(mounted.container.querySelector('[data-slot=\"rating-count\"]')).toBeNull();\n\t\texpect(\n\t\t\tmounted.container\n\t\t\t\t.querySelector<HTMLElement>('[data-slot=\"rating-fill\"]')!\n\t\t\t\t.getBoundingClientRect().width,\n\t\t).toBe(0);\n\t});\n});\n"
|
|
16
16
|
}
|
|
17
17
|
}
|