11import React from 'react' ;
22import cx from 'classnames' ;
33
4- import type { TElement } from '../common' ;
4+ import type { TNode } from '../common' ;
55import type { ActionSheetProps } from './ActionSheet' ;
66import type { ActionSheetItem } from './type' ;
77
88import { Button } from '../button' ;
99import { Badge } from '../badge' ;
1010import { usePrefixClass } from '../hooks/useClass' ;
1111
12- type ActionSheetListProps = Pick < ActionSheetProps , 'items' | 'align' > & {
12+ type ActionSheetListProps = Pick < ActionSheetProps , 'items' > & {
1313 onSelected ?: ( idx : number ) => void ;
1414} ;
1515
1616export function ActionSheetList ( props : ActionSheetListProps ) {
17- const { items = [ ] , align , onSelected } = props ;
17+ const { items = [ ] , onSelected } = props ;
1818
1919 const actionSheetClass = usePrefixClass ( 'action-sheet' ) ;
2020
21+ const renderTNode = ( node : TNode ) => {
22+ if ( ! node ) return null ;
23+ if ( typeof node === 'function' ) {
24+ return node ( ) ;
25+ }
26+ return node ;
27+ } ;
28+
2129 return (
2230 < div className = { cx ( `${ actionSheetClass } __list` ) } >
23- { items ?. map ( ( item , idx ) => {
31+ { items ?. map ( ( item : ActionSheetItem , idx : number ) => {
2432 let label : React . ReactNode ;
2533 let disabled : ActionSheetItem [ 'disabled' ] ;
26- let icon : ActionSheetItem [ 'icon' ] ;
2734 let color : ActionSheetItem [ 'color' ] ;
2835
2936 if ( typeof item === 'string' ) {
@@ -37,7 +44,7 @@ export function ActionSheetList(props: ActionSheetListProps) {
3744 dot = { item ?. badge ?. dot }
3845 content = { item ?. badge ?. content }
3946 size = { item ?. badge ?. size }
40- offset = { item ?. badge ?. offset || [ - 16 , 20 ] }
47+ offset = { item ?. badge ?. offset }
4148 >
4249 < span className = { cx ( [ `${ actionSheetClass } __list-item-text` ] ) } > { item ?. label } </ span >
4350 </ Badge >
@@ -46,30 +53,46 @@ export function ActionSheetList(props: ActionSheetListProps) {
4653 label = < span className = { cx ( [ `${ actionSheetClass } __list-item-text` ] ) } > { item ?. label } </ span > ;
4754 }
4855 disabled = item ?. disabled ;
49- icon = item ?. icon ;
5056 color = item ?. color ;
5157 }
5258
59+ const prefixIcon = renderTNode ( item ?. icon ) ;
60+ const suffixIcon = renderTNode ( item ?. suffixIcon ) ;
61+ const desc = item ?. description ;
62+ const content = (
63+ < >
64+ < div className = { `${ actionSheetClass } __list-item-content` } >
65+ { prefixIcon && < div className = { `${ actionSheetClass } __list-item-icon` } > { prefixIcon } </ div > }
66+ { label }
67+ { suffixIcon && (
68+ < div className = { `${ actionSheetClass } __list-item-icon ${ actionSheetClass } __list-item-suffix-icon` } >
69+ { suffixIcon }
70+ </ div >
71+ ) }
72+ </ div >
73+ { desc && < div className = { `${ actionSheetClass } __list-item-desc` } > { desc } </ div > }
74+ </ >
75+ ) ;
76+
5377 return (
5478 < Button
5579 key = { idx }
5680 variant = "text"
5781 block
5882 className = { cx ( {
5983 [ `${ actionSheetClass } __list-item` ] : true ,
60- [ `${ actionSheetClass } __list-item--left ` ] : align === 'left' ,
84+ [ `${ actionSheetClass } __list-item--disabled ` ] : disabled ,
6185 } ) }
6286 onClick = { ( ) => {
6387 onSelected ?.( idx ) ;
6488 } }
6589 disabled = { disabled }
66- icon = { icon as TElement }
6790 style = { {
6891 color,
6992 } }
7093 shape = "rectangle"
7194 >
72- { label }
95+ { content }
7396 </ Button >
7497 ) ;
7598 } ) }
0 commit comments