-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathTogglePanel.jsx
More file actions
40 lines (35 loc) · 1.15 KB
/
TogglePanel.jsx
File metadata and controls
40 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use client';
import React, { useState } from 'react';
import PropTypes from 'prop-types';
const TogglePanel = ({ title, children }) => {
const [isOpen, setIsOpen] = useState(false);
return (
<div className="border border-slate-200 rounded-lg overflow-hidden">
<button
type="button"
onClick={() => setIsOpen((prev) => !prev)}
className="w-full flex items-center justify-between px-4 py-2.5 bg-slate-50 hover:bg-slate-100 transition-colors text-left"
>
<span className="text-sm font-medium text-slate-700">{title}</span>
<svg
className={`w-4 h-4 text-slate-400 transition-transform ${isOpen ? 'rotate-180' : ''}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 9l-7 7-7-7" />
</svg>
</button>
{isOpen && (
<div className="px-4 py-3 bg-white">
{children}
</div>
)}
</div>
);
};
TogglePanel.propTypes = {
title: PropTypes.string.isRequired,
children: PropTypes.node.isRequired,
};
export default TogglePanel;