Skip to content

Commit

Permalink
Remove mapChildProps option
Browse files Browse the repository at this point in the history
The caller can transform the props themselves via the function that
receives them.
  • Loading branch information
ragalie committed May 17, 2020
1 parent 0dfcab4 commit 642c719
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 191 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ The function provided will receive the following object:
}
}
```
This structure may be customized by implementing `mapChildProps` API feature.

The information in `detectedEnvironment` is acquired from interaction with this component and will be unset until the first interaction.

## Props API
Expand All @@ -88,12 +86,6 @@ All props are optional.

**isEnabled** : Boolean - Enable or disable cursor position monitoring without remounting. Defaults to true.

**mapChildProps** : Function - Model child component props to your custom shape.
Function receives one parameter with the signature
`{ isActive: Boolean, isPositionOutside: Boolean, position: { x: Number, y: Number } }`.
It should return an object that is compatible with the props interface of your child components.
See [example demo](https://ethanselzer.github.io/react-cursor-position/#/map-child-props).

**onActivationChanged** : Function - Called when the component is active.
Function receives one parameter with the signature `{ isActive: Boolean }`.

Expand Down
44 changes: 0 additions & 44 deletions example/public/map-child-props.html

This file was deleted.

21 changes: 0 additions & 21 deletions example/src/components/MapProps.js

This file was deleted.

1 change: 0 additions & 1 deletion example/src/pages/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class App extends Component {
<NavItem href="#/activate-by-touch">Activate by Touch</NavItem>
<NavItem href="#/class-name">Class Name</NavItem>
<NavItem href="#/hover-delay">Hover Delay</NavItem>
<NavItem href="#/map-child-props">Map Child Props</NavItem>
<NavItem href="#/detected-environment-changed">On Environment Changed</NavItem>
<NavItem href="#/on-position-changed">On Position Changed</NavItem>
<NavItem href="#/on-activation-changed">On Activation Changed</NavItem>
Expand Down
73 changes: 0 additions & 73 deletions example/src/pages/MapProps.js

This file was deleted.

2 changes: 0 additions & 2 deletions example/src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import ClassName from './pages/ClassName';
import PositionChanged from './pages/PositionChanged';
import Home from './pages/Home';
import ImageMagnify from './pages/ImageMagnify';
import MapProps from './pages/MapProps';
import Style from './pages/Style';
import Support from './pages/Support';
import DetectedEnvironmentChanged from './pages/DetectedEnvironmentChanged';
Expand All @@ -28,7 +27,6 @@ const Routes = (props) => (
<Route path="/activate-by-touch" component={ActivatedByTouch} />
<Route path="/activate-by-tap" component={ActivateByTap} />
<Route path="/activate-by-press" component={ActivateByPress} />
<Route path="/map-child-props" component={MapProps} />
<Route path="/on-position-changed" component={PositionChanged} />
<Route path="/on-activation-changed" component={ActivationChanged} />
<Route path="/style" component={Style} />
Expand Down
1 change: 0 additions & 1 deletion src/ReactCursorPosition.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ interface CursorPositionOptionsProps {
className?: string;
hoverDelayInMs?: number;
isEnabled?: boolean;
mapChildProps?: (CursorPositionGeneratedProps) => object;
onActivationChanged?: ({isActive: boolean}) => void;
onDetectedEnvironmentChanged?: (DetectedEnvironment) => void;
onPositionChanged?: (CursorPositionGeneratedProps) => void;
Expand Down
6 changes: 2 additions & 4 deletions src/ReactCursorPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export default class extends React.Component {
hoverDelayInMs: PropTypes.number,
hoverOffDelayInMs: PropTypes.number,
isEnabled: PropTypes.bool,
mapChildProps: PropTypes.func,
onActivationChanged: PropTypes.func,
onDetectedEnvironmentChanged: PropTypes.func,
onPositionChanged: PropTypes.func,
Expand All @@ -95,7 +94,6 @@ export default class extends React.Component {
hoverDelayInMs: 0,
hoverOffDelayInMs: 0,
isEnabled: true,
mapChildProps: props => props,
onActivationChanged: noop,
onDetectedEnvironmentChanged: noop,
onPositionChanged: noop,
Expand Down Expand Up @@ -453,10 +451,10 @@ export default class extends React.Component {
}

render() {
const { children, className, mapChildProps, style } = this.props;
const { children, className, style } = this.props;
const props = objectAssign(
{},
mapChildProps(this.state),
this.state,
this.getPassThroughProps()
);

Expand Down
36 changes: 0 additions & 36 deletions test/ReactCursorPosition.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,42 +624,6 @@ describe('ReactCursorPosition', () => {
expect(tree.css('width')).toBe('100px');
});

it('supports mapChildProps', () => {
function mapChildProps({ elementDimensions, isActive, isPositionOutside, position }) {
return {
elementDimensions,
isOperative: isActive,
isAlfresco: isPositionOutside,
point: position
};
}
const tree = getMountedComponentTree({
mapChildProps,
activationInteractionMouse: INTERACTIONS.CLICK,
activationInteractionTouch: INTERACTIONS.TOUCH
});
const instance = tree.instance();

instance.componentDidMount();
instance.onTouchStart(touchEvent);
instance.onTouchMove(touchEvent);
tree.update();

const childComponent = tree.find(GenericSpanComponent);
expect(childComponent.props()).toEqual({
elementDimensions: {
width: 4,
height: 4
},
isOperative: true,
isAlfresco: false,
point: {
x: 1,
y: 2
}
});
});

it('supports onPositionChanged callback', () => {
const spy = jest.fn();
const tree = getMountedComponentTree({
Expand Down
1 change: 0 additions & 1 deletion test/__snapshots__/ReactCursorPosition.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ Object {
"hoverDelayInMs": 0,
"hoverOffDelayInMs": 0,
"isEnabled": true,
"mapChildProps": [Function],
"onActivationChanged": [Function],
"onDetectedEnvironmentChanged": [Function],
"onPositionChanged": [Function],
Expand Down

0 comments on commit 642c719

Please sign in to comment.