@c2n/tabs 0.0.6 → 0.0.8

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/README.md CHANGED
@@ -25,7 +25,7 @@ npm install @c2n/tabs
25
25
  - Children that are `<c2-tab>` become the header; every other child is a panel matched by `id` to a tab's `for`. Only the selected panel is rendered.
26
26
  - Omit `selected-tab` to start on the first enabled tab. Set the `selectedTab` property (or the attribute) to switch programmatically.
27
27
  - Keyboard: Left/Right arrows, Home and End move between tabs and select them (disabled tabs are skipped); Enter and Space activate the focused tab. The strip exposes `tablist` / `tab` / `tabpanel` roles with `aria-selected`, `aria-controls`, `aria-labelledby` and a roving `tabindex`.
28
- - Events: `c2-tabs` fires `change` (`detail: { value }`) after a user selection. Each `c2-tab` fires a cancelable `tab-change` (`detail: for`) first; call `preventDefault()` on it to keep the current tab.
28
+ - Events: `c2-tabs` fires `selection-change` (`detail: { value }`) after a user selection. Each `c2-tab` fires a cancelable `tab-change` (`detail: for`) first; call `preventDefault()` on it to keep the current tab.
29
29
  - The selection indicator follows the selected tab and re-measures on resize and label changes. Respects `prefers-reduced-motion`.
30
30
 
31
31
  Theming goes through CSS custom properties (`--c2-tabs--*`, `--c2-tabs__tab--*`, `--c2-tabs__tab__{hover,selected,focus,disabled}--*`, `--c2-tabs__indicator--*`). The full list is in `custom-elements.json` and on the docs site.
@@ -1,6 +1,7 @@
1
1
  import { t as selectedTabContext } from "./tab-context-C4m2EOBP.js";
2
2
  import { LitElement, html, unsafeCSS } from "lit";
3
- import { customElement, property } from "lit/decorators.js";
3
+ import { property } from "lit/decorators.js";
4
+ import { customElement } from "@c2n/core/element-helper.js";
4
5
  import { isServer } from "lit-html/is-server.js";
5
6
  //#region ../../../node_modules/@lit/context/lib/context-request-event.js
