- {separatedFields.value.shortcutFields.length && (
-
- {separatedFields.value.shortcutFields.map(field => (
-
- ))}
-
- )}
+ {renderShortcuts(prefixCls)}
{separatedFields.value.quickSelectFields.length && (
{separatedFields.value.quickSelectFields.map((field, idx) => {
diff --git a/packages/pro/search/src/components/quickSelect/QuickSelectShortcut.tsx b/packages/pro/search/src/components/quickSelect/QuickSelectShortcut.tsx
index 5ba8b6019..cf6eb3934 100644
--- a/packages/pro/search/src/components/quickSelect/QuickSelectShortcut.tsx
+++ b/packages/pro/search/src/components/quickSelect/QuickSelectShortcut.tsx
@@ -5,20 +5,21 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/
-import { defineComponent, inject } from 'vue'
+import { type Slot, computed, defineComponent, inject } from 'vue'
-import { callEmit } from '@idux/cdk/utils'
+import { callEmit, isEmptyNode } from '@idux/cdk/utils'
import { IxIcon } from '@idux/components/icon'
import { proSearchContext } from '../../token'
-import { quickSelectPanelShortcutProps } from '../../types'
+import { type SearchField, quickSelectPanelShortcutProps } from '../../types'
export default defineComponent({
props: quickSelectPanelShortcutProps,
- setup(props) {
+ setup(props, { slots }) {
const {
props: proSearchProps,
mergedPrefixCls,
+ resolvedSearchFields,
convertStateToValue,
createSearchState,
updateSearchValues,
@@ -26,19 +27,20 @@ export default defineComponent({
setActiveSegment,
} = inject(proSearchContext)!
+ const searchField = computed(() => resolvedSearchFields.value.find(field => field.key === props.fieldKey))
+
const handleClick = () => {
- const fieldKey = props.searchField.key
- if (!props.searchField.multiple && getSearchStatesByFieldKey(fieldKey).length) {
+ if (!searchField.value?.multiple && getSearchStatesByFieldKey(props.fieldKey).length) {
return
}
- const state = createSearchState(props.searchField.key)
+ const state = createSearchState(props.fieldKey)
if (state) {
updateSearchValues()
callEmit(proSearchProps.onItemCreate, {
...convertStateToValue(state.key),
- nameInput: props.searchField.label,
+ nameInput: searchField.value?.label,
})
setActiveSegment({
itemKey: state.key,
@@ -49,12 +51,29 @@ export default defineComponent({
return () => {
const prefixCls = `${mergedPrefixCls.value}-quick-select-shortcut`
+
return (
- {props.searchField.icon && }
- {props.searchField.label}
+ {slots.default?.() ?? [
+ renderIcon(prefixCls, props.icon ?? searchField.value?.icon, slots.icon, searchField.value),
+ renderLabel(slots.label, searchField.value),
+ ]}
)
}
},
})
+
+function renderIcon(prefixCls: string, icon: string | undefined, iconSlot: Slot | undefined, field?: SearchField) {
+ const content = iconSlot ? iconSlot(field) : icon ? : null
+
+ return !isEmptyNode(content) ? {content} : null
+}
+
+function renderLabel(labelSlot: Slot | undefined, field?: SearchField) {
+ if (labelSlot) {
+ return labelSlot(field)
+ }
+
+ return field?.label
+}
diff --git a/packages/pro/search/src/types/quickSelectPanel.ts b/packages/pro/search/src/types/quickSelectPanel.ts
index 60f1ef94c..98061bbc3 100644
--- a/packages/pro/search/src/types/quickSelectPanel.ts
+++ b/packages/pro/search/src/types/quickSelectPanel.ts
@@ -6,12 +6,21 @@
*/
import type { ResolvedSearchField } from './searchFields'
-import type { PropType } from 'vue'
+import type { ExtractInnerPropTypes, ExtractPublicPropTypes, VKey } from '@idux/cdk/utils'
+import type { DefineComponent, HTMLAttributes, PropType } from 'vue'
export const quickSelectPanelItemProps = {
searchField: { type: Object as PropType, required: true },
} as const
export const quickSelectPanelShortcutProps = {
- searchField: { type: Object as PropType, required: true },
+ fieldKey: { type: [String, Number, Symbol] as PropType, required: true },
+ icon: String,
} as const
+
+export type ProSearchShortcutProps = ExtractInnerPropTypes
+export type ProSearchShortcutPublicProps = ExtractPublicPropTypes
+export type ProSearchShortcutComponent = DefineComponent<
+ Omit & ProSearchShortcutPublicProps
+>
+export type ProSearchShortcutInstance = InstanceType>
diff --git a/packages/pro/search/style/quick-select.less b/packages/pro/search/style/quick-select.less
index bfe80ede4..8f460db54 100644
--- a/packages/pro/search/style/quick-select.less
+++ b/packages/pro/search/style/quick-select.less
@@ -39,11 +39,16 @@
align-items: center;
background-color: @color-graphite-l40;
border-radius: 2px;
+ cursor: pointer;
&:not(&:last-child) {
margin-right: 8px;
}
- cursor: pointer;
+ &-icon {
+ font-size: 16px;
+ margin-right: 4px;
+ color: @color-graphite;
+ }
}
&-item {
min-width: 220px;
diff --git a/packages/pro/types.d.ts b/packages/pro/types.d.ts
index 953d94c48..e59d1fd25 100644
--- a/packages/pro/types.d.ts
+++ b/packages/pro/types.d.ts
@@ -8,7 +8,7 @@
import type { LayoutSiderTriggerComponent } from '@idux/components/layout'
import type { ProFormComponent } from '@idux/pro/form'
import type { ProLayoutComponent } from '@idux/pro/layout'
-import type { ProSearchComponent } from '@idux/pro/search'
+import type { ProSearchComponent, ProSearchShortcutComponent } from '@idux/pro/search'
import type { ProTableComponent, ProTableLayoutToolComponent } from '@idux/pro/table'
import type { ProTextareaComponent } from '@idux/pro/textarea'
import type { ProTransferComponent } from '@idux/pro/transfer'
@@ -28,6 +28,7 @@ declare module 'vue' {
IxProTransfer: ProTransferComponent
IxProTree: ProTreeComponent
IxProSearch: ProSearchComponent
+ IxProSearchShortcut: ProSearchShortcutComponent
}
}