All Downloads are FREE. Search and download functionalities are using the official Maven repository.

web.lib.core.components.toggle-panel.tsx Maven / Gradle / Ivy

There is a newer version: 37
Show newest version
import * as React from 'react';
import { useLocalStorage } from '@rehooks/local-storage';
import './toggle-panel.scss';
import { Button } from 'react-bootstrap';
import { useAnalytics } from '../../core/analytics';
import { FaCaretSquareDown, FaCaretSquareLeft, FaCaretSquareRight, FaCaretSquareUp } from 'react-icons/fa';

interface TogglePanelProps {
  id: string;
  closeLabel?: string;
  openLabel?: string
  event?: string;
  eventContext?: object;
  mode?: 'vertical' | 'horizontal';
  children: React.ReactNode;
}

export function TogglePanel(props: TogglePanelProps) {
  const analytics = useAnalytics();
  const [ open, setOpen ] = useLocalStorage(props.id, false);
  const mode = props.mode || 'vertical';
  const CloseIcon = mode === 'horizontal' ?  : ;
  const OpenIcon = mode === 'horizontal' ?  : ;
  const flip = () => {
    if (props.event && props.event.length === 2) {
      let eventContext = props.eventContext || {};
      if (open) {
        analytics.event(props.event, { ...eventContext })
      }
    }
    setOpen(!open);
  };
  return (
    <>
      
{props.children}
); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy