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

Refactor button component #311

Open
wants to merge 3 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/BaseButton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { StyledButton } from './styles.js';

const BaseButton = (props) => {
return (
<StyledButton {...props}>
<StyledButton color={props.color || 'primary'} {...props}>
{typeof props.children === 'string' ? props.children : props.text}
</StyledButton>
);
Expand Down
80 changes: 41 additions & 39 deletions components/BaseButton/styles.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
import styled from 'styled-components';
import styled, { css } from 'styled-components';

const backgroundColorPriority = {
primary: '#04102F',
secondary: '#4EB5A2',
transparent: 'transparent',
disabled: '#8E94A4',
};

const borderColorPriority = {
primary: 'none',
secondary: 'none',
transparent: '#04102F',
disabled: 'none',
};

const borderWidthPriority = {
primary: '0px',
secondary: '0px',
transparent: '1px',
disabled: '0px',
};

const textColorPriority = {
primary: 'white',
secondary: 'white',
transparent: '#04102F',
disabled: 'white',
};

export const StyledButton = styled('button')`
background-color: ${(props) =>
backgroundColorPriority[props.type || 'primary']};
border-color: ${(props) => borderColorPriority[props.type || 'primary']};
border-width: ${(props) => borderWidthPriority[props.type || 'primary']};
export const StyledButton = styled('button').attrs((props) => ({
type: props.type || 'button',
}))`
background-color: #04102f;
border: none;
border-radius: 2rem;
cursor: ${(props) => (props.type === 'disabled' ? 'auto' : 'pointer')};
color: ${(props) => textColorPriority[props.type || 'primary']};
color: #ffffff;
cursor: pointer;
font-family: 'Roboto', sans-serif;
min-width: 7.375rem;
height: 3rem;
min-width: 7.375rem;
padding: 0 1.5rem;

&:hover {
text-decoration: ${(props) =>
props.type === 'disabled' ? 'none' : 'underline'};
text-decoration: underline;
}

&:disabled {
border: none;
opacity: 0.25;
&:hover {
cursor: auto;
text-decoration: none;
}
}

${(props) =>
props.color === 'primary' &&
css`
background-color: #04102f;
border: none;
color: #ffffff;
`}
${(props) =>
props.color === 'secondary' &&
css`
background-color: #4eb5a2;
border: none;
color: #ffffff;
`}
${(props) =>
props.color === 'transparent' &&
css`
background-color: transparent;
border: 1px solid #04102f;
color: #04102f;
`}
`;
2 changes: 1 addition & 1 deletion components/Favorites/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const CandidateCard = styled(BaseCandidateCard)`

// Todo: make it sticky / position-absoluted when needed
export const KeepLookingButton = styled((props) => (
<BaseButton type="secondary" {...props} />
<BaseButton color="secondary" {...props} />
))`
margin-top: 1.25rem;
`;
2 changes: 1 addition & 1 deletion components/PartyCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const PartyCard = (props) => {
{numberOfCandidates(props.numberOfCandidates)}
</Styled.NumberOfCandidates>
<Styled.SeeCandidatesButton
type="transparent"
color="transparent"
onClick={onSeeCandidatesButtonClick(props.partyName)(props.candidates)}>
Ver candidatos
</Styled.SeeCandidatesButton>
Expand Down
3 changes: 1 addition & 2 deletions components/PresidentialQuestion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,14 @@ export default function PresidentialQuestion() {
</Styled.QuestionList>
<Styled.QuestionButtons>
<BaseButton
type={selectedOption === '' ? 'disabled' : 'primary'}
disabled={selectedOption === ''}
onClick={handleNextButton}>
Continuar
</BaseButton>
<Styled.OmitButton
disabled={questionsOmitted === allowOmittedQuestionsPerTopic}
onClick={() => handleNextButton({ isOmitted: true })}
type="transparent">
color="transparent">
Omitir
</Styled.OmitButton>
</Styled.QuestionButtons>
Expand Down
7 changes: 0 additions & 7 deletions components/PresidentialQuestion/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ export const QuestionButtons = styled('div')`
export const OmitButton = styled(BaseButton)`
border: none;
margin-top: 1.125rem;
&:disabled {
opacity: 0.4;
&:hover {
cursor: auto;
text-decoration: none;
}
}
`;
export const NoQuestionChip = styled(BaseChip)`
margin: 0 auto;
Expand Down
5 changes: 0 additions & 5 deletions components/PresidentialQuizBreakdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ export default function PresidentialQuizBreakdown() {
<Styled.SubTitle>Ningún tópico seleccionado</Styled.SubTitle>
)}
<Styled.Button
type={
userSelectedTopics.length < requiredNumberOfSelectedTopics
? 'disabled'
: 'primary'
}
disabled={
userSelectedTopics.length < requiredNumberOfSelectedTopics
}
Expand Down
5 changes: 0 additions & 5 deletions components/PresidentialTopics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ export default function PresidentialTopics() {
/>
))}
<Styled.Button
type={
userSelectedTopics.length < requiredNumberOfSelectedTopics
? 'disabled'
: 'primary'
}
disabled={userSelectedTopics.length < requiredNumberOfSelectedTopics}
onClick={() => Router.push('/presidential-steps/2')}
text="Continuar"
Expand Down
10 changes: 2 additions & 8 deletions components/Steps/1/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import styled from 'styled-components';
import BaseHeader from 'components/Header';
import BaseStepper from 'components/Stepper';
import BaseTitle from 'components/BaseTitle';
import BaseParagraph from 'components/BaseParagraph';
import BaseSelect from 'components/BaseSelect';
import BaseLinkButton from 'components/LinkButton';
import BaseButton from 'components/BaseButton';
Expand All @@ -22,15 +21,15 @@ export const Header = styled(BaseHeader)`
`;

