Skip to content

Commit

Permalink
Add aurelia 2 (#164)
Browse files Browse the repository at this point in the history
* add aurelia 2

* remove template from au2
  • Loading branch information
brandonseydel committed Apr 19, 2023
1 parent 2a52125 commit fbf1f0b
Show file tree
Hide file tree
Showing 57 changed files with 433 additions and 4 deletions.
1 change: 1 addition & 0 deletions content/1-reactivity/1-declare-state/aurelia2/name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello ${name}</h1>
3 changes: 3 additions & 0 deletions content/1-reactivity/1-declare-state/aurelia2/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class Name {
name = "John";
}
1 change: 1 addition & 0 deletions content/1-reactivity/2-update-state/aurelia2/name.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello ${name}</h1>
7 changes: 7 additions & 0 deletions content/1-reactivity/2-update-state/aurelia2/name.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Name {
name = "John";

constructor() {
this.name = "Jane";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>${doubleCount}</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export class DoubleCount {
count: number = 10;
doubleCount = this.count * 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello world</h1>
3 changes: 3 additions & 0 deletions content/2-templating/2-styling/aurelia2/css-style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.title {
color: red;
}
2 changes: 2 additions & 0 deletions content/2-templating/2-styling/aurelia2/css-style.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1 class="title">I am red</h1>
<button style="font-size: 10rem">I am a button</button>
3 changes: 3 additions & 0 deletions content/2-templating/3-loop/aurelia2/colors.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<ul>
<li repeat.for="color of colors">${color}</li>
</ul>
3 changes: 3 additions & 0 deletions content/2-templating/3-loop/aurelia2/colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class Colors {
colors = ["red", "green", "blue"];
}
2 changes: 2 additions & 0 deletions content/2-templating/4-event-click/aurelia2/counter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>Counter: ${count}</p>
<button click.trigger="incrementCount">+1</button>
7 changes: 7 additions & 0 deletions content/2-templating/4-event-click/aurelia2/counter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class Counter {
count: number = 0;

incrementCount() {
this.count++;
}
}
1 change: 1 addition & 0 deletions content/2-templating/5-dom-ref/aurelia2/input-focused.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input ref="inputElement" />
7 changes: 7 additions & 0 deletions content/2-templating/5-dom-ref/aurelia2/input-focused.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class InputFocused {
inputElement: HTMLInputElement;

attached() {
this.inputElement.focus();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<button click.trigger="nextLight()">Next light</button>
<p>Light is: ${light}</p>
<p switch.bind="light">
You must
<span case="red">STOP</span>
<span case="orange">SLOW DOWN</span>
<span case="green">GO</span>
</p>
16 changes: 16 additions & 0 deletions content/2-templating/6-conditional/aurelia2/traffic-light.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const TRAFFIC_LIGHTS = ["red", "orange", "green"];

export class App {
lightIndex = 0;
get light() {
return TRAFFIC_LIGHTS[this.lightIndex];
}

nextLight() {
if (this.lightIndex + 1 > TRAFFIC_LIGHTS.length - 1) {
this.lightIndex = 0;
} else {
this.lightIndex++;
}
}
}
1 change: 1 addition & 0 deletions content/3-lifecycle/1-on-mount/aurelia2/page-title.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Page title is: ${pageTitle}</p>
7 changes: 7 additions & 0 deletions content/3-lifecycle/1-on-mount/aurelia2/page-title.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class PageTitle {
pageTitle = "";

attached(): void {
this.pageTitle = document.title;
}
}
1 change: 1 addition & 0 deletions content/3-lifecycle/2-on-unmount/aurelia2/time.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Current time: ${time}</p>
14 changes: 14 additions & 0 deletions content/3-lifecycle/2-on-unmount/aurelia2/time.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export class Time {
time: string = new Date().toLocaleTimeString();
timer: number;

constructor() {
this.timer = setInterval(() => {
this.time = new Date().toLocaleTimeString();
}, 1000);
}

dispose() {
clearInterval(this.timer);
}
}
6 changes: 6 additions & 0 deletions content/4-component-composition/1-props/aurelia2/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<user-profile
name.bind
age.bind
favourite-colors.bind="colors"
is-available.bind="available"
></user-profile>
9 changes: 9 additions & 0 deletions content/4-component-composition/1-props/aurelia2/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { UserProfile } from "./user-profile";

export class App {
static dependencies = [UserProfile]; // static dependecies way or registered globablly
age = 20;
name = "John";
colors = ["green", "blue", "red"];
available = false;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<p>My name is ${name}</p>
<p>My age is ${age}</p>
<p>My favourite colors are ${favouriteColors.join(", ")}</p>
<p>I am ${isAvailable ? "available" : "not available"}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { bindable } from "aurelia";

export class UserProfile {
@bindable name = "";
@bindable age = null;
@bindable favouriteColors = [];
@bindable isAvailable = true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<button click.trigger="actionHandler(true)">YES</button>
<button click.trigger="actionHandler()">NO</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { bindable } from "aurelia";

export class AnswerButton {
@bindable actionHandler;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<p>Can I come ?</p>
<answer-button action-handler.bind="handleAnswer"></answer-button>
<p style="font-size: 50px">${canCome ? "馃榾" : "馃槬"}</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class App {
canCome = false;

handleAnswer = (answer = false) => {
this.canCome = answer;
};
}
1 change: 1 addition & 0 deletions content/4-component-composition/3-slot/aurelia2/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<funny-button>Click me !</funny-button>
19 changes: 19 additions & 0 deletions content/4-component-composition/3-slot/aurelia2/funny-button.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<let
style="
color: #fff;
padding: 10px 20px;
font-size: 30px;
border: 2px solid #fff;
margin: 8px;
transform: scale(0.9);
box-shadow: 4px 4px rgba(0, 0, 0, 0.4);
transition: transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s;
outline: 0;
background: rgba(0, 0, 0, 0.4);
"
>
</let>

<button style.bind="style">
<au-slot></au-slot>
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<funny-button></funny-button>
<funny-button>Click me !</funny-button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<let
style="
background: rgba(0, 0, 0, 0.4);
color: #fff;
padding: 10px 20px;
font-size: 30px;
border: 2px solid #fff;
margin: 8px;
transform: scale(0.9);
box-shadow: 4px 4px rgba(0, 0, 0, 0.4);
transition: transform 0.2s cubic-bezier(0.34, 1.65, 0.88, 0.925) 0s;
outline: 0;
"
>
</let>

<button style.bind="style">
<au-slot> No content </au-slot>
</button>
2 changes: 2 additions & 0 deletions content/4-component-composition/5-context/aurelia2/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Welcome back, {{ user.username }}</h1>
<user-profile />
5 changes: 5 additions & 0 deletions content/4-component-composition/5-context/aurelia2/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { user } from "./user-profile";

export class App {
user = user;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div>
<h2>My Profile</h2>
<p>Username: ${ user.username }</p>
<p>Email: ${ user.email }</p>
<button click.trigger="user.username = 'Jane'">
Update username to Jane
</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const user = {
id: 1,
username: "unicorn42",
email: "[email protected]",
};

export class UserProfile {
user = user;
}
2 changes: 2 additions & 0 deletions content/6-form-input/1-input-text/aurelia2/input-hello.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<p>${text}</p>
<input value.bind />
3 changes: 3 additions & 0 deletions content/6-form-input/1-input-text/aurelia2/input-hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class InputHello {
value: string = "Hello World";
}
2 changes: 2 additions & 0 deletions content/6-form-input/2-checkbox/aurelia2/is-available.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<input id="is-available" type="checkbox" checked.bind="isAvailable" />
<label for="is-available">Is available</label>: ${isAvailable}
3 changes: 3 additions & 0 deletions content/6-form-input/2-checkbox/aurelia2/is-available.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class IsAvailable {
isAvailable = false;
}
7 changes: 7 additions & 0 deletions content/6-form-input/3-radio/aurelia2/pick-pill.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>Picked: ${picked}</div>

<input id="blue-pill" checked.bind="picked" type="radio" value="blue" />
<label for="blue-pill">Blue pill</label>

<input id="red-pill" checked.bind="picked" type="radio" value="red" />
<label for="red-pill">Red pill</label>
3 changes: 3 additions & 0 deletions content/6-form-input/3-radio/aurelia2/pick-pill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export class PickPill {
picked = "red";
}
10 changes: 10 additions & 0 deletions content/6-form-input/4-select/aurelia2/color-select.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<select value.bind="selectedColorId">
<option value="">Select A Color</option>
<option
repeat.for="color of colors"
value.bind="color.id"
disabled.bind="color.isDisabled"
>
${color.text}
</option>
</select>
11 changes: 11 additions & 0 deletions content/6-form-input/4-select/aurelia2/color-select.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const colors = [
{ id: 1, text: "red" },
{ id: 2, text: "blue" },
{ id: 3, text: "green" },
{ id: 4, text: "gray", isDisabled: true },
];

export class Select {
selectedColorId = 2;
colors = colors;
}
1 change: 1 addition & 0 deletions content/7-webapp-features/1-render-app/aurelia2/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>Hello world</h1>
1 change: 1 addition & 0 deletions content/7-webapp-features/1-render-app/aurelia2/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class App {}
10 changes: 10 additions & 0 deletions content/7-webapp-features/1-render-app/aurelia2/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<script type="module" src="./main.ts"></script>
</head>

<body>
<app></app>
</body>
</html>
4 changes: 4 additions & 0 deletions content/7-webapp-features/1-render-app/aurelia2/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Aurelia } from "aurelia";
import { App } from "./app";

Aurelia.app(App).start();
19 changes: 19 additions & 0 deletions content/7-webapp-features/2-fetch-data/aurelia2/UseFetchUsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export class UseFetchUsers {
data = null;
error = null;
isLoading = false;

async fetchData() {
this.isLoading = true;
try {
const response = await fetch("https://randomuser.me/api/?results=3");
const { results: users } = await response.json();
this.data = users;
this.error = null;
} catch (err) {
this.data = null;
this.error = err;
}
this.isLoading = false;
}
}
10 changes: 10 additions & 0 deletions content/7-webapp-features/2-fetch-data/aurelia2/app.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template promise.bind="useFetchUsers.fetchData()">
<p pending>Fetching users...</p>
<p catch>An error ocurred while fetching users</p>
<ul then.from-view="users">
<li repeat.for="user of users">
<img src.bind="user.picture.thumbnail" alt="user" />
<p>${ user.name.first } ${ user.name.last }</p>
</li>
</ul>
</template>
6 changes: 6 additions & 0 deletions content/7-webapp-features/2-fetch-data/aurelia2/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { UseFetchUsers } from "./UseFetchUsers";

export class App {
// eslint-disable-next-line no-unused-vars
constructor(private useFetchUsers: UseFetchUsers) {}
}
12 changes: 12 additions & 0 deletions content/7-webapp-features/3-router-link/aurelia2/router-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
See [Add routes and a viewport](https://docs.aurelia.io/routing/router-tutorial#add-routes-and-a-viewport)

```html
<ul>
<li>
<a load="/home">Home</a>
</li>
<li>
<a load="/about">About</a>
</li>
</ul>
```
8 changes: 8 additions & 0 deletions content/7-webapp-features/4-routing/aurelia2/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export class App {
static routes = [
{
path: ["", "home"],
},
];
static template = "<au-viewport></au-viewport>";
}
25 changes: 25 additions & 0 deletions frameworks.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,29 @@ export default [
return sortAllFilenames(files, ["app.html", "app.ts"]);
},
},
{
id: "aurelia2",
title: "Aurelia 2",
img: "framework/aurelia.svg",
eslint: {
env: {
browser: true,
es2021: true,
node: true,
},
parser: "@typescript-eslint/parser",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
},
files: ["**/aurelia2/**"],
extends: ["eslint:recommended"],
},
playgroundURL: "https://stackblitz.com/edit/au2-conventions?file=src%2Fmy-app.html",
documentationURL: "http://docs.aurelia.io",
filesSorter(files) {
return sortAllFilenames(files, ["app.html", "app.ts"]);
},
},
];
Loading

0 comments on commit fbf1f0b

Please sign in to comment.