Skip to content

Commit

Permalink
feat: nav 的连接支持设置 target (#2177)
Browse files Browse the repository at this point in the history
  • Loading branch information
吴多益 authored Jun 30, 2021
1 parent 54efd88 commit 63466f4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 17 deletions.
40 changes: 23 additions & 17 deletions docs/zh-CN/components/nav.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ order: 58
{
"label": "Nav 3",
"to": "/docs/renderers"
},
{
"label": "外部地址",
"to": "http://www.baidu.com/",
"target": "_blank"
}
]
}
Expand Down Expand Up @@ -115,20 +120,21 @@ order: 58

## 属性表

| 属性名 | 类型 | 默认值 | 说明 |
| ----------------- | ---------------------------------------- | ------- | ---------------------------------------------------------------- |
| type | `string` | `"nav"` | 指定为 Nav 渲染器 |
| className | `string` | | 外层 Dom 的类名 |
| stacked | `boolean` | `true` | 设置成 false 可以以 tabs 的形式展示 |
| source | `string`[API](../../docs/types/api) | | 可以通过变量或 API 接口动态创建导航 |
| deferApi | [API](../../docs/types/api) | | 用来延时加载选项详情的接口,可以不配置,不配置公用 source 接口。 |
| links | `Array` | | 链接集合 |
| links[x].label | `string` | | 名称 |
| links[x].to | [模板](../../docs/concepts/template) | | 链接地址 |
| links[x].icon | `string` | | 图标 |
| links[x].children | `Array<link>` | | 子链接 |
| links[x].unfolded | `boolean` | | 初始是否展开 |
| links[x].active | `boolean` | | 是否高亮 |
| links[x].activeOn | [表达式](../../docs/concepts/expression) | | 是否高亮的条件,留空将自动分析链接地址 |
| links[x].defer | `boolean` | | 标记是否为懒加载项 |
| links[x].deferApi | [API](../../docs/types/api) | | 可以不配置,如果配置优先级更高 |
| 属性名 | 类型 | 默认值 | 说明 |
| ----------------- | ---------------------------------------- | -------- | ---------------------------------------------------------------- |
| type | `string` | `"nav"` | 指定为 Nav 渲染器 |
| className | `string` | | 外层 Dom 的类名 |
| stacked | `boolean` | `true` | 设置成 false 可以以 tabs 的形式展示 |
| source | `string`[API](../../docs/types/api) | | 可以通过变量或 API 接口动态创建导航 |
| deferApi | [API](../../docs/types/api) | | 用来延时加载选项详情的接口,可以不配置,不配置公用 source 接口。 |
| links | `Array` | | 链接集合 |
| links[x].label | `string` | | 名称 |
| links[x].to | [模板](../../docs/concepts/template) | | 链接地址 |
| links[x].target | `string` | 链接关系 | |
| links[x].icon | `string` | | 图标 |
| links[x].children | `Array<link>` | | 子链接 |
| links[x].unfolded | `boolean` | | 初始是否展开 |
| links[x].active | `boolean` | | 是否高亮 |
| links[x].activeOn | [表达式](../../docs/concepts/expression) | | 是否高亮的条件,留空将自动分析链接地址 |
| links[x].defer | `boolean` | | 标记是否为懒加载项 |
| links[x].deferApi | [API](../../docs/types/api) | | 可以不配置,如果配置优先级更高 |
5 changes: 5 additions & 0 deletions examples/components/Play.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ export default class PlayGround extends React.Component {
return;
}

if (action && to && action.target) {
window.open(to, action.target);
return;
}

if (/^https?:\/\//.test(to)) {
window.location.replace(to);
} else {
Expand Down
4 changes: 4 additions & 0 deletions examples/components/SchemaRender.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export default function (schema, showCode, envOverrides) {
: window.open(to);
return;
}
if (action && to && action.target) {
window.open(to, action.target);
return;
}
if (/^https?:\/\//.test(to)) {
window.location.replace(to);
} else {
Expand Down
6 changes: 6 additions & 0 deletions examples/embed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ export function embed(
return;
}

// 主要是支持 nav 中的跳转
if (action && to && action.target) {
window.open(to, action.target);
return;
}

if (/^https?:\/\//.test(to)) {
window.location.replace(to);
} else {
Expand Down
3 changes: 3 additions & 0 deletions src/renderers/Nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export type NavItemSchema = {

to?: SchemaUrlPath;

target?: string;

unfolded?: boolean;
active?: boolean;

Expand Down Expand Up @@ -85,6 +87,7 @@ export interface Link {
className?: string;
label?: string;
to?: string;
target?: string;
icon?: string;
active?: boolean;
activeOn?: string;
Expand Down

0 comments on commit 63466f4

Please sign in to comment.