/** * Copyright 2022 Design Barn Inc. */ import { Panel, PanelBody, PanelRow, SelectControl } from '@wordpress/components'; import * as React from 'react'; import styled from 'styled-components'; import { InputLabel } from '../../../components/input-label'; import { SwitchLabel } from '../../../components/switch-label'; import { IHostAppProps } from '../../../interfaces/index'; import { Mode } from '../../../utils/enums'; export const PanelRowWrapper = styled(PanelRow)` gap: 10px; `; export const AnimationSettings: React.FC = ({ attributes, setAttributes }: IHostAppProps) => { const { loopHack } = attributes; const { autoplay = true, controls = true, loop = true } = JSON.parse(loopHack); const onChangeReflect = (val: unknown): void => { const newLoopHack = JSON.stringify({ autoplay, loop, controls, ...val }); setAttributes({ loopHack: newLoopHack }); }; const onChangeMode = (val: string): void => { if (val === Mode.SCROLL) { setAttributes({ animationType: val, interactivitymode: Mode.SCROLL, interactivitytype: 'seek', hover: false, state: 'none', loop: false, autoplay: false, }); onChangeReflect({ loop: false, autoplay: false }); } else if (val === Mode.NONE) { setAttributes({ animationType: val, interactivitymode: Mode.NONE, interactivitytype: Mode.NONE, state: 'autoplay', loop: true, autoplay: true, }); onChangeReflect({ loop: true, autoplay: true }); } else { setAttributes({ animationType: val, interactivitymode: Mode.CURSOR, interactivitytype: val, state: 'none', hover: false, loop: false, autoplay: false, }); } onChangeReflect({ loop: false, autoplay: false }); }; return ( onChangeMode(val)} options={[ { value: 'none', label: 'Page Load' }, { value: 'hold', label: 'Hover' }, { value: 'click', label: 'Click' }, { value: 'scroll', label: 'Scroll' }, ]} /> { const newValue = value ? value : null; setAttributes({ loop: newValue }); onChangeReflect({ loop: newValue }); }} /> { setAttributes({ controls: value ? value : null }); onChangeReflect({ controls: value ? value : null }); }} /> setAttributes({ speed: value })} /> ): void => setAttributes({ speed: event.target.value }) } /> setAttributes({ width: value })} /> setAttributes({ height: value })} /> ); };