This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtemplate.tsx
More file actions
126 lines (122 loc) · 5.58 KB
/
template.tsx
File metadata and controls
126 lines (122 loc) · 5.58 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { MenuComponent, FieldSettingsModel } from '@syncfusion/ej2-react-navigations';
import { SampleBase } from '../common/sample-base';
import './template.css';
/**
* Menu Template sample
*/
export class Template extends SampleBase<{}, {}> {
//Template datasource
public menuitems: { [key: string]: Object }[] = [
{
category: 'Products',
options: [
{ value: 'JavaScript', url: 'javascript' },
{ value: 'Angular', url: 'angular' },
{ value: 'ASP.NET Core', url: 'core' },
{ value: 'ASP.NET MVC', url: 'mvc' }
]
},
{
category: 'Services',
options: [
{
support: [
{ value: 'Application Development', count: '1200+' },
{ value: 'Maintenance & Support', count: '3700+' },
{ value: 'Quality Assurance' },
{ value: 'Cloud Integration', count: '900+' }
]
}
]
},
{
category: 'About Us',
options: [
{
about: {
value: "We are on a mission to provide world-class best software solutions for web, mobile and desktop platforms. Around 900+ applications are desgined and delivered to our customers to make digital & strengthen their businesses."
}
}
]
},
{ category: 'Careers' },
{ category: 'Sign In' }
];
menuTemplate(data: any): JSX.Element {
return (
data.category ? <span>{data.category}</span> :
(data.value && data.url) ?
<div className='e-avatar e-avatar-small image' style={{ backgroundImage: 'url(src/menu/images/' + data.url + '.png)' }}>{data.value}</div> :
data.support ?
<ul>
{
data.support.map((supp) => <li>
{supp.value}
{
supp.count ? <span className='e-badge e-badge-success'>{supp.count}</span> : ""
}
</li>)
}
</ul> :
<div tabIndex={0} className="e-card">
<div className="e-card-header">
<div className="e-card-header-caption">
<div className="e-card-header-title">About Us</div>
</div>
</div>
<div className="e-card-content">
{data.about.value}
</div>
<div className="e-card-actions">
<button className="e-btn e-outline">
Read More
</button>
</div>
</div>
);
}
//Menu fields definition
public menuFields: FieldSettingsModel = {
text: ['category', 'value'],
children: ['options']
};
render() {
return (
<div className='control-pane'>
<div className='control-section'>
<div className='menu-section'>
<div className='template-menu-control'>
<MenuComponent items={this.menuitems} fields={this.menuFields} template={this.menuTemplate}></MenuComponent>
</div>
</div>
</div>
<div id="action-description">
<p>
This sample demonstrates the template functionalities of the <code>menu</code> component. Interact with <code>menu</code> using hover / click to display sub menu pop-up items with its customized templates.
</p>
</div>
<div id="description">
<p>
The menu component has an option to customize menu items using the <code>template</code> property, so that the menu items can be rendered according to the requirement.
</p>
<p>
In this demo, the below customization are demonstrated.
<ul>
<li>Header menu items and the 'Products' sub menu items represents the customization of default rendering of li elements i.e. <b>data.category</b> in template.</li>
<li>'Services' sub menu item represent the customization of single li element with simulate the default rendering of Products sub menu items
i.e. ul li elements with added <code>badge</code> component are rendered in a single li with customized css styles.</li>
<li>'About Us' sub menu item showed with <code>card</code> component in a single li.</li>
</ul>
</p>
<p>
For more information, refer to the
<a target="_blank" href="http://ej2.syncfusion.com/react/documentation/menu/template.html">
templates</a> section in the documentation.
</p>
</div>
</div>
)
}
}