Skip to content

Instantly share code, notes, and snippets.

@3cp
Last active October 24, 2024 09:27
Show Gist options
  • Save 3cp/ad6f9292c4778d3fa30a450db2319ac0 to your computer and use it in GitHub Desktop.
Save 3cp/ad6f9292c4778d3fa30a450db2319ac0 to your computer and use it in GitHub Desktop.
bcx-aurelia-reorderable-repeat example: basics
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to aurelia-bootstrapper
(data-main attribute on script) for Aurelia,
The aurelia bootstrapper then loads up user module "main"
(aurelia-app attribute on <body>) which is your src/main.js.
-->
<body aurelia-app="main">
<script src="/dist/entry-bundle.js" data-main="aurelia-bootstrapper"></script>
</body>
</html>
{
"dependencies": {
"aurelia-bootstrapper": "^2.3.3"
}
}
<template>
<require from="./list-container"></require>
<require from="./list-container2"></require>
<div style="display:flex">
<list-container></list-container>
<list-container2></list-container2>
</div>
</template>
export class App {
}
.container {
width: 200px;
margin: 5px;
}
.item {
display: block;
box-sizing: border-box;
border: 1px solid #333;
width: 100%;
height: 50px;
text-align: center;
line-height: 50px;
overflow: hidden;
background: white;
}
.item:not(:first-child) {
margin-top: -1px;
}
<template>
<require from="./list-container.css"></require>
<p>Array of strings</p>
<div class="container">
<div class="item" reorderable-repeat.for="item of items">
${item}
</div>
</div>
</template>
export class ListContainer {
items = ['first', 'second', 'third', 'fourth'];
}
<template>
<require from="./list-container.css"></require>
<p>Array of objects</p>
<div class="container">
<div class="item" reorderable-repeat.for="item of items">
#${item.id} ${item.value}
</div>
</div>
</template>
export class ListContainer2 {
items = [
{id: '0', value: 'first'},
{id: '1', value: 'second'},
{id: '2', value: 'third'},
{id: '3', value: 'fourth'}
];
}
export function configure(aurelia) {
aurelia.use
.standardConfiguration()
.developmentLogging('info')
.plugin('bcx-aurelia-reorderable-repeat');
aurelia.start().then(() => aurelia.setRoot());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment