Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added layerName toggle to Layer Toggle switches #1408

Merged
merged 8 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/js/components/leftPanel/layersPanel/LayerToggleSwitch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import '../../../../css/layer-toggle-checkbox.scss';
import { handleCustomColorTheme } from '../../../../utils';
import { LAYER_IDS } from '../../../../../configs/layer-config';
import { setProdesLayer } from '../../../store/appState/actions';
import Switch from 'react-switch';
import ToggleComponent from '../../ui/ToggleComponent';
//Dynamic custom theme override using styled-components lib
interface CheckBoxWrapperProps {
Expand Down Expand Up @@ -62,7 +61,13 @@ const LayerToggleSwitch = (props: LayerToggleProps): React.ReactElement => {
return (
<CheckboxWrapper customColorTheme={themeColor}>
<div className="layer-checkbox">
<ToggleComponent themeColor={themeColor} onChange={toggleVisibility} checked={!!isChecked} disabled={isError} />
<ToggleComponent
themeColor={themeColor}
onChange={toggleVisibility}
checked={!!isChecked}
disabled={isError}
layerName={layerID}
/>
<label className="styled-checkboxlabel" htmlFor={`layer-checkbox-${layerID}`}>
{layerID}
</label>
Expand Down
23 changes: 20 additions & 3 deletions src/js/components/ui/ToggleComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
import React from 'react';
import { layer } from 'esri/views/3d/support/LayerPerformanceInfo';
import React, { useEffect } from 'react';
import Switch from 'react-switch';

interface IToggleComponent {
onChange: (checked: boolean) => void;
checked: boolean;
themeColor: string;
disabled: boolean;
layerName?: string;
}

const ToggleComponent = (props: IToggleComponent) => {
const { onChange, checked, themeColor, disabled } = props;
const { onChange, checked, themeColor, disabled, layerName } = props;

useEffect(() => {
// The class, id, and data-layer-name are tied to Google Analytics. Allows WRI to track clicks on the layer checkboxes and the layer name.
if (!layerName) return;

const layerElement = document.querySelector(`[data-layer-name="${layerName}"]`);
if (checked) {
layerElement?.setAttribute('class', `layer-checkbox-on`);
} else {
layerElement?.removeAttribute('class');
}
}, [checked, layerName]);

return (
<div>
<Switch
className="react-switch"
className={'react-switch' + (checked ? ' layer-checkbox-on' : '')}
checkedIcon={false}
height={13}
width={25}
Expand All @@ -23,6 +38,8 @@ const ToggleComponent = (props: IToggleComponent) => {
onChange={onChange}
checked={checked}
disabled={disabled}
id={`layer-checkbox-${layerName}`}
data-layer-name={layerName}
/>
</div>
);
Expand Down
Loading