Skip to content

Commit

Permalink
fix(component): fixes args usage with css helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dw2 committed Sep 28, 2019
1 parent 2d9e1a0 commit e65ccaf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/matchers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,36 @@
import { css } from "styled-components";

export const is = (prop: string) => (...args: any) => (props: object) =>
props[prop] ? css(args) : "";
props[prop]
? css`
${args}
`
: "";

export const isnt = (prop: string) => (...args: any) => (props: object) =>
!props[prop] ? css(args) : "";
!props[prop]
? css`
${args}
`
: "";

export const isAny = (prop: string, matches: any[]) => (...args: any) => (
props: object
) => (matches.includes(props[prop]) ? css(args) : "");
) =>
matches.includes(props[prop])
? css`
${args}
`
: "";

export const isntAny = (prop: string, matches: any[]) => (...args: any) => (
props: object
) => (!matches.includes(props[prop]) ? css(args) : "");
) =>
!matches.includes(props[prop])
? css`
${args}
`
: "";

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

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

export const over = (prop: string, amount: number) => (...args: any) => (
props: object
) => (props[prop] > amount ? css(args) : "");
) =>
props[prop] > amount
? css`
${args}
`
: "";

export const under = (prop: string, amount: number) => (...args: any) => (
props: object
) => (props[prop] < amount ? css(args) : "");
) =>
props[prop] < amount
? css`
${args}
`
: "";
10 changes: 10 additions & 0 deletions src/styled-tidy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ describe("styed-tidy", () => {
});
});

describe("'is' matcher with a mixin", () => {
it("should render the given CSS when matched", () => {
const Test = styled.div<TestProps>`
${is("enabled")`height: ${rem(16)}`};
`;
const { getByText } = setup(<Test enabled>test</Test>);
expect(getByText("test")).toHaveStyleRule("height", "1rem");
});
});

describe("'isnt' matcher", () => {
const Test = styled.div<TestProps>`
${isnt("enabled")`color: red`};
Expand Down

0 comments on commit e65ccaf

Please sign in to comment.