-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scaffolds more Nav components (#30227)
Co-authored-by: Makoto Morimoto <[email protected]>
- Loading branch information
Showing
28 changed files
with
424 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/NavCategory/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-nav-preview/src/NavSubItemGroup.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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './components/NavSubItemGroup/index'; |
10 changes: 5 additions & 5 deletions
10
packages/react-components/react-nav-preview/src/components/Nav/index.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,5 +1,5 @@ | ||
export * from './Nav'; | ||
export * from './Nav.types'; | ||
export * from './renderNav'; | ||
export * from './useNav'; | ||
export * from './useNavStyles.styles'; | ||
export { Nav } from './Nav'; | ||
export type { NavSlots, NavProps, OnNavItemSelectData, NavState } from './Nav.types'; | ||
export { renderNav_unstable } from './renderNav'; | ||
export { useNav_unstable } from './useNav'; | ||
export { useNavStyles_unstable, navClassNames } from './useNavStyles.styles'; |
9 changes: 9 additions & 0 deletions
9
packages/react-components/react-nav-preview/src/components/NavCategory/NavCategory.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { NavCategory } from './NavCategory'; | ||
|
||
describe('NavCategory', () => { | ||
isConformant({ | ||
Component: NavCategory, | ||
displayName: 'NavCategory', | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
packages/react-components/react-nav-preview/src/components/NavCategory/NavCategory.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,22 @@ | ||
import * as React from 'react'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
// import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts'; | ||
import { useNavCategory_unstable } from './useNavCategory'; | ||
import { renderNavCategory_unstable } from './renderNavCategory'; | ||
import { useNavCategoryStyles_unstable } from './useNavCategoryStyles.styles'; | ||
import type { NavCategoryProps } from './NavCategory.types'; | ||
|
||
/** | ||
* NavCategory component - TODO: add more docs | ||
*/ | ||
export const NavCategory: ForwardRefComponent<NavCategoryProps> = React.forwardRef((props, ref) => { | ||
const state = useNavCategory_unstable(props, ref); | ||
|
||
useNavCategoryStyles_unstable(state); | ||
// TODO update types in packages/react-components/react-shared-contexts/src/CustomStyleHooksContext/CustomStyleHooksContext.ts | ||
// https://github.com/microsoft/fluentui/blob/master/rfcs/react-components/convergence/custom-styling.md | ||
// useCustomStyleHook_unstable('useNavCategoryStyles_unstable')(state); | ||
return renderNavCategory_unstable(state); | ||
}); | ||
|
||
NavCategory.displayName = 'NavCategory'; |
17 changes: 17 additions & 0 deletions
17
packages/react-components/react-nav-preview/src/components/NavCategory/NavCategory.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type NavCategorySlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* NavCategory Props | ||
*/ | ||
export type NavCategoryProps = ComponentProps<NavCategorySlots> & {}; | ||
|
||
/** | ||
* State used in rendering NavCategory | ||
*/ | ||
export type NavCategoryState = ComponentState<NavCategorySlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from NavCategoryProps. | ||
// & Required<Pick<NavCategoryProps, 'propName'>> |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-nav-preview/src/components/NavCategory/index.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { NavCategory } from './NavCategory'; | ||
export type { NavCategorySlots, NavCategoryProps, NavCategoryState } from './NavCategory.types'; | ||
export { renderNavCategory_unstable } from './renderNavCategory'; | ||
export { useNavCategory_unstable } from './useNavCategory'; | ||
export { useNavCategoryStyles_unstable, navCategoryClassNames } from './useNavCategoryStyles.styles'; |
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-nav-preview/src/components/NavCategory/renderNavCategory.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,15 @@ | ||
/** @jsxRuntime automatic */ | ||
/** @jsxImportSource @fluentui/react-jsx-runtime */ | ||
|
||
import { assertSlots } from '@fluentui/react-utilities'; | ||
import type { NavCategoryState, NavCategorySlots } from './NavCategory.types'; | ||
|
||
/** | ||
* Render the final JSX of NavCategory | ||
*/ | ||
export const renderNavCategory_unstable = (state: NavCategoryState) => { | ||
assertSlots<NavCategorySlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <state.root />; | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/react-components/react-nav-preview/src/components/NavCategory/useNavCategory.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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import * as React from 'react'; | ||
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities'; | ||
import type { NavCategoryProps, NavCategoryState } from './NavCategory.types'; | ||
|
||
/** | ||
* Create the state required to render NavCategory. | ||
* | ||
* The returned state can be modified with hooks such as useNavCategoryStyles_unstable, | ||
* before being passed to renderNavCategory_unstable. | ||
* | ||
* @param props - props from this instance of NavCategory | ||
* @param ref - reference to root HTMLDivElement of NavCategory | ||
*/ | ||
export const useNavCategory_unstable = (props: NavCategoryProps, ref: React.Ref<HTMLDivElement>): NavCategoryState => { | ||
return { | ||
// TODO add appropriate props/defaults | ||
components: { | ||
// TODO add each slot's element type or component | ||
root: 'div', | ||
}, | ||
// TODO add appropriate slots, for example: | ||
// mySlot: resolveShorthand(props.mySlot), | ||
root: slot.always( | ||
getIntrinsicElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
{ elementType: 'div' }, | ||
), | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
...ct-components/react-nav-preview/src/components/NavCategory/useNavCategoryStyles.styles.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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { makeStyles, mergeClasses } from '@griffel/react'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import type { NavCategorySlots, NavCategoryState } from './NavCategory.types'; | ||
|
||
export const navCategoryClassNames: SlotClassNames<NavCategorySlots> = { | ||
root: 'fui-NavCategory', | ||
// TODO: add class names for all slots on NavCategorySlots. | ||
// Should be of the form `<slotName>: 'fui-NavCategory__<slotName>` | ||
}; | ||
|
||
/** | ||
* Styles for the root slot | ||
*/ | ||
const useStyles = makeStyles({ | ||
root: { | ||
// TODO Add default styles for the root element | ||
}, | ||
|
||
// TODO add additional classes for different states and/or slots | ||
}); | ||
|
||
/** | ||
* Apply styling to the NavCategory slots based on the state | ||
*/ | ||
export const useNavCategoryStyles_unstable = (state: NavCategoryState): NavCategoryState => { | ||
const styles = useStyles(); | ||
state.root.className = mergeClasses(navCategoryClassNames.root, styles.root, state.root.className); | ||
|
||
// TODO Add class names to slots, for example: | ||
// state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className); | ||
|
||
return state; | ||
}; |
10 changes: 5 additions & 5 deletions
10
packages/react-components/react-nav-preview/src/components/NavCategoryItem/index.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,5 +1,5 @@ | ||
export * from './NavCategoryItem'; | ||
export * from './NavCategoryItem.types'; | ||
export * from './renderNavCategoryItem'; | ||
export * from './useNavCategoryItem'; | ||
export * from './useNavCategoryItem.styles'; | ||
export { NavCategoryItem } from './NavCategoryItem'; | ||
export type { NavCategoryItemSlots, NavCategoryItemProps, NavCategoryItemState } from './NavCategoryItem.types'; | ||
export { renderNavCategoryItem_unstable } from './renderNavCategoryItem'; | ||
export { useNavCategoryItem_unstable } from './useNavCategoryItem'; | ||
export { useNavCategoryItemStyles_unstable, navCategoryItemClassNames } from './useNavCategoryItem.styles'; |
9 changes: 9 additions & 0 deletions
9
...eact-components/react-nav-preview/src/components/NavSubItemGroup/NavSubItemGroup.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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { NavSubItemGroup } from './NavSubItemGroup'; | ||
|
||
describe('NavSubItemGroup', () => { | ||
isConformant({ | ||
Component: NavSubItemGroup, | ||
displayName: 'NavSubItemGroup', | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
...ges/react-components/react-nav-preview/src/components/NavSubItemGroup/NavSubItemGroup.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,22 @@ | ||
import * as React from 'react'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
// import { useCustomStyleHook_unstable } from '@fluentui/react-shared-contexts'; | ||
import { useNavSubItemGroup_unstable } from './useNavSubItemGroup'; | ||
import { renderNavSubItemGroup_unstable } from './renderNavSubItemGroup'; | ||
import { useNavSubItemGroupStyles_unstable } from './useNavSubItemGroupStyles.styles'; | ||
import type { NavSubItemGroupProps } from './NavSubItemGroup.types'; | ||
|
||
/** | ||
* NavSubItemGroup component - TODO: add more docs | ||
*/ | ||
export const NavSubItemGroup: ForwardRefComponent<NavSubItemGroupProps> = React.forwardRef((props, ref) => { | ||
const state = useNavSubItemGroup_unstable(props, ref); | ||
|
||
useNavSubItemGroupStyles_unstable(state); | ||
// TODO update types in packages/react-components/react-shared-contexts/src/CustomStyleHooksContext/CustomStyleHooksContext.ts | ||
// https://github.com/microsoft/fluentui/blob/master/rfcs/react-components/convergence/custom-styling.md | ||
// useCustomStyleHook_unstable('useNavSubItemGroupStyles_unstable')(state); | ||
return renderNavSubItemGroup_unstable(state); | ||
}); | ||
|
||
NavSubItemGroup.displayName = 'NavSubItemGroup'; |
17 changes: 17 additions & 0 deletions
17
...eact-components/react-nav-preview/src/components/NavSubItemGroup/NavSubItemGroup.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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type NavSubItemGroupSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* NavSubItemGroup Props | ||
*/ | ||
export type NavSubItemGroupProps = ComponentProps<NavSubItemGroupSlots> & {}; | ||
|
||
/** | ||
* State used in rendering NavSubItemGroup | ||
*/ | ||
export type NavSubItemGroupState = ComponentState<NavSubItemGroupSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from NavSubItemGroupProps. | ||
// & Required<Pick<NavSubItemGroupProps, 'propName'>> |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-nav-preview/src/components/NavSubItemGroup/index.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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export { NavSubItemGroup } from './NavSubItemGroup'; | ||
export type { NavSubItemGroupSlots, NavSubItemGroupProps, NavSubItemGroupState } from './NavSubItemGroup.types'; | ||
export { renderNavSubItemGroup_unstable } from './renderNavSubItemGroup'; | ||
export { useNavSubItemGroup_unstable } from './useNavSubItemGroup'; | ||
export { useNavSubItemGroupStyles_unstable, navSubItemGroupClassNames } from './useNavSubItemGroupStyles.styles'; |
15 changes: 15 additions & 0 deletions
15
...act-components/react-nav-preview/src/components/NavSubItemGroup/renderNavSubItemGroup.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,15 @@ | ||
/** @jsxRuntime automatic */ | ||
/** @jsxImportSource @fluentui/react-jsx-runtime */ | ||
|
||
import { assertSlots } from '@fluentui/react-utilities'; | ||
import type { NavSubItemGroupState, NavSubItemGroupSlots } from './NavSubItemGroup.types'; | ||
|
||
/** | ||
* Render the final JSX of NavSubItemGroup | ||
*/ | ||
export const renderNavSubItemGroup_unstable = (state: NavSubItemGroupState) => { | ||
assertSlots<NavSubItemGroupSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <state.root />; | ||
}; |
34 changes: 34 additions & 0 deletions
34
...s/react-components/react-nav-preview/src/components/NavSubItemGroup/useNavSubItemGroup.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import * as React from 'react'; | ||
import { getIntrinsicElementProps, slot } from '@fluentui/react-utilities'; | ||
import type { NavSubItemGroupProps, NavSubItemGroupState } from './NavSubItemGroup.types'; | ||
|
||
/** | ||
* Create the state required to render NavSubItemGroup. | ||
* | ||
* The returned state can be modified with hooks such as useNavSubItemGroupStyles_unstable, | ||
* before being passed to renderNavSubItemGroup_unstable. | ||
* | ||
* @param props - props from this instance of NavSubItemGroup | ||
* @param ref - reference to root HTMLDivElement of NavSubItemGroup | ||
*/ | ||
export const useNavSubItemGroup_unstable = ( | ||
props: NavSubItemGroupProps, | ||
ref: React.Ref<HTMLDivElement>, | ||
): NavSubItemGroupState => { | ||
return { | ||
// TODO add appropriate props/defaults | ||
components: { | ||
// TODO add each slot's element type or component | ||
root: 'div', | ||
}, | ||
// TODO add appropriate slots, for example: | ||
// mySlot: resolveShorthand(props.mySlot), | ||
root: slot.always( | ||
getIntrinsicElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
{ elementType: 'div' }, | ||
), | ||
}; | ||
}; |
Oops, something went wrong.