Skip to content

Commit

Permalink
FS-73 Add outline button component (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
mic-smith authored Nov 27, 2024
1 parent e4fe03a commit 01df85f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"singleQuote": true,
"endOfLine": "lf"
"endOfLine": "auto"
}
25 changes: 25 additions & 0 deletions frontend/src/components/button.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
.button_container {
background-color: var(--primary);
border-radius: 20px;
display: inline-block;
}

.button_container.outline {
background-color: transparent;
}

.button_container:not(:has(.withText)) {
Expand Down Expand Up @@ -45,11 +50,31 @@
background-color: var(--primary-dark);
}

.outline {
.button {
border: 1px solid var(--grey-600);
}

.button:not(:disabled):hover {
background-color: rgb(224 221 220 / 0.4); /* --grey-300 */
}

.button.pressed,
.button:active:enabled {
background-color: rgb(224 221 220 / 0.7); /* --grey-300 */
border: 1px solid var(--primary);
}
}

.button_container:has(.button:disabled) {
background-color: var(--grey-400);
opacity: 0.5;
}

.button_container.outline:has(.button:disabled) {
background-color: transparent;
}

.iconBaseStyle {
margin-right: 8px;
}
Expand Down
28 changes: 24 additions & 4 deletions frontend/src/components/button.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import React from 'react';
import styles from './button.module.css';
import classNames from 'classnames';

interface ButtonProps {
text?: string;
icon?: string;
disabled?: boolean;
isOutline?: boolean;
isPressed?: boolean;
onClick?: () => void;
}

export const Button = ({ text, icon, disabled, onClick }: ButtonProps) => {
export const Button = ({
text,
icon,
disabled,
isOutline,
isPressed,
onClick,
}: ButtonProps) => {
const isIconOnly = !text && icon;

return (
<div className={styles.button_container}>
<div
className={classNames(styles.button_container, {
[styles.outline]: isOutline,
})}
>
<button
disabled={disabled}
className={`${styles.button} ${isIconOnly ? styles.iconOnly : styles.withText}`}
className={classNames(styles.button, {
[styles.iconOnly]: isIconOnly,
[styles.withText]: !isIconOnly,
[styles.pressed]: isPressed,
})}
onClick={onClick}
>
{icon && (
<img
src={icon}
className={`${styles.iconBaseStyle} ${isIconOnly ? styles.iconOnlyStyle : ''}`}
className={classNames(styles.iconBaseStyle, {
[styles.iconOnlyStyle]: isIconOnly,
})}
/>
)}
{text}
Expand Down

0 comments on commit 01df85f

Please sign in to comment.