Skip to content

Commit

Permalink
chore: moves slots from TreeItem to TreeItemLayout (#28621)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsunderhus authored Jul 25, 2023
1 parent c017e88 commit 0d4d0ef
Show file tree
Hide file tree
Showing 32 changed files with 461 additions and 470 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "chore: moves slots from TreeItem to TreeItemLayout",
"packageName": "@fluentui/react-tree",
"email": "[email protected]",
"dependentChangeType": "patch"
}
36 changes: 20 additions & 16 deletions packages/react-components/react-tree/etc/react-tree.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ArrowUp } from '@fluentui/keyboard-keys';
import type { AvatarContextValue } from '@fluentui/react-avatar';
import type { AvatarSize } from '@fluentui/react-avatar';
import { ButtonContextValue } from '@fluentui/react-button';
import type { Checkbox } from '@fluentui/react-checkbox';
import { Checkbox } from '@fluentui/react-checkbox';
import { CheckboxProps } from '@fluentui/react-checkbox';
import type { ComponentProps } from '@fluentui/react-utilities';
import type { ComponentState } from '@fluentui/react-utilities';
Expand All @@ -26,7 +26,7 @@ import type { ForwardRefComponent } from '@fluentui/react-utilities';
import type { Home } from '@fluentui/keyboard-keys';
import { Provider } from 'react';
import { ProviderProps } from 'react';
import type { Radio } from '@fluentui/react-radio';
import { Radio } from '@fluentui/react-radio';
import { RadioProps } from '@fluentui/react-radio';
import * as React_2 from 'react';
import { SelectionMode as SelectionMode_2 } from '@fluentui/react-utilities';
Expand Down Expand Up @@ -138,10 +138,15 @@ export type TreeContextValues = {
export const TreeItem: ForwardRefComponent<TreeItemProps>;

// @public (undocumented)
export const treeItemClassNames: SlotClassNames<TreeItemInternalSlot>;
export const treeItemClassNames: SlotClassNames<TreeItemSlots>;

// @public (undocumented)
export type TreeItemContextValue = {
isActionsVisible: boolean;
isAsideVisible: boolean;
selectionRef: React_2.Ref<HTMLInputElement>;
actionsRef: React_2.Ref<HTMLDivElement>;
expandIconRef: React_2.Ref<HTMLDivElement>;
layoutRef: React_2.Ref<HTMLDivElement>;
subtreeRef: React_2.Ref<HTMLDivElement>;
itemType: TreeItemType;
Expand All @@ -153,7 +158,7 @@ export type TreeItemContextValue = {
export const TreeItemLayout: ForwardRefComponent<TreeItemLayoutProps>;

// @public (undocumented)
export const treeItemLayoutClassNames: SlotClassNames<TreeItemLayoutInternalSlots>;
export const treeItemLayoutClassNames: SlotClassNames<TreeItemLayoutSlots>;

// @public
export type TreeItemLayoutProps = ComponentProps<Partial<TreeItemLayoutSlots>>;
Expand All @@ -164,10 +169,16 @@ export type TreeItemLayoutSlots = {
content: NonNullable<Slot<'div'>>;
iconBefore?: Slot<'div'>;
iconAfter?: Slot<'div'>;
expandIcon?: Slot<'div'>;
aside?: Slot<'div'>;
actions?: Slot<ExtractSlotProps<Slot<'div'> & {
visible?: boolean;
}>>;
selector?: Slot<typeof Checkbox> | Slot<typeof Radio>;
};

// @public
export type TreeItemLayoutState = ComponentState<TreeItemLayoutInternalSlots> & {
export type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots> & {
buttonContextValue: ButtonContextValue;
};

Expand All @@ -178,21 +189,21 @@ export const treeItemLevelToken: "--fluent-TreeItem--level";
export const TreeItemPersonaLayout: ForwardRefComponent<TreeItemPersonaLayoutProps>;

// @public (undocumented)
export const treeItemPersonaLayoutClassNames: SlotClassNames<TreeItemPersonaLayoutInternalSlots>;
export const treeItemPersonaLayoutClassNames: SlotClassNames<TreeItemPersonaLayoutSlots>;

// @public
export type TreeItemPersonaLayoutProps = ComponentProps<Partial<TreeItemPersonaLayoutSlots>>;

// @public (undocumented)
export type TreeItemPersonaLayoutSlots = {
export type TreeItemPersonaLayoutSlots = Pick<TreeItemLayoutSlots, 'actions' | 'aside' | 'expandIcon' | 'selector'> & {
root: NonNullable<Slot<'div'>>;
media: NonNullable<Slot<'div'>>;
content: NonNullable<Slot<'div'>>;
description?: Slot<'div'>;
};

// @public
export type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaLayoutInternalSlots> & {
export type TreeItemPersonaLayoutState = ComponentState<TreeItemPersonaLayoutSlots> & {
avatarSize: AvatarSize;
buttonContextValue: ButtonContextValue;
};
Expand All @@ -211,17 +222,10 @@ export type TreeItemSlots = {
root: Slot<ExtractSlotProps<Slot<'div'> & {
style?: TreeItemCSSProperties;
}>>;
expandIcon?: Slot<'div'>;
aside?: Slot<'div'>;
actions?: Slot<ExtractSlotProps<Slot<'div'> & {
visible?: boolean;
}>>;
checkboxIndicator?: Slot<typeof Checkbox>;
radioIndicator?: Slot<typeof Radio>;
};

// @public
export type TreeItemState = ComponentState<TreeItemInternalSlot> & TreeItemContextValue & TreeItemSlotsContextValue & {
export type TreeItemState = ComponentState<TreeItemSlots> & TreeItemContextValue & {
level: number;
itemType: TreeItemType;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ describe(TreeTest.displayName!, () => {
it('should not expand/collapse item on actions click', () => {
mount(
<TreeTest id="baseTree" aria-label="Tree">
<TreeItem actions={<Button id="action">action!</Button>} itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout>level 1, item 1</TreeItemLayout>
<TreeItem itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout actions={<Button id="action">action!</Button>}>level 1, item 1</TreeItemLayout>
<Tree>
<TreeItem itemType="leaf" value="item1__item1" data-testid="item1__item1">
<TreeItemLayout>level 2, item 1</TreeItemLayout>
Expand Down Expand Up @@ -169,8 +169,8 @@ describe(TreeTest.displayName!, () => {
it('should focus on actions when pressing tab key', () => {
mount(
<TreeTest id="baseTree" aria-label="Tree">
<TreeItem actions={<Button id="action">action</Button>} itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout>level 1, item 1</TreeItemLayout>
<TreeItem itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout actions={<Button id="action">action</Button>}>level 1, item 1</TreeItemLayout>
<Tree>
<TreeItem itemType="leaf" value="item1__item1" data-testid="item1__item1">
<TreeItemLayout>level 2, item 1</TreeItemLayout>
Expand All @@ -188,8 +188,8 @@ describe(TreeTest.displayName!, () => {
it('should not expand/collapse item on actions Enter/Space key', () => {
mount(
<TreeTest id="baseTree" aria-label="Tree">
<TreeItem actions={<Button id="action">action</Button>} itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout>level 1, item 1</TreeItemLayout>
<TreeItem itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout actions={<Button id="action">action</Button>}>level 1, item 1</TreeItemLayout>
<Tree>
<TreeItem itemType="leaf" value="item1__item1" data-testid="item1__item1">
<TreeItemLayout>level 2, item 1</TreeItemLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ describe(TreeTest.displayName!, () => {
it('should not expand/collapse item on actions click', () => {
mount(
<TreeTest id="baseTree" aria-label="Tree">
<TreeItem actions={<Button id="action">action!</Button>} itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout>level 1, item 1</TreeItemLayout>
<TreeItem itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout actions={<Button id="action">action!</Button>}>level 1, item 1</TreeItemLayout>
<Tree>
<TreeItem itemType="leaf" value="item1__item1" data-testid="item1__item1">
<TreeItemLayout>level 2, item 1</TreeItemLayout>
Expand Down Expand Up @@ -155,8 +155,8 @@ describe(TreeTest.displayName!, () => {
it('should focus on actions when pressing tab key', () => {
mount(
<TreeTest id="baseTree" aria-label="Tree">
<TreeItem actions={<Button id="action">action</Button>} itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout>level 1, item 1</TreeItemLayout>
<TreeItem itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout actions={<Button id="action">action</Button>}>level 1, item 1</TreeItemLayout>
<Tree>
<TreeItem itemType="leaf" value="item1__item1" data-testid="item1__item1">
<TreeItemLayout>level 2, item 1</TreeItemLayout>
Expand All @@ -174,8 +174,8 @@ describe(TreeTest.displayName!, () => {
it('should not expand/collapse item on actions Enter/Space key', () => {
mount(
<TreeTest id="baseTree" aria-label="Tree">
<TreeItem actions={<Button id="action">action</Button>} itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout>level 1, item 1</TreeItemLayout>
<TreeItem itemType="branch" value="item1" data-testid="item1">
<TreeItemLayout actions={<Button id="action">action</Button>}>level 1, item 1</TreeItemLayout>
<Tree>
<TreeItem itemType="leaf" value="item1__item1" data-testid="item1__item1">
<TreeItemLayout>level 2, item 1</TreeItemLayout>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,19 @@ import type { ComponentProps, ComponentState, ExtractSlotProps, Slot } from '@fl
import type { TreeItemContextValue } from '../../contexts';
import { treeItemLevelToken } from '../../utils/tokens';
import * as React from 'react';
import { TreeItemSlotsContextValue } from '../../contexts/treeItemSlotsContext';
import type { Checkbox } from '@fluentui/react-checkbox';
import type { Radio } from '@fluentui/react-radio';

export type TreeItemCSSProperties = React.CSSProperties & { [treeItemLevelToken]?: string | number };

export type TreeItemType = 'leaf' | 'branch';

export type TreeItemSlots = {
root: Slot<ExtractSlotProps<Slot<'div'> & { style?: TreeItemCSSProperties }>>;
/**
* Expand icon slot,
* by default renders a chevron icon to indicate opening and closing
*/
expandIcon?: Slot<'div'>;
aside?: Slot<'div'>;
/**
* actionable elements are normally buttons, menus, or other focusable elements.
* Those elements are only visibly available if the given tree item is currently active.
*/
actions?: Slot<
ExtractSlotProps<
Slot<'div'> & {
/**
* Forces visibility of the aside/action content
*/
visible?: boolean;
}
>
>;
/**
* Selection indicator if selection type is checkbox
*/
checkboxIndicator?: Slot<typeof Checkbox>;
/**
* Selection indicator if selection type is radio
*/
radioIndicator?: Slot<typeof Radio>;
};

export type TreeItemInternalSlot = Pick<TreeItemSlots, 'root'>;

export type TreeItemValue = string | number;

export type TreeItemContextValues = {
treeItem: TreeItemContextValue;
treeItemSlots: TreeItemSlotsContextValue;
};

/**
Expand All @@ -62,9 +28,8 @@ export type TreeItemProps = ComponentProps<Partial<TreeItemSlots>> & {
/**
* State used in rendering TreeItem
*/
export type TreeItemState = ComponentState<TreeItemInternalSlot> &
TreeItemContextValue &
TreeItemSlotsContextValue & {
export type TreeItemState = ComponentState<TreeItemSlots> &
TreeItemContextValue & {
level: number;
itemType: TreeItemType;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@

import { createElement } from '@fluentui/react-jsx-runtime';
import { getSlotsNext } from '@fluentui/react-utilities';
import type { TreeItemState, TreeItemContextValues, TreeItemInternalSlot } from './TreeItem.types';
import { TreeItemProvider, TreeItemSlotsProvider } from '../../contexts';
import type { TreeItemState, TreeItemContextValues, TreeItemSlots } from './TreeItem.types';
import { TreeItemProvider } from '../../contexts';

/**
* Render the final JSX of TreeItem
*/
export const renderTreeItem_unstable = (state: TreeItemState, contextValues: TreeItemContextValues) => {
const { slots, slotProps } = getSlotsNext<TreeItemInternalSlot>(state);
const { slots, slotProps } = getSlotsNext<TreeItemSlots>(state);

return (
<slots.root {...slotProps.root}>
<TreeItemProvider value={contextValues.treeItem}>
<TreeItemSlotsProvider value={contextValues.treeItemSlots}>{slotProps.root.children}</TreeItemSlotsProvider>
</TreeItemProvider>
<TreeItemProvider value={contextValues.treeItem}>{slotProps.root.children}</TreeItemProvider>
</slots.root>
);
};
Loading

0 comments on commit 0d4d0ef

Please sign in to comment.