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 #14 from Synthetixio/feat/button-onclick-type
Browse files Browse the repository at this point in the history
feat(button iconbutton selector): adds the event type of the onClick …
  • Loading branch information
fritzschoff authored Mar 21, 2022
2 parents ad0faac + 9faaeb3 commit 2b3bf85
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 41 deletions.
5 changes: 4 additions & 1 deletion src/components/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from 'styled-components';
import React, { ButtonHTMLAttributes, FC } from 'react';
import React, { ButtonHTMLAttributes, FC, MouseEvent } from 'react';
import { theme } from '../styles';
import { rem } from '../constants';
import colors from '../styles/colors';
Expand All @@ -12,6 +12,7 @@ interface ButtonProps {
variant?: 'primary' | 'secondary' | 'tertiary';
secondaryBackgroundColor?: string;
disabled?: boolean;
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
}

const Button: FC<ButtonProps> = ({
Expand All @@ -21,6 +22,7 @@ const Button: FC<ButtonProps> = ({
variant,
secondaryBackgroundColor,
disabled,
onClick,
...rest
}) => {
return (
Expand All @@ -31,6 +33,7 @@ const Button: FC<ButtonProps> = ({
variant={variant}
secondaryBackgroundColor={secondaryBackgroundColor}
size={size}
onClick={onClick}
>
<StyledButtonText variant={variant} disabled={disabled} size={size}>
{text}
Expand Down
6 changes: 4 additions & 2 deletions src/components/IconButton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { MouseEvent } from 'react';
import styled from 'styled-components';
import spacings from '../styles/spacings';

Expand All @@ -8,6 +8,7 @@ interface IconButtonProps {
rounded?: boolean;
size?: keyof typeof spacings.margin;
text?: string;
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
}

export default function IconButton({
Expand All @@ -16,11 +17,12 @@ export default function IconButton({
rounded = false,
size = 'small',
text,
onClick,
...rest
}: IconButtonProps) {
return (
<StyledWrapper rounded={rounded} {...rest}>
<StyledButton rounded={rounded} size={size} active={active}>
<StyledButton rounded={rounded} size={size} active={active} onClick={onClick}>
{icon} {text && <StyledText>{text}</StyledText>}
</StyledButton>
</StyledWrapper>
Expand Down
76 changes: 38 additions & 38 deletions src/components/Selector.tsx
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
import React from 'react';
import React, { MouseEvent } from 'react';
import styled from 'styled-components';
import colors from '../styles/colors';
import spacings from '../styles/spacings';

interface SelectorProps {
text: string;
icon?: JSX.Element;
onClick: () => void;
text: string;
icon?: JSX.Element;
onClick: (e: MouseEvent<HTMLButtonElement>) => void;
}

export default function Selector({ text, icon, onClick }: SelectorProps) {
return (
<SelectorWrapper onClick={onClick} hasIcon={!!icon}>
<SelectorText hasIcon={!!icon}>{text}</SelectorText> {icon}
</SelectorWrapper>
);
return (
<SelectorWrapper onClick={onClick} hasIcon={!!icon}>
<SelectorText hasIcon={!!icon}>{text}</SelectorText> {icon}
</SelectorWrapper>
);
}

const SelectorWrapper = styled.button<{ hasIcon: boolean }>`
display: flex;
flex-direction: row;
justify-content: ${({ hasIcon }) => (hasIcon ? 'space-between' : 'center')};
align-items: center;
padding: 6px 8px;
background-color: ${colors.backgroundColor};
border: 0;
outline: 0;
cursor: pointer;
min-height: 38px;
display: flex;
flex-direction: row;
justify-content: ${({ hasIcon }) => (hasIcon ? 'space-between' : 'center')};
align-items: center;
padding: 6px 8px;
background-color: ${colors.backgroundColor};
border: 0;
outline: 0;
cursor: pointer;
min-height: 38px;
:hover {
background-color: #13133a;
transition: background-color 200ms ease-in;
}
:active {
background-color: #13133a;
transition: background-color 200ms ease-in;
}
:hover {
background-color: #13133a;
transition: background-color 200ms ease-in;
}
:active {
background-color: #13133a;
transition: background-color 200ms ease-in;
}
`;

const SelectorText = styled.span<{ hasIcon: boolean }>`
font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 1rem;
line-height: 140%;
color: ${colors.lightBlue.primary};
${({ hasIcon }) => {
return hasIcon
? `margin-right: ${spacings.margin.big};`
: `margin: 0 ${spacings.margin.biggest};`;
}}
font-family: 'Inter';
font-style: normal;
font-weight: 400;
font-size: 1rem;
line-height: 140%;
color: ${colors.lightBlue.primary};
${({ hasIcon }) => {
return hasIcon
? `margin-right: ${spacings.margin.big};`
: `margin: 0 ${spacings.margin.biggest};`;
}}
`;

0 comments on commit 2b3bf85

Please sign in to comment.