Skip to content

Commit 0458d80

Browse files
authored
[Callout][macOS] Support Border Tokens (#3002)
* [Callout][macOS] Support Border Tokens * Change files * PR feedback
1 parent d1e10c6 commit 0458d80

15 files changed

+77
-26
lines changed

apps/fluent-tester/src/TestComponents/Callout/CalloutTest.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import type { KeyboardMetrics } from 'react-native';
3-
import { Text, View, Switch, ScrollView } from 'react-native';
3+
import { Text, View, Switch, ScrollView, Platform } from 'react-native';
44

55
import { Button, Callout, Separator, Pressable, StealthButton } from '@fluentui/react-native';
66
import type { IFocusable, RestoreFocusEvent, DismissBehaviors, ICalloutProps } from '@fluentui/react-native';
@@ -190,16 +190,26 @@ const StandardCallout: React.FunctionComponent = () => {
190190
const [selectedBackgroundColor, setSelectedBackgroundColor] = React.useState<string | undefined>(undefined);
191191
const [selectedBorderColor, setSelectedBorderColor] = React.useState<string | undefined>(undefined);
192192

193-
const borderWidthDefault: string = '1';
194-
const borderWidthSelections: string[] = ['1', '2', '4', '10'];
193+
const borderWidthDefault: string = Platform.OS === 'macos' ? '0' : '1';
194+
const borderWidthSelections: string[] = ['0', '1', '2', '4', '10'];
195195
const menuPickerBorderWidthCollection = borderWidthSelections.map((width) => {
196196
return {
197197
label: width,
198198
value: width,
199199
};
200200
});
201201

202+
const borderRadiusDefault: string = '5';
203+
const borderRadiusSelections: string[] = ['0', '5', '7', '15'];
204+
const menuPickerBorderRadiusCollection = borderRadiusSelections.map((width) => {
205+
return {
206+
label: width,
207+
value: width,
208+
};
209+
});
210+
202211
const [selectedBorderWidth, setSelectedBorderWidth] = React.useState<string | undefined>(undefined);
212+
const [selectedBorderRadius, setSelectedBorderRadius] = React.useState<string | undefined>(undefined);
203213

204214
const [showScrollViewCallout, setShowScrollViewCalout] = React.useState(false);
205215
const [scrollviewContents, setScrollviewContents] = React.useState([1, 2, 3]);
@@ -278,6 +288,12 @@ const StandardCallout: React.FunctionComponent = () => {
278288
onChange={(color) => setSelectedBorderWidth(color === colorDefault ? undefined : color)}
279289
collection={menuPickerBorderWidthCollection}
280290
/>
291+
<MenuPicker
292+
prompt="Border Radius"
293+
selected={selectedBorderRadius || borderRadiusDefault}
294+
onChange={(radius) => setSelectedBorderRadius(radius === borderRadiusDefault ? undefined : radius)}
295+
collection={menuPickerBorderRadiusCollection}
296+
/>
281297
</View>
282298

283299
<Separator vertical />
@@ -345,6 +361,7 @@ const StandardCallout: React.FunctionComponent = () => {
345361
...(selectedBorderColor && { borderColor: selectedBorderColor }),
346362
...(selectedBackgroundColor && { backgroundColor: selectedBackgroundColor }),
347363
...(selectedBorderWidth && { borderWidth: parseInt(selectedBorderWidth) }),
364+
...(selectedBorderRadius && { borderRadius: parseInt(selectedBorderRadius) }),
348365
...(calloutDismissBehaviors && { dismissBehaviors: calloutDismissBehaviors }),
349366
}}
350367
>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "[Callout][macOS] Support Border Tokens",
4+
"packageName": "@fluentui-react-native/callout",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "[Callout][macOS] Support Border Tokens",
4+
"packageName": "@fluentui-react-native/menu",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "[Callout][macOS] Support Border Tokens",
4+
"packageName": "@fluentui-react-native/tester",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/components/Callout/macos/CalloutView.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
6464
}
6565
}
6666

67+
override func updateLayer() {
68+
if let layer = calloutWindow.contentView?.layer {
69+
layer.borderColor = borderColor.cgColor
70+
layer.borderWidth = borderWidth
71+
layer.backgroundColor = backgroundColor.cgColor
72+
layer.cornerRadius = borderRadius
73+
}
74+
}
6775

6876
// MARK: RCTComponent Overrides
6977

@@ -365,7 +373,6 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
365373
visualEffectView.material = .menu
366374
visualEffectView.state = .active
367375
visualEffectView.wantsLayer = true
368-
visualEffectView.layer?.cornerRadius = calloutWindowCornerRadius
369376

370377
/**
371378
* We can't directly call touchHandler.attach(to:) because `visualEffectView` is not an RCTUIView.
@@ -398,7 +405,3 @@ class CalloutView: RCTView, CalloutWindowLifeCycleDelegate {
398405

399406
private var isCalloutWindowShown = false
400407
}
401-
402-
403-
404-
private var calloutWindowCornerRadius: CGFloat = 5.0

packages/components/Callout/src/Callout.settings.macos.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ export const settings: IComposeSettings<ICalloutType> = [
77
{
88
tokens: {
99
backgroundColor: 'bodyStandoutBackground',
10-
beakWidth: 20,
11-
borderColor: 'bodyFrameBackground',
12-
borderWidth: 1,
10+
borderColor: 'transparent',
11+
borderWidth: 0,
12+
borderRadius: 5,
1313
directionalHint: 'bottonLeftEdge',
14-
gapSpace: 0,
15-
minPadding: 0,
1614
},
1715
root: {
1816
style: {

packages/components/Callout/src/Callout.types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export interface RestoreFocusEvent {
3939
}
4040

4141
interface OmittedBorderTokens {
42-
borderRadius?: number | string;
4342
borderStyle?: ViewStyle['borderStyle'];
4443
}
4544

packages/components/Menu/SPEC.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ export interface MenuListTokens extends LayoutTokens, IBackgroundColorTokens {
293293

294294
/**
295295
* Corner radius of the menu list
296-
* @platform android
296+
* @platform android macos
297297
*/
298-
cornerRadius?: number;
298+
borderRadius?: number;
299299
}
300300
```
301301

packages/components/Menu/src/MenuCallout/MenuCallout.android.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const MenuCallout = stagedComponent((props: MenuCalloutProps) => {
3535
maxHeight: mergedProps.maxHeight ? mergedProps.maxHeight : tokens.maxHeight,
3636
maxWidth: tokens.maxWidth,
3737
position: 'absolute',
38-
borderRadius: tokens.cornerRadius,
38+
borderRadius: tokens.borderRadius,
3939
elevation: tokens.elevation,
4040
overflow: 'hidden',
4141
},

packages/components/Menu/src/MenuCallout/MenuCallout.types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export type MenuCalloutTokens =
88
| Omit<ICalloutTokens, 'anchorRect' | 'beakWidth' | 'dismissBehaviors'> & {
99
/**
1010
* The token for the corner radius for the Modal MenuPopover
11-
* @platform android
11+
* @platform android macos
1212
*/
13-
cornerRadius?: number;
13+
borderRadius?: number;
1414

1515
/**
1616
* Shadown elevation token for the Modal MenuPopover

0 commit comments

Comments
 (0)