@ac-components/ac-icon-basic 0.0.0-stage → 0.2.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 +21 -0
- package/README.md +60 -2
- package/index.js +10 -0
- package/locales.json +5 -0
- package/package.json +54 -3
- package/src/icon-basic.js +111 -0
- package/src/icon-basic.styles.js +31 -0
- package/src/icon-basic.styles.scss +30 -0
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,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ac-components/ac-icon-basic
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Componente fundacional del lote de 5 componentes básicos nuevos: renderiza **un** ícono de un set propio y pequeño del catálogo, por nombre — sin slots, sin eventos. Lo consume `ac-icon-button-basic` como dependencia interna, así que su API pública (`name`/`size`/`a11y-label`) se mantiene estable.
|
|
4
|
+
|
|
5
|
+
## Instalación
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @ac-components/ac-icon-basic
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import '@ac-components/ac-icon-basic';
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<ac-icon-basic name="check"></ac-icon-basic>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Propiedades
|
|
20
|
+
|
|
21
|
+
| Propiedad | Atributo | Tipo | Default | Descripción |
|
|
22
|
+
| ----------- | ------------ | ------ | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `name` | `name` | String | `''` | Nombre del ícono (ver whitelist abajo). Un `name` que no matchea ninguno cae a un fallback genérico (un círculo simple) — nunca rompe. |
|
|
24
|
+
| `size` | `size` | String | `'md'` | `sm` (16px) \| `md` (20px) \| `lg` (24px), con validación por whitelist y fallback a `'md'` si no matchea — mismo patrón que `ac-spinner-basic`. |
|
|
25
|
+
| `a11yLabel` | `a11y-label` | String | `''` | Si se define (texto o clave de traducción, pasa por `this.t()`), el ícono deja de ser decorativo: `role="img"` + `aria-label`. Vacío (default) ⇒ `aria-hidden="true"`. |
|
|
26
|
+
|
|
27
|
+
Sin eventos. Sin `ambient` — el color del ícono es siempre `currentColor`, heredado del elemento padre (mismo criterio que los íconos inline de `ac-notification-basic`).
|
|
28
|
+
|
|
29
|
+
## Set de íconos
|
|
30
|
+
|
|
31
|
+
Whitelist fija de esta primera versión (`viewBox="0 0 24 24"`, `fill="none"`, `stroke="currentColor"`):
|
|
32
|
+
|
|
33
|
+
`check`, `close`, `info`, `success`, `warning`, `danger`, `chevron-down`, `chevron-up`, `chevron-left`, `chevron-right`, `search`, `menu`, `arrow-left`, `arrow-right`, `email`, `calendar`, `currency`, `hash`.
|
|
34
|
+
|
|
35
|
+
| Ícono | Descripción |
|
|
36
|
+
| ---------- | --------------------------------------- |
|
|
37
|
+
| `email` | Sobre de correo — campos de tipo email. |
|
|
38
|
+
| `calendar` | Calendario — campos de tipo fecha. |
|
|
39
|
+
| `currency` | Billete/moneda — campos de tipo monto. |
|
|
40
|
+
| `hash` | Numeral (#) — campos numéricos. |
|
|
41
|
+
|
|
42
|
+
> `info`/`success`/`warning`/`danger` son deliberadamente idénticos a los paths ya usados en `ICON_MAP` de `ac-notification-basic` — misma identidad visual, no una reinterpretación.
|
|
43
|
+
|
|
44
|
+
Un `name` fuera de esta lista (incluido `''`) renderiza el fallback: un círculo simple (`<circle cx="12" cy="12" r="9"/>`), nunca un ícono vacío o roto.
|
|
45
|
+
|
|
46
|
+
## i18n
|
|
47
|
+
|
|
48
|
+
No tiene ningún texto propio fijo — todo es visual, y `a11yLabel` es un valor que define el consumidor (texto literal o clave de traducción de su propia app). `locales.json` no declara ninguna clave propia.
|
|
49
|
+
|
|
50
|
+
## Desarrollo
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pnpm --filter @ac-components/ac-icon-basic component:lint
|
|
54
|
+
pnpm --filter @ac-components/ac-icon-basic component:serve # demo en http://localhost:5173
|
|
55
|
+
pnpm --filter @ac-components/ac-icon-basic component:test
|
|
56
|
+
pnpm --filter @ac-components/ac-icon-basic component:build
|
|
57
|
+
pnpm --filter @ac-components/ac-icon-basic component:test:e2e # funcional (WebdriverIO + Cucumber)
|
|
58
|
+
pnpm --filter @ac-components/ac-icon-basic component:test:e2e:a11y # accesibilidad (axe-core)
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> `src/icon-basic.styles.js` se genera a partir de `src/icon-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 { IconBasic } from './src/icon-basic.js';
|
|
4
|
+
|
|
5
|
+
export { IconBasic } from './src/icon-basic.js';
|
|
6
|
+
|
|
7
|
+
registerTranslations(IconBasic.is, locales);
|
|
8
|
+
|
|
9
|
+
// Auto-registro del componente
|
|
10
|
+
customElements.define(IconBasic.is, IconBasic);
|
package/locales.json
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-components/ac-icon-basic",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://github.com/RenzoCordovaDev/ac-lit.git",
|
|
7
|
+
"directory": "packages/components/ac-icon-basic"
|
|
8
|
+
},
|
|
9
|
+
"description": "ac-lit basic icon Web Component",
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.js",
|
|
15
|
+
"./locales.json": "./locales.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"/src/",
|
|
19
|
+
"index.js",
|
|
20
|
+
"locales.json"
|
|
21
|
+
],
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"access": "public"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@ac-base/ac-intl-mixin": "^0.1.0",
|
|
27
|
+
"@ac-base/ac-component-mixin": "^0.1.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"lit": "^3.0.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@open-wc/testing": "^4.0.0",
|
|
34
|
+
"@web/test-runner": "^0.18.0",
|
|
35
|
+
"concurrently": "^9.1.0",
|
|
36
|
+
"lit": "^3.0.0",
|
|
37
|
+
"sass": "^1.79.4",
|
|
38
|
+
"vite": "^5.4.8",
|
|
39
|
+
"@ac-base/ac-demo-content": "^0.4.0",
|
|
40
|
+
"@ac-base/ac-core": "^0.1.0",
|
|
41
|
+
"@ac-base/cli": "^0.5.2",
|
|
42
|
+
"@ac-base/ac-e2e-testing": "^0.1.0"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"component:lint": "eslint .",
|
|
46
|
+
"component:build:styles": "node ./node_modules/@ac-base/cli/scripts/compile-scss-to-lit.cjs src/icon-basic.styles.scss src/icon-basic.styles.js IconBasicStyles",
|
|
47
|
+
"component:build:styles:watch": "node ./node_modules/@ac-base/cli/scripts/compile-scss-to-lit.cjs src/icon-basic.styles.scss src/icon-basic.styles.js IconBasicStyles --watch",
|
|
48
|
+
"component:serve": "pnpm run component:build:styles && concurrently -k -n styles,vite -c blue,green \"pnpm run component:build:styles:watch\" \"vite demo\"",
|
|
49
|
+
"component:build": "pnpm run component:build:styles && vite build",
|
|
50
|
+
"component:preview": "vite preview",
|
|
51
|
+
"component:test": "pnpm run component:build:styles && web-test-runner \"test/**/*.test.js\"",
|
|
52
|
+
"component:test:e2e": "pnpm run component:build && start-server-and-test component:preview http://localhost:4173 component:test:e2e:run",
|
|
53
|
+
"component:test:e2e:run": "wdio run test_e2e/wdio.conf.js",
|
|
54
|
+
"component:test:e2e:a11y": "pnpm run component:build && start-server-and-test component:preview http://localhost:4173 component:test:e2e:a11y:run",
|
|
55
|
+
"component:test:e2e:a11y:run": "wdio run test_e2e/wdio.a11y.conf.js"
|
|
56
|
+
}
|
|
6
57
|
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { LitElement, html, svg, nothing } from 'lit';
|
|
2
|
+
import { ComponentMixin, componentBaseStyles } from '@ac-base/ac-component-mixin';
|
|
3
|
+
// Authored in icon-basic.styles.scss, compiled to icon-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 { IconBasicStyles } from './icon-basic.styles.js';
|
|
7
|
+
|
|
8
|
+
const SIZES = new Set(['sm', 'md', 'lg']);
|
|
9
|
+
const DEFAULT_SIZE = 'md';
|
|
10
|
+
|
|
11
|
+
// Set de íconos propio, mínimo, para el catálogo — mismo estilo visual que
|
|
12
|
+
// los íconos inline de ac-notification-basic (ver ICON_MAP/CLOSE_ICON en
|
|
13
|
+
// notification-basic.js): viewBox 24x24, fill none, stroke currentColor
|
|
14
|
+
// (heredado del `<svg>`, no de cada path/circle). `info`/`success`/`warning`/
|
|
15
|
+
// `danger` son deliberadamente idénticos a los de ac-notification-basic (ver
|
|
16
|
+
// docs/CONVENTIONS.md) para mantener consistencia visual exacta, no una
|
|
17
|
+
// reinterpretación.
|
|
18
|
+
//
|
|
19
|
+
// Importante: estos fragmentos van con la función `svg` de lit, NO `html`.
|
|
20
|
+
// Son `<path>`/`<circle>` sueltos, sin su propio `<svg>` envolvente (a
|
|
21
|
+
// diferencia de ICON_MAP/CLOSE_ICON de ac-notification-basic, que sí son un
|
|
22
|
+
// `<svg>` completo cada uno) -- con `html`, lit-html parsea el fragmento en
|
|
23
|
+
// un namespace HTML (nunca ven un `<svg>` ancestro en su propio template),
|
|
24
|
+
// así que el `<path>`/`<circle>` resultante queda en el namespace HTML
|
|
25
|
+
// (`http://www.w3.org/1999/xhtml`), no el de SVG, y el navegador no lo pinta
|
|
26
|
+
// aunque todos sus atributos estén bien -- aunque se inserte después como
|
|
27
|
+
// hijo de un `<svg>` real, los elementos no se re-asignan de namespace al
|
|
28
|
+
// moverse en el DOM. `svg` le dice a lit-html que clone el fragmento con el
|
|
29
|
+
// wrapper de namespace SVG correcto.
|
|
30
|
+
const ICON_MAP = {
|
|
31
|
+
check: svg`<path d="M5 13l4 4L19 7" />`,
|
|
32
|
+
close: svg`<path d="M6 6l12 12M18 6L6 18" />`,
|
|
33
|
+
info: svg`<circle cx="12" cy="12" r="9" /><path d="M12 11v5M12 8v.01" />`,
|
|
34
|
+
success: svg`<circle cx="12" cy="12" r="9" /><path d="M8 12.5l2.5 2.5L16 9.5" />`,
|
|
35
|
+
warning: svg`<path d="M12 4.5l9 15.5H3l9-15.5z" /><path d="M12 10.5v3.5M12 17v.01" />`,
|
|
36
|
+
danger: svg`<circle cx="12" cy="12" r="9" /><path d="M12 7.5v5.5M12 16v.01" />`,
|
|
37
|
+
'chevron-down': svg`<path d="M6 9l6 6 6-6" />`,
|
|
38
|
+
'chevron-up': svg`<path d="M6 15l6-6 6 6" />`,
|
|
39
|
+
'chevron-left': svg`<path d="M15 6l-6 6 6 6" />`,
|
|
40
|
+
'chevron-right': svg`<path d="M9 6l6 6-6 6" />`,
|
|
41
|
+
search: svg`<circle cx="11" cy="11" r="7" /><path d="M21 21l-4.3-4.3" />`,
|
|
42
|
+
menu: svg`<path d="M4 6h16M4 12h16M4 18h16" />`,
|
|
43
|
+
'arrow-left': svg`<path d="M19 12H5M11 18l-6-6 6-6" />`,
|
|
44
|
+
'arrow-right': svg`<path d="M5 12h14M13 6l6 6-6 6" />`,
|
|
45
|
+
email: svg`<rect x="3" y="5" width="18" height="14" rx="2" /><path d="M3 7l9 6 9-6" />`,
|
|
46
|
+
calendar: svg`<rect x="3" y="5" width="18" height="16" rx="2" /><path d="M16 3v4M8 3v4M3 10h18" />`,
|
|
47
|
+
currency: svg`<rect x="2" y="7" width="20" height="10" rx="2" /><circle cx="12" cy="12" r="2.5" />`,
|
|
48
|
+
hash: svg`<path d="M5 9h14M5 15h14M9 4L7 20M17 4l-2 16" />`,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// Fallback para cualquier `name` fuera de la whitelist de arriba — un círculo
|
|
52
|
+
// simple, el ícono nunca queda vacío/roto.
|
|
53
|
+
const FALLBACK_ICON = svg`<circle cx="12" cy="12" r="9" />`;
|
|
54
|
+
|
|
55
|
+
export class IconBasic extends ComponentMixin(LitElement) {
|
|
56
|
+
static get is() {
|
|
57
|
+
return 'ac-icon-basic';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// componentBaseStyles primero: fija `font-family` (aunque acá no haya
|
|
61
|
+
// texto propio, es la convención del catálogo, ver docs/CONVENTIONS.md) y
|
|
62
|
+
// el skeleton de `loading` — no lo quites.
|
|
63
|
+
static get styles() {
|
|
64
|
+
return [componentBaseStyles, IconBasicStyles];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
static get properties() {
|
|
68
|
+
return {
|
|
69
|
+
name: { type: String },
|
|
70
|
+
size: { type: String, reflect: true },
|
|
71
|
+
a11yLabel: { type: String, attribute: 'a11y-label' },
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
constructor() {
|
|
76
|
+
super();
|
|
77
|
+
this.name = '';
|
|
78
|
+
this.size = DEFAULT_SIZE;
|
|
79
|
+
this.a11yLabel = '';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get _size() {
|
|
83
|
+
return SIZES.has(this.size) ? this.size : DEFAULT_SIZE;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
render() {
|
|
87
|
+
const classes = `ac-icon-basic ac-icon-basic--${this._size}`;
|
|
88
|
+
// Decorativo por defecto (sin `a11yLabel`): aria-hidden, igual criterio
|
|
89
|
+
// que ICON_MAP de ac-notification-basic (el texto ya está al lado). Con
|
|
90
|
+
// `a11yLabel` definido deja de ser decorativo: role="img" + aria-label.
|
|
91
|
+
const label = this.a11yLabel ? this.t(this.a11yLabel) : '';
|
|
92
|
+
|
|
93
|
+
return html`
|
|
94
|
+
<svg
|
|
95
|
+
part="icon"
|
|
96
|
+
class=${classes}
|
|
97
|
+
viewBox="0 0 24 24"
|
|
98
|
+
fill="none"
|
|
99
|
+
stroke="currentColor"
|
|
100
|
+
stroke-width="2"
|
|
101
|
+
stroke-linecap="round"
|
|
102
|
+
stroke-linejoin="round"
|
|
103
|
+
role=${label ? 'img' : nothing}
|
|
104
|
+
aria-label=${label ? label : nothing}
|
|
105
|
+
aria-hidden=${label ? nothing : 'true'}
|
|
106
|
+
>
|
|
107
|
+
${ICON_MAP[this.name] ?? FALLBACK_ICON}
|
|
108
|
+
</svg>
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
|
|
3
|
+
export const IconBasicStyles = css`
|
|
4
|
+
:host {
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
:host([hidden]) {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.ac-icon-basic {
|
|
13
|
+
display: block;
|
|
14
|
+
flex-shrink: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ac-icon-basic--sm {
|
|
18
|
+
width: 16px;
|
|
19
|
+
height: 16px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ac-icon-basic--md {
|
|
23
|
+
width: 20px;
|
|
24
|
+
height: 20px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ac-icon-basic--lg {
|
|
28
|
+
width: 24px;
|
|
29
|
+
height: 24px;
|
|
30
|
+
}
|
|
31
|
+
`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
:host {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
:host([hidden]) {
|
|
6
|
+
display: none;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.ac-icon-basic {
|
|
10
|
+
// Todo el color viene de `currentColor` (heredado del elemento padre) —
|
|
11
|
+
// el componente nunca define su propio color ni usa `ambient`, igual
|
|
12
|
+
// criterio que los íconos inline de ac-notification-basic.
|
|
13
|
+
display: block;
|
|
14
|
+
flex-shrink: 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ac-icon-basic--sm {
|
|
18
|
+
width: 16px;
|
|
19
|
+
height: 16px;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.ac-icon-basic--md {
|
|
23
|
+
width: 20px;
|
|
24
|
+
height: 20px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.ac-icon-basic--lg {
|
|
28
|
+
width: 24px;
|
|
29
|
+
height: 24px;
|
|
30
|
+
}
|