11import React , { Component , ComponentType } from 'react'
2- import { bool } from 'prop-types'
32
43import { getBoundsForNode , TComputedBounds , TGetBoundsForNodeArgs } from './utils'
5- import { TSelectableItemState } from './Selectable.types'
6- import SelectableGroupContext from './Context '
4+ import { TSelectableItemState , TSelectableItemProps } from './Selectable.types'
5+ import { SelectableGroupContext } from './SelectableGroup.context '
76
8- const createSelectable = ( WrappedComponent : ComponentType < any > ) =>
9- class SelectableItem extends Component < any , TSelectableItemState > {
10- static contextType = SelectableGroupContext
7+ type TAddedProps = Partial < Pick < TSelectableItemProps , 'isSelected' > >
118
12- static propTypes = {
13- isSelected : bool
14- }
9+ export const createSelectable = < T extends any > (
10+ WrappedComponent : ComponentType < TSelectableItemProps & T >
11+ ) : ComponentType < T & TAddedProps > =>
12+ class SelectableItem extends Component < T & TAddedProps , TSelectableItemState > {
13+ static contextType = SelectableGroupContext
1514
1615 static defaultProps = {
1716 isSelected : false
@@ -27,16 +26,16 @@ const createSelectable = (WrappedComponent: ComponentType<any>) =>
2726 bounds : TComputedBounds [ ] | null = null
2827
2928 componentDidMount ( ) {
30- this . registerSelectable ( )
29+ this . updateBounds ( )
30+ this . context . selectable . register ( this )
3131 }
3232
3333 componentWillUnmount ( ) {
3434 this . context . selectable . unregister ( this )
3535 }
3636
37- registerSelectable = ( containerScroll ?: TGetBoundsForNodeArgs ) => {
37+ updateBounds = ( containerScroll ?: TGetBoundsForNodeArgs ) => {
3838 this . bounds = getBoundsForNode ( this . node ! , containerScroll )
39- this . context . selectable . register ( this )
4039 }
4140
4241 getSelectableRef = ( ref : HTMLElement | null ) => {
@@ -49,5 +48,3 @@ const createSelectable = (WrappedComponent: ComponentType<any>) =>
4948 )
5049 }
5150 }
52-
53- export default createSelectable
0 commit comments