Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

feat(Props Interfaces): add props interface to Button, AccordionTitle, AccordionContent and refactoring the types definitions #130

Merged
merged 13 commits into from
Aug 27, 2018
Merged
8 changes: 5 additions & 3 deletions src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@ import * as _ from 'lodash'
import * as PropTypes from 'prop-types'
import * as React from 'react'

import { AutoControlledComponent, customPropTypes, childrenExist, Extendable } from '../../lib'
import { AutoControlledComponent, customPropTypes, childrenExist } from '../../lib'
import AccordionTitle from './AccordionTitle'
import AccordionContent from './AccordionContent'
import { DefaultBehavior } from '../../lib/accessibility'
import { Accessibility } from '../../lib/accessibility/interfaces'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
import { Extendable, ItemShorthand } from '../../../types/utils'

export interface IAccordionProps {
as?: any
activeIndex?: number[] | number
className?: string
children?: React.ReactNode
defaultActiveIndex?: number[] | number
exclusive?: boolean
onTitleClick?: (event: React.SyntheticEvent, data: IAccordionProps) => void
panels?: {
content: React.ReactNode | object
title: React.ReactNode | object
content: ItemShorthand
title: ItemShorthand
}[]
accessibility?: object | Function
styles?: IComponentPartStylesInput
Expand Down
12 changes: 11 additions & 1 deletion src/components/Accordion/AccordionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@ import * as PropTypes from 'prop-types'
import * as React from 'react'

import { childrenExist, createShorthandFactory, customPropTypes, UIComponent } from '../../lib'
import { Extendable } from '../../../types/utils'

export interface IAccordionContentProps {
as?: any
active?: boolean
children?: React.ReactNode
className?: string
content?: React.ReactNode
onClick?: (event: React.SyntheticEvent, data: IAccordionContentProps) => void
}

/**
* A standard AccordionContent.
*/
class AccordionContent extends UIComponent<any, any> {
class AccordionContent extends UIComponent<Extendable<IAccordionContentProps>, any> {
static displayName = 'AccordionContent'

static create: Function
Expand Down
13 changes: 12 additions & 1 deletion src/components/Accordion/AccordionTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@ import * as PropTypes from 'prop-types'
import * as React from 'react'

import { childrenExist, createShorthandFactory, customPropTypes, UIComponent } from '../../lib'
import { Extendable } from '../../../types/utils'

export interface IAccordionTitleProps {
as?: any
active?: boolean
children?: React.ReactNode
className?: string
content?: React.ReactNode
index?: string | number
onClick?: (event: React.SyntheticEvent, data: IAccordionTitleProps) => void
}

/**
* A standard AccordionTitle.
*/
class AccordionTitle extends UIComponent<any, any> {
class AccordionTitle extends UIComponent<Extendable<IAccordionTitleProps>, any> {
static displayName = 'AccordionTitle'

static create: Function
Expand Down
3 changes: 2 additions & 1 deletion src/components/Avatar/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import * as PropTypes from 'prop-types'
import * as React from 'react'
import { Image, Label, Icon } from '../../'

import { customPropTypes, UIComponent, Extendable } from '../../lib'
import { customPropTypes, UIComponent } from '../../lib'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
import { Extendable } from '../../../types/utils'

export interface IAvatarProps {
alt?: string
Expand Down
21 changes: 20 additions & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@ import { UIComponent, childrenExist, customPropTypes } from '../../lib'
import Icon from '../Icon'
import { ButtonBehavior } from '../../lib/accessibility'
import { Accessibility } from '../../lib/accessibility/interfaces'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
import { Extendable, ItemShorthand } from '../../../types/utils'

export interface IButtonProps {
as?: any
children?: React.ReactNode
circular?: boolean
className?: string
disabled?: boolean
content?: React.ReactNode
fluid?: boolean
icon?: ItemShorthand
iconPosition?: 'before' | 'after'
onClick?: (event: React.SyntheticEvent, data: IButtonProps) => void
type?: 'primary' | 'secondary'
accessibility?: object | Function
styles?: IComponentPartStylesInput
variables?: ComponentVariablesInput
}

/**
* A button.
Expand All @@ -17,7 +36,7 @@ import { Accessibility } from '../../lib/accessibility/interfaces'
* - for disabled buttons, add 'disabled' attribute so that the state is properly recognized by the screen reader
* - if button includes icon only, textual representation needs to be provided by using 'title', 'aria-label', or 'aria-labelledby' attributes
*/
class Button extends UIComponent<any, any> {
class Button extends UIComponent<Extendable<IButtonProps>, any> {
public static displayName = 'Button'

public static className = 'ui-button'
Expand Down
3 changes: 2 additions & 1 deletion src/components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as _ from 'lodash'
import * as PropTypes from 'prop-types'
import * as React from 'react'

import { childrenExist, customPropTypes, UIComponent, Extendable } from '../../lib'
import { childrenExist, customPropTypes, UIComponent } from '../../lib'
import ChatMessage from './ChatMessage'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
import { Extendable } from '../../../types/utils'

export interface IChatProps {
as?: any
Expand Down
9 changes: 2 additions & 7 deletions src/components/Divider/Divider.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import * as React from 'react'
import * as PropTypes from 'prop-types'

import {
childrenExist,
createShorthandFactory,
customPropTypes,
UIComponent,
Extendable,
} from '../../lib'
import { childrenExist, createShorthandFactory, customPropTypes, UIComponent } from '../../lib'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
import { Extendable } from '../../../types/utils'

export interface IDividerProps {
as?: any
Expand Down
10 changes: 2 additions & 8 deletions src/components/Grid/Grid.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import * as PropTypes from 'prop-types'
import * as React from 'react'
import ReactNode = React.ReactNode
import {
UIComponent,
childrenExist,
customPropTypes,
IRenderResultConfig,
Extendable,
} from '../../lib'
import { UIComponent, childrenExist, customPropTypes, IRenderResultConfig } from '../../lib'
import { ComponentVariablesInput, IComponentPartStylesInput } from '../../../types/theme'
import { ItemShorthand } from '../../../types/utils'
import { Extendable, ItemShorthand } from '../../../types/utils'

export interface IGridProps {
as?: any
Expand Down
3 changes: 0 additions & 3 deletions src/lib/Extendable.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ export { default as leven } from './leven'

export { pxToRem, setHTMLFontSize } from './fontSizeUtility'
export { customPropTypes, SUI }
export { Extendable } from './Extendable'
23 changes: 20 additions & 3 deletions src/themes/teams/components/Avatar/avatarStyles.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pxToRem } from '../../../../lib'
import { IComponentPartStylesInput, ICSSInJSStyle } from '../../../../../types/theme'
import { IAvatarPropsWithDefaults } from '../../../../components/Avatar/Avatar'

const getAvatarDimension = (size: number) => {
return 12 + size * 4
Expand Down Expand Up @@ -49,7 +50,12 @@ const getAvatarFontSize = (size: number) => {
}

const avatarStyles: IComponentPartStylesInput = {
root: ({ props: { size } }): ICSSInJSStyle => ({
root: ({
props: { size },
}: {
props: IAvatarPropsWithDefaults
variables: any
}): ICSSInJSStyle => ({
backgroundColor: 'inherit',
display: 'inline-block',
verticalAlign: 'top',
Expand All @@ -59,7 +65,12 @@ const avatarStyles: IComponentPartStylesInput = {
imageAvatar: (): ICSSInJSStyle => ({
verticalAlign: 'top',
}),
avatarNameContainer: ({ props: { size } }): ICSSInJSStyle => ({
avatarNameContainer: ({
props: { size },
}: {
props: IAvatarPropsWithDefaults
variables: any
}): ICSSInJSStyle => ({
display: 'inline-block',
width: pxToRem(getAvatarDimension(size)),
height: pxToRem(getAvatarDimension(size)),
Expand All @@ -68,7 +79,13 @@ const avatarStyles: IComponentPartStylesInput = {
verticalAlign: 'top',
textAlign: 'center',
}),
presenceIndicatorWrapper: ({ props: { size }, variables: v }): ICSSInJSStyle => ({
presenceIndicatorWrapper: ({
props: { size },
variables: v,
}: {
props: IAvatarPropsWithDefaults
variables: any
}): ICSSInJSStyle => ({
position: 'relative',
top: `-${pxToRem(getPresenceIndicatorWrapperTop(size))}`,
left: pxToRem(getPresenceIndicatorWrapperLeft(size)),
Expand Down