mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Info: tsx (#2768)
This commit is contained in:
parent
a6a733f735
commit
1d84d33264
@ -1,20 +0,0 @@
|
|||||||
import { use, isDef } from '../utils';
|
|
||||||
import { inherit } from '../utils/functional';
|
|
||||||
|
|
||||||
const [sfc, bem] = use('info');
|
|
||||||
|
|
||||||
function Info(h, props, slots, ctx) {
|
|
||||||
return (
|
|
||||||
isDef(props.info) && (
|
|
||||||
<div class={bem()} {...inherit(ctx, true)}>
|
|
||||||
{props.info}
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Info.props = {
|
|
||||||
info: [String, Number]
|
|
||||||
};
|
|
||||||
|
|
||||||
export default sfc(Info);
|
|
29
packages/info/index.tsx
Normal file
29
packages/info/index.tsx
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { use, isDef } from '../utils';
|
||||||
|
import { inherit } from '../utils/functional';
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import { FunctionalComponent } from '../utils/use/sfc';
|
||||||
|
|
||||||
|
const [sfc, bem] = use('info');
|
||||||
|
|
||||||
|
const Info: FunctionalComponent<InfoProps> = function(h, props, slots, ctx) {
|
||||||
|
if (!isDef(props.info)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={bem()} {...inherit(ctx, true)}>
|
||||||
|
{props.info}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export type InfoProps = {
|
||||||
|
info?: string | number;
|
||||||
|
};
|
||||||
|
|
||||||
|
Info.props = {
|
||||||
|
info: [String, Number]
|
||||||
|
};
|
||||||
|
|
||||||
|
export default sfc(Info);
|
@ -13,7 +13,7 @@ type Mods = Mod | Mod[];
|
|||||||
const ELEMENT = '__';
|
const ELEMENT = '__';
|
||||||
const MODS = '--';
|
const MODS = '--';
|
||||||
|
|
||||||
function join(name: string, el: string, symbol: string): string {
|
function join(name: string, el?: string, symbol?: string): string {
|
||||||
return el ? name + symbol + el : name;
|
return el ? name + symbol + el : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ function prefix(name: string, mods: Mods): Mods {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default (name: string) => (el: Mods, mods?: Mods): Mods => {
|
export default (name: string) => (el?: Mods, mods?: Mods): Mods => {
|
||||||
if (el && typeof el !== 'string') {
|
if (el && typeof el !== 'string') {
|
||||||
mods = el;
|
mods = el;
|
||||||
el = '';
|
el = '';
|
||||||
|
@ -15,7 +15,17 @@ import { InjectOptions, PropsDefinition } from 'vue/types/options';
|
|||||||
|
|
||||||
export type ScopedSlot = (props?: any) => VNode[] | undefined;
|
export type ScopedSlot = (props?: any) => VNode[] | undefined;
|
||||||
|
|
||||||
export type VantComponentOptions = ComponentOptions<Vue> & {
|
export type ScopedSlots = {
|
||||||
|
[key: string]: ScopedSlot | undefined;
|
||||||
|
default?: ScopedSlot;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ModelOptions = {
|
||||||
|
prop?: string;
|
||||||
|
event?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface VantComponentOptions extends ComponentOptions<Vue> {
|
||||||
functional?: boolean;
|
functional?: boolean;
|
||||||
install?: (Vue: VueConstructor) => void;
|
install?: (Vue: VueConstructor) => void;
|
||||||
};
|
};
|
||||||
@ -29,17 +39,11 @@ export type FunctionalComponent<
|
|||||||
(
|
(
|
||||||
h: CreateElement,
|
h: CreateElement,
|
||||||
props: Props,
|
props: Props,
|
||||||
slots: {
|
slots: ScopedSlots,
|
||||||
[key: string]: ScopedSlot | undefined
|
|
||||||
default: ScopedSlot | undefined
|
|
||||||
},
|
|
||||||
context: RenderContext<Props>
|
context: RenderContext<Props>
|
||||||
): VNode;
|
): VNode | undefined;
|
||||||
props?: PropDefs;
|
props?: PropDefs;
|
||||||
model?: {
|
model?: ModelOptions;
|
||||||
prop?: string;
|
|
||||||
event?: string;
|
|
||||||
};
|
|
||||||
inject?: InjectOptions;
|
inject?: InjectOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -94,7 +98,7 @@ function transformFunctionalComponent(
|
|||||||
functional: true,
|
functional: true,
|
||||||
props: pure.props,
|
props: pure.props,
|
||||||
model: pure.model,
|
model: pure.model,
|
||||||
render: (h, context) => pure(h, context.props, unifySlots(context), context)
|
render: (h, context): any => pure(h, context.props, unifySlots(context), context)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user