-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2073475
commit d40e007
Showing
23 changed files
with
241 additions
and
262 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
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,22 @@ | ||
import React from 'react'; | ||
import { Nav } from '@alifd/next'; | ||
import { createMenuItem } from './createMenuItem'; | ||
import type { DataSourceOption } from './types'; | ||
|
||
export function createContents(array: DataSourceOption[] = []) { | ||
return array.map(item => { | ||
if (item.type === 'group' && item.children && item.children.length > 0) { | ||
return ( | ||
<Nav.Group key={item.key} label={item.value}> | ||
{item.children.map(it => createMenuItem(it))} | ||
</Nav.Group> | ||
); | ||
} | ||
|
||
if (item.type === 'divider') { | ||
return <Nav.Divider key={item.key} />; | ||
} | ||
|
||
return createMenuItem(item); | ||
}); | ||
} |
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,43 @@ | ||
import React from 'react'; | ||
import { Nav } from '@alifd/next'; | ||
import { ContentType } from '@alifd/adaptor-helper'; | ||
import { createContents } from './createContents'; | ||
import type { DataSourceOption } from './types'; | ||
|
||
export function createMenuItem(item: DataSourceOption) { | ||
const { value } = | ||
((Array.isArray(item.value) && item.value) || []).find( | ||
item => item && typeof item === 'object' && item.type === ContentType.icon | ||
) || {}; | ||
if (item.children && item.children.length > 0) { | ||
return ( | ||
// TODO SubNav 并不支持 disabled 属性 (disabled={item.state === 'disabled'}) | ||
<Nav.SubNav | ||
key={item.key} | ||
icon={value} | ||
label={ | ||
Array.isArray(item.value) | ||
? item.value | ||
.filter(({ type }) => type === ContentType.text) | ||
.map(({ value }) => value) | ||
.join('') | ||
: '' | ||
} | ||
> | ||
{createContents(item.children)} | ||
</Nav.SubNav> | ||
); | ||
} | ||
|
||
return ( | ||
<Nav.Item | ||
key={item.key} | ||
icon={value} | ||
className={item.state === 'hover' ? 'next-focused' : ''} | ||
disabled={item.state === 'disabled'} | ||
children={(Array.isArray(item.value) ? item.value : ([] as Record<string, any>[])).map( | ||
({ type, value }) => (type === 'icon' ? null : value) | ||
)} | ||
/> | ||
); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import type { ContentType } from '@alifd/adaptor-helper'; | ||
|
||
type ValueType<T> = T extends keyof typeof ContentType | ||
? { type: keyof typeof ContentType; value: string }[] | ||
: boolean; | ||
|
||
export interface DataSourceOption { | ||
type: | ||
| 'node' | ||
| 'comment' | ||
| 'divider' | ||
| 'group' | ||
| typeof ContentType.icon | ||
| typeof ContentType.text; | ||
key?: string; | ||
value?: ValueType<DataSourceOption['type']>; | ||
children?: DataSourceOption[]; | ||
state?: 'active' | 'hover' | 'disabled'; | ||
level?: number; | ||
} |
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
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
Oops, something went wrong.