Skip to content

Commit

Permalink
type def fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanmarks committed Jul 17, 2019
1 parent 068ee4e commit 0985b99
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 20 deletions.
25 changes: 15 additions & 10 deletions src/components/Buttons/Button.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ import * as React from 'react'
import { RadiumStyles, ElementAttributes } from '../..'
import { WithThemeInjectedProps, ApplyWithTheme } from '../../styles/themer/withTheme'

export interface ButtonProps
extends WithThemeInjectedProps,
Pick<
React.ComponentPropsWithoutRef<'button'>,
'onClick' | 'onMouseDown' | 'type' | 'tabIndex'
> {
export interface ButtonProps extends WithThemeInjectedProps {
children?: React.ReactNode

/** Whether or not the button is disabled. */
Expand All @@ -22,9 +17,6 @@ export interface ButtonProps
/** Optional style overrides. */
style?: RadiumStyles

/** Any additonal props to add to the element (e.g. data attributes). */
elementAttributes?: ElementAttributes<React.ComponentPropsWithoutRef<'button'>>

/** An optional icon. Can be a an icon name or a Snacks `Icon` component. */
icon?: string | React.ReactElement<any> // eslint-disable-line @typescript-eslint/no-explicit-any

Expand All @@ -41,6 +33,19 @@ export interface ButtonProps
href?: string
}

declare const Button: ApplyWithTheme<React.ComponentClass<ButtonProps>>
type ButtonElementProps<C extends React.ElementType> = Pick<
React.ComponentPropsWithRef<C>,
'onClick' | 'onMouseDown' | 'type' | 'tabIndex'
> & {
elementAttributes?: ElementAttributes<React.ComponentPropsWithoutRef<C>>
}

type ButtonBase<C extends React.ElementType, P = {}> = ApplyWithTheme<
(props: P & ButtonProps & ButtonElementProps<C>) => JSX.Element
>

type Button = ButtonBase<'a', { href: string }> & ButtonBase<'button'>

declare const Button: Button

export default Button
6 changes: 3 additions & 3 deletions src/components/Icon/Icon.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import hexValues from './hexValues'

export interface IconProps {
/** String name of icon - ex 'cart' */
name: keyof typeof hexValues
name?: keyof typeof hexValues

/** Hexcode of desired icon from ic-icons */
code: string
code?: string

/** Optional style overrides */
style?: RadiumStyles

/** Callback function called after button click */
onClick: React.ComponentProps<'i'>['onClick']
onClick?: React.ComponentProps<'i'>['onClick']
}

declare const Icon: React.ComponentType<IconProps>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Loading/LoadingBox.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { RadiumStyles } from '../..'

export interface LoadingBoxProps {
/** Use for rendering dark backgrounds. */
background: 'light' | 'dark'
background?: 'light' | 'dark'

/** Use for rendering light backgrounds, overrides dark */
shape: 'circle' | 'square' | 'line'
shape?: 'circle' | 'square' | 'line'

/**
* By default, `size` will determine the components width.
* If the `shape` is prop `circle` or `square`, `size` will apply to height and width.
*/
size: string | number
size?: string | number

style?: RadiumStyles
}
Expand Down
4 changes: 1 addition & 3 deletions src/styles/themer/utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export declare function cleanConfig<T extends Theme>(themeConfig: T): Theme

export declare function validConfigValue(section: string, sectionKey: string): boolean

type DeepPartial<T> = { [P in keyof T]?: DeepPartial<T[P]> }

export interface ThemePropTypes extends DeepPartial<Theme> {}
export type ThemePropTypes = Theme

export declare const themePropTypes: PropTypes.Requireable<
PropTypes.InferProps<{
Expand Down
10 changes: 9 additions & 1 deletion test/typescript/foobar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import * as React from 'react'
import { Button, SVGIcon } from '../../src'

export function Foo() {
return <Button>Foo</Button>
return <Button onClick={(e: React.MouseEvent<HTMLButtonElement>) => e}>Foo</Button>
}

export function Foo2() {
return (
<Button href="foo.html" onClick={(e: React.MouseEvent<HTMLAnchorElement>) => e}>
Foo
</Button>
)
}

export function Bar() {
Expand Down

0 comments on commit 0985b99

Please sign in to comment.