6
7
  /**
@@ -103,13 +104,13 @@ var Tab = class Tab extends LitElement {
103
104
  }
104
105
  };
105
106
  if (!isServer) {
106
- this.setAttribute("slot", "tab");
107
107
  this.addEventListener("click", this.handleClick);
108
108
  this.addEventListener("keydown", this.handleKeydown);
109
109
  }
110
110
  }
111
111
  connectedCallback() {
112
112
  super.connectedCallback();
113
+ if (!isServer) this.setAttribute("slot", "tab");
113
114
  if (!this.hasAttribute("role")) this.setAttribute("role", "tab");
114
115
  if (!this.hasAttribute("tabindex")) this.tabIndex = -1;
115
116
  }
package/dist/tab.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as Tab } from "./tab-Cn3SGI4Q.js";
1
+ import { t as Tab } from "./tab-DUHny6Dg.js";
2
2
  export { Tab };
package/dist/tabs.js CHANGED
@@ -1,7 +1,8 @@
1
- import { n as __decorate, r as s$1 } from "./tab-Cn3SGI4Q.js";
1
+ import { n as __decorate, r as s$1 } from "./tab-DUHny6Dg.js";
2
2
  import { t as selectedTabContext } from "./tab-context-C4m2EOBP.js";
3
3
  import { LitElement, html, unsafeCSS } from "lit";
4
- import { customElement, property, query, state } from "lit/decorators.js";
4
+ import { property, query, state } from "lit/decorators.js";
5
+ import { customElement } from "@c2n/core/element-helper.js";
5
6
  import { classMap } from "lit/directives/class-map.js";
6
7
  import { isServer } from "lit-html/is-server.js";
7
8
  //#region ../../../node_modules/@lit/context/lib/value-notifier.js
@@ -165,9 +166,9 @@ var Tabs = class Tabs extends LitElement {
165
166
  const tab = this.tabs.find((t) => t.for === value);
166
167
  if (!tab || tab.disabled) return;
167
168
  this.selectedTab = value;
168
- this.dispatchEvent(new CustomEvent("change", {
169
+ this.dispatchEvent(new CustomEvent("selection-change", {
169
170
  detail: { value },
170
- bubbles: true,
171
+ bubbles: false,
171
172
  composed: true
172
173
  }));
173
174
  }
package/package.json CHANGED
@@ -1,26 +1,38 @@
1
1
  {
2
2
  "name": "@c2n/tabs",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/tabs.js",
6
6
  "exports": {
7
7
  ".": {
8
- "default": "./dist/tabs.js",
9
- "types": "./types/src/tabs.d.ts"
8
+ "types": "./types/src/tabs.d.ts",
9
+ "default": "./dist/tabs.js"
10
10
  },
11
11
  "./tab.js": {
12
- "default": "./dist/tab.js",
13
- "types": "./types/src/tab.d.ts"
12
+ "types": "./types/src/tab.d.ts",
13
+ "default": "./dist/tab.js"
14
14
  },
15
15
  "./tab-context.js": {
16
- "default": "./dist/tab-context.js",
17
- "types": "./types/src/tab-context.d.ts"
16
+ "types": "./types/src/tab-context.d.ts",
17
+ "default": "./dist/tab-context.js"
18
+ },
19
+ "./react": {
20
+ "types": "./react.d.ts",
21
+ "default": "./react.js"
22
+ },
23
+ "./vue": {
24
+ "types": "./vue.d.ts",
25
+ "default": "./vue.js"
18
26
  },
19
27
  "./custom-elements.json": "./custom-elements.json"
20
28
  },
21
29
  "files": [
22
30
  "dist",
23
- "types"
31
+ "types",
32
+ "react.d.ts",
33
+ "react.js",
34
+ "vue.d.ts",
35
+ "vue.js"
24
36
  ],
25
37
  "keywords": [
26
38
  "tabs",
@@ -56,7 +68,7 @@
56
68
  }
57
69
  },
58
70
  "dependencies": {
59
- "@c2n/core": "0.0.6",
71
+ "@c2n/core": "0.0.8",
60
72
  "@lit/context": "1.1.6",
61
73
  "lit": "3.3.3"
62
74
  },
@@ -64,5 +76,5 @@
64
76
  "@c2n/config": "*"
65
77
  },
66
78
  "customElements": "custom-elements.json",
67
- "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
79
+ "gitHead": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
68
80
  }
package/react.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // JSX types for the custom elements of @c2n/tabs. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/tabs/react'
6
+ //
7
+ // Register the elements at module scope before React renders, or React writes an object prop as an
8
+ // attribute and it stringifies.
9
+
10
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react'
11
+ import type { Tab } from '@c2n/tabs/tab.js'
12
+ import type { Tabs } from '@c2n/tabs'
13
+
14
+ /** Standard React host-element attributes plus the element's own public properties. */
15
+ type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
16
+
17
+ declare module 'react' {
18
+ namespace JSX {
19
+ interface IntrinsicElements {
20
+ 'c2-tab': C2Props<Tab>
21
+ 'c2-tabs': C2Props<Tabs>
22
+ }
23
+ }
24
+ }
25
+
26
+ export {}
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}
@@ -1,4 +1,13 @@
1
1
  import { LitElement, type PropertyValues } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
3
+ /** Events fired by {@link Tab}, keyed for `addEventListener`. */
4
+ export interface TabEventMap {
5
+ 'tab-change': CustomEvent<string>;
6
+ }
7
+ export interface Tab {
8
+ addEventListener: TypedAddEventListener<Tab, TabEventMap>;
9
+ removeEventListener: TypedRemoveEventListener<Tab, TabEventMap>;
10
+ }
2
11
  /**
3
12
  * A single tab inside `<c2-tabs>`. Its `for` attribute names the `id` of the panel it controls.
4
13
  * The parent owns selection: it sets `selected` and the roving `tabindex`; this element exposes
@@ -16,6 +25,7 @@ export declare class Tab extends LitElement {
16
25
  label: string;
17
26
  /** `id` of the panel this tab controls. */
18
27
  for: string;
28
+ /** Prevents activation and removes this tab from keyboard navigation. */
19
29
  disabled: boolean;
20
30
  /** Set by the parent `<c2-tabs>`; do not set by hand. */
21
31
  selected: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"tab.d.ts","sourceRoot":"","sources":["../../src/tab.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAOtE;;;;;;;;;;GAUG;AACH,qBACa,GAAI,SAAQ,UAAU;IACjC,OAAgB,MAAM,0BAAoB;IAE1C,8FAA8F;IACnD,KAAK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CAKpB;IAED,OAAO,CAAC,QAAQ;IAKP,MAAM;CAGhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,QAAQ,EAAE,GAAG,CAAA;KACd;CACF"}
@@ -1,6 +1,20 @@
1
1
  import { LitElement, type PropertyValues } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
2
3
  import './tab';
3
4
  import type { Tab } from './tab';
