-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split Nav Item Implementation (#32873)
- Loading branch information
Showing
16 changed files
with
540 additions
and
78 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-nav-preview-a6ef1dd9-e087-455c-8f57-279b716f32ae.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "feat: Build out SplitNavItem", | ||
"packageName": "@fluentui/react-nav-preview", | ||
"email": "matejera@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 21 additions & 9 deletions
30
...ct-components/react-nav-preview/library/src/components/SplitNavItem/SplitNavItem.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,30 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { SplitNavItem } from './SplitNavItem'; | ||
import { splitNavItemClassNames } from './useSplitNavItemStyles.styles'; | ||
|
||
describe('SplitNavItem', () => { | ||
isConformant({ | ||
Component: SplitNavItem, | ||
displayName: 'SplitNavItem', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<SplitNavItem>Default SplitNavItem</SplitNavItem>); | ||
expect(result.container).toMatchSnapshot(); | ||
testOptions: { | ||
'has-static-classnames': [ | ||
{ | ||
props: { | ||
icon: 'Test Icon', | ||
navItem: 'Some Content', | ||
actionButton: 'Some Content', | ||
toggleButton: 'Some Content', | ||
menuButton: 'Some Content', | ||
}, | ||
expectedClassNames: { | ||
root: splitNavItemClassNames.root, | ||
navItem: splitNavItemClassNames.navItem, | ||
actionButton: splitNavItemClassNames.actionButton, | ||
toggleButton: splitNavItemClassNames.toggleButton, | ||
menuButton: splitNavItemClassNames.menuButton, | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
}); |
39 changes: 35 additions & 4 deletions
39
...ct-components/react-nav-preview/library/src/components/SplitNavItem/SplitNavItem.types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,48 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
import { NavItemProps } from '../NavItem/NavItem.types'; | ||
import { ButtonProps, MenuButtonProps, ToggleButtonProps } from '@fluentui/react-button'; | ||
import { NavSize } from '../Nav/Nav.types'; | ||
|
||
export type SplitNavItemSlots = { | ||
/** | ||
* Root of the component, wrapping the children. | ||
*/ | ||
root: Slot<'div'>; | ||
|
||
/** | ||
* Primary navigation item in SplitNavItem. | ||
*/ | ||
navItem?: Slot<NavItemProps>; | ||
|
||
/** | ||
* Basic button slot. | ||
*/ | ||
actionButton?: Slot<ButtonProps>; | ||
|
||
/** | ||
* Toggle button slot | ||
*/ | ||
toggleButton?: Slot<ToggleButtonProps>; | ||
|
||
/** | ||
* Menu button slot to stuff more things in when the other two aren't enough. | ||
*/ | ||
menuButton?: Slot<MenuButtonProps>; | ||
}; | ||
|
||
/** | ||
* SplitNavItem Props | ||
*/ | ||
export type SplitNavItemProps = ComponentProps<SplitNavItemSlots> & {}; | ||
export type SplitNavItemProps = ComponentProps<SplitNavItemSlots>; | ||
|
||
/** | ||
* State used in rendering SplitNavItem | ||
*/ | ||
export type SplitNavItemState = ComponentState<SplitNavItemSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from SplitNavItemProps. | ||
// & Required<Pick<SplitNavItemProps, 'propName'>> | ||
export type SplitNavItemState = ComponentState<SplitNavItemSlots> & { | ||
/** | ||
* The size of the NavItem | ||
* | ||
* @default 'medium' | ||
*/ | ||
size: NavSize; | ||
}; |
11 changes: 0 additions & 11 deletions
11
...-nav-preview/library/src/components/SplitNavItem/__snapshots__/SplitNavItem.test.tsx.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
...react-components/react-nav-preview/library/src/components/SplitNavItem/useSplitNavItem.ts
This file was deleted.
Oops, something went wrong.
85 changes: 85 additions & 0 deletions
85
...eact-components/react-nav-preview/library/src/components/SplitNavItem/useSplitNavItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import * as React from 'react'; | ||
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities'; | ||
import type { SplitNavItemProps, SplitNavItemState } from './SplitNavItem.types'; | ||
import { useNavContext_unstable } from '../NavContext'; | ||
import { Button, MenuButton, ToggleButton } from '@fluentui/react-button'; | ||
import { MoreHorizontalFilled, Pin20Regular } from '@fluentui/react-icons'; | ||
import { NavItem } from '../NavItem/index'; | ||
|
||
/** | ||
* Create the state required to render SplitNavItem. | ||
* | ||
* The returned state can be modified with hooks such as useSplitNavItemStyles_unstable, | ||
* before being passed to renderSplitNavItem_unstable. | ||
* | ||
* @param props - props from this instance of SplitNavItem | ||
* @param ref - reference to root HTMLDivElement of SplitNavItem | ||
*/ | ||
export const useSplitNavItem_unstable = ( | ||
props: SplitNavItemProps, | ||
ref: React.Ref<HTMLDivElement>, | ||
): SplitNavItemState => { | ||
const { navItem, actionButton, toggleButton, menuButton, children } = props; | ||
|
||
const { size = 'medium' } = useNavContext_unstable(); | ||
|
||
const navItemShorthand = slot.optional(navItem, { | ||
defaultProps: { | ||
children, | ||
}, | ||
renderByDefault: true, | ||
elementType: NavItem, | ||
}); | ||
|
||
const actionButtonShorthand = slot.optional(actionButton, { | ||
defaultProps: { | ||
icon: <Pin20Regular />, | ||
size: 'small', | ||
appearance: 'transparent', | ||
}, | ||
elementType: Button, | ||
}); | ||
|
||
const toggleButtonShorthand = slot.optional(toggleButton, { | ||
defaultProps: { | ||
icon: <Pin20Regular />, | ||
size: 'small', | ||
appearance: 'transparent', | ||
}, | ||
elementType: ToggleButton, | ||
}); | ||
|
||
const menuButtonShorthand = slot.optional(menuButton, { | ||
defaultProps: { | ||
icon: <MoreHorizontalFilled />, | ||
size: 'small', | ||
appearance: 'transparent', | ||
}, | ||
elementType: MenuButton, | ||
}); | ||
|
||
return { | ||
components: { | ||
root: 'div', | ||
navItem: NavItem, | ||
actionButton: Button, | ||
toggleButton: ToggleButton, | ||
menuButton: MenuButton, | ||
}, | ||
root: slot.always( | ||
getIntrinsicElementProps('div', { | ||
ref, | ||
...props, | ||
// because we're passing in children to the NavItem, | ||
// We can be explicit about the children prop here | ||
children: null, | ||
}), | ||
{ elementType: 'div' }, | ||
), | ||
navItem: navItemShorthand, | ||
actionButton: actionButtonShorthand, | ||
toggleButton: toggleButtonShorthand, | ||
menuButton: menuButtonShorthand, | ||
size, | ||
}; | ||
}; |
Oops, something went wrong.