Skip to content

Commit b5d1f1e

Browse files
committed
introduce prettier
1 parent 50242e8 commit b5d1f1e

File tree

12 files changed

+86
-66
lines changed

12 files changed

+86
-66
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ coverage/
2929

3030
# cache
3131
.cache/
32-
.eslintcache
32+
.eslintcache

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,3 @@ coverage/
3636
npm-debug.log*
3737
yarn-debug.log*
3838
yarn-error.log*
39-

.prettierignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
build/
7+
lib/
8+
9+
# Package files
10+
package-lock.json
11+
*.tgz
12+
13+
# Logs
14+
*.log
15+
16+
# Coverage
17+
coverage/
18+
.nyc_output/
19+
20+
# Misc
21+
.DS_Store
22+
*.tsbuildinfo

README.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ const button = windCtrl({
3737
},
3838
dynamic: {
3939
w: (val) =>
40-
typeof val === "number"
41-
? { style: { width: `${val}px` } }
42-
: `w-${val}`,
40+
typeof val === "number" ? { style: { width: `${val}px` } } : `w-${val}`,
4341
},
4442
defaultVariants: {
4543
intent: "primary",
@@ -66,13 +64,9 @@ Dynamic props allow you to pass arbitrary values that can resolve to either Tail
6664
const button = windCtrl({
6765
dynamic: {
6866
w: (val) =>
69-
typeof val === "number"
70-
? { style: { width: `${val}px` } }
71-
: `w-${val}`,
67+
typeof val === "number" ? { style: { width: `${val}px` } } : `w-${val}`,
7268
h: (val) =>
73-
typeof val === "number"
74-
? { style: { height: `${val}px` } }
75-
: `h-${val}`,
69+
typeof val === "number" ? { style: { height: `${val}px` } } : `h-${val}`,
7670
},
7771
});
7872

@@ -122,7 +116,6 @@ const button = windCtrl({
122116

123117
The scope classes are automatically prefixed with `group-data-[scope=...]/wind-scope:` to work with Tailwind's group modifier.
124118

125-
126119
### Variants
127120

128121
Variants are mutually exclusive options. Each variant dimension can have multiple options, but only one option per dimension can be active at a time.

examples/Button.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,9 @@ const button = windCtrl({
2525
},
2626
dynamic: {
2727
w: (val) =>
28-
typeof val === "number"
29-
? { style: { width: `${val}px` } }
30-
: `w-${val}`,
28+
typeof val === "number" ? { style: { width: `${val}px` } } : `w-${val}`,
3129
h: (val) =>
32-
typeof val === "number"
33-
? { style: { height: `${val}px` } }
34-
: `h-${val}`,
30+
typeof val === "number" ? { style: { height: `${val}px` } } : `h-${val}`,
3531
},
3632
defaultVariants: {
3733
intent: "primary",
@@ -47,7 +43,9 @@ type ButtonProps<T extends ElementType = "button"> = {
4743
as?: T;
4844
intent?: "primary" | "secondary" | "destructive" | "outline" | "ghost";
4945
size?: "sm" | "md" | "lg";
50-
traits?: Array<"loading" | "glass" | "disabled"> | { loading?: boolean; glass?: boolean; disabled?: boolean };
46+
traits?:
47+
| Array<"loading" | "glass" | "disabled">
48+
| { loading?: boolean; glass?: boolean; disabled?: boolean };
5149
w?: string | number;
5250
h?: string | number;
5351
} & ComponentPropsWithoutRef<T>;
@@ -83,4 +81,3 @@ export function Button<T extends ElementType = "button">({
8381
</Component>
8482
);
8583
}
86-

examples/ButtonExample.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export function ButtonExample() {
3434
Loading (Object)
3535
</Button>
3636
<Button traits={["glass"]}>Glass Effect</Button>
37-
<Button traits={["loading", "glass"]}>
38-
Loading + Glass
39-
</Button>
37+
<Button traits={["loading", "glass"]}>Loading + Glass</Button>
4038
<Button traits={["disabled"]}>Disabled</Button>
4139
</div>
4240
</section>
@@ -59,19 +57,10 @@ export function ButtonExample() {
5957
<Button intent="secondary" size="lg" traits={["glass"]}>
6058
Secondary + Large + Glass
6159
</Button>
62-
<Button
63-
intent="primary"
64-
size="sm"
65-
traits={["loading"]}
66-
w={120}
67-
>
60+
<Button intent="primary" size="sm" traits={["loading"]} w={120}>
6861
Primary + Small + Loading
6962
</Button>
70-
<Button
71-
intent="outline"
72-
traits={["glass"]}
73-
w="full"
74-
>
63+
<Button intent="outline" traits={["glass"]} w="full">
7564
Outline + Glass + Full Width
7665
</Button>
7766
</div>
@@ -87,16 +76,24 @@ export function ButtonExample() {
8776
</section>
8877

8978
<section>
90-
<h2 className="text-2xl font-semibold mb-4">Scopes (Context-aware styling)</h2>
79+
<h2 className="text-2xl font-semibold mb-4">
80+
Scopes (Context-aware styling)
81+
</h2>
9182
<div className="space-y-4">
92-
<div data-scope="header" className="group/wind-scope p-4 bg-gray-100 rounded">
83+
<div
84+
data-scope="header"
85+
className="group/wind-scope p-4 bg-gray-100 rounded"
86+
>
9387
<p className="mb-2 text-sm text-gray-600">Header scope:</p>
9488
<Button intent="primary">Header Button</Button>
9589
<p className="mt-2 text-xs text-gray-500">
9690
This button will have smaller text due to header scope
9791
</p>
9892
</div>
99-
<div data-scope="footer" className="group/wind-scope p-4 bg-gray-100 rounded">
93+
<div
94+
data-scope="footer"
95+
className="group/wind-scope p-4 bg-gray-100 rounded"
96+
>
10097
<p className="mb-2 text-sm text-gray-600">Footer scope:</p>
10198
<Button intent="secondary">Footer Button</Button>
10299
<p className="mt-2 text-xs text-gray-500">
@@ -108,4 +105,3 @@ export function ButtonExample() {
108105
</div>
109106
);
110107
}
111-

package-lock.json

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,14 @@
4343
"test:coverage": "vitest --coverage",
4444
"build": "tsc",
4545
"dev": "tsc --watch",
46+
"format": "prettier --write .",
47+
"format:check": "prettier --check .",
4648
"prepublishOnly": "npm run build && npm test"
4749
},
4850
"devDependencies": {
4951
"@types/node": "^25.0.3",
52+
"@types/react": "^19.2.7",
53+
"prettier": "^3.7.4",
5054
"typescript": "^5.9.3",
5155
"vitest": "^4.0.16"
5256
},

src/__tests__/windctrl.test.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,12 @@ describe("windCtrl", () => {
313313
});
314314

315315
const result = button({});
316-
expect(result.className).toContain("group-data-[scope=header]/wind-scope:text-sm");
317-
expect(result.className).toContain("group-data-[scope=footer]/wind-scope:text-xs");
316+
expect(result.className).toContain(
317+
"group-data-[scope=header]/wind-scope:text-sm",
318+
);
319+
expect(result.className).toContain(
320+
"group-data-[scope=footer]/wind-scope:text-xs",
321+
);
318322
});
319323

320324
it("should combine scopes with base classes", () => {
@@ -328,7 +332,9 @@ describe("windCtrl", () => {
328332
const result = button({});
329333
expect(result.className).toContain("px-4");
330334
expect(result.className).toContain("py-2");
331-
expect(result.className).toContain("group-data-[scope=header]/wind-scope:text-sm");
335+
expect(result.className).toContain(
336+
"group-data-[scope=header]/wind-scope:text-sm",
337+
);
332338
});
333339
});
334340

@@ -415,7 +421,9 @@ describe("windCtrl", () => {
415421

416422
expect(result.style).toEqual({ width: "200px" });
417423

418-
expect(result.className).toContain("group-data-[scope=header]/wind-scope:text-sm");
424+
expect(result.className).toContain(
425+
"group-data-[scope=header]/wind-scope:text-sm",
426+
);
419427
});
420428

421429
it("should merge conflicting Tailwind classes (last one wins)", () => {
@@ -535,4 +543,3 @@ describe("windCtrl", () => {
535543
});
536544
});
537545
});
538-

src/index.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ type Props<
3838
} & {
3939
traits?:
4040
| Array<keyof TTraits extends string ? keyof TTraits : never>
41-
| Partial<Record<keyof TTraits extends string ? keyof TTraits : never, boolean>>;
41+
| Partial<
42+
Record<keyof TTraits extends string ? keyof TTraits : never, boolean>
43+
>;
4244
} & {
4345
[K in keyof TDynamic]?: Parameters<TDynamic[K]>[0];
4446
};
@@ -48,15 +50,13 @@ type Result = {
4850
style?: CSSProperties;
4951
};
5052

51-
function mergeStyles(
52-
...styles: (CSSProperties | undefined)[]
53-
): CSSProperties {
53+
function mergeStyles(...styles: (CSSProperties | undefined)[]): CSSProperties {
5454
return Object.assign({}, ...styles.filter(Boolean));
5555
}
5656

5757
function processTraits<TTraits extends Record<string, ClassValue>>(
5858
traits: TTraits,
59-
propsTraits?: Props<{}, TTraits>["traits"]
59+
propsTraits?: Props<{}, TTraits>["traits"],
6060
): ClassValue[] {
6161
if (!propsTraits) return [];
6262

@@ -77,7 +77,7 @@ function processTraits<TTraits extends Record<string, ClassValue>>(
7777

7878
function processDynamic<TDynamic extends Record<string, DynamicResolver>>(
7979
dynamic: TDynamic,
80-
props: Props<{}, {}, TDynamic>
80+
props: Props<{}, {}, TDynamic>,
8181
): { className: ClassValue[]; style: CSSProperties } {
8282
const classNameParts: ClassValue[] = [];
8383
const styles: CSSProperties[] = [];
@@ -106,13 +106,12 @@ function processDynamic<TDynamic extends Record<string, DynamicResolver>>(
106106
}
107107

108108
function processScopes<TScopes extends Record<string, ClassValue>>(
109-
scopes: TScopes
109+
scopes: TScopes,
110110
): ClassValue[] {
111111
return Object.entries(scopes).map(([scopeName, scopeClasses]) => {
112-
const classesStr = typeof scopeClasses === "string"
113-
? scopeClasses
114-
: clsx(scopeClasses);
115-
112+
const classesStr =
113+
typeof scopeClasses === "string" ? scopeClasses : clsx(scopeClasses);
114+
116115
return classesStr
117116
.split(/\s+/)
118117
.filter(Boolean)
@@ -127,7 +126,7 @@ export function windCtrl<
127126
TDynamic extends Record<string, DynamicResolver> = {},
128127
TScopes extends Record<string, ClassValue> = {},
129128
>(
130-
config: Config<TVariants, TTraits, TDynamic, TScopes>
129+
config: Config<TVariants, TTraits, TDynamic, TScopes>,
131130
): (props?: Props<TVariants, TTraits, TDynamic>) => Result {
132131
const {
133132
base,
@@ -184,11 +183,10 @@ export function windCtrl<
184183
const finalClassName = twMerge(clsx(classNameParts));
185184

186185
const hasStyle = Object.keys(mergedStyle).length > 0;
187-
186+
188187
return {
189188
className: finalClassName,
190189
...(hasStyle && { style: mergedStyle }),
191190
};
192191
};
193192
}
194-

0 commit comments

Comments
 (0)