diff --git a/Parts/Button.js b/Parts/Button.js index 8562218..e56a919 100644 --- a/Parts/Button.js +++ b/Parts/Button.js @@ -1,5 +1,16 @@ import React from 'react' +import tw, {styled} from "twin.macro" +import 'styled-components/macro' +import { colors, colorsDisabled, colorsHover } from './Colors' + + +const BtnBase = styled.button(({ 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`, + colors[type], colorsHover[type], colorsDisabled[type] +]) + +/* function ButtonBase(props) { let color = "bg-secondary hover:bg-trinary" switch (props.type) { @@ -33,7 +44,20 @@ function ButtonBase(props) { ) } +*/ +const ButtonBig = tw(BtnBase)`px-6 py-4 rounded-2xl` +const ButtonBigAnim = tw(ButtonBig)`transition duration-500 ease-in-out transform hover:scale-110` + +const Button = tw(BtnBase)`px-4 py-2 rounded-xl` +const ButtonSmall = tw(BtnBase)`px-3 py-1 rounded` +const ButtonRound = tw(BtnBase)`p-2 rounded-full` +const IconButton = tw(BtnBase)`p-2 rounded-full` + +export { ButtonBig, ButtonBigAnim, ButtonSmall, ButtonRound, IconButton } +export default Button; + +/* export function ButtonBig(props) { return ( @@ -41,6 +65,13 @@ export function ButtonBig(props) { ) } +export function ButtonBigAnim(props) { + return ( + + {props.children} + + ) +} export default function Button(props) { return ( @@ -62,10 +93,11 @@ export function ButtonRound(props) { ) } -export function IconButton({icon,...props}){ - return( +export function IconButton({ icon, ...props }) { + return ( - + ) -} \ No newline at end of file +} +*/ \ No newline at end of file diff --git a/Parts/Card.js b/Parts/Card.js index 724b03c..4253e72 100644 --- a/Parts/Card.js +++ b/Parts/Card.js @@ -1,15 +1,17 @@ import React from "react"; +import tw, {styled} from "twin.macro" +import 'styled-components/macro' export default function Card(props) { - return
+ return
{props.children}
; } export function CardHeader(props) { - return
-
-
- { props.desc != null ?

{props.desc}

: ""} + return
+
+
+ { props.desc != null ?

{props.desc}

: ""}
{props.children}
diff --git a/Parts/Charts.js b/Parts/Charts.js index 1f14b18..ac3d2fb 100644 --- a/Parts/Charts.js +++ b/Parts/Charts.js @@ -1,5 +1,5 @@ import React, { useRef, useState } from "react"; -import Chart from "chart.js"; +import Chart from 'chart.js/auto'; import Card, { CardHeader } from "./Card"; import { createPopper } from "@popperjs/core"; @@ -8,7 +8,7 @@ export function ChartTooltip({ tooltipData, ...props }) { return ( <>

{tooltipData.title}

- { tooltipData.body.map((item, index) => ( + {tooltipData.body.map((item, index) => (

{item.before + item.lines + item.after}

@@ -71,15 +71,15 @@ export default function NejChart(props) { responsive: true, defaultColor: [accentCol, accent2Col, accent3Col, accent4Col, accent5Col, accent6Col], legend: { - ...Chart.defaults.global.legend, + ...Chart.defaults.global?.legend, labels: { - ...Chart.defaults.global.legend.labels, + ...Chart.defaults.global?.legend?.labels, fontColor: secondary, usePointStyle: true }, }, tooltips: { - ...Chart.defaults.global.tooltips, + ...Chart.defaults.global?.tooltips, backgroundColor: bgTrianry, enabled: false, custom: (tooltipModel) => { @@ -125,7 +125,7 @@ export default function NejChart(props) { console.log(Chart.defaults); console.log(props.config); let chart = new Chart(ctx, props.config); - return ()=>{ + return () => { chart.destroy(); } }, []); @@ -223,7 +223,7 @@ export function ExLineChart() {
- +
) @@ -270,7 +270,7 @@ export function ExBarChart() { }, ], }, - options:{ + options: { legend: { display: false, }, diff --git a/Parts/Colors.js b/Parts/Colors.js new file mode 100644 index 0000000..707f367 --- /dev/null +++ b/Parts/Colors.js @@ -0,0 +1,47 @@ + +import tw, {styled} from "twin.macro" +import 'styled-components/macro' + + +export let colors = { + error: tw`bg-red-600`, + accent: tw`bg-accent`, + accent2: tw`bg-accent2`, + accent3: tw`bg-accent3`, + accent4: tw`bg-accent4`, + accent5: tw`bg-accent5`, +} + +export let colorsHover = { + error: tw`hover:bg-red-700`, + accent: tw`hover:bg-accent-dark`, + accent2: tw`hover:bg-accent2-dark`, + accent3: tw`hover:bg-accent3-dark`, + accent4: tw`hover:bg-accent4-dark`, + accent5: tw`hover:bg-accent5-dark`, +} +export let colorsDisabled = { + error: tw`disabled:bg-red-700`, + accent: tw`disabled:bg-accent-dark`, + accent2: tw`disabled:bg-accent2-dark`, + accent3: tw`disabled:bg-accent3-dark`, + accent4: tw`disabled:bg-accent4-dark`, + accent5: tw`disabled:bg-accent5-dark`, +} + +export let textColors = { + error: tw`text-red-600`, + accent: tw`text-accent`, + accent2: tw`text-accent2`, + accent3: tw`text-accent3`, + accent4: tw`text-accent4`, + accent5: tw`text-accent5`, +} +export let textColorsHover = { + error: tw`hover:text-red-700`, + accent: tw`hover:text-accent-dark`, + accent2: tw`hover:text-accent2-dark`, + accent3: tw`hover:text-accent3-dark`, + accent4: tw`hover:text-accent4-dark`, + accent5: tw`hover:text-accent5-dark`, +} \ No newline at end of file diff --git a/Parts/DropDown.js b/Parts/DropDown.js index 0f8be38..5f7de52 100644 --- a/Parts/DropDown.js +++ b/Parts/DropDown.js @@ -1,27 +1,41 @@ -import React, { useEffect } from "react"; +import React, { cloneElement, isValidElement, useEffect, useImperativeHandle, useRef, useState } from "react"; import { createPopper } from "@popperjs/core"; -export function DropDownItem(props) { - return ; -} -export default function Dropdown(props) { +import tw, { styled } from "twin.macro" +import 'styled-components/macro' +import { colors, colorsDisabled, colorsHover, textColors, textColorsHover } from "./Colors"; + +const DropDownItem = styled.button(({ type }) => [ + // The common button styles added with the tw import + tw`text-sm text-left py-2 px-4 focus:outline-none block w-full whitespace-nowrap bg-transparent hover:bg-secondary disabled:bg-secondary text-primary hover:text-primary`, + + // Use props to conditionally style your components + textColors[type], colorsHover[type] +]) +export { DropDownItem } + +let Dropdown = React.forwardRef(({ children, dropdownCss, onValueChanged, button, popper, placement, hover, ...props }, ref) => { // dropdown props + const [overButton, setOverButton] = React.useState(false); + const [overDropDown, setOverDropDown] = React.useState(false); + const [dropdownPopoverShow, setDropdownPopoverShow] = React.useState(false); + const btnDropdownRef = React.createRef(); const popoverDropdownRef = React.createRef(); + const openDropdownPopover = () => { createPopper(btnDropdownRef.current, popoverDropdownRef.current, { - placement: props.placement ?? "left-start", + placement: placement ?? "bottom", + ...popper }); setDropdownPopoverShow(true); + + onValueChanged && onValueChanged(true); }; const closeDropdownPopover = () => { setDropdownPopoverShow(false); + onValueChanged && onValueChanged(false); }; function handleOutsideClick(event) { @@ -31,6 +45,7 @@ export default function Dropdown(props) { } } + useEffect(() => { if ('ontouchend' in window) { document.addEventListener('touchend', handleOutsideClick) @@ -44,28 +59,71 @@ export default function Dropdown(props) { }; }); + useImperativeHandle(ref, () => ({ + openDropdownPopover, + closeDropdownPopover + })) + + let childrenWithProps = React.Children.map(children, (item) => { + if (!item) + return; + let click = item.props?.onClick; + let close = item.props?.closeOnClick ?? true; + return cloneElement(item, { key: children.indexOf ? children.indexOf(item) : 0, onClick: () => { close && closeDropdownPopover(); click && click() } }); + }); + return ( <> - { e.preventDefault(); dropdownPopoverShow ? closeDropdownPopover() : openDropdownPopover(); }} + onMouseEnter={() => { setOverButton(true); hover && openDropdownPopover() }} + onMouseLeave={() => { setOverButton(false); (!overDropDown && hover) && closeDropdownPopover() }} > - {props.button} - + {button} +
{ setOverDropDown(true); hover && openDropdownPopover() }} + onMouseLeave={() => { setOverDropDown(false); (!overButton && hover) && closeDropdownPopover() }} + css={[ + (dropdownPopoverShow ? tw`block` : tw`hidden`), + tw`bg-trinary text-base z-50 float-left rounded-xl overflow-hidden text-left shadow-lg`, + dropdownCss, + props.css + ]} > - {props.children} + {dropdownPopoverShow && childrenWithProps}
); -}; \ No newline at end of file +}); +export default Dropdown; + +export function DropdownMenu({ children, fallback, notSelectedOne = true, ...props }) { + let [selectedItem, setSelectedItem] = useState(0); + let ref = useRef() + + let btn = fallback ?? ""; + if (children && children.length > 0) + btn = children[selectedItem > children.length ? 0 : selectedItem] + + return <> + + { + children && children.map((i) => { + if (children.indexOf(i) == selectedItem) + return; + return setSelectedItem(children.indexOf(i))}>{i} + }) + } + { + (children == null || children.length <= (notSelectedOne ? 1 : 0)) &&

Nothing to show

+ } +
+ +} \ No newline at end of file diff --git a/Parts/Input.js b/Parts/Input.js index 8eaf093..2d71eb0 100644 --- a/Parts/Input.js +++ b/Parts/Input.js @@ -1,40 +1,46 @@ import React from 'react' +import tw from 'twin.macro' +import 'styled-components/macro' -export default function Input(props) { +export default function Input({ label, title, name, id, children, ...props }) { return ( -
- {props.title != null ? ( - - ) : null} - - {props.children} +
+ {title && ( + + )} + + {children}
) } -export function TextArea({label, title, name, id, children, ...props}) { +export function TextArea({ label, title, name, id, children, ...props }) { return ( -
- -