Skip to content
Snippets Groups Projects
Commit fa2882a7 authored by Thomas Fritsch's avatar Thomas Fritsch
Browse files

C.2. modules natifs

parent 4009e6bd
Branches
Tags
No related merge requests found
{
"presets": ["@babel/env"],
"presets": [
["@babel/env", {"modules": false}]
],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
\ No newline at end of file
......@@ -11,7 +11,7 @@
<link rel="stylesheet" type="text/css" href="css/flatly-bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script src="build/main.js" defer></script>
<script type="module" src="build/main.js"></script>
</head>
<body>
<main id="appContainer">
......
export default class Component {
tag;
attribute;
children;
constructor(tag, attribute, children) {
this.tag = tag;
this.attribute = attribute;
this.children = children;
}
render() {
return `<${this.tag} ${this.renderAttributes()} ${
this.children ? `>${this.children}</${this.tag}>` : ' />'
}`;
}
renderAttributes() {
if (this.attribute) {
return `${this.attribute.name}="${this.attribute.value}"`;
}
return '';
}
}
import Component from './Component.js';
export default class Img extends Component {
constructor(url) {
super('img', { name: 'src', value: url });
}
}
const data = [
{
nom: 'Regina',
base: 'tomate',
prix_petite: 6.5,
prix_grande: 9.95,
image:
'https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300',
},
{
nom: 'Napolitaine',
base: 'tomate',
prix_petite: 6.5,
prix_grande: 8.95,
image:
'https://images.unsplash.com/photo-1562707666-0ef112b353e0?&fit=crop&w=500&h=300',
},
{
nom: 'Spicy',
base: 'crème',
prix_petite: 5.5,
prix_grande: 8,
image:
'https://images.unsplash.com/photo-1458642849426-cfb724f15ef7?fit=crop&w=500&h=300',
},
];
export default data;
const data = [
{
nom: 'Regina',
base: 'tomate',
prix_petite: 6.5,
prix_grande: 9.95,
image:
'https://images.unsplash.com/photo-1532246420286-127bcd803104?fit=crop&w=500&h=300',
},
{
nom: 'Napolitaine',
base: 'tomate',
prix_petite: 6.5,
prix_grande: 8.95,
image:
'https://images.unsplash.com/photo-1562707666-0ef112b353e0?&fit=crop&w=500&h=300',
},
{
nom: 'Spicy',
base: 'crème',
prix_petite: 5.5,
prix_grande: 8,
image:
'https://images.unsplash.com/photo-1458642849426-cfb724f15ef7?fit=crop&w=500&h=300',
},
];
class Component {
tag;
attribute;
children;
constructor(tag, attribute, children) {
this.tag = tag;
this.attribute = attribute;
this.children = children;
}
render() {
return `<${this.tag} ${this.renderAttributes()} ${
this.children ? `>${this.children}</${this.tag}>` : ' />'
}`;
}
renderAttributes() {
if (this.attribute) {
return `${this.attribute.name}="${this.attribute.value}"`;
}
return '';
}
}
class Img extends Component {
constructor(url) {
super('img', { name: 'src', value: url });
}
}
import data from './data.js';
import Component from './components/Component.js';
import Img from './components/Img.js';
const title = new Component('h1', null, 'La carte');
document.querySelector('.pageTitle').innerHTML = title.render();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment