@rcarls/rc-field 0.0.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,187 @@
1
+ import { LitElement, PropertyValues } from 'lit';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'rc-field': RCField;
5
+ }
6
+ }
7
+ export type RCFieldControl = HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement;
8
+ /**
9
+ * Accessible field wrapper for a native input, textarea, or select with labels and supporting
10
+ * text.
11
+ *
12
+ * The native control remains connected in light DOM and owns its value, form association,
13
+ * autofill, constraint validation, and native events. `rc-field` derives visual state from that
14
+ * control and wires a slotted label, hint, and error without replacing author-provided ARIA
15
+ * references. Programmatic native value writes are visible after calling `sync()`.
16
+ *
17
+ * Derived host attributes expose `data-focused`, `data-populated`, `data-disabled`,
18
+ * `data-readonly`, `data-required`, `data-invalid`, `data-multiline`, `data-has-label`, and
19
+ * `data-validation-attempted` for themes.
20
+ *
21
+ * A direct `<fieldset>` child groups several native controls into one field, such as an amount
22
+ * and its unit. Its `<legend>` names the group and shows as the field label, and each control
23
+ * keeps its own accessible name. The first text-like input or textarea is the primary control,
24
+ * and the others attach before or after it in source order. Supporting text describes the
25
+ * fieldset.
26
+ *
27
+ * @see {@link https://richardcarls.github.io/rc-webcomponents/components/rc-field rc-field docs}
28
+ * @see {@link https://m3.material.io/components/text-fields/overview Material Design 3 text fields}
29
+ *
30
+ * @slot - Required native `<input>`, `<textarea>`, or `<select>` control. An enhancing direct
31
+ * child marked `data-rc-field-control` may own the native control as its direct child. A
32
+ * `<fieldset>` with a `<legend>` instead groups several controls into one field.
33
+ * @slot label - Visible label; use a native `<label>` unless an ancestor label wraps the field
34
+ * @slot leading - Leading icon or control outside the editable content
35
+ * @slot trailing - Trailing icon or control outside the editable content
36
+ * @slot prefix - Text or content immediately before the native control
37
+ * @slot suffix - Text or content immediately after the native control
38
+ * @slot hint - Supporting guidance associated with the native control
39
+ * @slot error - Error text shown and associated after validation is attempted
40
+ *
41
+ * @attr counter - Shows the current native value length and `maxlength`, when present
42
+ * @attr invalid - Forces invalid presentation and supplies native `aria-invalid` when absent
43
+ * @attr [data-focused] - Present while the native control has focus
44
+ * @attr [data-populated] - Present while the native control has a value, or a single select's
45
+ * selected option has visible label text
46
+ * @attr [data-disabled] - Mirrors the native control's disabled state
47
+ * @attr [data-readonly] - Mirrors the native control's readonly state
48
+ * @attr [data-required] - Mirrors the native control's required state
49
+ * @attr [data-invalid] - Present while an attempted or forced validation state is invalid
50
+ * @attr [data-multiline] - Present when the native control is a textarea
51
+ * @attr [data-has-label] - Present when the field has content in its label slot
52
+ * @attr [data-validation-attempted] - Present after the native control dispatches `invalid`
53
+ * @attr [data-control-provider] - Present when an enhancing direct child owns the native control
54
+ * @attr [data-group] - Present when a `<fieldset>` groups several controls into the field
55
+ *
56
+ * @cssprop [--rc-field-min-block-size=var(--rc-control-block-size, 2.5rem)] - Minimum field surface block size
57
+ * @cssprop [--rc-field-gap=var(--rc-control-gap, 0.5rem)] - Gap between leading, content, and trailing regions
58
+ * @cssprop [--rc-field-padding=var(--rc-control-padding-block, 0.5rem) var(--rc-control-padding-inline, 0.75rem)] - Field surface padding
59
+ * @cssprop [--rc-field-border=var(--rc-border, 1px solid ButtonBorder)] - Field surface border
60
+ * @cssprop [--rc-field-radius=var(--rc-control-radius, 0.125rem)] - Field surface corner radius
61
+ * @cssprop [--rc-field-background=var(--rc-field, Field)] - Field surface background
62
+ * @cssprop [--rc-field-color=var(--rc-field-text, FieldText)] - Input and affix text color
63
+ * @cssprop [--rc-field-label-color=var(--rc-field-text, CanvasText)] - Label color
64
+ * @cssprop [--rc-field-control-gap=var(--rc-control-gap, 0.25rem)] - Gap between control and prefix or suffix
65
+ * @cssprop [--rc-field-supporting-gap=var(--rc-control-gap, 0.5rem)] - Gap between supporting text and counter
66
+ * @cssprop [--rc-field-supporting-padding-block-start=0.25rem] - Supporting text top padding
67
+ * @cssprop [--rc-field-supporting-padding-inline=var(--rc-control-padding-inline, 0.75rem)] - Supporting text inline padding
68
+ * @cssprop [--rc-field-supporting-color=var(--rc-field-text, CanvasText)] - Hint and counter color
69
+ * @cssprop [--rc-field-supporting-font-size=0.75rem] - Hint, error, and counter font size
70
+ * @cssprop [--rc-field-error-color=Mark] - Invalid outline, label, and error color
71
+ * @cssprop [--rc-field-disabled-opacity=var(--rc-disabled-opacity, 0.6)] - Disabled field opacity
72
+ * @cssprop [--rc-field-focus-outline=var(--rc-focus-ring, 2px solid Highlight)] - Focus outline
73
+ * @cssprop [--rc-field-focus-outline-offset=var(--rc-focus-ring-offset, 0)] - Focus outline offset
74
+ *
75
+ * @csspart field - Field surface
76
+ * @csspart content - Label and editable content column
77
+ * @csspart label - Label container
78
+ * @csspart control - Native control, prefix, and suffix row
79
+ * @csspart leading - Leading content container
80
+ * @csspart trailing - Trailing content container
81
+ * @csspart prefix - Prefix content container
82
+ * @csspart suffix - Suffix content container
83
+ * @csspart supporting-text - Supporting text row
84
+ * @csspart hint - Hint container
85
+ * @csspart error - Error container
86
+ * @csspart counter - Character counter
87
+ */
88
+ export declare class RCField extends LitElement {
89
+ static styles: import('lit').CSSResult[];
90
+ private static readonly _styledRoots;
91
+ private static _ensureBaseStyles;
92
+ /** Shows the current native value length and `maxlength`, when present. */
93
+ counter: boolean;
94
+ /** Forces invalid presentation and supplies native `aria-invalid` when absent. */
95
+ invalid: boolean;
96
+ private _hasControl;
97
+ private _hasLabel;
98
+ private _hasLeading;
99
+ private _hasTrailing;
100
+ private _hasPrefix;
101
+ private _hasSuffix;
102
+ private _hasHint;
103
+ private _hasError;
104
+ private _focused;
105
+ private _populated;
106
+ private _disabled;
107
+ private _readOnly;
108
+ private _required;
109
+ private _multiline;
110
+ private _grouped;
111
+ private _validationAttempted;
112
+ private _nativeInvalid;
113
+ private _validationMessage;
114
+ private _$controlRef;
115
+ private _$controlProviderRef;
116
+ private _$groupRef;
117
+ private _groupObserver;
118
+ private _$formRef;
119
+ private _controlObserver;
120
+ private _compositionObserver;
121
+ private _managedDescriptionIds;
122
+ private _managedIds;
123
+ private _managedLabel;
124
+ private _managedControlId;
125
+ private _managedAriaInvalid;
126
+ private readonly _controlController;
127
+ /**
128
+ * Returns the native control, or `null` when the field is incomplete. In a group, this is the
129
+ * primary control: the first text-like input or textarea, or else the first control.
130
+ */
131
+ get control(): RCFieldControl | null;
132
+ /** Returns the `<fieldset>` that groups the field's controls, or `null` for a single control. */
133
+ get group(): HTMLFieldSetElement | null;
134
+ /** Returns every native control the field manages, in source order. */
135
+ get controls(): RCFieldControl[];
136
+ connectedCallback(): void;
137
+ disconnectedCallback(): void;
138
+ protected willUpdate(changed: PropertyValues<this>): void;
139
+ /** Focuses the native control. */
140
+ focus(options?: FocusOptions): void;
141
+ /** Removes focus from the native control. */
142
+ blur(): void;
143
+ /** Re-reads native value, validity, attributes, slots, and accessible relationships. */
144
+ sync(): void;
145
+ private _setupRoot;
146
+ private _setupGroup;
147
+ private _teardownGroup;
148
+ /** Re-resolves a group's primary control after its contents change. */
149
+ private _syncGroupControl;
150
+ private _setupControl;
151
+ private _teardownControl;
152
+ private _syncForm;
153
+ private _queueSync;
154
+ private readonly _onControlInput;
155
+ private readonly _onControlChange;
156
+ private readonly _onControlFocus;
157
+ private readonly _onControlBlur;
158
+ private readonly _onProviderFocusIn;
159
+ private readonly _onProviderFocusOut;
160
+ private readonly _onGroupFocusIn;
161
+ /** Moving focus between the group's own controls keeps the field focused. */
162
+ private readonly _onGroupFocusOut;
163
+ private readonly _onControlInvalid;
164
+ private readonly _onCompositionEnd;
165
+ private readonly _onFormReset;
166
+ private _syncState;
167
+ /**
168
+ * A control provider may disable its native control for a reason unrelated to the field's
169
+ * own enabled/disabled intent (`rc-select`'s picker guard force-disables a `multiple` native
170
+ * select to defeat a GeckoView label-activation bug, entirely independent of author intent).
171
+ * Prefer the provider's own `disabled` property, when it exposes one, over the raw control's
172
+ * — the same precedence `focus()`/`blur()` already give the provider over the control.
173
+ */
174
+ private _effectiveDisabled;
175
+ private _reflectStates;
176
+ private _effectiveInvalid;
177
+ private _syncSlots;
178
+ private _hasSlottedContent;
179
+ private _syncAssociations;
180
+ private _restoreAssociations;
181
+ private _ensureId;
182
+ private _warnGroupComposition;
183
+ private _warnComposition;
184
+ private _handleSurfaceClick;
185
+ private _slotClass;
186
+ protected render(): import('lit-html').TemplateResult<1>;
187
+ }
@@ -0,0 +1,2 @@
1
+ export declare const fieldStyles: import('lit').CSSResult;
2
+ export default fieldStyles;
package/package.json CHANGED
@@ -1,14 +1,65 @@
1
1
  {
2
2
  "name": "@rcarls/rc-field",
3
- "version": "0.0.0",
4
- "description": "Placeholder published only to register this package name on npm before configuring Trusted Publishing. Contains no code. Do not install or depend on this version.",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "0.7.0",
7
+ "description": "Accessible field wrapper for a native input or textarea with labels and supporting text.",
5
8
  "repository": {
6
9
  "type": "git",
7
- "url": "git+https://github.com/richardcarls/rc-webcomponents.git"
10
+ "url": "git+https://github.com/richardcarls/rc-webcomponents.git",
11
+ "directory": "packages/rc-field"
8
12
  },
13
+ "homepage": "https://richardcarls.github.io/rc-webcomponents/components/rc-field",
9
14
  "license": "MIT",
10
- "private": false,
11
- "publishConfig": {
12
- "access": "public"
15
+ "type": "module",
16
+ "files": [
17
+ "dist"
18
+ ],
19
+ "module": "./dist/rc-field.js",
20
+ "exports": {
21
+ ".": {
22
+ "import": {
23
+ "types": "./dist/types/packages/rc-field/src/index.d.ts",
24
+ "default": "./dist/rc-field.js"
25
+ }
26
+ },
27
+ "./define": {
28
+ "import": {
29
+ "types": "./dist/types/packages/rc-field/src/define.d.ts",
30
+ "default": "./dist/rc-field-define.js"
31
+ }
32
+ }
33
+ },
34
+ "types": "./dist/types/packages/rc-field/src/index.d.ts",
35
+ "sideEffects": [
36
+ "./dist/rc-field-define.js"
37
+ ],
38
+ "customElements": "dist/custom-elements.json",
39
+ "scripts": {
40
+ "build": "tsc && vite build && cem analyze",
41
+ "cem:analyze": "cem analyze",
42
+ "preview": "vite preview",
43
+ "test:browser": "vitest --run",
44
+ "test:browser:chrome": "vitest --run --project=chromium",
45
+ "test:browser:firefox": "vitest --run --project=firefox"
46
+ },
47
+ "devDependencies": {
48
+ "@custom-elements-manifest/analyzer": "0.11.0",
49
+ "@vitest/browser-playwright": "4.1.5",
50
+ "lit": "^3.0.0",
51
+ "playwright": "^1.56.0",
52
+ "rollup": "^4.60.2",
53
+ "typescript": "~5.9.3",
54
+ "vite": "^7.1.7",
55
+ "vite-plugin-dts": "^4.5.4",
56
+ "vitest": "^4.0.6",
57
+ "vitest-browser-lit": "^1.0.1"
58
+ },
59
+ "peerDependencies": {
60
+ "lit": "^3.0.0"
61
+ },
62
+ "dependencies": {
63
+ "@rcarls/rc-common": "0.7.0"
13
64
  }
14
- }
65
+ }