Skip to content

Open-source AI browser agent for Chrome and Firefox (monorepo) 🧠

1.8 KB
Raw Blame
import React, { useEffect, useState } from 'react';
import { Row, Content, Action } from 'components/Layout/Settings/Item';
import variables from 'config/variables';
import Slider from '../../../Form/Settings/Slider/Slider';

import values from 'utils/data/slider_values.json';
import EventBus from 'utils/eventbus';

const PreferencesWrapper = ({ children, ...props }) => {
  const [shown, setShown] = useState(localStorage.getItem(props.setting) === 'true');

  useEffect(() => {
    const handleToggle = (setting) => {
      // Header has already written the new value to storage.
      if (setting === props.setting) {
        setShown(localStorage.getItem(props.setting) === 'true');
      }
    };
    EventBus.on('toggle', handleToggle);
    return () => EventBus.off('toggle', handleToggle);
  }, [props.setting]);

  return (
    // `inert` takes the greyed-out controls out of the tab order and the accessibility tree too;
    // the CSS class alone only blocks the pointer.
    <div className={shown ? 'preferences' : 'preferencesInactive'} inert={!shown}>
      {props.zoomSetting && (
        <Row>
          <Content
            title={variables.getMessage(
              'modals.main.settings.sections.appearance.accessibility.widget_zoom',
            )}
            subtitle={variables.getMessage('modals.main.settings.sections.header.size')}
          />
          <Action>
            <Slider
              name={props.zoomSetting}
              min="10"
              max="400"
              default="100"
              display="%"
              marks={values.zoom}
              category={props.zoomCategory || props.category}
            />
          </Action>
        </Row>
      )}
      {children}
    </div>
  );
};

export { PreferencesWrapper as default, PreferencesWrapper };