feat: select add context size
parent
39e5824699
commit
124aae72a4
|
@ -52,5 +52,6 @@ export default (name: string, props: Record<any, any>) => {
|
||||||
csp,
|
csp,
|
||||||
iconPrefixCls,
|
iconPrefixCls,
|
||||||
disabled,
|
disabled,
|
||||||
|
select: configProvider.select,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -6,7 +6,7 @@ export interface RenderEmptyProps {
|
||||||
componentName?: string;
|
componentName?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RenderEmpty = (props: RenderEmptyProps) => {
|
export const DefaultRenderEmpty = (props: RenderEmptyProps) => {
|
||||||
const { prefixCls } = useConfigInject('empty', props);
|
const { prefixCls } = useConfigInject('empty', props);
|
||||||
const renderHtml = (componentName?: string) => {
|
const renderHtml = (componentName?: string) => {
|
||||||
switch (componentName) {
|
switch (componentName) {
|
||||||
|
@ -27,7 +27,7 @@ const RenderEmpty = (props: RenderEmptyProps) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderEmpty(componentName?: string): VueNode {
|
function renderEmpty(componentName?: string): VueNode {
|
||||||
return <RenderEmpty componentName={componentName} />;
|
return <DefaultRenderEmpty componentName={componentName} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type RenderEmptyHandler = typeof renderEmpty;
|
export type RenderEmptyHandler = typeof renderEmpty;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import type { App, Plugin, ExtractPropTypes } from 'vue';
|
import type { Plugin, ExtractPropTypes, App } from 'vue';
|
||||||
import { computed, defineComponent, ref } from 'vue';
|
import { computed, defineComponent, ref } from 'vue';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
import type { BaseSelectRef } from '../vc-select';
|
import type { BaseSelectRef } from '../vc-select';
|
||||||
|
@ -8,6 +8,7 @@ import type { OptionProps } from '../vc-select/Option';
|
||||||
import getIcons from './utils/iconUtil';
|
import getIcons from './utils/iconUtil';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
import useConfigInject from '../config-provider/hooks/useConfigInject';
|
||||||
|
import { DefaultRenderEmpty } from '../config-provider/renderEmpty';
|
||||||
import omit from '../_util/omit';
|
import omit from '../_util/omit';
|
||||||
import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItemContext';
|
import { FormItemInputContext, useInjectFormItemContext } from '../form/FormItemContext';
|
||||||
import type { SelectCommonPlacement } from '../_util/transition';
|
import type { SelectCommonPlacement } from '../_util/transition';
|
||||||
|
@ -17,9 +18,11 @@ import { initDefaultProps } from '../_util/props-util';
|
||||||
import type { InputStatus } from '../_util/statusUtils';
|
import type { InputStatus } from '../_util/statusUtils';
|
||||||
import { getStatusClassNames, getMergedStatus } from '../_util/statusUtils';
|
import { getStatusClassNames, getMergedStatus } from '../_util/statusUtils';
|
||||||
import { stringType, someType, functionType, booleanType } from '../_util/type';
|
import { stringType, someType, functionType, booleanType } from '../_util/type';
|
||||||
|
import { useCompactItemContext } from '../space/Compact';
|
||||||
// CSSINJS
|
// CSSINJS
|
||||||
import useStyle from './style';
|
import useStyle from './style';
|
||||||
|
import { useInjectDisabled } from '../config-provider/DisabledContext';
|
||||||
|
import devWarning from '../vc-util/devWarning';
|
||||||
|
|
||||||
type RawValue = string | number;
|
type RawValue = string | number;
|
||||||
|
|
||||||
|
@ -51,6 +54,9 @@ export const selectProps = () => ({
|
||||||
bordered: booleanType(true),
|
bordered: booleanType(true),
|
||||||
transitionName: String,
|
transitionName: String,
|
||||||
choiceTransitionName: stringType(''),
|
choiceTransitionName: stringType(''),
|
||||||
|
popupClassName: String,
|
||||||
|
/** @deprecated Please use `popupClassName` instead */
|
||||||
|
dropdownClassName: String,
|
||||||
placement: stringType<SelectCommonPlacement>(),
|
placement: stringType<SelectCommonPlacement>(),
|
||||||
status: stringType<InputStatus>(),
|
status: stringType<InputStatus>(),
|
||||||
'onUpdate:value': functionType<(val: SelectValue) => void>(),
|
'onUpdate:value': functionType<(val: SelectValue) => void>(),
|
||||||
|
@ -114,19 +120,32 @@ const Select = defineComponent({
|
||||||
|
|
||||||
return mode;
|
return mode;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ====================== Warning ======================
|
||||||
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
devWarning(
|
||||||
|
!props.dropdownClassName,
|
||||||
|
'Select',
|
||||||
|
'`dropdownClassName` is deprecated. Please use `popupClassName` instead.',
|
||||||
|
);
|
||||||
|
}
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
direction,
|
direction,
|
||||||
configProvider,
|
configProvider,
|
||||||
renderEmpty,
|
renderEmpty,
|
||||||
size,
|
size: contextSize,
|
||||||
getPrefixCls,
|
getPrefixCls,
|
||||||
getPopupContainer,
|
getPopupContainer,
|
||||||
|
disabled,
|
||||||
|
select,
|
||||||
} = useConfigInject('select', props);
|
} = useConfigInject('select', props);
|
||||||
|
const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction);
|
||||||
|
const mergedSize = computed(() => compactSize.value || contextSize.value);
|
||||||
// style
|
// style
|
||||||
const [wrapSSR, hashId] = useStyle(prefixCls);
|
const [wrapSSR, hashId] = useStyle(prefixCls);
|
||||||
|
const contextDisabled = useInjectDisabled();
|
||||||
|
const mergedDisabled = computed(() => disabled.value ?? contextDisabled.value);
|
||||||
const rootPrefixCls = computed(() => getPrefixCls());
|
const rootPrefixCls = computed(() => getPrefixCls());
|
||||||
// ===================== Placement =====================
|
// ===================== Placement =====================
|
||||||
const placement = computed(() => {
|
const placement = computed(() => {
|
||||||
|
@ -147,13 +166,14 @@ const Select = defineComponent({
|
||||||
const mergedClassName = computed(() =>
|
const mergedClassName = computed(() =>
|
||||||
classNames(
|
classNames(
|
||||||
{
|
{
|
||||||
[`${prefixCls.value}-lg`]: size.value === 'large',
|
[`${prefixCls.value}-lg`]: mergedSize.value === 'large',
|
||||||
[`${prefixCls.value}-sm`]: size.value === 'small',
|
[`${prefixCls.value}-sm`]: mergedSize.value === 'small',
|
||||||
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
|
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
|
||||||
[`${prefixCls.value}-borderless`]: !props.bordered,
|
[`${prefixCls.value}-borderless`]: !props.bordered,
|
||||||
[`${prefixCls.value}-in-form-item`]: formItemInputContext.isFormItemInput,
|
[`${prefixCls.value}-in-form-item`]: formItemInputContext.isFormItemInput,
|
||||||
},
|
},
|
||||||
getStatusClassNames(prefixCls.value, mergedStatus.value, formItemInputContext.hasFeedback),
|
getStatusClassNames(prefixCls.value, mergedStatus.value, formItemInputContext.hasFeedback),
|
||||||
|
compactItemClassnames.value,
|
||||||
hashId.value,
|
hashId.value,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
@ -183,6 +203,7 @@ const Select = defineComponent({
|
||||||
notFoundContent,
|
notFoundContent,
|
||||||
listHeight = 256,
|
listHeight = 256,
|
||||||
listItemHeight = 24,
|
listItemHeight = 24,
|
||||||
|
popupClassName,
|
||||||
dropdownClassName,
|
dropdownClassName,
|
||||||
virtual,
|
virtual,
|
||||||
dropdownMatchSelectWidth,
|
dropdownMatchSelectWidth,
|
||||||
|
@ -202,7 +223,7 @@ const Select = defineComponent({
|
||||||
} else if (mode.value === 'combobox') {
|
} else if (mode.value === 'combobox') {
|
||||||
mergedNotFound = null;
|
mergedNotFound = null;
|
||||||
} else {
|
} else {
|
||||||
mergedNotFound = renderEmpty('Select') as any;
|
mergedNotFound = renderEmpty?.('Select') || <DefaultRenderEmpty componentName="Select" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===================== Icons =====================
|
// ===================== Icons =====================
|
||||||
|
@ -230,7 +251,7 @@ const Select = defineComponent({
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const rcSelectRtlDropdownClassName = classNames(
|
const rcSelectRtlDropdownClassName = classNames(
|
||||||
dropdownClassName,
|
popupClassName || dropdownClassName,
|
||||||
{
|
{
|
||||||
[`${prefixCls.value}-dropdown-${direction.value}`]: direction.value === 'rtl',
|
[`${prefixCls.value}-dropdown-${direction.value}`]: direction.value === 'rtl',
|
||||||
},
|
},
|
||||||
|
@ -244,6 +265,7 @@ const Select = defineComponent({
|
||||||
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
|
dropdownMatchSelectWidth={dropdownMatchSelectWidth}
|
||||||
{...selectProps}
|
{...selectProps}
|
||||||
{...attrs}
|
{...attrs}
|
||||||
|
showSearch={props.showSearch ?? select.value?.showSearch}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
listHeight={listHeight}
|
listHeight={listHeight}
|
||||||
listItemHeight={listItemHeight}
|
listItemHeight={listItemHeight}
|
||||||
|
@ -269,6 +291,7 @@ const Select = defineComponent({
|
||||||
optionLabelRender={slots.optionLabel}
|
optionLabelRender={slots.optionLabel}
|
||||||
maxTagPlaceholder={props.maxTagPlaceholder || slots.maxTagPlaceholder}
|
maxTagPlaceholder={props.maxTagPlaceholder || slots.maxTagPlaceholder}
|
||||||
showArrow={hasFeedback || showArrow}
|
showArrow={hasFeedback || showArrow}
|
||||||
|
disabled={mergedDisabled.value}
|
||||||
></RcSelect>,
|
></RcSelect>,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,10 +13,7 @@ export default function getIcons(props: any, slots: any = {}) {
|
||||||
props.menuItemSelectedIcon || (slots.menuItemSelectedIcon && slots.menuItemSelectedIcon());
|
props.menuItemSelectedIcon || (slots.menuItemSelectedIcon && slots.menuItemSelectedIcon());
|
||||||
const removeIcon = props.removeIcon || (slots.removeIcon && slots.removeIcon());
|
const removeIcon = props.removeIcon || (slots.removeIcon && slots.removeIcon());
|
||||||
// Clear Icon
|
// Clear Icon
|
||||||
let mergedClearIcon = clearIcon;
|
const mergedClearIcon = clearIcon ?? <CloseCircleFilled />;
|
||||||
if (!clearIcon) {
|
|
||||||
mergedClearIcon = <CloseCircleFilled />;
|
|
||||||
}
|
|
||||||
// Validation Feedback Icon
|
// Validation Feedback Icon
|
||||||
const getSuffixIconNode = arrowIcon => (
|
const getSuffixIconNode = arrowIcon => (
|
||||||
<>
|
<>
|
||||||
|
|
Loading…
Reference in New Issue