-
Notifications
You must be signed in to change notification settings - Fork 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
feat: add CookieConsent folder #245
Open
Kwasako
wants to merge
7
commits into
hngprojects:dev
Choose a base branch
from
Kwasako:feat/HNG-33-cookie-consent-settings
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 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
24b5c0d
feat: add CookieConsent folder
Kwasako 19d8355
feat
Kwasako dc5d0ac
feat: use ShadCN modal component and slightly change modal design to …
Kwasako 5ef3bdb
feat: move cookieSettings to app/data/ui.ts
Kwasako fbd04eb
move cookiesetting data to app/data
Kwasako c91331b
feat: resolve coflict by removing CookieConsent from _index.tsx
Kwasako ab42429
feat: resolve conflict
Kwasako 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 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,47 @@ | ||
.CookieConsent{ | ||
background: rgba(20, 20, 20, 1); | ||
|
||
} | ||
|
||
*{ | ||
box-sizing: border-box; | ||
} | ||
.modal{ | ||
max-width: 791px; | ||
height: auto; | ||
width: 50%; | ||
max-height: 90vh; | ||
overflow-y: auto; | ||
} | ||
|
||
.modal_content{ | ||
padding: 0px 24px; | ||
} | ||
|
||
.roboto{ | ||
font-family: Roboto; | ||
font-size: 24px; | ||
font-weight: 700; | ||
line-height: 28.13px; | ||
text-align: left; | ||
} | ||
|
||
.inter{ | ||
font-family: Inter; | ||
font-size: 16px; | ||
font-weight: 400; | ||
line-height: 19.36px; | ||
text-align: left; | ||
} | ||
|
||
.cookie_info{ | ||
display: flex; | ||
justify-content: space-between; | ||
padding: 24px 0px; | ||
|
||
|
||
} | ||
|
||
.hidden{ | ||
display: none; | ||
} |
This file contains 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,69 @@ | ||
import React, {useState} from "react"; | ||
import styles from './CookieConsent.module.css'; | ||
import CookieSettings from "./CookieSettings"; | ||
|
||
export default function CookieConsent(){ | ||
const [isExpanded, setIsExpanded] = useState(false); | ||
|
||
const toggleExpand = () => { | ||
setIsExpanded(!isExpanded); | ||
}; | ||
|
||
return ( | ||
<div className='fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50"'> | ||
<div className={`${styles.modal} bg-white p-6 rounded-lg shadow-xl max-w-3xl w-full m-10`}> | ||
<div className={`mb-6`}> | ||
<p className="text-xl font-semibold">Customize cookies</p> | ||
<p className="text-sm text-gray-600 mt-2 mb-10"> | ||
Cookies are small text files that are stored on your device when you visit websites. | ||
They are used to remember information about you, such as your login details, preferences, and browsing history. | ||
Cookies help enhance your browsing experience by allowing websites to remember your actions and preferences over time, | ||
ensuring that you don’t have to re-enter information each time you visit a site. | ||
They also help website owners analyze traffic and user behavior to improve their services. | ||
Read our <a href="#" className="text-orange-600 hover:underline" target="_blank">Privacy Policy</a> for more details | ||
</p> | ||
<div className="relative mb-2"> | ||
<div className="flex justify-between items-start"> | ||
<div className="pr-8 flex-grow"> | ||
<div className='flex justify-between items-center mb-2'> | ||
<p className="font-medium">Strictly necessary</p> | ||
<div | ||
className="ml-4" | ||
onClick={toggleExpand} | ||
role="button" | ||
tabIndex={0} | ||
onKeyDown={(e) => { | ||
if (e.key === 'Enter' || e.key === ' ') { | ||
toggleExpand(); | ||
e.preventDefault() | ||
} | ||
}} | ||
aria-expanded={isExpanded} | ||
> | ||
<img | ||
src={isExpanded ? '/chevron-down.svg' : '/chevron-up.svg'} | ||
alt={isExpanded ? 'Collapse' : 'Expand'} | ||
/> | ||
</div> | ||
</div> | ||
<p className={`text-sm text-gray-600 ${isExpanded ? '' : 'hidden'}`}> | ||
These cookies are essential for the website to function properly. | ||
They enable basic functions like page navigation, secure login, | ||
and access to protected areas of the site. Without these cookies, | ||
the website cannot perform properly. | ||
</p> | ||
<hr className="my-6" /> | ||
</div> | ||
<p className="text-gray-500 text-sm whitespace-nowrap">Always Enabled</p> | ||
</div> | ||
</div> | ||
<CookieSettings/> | ||
<div className="flex justify-end mt-6"> | ||
<button className="bg-orange-500 text-white py-2 px-4 rounded-lg">Save & Accept</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
) | ||
} |
This file contains 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,118 @@ | ||
import React, { useState } from 'react'; | ||
|
||
interface CookieSetting { | ||
title: string; | ||
description: string; | ||
id: string; | ||
} | ||
|
||
interface CookiePreferenceProps extends CookieSetting { | ||
isExpanded: boolean; | ||
onToggle: () => void; | ||
isChecked: boolean; | ||
onCheckChange: (checked: boolean) => void; | ||
} | ||
|
||
const CookiePreference: React.FC<CookiePreferenceProps> = ({ | ||
title, | ||
description, | ||
isExpanded, | ||
onToggle, | ||
id, | ||
isChecked, | ||
onCheckChange | ||
}) => { | ||
return ( | ||
<div className="mb-6"> | ||
<div className="flex justify-between items-start"> | ||
<div className="flex-grow pr-20"> | ||
<div className="flex justify-between items-center mb-2"> | ||
<p className="text-lg font-medium">{title}</p> | ||
<div | ||
className="ml-4 cursor-pointer" | ||
onClick={onToggle} | ||
role="button" | ||
tabIndex={0} | ||
onKeyDown={(e) => { | ||
if (e.key === 'Enter' || e.key === ' ') { | ||
onToggle(); | ||
e.preventDefault() | ||
} | ||
}} | ||
aria-expanded={isExpanded} | ||
> | ||
<img | ||
src={isExpanded ? '/chevron-down.svg' : '/chevron-up.svg'} | ||
alt={isExpanded ? 'Collapse' : 'Expand'} | ||
/> | ||
</div> | ||
</div> | ||
<p className={`text-sm text-gray-600 ${isExpanded ? '' : 'hidden'}`}> | ||
{description} | ||
</p> | ||
<hr className="my-6" /> | ||
</div> | ||
<label className="relative inline-flex items-center cursor-pointer" htmlFor={id}> | ||
<input | ||
type="checkbox" | ||
className="sr-only peer" | ||
id={id} | ||
checked={isChecked} | ||
onChange={(e) => onCheckChange(e.target.checked)} | ||
/> | ||
<div className="w-11 h-6 bg-gray-200 rounded-full peer peer-focus:ring-4 peer-focus:ring-blue-300 dark:peer-focus:ring-blue-800 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-orange-500"></div> | ||
</label> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const CookieSettings: React.FC = () => { | ||
const [expandedIndex, setExpandedIndex] = useState<number | null>(null); | ||
const [checkedStates, setCheckedStates] = useState<{ [key: string]: boolean }>({}); | ||
|
||
const cookieSettings = [ | ||
{ | ||
title: "Performance Cookies", | ||
id: "pc", | ||
description: "These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site." | ||
}, | ||
{ | ||
title: "Functional Cookies", | ||
id: "fc", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this array: cookSettings outside this file, to app/data/ui.ts |
||
description: "These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages." | ||
}, | ||
{ | ||
title: "Targeting Cookies", | ||
id: "tc", | ||
description: "These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites." | ||
} | ||
]; | ||
|
||
const handleToggle = (index: number) => { | ||
setExpandedIndex(expandedIndex === index ? null : index); | ||
}; | ||
|
||
const handleCheckChange = (id: string, checked: boolean) => { | ||
setCheckedStates(prev => ({ ...prev, [id]: checked })); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{cookieSettings.map((setting, index) => ( | ||
<CookiePreference | ||
key={index} | ||
title={setting.title} | ||
description={setting.description} | ||
isExpanded={expandedIndex === index} | ||
onToggle={() => handleToggle(index)} | ||
id={setting.id} | ||
isChecked={checkedStates[setting.id] || false} | ||
onCheckChange={(checked) => handleCheckChange(setting.id, checked)} | ||
/> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
export default CookieSettings; |
This file contains 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use ShadCN modal component please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried installing ShadCN UI but got an error