-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcountries-no-spa-graphql.htm
More file actions
130 lines (117 loc) · 5.2 KB
/
countries-no-spa-graphql.htm
File metadata and controls
130 lines (117 loc) · 5.2 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
127
128
129
130
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Countries Demo | No SPA | GraphQL + React</title>
<link rel="stylesheet" href="css/countries.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui-flag@2.4.0/flag.min.css">
<link rel="canonical" href="https://www.dataformsjs.com/examples/countries-no-spa-hbs.htm">
</head>
<body>
<div id="view">
<h1>Countries</h1>
<div id="root"></div>
</div>
</div>
<!-- React -->
<script src="https://cdn.jsdelivr.net/npm/react@17.0.2/umd/react.production.min.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@17.0.2/umd/react-dom.production.min.js" crossorigin="anonymous"></script>
<!-- DataFormsJS React Components -->
<script type="module" src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/react/es6/DataFormsJS.min.js"></script>
<script nomodule src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/react/es5/DataFormsJS.min.js"></script>
<!-- DataFormsJS JSX Loader -->
<script src="https://cdn.jsdelivr.net/npm/dataformsjs@5/js/react/jsxLoader.min.js"></script>
<script>
// Set to `true` to view compiler details
jsxLoader.logCompileTime = false;
jsxLoader.logCompileDetails = false;
</script>
<script type="text/babel">
const format = new Format();
function toggleHighlight(e) {
if (e.target.nodeName === 'A') {
return;
}
e.currentTarget.classList.toggle('highlight');
}
function ShowLoading() {
return <h3 className="loading">Loading...</h3>;
}
function ShowError(props) {
return <p className="error">{props.error}</p>;
}
function ShowCountries(props) {
return (
<React.Fragment>
<InputFilter
filter-selector="table"
filter-results-selector="h1"
filter-results-text-all="{totalCount} Countries"
filter-results-text-filtered="Showing {displayCount} of {totalCount} Countries"
placeholder="Enter filter, example 'North America'" />
<p>Click on a column to sort rows based on column values.</p>
<SortableTable
data-sort-class-odd="row-odd"
data-sort-class-even="row-even">
<thead>
<tr>
<th>Code</th>
<th>Name</th>
<th>Size (KM)</th>
<th>Population</th>
<th>Continent</th>
</tr>
</thead>
<tbody>
{props.data && props.data.countries && props.data.countries.map(country => {
return (
<tr key={country.iso} onClick={toggleHighlight} className="pointer">
<td>
<i class={country.iso.toLowerCase() + ' flag'}></i>
<span>{country.iso}</span>
</td>
<td>{country.country}</td>
<td className="align-right" data-value={country.area_km}>{format.number(country.area_km)}</td>
<td className="align-right" data-value={country.population}>{format.number(country.population)}</td>
<td>{country.continent}</td>
</tr>
)
})}
</tbody>
</SortableTable>
</React.Fragment>
)
}
class App extends React.Component {
render() {
return (
<ErrorBoundary>
<JsonData
url="https://www.dataformsjs.com/graphql"
graphQL={true}
query={`
{
countries {
iso
country
area_km
population
continent
}
}
`}
isLoading={<ShowLoading />}
hasError={<ShowError />}
isLoaded={<ShowCountries />} />
</ErrorBoundary>
)
}
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
</script>
</body>
</html>