Files
liqa/client/src/ui/SidePanel/SidePanel.tsx
T
ars9 32beec2229 feat(client): add Timestamp component, ESLint 10 + Prettier, and code quality fixes
- add Timestamp component with moment relative time and ISO tooltip
- add Timestamp stories (JustNow, MinutesAgo, HoursAgo, DaysAgo, MonthsAgo)
- add ESLint 10 with typescript-eslint, react-hooks, react-refresh, prettier
- add Prettier config with singleQuote, semi, trailingComma all, printWidth 100
- add lint, lint:fix, format, test:storybook scripts to package.json
- fix react-hooks/set-state-in-effect in all page components
- auto-fix 113 Prettier formatting issues across src and .storybook
2026-04-09 10:25:15 +03:00

71 lines
1.9 KiB
TypeScript

import React, { useState } from 'react';
import styles from './SidePanel.module.css';
export interface SidePanelProps {
children: React.ReactNode;
header?: React.ReactNode;
width?: number;
defaultCollapsed?: boolean;
collapsed?: boolean;
onCollapsedChange?: (collapsed: boolean) => void;
className?: string;
}
export function SidePanel({
children,
header,
width = 240,
defaultCollapsed = false,
collapsed: controlledCollapsed,
onCollapsedChange,
className,
}: SidePanelProps) {
const [internalCollapsed, setInternalCollapsed] = useState(defaultCollapsed);
const isControlled = controlledCollapsed !== undefined;
const collapsed = isControlled ? controlledCollapsed : internalCollapsed;
function toggle() {
const next = !collapsed;
if (!isControlled) setInternalCollapsed(next);
onCollapsedChange?.(next);
}
return (
<aside
className={[styles.panel, collapsed ? styles.collapsed : '', className]
.filter(Boolean)
.join(' ')}
style={{ '--side-panel-width': `${width}px` } as React.CSSProperties}
aria-expanded={!collapsed}
>
<div className={styles.inner}>
{header && <div className={styles.header}>{header}</div>}
<div className={styles.content}>{children}</div>
</div>
<button
className={styles.toggle}
onClick={toggle}
aria-label={collapsed ? 'Expand panel' : 'Collapse panel'}
title={collapsed ? 'Expand' : 'Collapse'}
>
<svg
className={styles.chevron}
width="16"
height="16"
viewBox="0 0 16 16"
fill="none"
aria-hidden="true"
>
<path
d="M6 3L11 8L6 13"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
</button>
</aside>
);
}