Skip to content

Commit

Permalink
Small buttons (#303)
Browse files Browse the repository at this point in the history
- Refactors the button component to accept a buttonOuter prop
- Removed the theme from the NewComponentButton as pulls styles from the
app class
- Styling for the small button, with larger hit area

-----
To use the `btn--small` in the future just need to pass the
`buttonOuter` to the `Button` and `btn--small` class

-----
Video as no review app:


https://user-images.githubusercontent.com/14238047/209164727-63b36ed7-754f-4d1d-8d80-b240cb63f9f7.mov
  • Loading branch information
IzzySmillie committed Dec 22, 2022
1 parent d6da7fa commit 6618416
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Message prompting users to login or save if they make non-autosaved changes (#291)
- Unit tests for the autosave trigger (#291)
- Project not found and access denied modals shown on project loading error (#298)
- Styling for small buttons (#303)

## Changed

Expand Down
18 changes: 14 additions & 4 deletions src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { confirmAlert } from 'react-confirm-alert';
import 'react-confirm-alert/src/react-confirm-alert.css';

const Button = (props) => {
const { className, onClickHandler, ButtonIcon, buttonImage, buttonImageAltText, buttonText, disabled, confirmText } = props;
const { className, onClickHandler, ButtonIcon, buttonImage, buttonImageAltText, buttonText, buttonOuter, disabled, confirmText } = props;

var buttonClass="btn"
buttonClass = (className ? buttonClass += ` ${className}`: buttonClass)
Expand All @@ -30,13 +30,23 @@ const Button = (props) => {
});
}

return (
<button className={buttonClass} disabled={disabled} onClick={onButtonClick}>
const button = (
<button className={buttonClass} disabled={disabled} onClick={buttonOuter ? null : onButtonClick}>
{ buttonImage ? <img src={buttonImage} alt={buttonImageAltText}/> : null }
{ ButtonIcon ? <ButtonIcon /> : null }
{ buttonText ? <span>{buttonText}</span> : null }
</button>
)
);

if (buttonOuter) {
return (
<div className='btn-outer' onClick={onButtonClick}>
{button}
</div>
)
}

return button;
};

export default Button;
Expand Down
77 changes: 69 additions & 8 deletions src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}
}

&:active {
&:active, .btn-outer:active & {
background-color: $active-bg;
@content;
}
Expand All @@ -31,12 +31,12 @@
}
}

&:focus-visible {
&:focus-visible, .btn-outer:focus-visible & {
background-color: $focus-bg;
@content;
}

&:hover {
&:hover, .btn-outer:hover & {
background-color: $hover-bg;
@content;
}
Expand All @@ -58,6 +58,12 @@
text-decoration: none;
width: fit-content;

&:disabled {
background-color: $rpf-darkmode-grey32;
color: $rpf-white;
cursor: default;
}

&:focus-visible {
border: 3px solid $rpf-brand-raspberry;
outline: none;
Expand All @@ -67,14 +73,11 @@
margin-right: var(--spacing-1);
}

&:disabled {
background-color: $rpf-darkmode-grey32;
color: $rpf-white;
cursor: default;
&--small {
padding: var(--spacing-four);
}

// Variants

&--primary {
$colours: $rpf-teal, $rpf-teal-tint-25, $rpf-teal-tint-75, $rpi-grey-70, $rpf-teal, $rpf-teal-shade-20;
@include button-styling($colours...);
Expand Down Expand Up @@ -112,13 +115,71 @@
}
}

.btn-outer {
background: transparent;
cursor: pointer;
padding: var(--spacing-eight) 0;

&:focus-visible {
outline: none;

.btn {
border: 3px solid $rpf-brand-raspberry;
}
}
}

.font-size-large {
.btn svg {
margin-right: var(--spacing-2);
}
}

.--dark {
.btn-outer {
&:hover {
.btn--primary {
background-color: $rpf-teal-tint-25;
}

.btn--secondary {
background-color: $rpf-darkmode-grey22;
}

.btn--tertiary {
background-color: inherit;
}
}

&:active {
.btn--primary {
background-color: $rpf-teal-tint-75;
}

.btn--secondary {
background-color: $rpf-darkmode-grey22;
}

.btn--tertiary {
background-color: inherit;
}
}

&:focus-visible {
.btn--primary {
background-color: $rpf-teal-tint-50;
}

.btn--secondary {
background-color: $rpf-darkmode-grey32;
}

.btn--tertiary {
background-color: inherit;
}
}
}

.btn--primary {
$colours: $rpf-teal-tint-50, $rpf-teal-tint-75, $rpf-darkmode-grey80, $rpf-darkmode-grey22, $rpf-teal-tint-50, $rpf-teal-tint-25;
@include button-styling($colours...);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Button from '../../Button/Button'
import NameErrorMessage from '../ErrorMessage/NameErrorMessage';
import { CloseIcon, NewFileIcon } from '../../../Icons';
import { validateFileName } from '../../../utils/componentNameValidation';
import { useCookies } from 'react-cookie';
import { useTranslation } from 'react-i18next';

const NewComponentButton = () => {
Expand All @@ -20,10 +19,6 @@ const NewComponentButton = () => {
const projectComponents = useSelector((state) => state.editor.project.components);
const componentNames = projectComponents.map(component => `${component.name}.${component.extension}`)

const [cookies] = useCookies(['fontSize', 'theme'])
const isDarkMode = cookies.theme==="dark" || (!cookies.theme && window.matchMedia("(prefers-color-scheme:dark)").matches)
const theme = isDarkMode ? "dark" : "light"

const closeModal = () => setIsOpen(false);
const showModal = () => {
dispatch(setNameError(""));
Expand All @@ -40,8 +35,8 @@ const NewComponentButton = () => {
}

return (
<div className={`--${theme}`}>
<Button buttonText={t('filePane.newFileButton')} ButtonIcon={NewFileIcon} onClickHandler={showModal} className="btn--primary proj-new-component-button" />
<div>
<Button buttonText={t('filePane.newFileButton')} ButtonIcon={NewFileIcon} buttonOuter onClickHandler={showModal} className="btn--primary btn--small proj-new-component-button" />

<Modal
isOpen={modalIsOpen}
Expand Down
4 changes: 3 additions & 1 deletion src/editor-spacing.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
:root, :host {
--spacing-half: calc(0.5rem * var(--spacing-multiplier))
--spacing-half: calc(0.5rem * var(--spacing-multiplier));
--spacing-eight: calc(var(--spacing-1) / 1.25);
--spacing-four: calc(var(--spacing-eight) / 2);
}

0 comments on commit 6618416

Please sign in to comment.