Skip to content

Commit

Permalink
Modernize README.md example
Browse files Browse the repository at this point in the history
  • Loading branch information
RauliL committed Jan 10, 2025
1 parent b3a4382 commit 2907b40
Showing 1 changed file with 34 additions and 27 deletions.
61 changes: 34 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,42 @@ Pakertaja is a minimal JavaScript library for constructing DOM elements.
```JavaScript
import p from 'pakertaja';

function renderProduct(product) {
return p.div(
{ class: 'product' },

p.h1(product.title),

p.p(product.description),

p.form(
p.label({ for: 'quantity' }, 'Quantity: '),
p.input({ type: 'number', id: 'quantity', min: 10 }),
p.button(
'Add to cart',
{
type: 'submit',
onclick: (ev) => {
ev.preventDefault();
alert(`Added ${document.getElementById('quantity').value} products into cart.`);
},
const renderProduct(title, description) => p.div(
{
class: 'product',
style: {
background: 'black',
color: 'white'
}
},

p.h1(title),

p.p(description),

p.form(
p.label({ for: 'quantity' }, 'Quantity: '),
p.input({ type: 'number', id: 'quantity', min: 10 }),
p.button(
'Add to cart',
{
type: 'submit',
onclick(ev) {
ev.preventDefault();
alert(`Added ${document.getElementById('quantity').value} products into cart.`);
}
)
}
)
);
}

p.append(document.body, renderProduct({
title: 'Battlefield Earth DVDs',
description: 'Critically acclaimed as one of the best movies ever made.',
}));
)
);

p.append(
document.body,
renderProduct(
'Battlefield Earth DVDs',
'Critically acclaimed as one of the best movies ever made.'
)
);
```

## API
Expand Down

0 comments on commit 2907b40

Please sign in to comment.