5
+ /** Detail of the `selection-change` event of {@link Tabs}. */
6
+ export interface TabsSelectionChangeEventDetail {
7
+ /** `for` value of the tab that is now selected — the new `selected-tab`. */
8
+ value: string;
9
+ }
10
+ /** Events fired by {@link Tabs}, keyed for `addEventListener`. */
11
+ export interface TabsEventMap {
12
+ 'selection-change': CustomEvent<TabsSelectionChangeEventDetail>;
13
+ }
14
+ export interface Tabs {
15
+ addEventListener: TypedAddEventListener<Tabs, TabsEventMap>;
16
+ removeEventListener: TypedRemoveEventListener<Tabs, TabsEventMap>;
17
+ }
4
18
  /**
5
19
  * Tab strip that shows one content panel at a time.
6
20
  *
@@ -14,7 +28,10 @@ import type { Tab } from './tab';
14
28
  * @slot tab - The `<c2-tab>` elements (assigned automatically).
15
29
  * @slot tab-content - The panel of the selected tab (assigned automatically from the child whose `id` matches `selected-tab`).
16
30
  *
17
- * @event {CustomEvent<{ value: string }>} change - Fired after the user selects another tab. `detail.value` is the new `selected-tab`. Not fired for programmatic changes.
31
+ * @event {CustomEvent<TabsSelectionChangeEventDetail>} selection-change - Fired after the user selects another tab. `detail.value` is the new `selected-tab`. Not fired for programmatic changes. Does not bubble: several components fire `selection-change`, so a listener belongs on the element itself rather than on an ancestor.
32
+ *
33
+ * The name matches `c2-list`, `c2-select` and `c2-table`; it is deliberately not `change`, which every native form
34
+ * control bubbles — a `c2-text-field` inside a panel would otherwise reach a listener meant for the tab strip.
18
35
  *
19
36
  * @cssproperty {box-shadow} [--c2-tabs--box-shadow=inset 0px -2px 0px 0px rgb(230, 230, 230)]
20
37
  * @cssproperty {justify-content} [--c2-tabs--justify-content=flex-start]
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/tabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAQtE,OAAO,OAAO,CAAA;AACd,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAIhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,qBACa,IAAK,SAAQ,UAAU;IAClC,OAAgB,MAAM,0BAAoB;IAE1C,4GAA4G;IAG5G,WAAW,SAAK;IAGhB,OAAO,CAAC,MAAM,CAAc;IAG5B,OAAO,CAAC,QAAQ,CAAkB;IAGlC,OAAO,CAAC,cAAc,CAAK;IAE3B,4FAA4F;IAE5F,OAAO,CAAC,QAAQ,CAAQ;IAExB,OAAO,CAAC,cAAc,CAAC,CAAgB;IAE9B,iBAAiB;IAOjB,oBAAoB;IAK7B,iDAAiD;IACjD,IAAI,IAAI,IAAI,GAAG,EAAE,CAEhB;IAED,8EAA8E;IAC9E,MAAM,CAAC,KAAK,EAAE,MAAM;IAQpB,OAAO,CAAC,eAAe;IAQvB,OAAO,CAAC,aAAa;YA8BP,mBAAmB;IAqBjC,yGAAyG;IACzG,OAAO,CAAC,QAAQ;IA2BhB,OAAO,CAAC,eAAe;IAgBd,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAQxC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAOrC,MAAM;CAWhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,IAAI,CAAA;KAChB;CACF"}
1
+ {"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/tabs.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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Ac,CAAC,IAAI,CAAC;IAQxC,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAOrC,MAAM;CAWhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,IAAI,CAAA;KAChB;CACF"}
package/vue.d.ts ADDED
@@ -0,0 +1,40 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // Vue template types for the custom elements of @c2n/tabs. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/tabs/vue'
6
+ //
7
+ // Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
8
+ // nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
9
+
10
+ import type { DefineComponent, HTMLAttributes } from 'vue'
11
+ import type { Tab, TabEventMap } from '@c2n/tabs/tab.js'
12
+ import type { Tabs, TabsEventMap } from '@c2n/tabs'
13
+
14
+ /** The element's own public properties, plus every attribute Vue understands on a host element. */
15
+ type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
16
+
17
+ declare module 'vue' {
18
+ interface GlobalComponents {
19
+ 'c2-tab': DefineComponent<
20
+ C2Props<Tab> & {
21
+ onTabChange?: (event: TabEventMap['tab-change']) => void
22
+ }
23
+ >
24
+ 'c2-tabs': DefineComponent<
25
+ C2Props<Tabs> & {
26
+ 'selected-tab'?: unknown
27
+ onSelectionChange?: (event: TabsEventMap['selection-change']) => void
28
+ }
29
+ >
30
+ }
31
+ }
32
+
33
+ declare module '@vue/runtime-dom' {
34
+ interface HTMLAttributes {
35
+ /** Vue's own definition omits it, and slotting a plain element into a component needs it. */
36
+ slot?: string
37
+ }
38
+ }
39
+
40
+ export {}
package/vue.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}