import React, { useLayoutEffect } from "react"; import { Radio as MaterialRadio } from "@material-ui/core"; import { animated } from "@react-spring/web"; import styled from "styled-components"; import { useHighlightHover } from "../Actions/utils"; import { ItemAction } from "../Actions/ItemAction"; import { useTheme } from "@fiftyone/components"; const StyledRadioContainer = styled.div``; const StyledRadio = animated(styled(ItemAction)` display: flex; justify-content: space-between; flex-direction: row; margin: 0; `); const RadioName = styled.div` text-overflow: ellipses; font-weight: bold; flex-grow: 1; `; interface RadioProps { color: string; setValue: (value: string) => void; value: string; currentValue: string; } const Radio = React.memo( ({ color, currentValue, setValue, value }: RadioProps) => { const props = useHighlightHover(false); return ( setValue(value)}> {value} ); } ); const RadioGroupContainer = styled.div` overflow: auto visible; max-height: 165px; margin: 0 -0.5rem; scrollbar-width: none; &::-webkit-scrollbar { width: 0px; background: transparent; display: none; } &::-webkit-scrollbar-thumb { width: 0px; display: none; } `; interface RadioGroupProps { choices: string[]; setValue: (value: string) => void; value: string; color?: string; } const RadioGroup = React.memo( ({ choices, color = null, value, setValue }: RadioGroupProps) => { const theme = useTheme(); color = color ?? theme.brand; useLayoutEffect(() => { choices.length >= 1 && !value && setValue(choices[0]); }, [value, choices]); if (!value) { return null; } return ( {choices.map((choice) => ( ))} ); } ); export default RadioGroup;