import { h, createRef } from 'preact'; import { useEffect } from 'preact/hooks'; import PropTypes from 'prop-types'; import { defaultChannelPropTypes } from '../../common-prop-types/channel-list-prop-type'; import { ChannelImage } from './ChannelImage'; import { Button } from '@crayons'; /** * Render a button to switch focus to a channel * * @param {object} props * * @component * * @example * * * */ export function ChannelButton(props) { const buttonRef = createRef(); const { isActiveChannel = false } = props; useEffect(() => { if (isActiveChannel) { buttonRef.current.click(); } }, [isActiveChannel, buttonRef]); const { channel, handleSwitchChannel, otherClassname, newMessagesIndicator, isUnopened, discoverableChannel, triggerActiveContent, } = props; return ( ); } ChannelButton.propTypes = { channel: defaultChannelPropTypes, discoverableChannel: PropTypes.bool, handleSwitchChannel: PropTypes.func, triggerActiveContent: PropTypes.func, newMessagesIndicator: PropTypes.string, otherClassname: PropTypes.string, isUnopened: PropTypes.string, }; ChannelButton.defaultProps = { otherClassname: '', isUnopened: '', newMessagesIndicator: '', discoverableChannel: false, handleSwitchChannel: null, triggerActiveContent: null, };