Finish basic ptt implemenation

This commit is contained in:
Robert Long
2022-04-28 17:44:50 -07:00
parent 3a6346aa63
commit 363f2340a0
9 changed files with 350 additions and 45 deletions

36
src/input/Toggle.jsx Normal file
View File

@@ -0,0 +1,36 @@
import React, { useRef } from "react";
import styles from "./Toggle.module.css";
import { useToggleButton } from "@react-aria/button";
import { useToggleState } from "@react-stately/toggle";
import classNames from "classnames";
import { Field } from "./Input";
export function Toggle({ id, label, className, ...rest }) {
const buttonRef = useRef();
const state = useToggleState(rest);
const { buttonProps, isPressed } = useToggleButton(rest, state, buttonRef);
return (
<Field
className={classNames(
styles.toggle,
{ [styles.on]: isPressed },
className
)}
>
<button
{...buttonProps}
ref={buttonRef}
id={id}
className={classNames(styles.button, {
[styles.isPressed]: isPressed,
})}
>
<div className={styles.ball} />
</button>
<label className={styles.label} htmlFor={id}>
{label}
</label>
</Field>
);
}