Converts `ui/drive_lights.js` to Typescript (#70)

This change also exposes the `Callbacks` and `DriveNumber` types from
`disk2.ts`.
This commit is contained in:
Ian Flanigan 2021-03-26 15:45:51 +01:00 committed by GitHub
parent 342f024a85
commit 6395a9009e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 23 deletions

View File

@ -145,10 +145,10 @@ const PHASE_DELTA = [
[1, -2, -1, 0]
] as const;
const DRIVE_NUMBERS = [1, 2] as const;
type DriveNumber = MemberOf<typeof DRIVE_NUMBERS>;
export const DRIVE_NUMBERS = [1, 2] as const;
export type DriveNumber = MemberOf<typeof DRIVE_NUMBERS>;
interface Callbacks {
export interface Callbacks {
driveLight: (drive: DriveNumber, on: boolean) => void;
dirty: (drive: DriveNumber, dirty: boolean) => void;
label: (drive: DriveNumber, name: string) => void;

View File

@ -1,20 +0,0 @@
export default function DriveLights()
{
return {
driveLight: function(drive, on) {
var disk = document.querySelector('#disk' + drive);
disk.style.backgroundImage =
on ? 'url(css/red-on-16.png)' :
'url(css/red-off-16.png)';
},
dirty: function() {
// document.querySelector('#disksave' + drive).disabled = !dirty;
},
label: function(drive, label) {
if (label) {
document.querySelector('#disk-label' + drive).innerText = label;
}
return document.querySelector('#disk-label' + drive).innerText;
}
};
}

24
js/ui/drive_lights.ts Normal file
View File

@ -0,0 +1,24 @@
import { Callbacks, DriveNumber } from '../cards/disk2';
export default class DriveLights implements Callbacks {
public driveLight(drive: DriveNumber, on: boolean) {
const disk =
document.querySelector('#disk' + drive)! as HTMLElement;
disk.style.backgroundImage =
on ? 'url(css/red-on-16.png)' :
'url(css/red-off-16.png)';
}
public dirty() {
// document.querySelector('#disksave' + drive).disabled = !dirty;
}
public label(drive: DriveNumber, label: string) {
const labelElement =
document.querySelector('#disk-label' + drive)! as HTMLElement;
if (label) {
labelElement.innerText = label;
}
return labelElement.innerText;
}
}