Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add arbitrary width support for border #88

Merged
merged 2 commits into from Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/_rules/border.js
Expand Up @@ -24,6 +24,15 @@ export const borders = [
[/^border()-(.+)$/, handlerBorderStyle, { autocomplete: "(border)-style" }],
[/^border-([xy])-(.+)$/, handlerBorderStyle],
[/^border-([rltb])-(.+)$/, handlerBorderStyle],
[
/^border-([rltb])?-?\[([0-9])\]$/,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, why did you choose to limit the range to 9?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, good question. It kinda felt natural to me to have this range. Now when I think of it, maybe the arbitrary values should be whatever number? Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing now any digit 3752d88

handlerArbitraryBorderSize,
{
autocomplete: [
'border-<directions>-[$width]',
],
},
],
// divide
[/^divide-([xy])-(\d+)$/, handlerDivideBorder, { autocomplete: `divide-<x|y>-(${Object.keys(lineWidth).join('|')})-(reverse)` }],
[/^divide-([xy])$/, handlerDivideBorder],
Expand All @@ -41,6 +50,12 @@ function handlerBorderSize([, a = "", b], { theme }) {
if (a in directionMap && v != null) return directionMap[a].map((i) => [`border${i}-width`, v]);
}

function handlerArbitraryBorderSize([, a, v]) {
if (a in directionMap && v != null) return directionMap[a].map((i) => [`border${i}-width`, v]);

return [[`border-width`, v]];
}

function handlerBorderStyle([, a = "", s]) {
if (borderStyles.includes(s) && a in directionMap) return directionMap[a].map((i) => [`border${i}-style`, s]);
}
Expand Down
9 changes: 9 additions & 0 deletions test/__snapshots__/border.js.snap
Expand Up @@ -50,6 +50,15 @@ exports[`border > supports divide borders between horizontal and stacked childre
.divide-y>*+*{--w-divide-y-reverse:0;border-top-width:calc(1px * calc(1 - var(--w-divide-y-reverse)));border-bottom-width:calc(1px * var(--w-divide-y-reverse))}"
`;

exports[`border > supports setting arbitrary border width 1`] = `
"/* layer: default */
.border-\\\\[6\\\\]{border-width:6;}
.border-b-\\\\[7\\\\]{border-bottom-width:7;}
.border-l-\\\\[7\\\\]{border-left-width:7;}
.border-r-\\\\[7\\\\]{border-right-width:7;}
.border-t-\\\\[7\\\\]{border-top-width:7;}"
`;

exports[`border > supports setting border style 1`] = `
"/* layer: default */
.border-dashed{border-style:dashed;}
Expand Down
7 changes: 7 additions & 0 deletions test/border.js
Expand Up @@ -24,6 +24,13 @@ describe("border", () => {
expect(css).toMatchSnapshot();
});

test("supports setting arbitrary border width", async (t) => {
const classes = ["border-[6]", "border-l-[7]", "border-r-[7]", "border-t-[7]", "border-b-[7]", "border-w-[7]", "border-[wow]"];

const { css } = await t.uno.generate(classes);

expect(css).toMatchSnapshot();
});
test("supports setting border style", async (t) => {
const classes = [
"border-solid",
Expand Down