Skip to content

Commit

Permalink
Add types for scroll track
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarcuccio committed Mar 17, 2020
1 parent eb915bc commit 3c85b3e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
30 changes: 29 additions & 1 deletion src/components/ScrollTrack/ScrollTrack.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,34 @@ export interface ScrollTrackProps {
}
}

declare const ScrollTrack: React.ComponentClass<ScrollTrackProps>
interface TrackProps {
showLeftArrow: boolean
showRightArrow: boolean
left: number
isSliding: boolean
parentWidth: number | false
trackWidth: number | false
trackBounds: DOMRect | false
}

export interface WithEqualWidthTrackInjectedProps {
startIndex: number
lastIndex: number
trackProps: TrackProps
}

export interface WithTrackProps extends TrackProps {}

type GetChildWidth = (arguments: { trackProps: TrackProps }) => number

type EqualWidthTrack = (
childWidth: number | GetChildWidth
) => <T extends WithEqualWidthTrackInjectedProps>(
wrappedComponent: React.ComponentType<T>
) => React.ComponentType<Omit<T, keyof WithEqualWidthTrackInjectedProps>>

declare const ScrollTrack: React.ComponentClass<ScrollTrackProps> & {
equalWidthTrack: EqualWidthTrack
}

export default ScrollTrack
1 change: 1 addition & 0 deletions src/components/ScrollTrack/ScrollTrackPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import PropTypes from 'prop-types'

const propTypes = {
trackProps: PropTypes.shape({
isSliding: PropTypes.bool,
showLeftArrow: PropTypes.bool,
showRightArrow: PropTypes.bool,
left: PropTypes.number,
Expand Down
7 changes: 6 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ import SelectionPills from './components/SelectionPills/SelectionPills'
import Normalize from './styles/Normalize'
import responsive from './styles/responsive'
import Row from './components/Grid/Row'
import ScrollTrack from './components/ScrollTrack/ScrollTrack'
import ScrollTrack, {
WithEqualWidthTrackInjectedProps,
WithTrackProps,
} from './components/ScrollTrack/ScrollTrack'
import SetStyles from './styles/SetStyles'
import spacing from './styles/spacing'
import PhoneNumberField from './components/Forms/PhoneNumberField'
Expand Down Expand Up @@ -141,6 +144,8 @@ export {
SelectionPill,
SelectionPills,
ScrollTrack,
WithTrackProps,
WithEqualWidthTrackInjectedProps,
Menu,
MenuItem,
MenuDivider,
Expand Down

0 comments on commit 3c85b3e

Please sign in to comment.