@pindoba/core-button 0.0.0-alpha-20260320034942

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,12 @@
1
+ Copyright 2025 Eduardo Lopes
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
8
+ INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
9
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
10
+ FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
11
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
12
+ DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ import { ButtonApi, ButtonBackground, ButtonBaseCommon, ButtonBaseProps, ButtonEmphasis, ButtonFeedback, ButtonPassThrough, ButtonRootProps, ButtonShape, ButtonSize, ButtonSlotPassThrough, ConnectButtonOptions, ElementAttributes, PanelBackground, PanelBorder, PanelEmphasis } from "./src/types.js";
2
+ import { connectButton } from "./src/connect-button.js";
3
+ export { type ButtonApi, type ButtonBackground, type ButtonBaseCommon, type ButtonBaseProps, type ButtonEmphasis, type ButtonFeedback, type ButtonPassThrough, type ButtonRootProps, type ButtonShape, type ButtonSize, type ButtonSlotPassThrough, type ConnectButtonOptions, type ElementAttributes, type PanelBackground, type PanelBorder, type PanelEmphasis, connectButton };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { connectButton } from "./src/connect-button.js";
2
+ export { connectButton };
@@ -0,0 +1,12 @@
1
+ import { ButtonApi, ConnectButtonOptions } from "./types.js";
2
+
3
+ //#region src/connect-button.d.ts
4
+ declare const buttonDefaults: {
5
+ readonly emphasis: "primary";
6
+ readonly size: "md";
7
+ readonly svgFit: true;
8
+ };
9
+ declare function connectButton(options: ConnectButtonOptions): ButtonApi;
10
+ //#endregion
11
+ export { buttonDefaults, connectButton };
12
+ //# sourceMappingURL=connect-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-button.d.ts","names":[],"sources":["../../src/connect-button.ts"],"mappings":";;;cAaa,cAAA;EAAA;;;;iBA0BG,aAAA,CAAc,OAAA,EAAS,oBAAA,GAAuB,SAAA"}
@@ -0,0 +1,79 @@
1
+ import { css } from "@pindoba/styled-system/css";
2
+ import { buttonStyles } from "@pindoba/styles-button";
3
+ import { panelStyles } from "@pindoba/styles-panel";
4
+ //#region src/connect-button.ts
5
+ const buttonDefaults = {
6
+ emphasis: "primary",
7
+ size: "md",
8
+ svgFit: true
9
+ };
10
+ function isNil(value) {
11
+ return value === null || value === void 0;
12
+ }
13
+ /**
14
+ * Maps button feedback values to panel feedback values.
15
+ * Button's "default" maps to panel's "primary" (both set colorPalette: "primary").
16
+ * Other values are shared 1:1.
17
+ */
18
+ function mapFeedbackToPanel(feedback, emphasis) {
19
+ if (isNil(feedback) && emphasis === "primary") return "primary";
20
+ if (isNil(feedback) && emphasis === "secondary") return "neutral";
21
+ return feedback;
22
+ }
23
+ function connectButton(options) {
24
+ const { emphasis = buttonDefaults.emphasis, size = buttonDefaults.size, shape, svgFit = buttonDefaults.svgFit, feedback: feedbackProp, background, border, translucent, accent, radius, radiusTop, radiusBottom, radiusLeft, radiusRight, passThrough, class: className, ...restProps } = options;
25
+ const feedback = feedbackProp ?? (emphasis === "primary" ? "primary" : "neutral");
26
+ const resolvedBackground = background ?? (emphasis === "ghost" ? "transparent" : "surface");
27
+ const resolvedAccent = accent ?? emphasis === "primary";
28
+ const panelEmphasis = emphasis === "ghost" ? void 0 : emphasis;
29
+ const panelFeedback = mapFeedbackToPanel(feedback, panelEmphasis);
30
+ const { display: _display, flexDirection: _flexDir, width: _width, transition: _transition, borderRadius: _borderRadius, borderTopLeftRadius: _btlr, borderTopRightRadius: _btrr, borderBottomLeftRadius: _bblr, borderBottomRightRadius: _bbrr, ...panelBase } = panelStyles.raw({
31
+ emphasis: panelEmphasis,
32
+ background: resolvedBackground,
33
+ accent: resolvedAccent,
34
+ feedback: panelFeedback,
35
+ border: border ?? "default",
36
+ translucent: translucent ?? false,
37
+ radius: "none",
38
+ padding: "none",
39
+ interactive: true
40
+ }).root ?? {};
41
+ const buttonClasses = buttonStyles.raw({
42
+ emphasis,
43
+ shape,
44
+ size,
45
+ feedback,
46
+ svgFit
47
+ });
48
+ const radiusStyles = {
49
+ ...radius !== void 0 ? { borderRadius: radius } : {},
50
+ ...radiusTop !== void 0 ? {
51
+ borderTopLeftRadius: radiusTop,
52
+ borderTopRightRadius: radiusTop
53
+ } : {},
54
+ ...radiusBottom !== void 0 ? {
55
+ borderBottomLeftRadius: radiusBottom,
56
+ borderBottomRightRadius: radiusBottom
57
+ } : {},
58
+ ...radiusLeft !== void 0 ? {
59
+ borderTopLeftRadius: radiusLeft,
60
+ borderBottomLeftRadius: radiusLeft
61
+ } : {},
62
+ ...radiusRight !== void 0 ? {
63
+ borderTopRightRadius: radiusRight,
64
+ borderBottomRightRadius: radiusRight
65
+ } : {}
66
+ };
67
+ const generatedClass = css(panelBase, buttonClasses.root, radiusStyles, passThrough?.root?.style);
68
+ const userClass = className != null ? String(className) : void 0;
69
+ return { rootProps: {
70
+ ...restProps,
71
+ ...passThrough?.root?.props,
72
+ "data-component": "button",
73
+ class: userClass ? `${generatedClass} ${userClass}` : generatedClass
74
+ } };
75
+ }
76
+ //#endregion
77
+ export { buttonDefaults, connectButton };
78
+
79
+ //# sourceMappingURL=connect-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-button.js","names":[],"sources":["../../src/connect-button.ts"],"sourcesContent":["import { css } from \"@pindoba/styled-system/css\";\nimport type { SystemStyleObject } from \"@pindoba/styled-system/types\";\nimport { buttonStyles } from \"@pindoba/styles-button\";\nimport { panelStyles } from \"@pindoba/styles-panel\";\nimport type { PanelBackground, PanelEmphasis } from \"@pindoba/core-panel\";\nimport type {\n ConnectButtonOptions,\n ButtonRootProps,\n ButtonApi,\n ButtonFeedback,\n ButtonBaseProps,\n} from \"./types.js\";\n\nexport const buttonDefaults = {\n emphasis: \"primary\",\n size: \"md\",\n svgFit: true,\n} as const satisfies Partial<ButtonBaseProps>;\n\n// check if a value is null or undefined\nfunction isNil(value: unknown) {\n return value === null || value === undefined;\n}\n\n/**\n * Maps button feedback values to panel feedback values.\n * Button's \"default\" maps to panel's \"primary\" (both set colorPalette: \"primary\").\n * Other values are shared 1:1.\n */\nfunction mapFeedbackToPanel(\n feedback: ButtonFeedback,\n emphasis?: PanelEmphasis,\n) {\n if (isNil(feedback) && emphasis === \"primary\") return \"primary\";\n if (isNil(feedback) && emphasis === \"secondary\") return \"neutral\";\n\n return feedback;\n}\n\nexport function connectButton(options: ConnectButtonOptions): ButtonApi {\n const {\n // Button-own props\n emphasis = buttonDefaults.emphasis,\n size = buttonDefaults.size,\n shape,\n svgFit = buttonDefaults.svgFit,\n feedback: feedbackProp,\n\n // Panel surface props\n background,\n border,\n translucent,\n accent,\n\n // Panel radius props\n radius,\n radiusTop,\n radiusBottom,\n radiusLeft,\n radiusRight,\n\n passThrough,\n class: className,\n ...restProps\n } = options;\n\n // Resolve feedback based on emphasis when not explicitly set.\n // primary defaults to \"default\" (→ \"primary\"); secondary/ghost default to \"neutral\".\n const feedback =\n feedbackProp ?? (emphasis === \"primary\" ? \"primary\" : \"neutral\");\n\n // Derive panel config from emphasis — user props always win\n const resolvedBackground: PanelBackground =\n background ?? (emphasis === \"ghost\" ? \"transparent\" : \"surface\");\n const resolvedAccent = accent ?? emphasis === \"primary\";\n\n // Forward panel emphasis for \"primary\"/\"secondary\"; \"ghost\" uses background=\"transparent\" instead.\n const panelEmphasis: PanelEmphasis | undefined =\n emphasis === \"ghost\" ? undefined : (emphasis as PanelEmphasis);\n const panelFeedback = mapFeedbackToPanel(feedback, panelEmphasis);\n\n // Panel is always the base — handles all background/color/border/shadow/hover\n const panelClasses = panelStyles.raw({\n emphasis: panelEmphasis,\n background: resolvedBackground,\n accent: resolvedAccent,\n feedback: panelFeedback,\n border: border ?? \"default\",\n translucent: translucent ?? false,\n radius: \"none\", // suppress panel default; radius handled separately\n padding: \"none\",\n interactive: true, // panel provides hover/active background transitions\n });\n\n // Strip panel layout props + borderRadius (button's sizing pattern owns these)\n const {\n display: _display,\n flexDirection: _flexDir,\n width: _width,\n transition: _transition,\n borderRadius: _borderRadius,\n borderTopLeftRadius: _btlr,\n borderTopRightRadius: _btrr,\n borderBottomLeftRadius: _bblr,\n borderBottomRightRadius: _bbrr,\n ...panelBase\n } = panelClasses.root ?? {};\n\n // Button styles: sizing, shape, boxShadow ring borders, focus, disabled\n const buttonClasses = buttonStyles.raw({\n emphasis,\n shape,\n size,\n feedback,\n svgFit,\n });\n\n // User-explicit radius only — overrides sizing-pattern borderRadius when set\n const radiusStyles: SystemStyleObject = {\n ...(radius !== undefined ? { borderRadius: radius } : {}),\n ...(radiusTop !== undefined\n ? { borderTopLeftRadius: radiusTop, borderTopRightRadius: radiusTop }\n : {}),\n ...(radiusBottom !== undefined\n ? {\n borderBottomLeftRadius: radiusBottom,\n borderBottomRightRadius: radiusBottom,\n }\n : {}),\n ...(radiusLeft !== undefined\n ? { borderTopLeftRadius: radiusLeft, borderBottomLeftRadius: radiusLeft }\n : {}),\n ...(radiusRight !== undefined\n ? {\n borderTopRightRadius: radiusRight,\n borderBottomRightRadius: radiusRight,\n }\n : {}),\n };\n\n // Merge: panel surface → button (layout/sizing/rings) → radius → passThrough\n const generatedClass = css(\n panelBase,\n buttonClasses.root,\n radiusStyles,\n passThrough?.root?.style,\n );\n\n const userClass = className != null ? String(className) : undefined;\n\n const rootProps: ButtonRootProps = {\n ...restProps,\n ...passThrough?.root?.props,\n \"data-component\": \"button\",\n class: userClass ? `${generatedClass} ${userClass}` : generatedClass,\n };\n\n return { rootProps };\n}\n"],"mappings":";;;;AAaA,MAAa,iBAAiB;CAC5B,UAAU;CACV,MAAM;CACN,QAAQ;CACT;AAGD,SAAS,MAAM,OAAgB;AAC7B,QAAO,UAAU,QAAQ,UAAU,KAAA;;;;;;;AAQrC,SAAS,mBACP,UACA,UACA;AACA,KAAI,MAAM,SAAS,IAAI,aAAa,UAAW,QAAO;AACtD,KAAI,MAAM,SAAS,IAAI,aAAa,YAAa,QAAO;AAExD,QAAO;;AAGT,SAAgB,cAAc,SAA0C;CACtE,MAAM,EAEJ,WAAW,eAAe,UAC1B,OAAO,eAAe,MACtB,OACA,SAAS,eAAe,QACxB,UAAU,cAGV,YACA,QACA,aACA,QAGA,QACA,WACA,cACA,YACA,aAEA,aACA,OAAO,WACP,GAAG,cACD;CAIJ,MAAM,WACJ,iBAAiB,aAAa,YAAY,YAAY;CAGxD,MAAM,qBACJ,eAAe,aAAa,UAAU,gBAAgB;CACxD,MAAM,iBAAiB,UAAU,aAAa;CAG9C,MAAM,gBACJ,aAAa,UAAU,KAAA,IAAa;CACtC,MAAM,gBAAgB,mBAAmB,UAAU,cAAc;CAgBjE,MAAM,EACJ,SAAS,UACT,eAAe,UACf,OAAO,QACP,YAAY,aACZ,cAAc,eACd,qBAAqB,OACrB,sBAAsB,OACtB,wBAAwB,OACxB,yBAAyB,OACzB,GAAG,cAvBgB,YAAY,IAAI;EACnC,UAAU;EACV,YAAY;EACZ,QAAQ;EACR,UAAU;EACV,QAAQ,UAAU;EAClB,aAAa,eAAe;EAC5B,QAAQ;EACR,SAAS;EACT,aAAa;EACd,CAAC,CAce,QAAQ,EAAE;CAG3B,MAAM,gBAAgB,aAAa,IAAI;EACrC;EACA;EACA;EACA;EACA;EACD,CAAC;CAGF,MAAM,eAAkC;EACtC,GAAI,WAAW,KAAA,IAAY,EAAE,cAAc,QAAQ,GAAG,EAAE;EACxD,GAAI,cAAc,KAAA,IACd;GAAE,qBAAqB;GAAW,sBAAsB;GAAW,GACnE,EAAE;EACN,GAAI,iBAAiB,KAAA,IACjB;GACE,wBAAwB;GACxB,yBAAyB;GAC1B,GACD,EAAE;EACN,GAAI,eAAe,KAAA,IACf;GAAE,qBAAqB;GAAY,wBAAwB;GAAY,GACvE,EAAE;EACN,GAAI,gBAAgB,KAAA,IAChB;GACE,sBAAsB;GACtB,yBAAyB;GAC1B,GACD,EAAE;EACP;CAGD,MAAM,iBAAiB,IACrB,WACA,cAAc,MACd,cACA,aAAa,MAAM,MACpB;CAED,MAAM,YAAY,aAAa,OAAO,OAAO,UAAU,GAAG,KAAA;AAS1D,QAAO,EAAE,WAP0B;EACjC,GAAG;EACH,GAAG,aAAa,MAAM;EACtB,kBAAkB;EAClB,OAAO,YAAY,GAAG,eAAe,GAAG,cAAc;EACvD,EAEmB"}
@@ -0,0 +1,74 @@
1
+ import { ButtonStyleProps } from "@pindoba/styles-button";
2
+ import { PanelStyleProps } from "@pindoba/styles-panel";
3
+ import { SystemStyleObject } from "@pindoba/styled-system/types";
4
+ import { PanelBackground, PanelBorder, PanelEmphasis, PanelEmphasis as PanelEmphasis$1, PanelRadius, PanelRadiusBottom, PanelRadiusLeft, PanelRadiusRight, PanelRadiusTop } from "@pindoba/core-panel";
5
+
6
+ //#region src/types.d.ts
7
+ type ElementAttributes = Partial<Record<string, unknown>>;
8
+ /** Button emphasis — aligned with panel emphasis vocabulary, extended with `"ghost"`. */
9
+ type ButtonEmphasis = PanelEmphasis$1 | "ghost";
10
+ type ButtonFeedback = NonNullable<ButtonStyleProps["feedback"]>;
11
+ type ButtonShape = NonNullable<ButtonStyleProps["shape"]>;
12
+ type ButtonSize = NonNullable<ButtonStyleProps["size"]>;
13
+ /** Background values accepted by the button (panel backgrounds, `emphasis="secondary"` only). */
14
+ type ButtonBackground = PanelStyleProps["background"];
15
+ interface ButtonSlotPassThrough<T = ElementAttributes> {
16
+ style?: SystemStyleObject;
17
+ props?: T;
18
+ }
19
+ interface ButtonPassThrough<RootElementAttributes = ElementAttributes> {
20
+ root?: ButtonSlotPassThrough<RootElementAttributes>;
21
+ }
22
+ type ButtonBaseCommon<RootElementAttributes = ElementAttributes> = {
23
+ feedback?: ButtonStyleProps["feedback"];
24
+ shape?: ButtonStyleProps["shape"];
25
+ size?: ButtonStyleProps["size"];
26
+ svgFit?: boolean;
27
+ border?: PanelStyleProps["border"];
28
+ translucent?: PanelStyleProps["translucent"];
29
+ radius?: PanelStyleProps["radius"];
30
+ radiusTop?: PanelStyleProps["radiusTop"];
31
+ radiusBottom?: PanelStyleProps["radiusBottom"];
32
+ radiusLeft?: PanelStyleProps["radiusLeft"];
33
+ radiusRight?: PanelStyleProps["radiusRight"];
34
+ passThrough?: ButtonPassThrough<RootElementAttributes>;
35
+ };
36
+ /**
37
+ * Base button props shared across all frameworks (Svelte, React, Astro).
38
+ * Each framework extends this with its own additions.
39
+ *
40
+ * `background` is only allowed when `emphasis="secondary"`.
41
+ */
42
+ type ButtonBaseProps<RootElementAttributes = ElementAttributes> = ButtonBaseCommon<RootElementAttributes> & ({
43
+ emphasis: "secondary";
44
+ background?: ButtonBackground;
45
+ accent?: boolean;
46
+ } | {
47
+ emphasis?: Exclude<ButtonEmphasis, "secondary">;
48
+ background?: never;
49
+ accent?: boolean;
50
+ });
51
+ /**
52
+ * Options for connectButton. Framework components can spread their props
53
+ * directly into this function.
54
+ *
55
+ * This is intentionally flat (no discriminated union) — the emphasis/background
56
+ * constraint is enforced at the component level, not inside connectButton.
57
+ */
58
+ type ConnectButtonOptions = Partial<ButtonBaseCommon<ElementAttributes>> & {
59
+ emphasis?: ButtonEmphasis;
60
+ background?: ButtonBackground;
61
+ accent?: boolean;
62
+ class?: unknown;
63
+ };
64
+ interface ButtonRootProps {
65
+ class: string;
66
+ "data-component": "button";
67
+ [key: string]: unknown;
68
+ }
69
+ interface ButtonApi {
70
+ rootProps: ButtonRootProps;
71
+ }
72
+ //#endregion
73
+ export { ButtonApi, ButtonBackground, ButtonBaseCommon, ButtonBaseProps, ButtonEmphasis, ButtonFeedback, ButtonPassThrough, ButtonRootProps, ButtonShape, ButtonSize, ButtonSlotPassThrough, ConnectButtonOptions, ElementAttributes, type PanelBackground, type PanelBorder, type PanelEmphasis, type PanelRadius, type PanelRadiusBottom, type PanelRadiusLeft, type PanelRadiusRight, type PanelRadiusTop };
74
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/types.ts"],"mappings":";;;;;;KAkBY,iBAAA,GAAoB,OAAA,CAAQ,MAAA;AAAxC;AAAA,KAKY,cAAA,GAAiB,eAAA;AAAA,KACjB,cAAA,GAAiB,WAAA,CAAY,gBAAA;AAAA,KAC7B,WAAA,GAAc,WAAA,CAAY,gBAAA;AAAA,KAC1B,UAAA,GAAa,WAAA,CAAY,gBAAA;AAHrC;AAAA,KAKY,gBAAA,GAAmB,eAAA;AAAA,UAId,qBAAA,KAA0B,iBAAA;EACzC,KAAA,GAAQ,iBAAA;EACR,KAAA,GAAQ,CAAA;AAAA;AAAA,UAGO,iBAAA,yBAA0C,iBAAA;EACzD,IAAA,GAAO,qBAAA,CAAsB,qBAAA;AAAA;AAAA,KAKnB,gBAAA,yBAAyC,iBAAA;EAEnD,QAAA,GAAW,gBAAA;EACX,KAAA,GAAQ,gBAAA;EACR,IAAA,GAAO,gBAAA;EACP,MAAA;EAGA,MAAA,GAAS,eAAA;EACT,WAAA,GAAc,eAAA;EAGd,MAAA,GAAS,eAAA;EACT,SAAA,GAAY,eAAA;EACZ,YAAA,GAAe,eAAA;EACf,UAAA,GAAa,eAAA;EACb,WAAA,GAAc,eAAA;EAEd,WAAA,GAAc,iBAAA,CAAkB,qBAAA;AAAA;;;AA7BlC;;;;KAsCY,eAAA,yBAAwC,iBAAA,IAClD,gBAAA,CAAiB,qBAAA;EAGT,QAAA;EACA,UAAA,GAAa,gBAAA;EACb,MAAA;AAAA;EAGA,QAAA,GAAW,OAAA,CAAQ,cAAA;EACnB,UAAA;EACA,MAAA;AAAA;;;;AA5CV;;;;KAyDY,oBAAA,GAAuB,OAAA,CACjC,gBAAA,CAAiB,iBAAA;EAEjB,QAAA,GAAW,cAAA;EACX,UAAA,GAAa,gBAAA;EACb,MAAA;EACA,KAAA;AAAA;AAAA,UAGe,eAAA;EACf,KAAA;EACA,gBAAA;EAAA,CACC,GAAA;AAAA;AAAA,UAGc,SAAA;EACf,SAAA,EAAW,eAAA;AAAA"}
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@pindoba/core-button",
3
+ "version": "0.0.0-alpha-20260320034942",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "sideEffects": false,
7
+ "main": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./*": {
15
+ "types": "./dist/src/*.d.ts",
16
+ "import": "./dist/src/*.js"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "dependencies": {
23
+ "@pindoba/core-panel": "0.0.0-alpha-20260320034942",
24
+ "@pindoba/styles-panel": "0.0.0-alpha-20260320034942",
25
+ "@pindoba/styled-system": "0.0.0-alpha-20260320034942",
26
+ "@pindoba/styles-button": "0.0.0-alpha-20260320034942"
27
+ },
28
+ "devDependencies": {
29
+ "typescript": "^5.9.3",
30
+ "tsdown": "^0.21.2"
31
+ },
32
+ "scripts": {
33
+ "build": "tsdown",
34
+ "dev": "tsdown --watch",
35
+ "clean": "rm -rf dist && rm -rf node_modules && rm -rf .turbo"
36
+ }
37
+ }