|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +/* @conditional-compile-remove(reaction) */ |
| 5 | +import { IRawStyle, IStyle, mergeStyles, Stack } from '@fluentui/react'; |
| 6 | +/* @conditional-compile-remove(reaction) */ |
| 7 | +import React from 'react'; |
| 8 | +/* @conditional-compile-remove(reaction) */ |
| 9 | +import { useTheme } from '../../theming/FluentThemeProvider'; |
| 10 | +/* @conditional-compile-remove(reaction) */ |
| 11 | +import { mobileViewEmojiStyles, mobileViewMenuItemStyle } from '../styles/ReactionButton.styles'; |
| 12 | +/* @conditional-compile-remove(reaction) */ |
| 13 | +import { IconButton } from '@fluentui/react'; |
| 14 | +/* @conditional-compile-remove(reaction) */ |
| 15 | +import { _DrawerMenuItemProps, ReactionResources } from '../..'; |
| 16 | + |
| 17 | +/* @conditional-compile-remove(reaction) */ |
| 18 | +/** |
| 19 | + * Props for the ReactionMenuItem |
| 20 | + * |
| 21 | + * @internal |
| 22 | + */ |
| 23 | +export interface _ReactionMenuItemProps { |
| 24 | + /** |
| 25 | + * Reaction resources to render for mobile button menus for reaction |
| 26 | + */ |
| 27 | + reactionResources?: ReactionResources; |
| 28 | + /** |
| 29 | + * reaction click event from the call adapter. |
| 30 | + */ |
| 31 | + onReactionClick?: (reaction: string) => Promise<void>; |
| 32 | + /** |
| 33 | + * Whether the menu item is disabled |
| 34 | + * @defaultvalue false |
| 35 | + */ |
| 36 | + disabled?: boolean; |
| 37 | +} |
| 38 | + |
| 39 | +/* @conditional-compile-remove(reaction) */ |
| 40 | +/** |
| 41 | + * Maps the individual item in menuProps.items passed in the {@link DrawerMenu} into a UI component. |
| 42 | + * |
| 43 | + * @internal |
| 44 | + */ |
| 45 | +export const _ReactionDrawerMenuItem = (props: _ReactionMenuItemProps): JSX.Element => { |
| 46 | + const theme = useTheme(); |
| 47 | + const resources = props.reactionResources; |
| 48 | + const emojiResource: Map<string, string | undefined> = new Map([ |
| 49 | + ['like', resources?.likeReaction?.url], |
| 50 | + ['heart', resources?.heartReaction?.url], |
| 51 | + ['laugh', resources?.laughReaction?.url], |
| 52 | + ['applause', resources?.applauseReaction?.url], |
| 53 | + ['surprised', resources?.surprisedReaction?.url] |
| 54 | + ]); |
| 55 | + const emojis: string[] = ['like', 'heart', 'laugh', 'applause', 'surprised']; |
| 56 | + |
| 57 | + const borderRadius = useTheme().effects.roundedCorner4; |
| 58 | + const modifiedFirstItemStyle = { |
| 59 | + root: { |
| 60 | + borderTopRightRadius: borderRadius, |
| 61 | + borderTopLeftRadius: borderRadius, |
| 62 | + marginTop: '12px' |
| 63 | + } |
| 64 | + }; |
| 65 | + |
| 66 | + return ( |
| 67 | + <Stack |
| 68 | + id="reaction" |
| 69 | + role="menuitem" |
| 70 | + horizontal |
| 71 | + className={mergeStyles( |
| 72 | + drawerMenuItemRootStyles(theme.palette.neutralLight, theme.fonts.small), |
| 73 | + props.disabled ? disabledDrawerMenuItemRootStyles(theme.palette.neutralQuaternaryAlt) : undefined, |
| 74 | + modifiedFirstItemStyle.root |
| 75 | + )} |
| 76 | + > |
| 77 | + <div style={mobileViewMenuItemStyle()}> |
| 78 | + {emojis.map((emoji, index) => { |
| 79 | + const resourceUrl = emojiResource.get(emoji.toString()); |
| 80 | + |
| 81 | + return ( |
| 82 | + <IconButton |
| 83 | + key={index} |
| 84 | + onClick={() => { |
| 85 | + props.onReactionClick?.(emoji); |
| 86 | + }} |
| 87 | + style={mobileViewEmojiStyles(resourceUrl ? resourceUrl : '', 'running')} |
| 88 | + /> |
| 89 | + ); |
| 90 | + })} |
| 91 | + </div> |
| 92 | + </Stack> |
| 93 | + ); |
| 94 | +}; |
| 95 | + |
| 96 | +/* @conditional-compile-remove(reaction) */ |
| 97 | +const drawerMenuItemRootStyles = (hoverBackground: string, fontSize: IRawStyle): IStyle => ({ |
| 98 | + ...fontSize, |
| 99 | + height: '3rem', |
| 100 | + lineHeight: '3rem', |
| 101 | + padding: '0rem 0.75rem', |
| 102 | + cursor: 'pointer', |
| 103 | + ':hover, :focus': { |
| 104 | + background: hoverBackground |
| 105 | + } |
| 106 | +}); |
| 107 | + |
| 108 | +/* @conditional-compile-remove(reaction) */ |
| 109 | +const disabledDrawerMenuItemRootStyles = (background: string): IStyle => ({ |
| 110 | + pointerEvents: 'none', |
| 111 | + background: background, |
| 112 | + ':hover, :focus': { |
| 113 | + background: background |
| 114 | + } |
| 115 | +}); |
0 commit comments