@c2n/stat 0.0.7

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) 2024 Nguyen Thai Vinh
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 ADDED
@@ -0,0 +1,17 @@
1
+ # Stat
2
+
3
+ A compact KPI block with slots for an icon, formatted value, label, trend and supporting description.
4
+
5
+ ```bash
6
+ npm install @c2n/stat
7
+ ```
8
+
9
+ ```html
10
+ <script type="module">
11
+ import '@c2n/stat'
12
+ </script>
13
+
14
+ <c2-stat value="$18.4M" label="Assets under management" tone="positive">
15
+ <span slot="trend">+12%</span>
16
+ </c2-stat>
17
+ ```
package/dist/stat.js ADDED
@@ -0,0 +1,49 @@
1
+ import { LitElement, html, unsafeCSS } from "lit";
2
+ import { property } from "lit/decorators.js";
3
+ import { customElement } from "@c2n/core/element-helper.js";
4
+ //#region src/stat.scss?inline
5
+ var stat_default = "/* ex : var((width: 24px), width, c2-checkbox) returns var(--c2-checkbox-width, 24px) */\n:host {\n display: block;\n}\n\n.c2-stat {\n display: flex;\n align-items: flex-start;\n gap: var(--c2-stat--gap,12px);\n padding: var(--c2-stat--padding,16px);\n color: var(--c2-stat--color,#18181b);\n background: var(--c2-stat--background,#ffffff);\n border: var(--c2-stat--border,1px solid #e4e4e7);\n border-radius: var(--c2-stat--border-radius,8px);\n box-shadow: var(--c2-stat--box-shadow,none);\n}\n\n.icon {\n display: grid;\n width: var(--c2-stat__icon--size,40px);\n height: var(--c2-stat__icon--size,40px);\n flex: 0 0 var(--c2-stat__icon--size,40px);\n place-items: center;\n color: var(--c2-stat__icon--color,#71717a);\n background: var(--c2-stat__icon--background,#f4f4f5);\n border-radius: var(--c2-stat__icon--border-radius,8px);\n}\n.icon ::slotted(*) {\n width: 50%;\n height: 50%;\n}\n\n:host(:not(:has(> [slot=icon]))) .icon,\n:host(:not(:has(> [slot=description]))) .description {\n display: none;\n}\n\n.content {\n min-width: 0;\n margin: 0;\n}\n\n.value-row {\n display: flex;\n align-items: center;\n gap: 8px;\n}\n\n.value,\n.trend,\n.description {\n margin: 0;\n}\n\n.value {\n font-size: var(--c2-stat__value--font-size,24px);\n font-weight: var(--c2-stat__value--font-weight,600);\n line-height: var(--c2-stat__value--line-height,32px);\n}\n\n.label {\n color: var(--c2-stat__label--color,#71717a);\n font-size: var(--c2-stat__label--font-size,14px);\n}\n\n.description {\n margin-top: 4px;\n color: var(--c2-stat__description--color,#71717a);\n font-size: var(--c2-stat__description--font-size,12px);\n}\n\n:host([tone=positive]) .icon {\n color: var(--c2-stat__icon__positive--color,#15803d);\n background: var(--c2-stat__icon__positive--background,#dcfce7);\n}\n\n:host([tone=negative]) .icon {\n color: var(--c2-stat__icon__negative--color,#b91c1c);\n background: var(--c2-stat__icon__negative--background,#fee2e2);\n}\n\n:host([tone=warning]) .icon {\n color: var(--c2-stat__icon__warning--color,#a16207);\n background: var(--c2-stat__icon__warning--background,#fef3c7);\n}";
6
+ //#endregion
7
+ //#region \0@oxc-project+runtime@0.148.0/helpers/esm/decorate.js
8
+ function __decorate(decorators, target, key, desc) {
9
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
10
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
11
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
12
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
13
+ }
14
+ //#endregion
15
+ //#region src/stat.ts
16
+ var Stat = class Stat extends LitElement {
17
+ constructor(..._args) {
18
+ super(..._args);
19
+ this.value = "";
20
+ this.label = "";
21
+ this.tone = "neutral";
22
+ }
23
+ static {
24
+ this.styles = unsafeCSS(stat_default);
25
+ }
26
+ render() {
27
+ return html`
28
+ <div class="c2-stat" part="container">
29
+ <span class="icon" part="icon" aria-hidden="true"><slot name="icon"></slot></span>
30
+ <div class="content">
31
+ <div class="value-row">
32
+ <div class="value" part="value"><slot name="value">${this.value}</slot></div>
33
+ <div class="trend" part="trend"><slot name="trend"></slot></div>
34
+ </div>
35
+ <div class="label" part="label"><slot name="label">${this.label}</slot></div>
36
+ <div class="description" part="description">
37
+ <slot name="description"></slot>
38
+ </div>
39
+ </div>
40
+ </div>
41
+ `;
42
+ }
43
+ };
44
+ __decorate([property()], Stat.prototype, "value", void 0);
45
+ __decorate([property()], Stat.prototype, "label", void 0);
46
+ __decorate([property({ reflect: true })], Stat.prototype, "tone", void 0);
47
+ Stat = __decorate([customElement("c2-stat")], Stat);
48
+ //#endregion
49
+ export { Stat };
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@c2n/stat",
3
+ "version": "0.0.7",
4
+ "type": "module",
5
+ "main": "dist/stat.js",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./types/src/stat.d.ts",
9
+ "default": "./dist/stat.js"
10
+ },
11
+ "./react": {
12
+ "types": "./react.d.ts",
13
+ "default": "./react.js"
14
+ },
15
+ "./vue": {
16
+ "types": "./vue.d.ts",
17
+ "default": "./vue.js"
18
+ },
19
+ "./custom-elements.json": "./custom-elements.json"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "types",
24
+ "react.d.ts",
25
+ "react.js",
26
+ "vue.d.ts",
27
+ "vue.js"
28
+ ],
29
+ "keywords": [
30
+ "stat",
31
+ "web component",
32
+ "lit"
33
+ ],
34
+ "license": "MIT",
35
+ "author": "code2nguyen@gmail.com",
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org",
38
+ "access": "public"
39
+ },
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/code2nguyen/web-components.git"
43
+ },
44
+ "scripts": {
45
+ "dev": "vite",
46
+ "build": "wireit",
47
+ "build:only": "vite build",
48
+ "type-check": "wireit"
49
+ },
50
+ "wireit": {
51
+ "type-check": {
52
+ "dependencies": [
53
+ "../../core:build"
54
+ ],
55
+ "command": "tsc -p tsconfig.lib.json --composite false"
56
+ },
57
+ "build": {
58
+ "dependencies": [
59
+ "type-check"
60
+ ],
61
+ "command": "vite build"
62
+ }
63
+ },
64
+ "dependencies": {
65
+ "@c2n/core": "0.0.7",
66
+ "lit": "3.3.3"
67
+ },
68
+ "devDependencies": {
69
+ "@c2n/config": "*"
70
+ },
71
+ "customElements": "custom-elements.json",
72
+ "gitHead": "c8db398a27f7cd417d665fdf5da455fee2d4e910"
73
+ }
package/react.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // JSX types for the custom elements of @c2n/stat. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/stat/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 { Stat } from '@c2n/stat'
12
+
13
+ /** Standard React host-element attributes plus the element's own public properties. */
14
+ type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
15
+
16
+ declare module 'react' {
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'c2-stat': C2Props<Stat>
20
+ }
21
+ }
22
+ }
23
+
24
+ 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 {}
@@ -0,0 +1,53 @@
1
+ import { LitElement } from 'lit';
2
+ export type StatTone = 'neutral' | 'positive' | 'negative' | 'warning';
3
+ /**
4
+ * A compact KPI block with an optional icon and trend. Text can be supplied through attributes for simple cases or
5
+ * replaced with slots when the value needs richer formatting.
6
+ *
7
+ * @tag c2-stat
8
+ * @slot value - Replaces the `value` text.
9
+ * @slot label - Replaces the `label` text.
10
+ * @slot icon - Icon shown in the tinted leading container.
11
+ * @slot trend - Badge or short trend text shown beside the value.
12
+ * @slot description - Supporting context below the label.
13
+ * @cssproperty {padding} [--c2-stat--padding=16px]
14
+ * @cssproperty {pixel} [--c2-stat--gap=12px]
15
+ * @cssproperty {color} [--c2-stat--background=#ffffff]
16
+ * @cssproperty {color} [--c2-stat--color=#18181b]
17
+ * @cssproperty {border} [--c2-stat--border=1px solid #e4e4e7]
18
+ * @cssproperty {border-radius} [--c2-stat--border-radius=8px]
19
+ * @cssproperty {box-shadow} [--c2-stat--box-shadow=none]
20
+ * @cssproperty {pixel} [--c2-stat__icon--size=40px]
21
+ * @cssproperty {color} [--c2-stat__icon--background=#f4f4f5]
22
+ * @cssproperty {color} [--c2-stat__icon--color=#71717a]
23
+ * @cssproperty {border-radius} [--c2-stat__icon--border-radius=8px]
24
+ * @cssproperty {color} [--c2-stat__icon__positive--background=#dcfce7]
25
+ * @cssproperty {color} [--c2-stat__icon__positive--color=#15803d]
26
+ * @cssproperty {color} [--c2-stat__icon__negative--background=#fee2e2]
27
+ * @cssproperty {color} [--c2-stat__icon__negative--color=#b91c1c]
28
+ * @cssproperty {color} [--c2-stat__icon__warning--background=#fef3c7]
29
+ * @cssproperty {color} [--c2-stat__icon__warning--color=#a16207]
30
+ * @cssproperty {font-size} [--c2-stat__value--font-size=24px]
31
+ * @cssproperty {font-weight} [--c2-stat__value--font-weight=600]
32
+ * @cssproperty {pixel} [--c2-stat__value--line-height=32px]
33
+ * @cssproperty {font-size} [--c2-stat__label--font-size=14px]
34
+ * @cssproperty {color} [--c2-stat__label--color=#71717a]
35
+ * @cssproperty {font-size} [--c2-stat__description--font-size=12px]
36
+ * @cssproperty {color} [--c2-stat__description--color=#71717a]
37
+ */
38
+ export declare class Stat extends LitElement {
39
+ static styles: import("lit").CSSResult;
40
+ /** Plain-text metric. Use the `value` slot for formatted markup. */
41
+ value: string;
42
+ /** Plain-text label. Use the `label` slot for formatted markup. */
43
+ label: string;
44
+ /** Semantic colour applied to the icon container. */
45
+ tone: StatTone;
46
+ render(): import("lit-html").TemplateResult<1>;
47
+ }
48
+ declare global {
49
+ interface HTMLElementTagNameMap {
50
+ 'c2-stat': Stat;
51
+ }
52
+ }
53
+ //# sourceMappingURL=stat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stat.d.ts","sourceRoot":"","sources":["../../src/stat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAmB,MAAM,KAAK,CAAA;AAKjD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,CAAA;AAEtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,qBACa,IAAK,SAAQ,UAAU;IAClC,OAAgB,MAAM,0BAAoB;IAE1C,oEAAoE;IACxD,KAAK,SAAK;IAEtB,mEAAmE;IACvD,KAAK,SAAK;IAEtB,qDAAqD;IACxB,IAAI,EAAE,QAAQ,CAAY;IAE9C,MAAM;CAiBhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,SAAS,EAAE,IAAI,CAAA;KAChB;CACF"}
package/vue.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // Vue template types for the custom elements of @c2n/stat. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/stat/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 { Stat } from '@c2n/stat'
12
+
13
+ /** The element's own public properties, plus every attribute Vue understands on a host element. */
14
+ type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
15
+
16
+ declare module 'vue' {
17
+ interface GlobalComponents {
18
+ 'c2-stat': DefineComponent<C2Props<Stat>>
19
+ }
20
+ }
21
+
22
+ declare module '@vue/runtime-dom' {
23
+ interface HTMLAttributes {
24
+ /** Vue's own definition omits it, and slotting a plain element into a component needs it. */
25
+ slot?: string
26
+ }
27
+ }
28
+
29
+ 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 {}