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

✨ Create IconButton UI component #49

Merged
merged 1 commit into from
Oct 29, 2022
Merged
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 src/components/UI/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import classes from './styles.module.scss';

const Button: React.FC<ButtonProps> = (props) => {
const { children, className, ...restProps } = props;
const { children, className = '', ...restProps } = props;

return (
<button className={`${classes.button} ${className}`} {...restProps}>
Expand Down
5 changes: 5 additions & 0 deletions src/components/UI/Button/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
@include theme (color, contrast1);
cursor: pointer;
}

&:disabled {
cursor: auto;
filter: brightness(80%);
}
}
5 changes: 3 additions & 2 deletions src/components/UI/CodeBlock/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { monokai } from 'react-syntax-highlighter/dist/esm/styles/hljs';
import { copyTextToClipboard } from '../../../utils';
import ClipBoard from '../../Icons/Clipboard';
import ClipBoardChecked from '../../Icons/ClipboardChecked';
import IconButton from '../IconButton';
import classes from './styles.module.scss';

const CodeBlock: React.FC<CodeBlockProps> = (props) => {
Expand Down Expand Up @@ -36,9 +37,9 @@ const CodeBlock: React.FC<CodeBlockProps> = (props) => {
>
{codeString}
</SyntaxHighlighter>
<div onClick={handleCopyClick}>
<IconButton onClick={handleCopyClick} className={classes.iconButton}>
{isCopied ? <ClipBoardChecked /> : <ClipBoard />}
</div>
</IconButton>
</section>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/UI/CodeBlock/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
display: flex;
flex-direction: column;

& div {
& .iconButton {
position: absolute;
right: 1rem;
top: 1.75rem;
right: 0.75rem;
top: 0.75rem;
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/components/UI/IconButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import classes from './styles.module.scss';

const IconButton: React.FC<IconButtonProps> = (props) => {
const { children, size = 32, className = '', ...restProps } = props;

return (
<button className={`${classes.button} ${className}`} style={{ width: size, height: size }} {...restProps}>
{children}
</button>
);
};

export default IconButton;
25 changes: 25 additions & 0 deletions src/components/UI/IconButton/styles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@import '../../../utils/mixins.scss';

.button {
@include theme (background-color, iconButton);
border-radius: 50%;
border: none;
outline: none;
display: flex;
align-items: center;
justify-content: center;
box-shadow: none;
filter: brightness(80%);

&:hover {
cursor: pointer;
filter: brightness(100%);
box-shadow: 0 4px 6px rgba($color: $black, $alpha: 0.25);
}

&:disabled {
cursor: auto;
filter: brightness(60%);
box-shadow: none;
}
}
2 changes: 2 additions & 0 deletions src/constants/theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $LIGHT: (
contrast1: $black,
contrast2: $dark,
divider: rgba($color: $white, $alpha: 0.15),
iconButton: rgba($color: $black, $alpha: 0.1),
);

$DARK: (
Expand All @@ -23,6 +24,7 @@ $DARK: (
contrast1: $white,
contrast2: $light,
divider: rgba($color: $black, $alpha: 0.15),
iconButton: rgba($color: $white, $alpha: 0.1),
);

$themes: ($LIGHT, $DARK);
Expand Down
2 changes: 1 addition & 1 deletion src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*::after {
margin: 0;
box-sizing: border-box;
transition: all 0.25s;
transition: all 0.2s;
}

body {
Expand Down
5 changes: 5 additions & 0 deletions src/types/props.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ interface ClipboardProps {
height?: number;
width?: number;
}

interface IconButtonProps
extends React.DetailedHTMLProps<React.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement> {
size?: number;
}