{"id":13400979,"url":"https://github.com/tleunen/react-clickdrag","last_synced_at":"2025-03-16T10:31:50.855Z","repository":{"id":22111054,"uuid":"25441508","full_name":"tleunen/react-clickdrag","owner":"tleunen","description":"Easily click and drag a react component","archived":false,"fork":false,"pushed_at":"2020-07-13T21:39:26.000Z","size":70,"stargazers_count":54,"open_issues_count":2,"forks_count":8,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-14T05:15:31.131Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tleunen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-19T21:57:00.000Z","updated_at":"2023-12-31T01:35:34.000Z","dependencies_parsed_at":"2022-08-20T21:10:06.554Z","dependency_job_id":null,"html_url":"https://github.com/tleunen/react-clickdrag","commit_stats":null,"previous_names":["tleunen/react-clickdrag-mixin"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Freact-clickdrag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Freact-clickdrag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Freact-clickdrag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tleunen%2Freact-clickdrag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tleunen","download_url":"https://codeload.github.com/tleunen/react-clickdrag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814898,"owners_count":20352037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T19:00:57.582Z","updated_at":"2025-03-16T10:31:50.568Z","avatar_url":"https://github.com/tleunen.png","language":"JavaScript","readme":"# react-clickdrag\n![npm][npm-version-image] [![Build Status][ci-image]][ci-url] [![Coverage Status][coverage-image]][coverage-url]\n\nWith `react-clickdrag`, you'll be able to easily add a click and drag feature on every component you want.\n\n## Usage\n\n`react-clickdrag` is a special function which takes 2 arguments. The first one is the Component itself, the second argument is the options `react-clickdrag` can take.\n\nThe options are:\n- `touch`: Enable touch events (default: false)\n- `resetOnSpecialKeys`: Decide to reset the mouse position when a special keys is pressed (ctrl, shift, alt). (default: false)\n- `getSpecificEventData`: Function to specify if you need specific data from the mouse/touch event. (default: empty function)\n- `onDragStart`: Function called when you start dragging the component. (default: empty function)\n- `onDragStop`: Function called when you stop dragging the component. (default: empty function)\n- `onDragMove`: Function called when you move the component. (default: empty function)\n\nWhen you wrap your component using the `clickdrag` function, your component will receive a special props called `dataDrag`. Inside this `dataDrag` object, you'll find these information:\n- `isMouseDown` (boolean)\n- `isMoving` (boolean)\n- `mouseDownPositionX` (number)\n- `mouseDownPositionY` (number)\n- `moveDeltaX` (number)\n- `moveDeltaY` (number)\n\nIf you defined a specific event data function using `getSpecificEventData`. You'll also find the information you specify in the `dataDrag` props.\n\n## Example\n\nHere's a copy of the example you can find in [example folder](/examples/basic/)\n\n```js\nimport clickdrag from 'react-clickdrag';\n\n\nclass ExampleComponent extends React.Component {\n\n    constructor(props) {\n        super(props);\n\n        this.state = {\n            lastPositionX: 0,\n            lastPositionY: 0,\n            currentX: 0,\n            currentY: 0\n        };\n    }\n\n    componentWillReceiveProps(nextProps) {\n        if(nextProps.dataDrag.isMoving) {\n            this.setState({\n                currentX: this.state.lastPositionX + nextProps.dataDrag.moveDeltaX,\n                currentY: this.state.lastPositionY + nextProps.dataDrag.moveDeltaY\n            });\n        }\n        else {\n            this.setState({\n                lastPositionX: this.state.currentX,\n                lastPositionY: this.state.currentY\n            });\n        }\n    }\n\n    render() {\n        var translation = 'translate('+this.state.currentX+'px, '+this.state.currentY+'px)';\n\n        return React.createElement('div', {\n            style: {width: '200px', height: '200px', backgroundColor: 'red', transform: translation}\n        });\n    }\n}\n\nvar ClickDragExample = clickDrag(ExampleComponent, {touch: true});\n\nexport default ClickDragExample;\n\n```\nYou can find another example of this module inside [react-number-editor](https://github.com/tleunen/react-number-editor).\n\n## License\n\nMIT, see [LICENSE.md](/LICENSE.md) for details.\n\n\n[ci-image]: https://circleci.com/gh/tleunen/react-clickdrag.svg?style=shield\n[ci-url]: https://circleci.com/gh/tleunen/react-clickdrag\n[coverage-image]: https://codecov.io/gh/tleunen/react-clickdrag/branch/master/graph/badge.svg\n[coverage-url]: https://codecov.io/gh/tleunen/react-clickdrag\n[npm-version-image]: https://img.shields.io/npm/v/react-clickdrag.svg\n","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftleunen%2Freact-clickdrag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftleunen%2Freact-clickdrag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftleunen%2Freact-clickdrag/lists"}