commit 79aa7a4eb0a0eb674f32994cd3247e7a853890db Author: honzapatCZ Date: Wed Mar 24 22:27:46 2021 +0100 init diff --git a/Parts/Button.js b/Parts/Button.js new file mode 100644 index 0000000..14b101d --- /dev/null +++ b/Parts/Button.js @@ -0,0 +1,72 @@ +import React from 'react' + +function ButtonBase(props) { + let color = "bg-secondary hover:bg-trinary" + switch (props.type) { + case "warning": + color = "bg-accent4 hover:bg-accent4-dark" + break; + case "danger": + color = "bg-red-700 hover:bg-red-800" + break; + case "accent": + color = "bg-accent hover:bg-accent-dark" + break; + case "accent2": + color = "bg-accent2 hover:bg-accent2-dark" + break; + case "accent3": + color = "bg-accent3 hover:bg-accent3-dark" + break; + case "accent5": + color = "bg-accent5 hover:bg-accent5-dark" + break; + default: + color = "" + break; + } + return ( + + ) +} + +export function ButtonBig(props) { + return ( + + {props.children} + + ) +} +export default function Button(props) { + return ( + + {props.children} + + ) +} +export function ButtonSmall(props) { + return ( + + {props.children} + + ) +} +export function ButtonRound(props) { + return ( + + {props.children} + + ) +} +export function IconButton({icon,...props}){ + return( + + + + ) +} \ No newline at end of file diff --git a/Parts/Card.js b/Parts/Card.js new file mode 100644 index 0000000..724b03c --- /dev/null +++ b/Parts/Card.js @@ -0,0 +1,17 @@ +import React from "react"; + +export default function Card(props) { + return
+ {props.children} +
; +} +export function CardHeader(props) { + return
+
+
+ { props.desc != null ?

{props.desc}

: ""} +
+ {props.children} +
+
; + } \ No newline at end of file diff --git a/Parts/Charts.js b/Parts/Charts.js new file mode 100644 index 0000000..1f14b18 --- /dev/null +++ b/Parts/Charts.js @@ -0,0 +1,375 @@ +import React, { useRef, useState } from "react"; +import Chart from "chart.js"; + +import Card, { CardHeader } from "./Card"; +import { createPopper } from "@popperjs/core"; + +export function ChartTooltip({ tooltipData, ...props }) { + return ( + <> +

{tooltipData.title}

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

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

+
+ )) + } + + ) +} + +const setOpacity = (hex, alpha) => `${hex}${Math.floor(alpha * 255).toString(16).padStart(2, 0)}`; + +function generateGetBoundingClientRect(x = 0, y = 0) { return () => ({ width: 0, height: 0, top: y, right: x, bottom: y, left: x }); } + +function GetPlacement(tooltipModel) { + switch (tooltipModel.xAlign) { + case "right": + return "left"; + case "left": + return "right"; + } + switch (tooltipModel.yAlign) { + case "top": + return "bottom"; + case "bottom": + return "top"; + } +} + +export default function NejChart(props) { + let [tooltipData, setTooltipData] = useState(null) + let canvasRef = useRef(null); + let popperElement = useRef(null); + + let tooltipPositionEl = { + getBoundingClientRect: generateGetBoundingClientRect(100, 100), + contextElement: canvasRef.current + }; + + React.useEffect(() => { + var ctx = canvasRef.current.getContext("2d"); + + let popper = createPopper(tooltipPositionEl, popperElement.current, { placement: "bottom" }); + + let accentCol = getComputedStyle(document.body).getPropertyValue("--accent-dark"); + let accent2Col = getComputedStyle(document.body).getPropertyValue("--accent2"); + let accent3Col = getComputedStyle(document.body).getPropertyValue("--accent3"); + let accent4Col = getComputedStyle(document.body).getPropertyValue("--accent4"); + let accent5Col = getComputedStyle(document.body).getPropertyValue("--accent5"); + let accent6Col = "rgb(180,0,0)"//getComputedStyle(document.body).getPropertyValue("--accent6"); + + let bgTrianry = getComputedStyle(document.body).getPropertyValue("--trinary"); + let primary = getComputedStyle(document.body).getPropertyValue("--primary-text"); + let secondary = getComputedStyle(document.body).getPropertyValue("--secondary-text"); + + console.log(Chart.defaults); + Chart.defaults.global = { + ...Chart.defaults.global, + maintainAspectRatio: false, + responsive: true, + defaultColor: [accentCol, accent2Col, accent3Col, accent4Col, accent5Col, accent6Col], + legend: { + ...Chart.defaults.global.legend, + labels: { + ...Chart.defaults.global.legend.labels, + fontColor: secondary, + usePointStyle: true + }, + }, + tooltips: { + ...Chart.defaults.global.tooltips, + backgroundColor: bgTrianry, + enabled: false, + custom: (tooltipModel) => { + // if chart is not defined, return early + if (!canvasRef.current) { + return; + } + // hide the tooltip when chartjs determines you've hovered out + if (tooltipModel.opacity === 0) { + setTooltipData(null); + return; + } + + let position = canvasRef.current.getBoundingClientRect(); + let left = position.left + tooltipModel.caretX; + let top = position.top + tooltipModel.caretY; + + tooltipPositionEl.getBoundingClientRect = generateGetBoundingClientRect(left, top); + popper.setOptions({ placement: GetPlacement(tooltipModel) }); + + setTooltipData(tooltipModel); + }, + }, + } + Chart.defaults.scale = { + ...Chart.defaults.scale, + ticks: { + ...Chart.defaults.scale.ticks, + fontColor: secondary, + }, + gridLines: { + ...Chart.defaults.scale.gridLines, + drawBorder: false, + color: setOpacity(primary, 0.1), + zeroLineColor: "rgba(0, 0, 0, 0)", + /* + zeroLineBorderDash: [2], + zeroLineBorderDashOffset: [2], + */ + }, + } + + console.log(Chart.defaults); + console.log(props.config); + let chart = new Chart(ctx, props.config); + return ()=>{ + chart.destroy(); + } + }, []); + return ( + <> + +
+ {tooltipData ? : null} +
+ + ); +} + +export function ExLineChart() { + + let accentCol = getComputedStyle(document.body).getPropertyValue("--accent"); + let bgTrianry = getComputedStyle(document.body).getPropertyValue("--trinary"); + let primary = getComputedStyle(document.body).getPropertyValue("--primary-text"); + let secondary = getComputedStyle(document.body).getPropertyValue("--secondary-text"); + + var config = { + type: "line", + data: { + labels: [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + ], + datasets: [ + { + label: new Date().getFullYear(), + backgroundColor: accentCol, + borderColor: accentCol, + data: [65, 78, 66, 44, 56, 67, 75], + fill: true, + hoverBackgroundColor: accentCol, + hoverBorderColor: accentCol, + backgroundColor: setOpacity(accentCol, 0.1), + }, + { + label: new Date().getFullYear() - 1, + backgroundColor: primary, + borderColor: primary, + data: [40, 68, 86, 74, 56, 60, 87], + fill: true, + hoverBackgroundColor: primary, + hoverBorderColor: primary, + backgroundColor: setOpacity(primary, 0.1), + }, + ], + }, + options: { + legend: { + display: false, + }, + tooltips: { + mode: "index", + intersect: false, + }, + scales: { + xAxes: [ + { + display: true, + scaleLabel: { + display: false, + }, + gridLines: { + display: false, + }, + }, + ], + yAxes: [ + { + ticks: { + stepSize: 25 + }, + display: true, + scaleLabel: { + display: false, + }, + gridLines: { + zeroLineBorderDash: [2], + zeroLineBorderDashOffset: [2], + }, + }, + ], + }, + } + }; + return ( + + +
+ +
+
+ ) +} + + +export function ExBarChart() { + + let accentCol = getComputedStyle(document.body).getPropertyValue("--accent"); + let bgTrianry = getComputedStyle(document.body).getPropertyValue("--trinary"); + let primary = getComputedStyle(document.body).getPropertyValue("--primary-text"); + let secondary = getComputedStyle(document.body).getPropertyValue("--secondary-text"); + + var config = { + type: "bar", + data: { + labels: [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + ], + datasets: [ + { + label: new Date().getFullYear(), + backgroundColor: accentCol, + borderColor: accentCol, + data: [65, 78, 66, 44, 56, 67, 75], + fill: false, + hoverBackgroundColor: accentCol, + hoverBorderColor: accentCol, + }, + { + label: new Date().getFullYear() - 1, + backgroundColor: primary, + borderColor: primary, + data: [40, 68, 86, 74, 56, 60, 87], + fill: false, + hoverBackgroundColor: primary, + hoverBorderColor: primary, + }, + ], + }, + options:{ + legend: { + display: false, + }, + scales: { + xAxes: [ + { + display: true, + scaleLabel: { + display: false, + }, + gridLines: { + display: false, + }, + }, + ], + yAxes: [ + { + ticks: { + stepSize: 25 + }, + display: true, + scaleLabel: { + display: false, + }, + gridLines: { + zeroLineBorderDash: [2], + zeroLineBorderDashOffset: [2], + }, + }, + ], + }, + } + }; + return ( + + +
+ {/* Chart */} +
+ +
+
+
+ ) +} + + +export function ExPieChart() { + + let accentCol = getComputedStyle(document.body).getPropertyValue("--accent-dark"); + let accent2Col = getComputedStyle(document.body).getPropertyValue("--accent2"); + let accent3Col = getComputedStyle(document.body).getPropertyValue("--accent3"); + let accent4Col = getComputedStyle(document.body).getPropertyValue("--accent4"); + let accent5Col = getComputedStyle(document.body).getPropertyValue("--accent5"); + let accent6Col = "rgb(180,0,0)"//getComputedStyle(document.body).getPropertyValue("--accent6"); + + var config = { + type: "pie", + data: { + labels: [ + "Nejcraft", + "Honzapat", + "Kubacip", + "Viktorf1", + "Regi", + "Euler", + ], + datasets: [ + { + label: new Date().getFullYear(), + data: [50, 10, 10, 10, 10, 10], + fill: true, + borderColor: [accentCol, accent2Col, accent3Col, accent4Col, accent5Col, accent6Col], + hoverBorderColor: [accentCol, accent2Col, accent3Col, accent4Col, accent5Col, accent6Col], + hoverBackgroundColor: [accentCol, accent2Col, accent3Col, accent4Col, accent5Col, accent6Col], + backgroundColor: [accentCol, accent2Col, accent3Col, accent4Col, accent5Col, accent6Col], + }, + ], + }, + options: { + legend: { + labels: { + usePointStyle: true + }, + onClick: null, + align: "end", + position: "bottom", + }, + } + } + return ( + + +
+ {/* Chart */} +
+ +
+
+
+ ) +} \ No newline at end of file diff --git a/Parts/DropDown.js b/Parts/DropDown.js new file mode 100644 index 0000000..0f8be38 --- /dev/null +++ b/Parts/DropDown.js @@ -0,0 +1,71 @@ +import React, { useEffect } from "react"; +import { createPopper } from "@popperjs/core"; + +export function DropDownItem(props) { + return ; +} +export default function Dropdown(props) { + // dropdown props + 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", + }); + setDropdownPopoverShow(true); + }; + const closeDropdownPopover = () => { + setDropdownPopoverShow(false); + }; + + function handleOutsideClick(event) { + let node = popoverDropdownRef?.current; + if (node && !node?.contains(event.target)) { + closeDropdownPopover(); + } + } + + useEffect(() => { + if ('ontouchend' in window) { + document.addEventListener('touchend', handleOutsideClick) + } else { + document.addEventListener('click', handleOutsideClick) + } + // Specify how to clean up after this effect: + return function cleanup() { + document.removeEventListener('touchend', handleOutsideClick) + document.removeEventListener('click', handleOutsideClick) + }; + }); + + return ( + <> + { + e.preventDefault(); + dropdownPopoverShow ? closeDropdownPopover() : openDropdownPopover(); + }} + > + {props.button} + +
+ {props.children} +
+ + ); +}; \ No newline at end of file diff --git a/Parts/Input.js b/Parts/Input.js new file mode 100644 index 0000000..37b936a --- /dev/null +++ b/Parts/Input.js @@ -0,0 +1,31 @@ +import React from 'react' + +function Input(props) { + return ( +
+ {props.title != null ? ( + + ) : null} + + {props.children} +
+ ) +} +function TextArea(props) { + return ( +
+ +