-
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-dialog): scaffold DialogContent component (#24844)
* chore: scaffold DialogContent component * chore: updates API * bugfix: exports DialogSurfaceElement
- Loading branch information
1 parent
d83195c
commit cf5f5e1
Showing
17 changed files
with
203 additions
and
13 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-react-dialog-d69ce942-a1c5-4bc6-83b5-c91a69d5c2b5.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": "none", | ||
"comment": "chore: scaffold DialogContent component", | ||
"packageName": "@fluentui/react-dialog", | ||
"email": "[email protected]", | ||
"dependentChangeType": "none" | ||
} |
6 changes: 5 additions & 1 deletion
6
packages/react-components/react-dialog/config/api-extractor.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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", | ||
"extends": "@fluentui/scripts/api-extractor/api-extractor.common.v-next.json", | ||
"mainEntryPointFilePath": "<projectFolder>/dist/types/index.d.ts" | ||
"dtsRollup": { | ||
"enabled": true, | ||
"untrimmedFilePath": "", | ||
"publicTrimmedFilePath": "<projectFolder>/dist/index.d.ts" | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
packages/react-components/react-dialog/config/api-extractor.local.json
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
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/DialogContent/index'; |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-dialog/src/components/DialogContent/DialogContent.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 { DialogContent } from './DialogContent'; | ||
import { isConformant } from '../../common/isConformant'; | ||
|
||
describe('DialogContent', () => { | ||
isConformant({ | ||
Component: DialogContent, | ||
displayName: 'DialogContent', | ||
}); | ||
|
||
// TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
||
it('renders a default state', () => { | ||
const result = render(<DialogContent>Default DialogContent</DialogContent>); | ||
expect(result.container).toMatchSnapshot(); | ||
}); | ||
}); |
18 changes: 18 additions & 0 deletions
18
packages/react-components/react-dialog/src/components/DialogContent/DialogContent.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 { useDialogContent_unstable } from './useDialogContent'; | ||
import { renderDialogContent_unstable } from './renderDialogContent'; | ||
import { useDialogContentStyles_unstable } from './useDialogContentStyles'; | ||
import type { DialogContentProps } from './DialogContent.types'; | ||
import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
|
||
/** | ||
* DialogContent component - TODO: add more docs | ||
*/ | ||
export const DialogContent: ForwardRefComponent<DialogContentProps> = React.forwardRef((props, ref) => { | ||
const state = useDialogContent_unstable(props, ref); | ||
|
||
useDialogContentStyles_unstable(state); | ||
return renderDialogContent_unstable(state); | ||
}); | ||
|
||
DialogContent.displayName = 'DialogContent'; |
15 changes: 15 additions & 0 deletions
15
packages/react-components/react-dialog/src/components/DialogContent/DialogContent.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 DialogContentSlots = { | ||
root: Slot<'div'>; | ||
}; | ||
|
||
/** | ||
* DialogContent Props | ||
*/ | ||
export type DialogContentProps = ComponentProps<DialogContentSlots> & {}; | ||
|
||
/** | ||
* State used in rendering DialogContent | ||
*/ | ||
export type DialogContentState = ComponentState<DialogContentSlots>; |
11 changes: 11 additions & 0 deletions
11
...nents/react-dialog/src/components/DialogContent/__snapshots__/DialogContent.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[`DialogContent renders a default state 1`] = ` | ||
<div> | ||
<div | ||
class="fui-DialogContent" | ||
> | ||
Default DialogContent | ||
</div> | ||
</div> | ||
`; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-dialog/src/components/DialogContent/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 './DialogContent'; | ||
export * from './DialogContent.types'; | ||
export * from './renderDialogContent'; | ||
export * from './useDialogContent'; | ||
export * from './useDialogContentStyles'; |
13 changes: 13 additions & 0 deletions
13
packages/react-components/react-dialog/src/components/DialogContent/renderDialogContent.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 { DialogContentState, DialogContentSlots } from './DialogContent.types'; | ||
|
||
/** | ||
* Render the final JSX of DialogContent | ||
*/ | ||
export const renderDialogContent_unstable = (state: DialogContentState) => { | ||
const { slots, slotProps } = getSlots<DialogContentSlots>(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-dialog/src/components/DialogContent/useDialogContent.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 { DialogContentProps, DialogContentState } from './DialogContent.types'; | ||
|
||
/** | ||
* Create the state required to render DialogContent. | ||
* | ||
* The returned state can be modified with hooks such as useDialogContentStyles_unstable, | ||
* before being passed to renderDialogContent_unstable. | ||
* | ||
* @param props - props from this instance of DialogContent | ||
* @param ref - reference to root HTMLElement of DialogContent | ||
*/ | ||
export const useDialogContent_unstable = ( | ||
props: DialogContentProps, | ||
ref: React.Ref<HTMLElement>, | ||
): DialogContentState => { | ||
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-dialog/src/components/DialogContent/useDialogContentStyles.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 { DialogContentSlots, DialogContentState } from './DialogContent.types'; | ||
import type { SlotClassNames } from '@fluentui/react-utilities'; | ||
|
||
export const dialogContentClassNames: SlotClassNames<DialogContentSlots> = { | ||
root: 'fui-DialogContent', | ||
// TODO: add class names for all slots on DialogContentSlots. | ||
// Should be of the form `<slotName>: 'fui-DialogContent__<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 DialogContent slots based on the state | ||
*/ | ||
export const useDialogContentStyles_unstable = (state: DialogContentState): DialogContentState => { | ||
const styles = useStyles(); | ||
state.root.className = mergeClasses(dialogContentClassNames.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
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