Skip to content

Commit

Permalink
feat(comp:cascader): add IxCascaderPanel component
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Mar 2, 2023
1 parent f45776d commit 1716168
Show file tree
Hide file tree
Showing 24 changed files with 735 additions and 271 deletions.
7 changes: 3 additions & 4 deletions packages/components/cascader/__tests__/cascader.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MountingOptions, VueWrapper, mount } from '@vue/test-utils'
import { renderWork } from '@tests'

import Cascader from '../src/Cascader'
import OverlayContent from '../src/contents/OverlayContent'
import Panel from '../src/panel/Panel'
import { CascaderData, CascaderProps } from '../src/types'

const defaultDataSource: CascaderData[] = [
Expand Down Expand Up @@ -125,8 +125,7 @@ const defaultMultipleValue = [
]
const defaultExpandedKeys = ['components', 'general']

const getAllOptionGroup = (wrapper: VueWrapper) =>
wrapper.findComponent(OverlayContent).findAll('.ix-cascader-option-group')
const getAllOptionGroup = (wrapper: VueWrapper) => wrapper.findComponent(Panel).findAll('.ix-cascader-option-group')

describe('Cascader', () => {
describe('single work', () => {
Expand Down Expand Up @@ -200,7 +199,7 @@ describe('Cascader', () => {
expect(getAllOptionGroup(wrapper).length).toBe(2)

await wrapper
.findComponent(OverlayContent)
.findComponent(Panel)
.findAll('.ix-cascader-option-group')[1]
.find('.ix-cascader-option')
.trigger('click')
Expand Down
14 changes: 14 additions & 0 deletions packages/components/cascader/demo/Panel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 80
title:
zh: 级联选择面板
en: Cascader Panel
---

## zh

单独使用级联选择面板。

## en

use `IxCascaderPanel` only.
150 changes: 150 additions & 0 deletions packages/components/cascader/demo/Panel.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<template>
<IxSpace vertical>
<IxDropdown trigger="click">
<IxButton>{{ selectedText }}</IxButton>
<template #overlay>
<IxCascaderPanel v-model:selectedKeys="fullPathValue" :dataSource="dataSource" @select="onSelect" />
</template>
</IxDropdown>
<IxDropdown trigger="click">
<IxButton>{{ singlePathValue }}</IxButton>
<template #overlay>
<IxCascaderPanel
v-model:selectedKeys="singlePathValue"
:dataSource="dataSource"
:fullPath="false"
@select="onSelect"
/>
</template>
</IxDropdown>
</IxSpace>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import { CascaderData } from '@idux/components/cascader'
const fullPathValue = ref(['components', 'general', 'button'])
const selectedText = computed(() => fullPathValue.value.join('/'))
const singlePathValue = ref('button')
const onSelect = (option: CascaderData, isSelected: boolean) => {
console.log(option, isSelected)
}
const dataSource: CascaderData[] = [
{
key: 'components',
label: 'Components',
children: [
{
key: 'general',
label: 'General',
children: [
{
key: 'button',
label: 'Button',
},
{
key: 'header',
label: 'Header',
},
{
key: 'icon',
label: 'Icon',
},
],
},
{
key: 'layout',
label: 'Layout',
children: [
{
key: 'divider',
label: 'Divider',
},
{
key: 'grid',
label: 'Grid',
},
{
key: 'space',
label: 'Space',
},
],
},
{
key: 'navigation',
label: 'Navigation',
children: [
{
key: 'breadcrumb',
label: 'Breadcrumb',
},
{
key: 'dropdown',
label: 'Dropdown',
},
{
key: 'menu',
label: 'Menu',
},
{
key: 'pagination',
label: 'Pagination',
},
],
},
],
},
{
key: 'pro',
label: 'Pro',
children: [
{
key: 'pro-layout',
label: 'Layout',
},
{
key: 'pro-table',
label: 'Table',
disabled: true,
},
{
key: 'pro-transfer',
label: 'Transfer',
},
],
},
{
key: 'cdk',
label: 'CDK',
disabled: true,
children: [
{
key: 'a11y',
label: 'Accessibility',
},
{
key: 'breakpoint',
label: 'Breakpoint',
},
{
key: 'click-outside',
label: 'ClickOutside',
},
{
key: 'clipboard',
label: 'Clipboard',
},
{
key: 'forms',
label: 'Forms',
},
],
},
]
</script>

<style scoped lang="less"></style>
44 changes: 44 additions & 0 deletions packages/components/cascader/docs/Api.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,47 @@ interface SelectedItemProps {
| --- | --- | --- | --- |
| `blur` | 失去焦点 | - | - |
| `focus` | 获取焦点 | - | - |

### IxCascaderPanel

级联选择面板

#### CascaderPanelProps

| 名称 | 说明 | 类型 | 默认值 | 全局配置 | 备注 |
| --- | --- | --- | --- | --- | --- |
| `v-model:selectedKeys` | 当前选中的的值 | `any \| any[] \| any[][]` | - | - | - |
| `v-model:expandedKeys` | 展开节点的 `key` 数组 | `VKey[]` | - | - | - |
| `v-model:loadedKeys` | 已经加载完毕的节点的 `key` | `VKey[]` | - | - | - |
| `childrenKey` | 替代[CascaderData](#CascaderData)中的`children`字段 | `string` | `children` || - |
| `customAdditional` | 自定义下拉选项的额外属性 | `CascaderCustomAdditional` | - | - | 例如 `class`, 或者原生事件 |
| `dataSource` | 树型数据数组,参见[CascaderData](#CascaderData) | `CascaderData[]` | `[]` | - | - |
| `disabled` | 禁用选择器 | `boolean` | - | - | - |
| `disableData` | 动态禁用某些项 | `(data: CascaderData) => boolean` | - | - | - |
| `empty` | 空数据时的内容 | `'default' \| 'simple' \| EmptyProps` | `'simple'` | - | - |
| `expandIcon` | 展开图标 | `string \| #expandIcon="{key: VKey, expanded: boolean, data: CascaderData}"` | `right` || - |
| `expandTrigger` | 触发展开的方式 | `'click' \| 'hover'` | `click` | - | - |
| `fullPath` | 选中后的值是否包含全部路径 | `boolean` | `true` || 会影响值的类型,参见 [基本使用](#components-cascader-demo-Basic)[多选模式](#components-cascader-demo-Multiple) |
| `getKey` | 获取数据的唯一标识 | `string \| (data: CascaderData) => VKey` | `key` || - |
| `labelKey` | 替代[CascaderData](#CascaderData)中的`label`字段 | `string` | `label` | ✅ | -
| `loadChildren` | 加载子节点数据 | `(data: CascaderData) => Promise<CascaderData[]>` | - | - | - |
| `maxLabel` | 最多显示多少个标签 | `number \| 'responsive'` | - | - | 响应式模式会对性能产生损耗 |
| `multiple` | 多选模式 | `boolean` | `false` | - | - |
| `multipleLimit` | 最多选中多少项 | `number` | - | - | - |
| `searchable` | 是否可搜索 | `boolean \| 'overlay'` | `false` | - | 当为 `true` 时搜索功能集成在选择器上,当为 `overlay` 时,搜索功能集成在悬浮层上 |
| `searchFn` | 根据搜索的文本进行筛选 | `boolean \| SelectSearchFn` | `true` | - |`true` 时使用默认的搜索规则, 如果使用远程搜索,应该设置为 `false` |
| `separator` | 设置分割符 | `string` | `/` | - | - |
| `strategy` | 设置级联策略 | `'all' \| 'parent' \| 'child' \| 'off'` | `'all'` | - | 具体用法参见 [级联策略](#components-cascader-demo-Strategy) |
| `virtual` | 是否开启虚拟滚动 | `boolean` | `false` | - | 需要设置 `height` |
| `onSelect` | 选中值触发 | `(option: CascaderData, oldValue: any) => void` | - | - | - |
| `onExpand` | 点击展开图标时触发 | `(expanded: boolean, isSelected: boolean) => void` | - | - | - |
| `onExpandedChange` | 展开状态发生变化时触发 | `(expendedKeys: VKey[], expendedData: CascaderData[]) => void` | - | - | - |
| `onLoaded` | 子节点加载完毕时触发 | `(loadedKeys: VKey[], data: CascaderData) => void` | - | - | - |
| `onSearch` | 开启搜索功能后,输入后的回调 | `(searchValue: string) => void` | - | - | 通常用于服务端搜索 |

#### CascaderPanelSlots

| 名称 | 说明 | 参数类型 | 备注 |
| --- | --- | --- | --- |
| `empty` | 自定义空状态 | - | - |
| `optionLabel` | 自定义选项的文本 | `data: SelectOption` | - |
9 changes: 7 additions & 2 deletions packages/components/cascader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

import type { CascaderComponent } from './src/types'
import type { CascaderComponent, CascaderPanelComponent } from './src/types'

import Cascader from './src/Cascader'
import CascaderPanel from './src/panel/Panel'

const IxCascader = Cascader as unknown as CascaderComponent
const IxCascaderPanel = CascaderPanel as unknown as CascaderPanelComponent

export { IxCascader }
export { IxCascader, IxCascaderPanel }

export type {
CascaderInstance,
CascaderComponent,
CascaderPublicProps as CascaderProps,
CascaderPanelInstance,
CascaderPanelComponent,
CascaderPanelPublicProps as CascaderPanelProps,
CascaderData,
CascaderExpandTrigger,
CascaderSearchFn,
Expand Down

0 comments on commit 1716168

Please sign in to comment.