Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
feat(typescript): add type for props of glamorous component (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ailrun authored and Kent C. Dodds committed Aug 23, 2017
1 parent f209187 commit 51f70b2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
3 changes: 2 additions & 1 deletion test/glamorous-exports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SVGPropertiesCompleteSingle, SVGPropertiesComplete, SVGPropertiesLossy,

GlamorousComponent,
GlamorousComponentProps,
ExtraGlamorousProps,
WithComponent,
WithProps,
Expand All @@ -21,4 +22,4 @@ import {
HTMLKey,
SVGComponentFactory,
SVGKey,
} from '../'
} from '../'
17 changes: 16 additions & 1 deletion test/glamorous.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import glamorous, {

// Needed if generating definition files
// https://github.com/Microsoft/TypeScript/issues/5938
import { ExtraGlamorousProps } from "../";
import { ExtraGlamorousProps, GlamorousComponentProps } from "../";

import { WithComponent, WithProps, CSSPropertiesPseudo, CSSPropertiesLossy } from "../"

Expand Down Expand Up @@ -316,6 +316,21 @@ export const ThemeProviderAndThemedComponent = () => (
</ThemeProvider>
);

// Glamorous component using general prop

const props: GlamorousComponentProps<React.HTMLProps<HTMLButtonElement>> = {
name: 'button',
onClick: () => {}
}

const GlamorousButton = glamorous.button({
fontSize: '10px'
})

const UseGlamorousButtonWithGlamorousComponentProps = (
<GlamorousButton {...props} />
)

// Extended component with theme prop

interface ExampleTheme {
Expand Down
11 changes: 11 additions & 0 deletions typings/glamorous-component.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,14 @@ export type GlamorousComponent<ExternalProps, Props> =
& React.ComponentClass<ExtraGlamorousProps & ExternalProps>
& WithComponent<ExternalProps, Props>
& WithProps<ExternalProps, Props>

export type GlamorousComponentProps<ExternalProps> =
& JSX.IntrinsicAttributes
& JSX.IntrinsicClassAttributes<
React.Component<
ExtraGlamorousProps & ExternalProps,
React.ComponentState
>
>
& ExternalProps
& { children?: React.ReactNode }
2 changes: 2 additions & 0 deletions typings/glamorous.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from './built-in-component-factories'
import {
GlamorousComponent,
GlamorousComponentProps,
ExtraGlamorousProps,
WithComponent,
WithProps,
Expand Down Expand Up @@ -54,6 +55,7 @@ export {
SVGPropertiesCompleteSingle, SVGPropertiesComplete, SVGPropertiesLossy,

GlamorousComponent,
GlamorousComponentProps,
ExtraGlamorousProps,
WithComponent,
WithProps,
Expand Down

0 comments on commit 51f70b2

Please sign in to comment.