@geckou/ui-react 0.3.0 → 0.5.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.
@@ -1,16 +1,18 @@
1
1
  "use client";
2
- import { jsxs as x, jsx as f } from "react/jsx-runtime";
2
+ import { jsxs as h, Fragment as m, jsx as f } from "react/jsx-runtime";
3
3
  import { COLOR as e } from "@geckou/ui-core";
4
- function m({
4
+ function y({
5
5
  name: l,
6
6
  label: n = { on: "ON", off: "OFF" },
7
- checked: b,
7
+ checked: p,
8
8
  onChange: d,
9
9
  isDisabled: o,
10
- cssStyle: r
10
+ cssStyle: a,
11
+ ariaLabel: g,
12
+ ariaLabelledBy: c
11
13
  }) {
12
- var c, u, s;
13
- const a = b ?? !1, p = Math.max(n.on.length, n.off.length), t = o ? r == null ? void 0 : r.disabled : r == null ? void 0 : r.default, i = {
14
+ var u, s, b;
15
+ const r = p ?? !1, x = Math.max(n.on.length, n.off.length), t = o ? a == null ? void 0 : a.disabled : a == null ? void 0 : a.default, i = {
14
16
  on: {
15
17
  textColor: o ? e.lightGray : e.white,
16
18
  backgroundColor: o ? e.gray : e.blue,
@@ -33,60 +35,55 @@ function m({
33
35
  boxShadow: "0 0 0 0 rgba(0, 0, 0, 0)",
34
36
  ...t == null ? void 0 : t.off
35
37
  }
36
- }[a ? "on" : "off"], h = {
38
+ }[r ? "on" : "off"], z = {
37
39
  "--text-color": i.textColor,
38
- "--border-color": (c = i.border) == null ? void 0 : c.color,
39
- "--border-size": (u = i.border) == null ? void 0 : u.size,
40
- "--radius-size": (s = i.border) == null ? void 0 : s.radius,
40
+ "--border-color": (u = i.border) == null ? void 0 : u.color,
41
+ "--border-size": (s = i.border) == null ? void 0 : s.size,
42
+ "--radius-size": (b = i.border) == null ? void 0 : b.radius,
41
43
  "--background-color": i.backgroundColor,
42
44
  "--box-shadow": i.boxShadow,
43
- "--inline-size": `${p * 2}ch`,
45
+ "--inline-size": `${x * 2}ch`,
44
46
  "--handle-size": "1.5rem",
45
47
  "--padding-size": "calc(var(--border-size) + 2px)",
46
48
  "--duration": ".15s"
47
49
  };
48
- return /* @__PURE__ */ x(
49
- "button",
50
- {
51
- type: "button",
52
- style: h,
53
- disabled: o,
54
- "aria-pressed": a,
55
- "aria-label": l,
56
- onClick: (g) => {
57
- g.stopPropagation(), o || d == null || d(!a);
58
- },
59
- className: "relative inline-block w-[calc(var(--inline-size)+var(--handle-size)+(var(--padding-size)*2))] cursor-pointer rounded-(--radius-size) border-none bg-(--background-color) p-(--padding-size) shadow-[0_0_0_var(--border-size)_var(--border-color)_inset,var(--box-shadow)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--border-color)",
60
- children: [
61
- /* @__PURE__ */ f(
62
- "input",
63
- {
64
- type: "checkbox",
65
- name: l,
66
- checked: a,
67
- disabled: o,
68
- readOnly: !0,
69
- className: "hidden"
70
- }
71
- ),
72
- /* @__PURE__ */ f(
73
- "div",
74
- {
75
- "data-on": n.on,
76
- "data-off": n.off,
77
- className: `absolute top-0 left-0 h-full w-full text-(--text-color) uppercase before:absolute before:right-0 before:m-auto before:inline-flex before:h-full before:w-[calc(100%-var(--handle-size)-var(--padding-size))] before:items-center before:justify-center before:leading-none before:transition-opacity before:duration-(--duration) before:ease-out before:content-[attr(data-off)] after:absolute after:left-0 after:m-auto after:inline-flex after:h-full after:w-[calc(100%-var(--handle-size)-var(--padding-size))] after:items-center after:justify-center after:leading-none after:transition-opacity after:duration-(--duration) after:ease-out after:content-[attr(data-on)] ${a ? "before:opacity-0 after:opacity-100" : "before:opacity-100 after:opacity-0"}`
78
- }
79
- ),
80
- /* @__PURE__ */ f(
81
- "div",
82
- {
83
- className: `relative m-0 aspect-square w-(--handle-size) rounded-[calc(var(--radius-size)-(var(--padding-size)/2))] bg-(--text-color) shadow-(--box-shadow) transition-[left] duration-(--duration) ease-out ${a ? "left-[calc(100%-var(--handle-size))]" : "left-0"}`
84
- }
85
- )
86
- ]
87
- }
88
- );
50
+ return /* @__PURE__ */ h(m, { children: [
51
+ /* @__PURE__ */ h(
52
+ "button",
53
+ {
54
+ type: "button",
55
+ style: z,
56
+ disabled: o,
57
+ role: "switch",
58
+ "aria-checked": r,
59
+ "data-checked": r,
60
+ "aria-labelledby": c,
61
+ "aria-label": c ? void 0 : g ?? l,
62
+ onClick: (v) => {
63
+ v.stopPropagation(), o || d == null || d(!r);
64
+ },
65
+ className: "relative inline-block w-[calc(var(--inline-size)+var(--handle-size)+(var(--padding-size)*2))] cursor-pointer rounded-(--radius-size) border-none bg-(--background-color) p-(--padding-size) shadow-[0_0_0_var(--border-size)_var(--border-color)_inset,var(--box-shadow)] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--border-color)",
66
+ children: [
67
+ /* @__PURE__ */ f(
68
+ "div",
69
+ {
70
+ "data-on": n.on,
71
+ "data-off": n.off,
72
+ className: `absolute top-0 left-0 h-full w-full text-(--text-color) uppercase before:absolute before:right-0 before:m-auto before:inline-flex before:h-full before:w-[calc(100%-var(--handle-size)-var(--padding-size))] before:items-center before:justify-center before:leading-none before:transition-opacity before:duration-(--duration) before:ease-out before:content-[attr(data-off)] after:absolute after:left-0 after:m-auto after:inline-flex after:h-full after:w-[calc(100%-var(--handle-size)-var(--padding-size))] after:items-center after:justify-center after:leading-none after:transition-opacity after:duration-(--duration) after:ease-out after:content-[attr(data-on)] ${r ? "before:opacity-0 after:opacity-100" : "before:opacity-100 after:opacity-0"}`
73
+ }
74
+ ),
75
+ /* @__PURE__ */ f(
76
+ "div",
77
+ {
78
+ className: `relative m-0 aspect-square w-(--handle-size) rounded-[calc(var(--radius-size)-(var(--padding-size)/2))] bg-(--text-color) shadow-(--box-shadow) transition-[left] duration-(--duration) ease-out ${r ? "left-[calc(100%-var(--handle-size))]" : "left-0"}`
79
+ }
80
+ )
81
+ ]
82
+ }
83
+ ),
84
+ r && /* @__PURE__ */ f("input", { type: "hidden", name: l, value: "on", disabled: o })
85
+ ] });
89
86
  }
90
87
  export {
91
- m as ToggleButton
88
+ y as ToggleButton
92
89
  };
package/package.json CHANGED
@@ -1,9 +1,11 @@
1
1
  {
2
2
  "name": "@geckou/ui-react",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "description": "A set of reusable React UI components (forms) by Geckou",
5
5
  "type": "module",
6
- "sideEffects": false,
6
+ "sideEffects": [
7
+ "**/*.css"
8
+ ],
7
9
  "main": "./dist/index.js",
8
10
  "types": "./dist/index.d.ts",
9
11
  "exports": {
@@ -38,16 +40,16 @@
38
40
  "react-dom": "^19.0.0"
39
41
  },
40
42
  "dependencies": {
41
- "@geckou/ui-core": "^0.2.0"
43
+ "@geckou/ui-core": "^0.4.0"
42
44
  },
43
45
  "scripts": {
44
46
  "build": "vite build && node scripts/copy-assets.mjs",
45
- "lint": "eslint src",
46
- "lint:fix": "eslint src --fix",
47
+ "lint": "eslint src tests",
48
+ "lint:fix": "eslint src tests --fix",
47
49
  "prepublishOnly": "yarn build",
48
50
  "test": "vitest run",
49
51
  "test:watch": "vitest",
50
- "type-check": "tsc --noEmit"
52
+ "type-check": "tsc --noEmit && tsc -p tsconfig.test.json"
51
53
  },
52
54
  "devDependencies": {
53
55
  "@types/react": "^19.0.0",