export const GoBackButton = styled(BaseGoBackButton)`
margin-top: 16px;
margin-left: 16px;
margin-top: 16px;
`;

export const Step = styled('div')`
align-items: center;
display: flex;
flex: 1;
flex-direction: column;
display: flex;
padding: 0 1.5rem;
`;

Expand Down Expand Up @@ -63,10 +62,5 @@ export const LinkButton = styled(BaseLinkButton)`

export const Button = styled(BaseButton)`
align-self: center;
background-color: ${(props) => (props.disabled ? 'grey' : 'auto')};
cursor: ${(props) => (props.disabled ? 'auto' : 'pointer')};
margin-bottom: 5rem;
&:hover {
text-decoration: ${(props) => (props.disabled ? 'none' : 'underline')};
}
`;
2 changes: 1 addition & 1 deletion components/Steps/2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function Step2() {
<Styled.NoButton onClick={onNoButtonClick}>
Ocultar candidatos
</Styled.NoButton>
<Styled.YesButton type="transparent" onClick={onYesButtonClick}>
<Styled.YesButton color="transparent" onClick={onYesButtonClick}>
Incluir candidatos
</Styled.YesButton>
</Styled.YesNoButtons>
Expand Down
2 changes: 1 addition & 1 deletion components/Steps/3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default function Step3() {
<Styled.NoButton onClick={onNoButtonClick}>
Ocultar partidos
</Styled.NoButton>
<Styled.YesButton type="transparent" onClick={onYesButtonClick}>
<Styled.YesButton color="transparent" onClick={onYesButtonClick}>
Incluir partidos
</Styled.YesButton>
</Styled.YesNoButtons>
Expand Down
2 changes: 1 addition & 1 deletion components/Steps/CandidateResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default function Step4(props) {
</Styled.Emphasis>
</Styled.Title>
<Styled.FilterButton
type="transparent"
color="transparent"
onClick={() => setFilterModalState(true)}
/>
<Styled.ChipCard type="good">
Expand Down
5 changes: 2 additions & 3 deletions components/Steps/CandidateSingle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as Styled from './styles';
import { FavoritesContext } from 'hooks/useFavorites';
import Loading from 'components/Loading';
import GoBackButton from 'components/GoBackButton';
import toggleSlug from 'components/PartyCard/toggleSlug';

const LoadingScreen = () => {
return (
Expand Down Expand Up @@ -60,7 +59,7 @@ export default function CandidateSingle(props) {
setCollapsed(newCollapsedObject);
};

const { data, error } = useSWR(
const { data } = useSWR(
candidateId ? `/api/candidates/hoja_vida_id/${candidateId}` : null,
() =>
fetch(
Expand Down Expand Up @@ -198,7 +197,7 @@ export default function CandidateSingle(props) {
isFavorite ? (
<Styled.FavoriteButton
text="Sácame de tus opciones"
type="transparent"
color="transparent"
onClick={() => removeFavorite(c.hoja_vida_id)}
/>
) : (
Expand Down
2 changes: 1 addition & 1 deletion components/Steps/PartyResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export default function PartyResults(props) {
: 'única opción'}
</Styled.Title>
<Styled.FilterButton
type="transparent"
color="transparent"
onClick={() => setFilterModalState(true)}
/>
<Styled.Chip type={'good'}>
Expand Down