61 lines
1.3 KiB
TypeScript
61 lines
1.3 KiB
TypeScript
|
"use client";
|
||
|
import { Button, Grid, Slider, Stack } from "@mui/material";
|
||
|
import React from "react";
|
||
|
|
||
|
export interface StripBusOutputEvent {
|
||
|
busId: number;
|
||
|
isVirtual: boolean;
|
||
|
enabled: boolean;
|
||
|
}
|
||
|
|
||
|
export interface StripProps {
|
||
|
id: number;
|
||
|
isVirtual: boolean;
|
||
|
onChange: (event: StripBusOutputEvent) => any;
|
||
|
default?: Partial<StripState>;
|
||
|
}
|
||
|
|
||
|
export interface StripState {
|
||
|
enabled: boolean;
|
||
|
}
|
||
|
|
||
|
export class StripBusOutput extends React.Component<StripProps, StripState> {
|
||
|
constructor(props: StripProps) {
|
||
|
super(props);
|
||
|
this.state = {
|
||
|
enabled:
|
||
|
props.default && props.default.enabled !== undefined
|
||
|
? props.default.enabled
|
||
|
: false,
|
||
|
};
|
||
|
}
|
||
|
onClick(event: React.MouseEvent) {
|
||
|
this.setState(
|
||
|
(state) => ({ enabled: !state.enabled }),
|
||
|
() => {
|
||
|
this.props.onChange({
|
||
|
busId: this.props.id,
|
||
|
enabled: this.state.enabled,
|
||
|
isVirtual: this.props.isVirtual,
|
||
|
});
|
||
|
}
|
||
|
);
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
|
<>
|
||
|
<Button
|
||
|
size="small"
|
||
|
sx={{ width: "5px" }}
|
||
|
onClick={(ev) => this.onClick(ev)}
|
||
|
variant={this.state.enabled ? "contained" : "outlined"}
|
||
|
>
|
||
|
{this.props.isVirtual ? "B" : "A"}
|
||
|
{this.props.id + 1}
|
||
|
</Button>
|
||
|
</>
|
||
|
);
|
||
|
}
|
||
|
}
|