mirror of
https://github.com/detleph/components.git
synced 2026-09-04 08:36:03 +02:00
Add icon capability to the button
This commit is contained in:
@@ -25,6 +25,22 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.icon {
|
||||||
|
width: 3.2rem;
|
||||||
|
height: 3.2rem;
|
||||||
|
|
||||||
|
padding: 0;
|
||||||
|
|
||||||
|
.children {
|
||||||
|
position: absolute;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.background {
|
||||||
|
border-radius: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.background {
|
.background {
|
||||||
border-radius: 1rem;
|
border-radius: 1rem;
|
||||||
background: $accent;
|
background: $accent;
|
||||||
|
|||||||
@@ -3,16 +3,17 @@ import styles from "./Button.module.scss";
|
|||||||
import { ReactComponent } from "../../assets/svgr-custom";
|
import { ReactComponent } from "../../assets/svgr-custom";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { ReactComponent as LoadingCircles } from "../../assets/loading-circles.svg";
|
import { ReactComponent as LoadingCircles } from "../../assets/loading-circles.svg";
|
||||||
|
import { combineConditionalClasses } from "../../helpers/combineClasses";
|
||||||
|
|
||||||
interface ButtonProps {
|
interface ButtonProps {
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
icon?: typeof ReactComponent;
|
icon?: boolean;
|
||||||
children: any;
|
children: any;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button: React.FC<ButtonProps> = ({ children, loading, icon }) => {
|
const Button: React.FC<ButtonProps> = ({ children, loading, icon }) => {
|
||||||
return (
|
return (
|
||||||
<button className={styles.button}>
|
<button className={combineConditionalClasses({ [styles.button]: true, [styles.icon]: !!icon })}>
|
||||||
<div className={styles.background}></div>
|
<div className={styles.background}></div>
|
||||||
<div style={{ opacity: loading ? 0 : 1 }} className={styles.children}>
|
<div style={{ opacity: loading ? 0 : 1 }} className={styles.children}>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
export function combineClasses(...classes: string[]): string {
|
||||||
|
return classes.join(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
export function combineConditionalClasses(classes: { [k: string]: boolean }): string {
|
||||||
|
return combineClasses(
|
||||||
|
...Object.entries(classes)
|
||||||
|
.filter(([_, v]) => v)
|
||||||
|
.map(([k]) => k)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -13,4 +13,5 @@ export const defaultButton = Template.bind({});
|
|||||||
defaultButton.args = {
|
defaultButton.args = {
|
||||||
children: "Test",
|
children: "Test",
|
||||||
loading: false,
|
loading: false,
|
||||||
|
icon: false,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user