Skip to content

Commit 33a3b26

Browse files
committed
Create a Real-World Example #7144
1 parent dfec6c4 commit 33a3b26

3 files changed

Lines changed: 42 additions & 5 deletions

File tree

.github/epic-string-based-templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ After the feature is functionally complete and well-tested, refactor the new mod
163163

164164
### 12. Create a Real-World Example
165165

166-
**Status: To Do**
166+
**Status: Done**
167167

168168
**Description:**
169169
To showcase the new feature and provide a practical learning resource, create a new, simple example application that is built using a functional component with a string-based template. This will serve as a clear, working demonstration for developers.

examples/functional/templateComponent/Component.mjs

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,46 @@ export default defineComponent({
1616
* @member {String} greeting_='Hello'
1717
* @reactive
1818
*/
19-
greeting_: 'Hello'
19+
greeting_: 'Hello',
20+
/**
21+
* @member {String} jobTitle_='Neo.mjs Developer'
22+
* @reactive
23+
*/
24+
jobTitle_: 'Neo.mjs Developer'
2025
},
2126

2227
createTemplateVdom(config) {
23-
const [name, setName] = useConfig('World');
28+
const [isActive, setIsActive] = useConfig(true);
29+
30+
useEvent('click', () => setIsActive(prev => !prev));
31+
32+
const cardStyle = {
33+
border : '1px solid #eee',
34+
borderRadius: '8px',
35+
padding : '16px',
36+
textAlign : 'center',
37+
cursor : 'pointer',
38+
boxShadow : '0 2px 4px rgba(0,0,0,0.1)'
39+
};
2440

25-
useEvent('click', () => setName(prev => prev === 'Neo' ? 'World' : 'Neo'));
41+
const statusStyle = {
42+
display : 'inline-block',
43+
padding : '4px 8px',
44+
borderRadius : '12px',
45+
color : 'white',
46+
backgroundColor: isActive ? '#28a745' : '#dc3545',
47+
fontSize : '12px',
48+
marginTop : '10px'
49+
};
2650

2751
return html`
28-
<div>${config.greeting}, ${name}</div>
52+
<div style="${cardStyle}">
53+
<h2>${config.greeting}, Neo!</h2>
54+
<p>${config.jobTitle}</p>
55+
<div style="${statusStyle}">
56+
${isActive ? 'Active' : 'Inactive'}
57+
</div>
58+
</div>
2959
`
3060
}
3161
});

examples/functional/templateComponent/MainContainer.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ class MainContainer extends ConfigurationViewport {
2424
listeners : {change: me.onConfigChange.bind(me, 'greeting')},
2525
style : {marginTop: '10px'},
2626
value : me.exampleComponent.greeting
27+
}, {
28+
module : TextField,
29+
clearable : true,
30+
labelText : 'jobTitle',
31+
listeners : {change: me.onConfigChange.bind(me, 'jobTitle')},
32+
style : {marginTop: '10px'},
33+
value : me.exampleComponent.jobTitle
2734
}]
2835
}
2936

0 commit comments

Comments
 (0)