-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
68 lines (64 loc) · 1.67 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/**
* A Person component, for demo purposes.
*/
import { h, Fragment } from 'preact';
import Color from '../color';
/** @jsx h */
/** @jsxFrag Fragment */
const Person = ( { name, dob, favoriteColors, favoriteArtists, traits, showColors = true, showArtists = true, ...props } ) => {
const showTest = 'yes';
const favoriteColorsList = favoriteColors.map( ( color, index ) => {
return (
<Color color={ color } key={ index } />
);
} );
return (
<section class="profile">
<h1>{ name }</h1>
<p>Date of birth: { dob }</p>
{ showColors && (
<>
<h2>Favorite Colors</h2>
<div>{ favoriteColorsList }</div>
</>
) }
{ showArtists && (
<>
<h2>Favorite Artists</h2>
<div>
{ favoriteArtists.map( ( artist, index ) => {
return (
<div key={ index }>
{ artist.name } | { artist.genre }
</div>
)
} ) }
</div>
</>
) }
<h2>Character traits</h2>
{ traits.map( ( trait, index ) => {
return (
<div>A trait: { trait }</div>
);
} ) }
<h2>Character traits raw</h2>
{ traits }
<h2>Combining control + replace variables</h2>
{ showTest === 'yes' && name }
<h2>Combining control + list variables</h2>
{ showTest === 'yes' && traits }
</section>
);
}
Person.templateVars = [
'name',
'dob',
[ 'showColors', { type: 'control' } ],
[ 'showArtists', { type: 'control' } ],
[ 'favoriteColors', { type: 'list', child: { type: 'object', props: [ 'value', 'label' ] } } ],
[ 'favoriteArtists', { type: 'list', child: { type: 'object', props: [ 'name', 'genre' ] } } ],
[ 'traits', { type: 'list' } ],
[ 'showTest', { type: 'control' } ],
];
export default Person;