-
Notifications
You must be signed in to change notification settings - Fork 6
feat: Add Policies dropdown to navbar with General Policy and Good Practices documents #125
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
Open
ManiBAJPAI22
wants to merge
6
commits into
kleros:dev
Choose a base branch
from
ManiBAJPAI22:Policies
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b74bd92
adding policies
ManiBAJPAI22 275aa09
updated the dimensions
ManiBAJPAI22 55943be
optimised
ManiBAJPAI22 efc5ae5
issue resolved
ManiBAJPAI22 8cac6c0
Delete web/package.json
ManiBAJPAI22 9bb1a8f
Update Policies.tsx
ManiBAJPAI22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,267 @@ | ||
import React, { useState, useRef, useEffect } from "react"; | ||
import styled, { css } from "styled-components"; | ||
import { landscapeStyle } from "styles/landscapeStyle"; | ||
|
||
import { useOpenContext } from "../MobileHeader"; | ||
|
||
const Container = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
${landscapeStyle( | ||
() => css` | ||
flex-direction: row; | ||
` | ||
)}; | ||
`; | ||
|
||
const Title = styled.h1` | ||
display: block; | ||
margin-bottom: 8px; | ||
|
||
${landscapeStyle( | ||
() => css` | ||
display: none; | ||
` | ||
)}; | ||
`; | ||
|
||
const PoliciesButton = styled.button<{ isActive: boolean; isMobileNavbar?: boolean }>` | ||
display: flex; | ||
align-items: center; | ||
gap: 8px; | ||
background: none; | ||
border: none; | ||
cursor: pointer; | ||
font-size: 16px; | ||
color: ${({ isActive, theme }) => (isActive ? theme.primaryText : `${theme.primaryText}BA`)}; | ||
font-weight: ${({ isActive, isMobileNavbar }) => (isMobileNavbar && isActive ? "600" : "normal")}; | ||
padding: 8px 8px 8px 0; | ||
border-radius: 7px; | ||
|
||
&:hover { | ||
color: ${({ theme, isMobileNavbar }) => (isMobileNavbar ? theme.primaryText : theme.white)} !important; | ||
} | ||
|
||
${landscapeStyle( | ||
() => css` | ||
color: ${({ theme }) => theme.white}; | ||
padding: 16px 8px; | ||
` | ||
)}; | ||
`; | ||
|
||
const ChevronIcon = styled.span<{ isOpen: boolean }>` | ||
display: inline-block; | ||
width: 6px; | ||
height: 6px; | ||
border-right: 2px solid currentColor; | ||
border-bottom: 2px solid currentColor; | ||
transform: rotate(45deg); | ||
transition: transform 0.2s ease; | ||
margin-top: -4px; | ||
`; | ||
|
||
const DropdownContainer = styled.div<{ isOpen: boolean; isMobileNavbar?: boolean }>` | ||
position: absolute; | ||
top: 100%; | ||
left: 0; | ||
background: ${({ theme }) => theme.whiteBackground}; | ||
border: 1px solid ${({ theme }) => theme.stroke}; | ||
border-radius: 3px; | ||
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.15); | ||
width: 247px; | ||
z-index: 1000; | ||
opacity: ${({ isOpen }) => (isOpen ? 1 : 0)}; | ||
visibility: ${({ isOpen }) => (isOpen ? "visible" : "hidden")}; | ||
transform: translateY(${({ isOpen }) => (isOpen ? "0" : "-10px")}); | ||
transition: all 0.2s ease; | ||
|
||
${landscapeStyle( | ||
() => css` | ||
top: calc(100% + 8px); | ||
left: 50%; | ||
transform: translateX(-50%) translateY(0); | ||
` | ||
)}; | ||
`; | ||
|
||
const DropdownItem = styled.a` | ||
display: flex; | ||
align-items: center; | ||
gap: 12px; | ||
padding: 12px 16px; | ||
text-decoration: none; | ||
color: ${({ theme }) => theme.primaryText}; | ||
background: transparent; | ||
border-left: 3px solid transparent; | ||
height: 45px; | ||
transition: all 0.2s ease; | ||
|
||
&:hover { | ||
background: ${({ theme }) => theme.mediumBlue}; | ||
border-left-color: ${({ theme }) => theme.primaryBlue}; | ||
} | ||
|
||
&:first-child { | ||
border-top-left-radius: 3px; | ||
border-top-right-radius: 3px; | ||
} | ||
|
||
&:last-child { | ||
border-bottom-left-radius: 3px; | ||
border-bottom-right-radius: 3px; | ||
} | ||
`; | ||
|
||
const ItemIcon = styled.div` | ||
width: 20px; | ||
height: 20px; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
color: ${({ theme }) => theme.primaryBlue}; | ||
`; | ||
|
||
const CheckIcon = styled.div` | ||
width: 18px; | ||
height: 18px; | ||
border: 2px solid currentColor; | ||
border-radius: 50%; | ||
position: relative; | ||
|
||
&::after { | ||
content: ""; | ||
position: absolute; | ||
top: 2px; | ||
left: 5px; | ||
width: 5px; | ||
height: 8px; | ||
border: solid currentColor; | ||
border-width: 0 2px 2px 0; | ||
transform: rotate(45deg); | ||
} | ||
`; | ||
|
||
const DocumentIcon = styled.div` | ||
width: 18px; | ||
height: 22px; | ||
border: 2px solid currentColor; | ||
border-radius: 2px; | ||
position: relative; | ||
|
||
&::after { | ||
content: ""; | ||
position: absolute; | ||
top: 3px; | ||
left: 3px; | ||
right: 3px; | ||
height: 2px; | ||
background: currentColor; | ||
border-radius: 1px; | ||
} | ||
|
||
&::before { | ||
content: ""; | ||
position: absolute; | ||
top: 8px; | ||
left: 3px; | ||
right: 3px; | ||
height: 1px; | ||
background: currentColor; | ||
border-radius: 0.5px; | ||
} | ||
`; | ||
|
||
interface IPolicies { | ||
/** Whether the component is being used in the mobile navbar */ | ||
isMobileNavbar?: boolean; | ||
} | ||
|
||
const Policies: React.FC<IPolicies> = ({ isMobileNavbar }) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const dropdownRef = useRef<HTMLDivElement>(null); | ||
const { toggleIsOpen } = useOpenContext(); | ||
|
||
// Policy documents configuration | ||
|
||
const policies = [ | ||
{ | ||
id: "general-policy", | ||
name: "General Policy", | ||
url: "https://cdn.kleros.link/ipfs/QmU2GuwcSs8tFp8gWf5hcXVbcJKRqwoecNnERz9XjKr18d", | ||
icon: CheckIcon, | ||
}, | ||
{ | ||
id: "good-practices", | ||
name: "Good Practices", | ||
url: "https://cdn.kleros.link/ipfs/QmcCyR68RmwWfdVKinY8Fmiy73a6xEzGqYDcvAh9EFUnLF", | ||
icon: DocumentIcon, | ||
}, | ||
]; | ||
|
||
useEffect(() => { | ||
const handleClickOutside = (event: MouseEvent) => { | ||
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
document.addEventListener("mousedown", handleClickOutside); | ||
return () => { | ||
document.removeEventListener("mousedown", handleClickOutside); | ||
}; | ||
}, []); | ||
|
||
const handleItemClick = (policy: typeof policies[0]) => { | ||
setIsOpen(false); | ||
if (isMobileNavbar) { | ||
toggleIsOpen(); | ||
} | ||
window.open(policy.url, "_blank"); | ||
}; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const handleToggleDropdown = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return ( | ||
<Container ref={dropdownRef}> | ||
<Title>Policies</Title> | ||
<PoliciesButton | ||
onClick={handleToggleDropdown} | ||
isActive={isOpen} | ||
isMobileNavbar={isMobileNavbar} | ||
> | ||
Policies | ||
<ChevronIcon isOpen={isOpen} /> | ||
</PoliciesButton> | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<DropdownContainer isOpen={isOpen} isMobileNavbar={isMobileNavbar}> | ||
{policies.map((policy) => { | ||
const IconComponent = policy.icon; | ||
return ( | ||
<DropdownItem | ||
key={policy.id} | ||
href={policy.url} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
handleItemClick(policy); | ||
}} | ||
> | ||
<ItemIcon> | ||
<IconComponent /> | ||
</ItemIcon> | ||
{policy.name} | ||
</DropdownItem> | ||
); | ||
})} | ||
</DropdownContainer> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default Policies; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.