import React, { useState } from 'react' import * as RadixTooltip from '@radix-ui/react-tooltip' import { StyledLabel, CopyLabelContainer, StyledOptionalToggle, StyledToolTipContent, ToolTipArrow } from './StyledUI' import { useInputContext, usePanelSettingsContext } from '../../context' import { LevaErrors, warn } from '../../utils' function OptionalToggle() { const { id, disable, disabled } = useInputContext() return ( <> disable(!disabled)} /> ) } type LabelProps = React.ComponentProps function RawLabel(props: LabelProps) { const { id, optional, hint } = useInputContext() const htmlForProp = props.htmlFor || (id ? id : undefined) // If there's no tooltip, and if the label is of type string, then add a title. const titleProp = !hint && typeof props.children === 'string' ? props.children : undefined return ( <> {optional && } {hint !== undefined ? ( {hint} ) : ( )} ) } export function Label({ align, ...props }: LabelProps & { align?: 'top' }) { const { value, label, key, disabled } = useInputContext() const { hideCopyButton } = usePanelSettingsContext() const copyEnabled = !hideCopyButton && key !== undefined const [copied, setCopied] = useState(false) const handleClick = async () => { try { await navigator.clipboard.writeText(JSON.stringify({ [key]: value ?? '' })) setCopied(true) } catch { warn(LevaErrors.CLIPBOARD_ERROR, { [key]: value }) } } return ( setCopied(false)}> {copyEnabled && !disabled && (
{!copied ? ( ) : ( )}
)}
) }