Skip to content
This repository has been archived by the owner on Aug 31, 2022. It is now read-only.

Commit

Permalink
Merge pull request #62 from Synthetixio/modal-improvements
Browse files Browse the repository at this point in the history
fix(checkbox): added different color options to component
  • Loading branch information
fritzschoff authored Apr 28, 2022
2 parents e89b622 + b470f82 commit 7bea038
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 12 additions & 6 deletions src/components/Checkbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import styled from 'styled-components';

import colors from '../styles/colors';
import { Colors } from '../types';

interface CheckboxProps {
id: string;
Expand All @@ -10,6 +10,7 @@ interface CheckboxProps {
name?: string;
checked?: boolean;
onChange: (checked: boolean) => unknown;
color?: Colors;
}

export default function Checkbox({
Expand All @@ -19,6 +20,7 @@ export default function Checkbox({
name,
checked,
onChange,
color,
...rest
}: CheckboxProps) {
return (
Expand All @@ -31,7 +33,7 @@ export default function Checkbox({
onChange={() => onChange(!checked)}
/>
<StyledLabel htmlFor={id}>
<StyledCheckbox checked={checked} disabled={disabled} />
<StyledCheckbox checked={checked} disabled={disabled} color={color} />
{label && <StyledLabelText disabled={disabled}>{label}</StyledLabelText>}
</StyledLabel>
</StyledContainer>
Expand Down Expand Up @@ -68,7 +70,7 @@ const StyledLabelText = styled.span<{ disabled?: boolean }>`
color: ${(attrs) => (attrs.disabled ? colors.disabled : colors.white)};
`;

const StyledCheckbox = styled.div<{ checked?: boolean; disabled?: boolean }>`
const StyledCheckbox = styled.div<{ checked?: boolean; disabled?: boolean; color?: Colors }>`
position: relative;
display: inline-block;
cursor: pointer;
Expand All @@ -77,7 +79,8 @@ const StyledCheckbox = styled.div<{ checked?: boolean; disabled?: boolean }>`
width: 2.2rem;
height: 2.2rem;
border-radius: 50%;
background-image: ${colors.gradients.pink};
${({ color }) =>
color ? `background-color: ${colors.lightBlue}` : `background-image: ${colors.gradients.pink}`};
${(attrs) => attrs.disabled && `filter: grayscale(100%);`}
Expand All @@ -100,8 +103,11 @@ const StyledCheckbox = styled.div<{ checked?: boolean; disabled?: boolean }>`
border-radius: 50%;
width: 46%;
height: 46%;
background-image: ${colors.gradients.pink};
${({ color }) =>
color
? `background-color: ${colors.lightBlue}`
: `background-image: ${colors.gradients.pink}`};
opacity: ${(attrs) => (attrs.checked ? '1' : '0')};
transition: opacity 80ms ease-in-out;
transition: opacity 100ms ease-in-out;
}
`;
6 changes: 4 additions & 2 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components';

interface ModalProps {
open: boolean;
modalContent: JSX.Element;
modalContent?: JSX.Element;
}

export default function Modal({
Expand All @@ -14,7 +14,9 @@ export default function Modal({
}: PropsWithChildren<ModalProps>) {
return (
<StyledModalWrapper {...rest}>
{open && <StyledModalContentWrapper>{modalContent}</StyledModalContentWrapper>}
{open && modalContent && (
<StyledModalContentWrapper>{modalContent}</StyledModalContentWrapper>
)}
{children}
</StyledModalWrapper>
);
Expand Down

0 comments on commit 7bea038

Please sign in to comment.