import React, { useCallback, useRef, useEffect } from 'react'; import classNames from 'classnames'; import scrollIntoView from 'scroll-into-view-if-needed'; import { colors } from '@moda/tokens'; import { SelectableOption } from './Select'; import './SelectOption.scss'; export type SelectOptionProps = Omit, 'onClick'> & { id?: string; active: boolean; selected: boolean; option: SelectableOption; onClick: (option: SelectableOption) => void; dataTestId?: string; }; export const SelectOption: React.FC = ({ id, active, selected, option, option: { disabled, colorSwatch, label }, onClick, className, dataTestId }) => { const ref = useRef(null); const handleClick = useCallback( (event: React.MouseEvent) => { event.preventDefault(); if (!disabled) onClick(option); }, [disabled, onClick, option] ); useEffect(() => { if (active && ref.current) { scrollIntoView(ref.current, { scrollMode: 'if-needed', block: 'nearest' }); } }, [active, ref]); return (
  • {colorSwatch && (
    )} {label}
  • ); };