Skip to content

Commit 8185683

Browse files
fix(UI): replace button with icons in challenge lower jaw (freeCodeCamp#48014)
* fix: replace button with icons in challenge lower jaw * fix: update icon buttons to add data-cy, align right, and cleaner conditional display * fix: update cypress test with correct selector, update conditional button syntax * fix: add reset and help icon components, move lowerjaw.css to editor.css * feat: adjust icon buttons order Co-authored-by: ahmad abdolsaheb <[email protected]>
1 parent f22e400 commit 8185683

File tree

5 files changed

+96
-23
lines changed

5 files changed

+96
-23
lines changed

client/src/assets/icons/help.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
3+
function Help(
4+
props: JSX.IntrinsicAttributes & React.SVGProps<SVGSVGElement>
5+
): JSX.Element {
6+
return (
7+
<>
8+
<svg
9+
fill='currentColor'
10+
xmlns='http://www.w3.org/2000/svg'
11+
height='24'
12+
width='24'
13+
aria-hidden='true'
14+
{...props}
15+
>
16+
<path d='M11.95 18q.525 0 .888-.363.362-.362.362-.887t-.362-.887q-.363-.363-.888-.363t-.888.363q-.362.362-.362.887t.362.887q.363.363.888.363Zm-.9-3.85h1.85q0-.825.188-1.3.187-.475 1.062-1.3.65-.65 1.025-1.238.375-.587.375-1.412 0-1.4-1.025-2.15T12.1 6q-1.425 0-2.312.75-.888.75-1.238 1.8l1.65.65q.125-.45.563-.975Q11.2 7.7 12.1 7.7q.8 0 1.2.437.4.438.4.963 0 .5-.3.937-.3.438-.75.813-1.1.975-1.35 1.475-.25.5-.25 1.825ZM12 22q-2.075 0-3.9-.788-1.825-.787-3.175-2.137-1.35-1.35-2.137-3.175Q2 14.075 2 12t.788-3.9q.787-1.825 2.137-3.175 1.35-1.35 3.175-2.138Q9.925 2 12 2t3.9.787q1.825.788 3.175 2.138 1.35 1.35 2.137 3.175Q22 9.925 22 12t-.788 3.9q-.787 1.825-2.137 3.175-1.35 1.35-3.175 2.137Q14.075 22 12 22Zm0-2q3.35 0 5.675-2.325Q20 15.35 20 12q0-3.35-2.325-5.675Q15.35 4 12 4 8.65 4 6.325 6.325 4 8.65 4 12q0 3.35 2.325 5.675Q8.65 20 12 20Zm0-8Z' />
17+
</svg>
18+
</>
19+
);
20+
}
21+
22+
Help.displayName = 'Help';
23+
24+
export default Help;

client/src/assets/icons/reset.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import React from 'react';
2+
3+
function Reset(
4+
props: JSX.IntrinsicAttributes & React.SVGProps<SVGSVGElement>
5+
): JSX.Element {
6+
return (
7+
<>
8+
<svg
9+
fill='currentColor'
10+
xmlns='http://www.w3.org/2000/svg'
11+
height='24'
12+
width='24'
13+
aria-hidden='true'
14+
{...props}
15+
>
16+
<path d='M12 20q-3.35 0-5.675-2.325Q4 15.35 4 12q0-3.35 2.325-5.675Q8.65 4 12 4q1.725 0 3.3.713 1.575.712 2.7 2.037V4h2v7h-7V9h4.2q-.8-1.4-2.187-2.2Q13.625 6 12 6 9.5 6 7.75 7.75T6 12q0 2.5 1.75 4.25T12 18q1.925 0 3.475-1.1T17.65 14h2.1q-.7 2.65-2.85 4.325Q14.75 20 12 20Z' />
17+
</svg>
18+
</>
19+
);
20+
}
21+
22+
Reset.displayName = 'Reset';
23+
24+
export default Reset;

client/src/templates/Challenges/classic/editor.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,21 @@ textarea.inputarea {
170170
opacity: 1;
171171
}
172172
}
173+
174+
.lower-jaw-icon-bar {
175+
overflow: hidden;
176+
display: flex;
177+
flex-direction: row;
178+
}
179+
.lower-jaw-icon-bar > button {
180+
line-height: 0;
181+
margin-right: 10px;
182+
}
183+
184+
.lower-jaw-icon-bar > button:focus {
185+
outline: 2px solid var(--blue-mid);
186+
}
187+
188+
.lower-jaw-icon-bar > button:last-child {
189+
margin-right: 0;
190+
}

