-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mob navigation]: refactored Sidebar into SidebarComponent, added api…
…RefItems into uuiApp in index.tsx
- Loading branch information
Showing
6 changed files
with
127 additions
and
119 deletions.
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,63 @@ | ||
import { DocItem } from '../../documents/structure'; | ||
import { Sidebar } from '../sidebar'; | ||
import React from 'react'; | ||
import { DataRowProps } from '@epam/uui-core'; | ||
import { TreeListItem } from '@epam/uui-components'; | ||
import { useQuery } from '../../helpers'; | ||
import { TMode } from './docsConstants'; | ||
import { TTheme } from '../../data'; | ||
import { svc } from '../../services'; | ||
|
||
type DocsQuery = { | ||
id: string, | ||
mode?: TMode, | ||
isSkin?: boolean, | ||
theme?: TTheme, | ||
category?: string | ||
}; | ||
|
||
const redirectTo = (query: DocsQuery) => | ||
svc.uuiRouter.redirect({ | ||
pathname: '/documents', | ||
query, | ||
}); | ||
|
||
export function SidebarComponent(props: { docItems: DocItem[] }) { | ||
const mode = useQuery<DocsQuery['mode']>('mode') || TMode.doc; | ||
const queryParamId: string = useQuery('id'); | ||
const isSkin = useQuery<DocsQuery['isSkin']>('isSkin'); | ||
const theme = useQuery<DocsQuery['theme']>('theme'); | ||
|
||
const onChange = (row: DataRowProps<TreeListItem, string>) => { | ||
if (row.parentId === 'components') { | ||
redirectTo({ | ||
category: row.parentId, | ||
mode, | ||
id: row.id, | ||
isSkin, | ||
theme, | ||
}); | ||
} else { | ||
redirectTo({ id: row.id, category: row.parentId }); | ||
} | ||
}; | ||
|
||
return ( | ||
<Sidebar<DocItem> | ||
value={ queryParamId } | ||
onValueChange={ onChange } | ||
items={ props.docItems } | ||
getSearchFields={ (i) => [i.name, ...(i.tags || [])] } | ||
getItemLink={ (row) => | ||
!row.isFoldable && { | ||
pathname: '/documents', | ||
query: { | ||
id: row.id, | ||
mode: (row.parentId && mode), | ||
isSkin: (row.parentId && isSkin), | ||
category: row.parentId, | ||
}, | ||
} } | ||
/> | ||
); | ||
} |
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
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
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
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
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