Skip to content

Commit

Permalink
updated toggle example
Browse files Browse the repository at this point in the history
  • Loading branch information
flynneva committed May 20, 2020
1 parent 40f84ad commit a4d691a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-ros",
"version": "0.0.1",
"version": "0.0.2",
"description": "A React Component Library to help connect your website to your robot",
"author": "flynneva",
"license": "MIT",
Expand Down
7 changes: 4 additions & 3 deletions src/components/examples/ToggleConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import React from 'react'
import { useROS } from '../ROS'

function ToggleConnect() {
const { isConnected, topics, toggleConnection } = useROS();
const { isConnected, topics, url, toggleConnection } = useROS();

return (
<div>
<p><strong>ROS url:</strong> {url}</p>
<button onClick={ toggleConnection }>Toggle Connect</button>
<div>Status of ROS: { isConnected ? "connected" : "not connected" }</div>
<div>Topics detected:</div>
<p><strong>Status of ROS:</strong> { isConnected ? "connected" : "not connected" }</p>
<p><strong>Topics detected:</strong></p>
{ topics.map((topic, i) => <li key={i}> {topic.path}</li> )}
</div>
);
Expand Down
26 changes: 26 additions & 0 deletions src/components/examples/ToggleConnect.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ route: /examples/toggle_connect/
menu: Examples
---

## ToggleConnect

If you have ROS installed, go ahead and try out the demo below. Just start up a [rosbridge server](https://github.com/RobotWebTools/rosbridge_suite) using the default parameters and hit the button - you should see your topics listed along with the status of the connection changing too.

import { Playground } from 'docz'

import { ROS } from '../ROS'
Expand All @@ -15,3 +19,25 @@ import ToggleConnect from './ToggleConnect'
<ToggleConnect />
</ROS>
</Playground>


```javascript
import React from 'react'
import { useROS } from '../ROS'

function ToggleConnect() {
const { isConnected, topics, url, toggleConnection } = useROS();

return (
<div>
<p><strong>ROS url:</strong> {url}</p>
<button onClick={ toggleConnection }>Toggle Connect</button>
<p><strong>Status of ROS:</strong> { isConnected ? "connected" : "not connected" }</p>
<p><strong>Topics detected:</strong></p>
{ topics.map((topic, i) => <li key={i}> {topic.path}</li> )}
</div>
);
}

export default ToggleConnect;
```

0 comments on commit a4d691a

Please sign in to comment.