import { StackProps, Stack, Flex, Heading, FormControl, FormLabel, Switch, Input, HStack, Text, } from '@chakra-ui/react' import { DropdownList } from 'components/shared/DropdownList' import { useState, useEffect } from 'react' type StandardEmbedWindowSettingsProps = { onUpdateWindowSettings: (windowSettings: { heightLabel: string widthLabel: string }) => void } export const StandardEmbedWindowSettings = ({ onUpdateWindowSettings, ...props }: StandardEmbedWindowSettingsProps & StackProps) => { const [fullscreen, setFullscreen] = useState(false) const [inputValues, setInputValues] = useState({ widthValue: '100', widthType: '%', heightValue: '600', heightType: 'px', }) useEffect(() => { onUpdateWindowSettings({ widthLabel: fullscreen ? '100%' : inputValues.widthValue + inputValues.widthType, heightLabel: fullscreen ? '100vh' : inputValues.heightValue + inputValues.heightType, }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [inputValues, fullscreen]) const handleWidthTypeSelect = (widthType: string) => setInputValues({ ...inputValues, widthType }) const handleHeightTypeSelect = (heightType: string) => setInputValues({ ...inputValues, heightType }) return ( Window settings Set to fullscreen? setFullscreen(!fullscreen)} isChecked={fullscreen} /> {!fullscreen && ( <> Width setInputValues({ ...inputValues, widthValue: e.target.value, }) } w="70px" value={inputValues.widthValue} /> items={['px', '%']} onItemSelect={handleWidthTypeSelect} currentItem={inputValues.widthType} /> Height setInputValues({ ...inputValues, heightValue: e.target.value, }) } w="70px" value={inputValues.heightValue} /> items={['px', '%']} onItemSelect={handleHeightTypeSelect} currentItem={inputValues.heightType} /> )} ) }