Skip to content
Snippets Groups Projects
Verified Commit 9dee75fa authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: support for image in button

parent 8b1eda66
No related branches found
No related tags found
1 merge request!8Support for react.js components
Pipeline #1081 passed
...@@ -28,6 +28,12 @@ export const App = () => { ...@@ -28,6 +28,12 @@ export const App = () => {
return ( return (
<> <>
<Button text={getText()} onClick={onClick} /> <Button text={getText()} onClick={onClick} />
<Button
text={getText()}
image={require("../res/pause.svg")}
imageAlt="tobias"
onClick={onClick}
/>
<Info pairs={pairs()} /> <Info pairs={pairs()} />
</> </>
); );
......
...@@ -66,8 +66,7 @@ ...@@ -66,8 +66,7 @@
.button.simple > img { .button.simple > img {
margin-right: 6px; margin-right: 6px;
margin-top: 2px; vertical-align: middle;
vertical-align: top;
width: 13px; width: 13px;
} }
...@@ -83,6 +82,11 @@ ...@@ -83,6 +82,11 @@
width: 38px; width: 38px;
} }
.button.simple > span {
vertical-align: middle;
display: inline-block;
}
.button.simple.no-text > img { .button.simple.no-text > img {
margin-right: 0px; margin-right: 0px;
margin-top: 0px; margin-top: 0px;
......
...@@ -4,6 +4,8 @@ import "./button.css"; ...@@ -4,6 +4,8 @@ import "./button.css";
type ButtonProps = { type ButtonProps = {
text: string; text: string;
image?: string;
imageAlt?: string;
size?: string; size?: string;
style?: string[]; style?: string[];
onClick?: () => void; onClick?: () => void;
...@@ -11,17 +13,26 @@ type ButtonProps = { ...@@ -11,17 +13,26 @@ type ButtonProps = {
export const Button: FC<ButtonProps> = ({ export const Button: FC<ButtonProps> = ({
text, text,
image,
imageAlt,
size = "small", size = "small",
style = ["simple", "border"], style = ["simple", "border"],
onClick onClick
}) => { }) => {
const classes = () => ["button", size, ...style].join(" "); const classes = () => ["button", size, ...style].join(" ");
const _onClick = () => (onClick ? onClick() : undefined); const _onClick = () => (onClick ? onClick() : undefined);
return ( const buttonSimple = () => (
<span className={classes()} onClick={_onClick}> <span className={classes()} onClick={_onClick}>
{text} {text}
</span> </span>
); );
const buttonImage = () => (
<span className={classes()} onClick={_onClick}>
<img src={image} alt={imageAlt} />
<span>{text}</span>
</span>
);
return image ? buttonImage() : buttonSimple();
}; };
export default Button; export default Button;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment