Skip to content

Commit

Permalink
feat: 导出所有组件的 props 和 props type
Browse files Browse the repository at this point in the history
  • Loading branch information
winixt committed Jul 11, 2023
1 parent 2fc6959 commit 1859ddf
Show file tree
Hide file tree
Showing 120 changed files with 1,032 additions and 786 deletions.
10 changes: 10 additions & 0 deletions components/_util/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
DefineComponent,
App,
Plugin,
ExtractPropTypes,
} from 'vue';

export type Emit = SetupContext['emit'];
Expand Down Expand Up @@ -33,6 +34,15 @@ export type GetContainer = () => HTMLElement;

export type SFCWithInstall<T> = T & Plugin;

type RemoveReadonly<T> = {
-readonly [key in keyof T]: T[key];
};

export type ExtractPublicPropTypes<T> = Omit<
Partial<RemoveReadonly<ExtractPropTypes<T>>>,
Extract<keyof T, `internal${string}`>
>;

export interface Option {
value: string | number | boolean;
label: string | number;
Expand Down
3 changes: 1 addition & 2 deletions components/_util/withInstall.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component, App, Plugin } from 'vue';
import type { FObjectDirective } from './interface';

import { noop } from './utils';
import type { FObjectDirective } from './interface';

export function withInstall<T extends Plugin>(
main: T,
Expand Down
5 changes: 4 additions & 1 deletion components/alert/alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import CloseCircleOutlined from '../icon/CloseCircleOutlined';
import { CLOSE_EVENT } from '../_util/constants';
import { iconComponentMap } from '../_util/noticeManager';
import { useTheme } from '../_theme/useTheme';
import type { ExtractPublicPropTypes } from '../_util/interface';

const prefixCls = getPrefixCls('alert');

const alertProps = {
export const alertProps = {
message: String,
description: String,
showIcon: Boolean,
Expand All @@ -23,6 +24,8 @@ const alertProps = {
},
} as const;

export type AlertProps = ExtractPublicPropTypes<typeof alertProps>;

export default defineComponent({
name: 'FAlert',
props: alertProps,
Expand Down
4 changes: 3 additions & 1 deletion components/alert/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { withInstall } from '../_util/withInstall';
import Alert from './alert';

import type { SFCWithInstall } from '../_util/interface';

export { alertProps } from './alert';
export type { AlertProps } from './alert';

type AlertType = SFCWithInstall<typeof Alert>;
export const FAlert = withInstall<AlertType>(Alert as AlertType);

Expand Down
7 changes: 5 additions & 2 deletions components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import getPrefixCls from '../_util/getPrefixCls';
import { useAnimate } from '../_util/use/useAnimate';
import { useTheme } from '../_theme/useTheme';

import type { Type, Size } from './interface';
import useFormAdaptor from '../_util/use/useFormAdaptor';
import type { Type, Size } from './interface';
import type { ExtractPublicPropTypes } from '../_util/interface';

const prefixCls = getPrefixCls('btn');

const loadingIconClassName = `${prefixCls}-loading-icon`;

const buttonProps = {
export const buttonProps = {
disabled: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -42,6 +43,8 @@ const buttonProps = {
},
} as const;

export type ButtonProps = ExtractPublicPropTypes<typeof buttonProps>;

export default defineComponent({
name: 'FButton',
props: buttonProps,
Expand Down
3 changes: 3 additions & 0 deletions components/button/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Button from './button';

import type { SFCWithInstall } from '../_util/interface';

export { buttonProps } from './button';
export type { ButtonProps } from './button';

type ButtonType = SFCWithInstall<typeof Button>;
export const FButton = withInstall<ButtonType>(Button as ButtonType);

Expand Down
9 changes: 8 additions & 1 deletion components/card/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { withInstall } from '../_util/withInstall';
import Card from './card.vue';

import type { SFCWithInstall } from '../_util/interface';
import { cardProps } from './props';
import type {
SFCWithInstall,
ExtractPublicPropTypes,
} from '../_util/interface';

export { cardProps } from './props';
export type CardProps = ExtractPublicPropTypes<typeof cardProps>;

type CardType = SFCWithInstall<typeof Card>;
export const FCard = withInstall<CardType>(Card as CardType);
Expand Down
4 changes: 2 additions & 2 deletions components/carousel/carousel-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import {
getCurrentInstance,
ComputedRef,
} from 'vue';
import { useTheme } from '../_theme/useTheme';
import {
CAROUSEL_NAME,
CAROUSEL_ITEM_NAME,
CARD_SCALE,
provideKey,
} from './const';
import { useTheme } from '../_theme/useTheme';

import type { CarouselItemData, Direction } from './interface';
import { carouselItemProps } from './interface';
import type { CarouselItemData, Direction } from './interface';

const useItemStyle = (direction: ComputedRef<Direction>) => {
const itemStyleState = reactive({
Expand Down
7 changes: 4 additions & 3 deletions components/carousel/carousel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, watch, ref, PropType, ExtractPropTypes } from 'vue';
import { defineComponent, watch, ref, PropType } from 'vue';
import { useTheme } from '../_theme/useTheme';
import useResize from '../_util/use/useResize';
import { CAROUSEL_NAME, CHANGE_EVENT } from './const';
Expand All @@ -8,8 +8,9 @@ import useCarousel from './useCarousel';
import useCarouselStyle from './useCarouselStyle';
import useCarouselPlay from './useCarouselPlay';
import type { Placement } from './interface';
import type { ExtractPublicPropTypes } from '../_util/interface';

const carouselProps = {
export const carouselProps = {
height: {
type: String,
default: '',
Expand Down Expand Up @@ -60,7 +61,7 @@ const carouselProps = {
},
} as const;

export type CarouselProps = Partial<ExtractPropTypes<typeof carouselProps>>;
export type CarouselProps = ExtractPublicPropTypes<typeof carouselProps>;

export default defineComponent({
name: CAROUSEL_NAME,
Expand Down
4 changes: 4 additions & 0 deletions components/carousel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import type { SFCWithInstall } from '../_util/interface';
type CarouselType = SFCWithInstall<typeof Carousel>;
type CarouselItemType = SFCWithInstall<typeof CarouselItem>;

export { carouselProps } from './carousel';
export type { CarouselProps } from './carousel';

export const FCarousel = withInstall<CarouselType>(Carousel as CarouselType, {
CarouselItem,
});

export const FCarouselItem = withNoopInstall<CarouselItemType>(
CarouselItem as CarouselItemType,
);
Expand Down
3 changes: 3 additions & 0 deletions components/cascader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import Cascader from './cascader';

import type { SFCWithInstall } from '../_util/interface';

export { cascaderProps } from './props';
export type { CascaderProps } from './props';

type CascaderType = SFCWithInstall<typeof Cascader>;
export const FCascader = withInstall<CascaderType>(Cascader as CascaderType);

Expand Down
8 changes: 4 additions & 4 deletions components/cascader/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { extractPropsDefaultValue } from '../_util/utils';
import { CHECK_STRATEGY, EXPAND_TRIGGER } from './const';
import type { ExtractPropTypes, PropType, InjectionKey, Ref } from 'vue';

import type { PropType, InjectionKey, Ref } from 'vue';
import type { ExtractPublicPropTypes } from '../_util/interface';
import type {
CascaderOption,
CascaderNodeKey,
Expand Down Expand Up @@ -108,11 +108,11 @@ export const cascaderProps = {
},
} as const;

export type CascaderProps = ExtractPublicPropTypes<typeof cascaderProps>;

export const cascaderPropsDefaultValue =
extractPropsDefaultValue(cascaderProps);

export type CascaderProps = Partial<ExtractPropTypes<typeof cascaderProps>>;

export interface CascaderInst {
props: CascaderProps;
selectNode: (value: CascaderNodeKey, event: Event) => void;
Expand Down
4 changes: 2 additions & 2 deletions components/checkbox-group/checkbox-group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useTheme } from '../_theme/useTheme';
import getPrefixCls from '../_util/getPrefixCls';
import Checkbox from '../checkbox';
import { useCheckboxGroup } from './useCheckboxGroup';
import { name, checkboxProps } from './const';
import { name, checkboxGroupProps } from './const';
const prefixCls = getPrefixCls('checkbox-group');
Expand All @@ -26,7 +26,7 @@ export default defineComponent({
components: {
Checkbox,
},
props: checkboxProps,
props: checkboxGroupProps,
emits: ['update:modelValue', 'change'],
setup(props, { emit }) {
useTheme();
Expand Down
9 changes: 6 additions & 3 deletions components/checkbox-group/const.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import type { PropType, ExtractPropTypes } from 'vue';
import type { PropType } from 'vue';
import type { Option } from '../_util/interface';
import type { ExtractPublicPropTypes } from '../_util/interface';

export const checkboxGroupKey = Symbol('FCheckboxGroup');
export const name = 'FCheckboxGroup';

type OptionValue = string | number | boolean;

export const checkboxProps = {
export const checkboxGroupProps = {
modelValue: {
type: Array as PropType<OptionValue[]>,
default: () => [] as OptionValue[],
Expand All @@ -27,4 +28,6 @@ export const checkboxProps = {
},
} as const;

export type CheckboxProps = Partial<ExtractPropTypes<typeof checkboxProps>>;
export type CheckboxGroupProps = ExtractPublicPropTypes<
typeof checkboxGroupProps
>;
3 changes: 3 additions & 0 deletions components/checkbox-group/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import CheckboxGroup from './checkbox-group.vue';

import type { SFCWithInstall } from '../_util/interface';

export { checkboxGroupProps } from './const';
export type { CheckboxGroupProps } from './const';

type CheckboxGroupType = SFCWithInstall<typeof CheckboxGroup>;
export const FCheckboxGroup = withInstall<CheckboxGroupType>(
CheckboxGroup as CheckboxGroupType,
Expand Down
4 changes: 2 additions & 2 deletions components/checkbox-group/useCheckboxGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { provide, unref } from 'vue';
import { useArrayModel } from '../_util/use/useModel';
import useFormAdaptor from '../_util/use/useFormAdaptor';
import { CHANGE_EVENT } from '../_util/constants';
import { CheckboxProps, checkboxGroupKey, name } from './const';
import { CheckboxGroupProps, checkboxGroupKey, name } from './const';

import type { CheckboxGroupEmits } from './interface';

export const useCheckboxGroup = (
props: CheckboxProps,
props: CheckboxGroupProps,
emit: CheckboxGroupEmits,
) => {
const { validate, isFormDisabled } = useFormAdaptor({
Expand Down
Loading

0 comments on commit 1859ddf

Please sign in to comment.