Skip to content

Commit a5c689e

Browse files
committed
refactor(react-headless-components-preview): rebuild usePositioning on spec-pure CSS anchor positioning
1 parent 4dce4b8 commit a5c689e

32 files changed

Lines changed: 986 additions & 754 deletions

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ export type AccordionState = AccordionBaseState & {
216216
};
217217

218218
// @public (undocumented)
219-
export type Alignment = (typeof ALIGNMENTS)[keyof typeof ALIGNMENTS];
219+
export type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
220220

221221
// @public
222222
export const Avatar: ForwardRefComponent<AvatarProps>;
@@ -483,13 +483,12 @@ export type PopoverContextValue = Pick<PopoverState, 'open' | 'setOpen' | 'toggl
483483
positioning: {
484484
targetRef: React_2.RefCallback<HTMLElement>;
485485
containerRef: React_2.RefCallback<HTMLElement>;
486-
arrowRef: React_2.RefCallback<HTMLElement>;
487486
};
488487
};
489488

490489
// @public
491490
export type PopoverProps = {
492-
children: [React_2.ReactElement, React_2.ReactElement] | React_2.ReactElement;
491+
children: [JSXElement, JSXElement] | JSXElement;
493492
open?: boolean;
494493
defaultOpen?: boolean;
495494
onOpenChange?: EventHandler<OnOpenChangeData>;
@@ -561,7 +560,7 @@ export type PopoverTriggerState = {
561560
};
562561

563562
// @public (undocumented)
564-
export type Position = (typeof POSITIONS)[keyof typeof POSITIONS];
563+
export type Position = 'above' | 'below' | 'before' | 'after';
565564

566565
// @public
567566
export type PositioningImperativeRef = {
@@ -592,14 +591,13 @@ export type PositioningProps = {
592591
export type PositioningReturn = {
593592
targetRef: React_2.RefCallback<HTMLElement>;
594593
containerRef: React_2.RefCallback<HTMLElement>;
595-
arrowRef: React_2.RefCallback<HTMLElement>;
596594
};
597595

598596
// @public (undocumented)
599597
export type PositioningShorthand = PositioningProps | PositioningShorthandValue;
600598

601599
// @public (undocumented)
602-
export type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
600+
export type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-start' | 'before-end' | 'after' | 'after-start' | 'after-end';
603601

604602
// @public
605603
export const ProgressBar: ForwardRefComponent<ProgressBarProps>;
@@ -761,7 +759,7 @@ export const renderPopover: (state: PopoverState, contextValues: {
761759
export const renderPopoverSurface: (state: PopoverSurfaceState) => JSXElement;
762760

763761
// @public
764-
export const renderPopoverTrigger: (state: PopoverTriggerState) => React_2.ReactElement | null;
762+
export const renderPopoverTrigger: (state: PopoverTriggerState) => JSXElement | null;
765763

766764
// @public
767765
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
@@ -206,7 +206,6 @@ export const usePopoverContextValues = (state: PopoverState): { popover: Popover
206206
positioning: {
207207
targetRef: positioning.targetRef,
208208
containerRef: positioning.containerRef,
209-
arrowRef: positioning.arrowRef,
210209
},
211210
},
212211
};

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)