Skip to content

Commit 5691c82

Browse files
committed
add docs for button
1 parent d3ca898 commit 5691c82

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

packages/app/src/Sidebar.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Sidebar extends Component {
7373
<FocusableItem focusKey="sidebar-item-3" text="Stockholm" idx={200} />
7474
<View style={styles.buttonContainer}>
7575
<Button
76-
color="blue'"
76+
color="#2196F3''"
7777
title="Navigate"
7878
onClick = {()=>{}}
7979
/>

packages/docs/components-button.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
id: components-button
3+
title: Button
4+
sidebar_label: Button
5+
---
6+
7+
8+
A component for creating a Button.
9+
10+
The following example shows how to render a Button.
11+
```JS
12+
import React from "react";
13+
import { Button, View, render } from "react-ape";
14+
15+
class ImageExample extends React.Component {
16+
render() {
17+
return (
18+
<View>
19+
<Button
20+
title="Click Me"
21+
color="#2196F3'"
22+
onClick ={()=>{}}
23+
/>
24+
</View>
25+
);
26+
}
27+
}
28+
```
29+
<iframe src="https://codesandbox.io/embed/24zmzm07my?hidenavigation=1" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>

packages/react-ape/renderer/elements/Button.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import {ButtonDefaults} from '../constants';
99
import {trackMousePosition,isMouseInside} from '../utils'
10+
import type {CanvasComponentContext} from '../types'
1011
//TODO adjust Opacity when focus, Blur
1112
type PressEvent = {||};
1213
type ButtonProps = {|
@@ -65,8 +66,8 @@ type ButtonProps = {|
6566
testID?: ?string,
6667
|};
6768

68-
function renderButton(props: ButtonProps, apeContext, parentLayout) {
69-
const {spatialGeometry = {x: 0, y: 0}} = parentLayout;
69+
function renderButton(props: ButtonProps, apeContext:CanvasComponentContext, parentLayout) {
70+
const {spatialGeometry } = parentLayout;
7071
const {ctx} = apeContext;
7172

7273
// If is relative and x and y haven't be processed, don't render
@@ -160,11 +161,22 @@ function renderButton(props: ButtonProps, apeContext, parentLayout) {
160161

161162

162163

164+
165+
// TODO:
166+
/**
167+
* We need to remove addEventListeners from the renderButton
168+
* function because this function runs for each state/prop update.
169+
* It will keep creating/refreshing listeners for every render.
170+
171+
We can keep this way, if we run this addEventListener
172+
once by checking if the listener already exist.
173+
Note onClick will need to share scope with this function to work properly.
174+
*/
163175
ctx.canvas.addEventListener('click', onClick, false);
164176
ctx.canvas.addEventListener('focus', redrawButton);
165177
ctx.canvas.addEventListener('blur', redrawButton);
166178

167-
// events
179+
168180
}
169181

170182
export default function createButtonInstance(props: ButtonProps): mixed {

packages/react-ape/renderer/reactApeRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ const ReactApeFiber = reconciler({
116116

117117
if (diff) {
118118
const parentLayout = element.parentLayout || element.getParentLayout();
119-
if (type === 'Text') {
119+
if (type === 'Text' ) {
120120
parentLayout.resetLayout(); // View needs to be reset on text updates
121121
}
122122

packages/react-ape/renderer/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function trackMousePosition(canvas, event):MouseEventType {
1616
y: event.clientY - canvas.offsetTop,
1717
};
1818
}
19-
export const isMouseInside = (pos, rect):Boolean => {
19+
export const isMouseInside = (pos, rect):boolean => {
2020
return (
2121
pos.x > rect.x &&
2222
pos.x < rect.x + rect.width &&

packages/website/sidebars.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
"Components": [
1717
"components-image",
1818
"components-text",
19-
"components-view"
19+
"components-view",
20+
"components-button"
2021
],
22+
2123
"APIs": [
2224
"apis-dimensions",
2325
"apis-platform",

0 commit comments

Comments
 (0)