-
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.
- Loading branch information
Showing
12 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-nav-preview-8415b62b-8398-424c-9b31-d1ee026e9b99.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": "Scaffolds SplitNavItem", | ||
"packageName": "@fluentui/react-nav-preview", | ||
"email": "[email protected]", | ||
"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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-nav-preview/library/src/SplitNavItem.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/SplitNavItem/index'; |
18 changes: 18 additions & 0 deletions
18
...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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { SplitNavItem } from './SplitNavItem'; | ||
|
||
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(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
...s/react-components/react-nav-preview/library/src/components/SplitNavItem/SplitNavItem.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,29 @@ | ||
import * as React from 'react'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
import { useSplitNavItem_unstable } from './useSplitNavItem'; | ||
import { renderSplitNavItem_unstable } from './renderSplitNavItem'; | ||
import { useSplitNavItemStyles_unstable } from './useSplitNavItemStyles.styles'; | ||
import type { SplitNavItemProps } from './SplitNavItem.types'; | ||
|
||
/** | ||
* SplitNavItem component - TODO: add more docs | ||
*/ | ||
export const SplitNavItem: ForwardRefComponent<SplitNavItemProps> = React.forwardRef((props, ref) => { | ||
const state = useSplitNavItem_unstable(props, ref); | ||
|
||
useSplitNavItemStyles_unstable(state); | ||
|
||
/** | ||
* @see https://github.com/microsoft/fluentui/blob/master/docs/react-v9/contributing/rfcs/react-components/convergence/custom-styling.md | ||
* | ||
* TODO: 💡 once package will become stable (PR which will be part of promoting PREVIEW package to STABLE), | ||
* - uncomment this line | ||
* - update types {@link file://./../../../../../../../packages/react-components/react-shared-contexts/library/src/CustomStyleHooksContext/CustomStyleHooksContext.ts#CustomStyleHooksContextValue} | ||
* - verify that custom global style override works for your component | ||
*/ | ||
// useCustomStyleHook_unstable('useSplitNavItemStyles_unstable')(state); | ||
|
||
return renderSplitNavItem_unstable(state); | ||
}); | ||
|
||
SplitNavItem.displayName = 'SplitNavItem'; |
17 changes: 17 additions & 0 deletions
17
...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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type SplitNavItemSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* SplitNavItem Props | ||
*/ | ||
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'>> |
11 changes: 11 additions & 0 deletions
11
...-nav-preview/library/src/components/SplitNavItem/__snapshots__/SplitNavItem.test.tsx.snap
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,11 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`SplitNavItem renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-SplitNavItem" | ||
> | ||
Default SplitNavItem | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-nav-preview/library/src/components/SplitNavItem/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 * from './SplitNavItem'; | ||
export * from './SplitNavItem.types'; | ||
export * from './renderSplitNavItem'; | ||
export * from './useSplitNavItem'; | ||
export * from './useSplitNavItemStyles.styles'; |
15 changes: 15 additions & 0 deletions
15
...t-components/react-nav-preview/library/src/components/SplitNavItem/renderSplitNavItem.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 { SplitNavItemState, SplitNavItemSlots } from './SplitNavItem.types'; | ||
|
||
/** | ||
* Render the final JSX of SplitNavItem | ||
*/ | ||
export const renderSplitNavItem_unstable = (state: SplitNavItemState) => { | ||
assertSlots<SplitNavItemSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <state.root />; | ||
}; |
34 changes: 34 additions & 0 deletions
34
...react-components/react-nav-preview/library/src/components/SplitNavItem/useSplitNavItem.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 { SplitNavItemProps, SplitNavItemState } from './SplitNavItem.types'; | ||
|
||
/** | ||
* 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 => { | ||
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' }, | ||
), | ||
}; | ||
}; |
35 changes: 35 additions & 0 deletions
35
...nts/react-nav-preview/library/src/components/SplitNavItem/useSplitNavItemStyles.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,35 @@ | ||
import { makeStyles, mergeClasses } from '@griffel/react'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
import type { SplitNavItemSlots, SplitNavItemState } from './SplitNavItem.types'; | ||
|
||
export const splitNavItemClassNames: SlotClassNames<SplitNavItemSlots> = { | ||
root: 'fui-SplitNavItem', | ||
// TODO: add class names for all slots on SplitNavItemSlots. | ||
// Should be of the form `<slotName>: 'fui-SplitNavItem__<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 SplitNavItem slots based on the state | ||
*/ | ||
export const useSplitNavItemStyles_unstable = (state: SplitNavItemState): SplitNavItemState => { | ||
'use no memo'; | ||
|
||
const styles = useStyles(); | ||
state.root.className = mergeClasses(splitNavItemClassNames.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; | ||
}; |
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