From 9f3ea04eb7fc3584bb4d7f20610106f48b79b4c6 Mon Sep 17 00:00:00 2001 From: Kyle Schiller Date: Mon, 30 Mar 2020 14:18:48 -0700 Subject: [PATCH] update(MenuToggle): Add prop for custom trigger element. (#304) --- .../core/src/components/MenuToggle/index.tsx | 54 +++++++++++-------- .../core/src/components/MenuToggle/story.tsx | 22 ++++++++ .../core/src/components/MenuToggle/styles.ts | 6 ++- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/packages/core/src/components/MenuToggle/index.tsx b/packages/core/src/components/MenuToggle/index.tsx index f929c9bcb..d609022f1 100644 --- a/packages/core/src/components/MenuToggle/index.tsx +++ b/packages/core/src/components/MenuToggle/index.tsx @@ -41,6 +41,8 @@ export type MenuToggleProps = { toggleIcon?: React.ReactNode; /** Toggle button text. */ toggleLabel: NonNullable; + /** Custom toggle trigger. */ + toggleElement?: React.ReactNode; /** Z-index of the menu. */ zIndex?: number; /** @ignore @private */ @@ -153,6 +155,7 @@ export class MenuToggle extends React.Component< styles, toggleIcon, toggleLabel, + toggleElement, zIndex, } = this.props; let iconSize = '1.5em'; @@ -165,29 +168,38 @@ export class MenuToggle extends React.Component< const Button = muted ? MutedButton : BaseButton; + let toggleButton = toggleIcon ? ( + + {toggleIcon} + + ) : ( + + ); + + if (toggleElement) { + toggleButton = ( + + ); + } + return (
- {toggleIcon ? ( - - {toggleIcon} - - ) : ( - - )} - + {toggleButton}
console.log('onClick')}> @@ -35,6 +36,27 @@ aBasicMenuWithMenuItems.story = { name: 'A basic menu with menu items.', }; +export function withCustomTrigger() { + return ( + + Custom Menu Trigger + + } + toggleLabel="Actions" + zIndex={10} + > + {children} + + ); +} + +withCustomTrigger.story = { + name: 'With custom trigger.', +}; + export function withCustomIcon() { return ( ({ +export const styleSheetMenuToggle: StyleSheet = ({ pattern, unit, transition }) => ({ container: { display: 'inline-block', position: 'relative', @@ -26,4 +26,8 @@ export const styleSheetMenuToggle: StyleSheet = ({ unit, transition }) => ({ display: 'flex', justifyContent: 'space-between', }, + + customToggle: { + ...pattern.resetButton, + }, });