Skip to content

Feat: Enhance Component Props Type #3258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions components/layout/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import { createVNode, defineComponent, inject, provide, toRefs, ref } from 'vue';
import {
createVNode,
defineComponent,
inject,
provide,
toRefs,
ref,
ExtractPropTypes,
HTMLAttributes,
} from 'vue';
import PropTypes from '../_util/vue-types';
import classNames from '../_util/classNames';
import { defaultConfigProvider } from '../config-provider';
import { flattenChildren } from '../_util/props-util';

export const BasicProps = {
export const basicProps = {
prefixCls: PropTypes.string,
hasSider: PropTypes.looseBool,
tagName: PropTypes.string,
};

export type BasicProps = Partial<ExtractPropTypes<typeof basicProps>> & HTMLAttributes;

export interface SiderHookProvider {
addSider?: (id: string) => void;
removeSider?: (id: string) => void;
Expand All @@ -23,9 +34,8 @@ type GeneratorArgument = {

function generator({ suffixCls, tagName, name }: GeneratorArgument) {
return (BasicComponent: typeof Basic) => {
return defineComponent({
const Adapter = defineComponent<BasicProps>({
name,
props: BasicProps,
setup(props, { slots }) {
const { getPrefixCls } = inject('configProvider', defaultConfigProvider);
return () => {
Expand All @@ -44,19 +54,21 @@ function generator({ suffixCls, tagName, name }: GeneratorArgument) {
};
},
});
Adapter.props = basicProps;
return Adapter;
};
}

const Basic = defineComponent({
props: BasicProps,
props: basicProps,
setup(props, { slots }) {
const { prefixCls, tagName } = toRefs(props);
return () => createVNode(tagName.value, { class: prefixCls.value }, slots.default?.());
},
});

const BasicLayout = defineComponent({
props: BasicProps,
props: basicProps,
setup(props, { slots }) {
const siders = ref<string[]>([]);
const siderHookProvider: SiderHookProvider = {
Expand Down