Skip to content

Commit e65ccaf

Browse files
committed
fix(component): fixes args usage with css helper
1 parent 2d9e1a0 commit e65ccaf

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

src/matchers.tsx

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,36 @@
33
import { css } from "styled-components";
44

55
export const is = (prop: string) => (...args: any) => (props: object) =>
6-
props[prop] ? css(args) : "";
6+
props[prop]
7+
? css`
8+
${args}
9+
`
10+
: "";
711

812
export const isnt = (prop: string) => (...args: any) => (props: object) =>
9-
!props[prop] ? css(args) : "";
13+
!props[prop]
14+
? css`
15+
${args}
16+
`
17+
: "";
1018

1119
export const isAny = (prop: string, matches: any[]) => (...args: any) => (
1220
props: object
13-
) => (matches.includes(props[prop]) ? css(args) : "");
21+
) =>
22+
matches.includes(props[prop])
23+
? css`
24+
${args}
25+
`
26+
: "";
1427

1528
export const isntAny = (prop: string, matches: any[]) => (...args: any) => (
1629
props: object
17-
) => (!matches.includes(props[prop]) ? css(args) : "");
30+
) =>
31+
!matches.includes(props[prop])
32+
? css`
33+
${args}
34+
`
35+
: "";
1836

1937
export const value = (prop: string) => (props: object) => props[prop];
2038

@@ -26,8 +44,18 @@ export const choose = (prop: string, map: object) => (props: object) =>
2644

2745
export const over = (prop: string, amount: number) => (...args: any) => (
2846
props: object
29-
) => (props[prop] > amount ? css(args) : "");
47+
) =>
48+
props[prop] > amount
49+
? css`
50+
${args}
51+
`
52+
: "";
3053

3154
export const under = (prop: string, amount: number) => (...args: any) => (
3255
props: object
33-
) => (props[prop] < amount ? css(args) : "");
56+
) =>
57+
props[prop] < amount
58+
? css`
59+
${args}
60+
`
61+
: "";

src/styled-tidy.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ describe("styed-tidy", () => {
5252
});
5353
});
5454

55+
describe("'is' matcher with a mixin", () => {
56+
it("should render the given CSS when matched", () => {
57+
const Test = styled.div<TestProps>`
58+
${is("enabled")`height: ${rem(16)}`};
59+
`;
60+
const { getByText } = setup(<Test enabled>test</Test>);
61+
expect(getByText("test")).toHaveStyleRule("height", "1rem");
62+
});
63+
});
64+
5565
describe("'isnt' matcher", () => {
5666
const Test = styled.div<TestProps>`
5767
${isnt("enabled")`color: red`};

0 commit comments

Comments
 (0)