Skip to content

Commit

Permalink
Refactored Melody Editor to only use MUI components. #164
Browse files Browse the repository at this point in the history
  • Loading branch information
stylesuxx committed Jan 12, 2022
1 parent 73a4ea3 commit bc59178
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 316 deletions.
7 changes: 4 additions & 3 deletions src/Components/Input/LabeledSelect/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ function LabeledSelect({
variant="standard"
>

<InputLabel id={`${label}-select-label`}>
{label}
</InputLabel>
{ label &&
<InputLabel id={`${label}-select-label`}>
{label}
</InputLabel>}

<Select />
</FormControl>
Expand Down
39 changes: 22 additions & 17 deletions src/Components/MelodyEditor/MelodyElement/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ import React, {
useImperativeHandle,
forwardRef,
} from 'react';

import Button from '@mui/material/Button';
import ButtonGroup from '@mui/material/ButtonGroup';
import Divider from '@mui/material/Divider';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';

import './style.scss';

const MelodyElement = forwardRef(({
Expand Down Expand Up @@ -201,35 +208,33 @@ const MelodyElement = forwardRef(({
}

return (
<div className="esc-melody-wrapper">
<div className="esc-melody">
<div className="esc-melody">
<Stack spacing={1}>
<header>
<div className="index">
<h4>
{label}
</h4>
</div>

<div className="default-btn">
<button
<Typography>
{label}
</Typography>

<ButtonGroup>
<Button
className="play"
disabled={!isPlayable || disabled}
onClick={playing ? handleStopMelody : handlePlayMelody}
type="button"
variant='outlined'
>
{playing ? t('common:melodyEditorStop') : t('common:melodyEditorPlay')}
</button>
</Button>

{ !dummy &&
<button
<Button
className={`accept ${isAccepted ? 'accepted' : ''}`}
disabled={!isValid || playing || disabled}
onClick={handleAcceptMelody}
type="button"
variant='outlined'
>
{t('common:melodyEditorAccept')}
</button>}
</div>
</Button>}
</ButtonGroup>
</header>

<div className="editor-wrapper">
Expand All @@ -243,7 +248,7 @@ const MelodyElement = forwardRef(({
value={currentMelody}
/>
</div>
</div>
</Stack>
</div>
);
});
Expand Down
83 changes: 22 additions & 61 deletions src/Components/MelodyEditor/MelodyElement/style.scss
Original file line number Diff line number Diff line change
@@ -1,75 +1,36 @@
.esc-melody-wrapper {
width: 50%;
.esc-melody {
header {
display: flex;
justify-content: space-between;
width: 100%;
}

.esc-melody {
flex: 1;
margin: 10px;
position: relative;
.editor-wrapper {
border: 1px solid silver;
padding: 5px;
display: flex;

header {
padding-bottom: 5px;
margin-bottom: 10px;
border-bottom: 1px solid silver;
display: flex;
justify-content: space-between;
.editor {
width: 100%;
font-family: monospace;

.default-btn {
width: auto;
display: flex;

button {
margin-left: 10px;
width: 100px;
}

button.accepted {
background: var(--color-tertiary);
color: white;

&[disabled] {
cursor: default;
opacity: 0.5;
}
}
mark {
background: #FFCCCB;
}

.index {
flex: 1;
h4 {
padding-top: 5px;
font-size: 1.17em;
&.playing {
mark {
background: #CCFFCB;
}
}
}

.editor-wrapper {
border: 1px solid silver;
padding: 5px;
display: flex;

.editor {
textarea {
width: 100%;
font-family: monospace;

mark {
background: #FFCCCB;
}

&.playing {
mark {
background: #CCFFCB;
}
}

textarea {
width: 100%;
resize: none;
border: 0px;
resize: none;
border: 0px;

&[disabled] {
opacity: 0.75;
}
&[disabled] {
opacity: 0.75;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/Components/MelodyEditor/__tests__/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,10 @@ describe('MelodyEditor', () => {
userEvent.click(screen.getByText(/common:melodyEditorSave/i));
expect(onSave).not.toHaveBeenCalled();

expect(screen.getByTestId('saveMelodyName')).toBeInTheDocument();
const element = screen.getAllByRole('textbox')[0];
expect(element).toBeInTheDocument();

fireEvent.change(screen.getByTestId('saveMelodyName'), {
fireEvent.change(element, {
target: {
name: "",
value: "TestName",
Expand Down
Loading

0 comments on commit bc59178

Please sign in to comment.