Skip to content

Commit

Permalink
feat(pro:search): add size prop (#1667)
Browse files Browse the repository at this point in the history
  • Loading branch information
sallerli1 committed Sep 8, 2023
1 parent f6bed3c commit e8068bd
Show file tree
Hide file tree
Showing 10 changed files with 361 additions and 27 deletions.
1 change: 1 addition & 0 deletions packages/pro/config/src/defaultConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ export const defaultConfig: ProGlobalConfig = {
clearable: true,
clearIcon: 'close-circle',
searchIcon: 'search',
size: 'md',
},
}
2 changes: 2 additions & 0 deletions packages/pro/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { PortalTargetType } from '@idux/cdk/portal'
import type { FormSize } from '@idux/components/form'
import type { ProFormSchemaFormatter } from '@idux/pro/form'
import type { ProLocale } from '@idux/pro/locales'
import type { ProSearchSize } from '@idux/pro/search'
import type { ProTableColumnIndexable } from '@idux/pro/table'
import type { TextareaResize } from '@idux/pro/textarea'
import type { Options as AjvOptions } from 'ajv'
Expand Down Expand Up @@ -88,6 +89,7 @@ export interface ProSearchConfig {
clearable: boolean
clearIcon: string | VNode
searchIcon: string | VNode
size: ProSearchSize
overlayContainer?: PortalTargetType
}

Expand Down
14 changes: 14 additions & 0 deletions packages/pro/search/demo/Size.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
order: 2
title:
zh: 尺寸
en: Size
---

## zh

支持 `sm``md` 两种尺寸。

## en

Supports `sm` and `md` size.
295 changes: 295 additions & 0 deletions packages/pro/search/demo/Size.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
<template>
<IxRadioGroup v-model:value="size" buttoned>
<IxRadio value="sm">Small</IxRadio>
<IxRadio value="md">Medium</IxRadio>
</IxRadioGroup>
<br />
<br />
<IxProSearch
v-model:value="value"
style="width: 100%"
:size="size"
:searchFields="searchFields"
:onChange="onChange"
:onSearch="onSearch"
></IxProSearch>
</template>

<script setup lang="ts">
import type { ProSearchSize, SearchField, SearchValue } from '@idux/pro/search'
import { ref } from 'vue'
const size = ref<ProSearchSize>('md')
const value = ref<SearchValue[]>([
{
key: 'level',
name: 'Level',
operator: '=',
value: 'level1',
},
{
key: 'security_state',
name: 'Security State',
value: ['high', 'low'],
},
{
key: 'keyword',
name: '',
value: 'custom keyword',
},
])
const searchFields: SearchField[] = [
{
key: 'keyword',
type: 'input',
label: 'Keyword',
multiple: true,
placeholder: 'please input keyword',
fieldConfig: {
trim: true,
},
},
{
type: 'select',
label: 'Level',
key: 'level',
operators: ['=', '!='],
defaultOperator: '=',
fieldConfig: {
multiple: false,
searchable: true,
dataSource: [
{
key: 'level1',
label: 'Level 1',
},
{
key: 'level2',
label: 'Level 2',
},
{
key: 'level3',
label: 'Level 3',
},
],
},
},
{
type: 'select',
label: 'Security State',
key: 'security_state',
fieldConfig: {
multiple: true,
searchable: true,
dataSource: [
{
key: 'fatal',
label: 'fatal',
},
{
key: 'high',
label: 'high',
},
{
key: 'mediumn',
label: 'mediumn',
},
{
key: 'low',
label: 'low',
},
],
},
},
{
type: 'treeSelect',
label: 'Tree Data',
key: 'tree_data',
fieldConfig: {
multiple: true,
searchable: true,
checkable: true,
cascaderStrategy: 'all',
dataSource: [
{
label: 'Node 0',
key: '0',
children: [
{
label: 'Node 0-0',
key: '0-0',
children: [
{
label: 'Node 0-0-0',
key: '0-0-0',
},
{
label: 'Node 0-0-1',
key: '0-0-1',
},
],
},
{
label: 'Node 0-1',
key: '0-1',
children: [
{ label: 'Node 0-1-0', key: '0-1-0' },
{ label: 'Node 0-1-1', key: '0-1-1' },
],
},
],
},
],
},
},
{
type: 'cascader',
key: 'cascader',
label: 'Cascader',
fieldConfig: {
fullPath: true,
multiple: true,
searchable: true,
dataSource: [
{
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',
},
],
},
],
},
},
{
type: 'datePicker',
label: 'Date',
key: 'date',
fieldConfig: {
type: 'datetime',
},
},
{
type: 'dateRangePicker',
label: 'Date Range',
key: 'date_range',
fieldConfig: {
type: 'datetime',
},
},
]
const onChange = (value: SearchValue[] | undefined, oldValue: SearchValue[] | undefined) => {
console.log(value, oldValue)
}
const onSearch = () => {
console.log('onSearch')
}
</script>

<style scoped lang="less"></style>
1 change: 1 addition & 0 deletions packages/pro/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const IxProSearchShortcut = ProSearchShortcut as unknown as ProSearchShortcutCom
export { IxProSearch, IxProSearchShortcut }

export type {
ProSearchSize,
ProSearchInstance,
ProSearchComponent,
ProSearchPublicProps as ProSearchProps,
Expand Down
2 changes: 2 additions & 0 deletions packages/pro/search/src/ProSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ export default defineComponent({
const clearable = computed(() => props.clearable ?? config.clearable)
const clearIcon = computed(() => props.clearIcon ?? config.clearIcon)
const searchIcon = computed(() => props.searchIcon ?? config.searchIcon)
const size = computed(() => props.size ?? config.size)

const allItems = computed(() => [...searchItems.value, 'name-select' as const])

const classes = computed(() => {
const prefixCls = mergedPrefixCls.value
return normalizeClass({
[prefixCls]: true,
[`${prefixCls}-${size.value}`]: size.value,
[`${prefixCls}-focused`]: focused.value,
[`${prefixCls}-disabled`]: !!props.disabled,
})
Expand Down
3 changes: 3 additions & 0 deletions packages/pro/search/src/types/proSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import type { ExtractInnerPropTypes, ExtractPublicPropTypes, MaybeArray } from '
import type { OverlayContainerType } from '@idux/components/utils'
import type { DefineComponent, HTMLAttributes, PropType, VNode, VNodeChild } from 'vue'

export type ProSearchSize = 'sm' | 'md'

export const proSearchProps = {
value: Array as PropType<SearchValue[]>,
clearable: {
Expand All @@ -33,6 +35,7 @@ export const proSearchProps = {
},
placeholder: String,
searchFields: Array as PropType<SearchField[]>,
size: String as PropType<ProSearchSize>,
zIndex: Number,

//events
Expand Down

0 comments on commit e8068bd

Please sign in to comment.