mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] SwitchCell: tsx (#2785)
This commit is contained in:
parent
e860759f16
commit
c372638036
@ -15,6 +15,10 @@ export type IconProps = {
|
||||
classPrefix?: string;
|
||||
};
|
||||
|
||||
export type IconEvents = {
|
||||
onClick?(event: Event): void;
|
||||
};
|
||||
|
||||
const [sfc] = use('icon');
|
||||
|
||||
function Icon(
|
||||
@ -55,4 +59,4 @@ Icon.props = {
|
||||
}
|
||||
};
|
||||
|
||||
export default sfc<IconProps>(Icon);
|
||||
export default sfc<IconProps, IconEvents>(Icon);
|
||||
|
@ -1,33 +0,0 @@
|
||||
import { use } from '../utils';
|
||||
import { inherit } from '../utils/functional';
|
||||
import Cell from '../cell';
|
||||
import Switch from '../switch';
|
||||
import { switchProps } from '../switch/shared';
|
||||
|
||||
const [sfc, bem] = use('switch-cell');
|
||||
|
||||
function SwitchCell(h, props, slots, ctx) {
|
||||
return (
|
||||
<Cell
|
||||
center
|
||||
title={props.title}
|
||||
border={props.border}
|
||||
class={bem()}
|
||||
{...inherit(ctx)}
|
||||
>
|
||||
<Switch {...{ props, on: ctx.listeners }} />
|
||||
</Cell>
|
||||
);
|
||||
}
|
||||
|
||||
SwitchCell.props = {
|
||||
...switchProps,
|
||||
title: String,
|
||||
border: Boolean,
|
||||
size: {
|
||||
type: String,
|
||||
default: '24px'
|
||||
}
|
||||
};
|
||||
|
||||
export default sfc(SwitchCell);
|
48
packages/switch-cell/index.tsx
Normal file
48
packages/switch-cell/index.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
import { use } from '../utils';
|
||||
import { inherit } from '../utils/functional';
|
||||
import Cell from '../cell';
|
||||
import Switch, { SwitchEvents } from '../switch';
|
||||
import { switchProps, SharedSwitchProps } from '../switch/shared';
|
||||
|
||||
// Types
|
||||
import { CreateElement, RenderContext } from 'vue/types';
|
||||
import { DefaultSlots } from '../utils/use/sfc';
|
||||
|
||||
export type SwitchCellProps = SharedSwitchProps & {
|
||||
size?: string;
|
||||
title?: string;
|
||||
border?: boolean;
|
||||
};
|
||||
|
||||
const [sfc, bem] = use('switch-cell');
|
||||
|
||||
function SwitchCell(
|
||||
h: CreateElement,
|
||||
props: SwitchCellProps,
|
||||
slots: DefaultSlots,
|
||||
ctx: RenderContext<SwitchCellProps>
|
||||
) {
|
||||
return (
|
||||
<Cell
|
||||
center
|
||||
title={props.title}
|
||||
border={props.border}
|
||||
class={bem()}
|
||||
{...inherit(ctx)}
|
||||
>
|
||||
<Switch {...{ props, on: ctx.listeners }} />
|
||||
</Cell>
|
||||
);
|
||||
}
|
||||
|
||||
SwitchCell.props = {
|
||||
...switchProps,
|
||||
title: String,
|
||||
border: Boolean,
|
||||
size: {
|
||||
type: String,
|
||||
default: '24px'
|
||||
}
|
||||
};
|
||||
|
||||
export default sfc<SwitchCellProps, SwitchEvents>(SwitchCell);
|
@ -55,6 +55,8 @@ export type FunctionalComponent<
|
||||
export type TsxBaseProps = {
|
||||
class?: any;
|
||||
style?: any;
|
||||
// hack for jsx prop spread
|
||||
props?: any;
|
||||
};
|
||||
export type TsxComponent<Props, Events> = (
|
||||
props: Props & Events & TsxBaseProps
|
||||
|
Loading…
x
Reference in New Issue
Block a user