client/src/templates/Challenges/classic/lower-jaw.tsx

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { Button } from '@freecodecamp/react-bootstrap';
55
import Fail from '../../../assets/icons/fail';
66
import LightBulb from '../../../assets/icons/lightbulb';
77
import GreenPass from '../../../assets/icons/green-pass';
8+
import Help from '../../../assets/icons/help';
9+
import Reset from '../../../assets/icons/reset';
10+
811
import { MAX_MOBILE_WIDTH } from '../../../../../config/misc';
912
import { apiLocation } from '../../../../../config/env.json';
1013

@@ -181,32 +184,35 @@ const LowerJaw = ({
181184
testsLength &&
182185
(currentAttempts >= testsLength || currentAttempts >= 3);
183186

184-
if (isAttemptsLargerThanTest && !challengeIsCompleted) {
185-
return (
186-
<div>
187-
<hr />
187+
return (
188+
<div>
189+
<hr />
190+
<div className='lower-jaw-icon-bar'>
188191
<button
189-
className='btn-block btn fade-in'
190-
id='help-button'
191-
onClick={openHelpModal}
192+
className='btn fade-in'
193+
title={t('buttons.reset-code')}
194+
aria-label={t('buttons.reset-code')}
195+
data-cy='reset-code-button'
196+
onClick={openResetModal}
192197
>
193-
{t('buttons.ask-for-help')}
194-
</button>
195-
<button className='btn-block btn fade-in' onClick={openResetModal}>
196-
{t('learn.editor-tabs.restart-step')}
197-
</button>
198-
</div>
199-
);
200-
} else {
201-
return (
202-
<div>
203-
<hr />
204-
<button className='btn-block btn fade-in' onClick={openResetModal}>
205-
{t('learn.editor-tabs.restart-step')}
198+
<Reset />
206199
</button>
200+
201+
{isAttemptsLargerThanTest && !challengeIsCompleted ? (
202+
<button
203+
className='btn fade-in'
204+
id='get-help-button'
205+
title={t('buttons.get-help')}
206+
aria-label={t('buttons.get-help')}
207+
data-cy='get-help-button'
208+
onClick={openHelpModal}
209+
>
210+
<Help />
211+
</button>
212+
) : null}
207213
</div>
208-
);
209-
}
214+
</div>
215+
);
210216
};
211217

212218
const showDesktopButton = window.innerWidth > MAX_MOBILE_WIDTH;

cypress/e2e/default/learn/challenges/multifile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const selectors = {
66
monacoTabs: '.monaco-editor-tabs',
77
signInButton: '#action-buttons-container a[href$="/signin"]',
88
submitButton: '[data-cy=submit-button]',
9+
resetCodeButton: '[data-cy=reset-code-button]',
910
instructionContainer: '.action-row-container'
1011
};
1112

@@ -34,7 +35,7 @@ describe('Challenge with multifile editor', () => {
3435

3536
cy.contains('Check Your Code').click();
3637
cy.get('[data-cy=failing-test-feedback]').should('be.visible');
37-
cy.contains('Restart Step').click();
38+
cy.get(selectors.resetCodeButton).click();
3839
cy.get('[data-cy=reset-modal-confirm').click();
3940

4041
cy.get('[data-cy=failing-test-feedback]').should('not.exist');

0 commit comments

Comments
 (0)