Skip to content

Commit 50242e8

Browse files
committed
not to return the style property when dinamic is not specified
1 parent cbf85b4 commit 50242e8

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/__tests__/windctrl.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ describe("windCtrl", () => {
88
base: "rounded px-4 py-2",
99
});
1010

11-
const result = button({});
11+
const result = button();
1212
expect(result.className).toContain("rounded");
1313
expect(result.className).toContain("px-4");
1414
expect(result.className).toContain("py-2");
15-
expect(result.style).toEqual({});
15+
expect(result.style).toEqual(undefined);
1616
});
1717

1818
it("should work without base classes", () => {
1919
const button = windCtrl({});
2020

2121
const result = button({});
2222
expect(result.className).toBe("");
23-
expect(result.style).toEqual({});
23+
expect(result.style).toEqual(undefined);
2424
});
2525
});
2626

@@ -232,7 +232,7 @@ describe("windCtrl", () => {
232232

233233
const result = button({ w: "full" });
234234
expect(result.className).toContain("w-full");
235-
expect(result.style).toEqual({});
235+
expect(result.style).toEqual(undefined);
236236
});
237237

238238
it("should apply style when dynamic resolver returns object with style", () => {
@@ -295,7 +295,7 @@ describe("windCtrl", () => {
295295

296296
const stringResult = button({ w: "full" });
297297
expect(stringResult.className).toContain("w-full");
298-
expect(stringResult.style).toEqual({});
298+
expect(stringResult.style).toEqual(undefined);
299299

300300
const numberResult = button({ w: 300 });
301301
expect(numberResult.style).toEqual({ width: "300px" });
@@ -439,7 +439,7 @@ describe("windCtrl", () => {
439439
const button = windCtrl({});
440440
const result = button({});
441441
expect(result.className).toBe("");
442-
expect(result.style).toEqual({});
442+
expect(result.style).toEqual(undefined);
443443
});
444444

445445
it("should handle undefined props gracefully", () => {

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Props<
4545

4646
type Result = {
4747
className: string;
48-
style: CSSProperties;
48+
style?: CSSProperties;
4949
};
5050

5151
function mergeStyles(
@@ -183,9 +183,11 @@ export function windCtrl<
183183

184184
const finalClassName = twMerge(clsx(classNameParts));
185185

186+
const hasStyle = Object.keys(mergedStyle).length > 0;
187+
186188
return {
187189
className: finalClassName,
188-
style: mergedStyle,
190+
...(hasStyle && { style: mergedStyle }),
189191
};
190192
};
191193
}

0 commit comments

Comments
 (0)