feat(anchor): ts type

feat-css-var
tangjinzhou 2022-02-25 16:33:05 +08:00
parent 5ec5334195
commit 2a536380bc
3 changed files with 21 additions and 20 deletions

View File

@ -1,4 +1,4 @@
import type { ExtractPropTypes } from 'vue'; import type { CSSProperties, ExtractPropTypes, PropType } from 'vue';
import { import {
defineComponent, defineComponent,
nextTick, nextTick,
@ -9,7 +9,6 @@ import {
ref, ref,
computed, computed,
} from 'vue'; } from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from '../_util/classNames'; import classNames from '../_util/classNames';
import addEventListener from '../vc-util/Dom/addEventListener'; import addEventListener from '../vc-util/Dom/addEventListener';
import Affix from '../affix'; import Affix from '../affix';
@ -40,7 +39,7 @@ function getOffsetTop(element: HTMLElement, container: AnchorContainer): number
return rect.top; return rect.top;
} }
const sharpMatcherRegx = /#(\S+)$/; const sharpMatcherRegx = /#([\S ]+)$/;
type Section = { type Section = {
link: string; link: string;
@ -49,22 +48,22 @@ type Section = {
export type AnchorContainer = HTMLElement | Window; export type AnchorContainer = HTMLElement | Window;
const anchorProps = { export const anchorProps = () => ({
prefixCls: PropTypes.string, prefixCls: String,
offsetTop: PropTypes.number, offsetTop: Number,
bounds: PropTypes.number, bounds: Number,
affix: PropTypes.looseBool.def(true), affix: { type: Boolean, default: true },
showInkInFixed: PropTypes.looseBool.def(false), showInkInFixed: { type: Boolean, default: false },
getContainer: PropTypes.func.def(getDefaultContainer), getContainer: Function as PropType<() => AnchorContainer>,
wrapperClass: PropTypes.string, wrapperClass: String,
wrapperStyle: PropTypes.style, wrapperStyle: { type: Object as PropType<CSSProperties>, default: undefined as CSSProperties },
getCurrentAnchor: PropTypes.func, getCurrentAnchor: Function as PropType<() => string>,
targetOffset: PropTypes.number, targetOffset: Number,
onChange: PropTypes.func, onChange: Function as PropType<(currentActiveLink: string) => void>,
onClick: PropTypes.func, onClick: Function as PropType<(e: MouseEvent, link: { title: any; href: string }) => void>,
}; });
export type AnchorProps = Partial<ExtractPropTypes<typeof anchorProps>>; export type AnchorProps = Partial<ExtractPropTypes<ReturnType<typeof anchorProps>>>;
export interface AnchorState { export interface AnchorState {
scrollContainer: HTMLElement | Window; scrollContainer: HTMLElement | Window;
@ -76,8 +75,7 @@ export interface AnchorState {
export default defineComponent({ export default defineComponent({
name: 'AAnchor', name: 'AAnchor',
inheritAttrs: false, inheritAttrs: false,
props: anchorProps, props: anchorProps(),
emits: ['change', 'click'],
setup(props, { emit, attrs, slots, expose }) { setup(props, { emit, attrs, slots, expose }) {
const { prefixCls, getTargetContainer, direction } = useConfigInject('anchor', props); const { prefixCls, getTargetContainer, direction } = useConfigInject('anchor', props);
const inkNodeRef = ref(); const inkNodeRef = ref();

View File

@ -21,6 +21,7 @@
top: 0; top: 0;
left: 0; left: 0;
height: 100%; height: 100%;
&::before { &::before {
position: relative; position: relative;
display: block; display: block;
@ -30,6 +31,7 @@
background-color: @anchor-border-color; background-color: @anchor-border-color;
content: ' '; content: ' ';
} }
&-ball { &-ball {
position: absolute; position: absolute;
left: 50%; left: 50%;
@ -41,6 +43,7 @@
border-radius: 8px; border-radius: 8px;
transform: translateX(-50%); transform: translateX(-50%);
transition: top 0.3s ease-in-out; transition: top 0.3s ease-in-out;
&.visible { &.visible {
display: inline-block; display: inline-block;
} }