Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small buttons #303

Merged
merged 11 commits into from
Dec 22, 2022
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);
}