Skip to content

Commit f3562b3

Browse files
committed
Enable auto in fr.spacing
1 parent df7e7e2 commit f3562b3

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/fr/spacing.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,53 +12,53 @@ export function spacing<
1212
Params extends Partial<
1313
Record<
1414
"topBottom" | "rightLeft" | "top" | "right" | "bottom" | "left",
15-
SpacingToken | number
15+
SpacingToken | number | "auto"
1616
>
1717
>
1818
>(
1919
kind: Kind,
2020
params: Params
21-
): (Params extends { topBottom: SpacingToken | number }
21+
): (Params extends { topBottom: SpacingToken | number | "auto" }
2222
? Record<
2323
`${Kind}${"Top" | "Bottom"}`,
2424
Params["topBottom"] extends SpacingToken
2525
? SpacingTokenByValue[Params["topBottom"]]
2626
: Params["topBottom"]
2727
>
2828
: {}) &
29-
(Params extends { rightLeft: SpacingToken | number }
29+
(Params extends { rightLeft: SpacingToken | number | "auto" }
3030
? Record<
3131
`${Kind}${"Right" | "Left"}`,
3232
Params["rightLeft"] extends SpacingToken
3333
? SpacingTokenByValue[Params["rightLeft"]]
3434
: Params["rightLeft"]
3535
>
3636
: {}) &
37-
(Params extends { top: SpacingToken | number }
37+
(Params extends { top: SpacingToken | number | "auto" }
3838
? Record<
3939
`${Kind}Top`,
4040
Params["top"] extends SpacingToken
4141
? SpacingTokenByValue[Params["top"]]
4242
: Params["top"]
4343
>
4444
: {}) &
45-
(Params extends { right: SpacingToken | number }
45+
(Params extends { right: SpacingToken | number | "auto" }
4646
? Record<
4747
`${Kind}Right`,
4848
Params["right"] extends SpacingToken
4949
? SpacingTokenByValue[Params["right"]]
5050
: Params["right"]
5151
>
5252
: {}) &
53-
(Params extends { bottom: SpacingToken | number }
53+
(Params extends { bottom: SpacingToken | number | "auto" }
5454
? Record<
5555
`${Kind}Bottom`,
5656
Params["bottom"] extends SpacingToken
5757
? SpacingTokenByValue[Params["bottom"]]
5858
: Params["bottom"]
5959
>
6060
: {}) &
61-
(Params extends { left: SpacingToken | number }
61+
(Params extends { left: SpacingToken | number | "auto" }
6262
? Record<
6363
`${Kind}Left`,
6464
Params["left"] extends SpacingToken
@@ -71,7 +71,7 @@ export function spacing(
7171
params?: Partial<
7272
Record<
7373
"topBottom" | "rightLeft" | "top" | "right" | "bottom" | "left",
74-
SpacingToken | number
74+
SpacingToken | number | "auto"
7575
>
7676
>
7777
): any {
@@ -115,7 +115,8 @@ export function spacing(
115115
return;
116116
}
117117

118-
out[`${kind}${capitalize(p)}`] = typeof v === "number" ? v : spacingTokenByValue[v];
118+
out[`${kind}${capitalize(p)}`] =
119+
typeof v === "number" ? v : v === "auto" ? v : spacingTokenByValue[v];
119120
});
120121

121122
return out;

test/types/spacing.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,14 @@ import { Equals } from "tsafe";
7171

7272
assert<Equals<typeof got, Expected>>();
7373
}
74+
75+
{
76+
const got = spacing("margin", { "rightLeft": "auto" });
77+
78+
type Expected = {
79+
marginLeft: "auto";
80+
marginRight: "auto";
81+
};
82+
83+
assert<Equals<typeof got, Expected>>();
84+
}

0 commit comments

Comments
 (0)