@ac-components/ac-input-basic 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Renzo Cordova
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,79 @@
1
- # Temporary Holding Version
1
+ # `@ac-components/ac-input-basic`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Campo de texto accesible con etiqueta, texto de ayuda y mensaje de error. Usa un `<input>` nativo dentro del shadow root.
4
+
5
+ ## Instalación
6
+
7
+ ```bash
8
+ pnpm add @ac-components/ac-input-basic
9
+ ```
10
+
11
+ ```js
12
+ import '@ac-components/ac-input-basic';
13
+ ```
14
+
15
+ ```html
16
+ <ac-input-basic label="Nombre" name="name" hint="Como aparece en tu documento."></ac-input-basic>
17
+ <ac-input-basic label="Correo" type="email" error="Ingresa un correo válido."></ac-input-basic>
18
+ <ac-input-basic a11y-label="Buscar" type="search" placeholder="Buscar..."></ac-input-basic>
19
+ ```
20
+
21
+ ## Propiedades
22
+
23
+ | Propiedad | Atributo | Tipo | Default | Descripción |
24
+ | ------------- | ------------- | ------- | ----------- | ------------------------------------------------------------------------------------------------------------------ |
25
+ | `label` | `label` | String | `''` | Etiqueta visible. Se pasa por `this.t()`: si es una clave de `locales.json` se traduce, si no se muestra tal cual. |
26
+ | `a11yLabel` | `a11y-label` | String | `''` | Nombre accesible cuando **no** hay etiqueta visible (ej. un buscador). Se ignora si hay `label`. |
27
+ | `value` | `value` | String | `''` | Valor del campo. |
28
+ | `type` | `type` | String | `'text'` | `text`, `email`, `password`, `search`, `tel`, `url` o `number`. Cualquier otro valor cae a `text` (lista blanca). |
29
+ | `name` | `name` | String | `''` | Nombre del campo. |
30
+ | `placeholder` | `placeholder` | String | `''` | Texto de ejemplo (también pasa por `this.t()`). |
31
+ | `hint` | `hint` | String | `''` | Texto de ayuda bajo el campo (también pasa por `this.t()`). |
32
+ | `error` | `error` | String | `''` | Mensaje de error. Reemplaza a `hint`, marca el campo con `aria-invalid="true"` y se anuncia con `role="alert"`. |
33
+ | `disabled` | `disabled` | Boolean | `false` | Deshabilita el campo. |
34
+ | `readonly` | `readonly` | Boolean | `false` | Campo de solo lectura (borde punteado). |
35
+ | `required` | `required` | Boolean | `false` | Campo obligatorio; muestra un asterisco decorativo junto a la etiqueta. |
36
+ | `ambient` | `ambient` | String | `'primary'` | Color del foco: `primary` o `secondary`. Heredado de `ComponentMixin`. |
37
+
38
+ El método `focus()` lleva el foco al campo interno.
39
+
40
+ ## Eventos
41
+
42
+ | Evento | Cuándo | `detail` |
43
+ | ----------------------- | -------------------------------------------------- | ------------------- |
44
+ | `ac-input-basic-input` | En cada cambio mientras el usuario escribe | `{ value: string }` |
45
+ | `ac-input-basic-change` | Al confirmar el cambio (al perder el foco / Enter) | `{ value: string }` |
46
+
47
+ `bubbles` y `composed`.
48
+
49
+ ## Parts y CSS
50
+
51
+ | Part | Descripción |
52
+ | ------- | ---------------------------- |
53
+ | `root` | Contenedor de todo el campo. |
54
+ | `label` | La etiqueta. |
55
+ | `input` | El `<input>` nativo. |
56
+ | `hint` | El texto de ayuda. |
57
+ | `error` | El mensaje de error. |
58
+
59
+ ## Accesibilidad
60
+
61
+ - La etiqueta está asociada al campo (`for`/`id`); la ayuda y el error se enlazan con `aria-describedby`.
62
+ - El color del foco y del mensaje de error depende del tema (claro/oscuro) para cumplir contraste WCAG AA en ambos; el borde del campo cumple 3:1.
63
+ - Un `<input>` dentro de un shadow root **no participa** de un `<form>` nativo: lee `value` del componente o escucha los eventos.
64
+
65
+ ## i18n
66
+
67
+ `locales.json` incluye claves de ejemplo (`input-basic-email-label`, `-placeholder`, `-hint`, `-error`) en `es-PE`, `en-EN` y `pt-BR`.
68
+
69
+ ## Desarrollo
70
+
71
+ ```bash
72
+ ac component:serve # o: pnpm --filter @ac-components/ac-input-basic component:serve — demo en http://localhost:5173
73
+ ac component:test
74
+ ac component:build
75
+ ac component:test:e2e # funcional (WebdriverIO + Cucumber)
76
+ ac component:test:e2e:a11y # accesibilidad (axe-core)
77
+ ```
78
+
79
+ > `src/input-basic.styles.js` se genera a partir de `src/input-basic.styles.scss` (`component:build:styles`, corre automáticamente antes de `component:serve`/`component:build`/`component:test`) y no se versiona en git. Durante `component:serve` queda además en modo watch: cada guardado de `.scss` lo recompila y Vite recarga el navegador solo, sin reiniciar nada.
package/index.js ADDED
@@ -0,0 +1,10 @@
1
+ import locales from './locales.json' with { type: 'json' };
2
+ import { registerTranslations } from '@ac-base/ac-intl-mixin';
3
+ import { InputBasic } from './src/input-basic.js';
4
+
5
+ export { InputBasic } from './src/input-basic.js';
6
+
7
+ registerTranslations(InputBasic.is, locales);
8
+
9
+ // Auto-registro del componente
10
+ customElements.define(InputBasic.is, InputBasic);
package/locales.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "es-PE": {
3
+ "input-basic-email-label": "Correo electrónico",
4
+ "input-basic-email-placeholder": "nombre@empresa.com",
5
+ "input-basic-email-hint": "Usaremos este correo solo para avisarte.",
6
+ "input-basic-email-error": "Ingresa un correo válido."
7
+ },
8
+ "en-EN": {
9
+ "input-basic-email-label": "Email",
10
+ "input-basic-email-placeholder": "name@company.com",
11
+ "input-basic-email-hint": "We will only use this email to notify you.",
12
+ "input-basic-email-error": "Enter a valid email."
13
+ },
14
+ "pt-BR": {
15
+ "input-basic-email-label": "E-mail",
16
+ "input-basic-email-placeholder": "nome@empresa.com",
17
+ "input-basic-email-hint": "Usaremos este e-mail apenas para avisar você.",
18
+ "input-basic-email-error": "Digite um e-mail válido."
19
+ }
20
+ }
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@ac-components/ac-input-basic",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "ac-lit text input Web Component",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "index.js",
8
+ "exports": {
9
+ ".": "./index.js",
10
+ "./locales.json": "./locales.json"
11
+ },
12
+ "files": [
13
+ "/src/",
14
+ "index.js",
15
+ "locales.json"
16
+ ],
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "dependencies": {
21
+ "@ac-base/ac-component-mixin": "^0.1.0",
22
+ "@ac-base/ac-intl-mixin": "^0.1.0"
23
+ },
24
+ "peerDependencies": {
25
+ "lit": "^3.0.0"
26
+ },
27
+ "devDependencies": {
28
+ "@ac-base/ac-core": "^0.1.0",
29
+ "@ac-base/ac-demo-content": "^0.1.0",
30
+ "@ac-base/ac-e2e-testing": "^0.1.0",
31
+ "@ac-base/cli": "^0.1.0",
32
+ "@open-wc/testing": "^4.0.0",
33
+ "@web/test-runner": "^0.18.0",
34
+ "concurrently": "^9.1.0",
35
+ "lit": "^3.0.0",
36
+ "sass": "^1.79.4",
37
+ "vite": "^5.4.8"
38
+ },
39
+ "scripts": {
40
+ "component:build:styles": "node ./node_modules/@ac-base/cli/scripts/compile-scss-to-lit.cjs src/input-basic.styles.scss src/input-basic.styles.js InputBasicStyles",
41
+ "component:build:styles:watch": "node ./node_modules/@ac-base/cli/scripts/compile-scss-to-lit.cjs src/input-basic.styles.scss src/input-basic.styles.js InputBasicStyles --watch",
42
+ "component:serve": "pnpm run component:build:styles && concurrently -k -n styles,vite -c blue,green \"pnpm run component:build:styles:watch\" \"vite demo\"",
43
+ "component:build": "pnpm run component:build:styles && vite build",
44
+ "component:preview": "vite preview",
45
+ "component:test": "pnpm run component:build:styles && web-test-runner \"test/**/*.test.js\"",
46
+ "component:test:e2e": "pnpm run component:build && start-server-and-test component:preview http://localhost:4173 component:test:e2e:run",
47
+ "component:test:e2e:run": "wdio run test_e2e/wdio.conf.js",
48
+ "component:test:e2e:a11y": "pnpm run component:build && start-server-and-test component:preview http://localhost:4173 component:test:e2e:a11y:run",
49
+ "component:test:e2e:a11y:run": "wdio run test_e2e/wdio.a11y.conf.js"
50
+ }
6
51
  }
