-
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.
chore(react-tree): scaffold TreeItemLayout
+ export composition methods
- Loading branch information
1 parent
0df4721
commit b8d9075
Showing
11 changed files
with
206 additions
and
2 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/TreeItemLayout/index'; |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-tree/src/components/TreeItemLayout/TreeItemLayout.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 { TreeItemLayout } from './TreeItemLayout'; | ||
import { isConformant } from '../../testing/isConformant'; | ||
|
||
describe('TreeItemLayout', () => { | ||
isConformant({ | ||
Component: TreeItemLayout, | ||
displayName: 'TreeItemLayout', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<TreeItemLayout>Default TreeItemLayout</TreeItemLayout>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-tree/src/components/TreeItemLayout/TreeItemLayout.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 { useTreeItemLayout_unstable } from './useTreeItemLayout'; | ||
import { renderTreeItemLayout_unstable } from './renderTreeItemLayout'; | ||
import { useTreeItemLayoutStyles_unstable } from './useTreeItemLayoutStyles'; | ||
import type { TreeItemLayoutProps } from './TreeItemLayout.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* TreeItemLayout component - TODO: add more docs | ||
*/ | ||
export const TreeItemLayout: ForwardRefComponent<TreeItemLayoutProps> = React.forwardRef((props, ref) => { | ||
const state = useTreeItemLayout_unstable(props, ref); | ||
|
||
useTreeItemLayoutStyles_unstable(state); | ||
return renderTreeItemLayout_unstable(state); | ||
}); | ||
|
||
TreeItemLayout.displayName = 'TreeItemLayout'; |
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-tree/src/components/TreeItemLayout/TreeItemLayout.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,15 @@ | ||
import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
||
export type TreeItemLayoutSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* TreeItemLayout Props | ||
*/ | ||
export type TreeItemLayoutProps = ComponentProps<TreeItemLayoutSlots>; | ||
|
||
/** | ||
* State used in rendering TreeItemLayout | ||
*/ | ||
export type TreeItemLayoutState = ComponentState<TreeItemLayoutSlots>; |
11 changes: 11 additions & 0 deletions
11
...nents/react-tree/src/components/TreeItemLayout/__snapshots__/TreeItemLayout.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[`TreeItemLayout renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-TreeItemLayout" | ||
> | ||
Default TreeItemLayout | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-tree/src/components/TreeItemLayout/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 './TreeItemLayout'; | ||
export * from './TreeItemLayout.types'; | ||
export * from './renderTreeItemLayout'; | ||
export * from './useTreeItemLayout'; | ||
export * from './useTreeItemLayoutStyles'; |
13 changes: 13 additions & 0 deletions
13
packages/react-components/react-tree/src/components/TreeItemLayout/renderTreeItemLayout.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,13 @@ | ||
import * as React from 'react'; | ||
import { getSlots } from '@fluentui/react-utilities'; | ||
import type { TreeItemLayoutState, TreeItemLayoutSlots } from './TreeItemLayout.types'; | ||
|
||
/** | ||
* Render the final JSX of TreeItemLayout | ||
*/ | ||
export const renderTreeItemLayout_unstable = (state: TreeItemLayoutState) => { | ||
const { slots, slotProps } = getSlots<TreeItemLayoutSlots>(state); | ||
|
||
// TODO Add additional slots in the appropriate place | ||
return <slots.root {...slotProps.root} />; | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/react-components/react-tree/src/components/TreeItemLayout/useTreeItemLayout.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 { getNativeElementProps } from '@fluentui/react-utilities'; | ||
import type { TreeItemLayoutProps, TreeItemLayoutState } from './TreeItemLayout.types'; | ||
|
||
/** | ||
* Create the state required to render TreeItemLayout. | ||
* | ||
* The returned state can be modified with hooks such as useTreeItemLayoutStyles_unstable, | ||
* before being passed to renderTreeItemLayout_unstable. | ||
* | ||
* @param props - props from this instance of TreeItemLayout | ||
* @param ref - reference to root HTMLElement of TreeItemLayout | ||
*/ | ||
export const useTreeItemLayout_unstable = ( | ||
props: TreeItemLayoutProps, | ||
ref: React.Ref<HTMLElement>, | ||
): TreeItemLayoutState => { | ||
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: getNativeElementProps('div', { | ||
ref, | ||
...props, | ||
}), | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
...ages/react-components/react-tree/src/components/TreeItemLayout/useTreeItemLayoutStyles.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 { TreeItemLayoutSlots, TreeItemLayoutState } from './TreeItemLayout.types'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
||
export const treeItemLayoutClassNames: SlotClassNames<TreeItemLayoutSlots> = { | ||
root: 'fui-TreeItemLayout', | ||
// TODO: add class names for all slots on TreeItemLayoutSlots. | ||
// Should be of the form `<slotName>: 'fui-TreeItemLayout__<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 TreeItemLayout slots based on the state | ||
*/ | ||
export const useTreeItemLayoutStyles_unstable = (state: TreeItemLayoutState): TreeItemLayoutState => { | ||
const styles = useStyles(); | ||
state.root.className = mergeClasses(treeItemLayoutClassNames.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,22 @@ | ||
export { Tree, treeClassNames } from './Tree'; | ||
export { Tree, treeClassNames, renderTree_unstable, useTreeStyles_unstable, useTree_unstable } from './Tree'; | ||
export type { TreeProps, TreeState, TreeSlots } from './Tree'; | ||
|
||
export { TreeItem, treeItemClassNames } from './TreeItem'; | ||
export { | ||
TreeItem, | ||
treeItemClassNames, | ||
renderTreeItem_unstable, | ||
useTreeItemStyles_unstable, | ||
useTreeItem_unstable, | ||
} from './TreeItem'; | ||
export type { TreeItemProps, TreeItemState, TreeItemSlots } from './TreeItem'; | ||
|
||
export type { TreeContextValue, useTreeContext_unstable, TreeProvider } from './contexts'; | ||
|
||
export { | ||
TreeItemLayout, | ||
treeItemLayoutClassNames, | ||
renderTreeItemLayout_unstable, | ||
useTreeItemLayoutStyles_unstable, | ||
useTreeItemLayout_unstable, | ||
} from './TreeItemLayout'; | ||
export type { TreeItemLayoutProps, TreeItemLayoutState, TreeItemLayoutSlots } from './TreeItemLayout'; |