Skip to content

Commit

Permalink
Merge pull request #4 from cindyli/feat/create-bmw-encoding
Browse files Browse the repository at this point in the history
feat: implement a content display area and associated buttons (resolves #2)
  • Loading branch information
cindyli committed Feb 1, 2024
2 parents 2132549 + a1badc7 commit 598529a
Show file tree
Hide file tree
Showing 30 changed files with 1,836 additions and 811 deletions.
1,861 changes: 1,114 additions & 747 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion setupFetchForJest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
Expand Down
13 changes: 3 additions & 10 deletions src/ActionBmwCodeCell.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
Expand All @@ -11,14 +11,7 @@

.actionBmwCodeCell {
border: 2px solid blue;
background-color: gray;
border-radius: 5px;
padding: 1rem;
font-size: 1rem;
background-color: beige;
padding-inline: 0.5rem;
text-align: center;

&:hover, &:focus {
background-color: lightblue;
color: #0000aa;
}
}
2 changes: 1 addition & 1 deletion src/ActionBmwCodeCell.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
Expand Down
28 changes: 20 additions & 8 deletions src/ActionBmwCodeCell.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
Expand All @@ -10,28 +10,40 @@
*/

import { html } from "htm/preact";
import { OptionsType } from "./index.d";
import { BlissSymbolCellType } from "./index.d";
import { BlissSymbol } from "./BlissSymbol";
import { usePaletteState } from "./GlobalData";
import { generateGridStyle, speak } from "./GlobalUtils";
import "./ActionBmwCodeCell.scss";


type ActionBmwCodeCellPropsType = {
id: string,
options: OptionsType
options: BlissSymbolCellType
};

export function ActionBmwCodeCell (props: ActionBmwCodeCellPropsType) {
const paletteState = usePaletteState();

const {
columnStart, columnSpan, rowStart, rowSpan, bciAvId, label
} = props.options;

const gridStyles = `
grid-column: ${columnStart} / span ${columnSpan};
grid-row: ${rowStart} / span ${rowSpan};
`;
const gridStyles = generateGridStyle(columnStart, columnSpan, rowStart, rowSpan);

const cellClicked = () => {
const payload = {
"id": props.id,
"label": props.options.label,
"bciAvId": props.options.bciAvId
};
const fullEncoding = paletteState.fullEncoding;
paletteState.setFullEncoding([...fullEncoding, payload]);
speak(props.options.label);
};

return html`
<button id="${props.id}" class="actionBmwCodeCell" style="${gridStyles}" >
<button id="${props.id}" class="actionBmwCodeCell" style="${gridStyles}" onClick=${cellClicked}>
<${BlissSymbol}
bciAvId=${bciAvId}
label=${label}
Expand Down
3 changes: 1 addition & 2 deletions src/BlissSymbol.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
Expand Down Expand Up @@ -114,4 +114,3 @@ describe("BlissSymbol render tests", () => {
expect(svgElement.getAttribute("aria-hidden")).toBe(null);
});
});

5 changes: 3 additions & 2 deletions src/BlissSymbol.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Inclusive Design Research Centre, OCAD University
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
Expand Down Expand Up @@ -32,7 +32,8 @@ export function BlissSymbol (props: BlissSymbolPropsType) {

let svgMarkupString = "";
if (svgElement) {
// Deal with aria markup, depending on whether the SVG
// Deal with aria markup, depending on whether the SVG is for presentation only or
// associates with a labelled area.
if (isPresentation === "true") {
svgElement.setAttribute("aria-hidden", true);
} else {
Expand Down
65 changes: 65 additions & 0 deletions src/CommandClearEncoding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE
*/

import { render, screen } from "@testing-library/preact";
import "@testing-library/jest-dom";
import { html } from "htm/preact";

import { initAdaptivePaletteGlobals } from "./GlobalData";
import { CommandClearEncoding } from "./CommandClearEncoding";

describe("CommandClearEncoding render tests", () => {

const TEST_CELL_ID = "command-del-last-encoding";
const testCell = {
options: {
"label": "Clear",
"bciAvId": 13665,
"rowStart": 2,
"rowSpan": 1,
"columnStart": 14,
"columnSpan": 1
}
};

beforeAll(async () => {
await initAdaptivePaletteGlobals();
});

test("CommandClearEncoding rendering", async () => {

render(html`
<${CommandClearEncoding}
id="${TEST_CELL_ID}"
options=${testCell.options}
/>`
);

// Check the rendered cell
const button = await screen.findByRole("button", {name: testCell.options.label});

// Check that the CommandClearEncoding/button is rendered and has the correct
// attributes and text.
expect(button).toBeVisible();
expect(button).toBeValid();
expect(button.id).toBe(TEST_CELL_ID);
expect(button.getAttribute("class")).toBe("btn-command");
expect(button.textContent).toBe(testCell.options.label);

// Check the grid cell styles.
expect(button.style["grid-column"]).toBe("14 / span 1");
expect(button.style["grid-row"]).toBe("2 / span 1");

// Check disabled state (should be enabled)
expect(button.getAttribute("disabled")).toBe(null);
});

});
42 changes: 42 additions & 0 deletions src/CommandClearEncoding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE
*/

import { html } from "htm/preact";
import { BlissSymbol } from "./BlissSymbol";
import { usePaletteState } from "./GlobalData";
import { BlissSymbolCellType } from "./index.d";
import { generateGridStyle, speak } from "./GlobalUtils";

type CommandClearEncodingProps = {
id: string,
options: BlissSymbolCellType
}

export function CommandClearEncoding (props: CommandClearEncodingProps) {
const { id, options } = props;
const { label, bciAvId, columnStart, columnSpan, rowStart, rowSpan } = options;

const paletteState = usePaletteState();
const setFullEncoding = paletteState?.setFullEncoding;

const gridStyles = generateGridStyle(columnStart, columnSpan, rowStart, rowSpan);

const cellClicked = () => {
setFullEncoding([]);
speak(label);
};

return html`
<button id="${id}" class="btn-command" style="${gridStyles}" onClick=${cellClicked}>
<${BlissSymbol} bciAvId=${bciAvId} label=${label}/>
</button>
`;
}
65 changes: 65 additions & 0 deletions src/CommandDelLastEncoding.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE
*/

import { render, screen } from "@testing-library/preact";
import "@testing-library/jest-dom";
import { html } from "htm/preact";

import { initAdaptivePaletteGlobals } from "./GlobalData";
import { CommandDelLastEncoding } from "./CommandDelLastEncoding";

describe("CommandDelLastEncoding render tests", () => {

const TEST_CELL_ID = "command-del-last-encoding";
const testCell = {
options: {
"label": "Delete",
"bciAvId": 12613,
"rowStart": 2,
"rowSpan": 1,
"columnStart": 13,
"columnSpan": 1
}
};

beforeAll(async () => {
await initAdaptivePaletteGlobals();
});

test("CommandDelLastEncoding rendering", async () => {

render(html`
<${CommandDelLastEncoding}
id="${TEST_CELL_ID}"
options=${testCell.options}
/>`
);

// Check the rendered cell
const button = await screen.findByRole("button", {name: testCell.options.label});

// Check that the CommandDelLastEncoding/button is rendered and has the correct
// attributes and text.
expect(button).toBeVisible();
expect(button).toBeValid();
expect(button.id).toBe(TEST_CELL_ID);
expect(button.getAttribute("class")).toBe("btn-command");
expect(button.textContent).toBe(testCell.options.label);

// Check the grid cell styles.
expect(button.style["grid-column"]).toBe("13 / span 1");
expect(button.style["grid-row"]).toBe("2 / span 1");

// Check disabled state (should be enabled)
expect(button.getAttribute("disabled")).toBe(null);
});

});
43 changes: 43 additions & 0 deletions src/CommandDelLastEncoding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE
*/

import { html } from "htm/preact";
import { BlissSymbol } from "./BlissSymbol";
import { usePaletteState } from "./GlobalData";
import { BlissSymbolCellType } from "./index.d";
import { generateGridStyle, speak } from "./GlobalUtils";

type CommandDelLastEncodingProps = {
id: string,
options: BlissSymbolCellType
}

export function CommandDelLastEncoding (props: CommandDelLastEncodingProps) {
const { id, options } = props;
const { label, bciAvId, columnStart, columnSpan, rowStart, rowSpan } = options;

const paletteState = usePaletteState();

const gridStyles = generateGridStyle(columnStart, columnSpan, rowStart, rowSpan);

const cellClicked = () => {
const newEncoding = [...paletteState.fullEncoding];
newEncoding.pop();
paletteState.setFullEncoding(newEncoding);
speak(label);
};

return html`
<button id="${id}" class="btn-command" style="${gridStyles}" onClick=${cellClicked}>
<${BlissSymbol} bciAvId=${bciAvId} label=${label}/>
</button>
`;
}
30 changes: 30 additions & 0 deletions src/ContentBmwEncoding.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2023-2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE
*/

.bmwEncodingArea {
align-items: center;
background-color: #fff;
border: 3px solid #ccc;
color: #000;
display: flex;
overflow: auto; /* Add scrollbar when content overflows */
white-space: nowrap;

&:hover {
background-color: limegreen;
color: white;
}

.blissSymbol {
margin: 0 0.5rem;
text-align: center;
}
}

0 comments on commit 598529a

Please sign in to comment.