Skip to content

Commit 58218ca

Browse files
committed
refactor(react-headless-components-preview): rebuild usePositioning on spec-pure CSS anchor positioning
1 parent 86973b7 commit 58218ca

32 files changed

Lines changed: 972 additions & 750 deletions

packages/react-components/react-headless-components-preview/library/etc/react-headless-components-preview.api.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,12 @@ export type PopoverContextValue = Pick<PopoverState, 'open' | 'setOpen' | 'toggl
396396
positioning: {
397397
targetRef: React_2.RefCallback<HTMLElement>;
398398
containerRef: React_2.RefCallback<HTMLElement>;
399-
arrowRef: React_2.RefCallback<HTMLElement>;
400399
};
401400
};
402401

403402
// @public
404403
export type PopoverProps = {
405-
children: [React_2.ReactElement, React_2.ReactElement] | React_2.ReactElement;
404+
children: [JSXElement, JSXElement] | JSXElement;
406405
open?: boolean;
407406
defaultOpen?: boolean;
408407
onOpenChange?: EventHandler<OnOpenChangeData>;
@@ -505,14 +504,13 @@ export type PositioningProps = {
505504
export type PositioningReturn = {
506505
targetRef: React_2.RefCallback<HTMLElement>;
507506
containerRef: React_2.RefCallback<HTMLElement>;
508-
arrowRef: React_2.RefCallback<HTMLElement>;
509507
};
510508

511509
// @public (undocumented)
512510
export type PositioningShorthand = PositioningProps | PositioningShorthandValue;
513511

514512
// @public (undocumented)
515-
export type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
513+
export type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-start' | 'before-end' | 'after' | 'after-start' | 'after-end';
516514

517515
// @public
518516
export const ProgressBar: ForwardRefComponent<ProgressBarProps>;
@@ -662,7 +660,7 @@ export const renderPopover: (state: PopoverState, contextValues: {
662660
export const renderPopoverSurface: (state: PopoverSurfaceState) => JSXElement;
663661

664662
// @public
665-
export const renderPopoverTrigger: (state: PopoverTriggerState) => React_2.ReactElement | null;
663+
export const renderPopoverTrigger: (state: PopoverTriggerState) => JSXElement | null;
666664

667665
// @public
668666
export const renderProgressBar: (state: ProgressBarState) => JSXElement;

packages/react-components/react-headless-components-preview/library/src/components/Popover/Popover.types.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type * as React from 'react';
2-
import type { ComponentProps, ComponentState, EventData, EventHandler, Slot } from '@fluentui/react-utilities';
2+
import type {
3+
ComponentProps,
4+
ComponentState,
5+
EventData,
6+
EventHandler,
7+
Slot,
8+
JSXElement,
9+
} from '@fluentui/react-utilities';
310
import type { PositioningShorthand, PositioningReturn } from '../../hooks/usePositioning';
411

512
/**
@@ -24,10 +31,10 @@ export type OnOpenChangeData = EventData<string, React.SyntheticEvent | Event> &
2431
*/
2532
export type PopoverProps = {
2633
/**
27-
* Can contain two children including PopoverTrigger and PopoverSurface.
28-
* Alternatively can only contain PopoverSurface if using a custom target.
34+
* Can contain two children including `PopoverTrigger` and `PopoverSurface`.
35+
* Alternatively can only contain `PopoverSurface` if using a custom `target`.
2936
*/
30-
children: [React.ReactElement, React.ReactElement] | React.ReactElement;
37+
children: [JSXElement, JSXElement] | JSXElement;
3138

3239
/** Controlled open state. */
3340
open?: boolean;
@@ -190,6 +197,5 @@ export type PopoverContextValue = Pick<
190197
positioning: {
191198
targetRef: React.RefCallback<HTMLElement>;
192199
containerRef: React.RefCallback<HTMLElement>;
193-
arrowRef: React.RefCallback<HTMLElement>;
194200
};
195201
};

packages/react-components/react-headless-components-preview/library/src/components/Popover/PopoverSurface/usePopoverSurface.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ export const usePopoverSurface = (props: PopoverSurfaceProps, ref: React.Ref<HTM
4242
onMountAutoFocus,
4343
});
4444

45-
const mergedArrowRef = useMergedRefs(arrowRef, positioningCtx.arrowRef);
46-
4745
const state: PopoverSurfaceState = {
4846
inline,
4947
withArrow,
50-
arrowRef: mergedArrowRef as React.RefObject<HTMLDivElement | null>,
48+
arrowRef,
5149
mountNode,
5250
components: { root: 'div' },
5351
root: slot.always(
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type * as React from 'react';
21
import type { PopoverTriggerState } from './PopoverTrigger.types';
2+
import type { JSXElement } from '@fluentui/react-utilities';
33

44
/**
55
* Renders the PopoverTrigger (returns the cloned child element).
66
*/
7-
export const renderPopoverTrigger = (state: PopoverTriggerState): React.ReactElement | null => {
7+
export const renderPopoverTrigger = (state: PopoverTriggerState): JSXElement | null => {
88
return state.children;
99
};

packages/react-components/react-headless-components-preview/library/src/components/Popover/popoverContext.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const popoverContextDefaultValue: PopoverContextValue = {
2525
positioning: {
2626
targetRef: () => undefined,
2727
containerRef: () => undefined,
28-
arrowRef: () => undefined,
2928
},
3029
};
3130

packages/react-components/react-headless-components-preview/library/src/components/Popover/usePopover.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ export const usePopoverContextValues = (state: PopoverState): { popover: Popover
199199
positioning: {
200200
targetRef: positioning.targetRef,
201201
containerRef: positioning.containerRef,
202-
arrowRef: positioning.arrowRef,
203202
},
204203
},
205204
};

packages/react-components/react-headless-components-preview/library/src/hooks/usePositioning/constants.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,38 @@
1-
import type { Position, Alignment } from './types';
1+
import type { LogicalAlignment, Position } from './types';
22

3-
export const FALLBACK_NAME_PREFIX = '--fluent-fallback-';
3+
export const GAP = 8;
44

55
export const POSITIONS = {
66
above: 'above',
77
below: 'below',
88
before: 'before',
99
after: 'after',
10-
};
10+
} as const;
1111

1212
export const ALIGNMENTS = {
1313
start: 'start',
1414
center: 'center',
1515
end: 'end',
16-
};
17-
18-
export const FLIP_POSITION_MAP: Record<Position, Position> = {
19-
above: 'below',
20-
below: 'above',
21-
before: 'after',
22-
after: 'before',
23-
};
16+
} as const;
2417

25-
export const POSITION_AREA_MAP: Record<Position, Record<Alignment, string>> = {
18+
export const POSITION_AREA_MAP: Record<Position, Record<LogicalAlignment, string>> = {
2619
above: {
27-
center: 'block-start center',
20+
center: 'block-start',
2821
start: 'block-start span-inline-end',
2922
end: 'block-start span-inline-start',
3023
},
3124
below: {
32-
center: 'block-end center',
25+
center: 'block-end',
3326
start: 'block-end span-inline-end',
3427
end: 'block-end span-inline-start',
3528
},
3629
before: {
37-
center: 'center inline-start',
30+
center: 'inline-start',
3831
start: 'inline-start span-block-end',
3932
end: 'inline-start span-block-start',
4033
},
4134
after: {
42-
center: 'center inline-end',
35+
center: 'inline-end',
4336
start: 'inline-end span-block-end',
4437
end: 'inline-end span-block-start',
4538
},

packages/react-components/react-headless-components-preview/library/src/hooks/usePositioning/fallbackStyles.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { usePositioning } from './usePositioning';
2-
export { getPlacementString, resolvePositioningShorthand } from './placement';
2+
export { getPlacementString, resolvePositioningShorthand } from './utils';
3+
export { POSITIONS, ALIGNMENTS } from './constants';
34
export type {
45
Position,
56
Alignment,
@@ -9,4 +10,3 @@ export type {
910
PositioningShorthand,
1011
PositioningShorthandValue,
1112
} from './types';
12-
export { POSITIONS, ALIGNMENTS } from './constants';

packages/react-components/react-headless-components-preview/library/src/hooks/usePositioning/placement.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)