Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Commit 1b4b6b6

Browse files
authored
fix(SplitButton): Updating splitButton component to match Teams redlines (#2108)
Updating the splitButton component to match Teams redlines...
1 parent 7491e57 commit 1b4b6b6

File tree

7 files changed

+130
-45
lines changed

7 files changed

+130
-45
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
2828

2929
### Fixes
3030
- Fix `toggle` changing width during animation in Teams theme @mnajdova ([#2189](https://github.com/microsoft/fluent-ui-react/pull/2189))
31+
- Update `SplitButton` styles in Teams theme [redlines] @notandrew ([#2108](https://github.com/microsoft/fluent-ui-react/pull/2108))
3132
- Fix `Popup` positioning in multiple cases @layershifter ([#2187](https://github.com/microsoft/fluent-ui-react/pull/2187))
3233
- Fix click outside in `Popup` when `trigger` is not defined @layershifter ([#2202](https://github.com/microsoft/fluent-ui-react/pull/2202))
3334
- Use `debounce` from `lodash` in `Dropdown` and `Carouel` @silviuavram ([#2203](https://github.com/microsoft/fluent-ui-react/pull/2203))

docs/src/examples/components/SplitButton/Slots/SplitButtonToggleButtonExample.shorthand.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ const SplitButtonExampleToggleButtonShorthand = () => {
1818
'aria-describedby': 'instruction-message-icon',
1919
}}
2020
toggleButton={{
21-
icon: open ? 'triangle-up' : 'triangle-down',
21+
icon: {
22+
name: 'icon-menu-arrow-down',
23+
style: open ? { transform: 'rotate(180deg)' } : null,
24+
},
2225
'aria-label': 'more options',
2326
}}
2427
onOpenChange={(e, { open }) => setOpen(open)}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react'
2+
import { SplitButton } from '@fluentui/react'
3+
4+
const SplitButtonExampleSmallShorthand = () => (
5+
<>
6+
<SplitButton
7+
menu={[
8+
{ key: 'group', content: 'New group message' },
9+
{ key: 'channel', content: 'New channel message' },
10+
]}
11+
button={{
12+
content: 'small',
13+
'aria-roledescription': 'splitbutton',
14+
'aria-describedby': 'instruction-message',
15+
}}
16+
size="small"
17+
toggleButton={{ 'aria-label': 'expand options menu' }}
18+
onMainButtonClick={() => alert('button was clicked')}
19+
/>
20+
<span aria-hidden="true" id="instruction-message" style={{ opacity: 0 }}>
21+
to open menu, press Alt + Arrow Down
22+
</span>
23+
</>
24+
)
25+
26+
export default SplitButtonExampleSmallShorthand

docs/src/examples/components/SplitButton/Types/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const SplitButton = () => (
1414
description="A SplitButton can be formatted to show primary level of emphasis."
1515
examplePath="components/SplitButton/Types/SplitButtonExamplePrimary"
1616
/>
17+
<ComponentExample
18+
title="Small"
19+
description="small splitbutton"
20+
examplePath="components/SplitButton/Types/SplitButtonExampleSmall"
21+
/>
1722
</ExampleSection>
1823
)
1924

packages/react/src/components/SplitButton/SplitButton.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
AutoControlledComponent,
2121
RenderResultConfig,
2222
ShorthandFactory,
23+
SizeValue,
2324
} from '../../utils'
2425
import Button, { ButtonProps } from '../Button/Button'
2526
import MenuButton, { MenuButtonProps } from '../MenuButton/MenuButton'
@@ -29,6 +30,7 @@ import { PopupProps } from '../Popup/Popup'
2930

3031
export interface SplitButtonSlotClassNames {
3132
toggleButton: string
33+
size?: SizeValue
3234
}
3335

3436
export interface SplitButtonProps
@@ -84,6 +86,9 @@ export interface SplitButtonProps
8486
/** A split button can be formatted to show different levels of emphasis. */
8587
secondary?: boolean
8688

89+
/** A split button can be sized */
90+
size?: SizeValue
91+
8792
/** Shorthand for the toggle button. */
8893
toggleButton?: ShorthandValue<ButtonProps>
8994
}
@@ -118,14 +123,15 @@ class SplitButton extends AutoControlledComponent<WithAsProp<SplitButtonProps>,
118123
onMenuItemClick: PropTypes.func,
119124
onOpenChange: PropTypes.func,
120125
open: PropTypes.bool,
126+
size: customPropTypes.size,
121127
primary: customPropTypes.every([customPropTypes.disallow(['secondary']), PropTypes.bool]),
122128
secondary: customPropTypes.every([customPropTypes.disallow(['primary']), PropTypes.bool]),
123129
toggleButton: customPropTypes.itemShorthand,
124130
}
125131

126132
static defaultProps = {
127133
accessibility: splitButtonBehavior,
128-
as: 'span',
134+
as: 'div',
129135
toggleButton: {},
130136
}
131137

@@ -174,7 +180,7 @@ class SplitButton extends AutoControlledComponent<WithAsProp<SplitButtonProps>,
174180
const { button, disabled, menu, primary, secondary, toggleButton } = this.props
175181
const trigger = Button.create(button, {
176182
defaultProps: () => ({
177-
styles: styles.button,
183+
styles: styles.menuButton,
178184
primary,
179185
secondary,
180186
disabled,
@@ -202,9 +208,10 @@ class SplitButton extends AutoControlledComponent<WithAsProp<SplitButtonProps>,
202208
)}
203209
{Button.create(toggleButton, {
204210
defaultProps: () => ({
211+
styles: styles.toggleButton,
205212
className: SplitButton.slotClassNames.toggleButton,
206213
disabled,
207-
icon: 'icon-arrow-down',
214+
icon: 'icon-menu-arrow-down',
208215
iconOnly: true,
209216
primary,
210217
secondary,

packages/react/src/themes/teams/components/SplitButton/splitButtonStyles.ts

Lines changed: 71 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,95 @@
11
import { ICSSInJSStyle } from '../../../types'
22
import getBorderFocusStyles from '../../getBorderFocusStyles'
3-
import SplitButton from '../../../../components/SplitButton/SplitButton'
3+
import getIconFillOrOutlineStyles from '../../getIconFillOrOutlineStyles'
44

55
const splitButtonStyles = {
6-
button: ({ variables: v }): ICSSInJSStyle => ({
7-
border: 0,
6+
menuButton: ({ props: p, variables: v }): ICSSInJSStyle => ({
7+
borderTopRightRadius: 0,
8+
borderBottomRightRadius: 0,
9+
borderRightWidth: 0,
810
padding: v.padding,
911

12+
...(p.size === 'small' && {
13+
height: v.smallDimension,
14+
padding: v.smallPadding,
15+
minWidth: v.smallMinWidth,
16+
boxShadow: v.smallBoxShadow,
17+
}),
18+
1019
':focus-visible': {
11-
'::before': { border: 0 },
12-
'::after': { border: 0 },
20+
borderRightWidth: 0,
21+
22+
':before': {
23+
borderRightWidth: 0,
24+
},
25+
26+
':after': {
27+
borderRightWidth: 0,
28+
},
29+
},
30+
31+
':active': {
32+
animationName: 'unset',
33+
animationDuration: 'unset',
1334
},
14-
':active': { backgroundColor: v.backgroundColorActive },
1535
}),
36+
37+
toggleButton: ({ props: p, variables: v, theme: { siteVariables } }): ICSSInJSStyle => ({
38+
borderTopLeftRadius: 0,
39+
borderBottomLeftRadius: 0,
40+
borderColor: v.borderColor,
41+
...getIconFillOrOutlineStyles({ outline: true }),
42+
43+
...(p.primary && {
44+
borderWidth: `0 0 0 ${siteVariables.borderWidth}`,
45+
borderColor: v.borderColorPrimary,
46+
}),
47+
48+
...(p.disabled && {
49+
borderWidth: `0 0 0 ${siteVariables.borderWidth}`,
50+
borderColor: v.borderColorDisabled,
51+
}),
52+
53+
...(p.size === 'small' && {
54+
height: v.smallDimension,
55+
width: v.smallDimension,
56+
minWidth: v.smallMinWidth,
57+
boxShadow: v.smallBoxShadow,
58+
}),
59+
60+
':focus-visible': {
61+
':before': {
62+
borderLeftWidth: 0,
63+
},
64+
65+
':after': {
66+
borderLeftWidth: 0,
67+
},
68+
},
69+
70+
':active': {
71+
animationName: 'unset',
72+
animationDuration: 'unset',
73+
},
74+
}),
75+
1676
root: ({ props: p, variables: v, theme: { siteVariables } }): ICSSInJSStyle => {
17-
const { borderWidth } = siteVariables
1877
const borderFocusStyles = getBorderFocusStyles({
1978
siteVariables,
2079
})
2180

2281
return {
23-
border: `${borderWidth} solid ${v.borderColor}`,
2482
borderRadius: v.borderRadius,
2583
position: 'relative',
2684
display: 'inline-block',
2785

28-
[`& .${SplitButton.slotClassNames.toggleButton}`]: {
29-
borderRight: 0,
30-
borderTop: 0,
31-
borderBottom: 0,
32-
},
33-
3486
':focus-within': {
3587
boxShadow: 'none',
36-
...(p.isFromKeyboard
37-
? {
38-
[`& .${SplitButton.slotClassNames.toggleButton}`]: {
39-
color: p.primary ? v.primaryColorFocus : v.colorFocus,
40-
backgroundColor: p.primary ? v.primaryBackgroundColorFocus : v.backgroundColorFocus,
41-
borderColor: siteVariables.colors.white,
42-
},
43-
44-
color: v.colorFocus,
45-
backgroundColor: v.backgroundColorFocus,
46-
...borderFocusStyles[':focus-visible'],
47-
}
48-
: { ':active': { backgroundColor: v.backgroundColorActive } }),
88+
...(p.isFromKeyboard && {
89+
// make sure focus is coming from keyboard before applying the focus styles
90+
// otherwise focus state is applied only to the button and not the toggle
91+
...borderFocusStyles[':focus-visible'],
92+
}),
4993
},
5094
}
5195
},
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import { SiteVariablesPrepared } from '../../../types'
2-
32
import { pxToRem } from '../../../../utils'
43

54
export interface SplitButtonVariables {
65
borderRadius: string
7-
backgroundColorFocus: string
8-
boxShadow: string
6+
borderColorPrimary: string
97
borderColor: string
10-
colorFocus: string
11-
primaryBackgroundColorFocus: string
12-
primaryColorFocus: string
8+
borderColorDisabled: string
9+
smallDimension: string
10+
smallPadding: string
11+
smallMinWidth: string
12+
smallBoxShadow: string
1313
padding: string
14-
iconMargin: string
1514
}
1615

1716
export default (siteVars: SiteVariablesPrepared): SplitButtonVariables => {
1817
return {
1918
borderRadius: siteVars.borderRadius,
20-
backgroundColorFocus: siteVars.colors.grey[200],
21-
boxShadow: siteVars.shadowLevel1,
22-
borderColor: siteVars.colors.grey[200],
23-
colorFocus: siteVars.colors.grey[750],
24-
primaryBackgroundColorFocus: siteVars.colors.brand[800],
25-
primaryColorFocus: siteVars.colors.white,
19+
borderColor: siteVars.colorScheme.default.border,
20+
borderColorPrimary: siteVars.colors.brand[500],
21+
borderColorDisabled: siteVars.colorScheme.brand.foregroundDisabled,
22+
smallDimension: pxToRem(24),
23+
smallPadding: `0 ${pxToRem(8)}`,
24+
smallMinWidth: '0',
25+
smallBoxShadow: 'none',
2626
padding: `0 ${pxToRem(16)}`,
27-
iconMargin: `0 0 ${pxToRem(8)} 0`,
2827
}
2928
}

0 commit comments

Comments
 (0)