/** * Copyright (c) OpenLens Authors. All rights reserved. * Licensed under MIT License. See LICENSE in root directory for more information. */ import "./radio.scss"; import React, { useContext, useRef } from "react"; import type { SingleOrMany } from "../../utils"; import { cssNames, noop } from "../../utils"; export interface RadioGroupProps { className?: string; value?: T; asButtons?: boolean; disabled?: boolean; onChange: (value: T) => void; children: SingleOrMany>>; } interface RadioGroupContext { disabled: boolean; value: any | undefined; onSelect: (newValue: any) => void; } const radioGroupContext = React.createContext({ disabled: false, value: undefined, onSelect: noop, }); export function RadioGroup({ value, asButtons, disabled = false, onChange, className, children, }: RadioGroupProps) { return (
{children}
); } export interface RadioProps { className?: string; label: React.ReactNode; value: T; disabled?: boolean; } export function Radio({ className, label, value, disabled = false, }: RadioProps) { const ctx = useContext(radioGroupContext); const ref = useRef(null); const checked = ctx.value === value; return ( ); }