@gohopo/xy-core 0.0.0-stage → 0.0.2-alpha.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/contract/button.d.ts +32 -0
  2. package/dist/contract/button.js +26 -0
  3. package/dist/contract/calendar.d.ts +28 -0
  4. package/dist/contract/calendar.js +30 -0
  5. package/dist/contract/checkbox.d.ts +45 -0
  6. package/dist/contract/checkbox.js +46 -0
  7. package/dist/contract/color.d.ts +29 -0
  8. package/dist/contract/color.js +25 -0
  9. package/dist/contract/combobox.d.ts +49 -0
  10. package/dist/contract/combobox.js +51 -0
  11. package/dist/contract/date-input.d.ts +22 -0
  12. package/dist/contract/date-input.js +25 -0
  13. package/dist/contract/date-range-input.d.ts +26 -0
  14. package/dist/contract/date-range-input.js +29 -0
  15. package/dist/contract/dialog.d.ts +18 -0
  16. package/dist/contract/dialog.js +16 -0
  17. package/dist/contract/drawer.d.ts +24 -0
  18. package/dist/contract/drawer.js +18 -0
  19. package/dist/contract/field.d.ts +62 -0
  20. package/dist/contract/field.js +67 -0
  21. package/dist/contract/index.d.ts +28 -0
  22. package/dist/contract/index.js +28 -0
  23. package/dist/contract/listbox.d.ts +41 -0
  24. package/dist/contract/listbox.js +43 -0
  25. package/dist/contract/menu.d.ts +27 -0
  26. package/dist/contract/menu.js +29 -0
  27. package/dist/contract/number-input.d.ts +27 -0
  28. package/dist/contract/number-input.js +30 -0
  29. package/dist/contract/popover.d.ts +20 -0
  30. package/dist/contract/popover.js +25 -0
  31. package/dist/contract/radio-group.d.ts +46 -0
  32. package/dist/contract/radio-group.js +47 -0
  33. package/dist/contract/size.d.ts +6 -0
  34. package/dist/contract/size.js +2 -0
  35. package/dist/contract/slider.d.ts +46 -0
  36. package/dist/contract/slider.js +42 -0
  37. package/dist/contract/split-date-input.d.ts +24 -0
  38. package/dist/contract/split-date-input.js +27 -0
  39. package/dist/contract/switch.d.ts +57 -0
  40. package/dist/contract/switch.js +55 -0
  41. package/dist/contract/table.d.ts +69 -0
  42. package/dist/contract/table.js +58 -0
  43. package/dist/contract/tabs.d.ts +25 -0
  44. package/dist/contract/tabs.js +21 -0
  45. package/dist/contract/textarea.d.ts +20 -0
  46. package/dist/contract/textarea.js +20 -0
  47. package/dist/contract/theme.d.ts +16 -0
  48. package/dist/contract/theme.js +39 -0
  49. package/dist/contract/time-input.d.ts +38 -0
  50. package/dist/contract/time-input.js +41 -0
  51. package/dist/contract/time-range-input.d.ts +26 -0
  52. package/dist/contract/time-range-input.js +29 -0
  53. package/dist/contract/tooltip.d.ts +24 -0
  54. package/dist/contract/tooltip.js +20 -0
  55. package/dist/contract/typography.d.ts +56 -0
  56. package/dist/contract/typography.js +51 -0
  57. package/dist/contract/utils.d.ts +5 -0
  58. package/dist/contract/utils.js +3 -0
  59. package/dist/core/contracts.d.ts +32 -0
  60. package/dist/core/contracts.js +1 -0
  61. package/dist/core/index.d.ts +4 -0
  62. package/dist/core/index.js +4 -0
  63. package/dist/core/provider.d.ts +9 -0
  64. package/dist/core/provider.js +20 -0
  65. package/dist/core/ref.svelte.d.ts +16 -0
  66. package/dist/core/ref.svelte.js +26 -0
  67. package/dist/core/utils.d.ts +7 -0
  68. package/dist/core/utils.js +115 -0
  69. package/dist/index.d.ts +3 -0
  70. package/dist/index.js +3 -0
  71. package/dist/web/dom.svelte.d.ts +30 -0
  72. package/dist/web/dom.svelte.js +91 -0
  73. package/dist/web/events.d.ts +4 -0
  74. package/dist/web/events.js +126 -0
  75. package/dist/web/index.d.ts +4 -0
  76. package/dist/web/index.js +4 -0
  77. package/dist/web/kbd.d.ts +44 -0
  78. package/dist/web/kbd.js +44 -0
  79. package/dist/web/style.d.ts +8 -0
  80. package/dist/web/style.js +51 -0
  81. package/package.json +56 -3
  82. package/README.md +0 -3
