Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,14 @@ const button = windctrl({
});

// Usage
// 1. Wrap the parent with `data-scope` and `group/wind-scope`
// 1. Wrap the parent with `data-windctrl-scope` and `group/windctrl-scope`
// 2. The button automatically adapts its style based on the parent
<div data-scope="header" className="group/wind-scope">
<div data-windctrl-scope="header" className="group/windctrl-scope">
<button className={button().className}>Header Button</button>
</div>
```

The scope classes are automatically prefixed with `group-data-[scope=...]/wind-scope:` to target the parent's data attribute.
The scope classes are automatically prefixed with `group-data-[windctrl-scope=...]/windctrl-scope:` to target the parent's data attribute.

### Variants

Expand Down
8 changes: 4 additions & 4 deletions examples/ButtonExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export function ButtonExample() {
</h2>
<div className="space-y-4">
<div
data-scope="header"
className="group/wind-scope p-4 bg-gray-100 rounded"
data-windctrl-scope="header"
className="group/windctrl-scope p-4 bg-gray-100 rounded"
>
<p className="mb-2 text-sm text-gray-600">Header scope:</p>
<Button intent="primary">Header Button</Button>
Expand All @@ -91,8 +91,8 @@ export function ButtonExample() {
</p>
</div>
<div
data-scope="footer"
className="group/wind-scope p-4 bg-gray-100 rounded"
data-windctrl-scope="footer"
className="group/windctrl-scope p-4 bg-gray-100 rounded"
>
<p className="mb-2 text-sm text-gray-600">Footer scope:</p>
<Button intent="secondary">Footer Button</Button>
Expand Down
12 changes: 6 additions & 6 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,10 @@ describe("windctrl", () => {

const result = button({});
expect(result.className).toContain(
"group-data-[scope=header]/wind-scope:text-sm",
"group-data-[windctrl-scope=header]/windctrl-scope:text-sm",
);
expect(result.className).toContain(
"group-data-[scope=footer]/wind-scope:text-xs",
"group-data-[windctrl-scope=footer]/windctrl-scope:text-xs",
);
});

Expand All @@ -352,7 +352,7 @@ describe("windctrl", () => {
expect(result.className).toContain("px-4");
expect(result.className).toContain("py-2");
expect(result.className).toContain(
"group-data-[scope=header]/wind-scope:text-sm",
"group-data-[windctrl-scope=header]/windctrl-scope:text-sm",
);
});

Expand All @@ -366,10 +366,10 @@ describe("windctrl", () => {
const result = button({});

expect(result.className).toContain(
"group-data-[scope=header]/wind-scope:text-sm",
"group-data-[windctrl-scope=header]/windctrl-scope:text-sm",
);
expect(result.className).toContain(
"group-data-[scope=header]/wind-scope:py-1",
"group-data-[windctrl-scope=header]/windctrl-scope:py-1",
);
});
});
Expand Down Expand Up @@ -458,7 +458,7 @@ describe("windctrl", () => {
expect(result.style).toEqual({ width: "200px" });

expect(result.className).toContain(
"group-data-[scope=header]/wind-scope:text-sm",
"group-data-[windctrl-scope=header]/windctrl-scope:text-sm",
);
});

Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ function processScopes<TScopes extends Record<string, ClassValue>>(
return classesStr
.split(/\s+/)
.filter(Boolean)
.map((cls) => `group-data-[scope=${scopeName}]/wind-scope:${cls}`)
.map(
(cls) =>
`group-data-[windctrl-scope=${scopeName}]/windctrl-scope:${cls}`,
)
.join(" ");
});
}
Expand Down