-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Initial implementation of new StartStop UI
- Loading branch information
Showing
25 changed files
with
329 additions
and
111 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/app/Marine2/components/_composed/StartStop/Buttons/Buttons.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { FC, useState } from "react" | ||
import { translate } from "react-i18nify" | ||
import Button from "../../../_elements/Button" | ||
import { ToggleSwitchButton } from "../../../_elements/ToggleSwitchButton/ToggleSwitchButton" | ||
import { formatStartStopFor } from "../../../../utils/formatters/general/start-stop/format-start-stop-for" | ||
import { AutoStartStopModal } from "../Modals/AutoStartStopModal" | ||
|
||
interface Props {} | ||
|
||
export const Buttons: FC<Props> = ({}) => { | ||
const [showModal, setShowModal] = useState(false) // naar global state? modal systeem. | ||
const [disabled, setDisabled] = useState(false) // dynamisch maken | ||
|
||
const clickHandler = () => { | ||
setDisabled(!disabled) | ||
setShowModal(!showModal) | ||
} | ||
|
||
return ( | ||
<> | ||
<Button size="lg" className="w-full" disabled={false} onClick={() => console.log(true)}> | ||
{formatStartStopFor(0)} | ||
</Button> | ||
<ToggleSwitchButton | ||
id="toggleAutoStart" | ||
toggle={() => setShowModal(!showModal)} | ||
size="lg" | ||
className="w-full" | ||
selected={!disabled} | ||
> | ||
{translate("common.autoStart")} | ||
</ToggleSwitchButton> | ||
|
||
{showModal && ( | ||
<AutoStartStopModal disabled={disabled} onClose={() => setShowModal(!showModal)} onClick={clickHandler} /> | ||
)} | ||
</> | ||
) | ||
} |
61 changes: 61 additions & 0 deletions
61
src/app/Marine2/components/_composed/StartStop/Modals/AutoStartStopModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { FC } from "react" | ||
import { Modal } from "../../../ui/Modal" | ||
import { translate } from "react-i18nify" | ||
import { Message } from "../../../_elements/Message/Message" | ||
|
||
interface Props { | ||
disabled: boolean | ||
onClose: () => void | ||
onClick: () => void | ||
} | ||
|
||
export const AutoStartStopModal: FC<Props> = ({ disabled, onClose, onClick }) => { | ||
|
||
const classes = "border-victron-darkGray-200 border rounded-md w-[95%] md:w-[40rem] scale-[0.7] h-short:scale-[1]" | ||
|
||
if (disabled) { | ||
return ( | ||
<Modal.Frame open={true} onClose={() => console.log(false)} className={classes}> | ||
<Modal.Body> | ||
<Message | ||
variant="info" | ||
label="Fischer Panda Genset" | ||
title={translate("messages.enableAutostart.title")} | ||
text={translate("messages.enableAutostart.text")} | ||
/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<button onClick={onClose} className="w-full"> | ||
{translate("common.close")} | ||
</button> | ||
<div className="w-0 h-10 my-2 border-r border-victron-darkGray-200" /> | ||
<button onClick={onClick} className="w-full"> | ||
{translate("common.enable")} | ||
</button> | ||
</Modal.Footer> | ||
</Modal.Frame> | ||
) | ||
} | ||
|
||
return ( | ||
<Modal.Frame open={true} onClose={() => console.log(false)} className={classes}> | ||
<Modal.Body> | ||
<Message | ||
variant="warning" | ||
label="Fischer Panda Genset" | ||
title={translate("messages.disableAutostart.title")} | ||
text={translate("messages.disableAutostart.text")} | ||
/> | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<button onClick={onClose} className="w-full"> | ||
{translate("common.close")} | ||
</button> | ||
<div className="w-0 h-10 my-2 border-r border-victron-darkGray-200" /> | ||
<button onClick={onClick} className="w-full"> | ||
{translate("common.disable")} | ||
</button> | ||
</Modal.Footer> | ||
</Modal.Frame> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { ReactNode } from "react" | ||
import classNames from "classnames" | ||
|
||
interface Props { | ||
children: ReactNode | ||
onClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void | ||
className?: string | ||
disabled?: boolean | ||
size?: "lg" | "md" | ||
variant?: "primary" | "transparent" | ||
} | ||
|
||
const Button = ({ children, onClick, className, disabled, size = "lg", variant = "primary", ...props }: Props) => { | ||
const classes = classNames("px-4 py-1.5 whitespace-nowrap", { | ||
"rounded-md border-2": variant === "primary", | ||
"bg-victron-blue/30 dark:bg-victron-blue-dark/30 border-victron-blue text-black dark:text-white cursor-pointer": | ||
!disabled && variant === "primary", | ||
"bg-victron-gray/30 dark:bg-victron-gray-dark/30 border-victron-gray text-victron-gray dark:text-victron-gray-dark": | ||
disabled && variant === "primary", | ||
"bg-transparent text-black dark:text-white cursor-pointer": !disabled && variant === "transparent", | ||
"bg-transparent text-victron-gray dark:text-victron-gray-dark": disabled && variant === "transparent", | ||
"text-base min-h-[2.675rem]": size === "lg", | ||
"text-sm min-h-[2.375rem]": size === "md", | ||
[className as string]: className, | ||
}) | ||
|
||
return ( | ||
<button className={classes} onClick={disabled ? undefined : onClick} disabled={disabled} {...props}> | ||
{children} | ||
</button> | ||
) | ||
} | ||
|
||
export default Button |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, { FC, ReactNode } from "react" | ||
import InfoIcon from "../../../images/icons/info.svg" | ||
import WarningIcon from "../../../images/icons/warning.svg" | ||
|
||
type VariantType = "info" | "warning" | ||
|
||
interface Props { | ||
variant: VariantType | ||
label?: string | ||
title: string | ||
text: string | ||
} | ||
|
||
export const Message: FC<Props> = ({ variant, label, title, text }) => { | ||
const variantToIcon: Record<VariantType, ReactNode> = { | ||
info: ( | ||
<InfoIcon className="w-12 text-victron-blue dark:text-victron-blue-dark cursor-pointer outline-none" alt="Info" /> | ||
), | ||
warning: ( | ||
<WarningIcon | ||
className="w-12 text-victron-red dark:text-victron-red-dark cursor-pointer outline-none" | ||
alt="Info" | ||
/> | ||
), | ||
} | ||
|
||
return ( | ||
<div className="flex flex-col justify-center items-center gap-4 text-center"> | ||
{variantToIcon[variant]} | ||
<span> | ||
{label && <label className="text-center text-sm">{label}</label>} | ||
<h3 className="text-center text-lg">{title}</h3> | ||
</span> | ||
<p className="text-base">{text}</p> | ||
</div> | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
src/app/Marine2/components/_elements/ToggleSwitchButton/ToggleSwitchButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FC, ReactNode } from "react" | ||
import ToggleSwitch from "../../ui/ToggleSwitch" | ||
import classNames from "classnames" | ||
|
||
interface Props { | ||
id: string | ||
toggle: () => void | ||
selected: boolean | ||
children: ReactNode | ||
size?: "lg" | "md" | ||
className?: string | ||
} | ||
|
||
export const ToggleSwitchButton: FC<Props> = ({ id, toggle, children, size = "lg", className, selected }) => { | ||
const classes = classNames( | ||
"flex justify-between items-center min-h-[2.375rem] border-2 border-victron-gray dark:border-victron-gray-200 text-black dark:text-white cursor-pointer rounded-md px-4 py-1.5", | ||
{ | ||
"text-base min-h-[2.675rem]": size === "lg", | ||
"text-sm min-h-[2.375rem]": size === "md", | ||
[className as string]: className, | ||
} | ||
) | ||
|
||
return ( | ||
<button className={classes} onClick={toggle}> | ||
{children} | ||
<ToggleSwitch id={id} selected={selected} /> | ||
</button> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.