import React from 'react' import type { ViewProps } from '@tarojs/components' import { View } from '@tarojs/components' import type { PaddingProps, MarginProps, BackgroundProps, BorderRadiusProps, BorderProps } from '@lx-react-materiel/shared' import { commonStyleFn } from '@lx-react-materiel/shared' import { LxText } from '../lxText' import { type Required as IRequired } from 'utility-types' import './index.less' // ViewProps 只用到的部分属性。 type PickViewProps = Pick // LxItem 属性合集。 interface LxItemProps extends PaddingProps, MarginProps, BackgroundProps, BorderRadiusProps, BorderProps, PickViewProps { // left label?: string leftColor?: string leftSize?: number // right value?: string | number rightColor?: string rightSize?: number valueOnClick?: Pick['onClick'] // slot slotLeft?: React.ReactNode slotRight?: React.ReactNode } /** * 仅仅有 slot 用法 * slotLeft & slotRight 是必备属性 * 其他属性是可选属性 */ export type IOnlySlot = IRequired, 'slotLeft' | 'slotRight'> /** * 传递 slotLeft 场景 * slotLeft & value 是必备属性,其他是可选属性 */ export type IOnlySlotLeft = IRequired, 'slotLeft' | 'value'> /** * 传递 slotRight 场景 * slotRight & label 是必备属性,其他是可选属性 */ export type IOnlySlotRight = IRequired, 'slotRight' | 'label'> /** * 没有 slot 场景。默认 * label & value 是必备属性,其他是可选属性 */ export type INotSlot = IRequired, 'label' | 'value'> /** * @param props * @constructor * @example * // 没有 slot * console.log('click')}> * * // 只传递了 slot left * slotLeft={12312} value='微信支付' rightColor='#333' background='#fff' padding='' borderRadius={30} valueOnClick={() => console.log('click')}> * * // 只传递了 slot right * label='只传递了 slot right' leftColor='#666' slotRight={slot right value} background='#fff' padding='' borderRadius={30}> * * // 传递了slotLeft & slotRight * slotLeft={12312} slotRight={slot right value} background='#fff' padding='' borderRadius={30}> */ export function LxItem

(props: P) { // 没有 slot const { // left props label = '', leftColor = '#12151B', leftSize = 26, // right props value = '', rightColor = '#464D5A', rightSize = 26, valueOnClick, // slot props slotLeft, slotRight, // style prop style = commonStyleFn(props), className = null, ...rest } = props // 基础属性。 const mergeProps = { ...rest, className: `lx-item ${className ?? ''}`, style } return ( { slotLeft ?? {label} } { slotRight ?? {value} } ) } // 设置一下属性默认值 // style 属性因为需要 compose 计算,不方便在 props 上进行赋值 // 注意:style 属性不能带上 rpx 单位 LxItem.defaultProps = { background: '#fff', borderRadius: 16 }