@punica/components-mcp 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/bundled.json +1 -0
- package/dist/custom-elements.json +38745 -0
- package/dist/guide.md +118 -0
- package/dist/server.mjs +779 -0
- package/package.json +45 -4
package/dist/guide.md
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# @punica/components 2.0: how to use it
|
|
2
|
+
|
|
3
|
+
Framework-free custom elements, all named `punica-*`. Version 2.0 is a clean
|
|
4
|
+
break from 1.x: names you may remember from 1.x (`punica-typography`,
|
|
5
|
+
`punica-modal`, `change` events, `startIcon` slots, `fullwidth`) are wrong.
|
|
6
|
+
Use only the tags, attributes, events and slots this document lists; never
|
|
7
|
+
guess one.
|
|
8
|
+
|
|
9
|
+
## Loading
|
|
10
|
+
|
|
11
|
+
```html
|
|
12
|
+
<!-- No build step: one classic script, global `Punica` -->
|
|
13
|
+
<script src="https://cdn.jsdelivr.net/npm/@punica/components@2/dist/punica-components.min.js"></script>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import '@punica/components'; // every element
|
|
18
|
+
import '@punica/components/components/button/button.js'; // one element
|
|
19
|
+
import { toast } from '@punica/components'; // toast('Saved', { color: 'success' })
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Rules that hold for every element
|
|
23
|
+
|
|
24
|
+
- **Attributes are kebab-case**: `full-width`, `label-close`, `no-light-dismiss`.
|
|
25
|
+
HTML lowercases `fullWidth` to `fullwidth`, which is not an attribute.
|
|
26
|
+
- **Booleans follow HTML**: present means on. `disabled="false"` is still
|
|
27
|
+
disabled; leave the attribute out instead.
|
|
28
|
+
- **Enumerations** take exactly the listed values. Shared ones:
|
|
29
|
+
`size`: `small | medium | large`; `color`: `primary | secondary | error |
|
|
30
|
+
warning | info | success | neutral`; `orientation`: `horizontal | vertical`.
|
|
31
|
+
- **Events are `punica-*`**, bubbling and composed: `punica-input` (while
|
|
32
|
+
editing), `punica-change` (committed), `punica-select`, `punica-open`,
|
|
33
|
+
`punica-close`, `punica-toggle`, `punica-dismiss`. No element fires a
|
|
34
|
+
native `change`, `input`, `select` or `close`; a listener for those never
|
|
35
|
+
runs. Read the value from `event.detail` (`detail.value`, `detail.checked`).
|
|
36
|
+
A change made from script fires nothing.
|
|
37
|
+
- **Native `click`, `focus`, `keydown`** pass through as usual.
|
|
38
|
+
- **Slots**: `start` and `end` hold leading and trailing content (icons,
|
|
39
|
+
adornments). Other slot names are per element.
|
|
40
|
+
- **Data** (arrays, objects, functions) is a property set from script, never
|
|
41
|
+
an attribute: `table.rows = [...]`.
|
|
42
|
+
- **Accessible names**: a control's `label` attribute, or its text content.
|
|
43
|
+
An icon-only control needs `label`.
|
|
44
|
+
- **Icons**: `<punica-icon name="…">` draws only the built-in glyphs listed
|
|
45
|
+
under `punica-icon`. For any other icon, put an `<svg>` inside
|
|
46
|
+
`<punica-icon>` or in the control's `start` slot.
|
|
47
|
+
|
|
48
|
+
## Forms
|
|
49
|
+
|
|
50
|
+
Every element that takes a value is a real form control: give it `name` and
|
|
51
|
+
it is in `FormData`, reset with the form, validated (`required`, `min`,
|
|
52
|
+
`max`), disabled by `<fieldset disabled>`. Wrap a control in `punica-field`
|
|
53
|
+
for a label, help text and an error message:
|
|
54
|
+
|
|
55
|
+
```html
|
|
56
|
+
<form>
|
|
57
|
+
<punica-field label="Email" help="We never share it.">
|
|
58
|
+
<punica-input name="email" type="email" required></punica-input>
|
|
59
|
+
</punica-field>
|
|
60
|
+
<punica-button type="submit">Subscribe</punica-button>
|
|
61
|
+
</form>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Overlays
|
|
65
|
+
|
|
66
|
+
Dialogs, menus, popovers and drawers open in the browser's top layer: no
|
|
67
|
+
z-index, no portal. Open them with the `open` attribute (dialogs, drawers,
|
|
68
|
+
sheets and menus also have `show()` and `hide()`); they fire `punica-open` and `punica-close` (with
|
|
69
|
+
`detail.reason`).
|
|
70
|
+
|
|
71
|
+
## Theming
|
|
72
|
+
|
|
73
|
+
Design tokens are `--punica-*` custom properties, built in. Override any of
|
|
74
|
+
them; set `color-scheme` for light and dark:
|
|
75
|
+
|
|
76
|
+
```css
|
|
77
|
+
:root {
|
|
78
|
+
color-scheme: light dark;
|
|
79
|
+
--punica-color-primary: light-dark(#0b57d0, #a8c7fa);
|
|
80
|
+
--punica-radius: 8px;
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Restyle inside an element with `::part(name)` and `:state(name)`; each
|
|
85
|
+
element lists its parts, states and its own `--punica-<element>-*`
|
|
86
|
+
properties. Right-to-left works with `dir="rtl"` on any ancestor.
|
|
87
|
+
|
|
88
|
+
## Frameworks
|
|
89
|
+
|
|
90
|
+
- **React 19**: props that name a property are set as properties; listen
|
|
91
|
+
with `on` + the event name: `onpunica-change={(e) => set(e.detail.value)}`.
|
|
92
|
+
`onChange` never fires.
|
|
93
|
+
- **React 18**: props become string attributes and custom events are not
|
|
94
|
+
wired: add listeners with a `ref` and `useEffect`, and set data properties
|
|
95
|
+
on the ref.
|
|
96
|
+
- **Vue**: `@punica-change="…"`, `:value="…"`; mark `punica-*` as custom
|
|
97
|
+
elements (`compilerOptions.isCustomElement`).
|
|
98
|
+
- **Angular**: `CUSTOM_ELEMENTS_SCHEMA`, `(punica-change)="…"`, `[value]="…"`.
|
|
99
|
+
|
|
100
|
+
## Testing
|
|
101
|
+
|
|
102
|
+
Elements carry their role through `ElementInternals`: a `punica-heading` is
|
|
103
|
+
a heading and a `punica-table-row` a row to a screen reader, with no `role`
|
|
104
|
+
attribute in the markup. Tools that read the markup instead of the
|
|
105
|
+
accessibility tree do not see those roles yet: Playwright's `getByRole`,
|
|
106
|
+
Testing Library's `getByRole`, and rules of axe-core such as
|
|
107
|
+
`page-has-heading-one`. In tests, find such an element by its tag
|
|
108
|
+
(`page.locator('punica-table-row')`); for the one heading of a page that an
|
|
109
|
+
audit has to find, use a native `<h1>`. Roles of native elements inside an
|
|
110
|
+
element (the `button` in a `punica-button`, the `dialog` in a
|
|
111
|
+
`punica-alert-dialog`) are found as usual.
|
|
112
|
+
|
|
113
|
+
## Check your work
|
|
114
|
+
|
|
115
|
+
`npx punica-components validate <files>` checks tags, attributes, values,
|
|
116
|
+
slots, events and icon names against this version and exits 1 on an error.
|
|
117
|
+
`npx punica-components info <tag>` prints one element's whole API.
|
|
118
|
+
Documentation with live examples: https://components.punicalab.com
|