Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.1",
"@fontsource/noto-sans-jp": "^5.3.1",
"@fontsource/roboto": "^5.3.0",
"@mui/icons-material": "^7.3.1",
"@mui/material": "^7.3.1",
"clsx": "^2.1.1",
Expand Down
21 changes: 5 additions & 16 deletions src/components/TruthTableView.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { Box, type Theme } from "@mui/material";
import { useContext } from "react";
import { bitDigit, bitLabel } from "../common/bitLabel";
import { useMessages } from "../i18n";
import type { TruthTable } from "../store/intrinsics/truthTable";
import type { SimulationValue } from "../store/simulation";
import { theme } from "../style";
import { BitNotationContext } from "./bitNotation";
import { truthTableColumnsOf, truthTableLinesOf } from "./truthTableLayout";
import { ValueView } from "./ValueView";

const divider = (muiTheme: Theme) => `1px solid ${muiTheme.palette.divider}`;
const onSx = { color: theme.colors.primary, fontWeight: "bold" } as const;

export function TruthTableView({ table }: { table: TruthTable }) {
const messages = useMessages();
const singleBitLabel =
useContext(BitNotationContext) === "digits" ? bitDigit : bitLabel;
const notation = useContext(BitNotationContext);
const columns = truthTableColumnsOf(table, messages.truthTable.timeStep);
const cellSx = (column: number) =>
({
Expand All @@ -23,17 +20,9 @@ export function TruthTableView({ table }: { table: TruthTable }) {
textAlign: "center",
...(columns[column]?.startsGroup && { borderLeft: divider }),
}) as const;
const valueCell = (value: SimulationValue) =>
value.map((bit, index) => (
<Box
// biome-ignore lint/suspicious/noArrayIndexKey: bits are identified by their index
key={index}
component="span"
sx={bit ? onSx : {}}
>
{value.length === 1 ? singleBitLabel(bit) : bitDigit(bit)}
</Box>
));
const valueCell = (value: SimulationValue) => (
<ValueView value={value} notation={notation} />
);

return (
<Box
Expand Down
27 changes: 27 additions & 0 deletions src/components/ValueView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Box } from "@mui/material";
import { type BitNotation, bitDigit, bitLabel } from "../common/bitLabel";
import type { SimulationValue } from "../store/simulation";
import { theme } from "../style";

const onSx = { color: theme.colors.primary, fontWeight: "bold" } as const;

/** A value as the tables write it, with the bits that are ON stressed */
export function ValueView({
value,
notation,
}: {
value: SimulationValue;
notation: BitNotation;
}) {
const singleBitLabel = notation === "digits" ? bitDigit : bitLabel;
return value.map((bit, index) => (
<Box
// biome-ignore lint/suspicious/noArrayIndexKey: bits are identified by their index
key={index}
component="span"
sx={bit ? onSx : {}}
>
{value.length === 1 ? singleBitLabel(bit) : bitDigit(bit)}
</Box>
));
}
40 changes: 40 additions & 0 deletions src/components/controlLooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type {
ButtonProps,
SxProps,
Theme,
ToggleButtonProps,
} from "@mui/material";
import { theme } from "../style";

// The looks of controls a stage text draws too, so that the two cannot drift apart

export const checkButtonLook = {
variant: "contained",
sx: { background: theme.colors.tutorial },
} as const satisfies ButtonProps;

export const valueApplyButtonLook = {
variant: "outlined",
size: "small",
sx: { py: 0.25 },
} as const satisfies ButtonProps;

export const pinApplyButtonLook = {
variant: "contained",
size: "small",
} as const satisfies ButtonProps;

export const autoToggleButtonLook = {
size: "small",
} as const satisfies Partial<ToggleButtonProps>;

const sxList = (sx: SxProps<Theme> | undefined) =>
sx === undefined ? [] : Array.isArray(sx) ? sx : [sx];

/** The `sx` of `look` with `sx` after it, so that neither is dropped */
export function withLookSx(
look: ButtonProps | Partial<ToggleButtonProps>,
sx: SxProps<Theme>,
): SxProps<Theme> {
return [...sxList(look.sx), ...sxList(sx)];
}
Loading
Loading