diff --git a/packages/components/scrollbar/src/bar.ts b/packages/components/scrollbar/src/bar.ts index 48ff1bd3fb..b109045eee 100644 --- a/packages/components/scrollbar/src/bar.ts +++ b/packages/components/scrollbar/src/bar.ts @@ -1,8 +1,16 @@ import { buildProps } from '@element-plus/utils' -import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue' +import type { ExtractPublicPropTypes } from 'vue' import type Bar from './bar.vue' +export interface BarProps { + always?: boolean + minSize: number +} + +/** + * @deprecated Removed after 3.0.0, Use `BarProps` instead. + */ export const barProps = buildProps({ always: { type: Boolean, @@ -13,7 +21,7 @@ export const barProps = buildProps({ required: true, }, } as const) -export type BarProps = ExtractPropTypes + export type BarPropsPublic = ExtractPublicPropTypes export type BarInstance = InstanceType & unknown diff --git a/packages/components/scrollbar/src/bar.vue b/packages/components/scrollbar/src/bar.vue index 54718dfe8f..e879b6ce05 100644 --- a/packages/components/scrollbar/src/bar.vue +++ b/packages/components/scrollbar/src/bar.vue @@ -13,10 +13,13 @@ import { inject, ref } from 'vue' import { GAP } from './util' import Thumb from './thumb.vue' -import { barProps } from './bar' import { scrollbarContextKey } from './constants' -const props = defineProps(barProps) +import type { BarProps } from './bar' + +const props = withDefaults(defineProps(), { + always: true, +}) const scrollbar = inject(scrollbarContextKey) diff --git a/packages/components/scrollbar/src/scrollbar.ts b/packages/components/scrollbar/src/scrollbar.ts index 35d58b6a81..d8416a1113 100644 --- a/packages/components/scrollbar/src/scrollbar.ts +++ b/packages/components/scrollbar/src/scrollbar.ts @@ -1,9 +1,93 @@ import { buildProps, definePropType, isNumber } from '@element-plus/utils' import { useAriaProps } from '@element-plus/hooks' -import type { ExtractPropTypes, ExtractPublicPropTypes, StyleValue } from 'vue' +import type { ExtractPublicPropTypes, StyleValue } from 'vue' import type Scrollbar from './scrollbar.vue' +export interface ScrollbarProps { + /** + * @description trigger distance(px) + * @default 0 + */ + distance?: number + /** + * @description height of scrollbar + * @default '' + */ + height?: number | string + /** + * @description max height of scrollbar + * @default '' + */ + maxHeight?: number | string + /** + * @description whether to use the native scrollbar + */ + native?: boolean + /** + * @description style of wrap + * @default '' + */ + wrapStyle?: StyleValue + /** + * @description class of wrap + * @default '' + */ + wrapClass?: string | string[] + /** + * @description class of view + * @default '' + */ + viewClass?: string | string[] + /** + * @description style of view + * @default '' + */ + viewStyle?: StyleValue + /** + * @description do not respond to container size changes, if the container size does not change, it is better to set it to optimize performance + */ + noresize?: boolean + /** + * @description element tag of the view + * @default 'div' + */ + tag?: keyof HTMLElementTagNameMap | (string & {}) + /** + * @description always show + */ + always?: boolean + /** + * @description minimum size of scrollbar + * @default 20 + */ + minSize?: number + /** + * @description Wrap tabindex + * @default undefined + */ + tabindex?: number | string + /** + * @description id of view + */ + id?: string + /** + * @description role of view + */ + role?: string + /** + * @description native `aria-label` attribute + */ + ariaLabel?: string + /** + * @description native `aria-orientation` attribute + */ + ariaOrientation?: 'horizontal' | 'vertical' | 'undefined' +} + +/** + * @deprecated Removed after 3.0.0, Use `ScrollbarProps` instead. + */ export const scrollbarProps = buildProps({ /** * @description trigger distance(px) @@ -97,7 +181,6 @@ export const scrollbarProps = buildProps({ role: String, ...useAriaProps(['ariaLabel', 'ariaOrientation']), } as const) -export type ScrollbarProps = ExtractPropTypes export type ScrollbarPropsPublic = ExtractPublicPropTypes export const scrollbarEmits = { diff --git a/packages/components/scrollbar/src/scrollbar.vue b/packages/components/scrollbar/src/scrollbar.vue index 231227babb..11ed9b6c2a 100644 --- a/packages/components/scrollbar/src/scrollbar.vue +++ b/packages/components/scrollbar/src/scrollbar.vue @@ -43,9 +43,9 @@ import { addUnit, debugWarn, isNumber, isObject } from '@element-plus/utils' import { useNamespace } from '@element-plus/hooks' import Bar from './bar.vue' import { scrollbarContextKey } from './constants' -import { scrollbarEmits, scrollbarProps } from './scrollbar' +import { scrollbarEmits } from './scrollbar' -import type { ScrollbarDirection } from './scrollbar' +import type { ScrollbarDirection, ScrollbarProps } from './scrollbar' import type { BarInstance } from './bar' import type { CSSProperties, StyleValue } from 'vue' @@ -55,7 +55,18 @@ defineOptions({ name: COMPONENT_NAME, }) -const props = defineProps(scrollbarProps) +const props = withDefaults(defineProps(), { + distance: 0, + height: '', + maxHeight: '', + wrapStyle: '', + wrapClass: '', + viewStyle: '', + viewClass: '', + tag: 'div', + minSize: 20, + tabindex: undefined, +}) const emit = defineEmits(scrollbarEmits) const ns = useNamespace('scrollbar') diff --git a/packages/components/scrollbar/src/thumb.ts b/packages/components/scrollbar/src/thumb.ts index 4f87d01b52..2abc2b53c3 100644 --- a/packages/components/scrollbar/src/thumb.ts +++ b/packages/components/scrollbar/src/thumb.ts @@ -1,8 +1,19 @@ import { buildProps } from '@element-plus/utils' -import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue' +import type { ExtractPublicPropTypes } from 'vue' import type Thumb from './thumb.vue' +export interface ThumbProps { + vertical?: boolean + size?: string + move?: number + ratio: number + always?: boolean +} + +/** + * @deprecated Removed after 3.0.0, Use `ThumbProps` instead. + */ export const thumbProps = buildProps({ vertical: Boolean, size: String, @@ -13,7 +24,6 @@ export const thumbProps = buildProps({ }, always: Boolean, } as const) -export type ThumbProps = ExtractPropTypes export type ThumbPropsPublic = ExtractPublicPropTypes export type ThumbInstance = InstanceType & unknown diff --git a/packages/components/scrollbar/src/thumb.vue b/packages/components/scrollbar/src/thumb.vue index a2a4a312b5..d646776bce 100644 --- a/packages/components/scrollbar/src/thumb.vue +++ b/packages/components/scrollbar/src/thumb.vue @@ -24,10 +24,11 @@ import { isClient, throwError } from '@element-plus/utils' import { useNamespace } from '@element-plus/hooks' import { scrollbarContextKey } from './constants' import { BAR_MAP, renderThumbStyle } from './util' -import { thumbProps } from './thumb' + +import type { ThumbProps } from './thumb' const COMPONENT_NAME = 'Thumb' -const props = defineProps(thumbProps) +const props = defineProps() const scrollbar = inject(scrollbarContextKey) const ns = useNamespace('scrollbar')