@antadesign/anta 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/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Anta
2
+
3
+ Portable UI component library. Framework-agnostic web components with JSX wrappers that work in React, Preact, or any custom JSX runtime.
4
+
5
+ ## Usage
6
+
7
+ ### React
8
+
9
+ Works out of the box — no configuration needed.
10
+
11
+ ```tsx
12
+ import { Progress } from 'anta'
13
+
14
+ <Progress value={42} max={100} tone="info" />
15
+ ```
16
+
17
+ ### Preact (compat mode)
18
+
19
+ If your project aliases `react` → `preact/compat`, anta works with no extra setup — same as React.
20
+
21
+ ### Preact (no compat)
22
+
23
+ Call `configure()` before rendering any anta components:
24
+
25
+ ```ts
26
+ import { configure } from 'anta'
27
+ import { h, Fragment } from 'preact'
28
+
29
+ configure(h, Fragment)
30
+ ```
31
+
32
+ ### Custom JSX runtime
33
+
34
+ Pass any `h(type, props, ...children)` function:
35
+
36
+ ```ts
37
+ import { configure } from 'anta'
38
+ configure(myH, myFragment)
39
+ ```
40
+
41
+ ## Web components
42
+
43
+ Anta components are built on custom elements with shadow DOM. Import `anta/elements` to auto-register them, or use individual register functions:
44
+
45
+ ```ts
46
+ import 'anta/elements' // auto-register all
47
+ import { register_a_progress } from 'anta/elements' // one at a time
48
+ ```
49
+
50
+ Raw web components work without JSX:
51
+
52
+ ```html
53
+ <a-progress value="42" max="100" tone="info"></a-progress>
54
+ ```
@@ -0,0 +1 @@
1
+ export declare function hasChildren(children: React.ReactNode): boolean;
@@ -0,0 +1,6 @@
1
+ function hasChildren(children) {
2
+ return Array.isArray(children) ? children.length > 0 : children != null;
3
+ }
4
+ export {
5
+ hasChildren
6
+ };
@@ -0,0 +1,12 @@
1
+ import type { BaseProps } from "../general_types";
2
+ interface ProgressProps extends BaseProps {
3
+ /** Current progress. Negative values are clamped to 0. */
4
+ value: number;
5
+ /** Upper bound of the range. Defaults to 100. Negative values are clamped to 0. */
6
+ max?: number;
7
+ tone?: 'neutral' | 'info';
8
+ label?: string;
9
+ hint?: string;
10
+ }
11
+ export declare const Progress: ({ value, max, tone, label, hint, className, children, ...rest }: ProgressProps) => any;
12
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jsx, jsxs } from "@antadesign/anta/jsx-runtime";
2
+ import { hasChildren } from "../anta_helpers";
3
+ const Progress = ({ value, max = 100, tone, label, hint, className, children, ...rest }) => {
4
+ const percent = max > 0 ? Math.round(Math.min(100, Math.max(0, value / max * 100))) : 0;
5
+ return /* @__PURE__ */ jsx(
6
+ "a-progress",
7
+ {
8
+ value,
9
+ max,
10
+ tone,
11
+ class: className,
12
+ ...rest,
13
+ children: hasChildren(children) ? children : /* @__PURE__ */ jsxs("a-progress-label", { children: [
14
+ /* @__PURE__ */ jsxs("a-progress-number", { children: [
15
+ percent,
16
+ "%"
17
+ ] }),
18
+ label != null && /* @__PURE__ */ jsx("a-progress-text", { children: label }),
19
+ hint != null && /* @__PURE__ */ jsx("a-progress-hint", { children: hint })
20
+ ] })
21
+ }
22
+ );
23
+ };
24
+ export {
25
+ Progress
26
+ };
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Base layout is handled by the <a-progress> web component (display: block).
3
+ * This module is reserved for conditional styles driven by JSX logic.
4
+ * And in this case we usually start with .container style
5
+ */
@@ -0,0 +1,65 @@
1
+ a-progress {
2
+ --progress-bg: hsla(300, 10%, 96%, 1);
3
+ --progress-border-color: hsla(300, 6%, 87%, 1);
4
+ --progress-indicator-bg: hsla(300, 7%, 92%, 1);
5
+ --progress-indicator-edge: linear-gradient(90deg, hsla(300, 6%, 87%, 0) 0%, hsla(300, 6%, 87%, 1) 100%);
6
+ --progress-label-color: var(--fg-1);
7
+
8
+ display: block;
9
+ container-type: inline-size;
10
+ padding: 4px 8px;
11
+ min-height: 8px;
12
+ background: var(--progress-bg);
13
+ border: 0px solid var(--progress-border-color);
14
+ border-radius: 0;
15
+ }
16
+
17
+ .dark a-progress {
18
+ --progress-bg: hsla(278, 8%, 9%, 1);
19
+ --progress-border-color: hsla(278, 8%, 23%, 1);
20
+ --progress-indicator-bg: hsla(278, 8%, 15%, 1);
21
+ --progress-indicator-edge: linear-gradient(90deg, hsla(278, 8%, 23%, 0) 0%, hsla(278, 8%, 23%, 1) 100%);
22
+ }
23
+
24
+ a-progress[tone="info"] {
25
+ --progress-bg: #E7F4FF;
26
+ --progress-border-color: #B8DCF6;
27
+ --progress-indicator-bg: #DBEDFA;
28
+ --progress-indicator-edge: linear-gradient(90deg, hsla(205, 79%, 85%, 0) 0%, hsla(205, 79%, 85%, 1) 100%);
29
+ --progress-label-color: var(--fg-1-blue);
30
+ }
31
+
32
+ .dark a-progress[tone="info"] {
33
+ --progress-bg: #021A2D;
34
+ --progress-border-color: #062F4C;
35
+ --progress-indicator-bg: #05253F;
36
+ --progress-indicator-edge: linear-gradient(90deg, hsla(207, 85%, 16%, 0) 0%, hsla(207, 85%, 16%, 1) 100%);
37
+ }
38
+
39
+ a-progress-label {
40
+ display: flex;
41
+ align-items: flex-start;
42
+ gap: 0.5ch;
43
+ font-variant-numeric: tabular-nums;
44
+ font-feature-settings: 'ss02', 'ss05';
45
+ letter-spacing: 0.03em;
46
+ font-size: 13px;
47
+ line-height: 16px;
48
+ }
49
+
50
+ a-progress-number {
51
+ flex-shrink: 0;
52
+ color: var(--progress-label-color);
53
+ }
54
+
55
+ a-progress-text {
56
+ flex: 1 1 auto;
57
+ min-width: 0;
58
+ color: var(--fg-2);
59
+ }
60
+
61
+ a-progress-hint {
62
+ flex-shrink: 0;
63
+ margin-left: auto;
64
+ color: var(--fg-3);
65
+ }
@@ -0,0 +1,9 @@
1
+ export declare class AProgressElement extends HTMLElement {
2
+ static observedAttributes: string[];
3
+ indicator: HTMLDivElement;
4
+ constructor();
5
+ connectedCallback(): void;
6
+ attributeChangedCallback(): void;
7
+ update(): void;
8
+ }
9
+ export declare function register_a_progress(): void;
@@ -0,0 +1,64 @@
1
+ class AProgressElement extends HTMLElement {
2
+ static observedAttributes = ["value", "max", "tone"];
3
+ indicator;
4
+ constructor() {
5
+ super();
6
+ const shadow = this.attachShadow({ mode: "open" });
7
+ const style = document.createElement("style");
8
+ style.textContent = `
9
+ :host {
10
+ display: block;
11
+ position: relative;
12
+ overflow: hidden;
13
+ }
14
+ .indicator {
15
+ position: absolute;
16
+ top: 0;
17
+ left: 0;
18
+ bottom: 0;
19
+ width: var(--_percent, 0%);
20
+ background: var(--progress-indicator-bg);
21
+ border-radius: 0;
22
+ transition: width 0.2s ease;
23
+ }
24
+ .indicator::after {
25
+ content: '';
26
+ position: absolute;
27
+ top: 0;
28
+ right: 0;
29
+ bottom: 0;
30
+ width: 90px;
31
+ background: var(--progress-indicator-edge);
32
+ }
33
+ slot {
34
+ display: block;
35
+ position: relative;
36
+ }
37
+ `;
38
+ this.indicator = document.createElement("div");
39
+ this.indicator.className = "indicator";
40
+ const slot = document.createElement("slot");
41
+ shadow.append(style, this.indicator, slot);
42
+ }
43
+ connectedCallback() {
44
+ this.update();
45
+ }
46
+ attributeChangedCallback() {
47
+ this.update();
48
+ }
49
+ update() {
50
+ const value = Number(this.getAttribute("value") ?? 0);
51
+ const max = Number(this.getAttribute("max") ?? 100);
52
+ const percent = max > 0 ? Math.min(100, Math.max(0, value / max * 100)) : 0;
53
+ this.indicator.style.setProperty("--_percent", `${percent}%`);
54
+ }
55
+ }
56
+ function register_a_progress() {
57
+ if (!customElements.get("a-progress")) {
58
+ customElements.define("a-progress", AProgressElement);
59
+ }
60
+ }
61
+ export {
62
+ AProgressElement,
63
+ register_a_progress
64
+ };
@@ -0,0 +1,2 @@
1
+ import './a-progress.css';
2
+ export { AProgressElement, register_a_progress } from './a-progress';
@@ -0,0 +1,10 @@
1
+ import { register_a_progress } from "./a-progress";
2
+ import "./a-progress.css";
3
+ import { AProgressElement, register_a_progress as register_a_progress2 } from "./a-progress";
4
+ if (typeof customElements !== "undefined") {
5
+ register_a_progress();
6
+ }
7
+ export {
8
+ AProgressElement,
9
+ register_a_progress2 as register_a_progress
10
+ };
@@ -0,0 +1,16 @@
1
+ export interface BaseProps {
2
+ className?: string;
3
+ style?: React.CSSProperties;
4
+ children?: React.ReactNode;
5
+ }
6
+ export interface BaseAttributes {
7
+ class?: string;
8
+ className?: string;
9
+ style?: React.CSSProperties;
10
+ children?: React.ReactNode;
11
+ }
12
+ export interface AProgressAttributes extends BaseAttributes {
13
+ value?: number | string;
14
+ max?: number | string;
15
+ tone?: 'neutral' | 'info';
16
+ }
File without changes
@@ -0,0 +1,2 @@
1
+ export { Progress } from './components/Progress';
2
+ export { configure } from './jsx-runtime';
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { Progress } from "./components/Progress";
2
+ import { configure } from "./jsx-runtime";
3
+ export {
4
+ Progress,
5
+ configure
6
+ };
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ type ComponentType = string | Function | symbol;
3
+ type JsxFunction = {
4
+ h(type: ComponentType, props: Record<string, unknown> | null, ...children: unknown[]): unknown;
5
+ }['h'];
6
+ declare let _Fragment: ComponentType;
7
+ export declare function configure(jsx: JsxFunction, Fragment?: ComponentType): void;
8
+ export declare function jsx(type: ComponentType, props: Record<string, unknown> | null, key?: string | number): unknown;
9
+ export declare function jsxs(type: ComponentType, props: Record<string, unknown> | null, key?: string | number): unknown;
10
+ export { _Fragment as Fragment };
11
+ import type { AProgressAttributes, BaseAttributes } from './general_types';
12
+ export declare namespace JSX {
13
+ type IntrinsicElements = React.JSX.IntrinsicElements & {
14
+ 'a-progress': AProgressAttributes;
15
+ 'a-progress-label': BaseAttributes;
16
+ 'a-progress-number': BaseAttributes;
17
+ 'a-progress-text': BaseAttributes;
18
+ 'a-progress-hint': BaseAttributes;
19
+ };
20
+ }
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ let _jsx = React.createElement;
3
+ let _Fragment = React.Fragment;
4
+ function configure(jsx2, Fragment) {
5
+ _jsx = jsx2;
6
+ if (Fragment !== void 0) _Fragment = Fragment;
7
+ }
8
+ function jsx(type, props, key) {
9
+ const { children, ...rest } = props ?? {};
10
+ const p = key !== void 0 ? { ...rest, key } : rest;
11
+ if (children !== void 0) {
12
+ return _jsx(type, p, children);
13
+ }
14
+ return _jsx(type, p);
15
+ }
16
+ function jsxs(type, props, key) {
17
+ const { children, ...rest } = props ?? {};
18
+ const p = key !== void 0 ? { ...rest, key } : rest;
19
+ if (children !== void 0) {
20
+ return _jsx(type, p, ...children);
21
+ }
22
+ return _jsx(type, p);
23
+ }
24
+ export {
25
+ _Fragment as Fragment,
26
+ configure,
27
+ jsx,
28
+ jsxs
29
+ };
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@antadesign/anta",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": ["dist"],
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./elements": {
14
+ "types": "./dist/elements/index.d.ts",
15
+ "default": "./dist/elements/index.js"
16
+ },
17
+ "./*": {
18
+ "types": "./dist/*.d.ts",
19
+ "default": "./dist/*"
20
+ }
21
+ },
22
+ "scripts": {
23
+ "build": "pnpm run build:js && pnpm run build:types",
24
+ "build:js": "esbuild src/components/Progress.tsx src/index.ts src/jsx-runtime.ts src/general_types.ts src/anta_helpers.ts src/elements/index.ts src/elements/a-progress.ts --outdir=dist --outbase=src --jsx=automatic --jsx-import-source=@antadesign/anta --format=esm --target=ES2022 --loader:.module.css=local-css --loader:.css=global-css",
25
+ "build:types": "tsc -p src/tsconfig.json",
26
+ "typecheck": "tsc --noEmit -p src/tsconfig.json",
27
+ "clean": "rm -rf dist"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^19.0.0",
31
+ "esbuild": "^0.25.0",
32
+ "typescript": "^5.7.0"
33
+ },
34
+ "dependencies": {
35
+ "classnames": "^2.5.0"
36
+ },
37
+ "peerDependencies": {
38
+ "react": "^18.0.0 || ^19.0.0"
39
+ },
40
+ "pnpm": {
41
+ "onlyBuiltDependencies": [
42
+ "esbuild",
43
+ "sharp"
44
+ ]
45
+ }
46
+ }