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: prop types for styled element: JSX.IntrinsicElements[T] #3

Merged
merged 1 commit into from
Aug 18, 2021
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 src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export declare function ThemeProvider<
>(props: T): JSX.Element;
export declare function useTheme(): unknown;
export declare function styled<T extends keyof JSX.IntrinsicElements>(
tag: T | ((props: JSX.HTMLAttributes<JSX.IntrinsicElements[T]>) => JSX.Element)
tag: T | ((props: JSX.IntrinsicElements[T]) => JSX.Element)
): <P>(
args_0:
| string
Expand All @@ -51,8 +51,8 @@ export declare function styled<T extends keyof JSX.IntrinsicElements>(
}
) => string | number | CSSAttribute | undefined)
)[]
) => ((props: P & JSX.HTMLAttributes<JSX.IntrinsicElements[T]>) => JSX.Element) & {
className: (props: P & JSX.HTMLAttributes<JSX.IntrinsicElements[T]>) => string;
) => ((props: P & JSX.IntrinsicElements[T]) => JSX.Element) & {
className: (props: P & JSX.IntrinsicElements[T]) => string;
};
export declare function createGlobalStyles(
tag: CSSAttribute | TemplateStringsArray | string,
Expand Down
17 changes: 17 additions & 0 deletions test/test.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ describe("Simple Styled", () => {
});
});

test("Creates input properly", () => {
const Input = styled('input')`

Choose a reason for hiding this comment

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

I might be wrong, but the issue was pointing out that we should handle the case of something like:

const SpecialInput = styled(Input)``

Isn't worth to add a test case where you test this too?

width: 5em;
text-align: right;
`;

let currentTarget:HTMLInputElement
createRoot(() => {
const v = (
<Input
type="number"
onchange={evt=>currentTarget = evt.currentTarget}
/>
);
})
})

test("Test Theming", () => {
const Div = styled("div")<{ bold: boolean; border: number; color: string }>`
color: steelblue;
Expand Down