Skip to content

Commit e6d2527

Browse files
Update example.php
1 parent 22a37bd commit e6d2527

File tree

1 file changed

+42
-29
lines changed

1 file changed

+42
-29
lines changed

example.php

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,43 +5,56 @@
55

66
include_once 'React.php';
77

8-
Component::registerTag('safwan');
9-
10-
class CustomComponent extends Component{
11-
var $state = ['test' => 1];
12-
13-
function componentDidUpdate($prevState, $currState){
8+
class Header extends Component{
9+
function render(){
10+
return new div('This is Header',
11+
['class'=> 'navbar navbar-expand-lg navbar-dark bg-dark p-3 text-white']);
1412
}
15-
13+
}
14+
class Content extends Component{
1615
function render(){
17-
$test = $this->state['test'];
18-
19-
return new div([
20-
new p('Hello World', ['style'=> 'color:red;background:blue']),
21-
new div('Many div'),
22-
new button("set my state ($test)", ['onclick'=> "phpReact.setState('$this->id', {test: ".($test+1)."})"])
23-
], ['style'=> 'border:1px solid #eee;border-radius:4px;max-width:500px;padding:5px;margin:10px', 'id'=> $this->id]);
16+
return new div(
17+
new div(array_map(function(){
18+
return new div(new Card, ['class' => 'col-md-2 my-2']);
19+
}, range(0, 11)), ['class'=> 'row']),
20+
['class'=> 'container py-2']);
2421
}
2522
}
2623

27-
class App extends Component{
24+
class Card extends Component{
25+
var $state = ['counter' => 1];
26+
2827
function render(){
29-
$customs = [];
30-
for($i=0;$i<3; $i++){
31-
$customs[] = new CustomComponent;
32-
}
28+
$counter = $this->state->counter;
3329

3430
return new div([
35-
new safwan('Hi I am safwan tag', ['onclick'=> 'alert("hello")']),
36-
new form([
37-
new img(['src'=> 'https://image.flaticon.com/icons/png/512/1453/1453608.png']),
38-
new select([
39-
new option('hi'),
40-
new option('hello'),
41-
], ['name'=> 'select']),
42-
new input(['type'=>'submit'])
43-
])
44-
] + $customs );
31+
new div($counter, ['class'=> 'card-body']),
32+
new div([
33+
new button('update state', [
34+
'onclick'=> 'phpReact.setState("'.$this->id.'", prevState => ({counter: prevState.counter + 1}))',
35+
'class' => 'm-auto btn btn-primary'
36+
]),
37+
], ['class'=> 'card-footer'])
38+
], ['class'=> 'card', 'id'=> $this->id]);
39+
}
40+
}
41+
42+
class Footer extends Component{
43+
function render(){
44+
return new div('This is Footer',
45+
['style'=> 'border-top:1px solid;padding:5px;font-size:18px;position:absolute;bottom:0;width:100%']);
46+
}
47+
}
48+
49+
class App extends Component{
50+
function render(){
51+
return [
52+
new link(['href'=> 'https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css', 'rel'=> 'stylesheet']),
53+
new Header,
54+
new Content,
55+
new Footer,
56+
new script(null,['src'=> 'https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js']),
57+
];
4558
}
4659
}
4760

0 commit comments

Comments
 (0)