import * as React from "react"; import { controlStyle, radioIconStyle } from "../styles/Control.styles"; import { ControlProps } from "../typings/Control"; import { cx } from "emotion"; import { colors } from "pebble-shared"; function Control(props: ControlProps) { const { checked, onChange, value, disabled, children = ControlView, type, className, indeterminate } = props; return (
onChange && onChange({ value, checked: !checked }, e) : undefined } > {children(props)}
); } interface ControlViewProps { label: React.ReactNode; checked?: boolean; type: "radio" | "checkbox"; disabled?: boolean; iconClassName?: string; indeterminate?: boolean; } export const ControlView = ({ checked, label, type, disabled, iconClassName, indeterminate }: ControlViewProps) => { const isRadio = type === "radio"; const wrapClass = cx(radioIconStyle, iconClassName); const iconClass = cx("pi", { "pi-radio": !!isRadio && !checked, "pi-radio-selected": !!isRadio && !!checked, "pi-checkbox-selected": !indeterminate && !isRadio && !!checked, "pi-checkbox-unselected": !indeterminate && !isRadio && !checked, "pi-checkbox-indeterminate": !!indeterminate && !isRadio }); const getColor = () => { if (disabled) { return colors.gray.base; } if (checked) { return colors.violet.base; } return colors.gray.light; }; return ( <>
{" "} {label} ); }; export default Control;