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

feat: new button switch component

parent 7103503a
No related branches found
No related tags found
1 merge request!8Support for react.js components
Pipeline #1069 passed
import React, { useState } from "react";
import ReactDOM from "react-dom/client";
import { Button, Info, Pair } from "./components";
import { Button, ButtonSwitch, Info, Pair } from "./components";
import "./app.css";
......@@ -15,7 +15,14 @@ export const App = () => {
<Pair
key="button"
name={"Button"}
valueNode={<Button text="NEO" size={"large"} style={["simple"]} />}
valueNode={
<ButtonSwitch
options={["NEO", "CLASSIC"]}
size={"large"}
style={["simple"]}
onChange={(v) => alert(v)}
/>
}
/>
];
return (
......
import React, { FC, useState } from "react";
import Button from "../button/button";
type ButtonSwitchProps = {
options: string[];
size?: string;
style?: string[];
onClick?: () => void;
onChange?: (value: string, index: number) => void;
};
export const ButtonSwitch: FC<ButtonSwitchProps> = ({
options,
size = "small",
style = ["simple", "border"],
onClick,
onChange
}) => {
const [index, setIndex] = useState(0);
const text = () => options[index];
const _onClick = () => {
const indexNew = (index + 1) % options.length;
const option = options[indexNew];
setIndex(indexNew);
if (onClick) onClick();
if (onChange) onChange(option, indexNew);
};
return (
<Button text={text()} size={size} style={style} onClick={_onClick} />
);
};
export default ButtonSwitch;
export * from "./button/button";
export * from "./button-switch/button-switch";
export * from "./info/info";
export * from "./pair/pair";
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