Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵🏾‍♀️ visual changes to review in the Visual Change Report

vr-tests-react-components/CalendarCompat 4 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/CalendarCompat.multiDayView - Dark Mode.default.chromium.png 1107 Changed
vr-tests-react-components/CalendarCompat.multiDayView.default.chromium_1.png 403 Changed
vr-tests-react-components/CalendarCompat.multiDayView - RTL.default.chromium.png 495 Changed
vr-tests-react-components/CalendarCompat.multiDayView - High Contrast.default.chromium.png 1236 Changed
vr-tests-react-components/Charts-DonutChart 1 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Charts-DonutChart.Dynamic - RTL.default.chromium.png 5570 Changed
vr-tests-react-components/Menu Converged - submenuIndicator slotted content 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Menu Converged - submenuIndicator slotted content.default - RTL.submenus open.chromium.png 404 Changed
vr-tests-react-components/Menu Converged - submenuIndicator slotted content.default.submenus open.chromium.png 606 Changed
vr-tests-react-components/Positioning 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/Positioning.Positioning end.chromium.png 608 Changed
vr-tests-react-components/Positioning.Positioning end.updated 2 times.chromium.png 125 Changed
vr-tests-react-components/TagPicker 2 screenshots
Image Name Diff(in Pixels) Image Type
vr-tests-react-components/TagPicker.disabled - Dark Mode.disabled input hover.chromium.png 658 Changed
vr-tests-react-components/TagPicker.disabled - High Contrast.disabled input hover.chromium.png 1319 Changed

There were 3 duplicate changes discarded. Check the build logs for more information.

"type": "minor",
"comment": "feat: add base hooks for Link",
"packageName": "@fluentui/react-link",
"email": "dmytrokirpa@microsoft.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';
import type { ComponentProps, ComponentState, DistributiveOmit, Slot } from '@fluentui/react-utilities';
import { BackgroundAppearanceContextValue } from '@fluentui/react-shared-contexts';

export type LinkSlots = {
Expand Down Expand Up @@ -36,7 +36,18 @@ export type LinkProps = ComponentProps<LinkSlots> & {
inline?: boolean;
};

/**
* Link props without design-specific props (appearance).
* Use this when building a base link that is unstyled or uses a custom design system.
*/
export type LinkBaseProps = DistributiveOmit<LinkProps, 'appearance'>;

export type LinkState = ComponentState<LinkSlots> &
Required<Pick<LinkProps, 'appearance' | 'disabled' | 'disabledFocusable' | 'inline'>> & {
backgroundAppearance?: BackgroundAppearanceContextValue;
};

/**
* Link state without design-specific state (appearance, backgroundAppearance).
*/
export type LinkBaseState = DistributiveOmit<LinkState, 'appearance' | 'backgroundAppearance'>;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { Link } from './Link';
export type { LinkProps, LinkSlots, LinkState } from './Link.types';
export type { LinkBaseProps, LinkBaseState, LinkProps, LinkSlots, LinkState } from './Link.types';
export { renderLink_unstable } from './renderLink';
export { useLink_unstable } from './useLink';
export { useLink_unstable, useLinkBase_unstable } from './useLink';
export { useLinkState_unstable } from './useLinkState';
export { linkClassNames, useLinkStyles_unstable } from './useLinkStyles.styles';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as React from 'react';
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities';
import { useBackgroundAppearance } from '@fluentui/react-shared-contexts';
import { useLinkState_unstable } from './useLinkState';
import type { LinkProps, LinkState } from './Link.types';
import type { LinkBaseProps, LinkBaseState, LinkProps, LinkState } from './Link.types';
import { useLinkContext } from '../../contexts/linkContext';

/**
Expand All @@ -17,8 +17,30 @@ export const useLink_unstable = (
ref: React.Ref<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>,
): LinkState => {
const backgroundAppearance = useBackgroundAppearance();
const { appearance = 'default', ...baseProps } = props;

const state = useLinkBase_unstable(baseProps, ref);

return {
appearance,
backgroundAppearance,
...state,
};
};

/**
* Base hook for Link component, which manages state related to ARIA, keyboard handling,
* disabled behavior, and slot structure. This hook excludes design-specific props (appearance).
*
* @param props - User provided props to the Link component.
* @param ref - User provided ref to be passed to the Link component.
*/
export const useLinkBase_unstable = (
props: LinkBaseProps,
ref: React.Ref<HTMLAnchorElement | HTMLButtonElement | HTMLSpanElement>,
): LinkBaseState => {
const { inline: inlineContext } = useLinkContext();
const { appearance = 'default', disabled = false, disabledFocusable = false, inline = false } = props;
const { disabled = false, disabledFocusable = false, inline = false } = props;

const elementType = props.as || (props.href ? 'a' : 'button');

Expand All @@ -28,11 +50,10 @@ export const useLink_unstable = (
type: elementType === 'button' ? 'button' : undefined,
...props,
as: elementType,
} as LinkProps;
} as LinkBaseProps;

const state: LinkState = {
const state: LinkBaseState = {
// Props passed at the top-level
appearance,
disabled,
disabledFocusable,
inline: inline ?? !!inlineContext,
Expand All @@ -43,16 +64,16 @@ export const useLink_unstable = (
},

root: slot.always(
getIntrinsicElementProps<LinkProps>(elementType, {
getIntrinsicElementProps<LinkBaseProps>(elementType, {
ref,
...propsWithAssignedAs,
} as const),
{ elementType },
),
backgroundAppearance,
};

useLinkState_unstable(state);
// useLinkState_unstable only accesses disabled, disabledFocusable, and root — all present in LinkBaseState
useLinkState_unstable(state as unknown as LinkState);

return state;
};
4 changes: 4 additions & 0 deletions packages/react-components/react-link/library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ export {
export type { LinkProps, LinkSlots, LinkState } from './Link';
export { linkContextDefaultValue, LinkContextProvider, useLinkContext } from './contexts';
export type { LinkContextValue } from './contexts';

// Experimental APIs - will be uncommented in the experimental release branch
// export { useLinkBase_unstable } from './Link';
// export type { LinkBaseProps, LinkBaseState } from './Link';
Loading