sabmoďjuly

This commit is contained in:
Regi 2022-06-13 21:25:09 +02:00
parent be59cd8df2
commit 13da18bf3c
3 changed files with 29 additions and 8 deletions

View File

@ -3,9 +3,26 @@ import tw, {styled} from "twin.macro"
import "styled-components/macro" import "styled-components/macro"
import { colors, colorsDisabled, colorsHover } from "./Colors" import { colors, colorsDisabled, colorsHover } from "./Colors"
const BtnCreator = function ({ children, type, ...props }) {
switch(type){
case "submit":
type = "submit";
break;
case "reset":
type = "reset";
break;
default:
type = "button";
break;
}
return <button type={type} {...props}>
{children}
</button>
const BtnBase = styled.button(({ type }) => [ }
const BtnBase = styled(BtnCreator)(({ type }) => [
tw`bg-secondary hover:bg-trinary disabled:bg-trinary m-2 outline-none focus:outline-none text-primary font-bold ease-linear transition-all duration-150`, tw`bg-secondary hover:bg-trinary disabled:bg-trinary m-2 outline-none focus:outline-none text-primary font-bold ease-linear transition-all duration-150`,
colors[type], colorsHover[type], colorsDisabled[type] colors[type], colorsHover[type], colorsDisabled[type]
]) ])

View File

@ -6,6 +6,7 @@ import "styled-components/macro"
export let colors = { export let colors = {
error: tw`bg-red-600`, error: tw`bg-red-600`,
accent: tw`bg-accent`, accent: tw`bg-accent`,
submit: tw`bg-accent`,
accent2: tw`bg-accent2`, accent2: tw`bg-accent2`,
accent3: tw`bg-accent3`, accent3: tw`bg-accent3`,
accent4: tw`bg-accent4`, accent4: tw`bg-accent4`,
@ -15,6 +16,7 @@ export let colors = {
export let colorsHover = { export let colorsHover = {
error: tw`hover:bg-red-700`, error: tw`hover:bg-red-700`,
accent: tw`hover:bg-accent-dark`, accent: tw`hover:bg-accent-dark`,
submit: tw`hover:bg-accent-dark`,
accent2: tw`hover:bg-accent2-dark`, accent2: tw`hover:bg-accent2-dark`,
accent3: tw`hover:bg-accent3-dark`, accent3: tw`hover:bg-accent3-dark`,
accent4: tw`hover:bg-accent4-dark`, accent4: tw`hover:bg-accent4-dark`,
@ -23,6 +25,7 @@ export let colorsHover = {
export let colorsDisabled = { export let colorsDisabled = {
error: tw`disabled:bg-red-700`, error: tw`disabled:bg-red-700`,
accent: tw`disabled:bg-accent-dark`, accent: tw`disabled:bg-accent-dark`,
submit: tw`disabled:bg-accent-dark`,
accent2: tw`disabled:bg-accent2-dark`, accent2: tw`disabled:bg-accent2-dark`,
accent3: tw`disabled:bg-accent3-dark`, accent3: tw`disabled:bg-accent3-dark`,
accent4: tw`disabled:bg-accent4-dark`, accent4: tw`disabled:bg-accent4-dark`,
@ -32,6 +35,7 @@ export let colorsDisabled = {
export let textColors = { export let textColors = {
error: tw`text-red-600`, error: tw`text-red-600`,
accent: tw`text-accent`, accent: tw`text-accent`,
submit: tw`text-accent`,
accent2: tw`text-accent2`, accent2: tw`text-accent2`,
accent3: tw`text-accent3`, accent3: tw`text-accent3`,
accent4: tw`text-accent4`, accent4: tw`text-accent4`,
@ -40,6 +44,7 @@ export let textColors = {
export let textColorsHover = { export let textColorsHover = {
error: tw`hover:text-red-700`, error: tw`hover:text-red-700`,
accent: tw`hover:text-accent-dark`, accent: tw`hover:text-accent-dark`,
submit: tw`hover:text-accent-dark`,
accent2: tw`hover:text-accent2-dark`, accent2: tw`hover:text-accent2-dark`,
accent3: tw`hover:text-accent3-dark`, accent3: tw`hover:text-accent3-dark`,
accent4: tw`hover:text-accent4-dark`, accent4: tw`hover:text-accent4-dark`,

View File

@ -104,21 +104,20 @@ let Dropdown = React.forwardRef(({ children, dropdownCss, onValueChanged, button
}); });
export default Dropdown; export default Dropdown;
export function DropdownMenu({ children, fallback, notSelectedOne = true, ...props }) { export function DropdownMenu({ children, fallback, notSelectedOne = true, value, onChange, ...props }) {
let [selectedItem, setSelectedItem] = useState(0);
let ref = useRef() let ref = useRef()
let btn = fallback ?? ""; let btn = fallback ?? "";
if (children && children.length > 0) if (children && children.length > 0)
btn = children[selectedItem > children.length ? 0 : selectedItem] btn = children[value > children.length ? 0 : value]
return <> return <>
<Dropdown ref={ref} button={btn} {...props}> <Dropdown ref={ref} button={btn} {...props}>
{ {
children && children.map((i) => { children && children.map((i) => {
if (children.indexOf(i) == selectedItem) if (children.indexOf(i) == value)
return; return;
return <DropDownItem key={children.indexOf(i)} onClick={() => setSelectedItem(children.indexOf(i))}>{i}</DropDownItem> return <DropDownItem key={children.indexOf(i)} onClick={() => onChange(children.indexOf(i))}>{i}</DropDownItem>
}) })
} }
{ {