Last active
November 22, 2021 11:56
-
-
Save hieptl/a88e7ec5ece693d1849ed11b8ae16fd4 to your computer and use it in GitHub Desktop.
Channels.js - Discord Clone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import Channel from './Channel'; | |
const Channels = (props) => { | |
const { title, channelType, channels, onItemClicked } = props; | |
const [isExpanded, setIsExpanded] = useState(false); | |
const toggleExpand = () => { | |
setIsExpanded(previous => !previous); | |
}; | |
return ( | |
<div className="channels"> | |
<div className="channels__title" onClick={toggleExpand}> | |
<div className={`channel__title-left ${isExpanded ? 'channel__title-left--active' : ''}`}> | |
<svg className="arrow-gKvcEx icon-2yIBmh" width="24" height="24" viewBox="0 0 24 24"><path fill="currentColor" fillRule="evenodd" clipRule="evenodd" d="M16.59 8.59004L12 13.17L7.41 8.59004L6 10L12 16L18 10L16.59 8.59004Z"></path></svg> | |
</div> | |
<div className="channel__title-right"> | |
<span>{title}</span> | |
</div> | |
</div> | |
{isExpanded && <div className="channels__list"> | |
{channels && channels.map(channel => <Channel key={channel.guid} channelType={channelType} channel={channel} onItemClicked={onItemClicked} />)} | |
</div>} | |
</div> | |
); | |
}; | |
export default Channels; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment