Skip to content

Commit 3350110

Browse files
authored
Merge pull request #31 from knowlyai/feature/faq
Feature - Add "FAQ" section to Home Page
2 parents 0290d7f + 479b58f commit 3350110

3 files changed

Lines changed: 136 additions & 1 deletion

File tree

src/features/home/pages/home-page.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,27 @@ import { Background } from '@/shared/components/background'
33
import { Layout } from '@/shared/components/layout'
44
import { motion } from 'framer-motion'
55
import { Button } from '@/shared/components/button'
6+
import { Accordion, AccordionItem } from '@/shared/components/accordion'
67
import { DotLottieReact } from '@lottiefiles/dotlottie-react'
78

9+
const faqs = [
10+
{
11+
title: 'What kind of file can I upload?',
12+
content:
13+
'Currently, you can upload PDF files. We are working on adding support for other file types in the future.'
14+
},
15+
{
16+
title: 'Can I create more than one model?',
17+
content:
18+
'Yes, you can create multiple models with different knowledge bases.'
19+
},
20+
{
21+
title: 'Do I need to code?',
22+
content:
23+
'No, you only need to upload the files and we take care of the rest.'
24+
}
25+
]
26+
827
function BackgroundBlobs() {
928
return (
1029
<>
@@ -163,6 +182,19 @@ export function HomePage() {
163182
<Card></Card>
164183
*/}
165184
</section>
185+
<section
186+
id="faq"
187+
className="flex h-screen flex-col items-center justify-center"
188+
>
189+
<h1 className="mb-12 text-6xl font-semibold">FAQ</h1>
190+
<Accordion className="w-250">
191+
{faqs.map((faq, i) => (
192+
<AccordionItem key={i} title={faq.title}>
193+
{faq.content}
194+
</AccordionItem>
195+
))}
196+
</Accordion>
197+
</section>
166198
</Layout>
167199
</Background>
168200
)
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import React, { useState, useRef, useEffect } from 'react'
2+
import { cn } from '../utils/cn'
3+
4+
export type AccordionItemProps = {
5+
title: string
6+
children: React.ReactNode
7+
defaultOpen?: boolean
8+
className?: string
9+
}
10+
11+
export const AccordionItem = React.forwardRef<
12+
HTMLDivElement,
13+
AccordionItemProps
14+
>(({ title, children, defaultOpen = false, className }, ref) => {
15+
const [isOpen, setIsOpen] = useState(defaultOpen)
16+
const contentRef = useRef<HTMLDivElement>(null)
17+
const [maxHeight, setMaxHeight] = useState<string>('0px')
18+
19+
useEffect(() => {
20+
if (contentRef.current) {
21+
const scrollHeight = contentRef.current.scrollHeight
22+
setMaxHeight(isOpen ? `${scrollHeight}px` : '0px')
23+
}
24+
}, [isOpen, children])
25+
26+
return (
27+
<div
28+
ref={ref}
29+
className={cn(
30+
'border-b border-white/10 py-4 transition-colors',
31+
className
32+
)}
33+
>
34+
<button
35+
onClick={() => setIsOpen(!isOpen)}
36+
className="flex w-full items-center justify-between text-left"
37+
>
38+
<svg
39+
className={cn(
40+
'h-6 w-6 transform transition-transform',
41+
isOpen ? 'rotate-45 text-white' : 'text-white/80'
42+
)}
43+
fill="none"
44+
stroke="currentColor"
45+
viewBox="0 0 24 24"
46+
xmlns="http://www.w3.org/2000/svg"
47+
>
48+
<path
49+
strokeLinecap="round"
50+
strokeLinejoin="round"
51+
strokeWidth={2}
52+
d="M12 4v16m8-8H4"
53+
/>
54+
</svg>
55+
<span
56+
className={cn(
57+
'ml-2 flex-1 text-left font-semibold transition-colors',
58+
isOpen ? 'text-white' : 'text-white/80'
59+
)}
60+
>
61+
{title}
62+
</span>
63+
</button>
64+
65+
<div
66+
ref={contentRef}
67+
style={{ maxHeight }}
68+
className="transition-max-height overflow-hidden duration-300 ease-in-out"
69+
>
70+
<div className="mt-2 font-medium text-white/70">{children}</div>
71+
</div>
72+
</div>
73+
)
74+
})
75+
76+
AccordionItem.displayName = 'AccordionItem'
77+
78+
export type AccordionProps = {
79+
children: React.ReactElement<AccordionItemProps>[]
80+
className?: string
81+
}
82+
83+
export const Accordion: React.FC<AccordionProps> = ({
84+
children,
85+
className
86+
}) => {
87+
return (
88+
<div
89+
className={cn(
90+
'w-full rounded-2xl bg-[#2c2c54]/60 p-6 shadow-lg backdrop-blur-md',
91+
className
92+
)}
93+
>
94+
{React.Children.map(children, (child, idx) =>
95+
React.cloneElement(child, {
96+
key: idx
97+
})
98+
)}
99+
</div>
100+
)
101+
}
102+
103+
Accordion.displayName = 'Accordion'

src/shared/components/navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function Navbar() {
2424
<a href="#how-knowly-works">Our product</a>
2525
<a href="">About us</a>
2626
<a href="">Pricing</a>
27-
<a href="">FAQ</a>
27+
<a href="#faq">FAQ</a>
2828
<Button className="px-6">Login</Button>
2929
</div>
3030
</div>

0 commit comments

Comments
 (0)