@@ -0,0 +1,133 @@
1
+ import { LitElement, html, nothing } from 'lit';
2
+ import { ComponentMixin, componentBaseStyles } from '@ac-base/ac-component-mixin';
3
+ // Authored in input-basic.styles.scss, compiled to input-basic.styles.js by
4
+ // `pnpm run component:build:styles` (@ac-base/cli/scripts/compile-scss-to-lit.cjs). The compiled file
5
+ // is gitignored — run `pnpm install` then `pnpm component:build` or `pnpm component:serve` to generate it.
6
+ import { InputBasicStyles } from './input-basic.styles.js';
7
+
8
+ const ALLOWED_TYPES = ['text', 'email', 'password', 'search', 'tel', 'url', 'number'];
9
+
10
+ export class InputBasic extends ComponentMixin(LitElement) {
11
+ static get is() {
12
+ return 'ac-input-basic';
13
+ }
14
+
15
+ static get styles() {
16
+ return [componentBaseStyles, InputBasicStyles];
17
+ }
18
+
19
+ static get properties() {
20
+ return {
21
+ label: { type: String },
22
+ a11yLabel: { type: String, attribute: 'a11y-label' },
23
+ value: { type: String },
24
+ type: { type: String },
25
+ name: { type: String },
26
+ placeholder: { type: String },
27
+ hint: { type: String },
28
+ error: { type: String },
29
+ disabled: { type: Boolean, reflect: true },
30
+ readonly: { type: Boolean, reflect: true },
31
+ required: { type: Boolean, reflect: true },
32
+ };
33
+ }
34
+
35
+ constructor() {
36
+ super();
37
+ this.label = '';
38
+ this.a11yLabel = '';
39
+ this.value = '';
40
+ this.type = 'text';
41
+ this.name = '';
42
+ this.placeholder = '';
43
+ this.hint = '';
44
+ this.error = '';
45
+ this.disabled = false;
46
+ this.readonly = false;
47
+ this.required = false;
48
+ this.ambient = 'primary';
49
+ }
50
+
51
+ get _type() {
52
+ return ALLOWED_TYPES.includes(this.type) ? this.type : 'text';
53
+ }
54
+
55
+ get _message() {
56
+ return this.error || this.hint;
57
+ }
58
+
59
+ /** Lleva el foco al campo interno. */
60
+ focus(options) {
61
+ this.renderRoot.querySelector('input')?.focus(options);
62
+ }
63
+
64
+ render() {
65
+ const hasError = Boolean(this.error);
66
+ const classes = `ac-input-basic ac-input--${this.ambient}${hasError ? ' ac-input--invalid' : ''}`;
67
+
68
+ return html`
69
+ <div part="root" class=${classes}>
70
+ ${
71
+ this.label
72
+ ? html`<label part="label" class="ac-input-basic__label" for="field">
73
+ ${this.t(this.label)}${
74
+ this.required
75
+ ? html`<span class="ac-input-basic__required" aria-hidden="true"> *</span>`
76
+ : nothing
77
+ }
78
+ </label>`
79
+ : nothing
80
+ }
81
+ <input
82
+ part="input"
83
+ id="field"
84
+ class="ac-input-basic__field"
85
+ type=${this._type}
86
+ name=${this.name}
87
+ .value=${this.value}
88
+ placeholder=${this.placeholder ? this.t(this.placeholder) : nothing}
89
+ aria-label=${!this.label && this.a11yLabel ? this.t(this.a11yLabel) : nothing}
90
+ aria-invalid=${hasError ? 'true' : 'false'}
91
+ aria-describedby=${this._message ? 'message' : nothing}
92
+ ?disabled=${this.disabled}
93
+ ?readonly=${this.readonly}
94
+ ?required=${this.required}
95
+ @input=${this._onInput}
96
+ @change=${this._onChange}
97
+ />
98
+ ${
99
+ this._message
100
+ ? html`<p
101
+ part=${hasError ? 'error' : 'hint'}
102
+ id="message"
103
+ class="ac-input-basic__message ${hasError ? 'ac-input-basic__message--error' : ''}"
104
+ role=${hasError ? 'alert' : nothing}
105
+ >
106
+ ${this.t(this._message)}
107
+ </p>`
108
+ : nothing
109
+ }
110
+ </div>
111
+ `;
112
+ }
113
+
114
+ _onInput(event) {
115
+ this.value = event.target.value;
116
+ this._emit('ac-input-basic-input');
117
+ }
118
+
119
+ _onChange(event) {
120
+ this.value = event.target.value;
121
+ this._emit('ac-input-basic-change');
122
+ }
123
+
124
+ _emit(name) {
125
+ this.dispatchEvent(
126
+ new CustomEvent(name, {
127
+ detail: { value: this.value },
128
+ bubbles: true,
129
+ composed: true,
130
+ }),
131
+ );
132
+ }
133
+ }
@@ -0,0 +1,108 @@
1
+ import { css } from 'lit';
2
+
3
+ export const InputBasicStyles = css`
4
+ @charset "UTF-8";
5
+ :host {
6
+ display: block;
7
+ }
8
+
9
+ :host([hidden]) {
10
+ display: none;
11
+ }
12
+
13
+ .ac-input-basic {
14
+ /* Foco y error dependen del tema porque el texto/borde va sobre la página:
15
+ tonos claros sobre fondo oscuro, tonos oscuros sobre fondo claro. Ver
16
+ "Dark-mode y colores de fondo sólido" en docs/CONVENTIONS.md. */
17
+ --ac-input-focus: var(--color-primary-500, #10b981);
18
+ --ac-input-error: #ff9b9b;
19
+ display: flex;
20
+ flex-direction: column;
21
+ gap: var(--space-1, 0.35rem);
22
+ font-size: var(--font-size-md, 0.95rem);
23
+ color: var(--color-text, #bcbec4);
24
+ }
25
+
26
+ .ac-input--secondary {
27
+ --ac-input-focus: var(--color-accent-500, #f59e0b);
28
+ }
29
+
30
+ :host-context([data-theme=light]) .ac-input-basic {
31
+ --ac-input-focus: var(--color-primary-700, #047857);
32
+ --ac-input-error: #b42318;
33
+ }
34
+
35
+ :host-context([data-theme=light]) .ac-input--secondary {
36
+ --ac-input-focus: var(--color-accent-700, #b45309);
37
+ }
38
+
39
+ .ac-input-basic__label {
40
+ font-size: var(--font-size-sm, 0.85rem);
41
+ font-weight: var(--font-weight-medium, 600);
42
+ }
43
+
44
+ .ac-input-basic__field {
45
+ box-sizing: border-box;
46
+ width: 100%;
47
+ padding: var(--space-2, 0.55rem) var(--space-3, 0.75rem);
48
+ font: inherit;
49
+ color: var(--color-text, #bcbec4);
50
+ background: var(--color-surface, #2b2b2b);
51
+ /* El borde (elemento de interfaz) cumple 3:1 contra el fondo en ambos temas. */
52
+ border: 1px solid var(--color-subtext, #787a80);
53
+ border-radius: var(--radius-md, 1rem);
54
+ /* corner-shape: squircle (soportado en Chromium, ver "Emerald Pro" en
55
+ docs/CONVENTIONS.md) suaviza la curva junto a --radius/--radius-sm —
56
+ mejora progresiva, sin @supports: se ignora sola donde no se reconoce. */
57
+ corner-shape: squircle;
58
+ transition: border-color 120ms ease, box-shadow 120ms ease;
59
+ }
60
+
61
+ .ac-input-basic__field::placeholder {
62
+ /* Mezcla (no opacity): el contraste se calcula contra el fondo del campo. */
63
+ color: color-mix(in srgb, var(--color-text, #bcbec4) 70%, var(--color-surface, #2b2b2b));
64
+ }
65
+
66
+ .ac-input-basic__field:focus-visible {
67
+ outline: none;
68
+ border-color: var(--ac-input-focus);
69
+ box-shadow: 0 0 0 2px var(--ac-input-focus);
70
+ }
71
+
72
+ .ac-input--invalid .ac-input-basic__field {
73
+ border-color: var(--color-danger, #e05555);
74
+ }
75
+
76
+ .ac-input--invalid .ac-input-basic__field:focus-visible {
77
+ border-color: var(--color-danger, #e05555);
78
+ box-shadow: 0 0 0 2px var(--color-danger, #e05555);
79
+ }
80
+
81
+ .ac-input-basic__field[readonly] {
82
+ border-style: dashed;
83
+ }
84
+
85
+ .ac-input-basic__field:disabled {
86
+ cursor: not-allowed;
87
+ color: var(--color-subtext, #787a80);
88
+ background: var(--color-muted, #313335);
89
+ border-color: var(--color-muted, #313335);
90
+ }
91
+
92
+ .ac-input-basic__message {
93
+ margin: 0;
94
+ font-size: var(--font-size-sm, 0.8rem);
95
+ color: var(--color-text, #bcbec4);
96
+ }
97
+
98
+ .ac-input-basic__message--error {
99
+ color: var(--ac-input-error);
100
+ font-weight: var(--font-weight-medium, 600);
101
+ }
102
+
103
+ @media (prefers-reduced-motion: reduce) {
104
+ .ac-input-basic__field {
105
+ transition: none;
106
+ }
107
+ }
108
+ `;
@@ -0,0 +1,106 @@
1
+ :host {
2
+ display: block;
3
+ }
4
+
5
+ :host([hidden]) {
6
+ display: none;
7
+ }
8
+
9
+ .ac-input-basic {
10
+ /* Foco y error dependen del tema porque el texto/borde va sobre la página:
11
+ tonos claros sobre fondo oscuro, tonos oscuros sobre fondo claro. Ver
12
+ "Dark-mode y colores de fondo sólido" en docs/CONVENTIONS.md. */
13
+ --ac-input-focus: var(--color-primary-500, #10b981);
14
+ --ac-input-error: #ff9b9b;
15
+
16
+ display: flex;
17
+ flex-direction: column;
18
+ gap: var(--space-1, 0.35rem);
19
+ font-size: var(--font-size-md, 0.95rem);
20
+ color: var(--color-text, #bcbec4);
21
+ }
22
+
23
+ .ac-input--secondary {
24
+ --ac-input-focus: var(--color-accent-500, #f59e0b);
25
+ }
26
+
27
+ :host-context([data-theme='light']) .ac-input-basic {
28
+ --ac-input-focus: var(--color-primary-700, #047857);
29
+ --ac-input-error: #b42318;
30
+ }
31
+
32
+ :host-context([data-theme='light']) .ac-input--secondary {
33
+ --ac-input-focus: var(--color-accent-700, #b45309);
34
+ }
35
+
36
+ .ac-input-basic__label {
37
+ font-size: var(--font-size-sm, 0.85rem);
38
+ font-weight: var(--font-weight-medium, 600);
39
+ }
40
+
41
+ .ac-input-basic__field {
42
+ box-sizing: border-box;
43
+ width: 100%;
44
+ padding: var(--space-2, 0.55rem) var(--space-3, 0.75rem);
45
+ font: inherit;
46
+ color: var(--color-text, #bcbec4);
47
+ background: var(--color-surface, #2b2b2b);
48
+ /* El borde (elemento de interfaz) cumple 3:1 contra el fondo en ambos temas. */
49
+ border: 1px solid var(--color-subtext, #787a80);
50
+ border-radius: var(--radius-md, 1rem);
51
+ /* corner-shape: squircle (soportado en Chromium, ver "Emerald Pro" en
52
+ docs/CONVENTIONS.md) suaviza la curva junto a --radius/--radius-sm —
53
+ mejora progresiva, sin @supports: se ignora sola donde no se reconoce. */
54
+ corner-shape: squircle;
55
+ transition:
56
+ border-color 120ms ease,
57
+ box-shadow 120ms ease;
58
+ }
59
+
60
+ .ac-input-basic__field::placeholder {
61
+ /* Mezcla (no opacity): el contraste se calcula contra el fondo del campo. */
62
+ color: color-mix(in srgb, var(--color-text, #bcbec4) 70%, var(--color-surface, #2b2b2b));
63
+ }
64
+
65
+ .ac-input-basic__field:focus-visible {
66
+ outline: none;
67
+ border-color: var(--ac-input-focus);
68
+ box-shadow: 0 0 0 2px var(--ac-input-focus);
69
+ }
70
+
71
+ .ac-input--invalid .ac-input-basic__field {
72
+ border-color: var(--color-danger, #e05555);
73
+ }
74
+
75
+ .ac-input--invalid .ac-input-basic__field:focus-visible {
76
+ border-color: var(--color-danger, #e05555);
77
+ box-shadow: 0 0 0 2px var(--color-danger, #e05555);
78
+ }
79
+
80
+ .ac-input-basic__field[readonly] {
81
+ border-style: dashed;
82
+ }
83
+
84
+ .ac-input-basic__field:disabled {
85
+ cursor: not-allowed;
86
+ color: var(--color-subtext, #787a80);
87
+ background: var(--color-muted, #313335);
88
+ border-color: var(--color-muted, #313335);
89
+ }
90
+
91
+ .ac-input-basic__message {
92
+ margin: 0;
93
+ font-size: var(--font-size-sm, 0.8rem);
94
+ color: var(--color-text, #bcbec4);
95
+ }
96
+
97
+ .ac-input-basic__message--error {
98
+ color: var(--ac-input-error);
99
+ font-weight: var(--font-weight-medium, 600);
100
+ }
101
+
102
+ @media (prefers-reduced-motion: reduce) {
103
+ .ac-input-basic__field {
104
+ transition: none;
105
+ }
106
+ }