@@ -0,0 +1,32 @@
1
+ import { type Color } from "./color.js";
2
+ import type { Orientation, Shape, Size } from "./size.js";
3
+ import { type ClassStyle } from "./utils.js";
4
+ export declare const buttonVariantNames: readonly ["solid", "soft", "outline", "dashed", "text", "link"];
5
+ export type ButtonVariant = typeof buttonVariantNames[number];
6
+ export interface ButtonVariantsOptions {
7
+ /** 整行宽度。 */
8
+ block?: boolean | null;
9
+ /** 不传时 solid 用 primary,其他变体用 neutral;也会继承容器(如 ButtonGroup)设置的组件颜色。 */
10
+ color?: Color | null;
11
+ /** 图标按钮:宽高相等,没有内边距。使用者必须提供 aria-label。 */
12
+ iconOnly?: boolean | null;
13
+ shape?: Shape | null;
14
+ size?: Size | null;
15
+ variant?: ButtonVariant | null;
16
+ }
17
+ export interface ButtonGroupVariantsOptions {
18
+ block?: boolean | null;
19
+ orientation?: Orientation | null;
20
+ }
21
+ /**
22
+ * Button 的变体函数:把参数换算成约定的 class 和 style,让任意元素获得按钮样式。
23
+ *
24
+ * ```ts
25
+ * const { class: cls, style } = buttonVariants({ variant: 'soft', color: 'danger' });
26
+ * // cls = 'xy-button xy-button--soft xy-button--md'
27
+ * // style = '--xy-button-color: var(--xy-danger); --xy-button-color-foreground: var(--xy-danger-foreground);'
28
+ * ```
29
+ */
30
+ export declare function buttonVariants(options?: ButtonVariantsOptions): ClassStyle;
31
+ /** ButtonGroup 的变体函数。组件颜色写在 group 上时,组内的按钮会继承。 */
32
+ export declare function buttonGroupVariants(options?: ButtonGroupVariantsOptions): ClassStyle;
@@ -0,0 +1,26 @@
1
+ import { componentColorStyle } from "./color.js";
2
+ import { joinClasses } from "./utils.js";
3
+ export const buttonVariantNames = ['solid', 'soft', 'outline', 'dashed', 'text', 'link'];
4
+ /**
5
+ * Button 的变体函数:把参数换算成约定的 class 和 style,让任意元素获得按钮样式。
6
+ *
7
+ * ```ts
8
+ * const { class: cls, style } = buttonVariants({ variant: 'soft', color: 'danger' });
9
+ * // cls = 'xy-button xy-button--soft xy-button--md'
10
+ * // style = '--xy-button-color: var(--xy-danger); --xy-button-color-foreground: var(--xy-danger-foreground);'
11
+ * ```
12
+ */
13
+ export function buttonVariants(options = {}) {
14
+ const { block, color, iconOnly, shape, size, variant } = options;
15
+ return {
16
+ class: joinClasses('xy-button', `xy-button--${variant ?? 'solid'}`, `xy-button--${size ?? 'md'}`, shape === 'round' && 'xy-button--round', iconOnly && 'xy-button--icon-only', block && 'xy-button--block'),
17
+ style: componentColorStyle('button', color),
18
+ };
19
+ }
20
+ /** ButtonGroup 的变体函数。组件颜色写在 group 上时,组内的按钮会继承。 */
21
+ export function buttonGroupVariants(options = {}) {
22
+ const { block, orientation } = options;
23
+ return {
24
+ class: joinClasses('xy-button-group', orientation === 'vertical' && 'xy-button-group--vertical', block && 'xy-button-group--block'),
25
+ };
26
+ }
@@ -0,0 +1,28 @@
1
+ import { type ClassStyle } from "./utils.js";
2
+ /**
3
+ * Calendar 的变体函数。日历只有一套尺寸,不跟着输入框的五档变(见 docs/adr/0020)。
4
+ *
5
+ * ```html
6
+ * <div class="xy-calendar">
7
+ * <div class="xy-calendar__header">
8
+ * <button class="xy-calendar__nav" aria-label="上一年">…</button>
9
+ * <button class="xy-calendar__nav" aria-label="上个月">…</button>
10
+ * <div class="xy-calendar__title" aria-live="polite">2025年11月</div>
11
+ * …
12
+ * </div>
13
+ * <table class="xy-calendar__grid" role="grid">
14
+ * <thead><tr><th class="xy-calendar__weekday">…</th>…</tr></thead>
15
+ * <tbody><tr><td class="xy-calendar__day" role="gridcell" tabindex="0" aria-selected="true">5</td>…</tr></tbody>
16
+ * </table>
17
+ * </div>
18
+ * ```
19
+ *
20
+ * 日期格子的状态写在 data-* 上:data-selected、data-today、data-disabled、data-outside(相邻月份补位)、data-focused(键盘位置)。
21
+ */
22
+ export declare function calendarVariants(): ClassStyle;
23
+ export declare const calendarHeaderClass = "xy-calendar__header";
24
+ export declare const calendarNavClass = "xy-calendar__nav";
25
+ export declare const calendarTitleClass = "xy-calendar__title";
26
+ export declare const calendarGridClass = "xy-calendar__grid";
27
+ export declare const calendarWeekdayClass = "xy-calendar__weekday";
28
+ export declare const calendarDayClass = "xy-calendar__day";
@@ -0,0 +1,30 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /**
3
+ * Calendar 的变体函数。日历只有一套尺寸,不跟着输入框的五档变(见 docs/adr/0020)。
4
+ *
5
+ * ```html
6
+ * <div class="xy-calendar">
7
+ * <div class="xy-calendar__header">
8
+ * <button class="xy-calendar__nav" aria-label="上一年">…</button>
9
+ * <button class="xy-calendar__nav" aria-label="上个月">…</button>
10
+ * <div class="xy-calendar__title" aria-live="polite">2025年11月</div>
11
+ * …
12
+ * </div>
13
+ * <table class="xy-calendar__grid" role="grid">
14
+ * <thead><tr><th class="xy-calendar__weekday">…</th>…</tr></thead>
15
+ * <tbody><tr><td class="xy-calendar__day" role="gridcell" tabindex="0" aria-selected="true">5</td>…</tr></tbody>
16
+ * </table>
17
+ * </div>
18
+ * ```
19
+ *
20
+ * 日期格子的状态写在 data-* 上:data-selected、data-today、data-disabled、data-outside(相邻月份补位)、data-focused(键盘位置)。
21
+ */
22
+ export function calendarVariants() {
23
+ return { class: joinClasses('xy-calendar') };
24
+ }
25
+ export const calendarHeaderClass = 'xy-calendar__header';
26
+ export const calendarNavClass = 'xy-calendar__nav';
27
+ export const calendarTitleClass = 'xy-calendar__title';
28
+ export const calendarGridClass = 'xy-calendar__grid';
29
+ export const calendarWeekdayClass = 'xy-calendar__weekday';
30
+ export const calendarDayClass = 'xy-calendar__day';
@@ -0,0 +1,45 @@
1
+ import type { Orientation, Size } from "./size.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ export interface CheckboxVariantsOptions {
4
+ /** 尺寸改变方框大小和文字字号,五档方框是 12、14、16、20、24px。 */
5
+ size?: Size | null;
6
+ }
7
+ /**
8
+ * 复选框的变体函数,结果用在最外层元素上。
9
+ * 方框就是原生 `<input type="checkbox">`(`appearance: none`),和文字一起包在 `<label>` 里;
10
+ * 说明放在 `<label>` 外面,用 `aria-describedby` 关联,免得被读成名字的一部分。
11
+ * 勾选、半选、禁用、无效、只读从 `:checked` / `:indeterminate` / `:disabled` /
12
+ * `aria-invalid` / `aria-readonly` 读出来,不进 class。
13
+ *
14
+ * ```html
15
+ * <div class="xy-checkbox xy-checkbox--md">
16
+ * <label class="xy-checkbox__label">
17
+ * <input class="xy-checkbox__control" type="checkbox" aria-describedby="d1" />
18
+ * <span class="xy-checkbox__text">订阅周报</span>
19
+ * </label>
20
+ * <div class="xy-checkbox__description" id="d1">每周一发一封</div>
21
+ * </div>
22
+ * ```
23
+ */
24
+ export declare function checkboxVariants(options?: CheckboxVariantsOptions): ClassStyle;
25
+ /** 包住方框和文字的 `<label>`,整块都能点。 */
26
+ export declare const checkboxLabelClass = "xy-checkbox__label";
27
+ /** 方框本身:原生 `<input type="checkbox">`。 */
28
+ export declare const checkboxControlClass = "xy-checkbox__control";
29
+ /** 标签文字。换行时第二行和第一行左对齐,不钻到方框下面。 */
30
+ export declare const checkboxTextClass = "xy-checkbox__text";
31
+ /** 说明,和标签文字左对齐。 */
32
+ export declare const checkboxDescriptionClass = "xy-checkbox__description";
33
+ export interface CheckboxGroupVariantsOptions {
34
+ /** 排列方向,默认竖排。 */
35
+ orientation?: Orientation | null;
36
+ }
37
+ /**
38
+ * 复选框组的变体函数,结果用在 `<fieldset>` 上。它只负责去掉 fieldset 的默认样式和排列复选框;
39
+ * 组的名字通常是外面 Field 的标签,由 `aria-labelledby` 关联。
40
+ *
41
+ * ```ts
42
+ * checkboxGroupVariants({ orientation: 'horizontal' }).class; // 'xy-checkbox-group xy-checkbox-group--horizontal'
43
+ * ```
44
+ */
45
+ export declare function checkboxGroupVariants(options?: CheckboxGroupVariantsOptions): ClassStyle;
@@ -0,0 +1,46 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /**
3
+ * 复选框的变体函数,结果用在最外层元素上。
4
+ * 方框就是原生 `<input type="checkbox">`(`appearance: none`),和文字一起包在 `<label>` 里;
5
+ * 说明放在 `<label>` 外面,用 `aria-describedby` 关联,免得被读成名字的一部分。
6
+ * 勾选、半选、禁用、无效、只读从 `:checked` / `:indeterminate` / `:disabled` /
7
+ * `aria-invalid` / `aria-readonly` 读出来,不进 class。
8
+ *
9
+ * ```html
10
+ * <div class="xy-checkbox xy-checkbox--md">
11
+ * <label class="xy-checkbox__label">
12
+ * <input class="xy-checkbox__control" type="checkbox" aria-describedby="d1" />
13
+ * <span class="xy-checkbox__text">订阅周报</span>
14
+ * </label>
15
+ * <div class="xy-checkbox__description" id="d1">每周一发一封</div>
16
+ * </div>
17
+ * ```
18
+ */
19
+ export function checkboxVariants(options = {}) {
20
+ const { size } = options;
21
+ return {
22
+ class: joinClasses('xy-checkbox', `xy-checkbox--${size ?? 'md'}`),
23
+ };
24
+ }
25
+ /** 包住方框和文字的 `<label>`,整块都能点。 */
26
+ export const checkboxLabelClass = 'xy-checkbox__label';
27
+ /** 方框本身:原生 `<input type="checkbox">`。 */
28
+ export const checkboxControlClass = 'xy-checkbox__control';
29
+ /** 标签文字。换行时第二行和第一行左对齐,不钻到方框下面。 */
30
+ export const checkboxTextClass = 'xy-checkbox__text';
31
+ /** 说明,和标签文字左对齐。 */
32
+ export const checkboxDescriptionClass = 'xy-checkbox__description';
33
+ /**
34
+ * 复选框组的变体函数,结果用在 `<fieldset>` 上。它只负责去掉 fieldset 的默认样式和排列复选框;
35
+ * 组的名字通常是外面 Field 的标签,由 `aria-labelledby` 关联。
36
+ *
37
+ * ```ts
38
+ * checkboxGroupVariants({ orientation: 'horizontal' }).class; // 'xy-checkbox-group xy-checkbox-group--horizontal'
39
+ * ```
40
+ */
41
+ export function checkboxGroupVariants(options = {}) {
42
+ const { orientation } = options;
43
+ return {
44
+ class: joinClasses('xy-checkbox-group', orientation === 'horizontal' && 'xy-checkbox-group--horizontal'),
45
+ };
46
+ }
@@ -0,0 +1,29 @@
1
+ /** 内置的语义色,按用途命名。 */
2
+ export declare const semanticColors: readonly ["primary", "secondary", "tertiary", "neutral", "info", "success", "warning", "danger"];
3
+ /** 内置的命名色相,每个只有一个取值,没有色阶。 */
4
+ export declare const namedHues: readonly ["red", "orange", "amber", "yellow", "lime", "light-green", "green", "teal", "cyan", "light-blue", "blue", "indigo", "violet", "purple", "pink", "gray"];
5
+ /**
6
+ * 自定义颜色的注册表。用声明合并注册名字,并在 CSS 里定义 `--xy-NAME` 和 `--xy-NAME-foreground`:
7
+ *
8
+ * ```ts
9
+ * declare module '@gohopo/xy-core' {
10
+ * interface CustomColors { brand: true }
11
+ * }
12
+ * ```
13
+ */
14
+ export interface CustomColors {
15
+ }
16
+ export type SemanticColor = typeof semanticColors[number];
17
+ export type NamedHue = typeof namedHues[number];
18
+ /** 颜色参数的取值:语义色、命名色相或注册过的自定义颜色的名字,不接受原始颜色值。 */
19
+ export type Color = SemanticColor | NamedHue | Extract<keyof CustomColors, string>;
20
+ /** 颜色本身的 CSS 变量名,如 `--xy-primary`。 */
21
+ export declare function colorVar(color: Color): "--xy-info" | "--xy-warning" | "--xy-success" | "--xy-primary" | "--xy-secondary" | "--xy-tertiary" | "--xy-neutral" | "--xy-danger" | "--xy-red" | "--xy-orange" | "--xy-amber" | "--xy-yellow" | "--xy-lime" | "--xy-light-green" | "--xy-green" | "--xy-teal" | "--xy-cyan" | "--xy-light-blue" | "--xy-blue" | "--xy-indigo" | "--xy-violet" | "--xy-purple" | "--xy-pink" | "--xy-gray";
22
+ /** 颜色的前景色的 CSS 变量名,如 `--xy-primary-foreground`。 */
23
+ export declare function colorForegroundVar(color: Color): "--xy-info-foreground" | "--xy-warning-foreground" | "--xy-success-foreground" | "--xy-primary-foreground" | "--xy-secondary-foreground" | "--xy-tertiary-foreground" | "--xy-neutral-foreground" | "--xy-danger-foreground" | "--xy-red-foreground" | "--xy-orange-foreground" | "--xy-amber-foreground" | "--xy-yellow-foreground" | "--xy-lime-foreground" | "--xy-light-green-foreground" | "--xy-green-foreground" | "--xy-teal-foreground" | "--xy-cyan-foreground" | "--xy-light-blue-foreground" | "--xy-blue-foreground" | "--xy-indigo-foreground" | "--xy-violet-foreground" | "--xy-purple-foreground" | "--xy-pink-foreground" | "--xy-gray-foreground";
24
+ /**
25
+ * 把颜色名字映射成组件颜色的 style 字符串。
26
+ * `componentColorStyle('button', 'brand')` →
27
+ * `--xy-button-color: var(--xy-brand); --xy-button-color-foreground: var(--xy-brand-foreground);`
28
+ */
29
+ export declare function componentColorStyle(component: string, color: Color | null | undefined): string | undefined;
@@ -0,0 +1,25 @@
1
+ /** 内置的语义色,按用途命名。 */
2
+ export const semanticColors = ['primary', 'secondary', 'tertiary', 'neutral', 'info', 'success', 'warning', 'danger'];
3
+ /** 内置的命名色相,每个只有一个取值,没有色阶。 */
4
+ export const namedHues = [
5
+ 'red', 'orange', 'amber', 'yellow', 'lime', 'light-green', 'green', 'teal',
6
+ 'cyan', 'light-blue', 'blue', 'indigo', 'violet', 'purple', 'pink', 'gray',
7
+ ];
8
+ /** 颜色本身的 CSS 变量名,如 `--xy-primary`。 */
9
+ export function colorVar(color) {
10
+ return `--xy-${color}`;
11
+ }
12
+ /** 颜色的前景色的 CSS 变量名,如 `--xy-primary-foreground`。 */
13
+ export function colorForegroundVar(color) {
14
+ return `--xy-${color}-foreground`;
15
+ }
16
+ /**
17
+ * 把颜色名字映射成组件颜色的 style 字符串。
18
+ * `componentColorStyle('button', 'brand')` →
19
+ * `--xy-button-color: var(--xy-brand); --xy-button-color-foreground: var(--xy-brand-foreground);`
20
+ */
21
+ export function componentColorStyle(component, color) {
22
+ if (!color)
23
+ return undefined;
24
+ return `--xy-${component}-color: var(${colorVar(color)}); --xy-${component}-color-foreground: var(${colorForegroundVar(color)});`;
25
+ }
@@ -0,0 +1,49 @@
1
+ import type { InputVariantsOptions } from "./field.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ export type ComboboxVariantsOptions = InputVariantsOptions;
4
+ /**
5
+ * 组合框的变体函数,结果用在包着可见 <input> 的元素上:
6
+ * 外框、清除按钮、展开按钮都在这个包装元素里,<input> 透明铺满其中(见 docs/adr/0006)。
7
+ * 聚焦、无效、禁用由 `:has(> input:…)` 从 <input> 读出来,不进 class。
8
+ *
9
+ * ```html
10
+ * <span class="xy-combobox xy-combobox--outline xy-combobox--md">
11
+ * <input role="combobox" aria-expanded="false" />
12
+ * </span>
13
+ * ```
14
+ */
15
+ export declare function comboboxVariants(options?: ComboboxVariantsOptions): ClassStyle;
16
+ /**
17
+ * 下拉列表的变体函数,结果用在带 popover 属性的浮层上。
18
+ * 翻转后的方向写在元素的 data-placement 上,样式据此做进场动画。
19
+ *
20
+ * ```ts
21
+ * comboboxPickerVariants().class; // 'xy-combobox__picker'
22
+ * ```
23
+ */
24
+ export declare function comboboxPickerVariants(): ClassStyle;
25
+ /** 下拉列表里 role="listbox" 的元素。选项和选项组是它唯一允许的子元素。 */
26
+ export declare const comboboxListClass = "xy-combobox__list";
27
+ /** 选项组,role="group",由组标题命名。 */
28
+ export declare const comboboxGroupClass = "xy-combobox__group";
29
+ /** 组标题。它只是文字,不可聚焦,也不是选项。 */
30
+ export declare const comboboxGroupLabelClass = "xy-combobox__group-label";
31
+ /** 空状态。放在 role="listbox" 外面,自己是 role="status"。 */
32
+ export declare const comboboxEmptyClass = "xy-combobox__empty";
33
+ export interface ComboboxOptionVariantsOptions {
34
+ /** 活动项:键盘当前指向的选项,由 aria-activedescendant 指出,样式加底色。 */
35
+ active?: boolean | null;
36
+ /** 禁用:留在列表里、读屏能读到,但不能选中,键盘也跳过。 */
37
+ disabled?: boolean | null;
38
+ /** 选中:它的值就是当前值,行首画对勾。 */
39
+ selected?: boolean | null;
40
+ }
41
+ /**
42
+ * 选项的变体函数,结果用在 role="option" 的元素上。
43
+ * 活动项不用 `:focus`:焦点全程留在输入框里,这里没有真实焦点可用。
44
+ *
45
+ * ```ts
46
+ * comboboxOptionVariants({ active: true }).class; // 'xy-combobox__option xy-combobox__option--active'
47
+ * ```
48
+ */
49
+ export declare function comboboxOptionVariants(options?: ComboboxOptionVariantsOptions): ClassStyle;
@@ -0,0 +1,51 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /**
3
+ * 组合框的变体函数,结果用在包着可见 <input> 的元素上:
4
+ * 外框、清除按钮、展开按钮都在这个包装元素里,<input> 透明铺满其中(见 docs/adr/0006)。
5
+ * 聚焦、无效、禁用由 `:has(> input:…)` 从 <input> 读出来,不进 class。
6
+ *
7
+ * ```html
8
+ * <span class="xy-combobox xy-combobox--outline xy-combobox--md">
9
+ * <input role="combobox" aria-expanded="false" />
10
+ * </span>
11
+ * ```
12
+ */
13
+ export function comboboxVariants(options = {}) {
14
+ const { size, variant } = options;
15
+ return {
16
+ class: joinClasses('xy-combobox', `xy-combobox--${variant ?? 'outline'}`, `xy-combobox--${size ?? 'md'}`),
17
+ };
18
+ }
19
+ /**
20
+ * 下拉列表的变体函数,结果用在带 popover 属性的浮层上。
21
+ * 翻转后的方向写在元素的 data-placement 上,样式据此做进场动画。
22
+ *
23
+ * ```ts
24
+ * comboboxPickerVariants().class; // 'xy-combobox__picker'
25
+ * ```
26
+ */
27
+ export function comboboxPickerVariants() {
28
+ return { class: 'xy-combobox__picker' };
29
+ }
30
+ /** 下拉列表里 role="listbox" 的元素。选项和选项组是它唯一允许的子元素。 */
31
+ export const comboboxListClass = 'xy-combobox__list';
32
+ /** 选项组,role="group",由组标题命名。 */
33
+ export const comboboxGroupClass = 'xy-combobox__group';
34
+ /** 组标题。它只是文字,不可聚焦,也不是选项。 */
35
+ export const comboboxGroupLabelClass = 'xy-combobox__group-label';
36
+ /** 空状态。放在 role="listbox" 外面,自己是 role="status"。 */
37
+ export const comboboxEmptyClass = 'xy-combobox__empty';
38
+ /**
39
+ * 选项的变体函数,结果用在 role="option" 的元素上。
40
+ * 活动项不用 `:focus`:焦点全程留在输入框里,这里没有真实焦点可用。
41
+ *
42
+ * ```ts
43
+ * comboboxOptionVariants({ active: true }).class; // 'xy-combobox__option xy-combobox__option--active'
44
+ * ```
45
+ */
46
+ export function comboboxOptionVariants(options = {}) {
47
+ const { active, disabled, selected } = options;
48
+ return {
49
+ class: joinClasses('xy-combobox__option', active && 'xy-combobox__option--active', disabled && 'xy-combobox__option--disabled', selected && 'xy-combobox__option--selected'),
50
+ };
51
+ }
@@ -0,0 +1,22 @@
1
+ import type { InputVariantsOptions } from "./field.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ export type DateInputVariantsOptions = InputVariantsOptions;
4
+ /**
5
+ * DateInput 的变体函数,结果用在包着原生 <input> 的 <span> 上:外框画在这个包装元素上,
6
+ * <input> 透明铺满其中(见 docs/adr/0019)。聚焦、无效、禁用、只读由 `:has(> input:…)` 读出来,不进 class。
7
+ *
8
+ * ```html
9
+ * <span class="xy-date-input xy-date-input--outline xy-date-input--md">
10
+ * <input class="xy-date-input__control" type="text" inputmode="decimal" placeholder="年-月-日" value="2025-11-05">
11
+ * </span>
12
+ * ```
13
+ */
14
+ export declare function dateInputVariants(options?: DateInputVariantsOptions): ClassStyle;
15
+ /** DateInput 里真正接收输入的 <input>,type 是 text。 */
16
+ export declare const dateInputControlClass = "xy-date-input__control";
17
+ /** 前缀、后缀:边框内的装饰。前缀靠 CSS 的 order 排到日期前面。 */
18
+ export declare const dateInputPrefixClass = "xy-date-input__prefix";
19
+ export declare const dateInputSuffixClass = "xy-date-input__suffix";
20
+ /** 日历按钮:放在后缀的位置,点它弹出日历(见 docs/adr/0020)。弹层用 dateInputPopupClass。 */
21
+ export declare const dateInputCalendarButtonClass = "xy-date-input__calendar-button";
22
+ export declare const dateInputPopupClass = "xy-date-input__popup";
@@ -0,0 +1,25 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /**
3
+ * DateInput 的变体函数,结果用在包着原生 <input> 的 <span> 上:外框画在这个包装元素上,
4
+ * <input> 透明铺满其中(见 docs/adr/0019)。聚焦、无效、禁用、只读由 `:has(> input:…)` 读出来,不进 class。
5
+ *
6
+ * ```html
7
+ * <span class="xy-date-input xy-date-input--outline xy-date-input--md">
8
+ * <input class="xy-date-input__control" type="text" inputmode="decimal" placeholder="年-月-日" value="2025-11-05">
9
+ * </span>
10
+ * ```
11
+ */
12
+ export function dateInputVariants(options = {}) {
13
+ const { size, variant } = options;
14
+ return {
15
+ class: joinClasses('xy-date-input', `xy-date-input--${variant ?? 'outline'}`, `xy-date-input--${size ?? 'md'}`),
16
+ };
17
+ }
18
+ /** DateInput 里真正接收输入的 <input>,type 是 text。 */
19
+ export const dateInputControlClass = 'xy-date-input__control';
20
+ /** 前缀、后缀:边框内的装饰。前缀靠 CSS 的 order 排到日期前面。 */
21
+ export const dateInputPrefixClass = 'xy-date-input__prefix';
22
+ export const dateInputSuffixClass = 'xy-date-input__suffix';
23
+ /** 日历按钮:放在后缀的位置,点它弹出日历(见 docs/adr/0020)。弹层用 dateInputPopupClass。 */
24
+ export const dateInputCalendarButtonClass = 'xy-date-input__calendar-button';
25
+ export const dateInputPopupClass = 'xy-date-input__popup';
@@ -0,0 +1,26 @@
1
+ import type { InputVariantsOptions } from "./field.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ export type DateRangeInputVariantsOptions = InputVariantsOptions;
4
+ /**
5
+ * DateRangeInput 的变体函数,结果用在包着两个原生 <input> 的 <span role="group"> 上:
6
+ * 外框画在包装上,两个输入框透明地并排在里面(见 docs/adr/0021)。
7
+ * 聚焦、无效、禁用、只读由 `:has(> input:…)` 读出来,不进 class。
8
+ *
9
+ * ```html
10
+ * <span class="xy-date-range-input xy-date-range-input--outline xy-date-range-input--md" role="group">
11
+ * <input class="xy-date-range-input__control" aria-label="开始日期" placeholder="年-月-日">
12
+ * <span class="xy-date-range-input__separator" aria-hidden="true">至</span>
13
+ * <input class="xy-date-range-input__control" aria-label="结束日期" placeholder="年-月-日">
14
+ * </span>
15
+ * ```
16
+ */
17
+ export declare function dateRangeInputVariants(options?: DateRangeInputVariantsOptions): ClassStyle;
18
+ /** 开始、结束两个输入框,type 都是 text。 */
19
+ export declare const dateRangeInputControlClass = "xy-date-range-input__control";
20
+ /** 两个输入框之间的「至」。 */
21
+ export declare const dateRangeInputSeparatorClass = "xy-date-range-input__separator";
22
+ export declare const dateRangeInputPrefixClass = "xy-date-range-input__prefix";
23
+ export declare const dateRangeInputSuffixClass = "xy-date-range-input__suffix";
24
+ /** 日历按钮和它的弹层,样子和日期输入框的一样。 */
25
+ export declare const dateRangeInputCalendarButtonClass = "xy-date-range-input__calendar-button";
26
+ export declare const dateRangeInputPopupClass = "xy-date-range-input__popup";
@@ -0,0 +1,29 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /**
3
+ * DateRangeInput 的变体函数,结果用在包着两个原生 <input> 的 <span role="group"> 上:
4
+ * 外框画在包装上,两个输入框透明地并排在里面(见 docs/adr/0021)。
5
+ * 聚焦、无效、禁用、只读由 `:has(> input:…)` 读出来,不进 class。
6
+ *
7
+ * ```html
8
+ * <span class="xy-date-range-input xy-date-range-input--outline xy-date-range-input--md" role="group">
9
+ * <input class="xy-date-range-input__control" aria-label="开始日期" placeholder="年-月-日">
10
+ * <span class="xy-date-range-input__separator" aria-hidden="true">至</span>
11
+ * <input class="xy-date-range-input__control" aria-label="结束日期" placeholder="年-月-日">
12
+ * </span>
13
+ * ```
14
+ */
15
+ export function dateRangeInputVariants(options = {}) {
16
+ const { size, variant } = options;
17
+ return {
18
+ class: joinClasses('xy-date-range-input', `xy-date-range-input--${variant ?? 'outline'}`, `xy-date-range-input--${size ?? 'md'}`),
19
+ };
20
+ }
21
+ /** 开始、结束两个输入框,type 都是 text。 */
22
+ export const dateRangeInputControlClass = 'xy-date-range-input__control';
23
+ /** 两个输入框之间的「至」。 */
24
+ export const dateRangeInputSeparatorClass = 'xy-date-range-input__separator';
25
+ export const dateRangeInputPrefixClass = 'xy-date-range-input__prefix';
26
+ export const dateRangeInputSuffixClass = 'xy-date-range-input__suffix';
27
+ /** 日历按钮和它的弹层,样子和日期输入框的一样。 */
28
+ export const dateRangeInputCalendarButtonClass = 'xy-date-range-input__calendar-button';
29
+ export const dateRangeInputPopupClass = 'xy-date-range-input__popup';
@@ -0,0 +1,18 @@
1
+ import type { Size } from "./size.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ export interface DialogVariantsOptions {
4
+ /** 正在播放退场动画。实现方先加上它,等动画结束再调用 dialog.close()。 */
5
+ closing?: boolean | null;
6
+ /** 最大宽度档位,默认 md。 */
7
+ size?: Size | null;
8
+ }
9
+ /** 退场动画期间加在 <dialog> 上的类。 */
10
+ export declare const dialogClosingClass = "xy-dialog--closing";
11
+ /**
12
+ * Dialog 和 AlertDialog 共用的变体函数,结果用在原生 <dialog> 上。
13
+ *
14
+ * ```ts
15
+ * dialogVariants({ size: 'lg' }).class; // 'xy-dialog xy-dialog--lg'
16
+ * ```
17
+ */
18
+ export declare function dialogVariants(options?: DialogVariantsOptions): ClassStyle;
@@ -0,0 +1,16 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /** 退场动画期间加在 <dialog> 上的类。 */
3
+ export const dialogClosingClass = 'xy-dialog--closing';
4
+ /**
5
+ * Dialog 和 AlertDialog 共用的变体函数,结果用在原生 <dialog> 上。
6
+ *
7
+ * ```ts
8
+ * dialogVariants({ size: 'lg' }).class; // 'xy-dialog xy-dialog--lg'
9
+ * ```
10
+ */
11
+ export function dialogVariants(options = {}) {
12
+ const { closing, size } = options;
13
+ return {
14
+ class: joinClasses('xy-dialog', `xy-dialog--${size ?? 'md'}`, closing && dialogClosingClass),
15
+ };
16
+ }
@@ -0,0 +1,24 @@
1
+ import type { Size } from "./size.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ /** 抽屉贴着哪条边。start 和 end 跟着书写方向翻转。 */
4
+ export type DrawerPlacement = 'start' | 'end' | 'top' | 'bottom';
5
+ export interface DrawerVariantsOptions {
6
+ /** 正在播放退场动画。实现方先加上它,等动画结束再调用 dialog.close()。 */
7
+ closing?: boolean | null;
8
+ /** 贴哪条边,默认 end(RTL 下是左侧)。 */
9
+ placement?: DrawerPlacement | null;
10
+ /** start、end 时是宽度,top、bottom 时是最大高度,默认 md。 */
11
+ size?: Size | null;
12
+ }
13
+ /** 退场动画期间加在 <dialog> 上的类。 */
14
+ export declare const drawerClosingClass = "xy-drawer--closing";
15
+ /**
16
+ * 抽屉的变体函数,结果用在原生 <dialog> 上。方位同时写成类名和 data-placement:
17
+ * 类名给样式用,属性给使用者的选择器和测试用。
18
+ *
19
+ * ```ts
20
+ * drawerVariants({ placement: 'bottom', size: 'lg' }).class;
21
+ * // 'xy-drawer xy-drawer--bottom xy-drawer--lg'
22
+ * ```
23
+ */
24
+ export declare function drawerVariants(options?: DrawerVariantsOptions): ClassStyle;
@@ -0,0 +1,18 @@
1
+ import { joinClasses } from "./utils.js";
2
+ /** 退场动画期间加在 <dialog> 上的类。 */
3
+ export const drawerClosingClass = 'xy-drawer--closing';
4
+ /**
5
+ * 抽屉的变体函数,结果用在原生 <dialog> 上。方位同时写成类名和 data-placement:
6
+ * 类名给样式用,属性给使用者的选择器和测试用。
7
+ *
8
+ * ```ts
9
+ * drawerVariants({ placement: 'bottom', size: 'lg' }).class;
10
+ * // 'xy-drawer xy-drawer--bottom xy-drawer--lg'
11
+ * ```
12
+ */
13
+ export function drawerVariants(options = {}) {
14
+ const { closing, placement, size } = options;
15
+ return {
16
+ class: joinClasses('xy-drawer', `xy-drawer--${placement ?? 'end'}`, `xy-drawer--${size ?? 'md'}`, closing && drawerClosingClass),
17
+ };
18
+ }
@@ -0,0 +1,62 @@
1
+ import type { Size } from "./size.js";
2
+ import { type ClassStyle } from "./utils.js";
3
+ /**
4
+ * 字段控件的外观变体。输入框、文本域、选择框触发器、组合框共用这一套,
5
+ * 名字与 Button 的同名变体一致:outline 是描边,soft 是填充底加一条底边。
6
+ */
7
+ export declare const controlVariantNames: readonly ["outline", "soft"];
8
+ export type ControlVariant = typeof controlVariantNames[number];
9
+ export interface InputVariantsOptions {
10
+ size?: Size | null;
11
+ variant?: ControlVariant | null;
12
+ }
13
+ /** 字段各部件的 class。字段本身不画边框,只负责标签、控件、说明、错误信息的纵向排布。 */
14
+ export declare const fieldLabelClass = "xy-field__label";
15
+ /** 必填星号。它是 aria-hidden 的装饰,必填的语义由控件的原生 required 属性承载。 */
16
+ export declare const fieldRequiredClass = "xy-field__required";
17
+ export declare const fieldDescriptionClass = "xy-field__description";
18
+ /** 错误信息。容器始终挂载(live region 要先存在才可靠),`:empty` 时自动不占位。 */
19
+ export declare const fieldErrorClass = "xy-field__error";
20
+ /**
21
+ * 字段的变体函数,结果用在包着标签、控件、说明、错误信息的元素上。
22
+ * 状态不进 class,而是写成 data 属性:data-invalid / data-disabled / data-required / data-readonly。
23
+ * 样式据此变化(比如 data-disabled 时标签和说明变淡),纯 HTML 使用者照写这几个属性即可。
24
+ *
25
+ * ```ts
26
+ * fieldVariants().class; // 'xy-field'
27
+ * ```
28
+ */
29
+ export declare function fieldVariants(): ClassStyle;
30
+ /**
31
+ * Input 的变体函数,结果用在包着原生 <input> 的 <span> 上:外框画在这个包装元素上,
32
+ * <input> 透明铺满其中(见 docs/adr/0010)。聚焦、无效、禁用、只读由 `:has(> input:…)` 读出来,不进 class。
33
+ *
34
+ * ```html
35
+ * <span class="xy-input xy-input--soft xy-input--lg">
36
+ * <input class="xy-input__control" name="amount">
37
+ * <span class="xy-input__prefix" aria-hidden="true">¥</span>
38
+ * </span>
39
+ * ```
40
+ */
41
+ export declare function inputVariants(options?: InputVariantsOptions): ClassStyle;
42
+ /** Input 里真正接收输入的 <input>。 */
43
+ export declare const inputControlClass = "xy-input__control";
44
+ /** 前缀、后缀:边框内的装饰,aria-hidden。前缀靠 CSS 的 order 排到视觉最前。 */
45
+ export declare const inputPrefixClass = "xy-input__prefix";
46
+ export declare const inputSuffixClass = "xy-input__suffix";
47
+ /** 清除按钮、密码切换按钮。图标用 CSS mask 画,按钮本身没有内容。 */
48
+ export declare const inputClearClass = "xy-input__clear";
49
+ export declare const inputPasswordToggleClass = "xy-input__password-toggle";
50
+ export type SelectVariantsOptions = InputVariantsOptions;
51
+ /**
52
+ * Select 的变体函数,结果用在包着原生 <select> 的 <span> 上:
53
+ * 外框、下拉图标都画在这个包装元素上,<select> 透明铺满其中(见 docs/adr/0006)。
54
+ * 聚焦、无效、禁用由 `:has(> select:…)` 从 <select> 读出来,不进 class。
55
+ *
56
+ * ```html
57
+ * <span class="xy-select xy-select--outline xy-select--md">
58
+ * <select name="city">…</select>
59
+ * </span>
60
+ * ```
61
+ */
62
+ export declare function selectVariants(options?: SelectVariantsOptions): ClassStyle;