@@ -8,17 +8,16 @@ import React, {
88} from 'react'
99import styled , { css } from 'styled-components'
1010
11- import { spacing , componentSize , opacity , shape } from '../designparams'
12- import { remainder } from '../utils/math'
13-
14- import { Icon , IconType } from '../Icon'
15- import { MoreVertIcon } from 'practical-react-components-icons'
16- import { PopOver , PopOverProps } from '../PopOver'
1711import {
1812 useBoolean ,
1913 useVisibleFocus ,
2014 useClickOutside ,
2115} from 'react-hooks-shareable'
16+
17+ import { spacing , componentSize , opacity , shape } from '../designparams'
18+ import { remainder } from '../utils/math'
19+ import { Icon } from '../Icon'
20+ import { PopOver , PopOverProps } from '../PopOver'
2221import { useEscapeListenerStack } from '../Modal/hooks/useEscapeListenerStack'
2322
2423type BaseElement = HTMLDivElement
@@ -35,12 +34,24 @@ const Anchor = styled.div`
3534 height : fit-content;
3635`
3736
38- const MenuIcon = styled ( Icon ) . attrs ( { className : 'sc-ButtonIcon' } ) `
37+ export const MenuButtonIconContainer = styled . div `
38+ position : relative;
39+ height : ${ componentSize . small } ;
40+ width : ${ componentSize . small } ;
41+ border-radius : ${ shape . radius . circle } ;
42+ display : flex;
43+ align-items : center;
44+ justify-content : center;
45+ `
46+
47+ export const MenuButtonIcon = styled ( Icon ) . attrs ( {
48+ className : 'sc-ButtonIcon' ,
49+ } ) `
3950 fill: inherit;
4051 flex: none;
4152`
4253
43- const MenuButtonHalo = styled . div `
54+ export const MenuButtonHalo = styled . div `
4455 position : absolute;
4556 top : 0 ;
4657 right : 0 ;
@@ -53,27 +64,30 @@ const MenuButtonHalo = styled.div`
5364 transition : transform 100ms ;
5465`
5566
56- const MenuNativeButton = styled . button < { readonly visibleFocus : boolean } > `
57- position: relative;
67+ const MenuNativeButton = styled . button < {
68+ readonly visibleFocus : boolean
69+ } > `
5870 flex: none;
59- height: ${ componentSize . small } ;
60- width: ${ componentSize . small } ;
61- border-radius: ${ shape . radius . circle } ;
6271 min-width: unset;
6372 padding: unset;
6473 outline: none;
65- border: 2px solid transparent;
6674 cursor: pointer;
75+ border: 0;
6776 &::-moz-focus-inner {
6877 border: 0;
6978 }
7079 color: ${ ( { theme } ) => theme . color . text04 ( ) } ;
7180 fill: ${ ( { theme } ) => theme . color . text04 ( ) } ;
7281 background-color: transparent;
7382 transition: all 200ms;
83+ ${ MenuButtonIconContainer } {
84+ border: 2px solid transparent;
85+ }
7486
7587 &:hover {
76- border: 0 solid transparent;
88+ ${ MenuButtonIconContainer } {
89+ border: 0 solid transparent;
90+ }
7791 ${ MenuButtonHalo } {
7892 background-color: ${ ( { theme } ) => theme . color . element11 ( opacity [ 16 ] ) } ;
7993 transform: scale(1);
@@ -85,7 +99,9 @@ const MenuNativeButton = styled.button<{ readonly visibleFocus: boolean }>`
8599 visibleFocus
86100 ? css `
87101 & : focus {
88- border : 2px solid ${ ( { theme } ) => theme . color . elementBorder ( ) } ;
102+ ${ MenuButtonIconContainer } {
103+ border : 2px solid ${ ( { theme } ) => theme . color . elementBorder ( ) } ;
104+ }
89105 ${ MenuButtonHalo } {
90106 background-color : ${ ( { theme } ) =>
91107 theme . color . element11 ( opacity [ 16 ] ) } ;
@@ -177,27 +193,23 @@ interface MenuButtonProps extends BaseButtonProps {
177193 * `class` to be passed to the component.
178194 */
179195 readonly className ?: string
180- /**
181- * Icon that shows inside Button.
182- */
183- readonly icon : IconType
184196 /**
185197 * The title attribute specifies extra information about an element.
186198 */
187199 readonly title ?: string
188200}
189201
190- export const MenuButton = React . forwardRef < BaseButtonElement , MenuButtonProps > (
202+ const MenuButton = React . forwardRef < BaseButtonElement , MenuButtonProps > (
191203 (
192204 {
193205 disabled,
194206 name,
195207 onClick,
196208 className,
197- icon,
198209 onPointerDown,
199210 onPointerUp,
200211 onFocus,
212+ children,
201213 ...props
202214 } ,
203215 ref
@@ -249,8 +261,7 @@ export const MenuButton = React.forwardRef<BaseButtonElement, MenuButtonProps>(
249261 visibleFocus = { visibleFocus }
250262 { ...props }
251263 >
252- < MenuIcon icon = { icon } />
253- < MenuButtonHalo />
264+ { children }
254265 </ MenuNativeButton >
255266 )
256267 }
@@ -378,9 +389,9 @@ const BaseItem: React.FunctionComponent<BaseItemProps> = ({
378389
379390export interface BaseMenuProps extends Omit < PopOverProps , 'anchorEl' > {
380391 /**
381- * The icon element.
392+ * React element that will appear as menu button
382393 */
383- readonly icon ?: IconType
394+ readonly button : ReactNode
384395 /**
385396 * Aligns the menu either left or right.
386397 */
@@ -403,7 +414,7 @@ export interface BaseMenuProps extends Omit<PopOverProps, 'anchorEl'> {
403414 */
404415export const BaseMenu = memo < BaseMenuProps > (
405416 ( {
406- icon = MoreVertIcon ,
417+ button ,
407418 align = 'left' ,
408419 disabled = false ,
409420 components,
@@ -537,7 +548,9 @@ export const BaseMenu = memo<BaseMenuProps>(
537548 onBlur = { handleBlur }
538549 { ...props }
539550 >
540- < MenuButton icon = { icon } onClick = { mouseToggleMenu } disabled = { disabled } />
551+ < MenuButton onClick = { mouseToggleMenu } disabled = { disabled } >
552+ { button }
553+ </ MenuButton >
541554 { menuVisible ? (
542555 < PopOver
543556 horizontalPosition = { align }
0 commit comments