1+ import { forwardRef } from 'react' ;
2+
13import WithNoScriptSelect from '#ui/Common/Select/NoScriptSelect' ;
24import SidebarGroup from '#ui/Containers/Sidebar/SidebarGroup' ;
35
46import type { LinkLike } from '#ui/types' ;
5- import type { ComponentProps , FC , PropsWithChildren } from 'react' ;
7+ import type { ComponentProps , PropsWithChildren } from 'react' ;
68
79import styles from './index.module.css' ;
810
@@ -17,52 +19,46 @@ type SidebarProps = {
1719 placeholder ?: string ;
1820} ;
1921
20- const SideBar : FC < PropsWithChildren < SidebarProps > > = ( {
21- groups,
22- pathname,
23- title,
24- onSelect,
25- as,
26- children,
27- placeholder,
28- } ) => {
29- const selectItems = groups . map ( ( { items, groupName } ) => ( {
30- label : groupName ,
31- items : items . map ( ( { label, link } ) => ( { value : link , label } ) ) ,
32- } ) ) ;
22+ const SideBar = forwardRef < HTMLElement , PropsWithChildren < SidebarProps > > (
23+ ( { groups, pathname, title, onSelect, as, children, placeholder } , ref ) => {
24+ const selectItems = groups . map ( ( { items, groupName } ) => ( {
25+ label : groupName ,
26+ items : items . map ( ( { label, link } ) => ( { value : link , label } ) ) ,
27+ } ) ) ;
3328
34- const currentItem = selectItems
35- . flatMap ( item => item . items )
36- . find ( item => pathname === item . value ) ;
29+ const currentItem = selectItems
30+ . flatMap ( item => item . items )
31+ . find ( item => pathname === item . value ) ;
3732
38- return (
39- < aside className = { styles . wrapper } >
40- { children }
33+ return (
34+ < aside ref = { ref } className = { styles . wrapper } >
35+ { children }
4136
42- { selectItems . length > 0 && (
43- < WithNoScriptSelect
44- label = { title }
45- values = { selectItems }
46- defaultValue = { currentItem ?. value }
47- placeholder = { placeholder }
48- onChange = { onSelect }
49- className = { styles . mobileSelect }
50- as = { as }
51- />
52- ) }
37+ { selectItems . length > 0 && (
38+ < WithNoScriptSelect
39+ label = { title }
40+ values = { selectItems }
41+ defaultValue = { currentItem ?. value }
42+ placeholder = { placeholder }
43+ onChange = { onSelect }
44+ className = { styles . mobileSelect }
45+ as = { as }
46+ />
47+ ) }
5348
54- { groups . map ( ( { groupName, items } ) => (
55- < SidebarGroup
56- key = { groupName . toString ( ) }
57- groupName = { groupName }
58- items = { items }
59- pathname = { pathname }
60- as = { as }
61- className = { styles . navigation }
62- />
63- ) ) }
64- </ aside >
65- ) ;
66- } ;
49+ { groups . map ( ( { groupName, items } ) => (
50+ < SidebarGroup
51+ key = { groupName . toString ( ) }
52+ groupName = { groupName }
53+ items = { items }
54+ pathname = { pathname }
55+ as = { as }
56+ className = { styles . navigation }
57+ />
58+ ) ) }
59+ </ aside >
60+ ) ;
61+ }
62+ ) ;
6763
6864export default SideBar ;
0 commit comments