import React, { useCallback, useEffect, useRef, useState } from 'react'; import { RadioButton } from 'primereact/radiobutton'; import { InputSwitch } from 'primereact/inputswitch'; import classNames from 'classnames'; import { Button } from "primereact/button"; export const AppConfig = (props) => { const [active, setActive] = useState(false); const [scale, setScale] = useState(14); const [scales] = useState([12, 13, 14, 15, 16]); const [theme, setTheme] = useState('khaki'); const config = useRef(null); let outsideClickListener = useRef(null); const unbindOutsideClickListener = useCallback(() => { if (outsideClickListener.current) { document.removeEventListener('click', outsideClickListener.current); outsideClickListener.current = null; } }, []); const hideConfigurator = useCallback((event) => { setActive(false); unbindOutsideClickListener(); event.preventDefault(); }, [unbindOutsideClickListener]); const bindOutsideClickListener = useCallback(() => { if (!outsideClickListener.current) { outsideClickListener.current = (event) => { if (active && isOutsideClicked(event)) { hideConfigurator(event); } }; document.addEventListener('click', outsideClickListener.current); } }, [active, hideConfigurator]); useEffect(() => { if (active) { bindOutsideClickListener() } else { unbindOutsideClickListener() } }, [active, bindOutsideClickListener, unbindOutsideClickListener]); const isOutsideClicked = (event) => { return !(config.current.isSameNode(event.target) || config.current.contains(event.target)); } const decrementScale = () => { setScale((prevState) => --prevState); } const incrementScale = () => { setScale((prevState) => ++prevState); } useEffect(() => { document.documentElement.style.fontSize = scale + 'px'; }, [scale]) const toggleConfigurator = (event) => { setActive(prevState => !prevState); } const configClassName = classNames('layout-config', { 'layout-config-active': active }) const replaceLink = useCallback((linkElement, href, callback) => { if (isIE()) { linkElement.setAttribute('href', href); if (callback) { callback(); } } else { const id = linkElement.getAttribute('id'); const cloneLinkElement = linkElement.cloneNode(true); cloneLinkElement.setAttribute('href', href); cloneLinkElement.setAttribute('id', id + '-clone'); linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling); cloneLinkElement.addEventListener('load', () => { linkElement.remove(); cloneLinkElement.setAttribute('id', id); if (callback) { callback(); } }); } }, []) useEffect(() => { let themeElement = document.getElementById('theme-link'); const themeHref = 'assets/themes/' + theme + '/theme.css'; replaceLink(themeElement, themeHref); }, [theme, replaceLink]) const isIE = () => { return /(MSIE|Trident\/|Edge\/)/i.test(window.navigator.userAgent) } const changeTheme = (e, theme, scheme) => { props.onColorModeChange(scheme); setTheme(theme); } return (
Input Style
props.onInputStyleChange(e.value)} checked={props.inputStyle === 'outlined'} />
props.onInputStyleChange(e.value)} checked={props.inputStyle === 'filled'} />
Ripple Effect
Menu Type
props.onLayoutModeChange(e.value)} checked={props.layoutMode === 'static'} />
props.onLayoutModeChange(e.value)} checked={props.layoutMode === 'overlay'} />
Themes
Bootstrap
Material Design
Material Design Compact
Tailwind
Fluent UI
PrimeOne Design - 2022
PrimeOne Design - 2021
); }