@gridui/number-field 0.0.0-stage → 1.0.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 CHANGED
@@ -1,3 +1,8 @@
1
- # Temporary Holding Version
1
+ # @gridui/number-field
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Core family. Public API: `NumberField`, `NumberFieldProps`.
4
+
5
+ Import components from `@gridui/number-field` and load `@gridui/number-field/styles.css` after Theme.
6
+ Load styles for any composed dependency used by this family. Applications own routes, labels, state persistence, and branding.
7
+
8
+ See [component ownership](../../docs/component-ownership.md) and [release history](.changeset/history/).
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Number Field
4
+ * @namespace Root
5
+ * @description Index
6
+ */
7
+ export type { NumberFieldProps } from "./number-field/number-field";
8
+ export { NumberField } from "./number-field/number-field";
package/dist/index.js ADDED
@@ -0,0 +1,153 @@
1
+ // src/number-field/number-field.tsx
2
+ import { Button } from "@gridui/button";
3
+ import { controlVariants } from "@gridui/input";
4
+ import { cn } from "@gridui/style-utils";
5
+ import { Minus, Plus } from "lucide-react";
6
+ import { useEffect, useImperativeHandle, useRef, useState } from "react";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ var NumberField = (props) => {
9
+ const {
10
+ value,
11
+ defaultValue = null,
12
+ min,
13
+ max,
14
+ step = 1,
15
+ controlSize = "standard",
16
+ incrementLabel,
17
+ decrementLabel,
18
+ onValueChange,
19
+ onChange,
20
+ className,
21
+ ref,
22
+ ...restProps
23
+ } = props;
24
+ if (!Number.isFinite(step) || step <= 0 || min !== void 0 && !Number.isFinite(min) || max !== void 0 && !Number.isFinite(max) || min !== void 0 && max !== void 0 && min > max || value !== void 0 && value !== null && !Number.isFinite(value) || defaultValue !== null && !Number.isFinite(defaultValue)) {
25
+ throw new RangeError("NumberField requires finite values and bounds, an ordered range, and a positive step.");
26
+ }
27
+ const [
28
+ local,
29
+ setLocal
30
+ ] = useState(defaultValue);
31
+ const input = useRef(null);
32
+ const initial = useRef(defaultValue);
33
+ const current = value === void 0 ? local : value;
34
+ useImperativeHandle(ref, () => {
35
+ return input.current;
36
+ });
37
+ useEffect(() => {
38
+ const form = input.current?.form;
39
+ if (!form || value !== void 0) {
40
+ return;
41
+ }
42
+ let mounted = true;
43
+ const reset = (event) => {
44
+ setTimeout(() => {
45
+ if (mounted && !event.defaultPrevented) {
46
+ setLocal(initial.current);
47
+ }
48
+ }, 0);
49
+ };
50
+ form.addEventListener("reset", reset);
51
+ return () => {
52
+ mounted = false;
53
+ form.removeEventListener("reset", reset);
54
+ };
55
+ }, [
56
+ restProps.form,
57
+ value
58
+ ]);
59
+ const change = (next) => {
60
+ if (restProps.readOnly || restProps.disabled || input.current?.matches(":disabled")) {
61
+ return;
62
+ }
63
+ if (value === void 0) {
64
+ setLocal(next);
65
+ }
66
+ if (next !== current) {
67
+ onValueChange?.(next);
68
+ }
69
+ };
70
+ const move = (direction) => {
71
+ const element = input.current;
72
+ if (!element || restProps.readOnly || element.matches(":disabled")) {
73
+ return;
74
+ }
75
+ element.stepUp(direction);
76
+ const next = element.valueAsNumber;
77
+ change(Number.isFinite(next) ? next : null);
78
+ if (value !== void 0) {
79
+ element.value = current === null ? "" : String(current);
80
+ }
81
+ element.focus();
82
+ };
83
+ return /* @__PURE__ */ jsxs(
84
+ "div",
85
+ {
86
+ className: "flex min-w-0 items-stretch gap-gridui-4",
87
+ dir: restProps.dir,
88
+ children: [
89
+ /* @__PURE__ */ jsx(
90
+ Button,
91
+ {
92
+ variant: "secondary",
93
+ layout: "icon",
94
+ size: controlSize,
95
+ "aria-label": decrementLabel,
96
+ disabled: restProps.disabled || restProps.readOnly || current !== null && min !== void 0 && current <= min,
97
+ onClick: () => {
98
+ move(-1);
99
+ },
100
+ children: /* @__PURE__ */ jsx(
101
+ Minus,
102
+ {
103
+ "aria-hidden": "true"
104
+ }
105
+ )
106
+ }
107
+ ),
108
+ /* @__PURE__ */ jsx(
109
+ "input",
110
+ {
111
+ ...restProps,
112
+ ref: input,
113
+ type: "number",
114
+ min,
115
+ max,
116
+ step,
117
+ value: current ?? "",
118
+ className: cn(controlVariants({ size: controlSize }), "gridui-number-field flex-1", className),
119
+ onChange: (event) => {
120
+ onChange?.(event);
121
+ if (!event.defaultPrevented) {
122
+ change(Number.isFinite(event.currentTarget.valueAsNumber) ? event.currentTarget.valueAsNumber : null);
123
+ }
124
+ }
125
+ }
126
+ ),
127
+ /* @__PURE__ */ jsx(
128
+ Button,
129
+ {
130
+ variant: "secondary",
131
+ layout: "icon",
132
+ size: controlSize,
133
+ "aria-label": incrementLabel,
134
+ disabled: restProps.disabled || restProps.readOnly || current !== null && max !== void 0 && current >= max,
135
+ onClick: () => {
136
+ move(1);
137
+ },
138
+ children: /* @__PURE__ */ jsx(
139
+ Plus,
140
+ {
141
+ "aria-hidden": "true"
142
+ }
143
+ )
144
+ }
145
+ )
146
+ ]
147
+ }
148
+ );
149
+ };
150
+ export {
151
+ NumberField
152
+ };
153
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/number-field/number-field.tsx"],
4
+ "sourcesContent": ["/**\n * @author WMXPY\n * @package Number Field\n * @namespace NumberField\n * @description Number Field\n */\n\nimport { Button } from \"@gridui/button\";\nimport { controlVariants } from \"@gridui/input\";\nimport { cn } from \"@gridui/style-utils\";\nimport { Minus, Plus } from \"lucide-react\";\nimport { type ComponentPropsWithRef, type FC, useEffect, useImperativeHandle, useRef, useState } from \"react\";\n\nexport type NumberFieldProps = Omit<ComponentPropsWithRef<\"input\">, \"type\" | \"value\" | \"defaultValue\" | \"min\" | \"max\" | \"step\" | \"size\"> & {\n readonly value?: number | null;\n readonly defaultValue?: number | null;\n readonly min?: number;\n readonly max?: number;\n readonly step?: number;\n readonly controlSize?: \"standard\" | \"small\";\n readonly incrementLabel: string;\n readonly decrementLabel: string;\n readonly onValueChange?: (value: number | null) => void;\n};\n\nexport const NumberField: FC<NumberFieldProps> = (props: NumberFieldProps) => {\n const { value, defaultValue = null, min, max, step = 1, controlSize = \"standard\", incrementLabel, decrementLabel,\n onValueChange, onChange, className, ref, ...restProps } = props;\n if (!Number.isFinite(step) || step <= 0 || (min !== undefined && !Number.isFinite(min)) || (max !== undefined && !Number.isFinite(max))\n || (min !== undefined && max !== undefined && min > max)\n || (value !== undefined && value !== null && !Number.isFinite(value))\n || (defaultValue !== null && !Number.isFinite(defaultValue))) {\n throw new RangeError(\"NumberField requires finite values and bounds, an ordered range, and a positive step.\");\n }\n const [\n local,\n setLocal,\n ] = useState<number | null>(defaultValue);\n const input = useRef<HTMLInputElement>(null);\n const initial = useRef(defaultValue);\n const current = value === undefined ? local : value;\n useImperativeHandle(ref, () => {\n return input.current as HTMLInputElement;\n });\n useEffect(() => {\n const form = input.current?.form;\n if (!form || value !== undefined) {\n return;\n }\n let mounted = true;\n const reset = (event: Event) => {\n // Wait until React bubbling handlers can cancel the native reset.\n setTimeout(() => {\n if (mounted && !event.defaultPrevented) {\n setLocal(initial.current);\n }\n }, 0);\n };\n form.addEventListener(\"reset\", reset);\n return () => {\n mounted = false;\n form.removeEventListener(\"reset\", reset);\n };\n }, [\n restProps.form,\n value,\n ]);\n const change = (next: number | null) => {\n if (restProps.readOnly || restProps.disabled || input.current?.matches(\":disabled\")) {\n return;\n }\n if (value === undefined) {\n setLocal(next);\n }\n if (next !== current) {\n onValueChange?.(next);\n }\n };\n const move = (direction: number) => {\n const element = input.current;\n if (!element || restProps.readOnly || element.matches(\":disabled\")) {\n return;\n }\n element.stepUp(direction);\n const next = element.valueAsNumber;\n change(Number.isFinite(next) ? next : null);\n // A controlled consumer can reject the requested value.\n if (value !== undefined) {\n element.value = current === null ? \"\" : String(current);\n }\n element.focus();\n };\n return (<div\n className=\"flex min-w-0 items-stretch gap-gridui-4\"\n dir={restProps.dir}\n >\n <Button\n variant=\"secondary\"\n layout=\"icon\"\n size={controlSize}\n aria-label={decrementLabel}\n disabled={restProps.disabled || restProps.readOnly || (current !== null && min !== undefined && current <= min)}\n onClick={() => {\n move(-1);\n }}\n >\n <Minus\n aria-hidden=\"true\"\n />\n </Button>\n <input\n {...restProps}\n ref={input}\n type=\"number\"\n min={min}\n max={max}\n step={step}\n value={current ?? \"\"}\n className={cn(controlVariants({ size: controlSize }), \"gridui-number-field flex-1\", className)}\n onChange={(event) => {\n onChange?.(event);\n if (!event.defaultPrevented) {\n change(Number.isFinite(event.currentTarget.valueAsNumber) ? event.currentTarget.valueAsNumber : null);\n }\n }}\n />\n <Button\n variant=\"secondary\"\n layout=\"icon\"\n size={controlSize}\n aria-label={incrementLabel}\n disabled={restProps.disabled || restProps.readOnly || (current !== null && max !== undefined && current >= max)}\n onClick={() => {\n move(1);\n }}\n >\n <Plus\n aria-hidden=\"true\"\n />\n </Button>\n </div>);\n};\n"],
5
+ "mappings": ";AAOA,SAAS,cAAc;AACvB,SAAS,uBAAuB;AAChC,SAAS,UAAU;AACnB,SAAS,OAAO,YAAY;AAC5B,SAA8C,WAAW,qBAAqB,QAAQ,gBAAgB;AAiF1F,SAcA,KAdA;AAnEL,IAAM,cAAoC,CAAC,UAA4B;AAC1E,QAAM;AAAA,IAAE;AAAA,IAAO,eAAe;AAAA,IAAM;AAAA,IAAK;AAAA,IAAK,OAAO;AAAA,IAAG,cAAc;AAAA,IAAY;AAAA,IAAgB;AAAA,IAC9F;AAAA,IAAe;AAAA,IAAU;AAAA,IAAW;AAAA,IAAK,GAAG;AAAA,EAAU,IAAI;AAC9D,MAAI,CAAC,OAAO,SAAS,IAAI,KAAK,QAAQ,KAAM,QAAQ,UAAa,CAAC,OAAO,SAAS,GAAG,KAAO,QAAQ,UAAa,CAAC,OAAO,SAAS,GAAG,KAC7H,QAAQ,UAAa,QAAQ,UAAa,MAAM,OAChD,UAAU,UAAa,UAAU,QAAQ,CAAC,OAAO,SAAS,KAAK,KAC/D,iBAAiB,QAAQ,C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;AAAA;AAAA,EACJ;AACJ;",
6
+ "names": []
7
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @author WMXPY
3
+ * @package Number Field
4
+ * @namespace NumberField
5
+ * @description Number Field
6
+ */
7
+ import { type ComponentPropsWithRef, type FC } from "react";
8
+ export type NumberFieldProps = Omit<ComponentPropsWithRef<"input">, "type" | "value" | "defaultValue" | "min" | "max" | "step" | "size"> & {
9
+ readonly value?: number | null;
10
+ readonly defaultValue?: number | null;
11
+ readonly min?: number;
12
+ readonly max?: number;
13
+ readonly step?: number;
14
+ readonly controlSize?: "standard" | "small";
15
+ readonly incrementLabel: string;
16
+ readonly decrementLabel: string;
17
+ readonly onValueChange?: (value: number | null) => void;
18
+ };
19
+ export declare const NumberField: FC<NumberFieldProps>;
@@ -0,0 +1,28 @@
1
+ /*! tailwindcss v4.3.3 | MIT License | https://tailwindcss.com */
2
+ @layer theme, base, components, utilities;
3
+ @layer utilities {
4
+ .flex {
5
+ display: flex;
6
+ }
7
+ .min-w-0 {
8
+ min-width: 0px;
9
+ }
10
+ .flex-1 {
11
+ flex: 1;
12
+ }
13
+ .items-stretch {
14
+ align-items: stretch;
15
+ }
16
+ .gap-gridui-4 {
17
+ gap: var(--gridui-space-4);
18
+ }
19
+ }
20
+ @layer components {
21
+ .gridui-number-field {
22
+ appearance: textfield;
23
+ }
24
+ .gridui-number-field::-webkit-inner-spin-button, .gridui-number-field::-webkit-outer-spin-button {
25
+ margin: 0;
26
+ appearance: none;
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@gridui/number-field",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0",
4
+ "description": "GridUI React number field",
5
+ "license": "UNLICENSED",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "README.md"
10
+ ],
11
+ "sideEffects": [
12
+ "**/*.css"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "import": "./dist/index.js"
18
+ },
19
+ "./styles.css": "./dist/styles.css"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "peerDependencies": {
25
+ "react": "^19.2.0",
26
+ "react-dom": "^19.2.0"
27
+ },
28
+ "dependencies": {
29
+ "@gridui/button": "^2.1.1",
30
+ "@gridui/input": "^1.0.0",
31
+ "@gridui/style-utils": "^2.1.2",
32
+ "@gridui/theme": "^2.1.2",
33
+ "lucide-react": "1.62.0"
34
+ },
35
+ "devDependencies": {
36
+ "@gridui-internal/configuration": "0.0.0",
37
+ "@jest/globals": "30.5.2",
38
+ "@types/jest": "30.0.0",
39
+ "@types/node": "26.6.5",
40
+ "@types/react": "19.3.0",
41
+ "@types/react-dom": "19.3.0",
42
+ "jest": "30.5.2",
43
+ "react": "19.3.1",
44
+ "react-dom": "19.3.1",
45
+ "typescript": "6.0.3"
46
+ },
47
+ "scripts": {
48
+ "build": "node ../../scripts/compilation/package.ts",
49
+ "compile": "tsc --project tsconfig.json",
50
+ "test": "jest",
51
+ "coverage": "jest --coverage"
52
+ }
6
53
  }