-
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.
chore:(react-nav-preview) Scaffold AppItem (#32088)
- Loading branch information
Showing
36 changed files
with
357 additions
and
116 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-nav-preview-19bf0a36-ee5b-4bec-8be9-b195b29bc9a7.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": "Adds AppItem and AppItemStatic, removes AppNode", | ||
"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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-nav-preview/library/src/AppItem.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/AppItem/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-nav-preview/library/src/AppItemStatic.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/AppItemStatic/index'; |
1 change: 0 additions & 1 deletion
1
packages/react-components/react-nav-preview/library/src/AppNode.ts
This file was deleted.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
...y/src/components/AppNode/AppNode.test.tsx → ...y/src/components/AppItem/AppItem.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,18 @@ | ||
import * as React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
import { AppNode } from './AppNode'; | ||
import { AppItem } from './AppItem'; | ||
|
||
describe('AppNode', () => { | ||
describe('AppItem', () => { | ||
isConformant({ | ||
Component: AppNode, | ||
displayName: 'AppNode', | ||
Component: AppItem, | ||
displayName: 'AppItem', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<AppNode>Default AppNode</AppNode>); | ||
const result = render(<AppItem>Default AppItem</AppItem>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
packages/react-components/react-nav-preview/library/src/components/AppItem/AppItem.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 { useAppItem_unstable } from './useAppItem'; | ||
import { renderAppItem_unstable } from './renderAppItem'; | ||
import { useAppItemStyles_unstable } from './useAppItemStyles.styles'; | ||
import type { AppItemProps } from './AppItem.types'; | ||
|
||
/** | ||
* AppItem component - TODO: add more docs | ||
*/ | ||
export const AppItem: ForwardRefComponent<AppItemProps> = React.forwardRef((props, ref) => { | ||
const state = useAppItem_unstable(props, ref); | ||
|
||
useAppItemStyles_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('useAppItemStyles_unstable')(state); | ||
|
||
return renderAppItem_unstable(state); | ||
}); | ||
|
||
AppItem.displayName = 'AppItem'; |
17 changes: 17 additions & 0 deletions
17
packages/react-components/react-nav-preview/library/src/components/AppItem/AppItem.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 AppItemSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* AppItem Props | ||
*/ | ||
export type AppItemProps = ComponentProps<AppItemSlots> & {}; | ||
|
||
/** | ||
* State used in rendering AppItem | ||
*/ | ||
export type AppItemState = ComponentState<AppItemSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from AppItemProps. | ||
// & Required<Pick<AppItemProps, 'propName'>> |
11 changes: 11 additions & 0 deletions
11
...ents/react-nav-preview/library/src/components/AppItem/__snapshots__/AppItem.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[`AppItem renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-AppItem" | ||
> | ||
Default AppItem | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-nav-preview/library/src/components/AppItem/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 './AppItem'; | ||
export * from './AppItem.types'; | ||
export * from './renderAppItem'; | ||
export * from './useAppItem'; | ||
export * from './useAppItemStyles.styles'; |
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
14 changes: 7 additions & 7 deletions
14
...rary/src/components/AppNode/useAppNode.ts → ...rary/src/components/AppItem/useAppItem.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
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
18 changes: 18 additions & 0 deletions
18
...-components/react-nav-preview/library/src/components/AppItemStatic/AppItemStatic.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 { AppItemStatic } from './AppItemStatic'; | ||
|
||
describe('AppItemStatic', () => { | ||
isConformant({ | ||
Component: AppItemStatic, | ||
displayName: 'AppItemStatic', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<AppItemStatic>Default AppItemStatic</AppItemStatic>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
...react-components/react-nav-preview/library/src/components/AppItemStatic/AppItemStatic.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 { useAppItemStatic_unstable } from './useAppItemStatic'; | ||
import { renderAppItemStatic_unstable } from './renderAppItemStatic'; | ||
import { useAppItemStaticStyles_unstable } from './useAppItemStaticStyles.styles'; | ||
import type { AppItemStaticProps } from './AppItemStatic.types'; | ||
|
||
/** | ||
* AppItemStatic component - TODO: add more docs | ||
*/ | ||
export const AppItemStatic: ForwardRefComponent<AppItemStaticProps> = React.forwardRef((props, ref) => { | ||
const state = useAppItemStatic_unstable(props, ref); | ||
|
||
useAppItemStaticStyles_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('useAppItemStaticStyles_unstable')(state); | ||
|
||
return renderAppItemStatic_unstable(state); | ||
}); | ||
|
||
AppItemStatic.displayName = 'AppItemStatic'; |
17 changes: 17 additions & 0 deletions
17
...-components/react-nav-preview/library/src/components/AppItemStatic/AppItemStatic.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 AppItemStaticSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* AppItemStatic Props | ||
*/ | ||
export type AppItemStaticProps = ComponentProps<AppItemStaticSlots> & {}; | ||
|
||
/** | ||
* State used in rendering AppItemStatic | ||
*/ | ||
export type AppItemStaticState = ComponentState<AppItemStaticSlots>; | ||
// TODO: Remove semicolon from previous line, uncomment next line, and provide union of props to pick from AppItemStaticProps. | ||
// & Required<Pick<AppItemStaticProps, 'propName'>> |
11 changes: 11 additions & 0 deletions
11
...av-preview/library/src/components/AppItemStatic/__snapshots__/AppItemStatic.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[`AppItemStatic renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-AppItemStatic" | ||
> | ||
Default AppItemStatic | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-nav-preview/library/src/components/AppItemStatic/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 './AppItemStatic'; | ||
export * from './AppItemStatic.types'; | ||
export * from './renderAppItemStatic'; | ||
export * from './useAppItemStatic'; | ||
export * from './useAppItemStaticStyles.styles'; |
15 changes: 15 additions & 0 deletions
15
...components/react-nav-preview/library/src/components/AppItemStatic/renderAppItemStatic.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 { AppItemStaticState, AppItemStaticSlots } from './AppItemStatic.types'; | ||
|
||
/** | ||
* Render the final JSX of AppItemStatic | ||
*/ | ||
export const renderAppItemStatic_unstable = (state: AppItemStaticState) => { | ||
assertSlots<AppItemStaticSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <state.root />; | ||
}; |
34 changes: 34 additions & 0 deletions
34
...act-components/react-nav-preview/library/src/components/AppItemStatic/useAppItemStatic.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 { AppItemStaticProps, AppItemStaticState } from './AppItemStatic.types'; | ||
|
||
/** | ||
* Create the state required to render AppItemStatic. | ||
* | ||
* The returned state can be modified with hooks such as useAppItemStaticStyles_unstable, | ||
* before being passed to renderAppItemStatic_unstable. | ||
* | ||
* @param props - props from this instance of AppItemStatic | ||
* @param ref - reference to root HTMLDivElement of AppItemStatic | ||
*/ | ||
export const useAppItemStatic_unstable = ( | ||
props: AppItemStaticProps, | ||
ref: React.Ref<HTMLDivElement>, | ||
): AppItemStaticState => { | ||
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.