UNPKG

abhi-react-lib

Version:
53 lines (49 loc) 1.46 kB
import * as React from 'react'; import { useState } from 'react'; const Button = ({ children, onClick, color, variant = "default", style, disabled }) => { const getBackgroundColor = () => { if (color) return color; switch (variant) { case "success": return "green"; case "danger": return "red"; case "primary": return "#61dafbaa"; case "secondary": return "#cd13fbaa"; case "warning": return "orange"; default: return "black"; } }; return (React.createElement("button", { onClick: onClick, style: { padding: "10px 20px", fontSize: "1em", borderRadius: "5px", cursor: disabled ? "not-allowed" : "pointer", backgroundColor: getBackgroundColor(), color: "white", border: "none", outline: "none", ...style, }, disabled: disabled }, children)); }; const useCounter = () => { const [count, setCount] = useState(0); const increment = () => { setCount(count + 1); }; const decrement = () => { if (count > 0) { setCount(count - 1); } }; const reset = () => { setCount(0); }; return { count, increment, decrement, reset }; }; export { Button, useCounter };