11import { ReactNode } from 'react' ;
22import { Button , CubeButtonProps } from '../../actions' ;
33import { Text } from '../../content/Text' ;
4- import { Styles } from '../../../tasty' ;
4+ import { Styles , tasty } from '../../../tasty' ;
55import { Space } from '../../layout/Space' ;
6- import { CheckOutlined } from '@ant-design/icons' ;
6+ import { CheckOutlined , CheckCircleOutlined } from '@ant-design/icons' ;
77
88const ACTION_BUTTON : Styles = {
99 border : {
@@ -30,6 +30,8 @@ const ACTION_BUTTON: Styles = {
3030 padding : {
3131 '' : '(0.75x - 1px) (1.5x - 1px)' ,
3232 'selectable & !selected' :
33+ '(0.75x - 1px) (1.5x - 1px) (0.75x - 1px) (1.5x - 1px)' ,
34+ 'selectionIcon & selectable & !selected' :
3335 '(0.75x - 1px) (1.5x - 1px) (0.75x - 1px) (1.5x - 1px + 22px)' ,
3436 } ,
3537 display : 'flex' ,
@@ -45,6 +47,23 @@ const ACTION_BUTTON: Styles = {
4547 } ,
4648} ;
4749
50+ const RadioIcon = tasty ( {
51+ styles : {
52+ display : 'flex' ,
53+ width : '1.875x' ,
54+ placeContent : 'center' ,
55+
56+ '&::before' : {
57+ display : 'block' ,
58+ content : '""' ,
59+ width : '1x' ,
60+ height : '1x' ,
61+ radius : 'round' ,
62+ fill : '#current' ,
63+ } ,
64+ } ,
65+ } ) ;
66+
4867const getPostfix = ( postfix ) =>
4968 typeof postfix === 'string' ? (
5069 < Text nowrap color = "inherit" data-element = "Postfix" >
@@ -54,22 +73,38 @@ const getPostfix = (postfix) =>
5473 postfix
5574 ) ;
5675
76+ export type MenuSelectionType = 'checkbox' | 'radio' ;
77+
5778export type MenuButtonProps = {
5879 postfix : ReactNode ;
80+ selectionIcon ?: MenuSelectionType ;
5981 isSelectable ?: boolean ;
6082 disabled ?: boolean ;
6183} & CubeButtonProps ;
6284
85+ const getSelectionTypeIcon = ( selectionIcon ?: MenuSelectionType ) => {
86+ switch ( selectionIcon ) {
87+ case 'checkbox' :
88+ return < CheckOutlined /> ;
89+ case 'radio' :
90+ return < RadioIcon /> ;
91+ default :
92+ return null ;
93+ }
94+ } ;
95+
6396export function MenuButton ( {
6497 children,
6598 icon,
6699 postfix,
67100 ...props
68101} : MenuButtonProps ) {
69- const { isSelected, isSelectable } = props ;
70- const checkIcon = isSelectable && isSelected ? < CheckOutlined /> : null ;
102+ const { selectionIcon, isSelected, isSelectable } = props ;
103+ const checkIcon =
104+ isSelectable && isSelected ? getSelectionTypeIcon ( selectionIcon ) : null ;
71105 const mods = {
72106 ...props . mods ,
107+ selectionIcon : ! ! selectionIcon ,
73108 selectable : isSelectable ,
74109 selected : isSelected ,
75110 } ;
0 commit comments