-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(react-dialog): scaffold DialogContent component #24844
Merged
bsunderhus
merged 3 commits into
microsoft:master
from
bsunderhus:chore(react-dialog)--scaffold-DialogContent-compound-component
Sep 19, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a part of the updated migration generator which is when during
create-component
command