-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(react-infobutton): Add initial implementation #25247
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
Merged
Esteban Munoz Facusse (sopranopillow)
merged 15 commits into
microsoft:master
from
sopranopillow:info-button/initial-implementation
Nov 2, 2022
Merged
Changes from 4 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
29c1a87
adding initial implementation
sopranopillow eee5466
Merge branch 'master' of https://www.github.com/microsoft/fluentui in…
sopranopillow c9c76d1
fixing syncpack error
sopranopillow 3f53fd9
updating to remove v9 button
sopranopillow 75bc33b
updating implementation to new way
sopranopillow 8630172
Merge branch 'master' of https://www.github.com/microsoft/fluentui in…
sopranopillow b225c04
typos
sopranopillow 7883f2b
removing missing story
sopranopillow 381d61c
fixing syncpack error
sopranopillow 2f9aa37
convert Popover to a slot
sopranopillow 754a7f3
cleaning up types
sopranopillow e80518f
adding requested chan geS:
sopranopillow ab0e929
updating spread-radius to be a token
sopranopillow 668d364
adding requested changes
sopranopillow eebe657
fixing syncpack error
sopranopillow 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
This file contains hidden or 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 hidden or 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
3 changes: 3 additions & 0 deletions
3
...ges/react-components/react-infobutton/src/components/InfoButton/DefaultInfoButtonIcon.tsx
This file contains hidden or 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,3 @@ | ||
| import { Info12Regular, Info12Filled, bundleIcon } from '@fluentui/react-icons'; | ||
|
|
||
| export const DefaultInfoButtonIcon = bundleIcon(Info12Filled, Info12Regular); |
52 changes: 43 additions & 9 deletions
52
packages/react-components/react-infobutton/src/components/InfoButton/InfoButton.test.tsx
This file contains hidden or 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,52 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { InfoButton } from './InfoButton'; | ||
| import { isConformant } from '../../common/isConformant'; | ||
| import { infoButtonClassNames } from './useInfoButtonStyles'; | ||
| import { RenderResult } from '@testing-library/react'; | ||
|
|
||
| // testing-library's queryByRole function doesn't look inside portals | ||
| function queryByRoleDialog(result: RenderResult) { | ||
| const dialogs = result.baseElement.querySelectorAll('*[role="dialog"]'); | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
| if (!dialogs?.length) { | ||
| return null; | ||
| } else { | ||
| expect(dialogs.length).toBe(1); | ||
| return dialogs.item(0) as HTMLElement; | ||
| } | ||
| } | ||
|
|
||
| const getPopoverSurfaceElement = (result: RenderResult) => { | ||
| // button needs to be clicked otherwise content won't be rendered. | ||
| result.getByRole('button').click(); | ||
| const dialog = queryByRoleDialog(result); | ||
| expect(dialog).not.toBeNull(); | ||
| return dialog!; | ||
| }; | ||
|
|
||
| describe('InfoButton', () => { | ||
| isConformant({ | ||
| Component: InfoButton, | ||
| displayName: 'InfoButton', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<InfoButton>Default InfoButton</InfoButton>); | ||
| expect(result.container).toMatchSnapshot(); | ||
| requiredProps: { | ||
| content: 'Popover content', | ||
| }, | ||
| disabledTests: [ | ||
| 'component-handles-ref', | ||
| 'component-has-root-ref', | ||
| 'component-handles-classname', | ||
| 'make-styles-overrides-win', | ||
| ], | ||
| testOptions: { | ||
| 'has-static-classnames': [ | ||
| { | ||
| props: {}, | ||
| expectedClassNames: { | ||
| // root shouldn't be expected since the root is a Popover | ||
| button: infoButtonClassNames.button, | ||
| content: infoButtonClassNames.content, | ||
| }, | ||
| getPortalElement: getPopoverSurfaceElement, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
| }); | ||
This file contains hidden or 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
19 changes: 16 additions & 3 deletions
19
packages/react-components/react-infobutton/src/components/InfoButton/InfoButton.types.ts
This file contains hidden or 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,15 +1,28 @@ | ||
| import type { PopoverProps, PopoverSurface } from '@fluentui/react-popover'; | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
|
|
||
| export type InfoButtonSlots = { | ||
| root: Slot<'div'>; | ||
| root: NonNullable<Slot<PopoverProps>>; | ||
|
|
||
| /** | ||
| * The button that triggers the Popover. | ||
| */ | ||
| button: NonNullable<Slot<'button'>>; | ||
|
|
||
| /** | ||
| * The content to be displayed in the Popover. | ||
| */ | ||
| content: NonNullable<Slot<typeof PopoverSurface>>; | ||
| }; | ||
|
|
||
| /** | ||
| * InfoButton Props | ||
| */ | ||
| export type InfoButtonProps = ComponentProps<InfoButtonSlots> & {}; | ||
| export type InfoButtonProps = Omit<ComponentProps<Partial<InfoButtonSlots>>, 'children'>; | ||
|
sopranopillow marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * State used in rendering InfoButton | ||
| */ | ||
| export type InfoButtonState = ComponentState<InfoButtonSlots>; | ||
| export type InfoButtonState = ComponentState<InfoButtonSlots> & { | ||
| popoverOpen: boolean; | ||
| }; | ||
11 changes: 0 additions & 11 deletions
11
...ponents/react-infobutton/src/components/InfoButton/__snapshots__/InfoButton.test.tsx.snap
This file was deleted.
Oops, something went wrong.
11 changes: 9 additions & 2 deletions
11
packages/react-components/react-infobutton/src/components/InfoButton/renderInfoButton.tsx
This file contains hidden or 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,13 +1,20 @@ | ||
| import * as React from 'react'; | ||
| import { getSlots } from '@fluentui/react-utilities'; | ||
| import type { InfoButtonState, InfoButtonSlots } from './InfoButton.types'; | ||
| import { PopoverProps, PopoverTrigger } from '@fluentui/react-popover'; | ||
|
|
||
| /** | ||
| * Render the final JSX of InfoButton | ||
| */ | ||
| export const renderInfoButton_unstable = (state: InfoButtonState) => { | ||
| const { slots, slotProps } = getSlots<InfoButtonSlots>(state); | ||
|
|
||
| // TODO Add additional slots in the appropriate place | ||
| return <slots.root {...slotProps.root} />; | ||
| return ( | ||
| <slots.root {...(slotProps.root as PopoverProps)}> | ||
| <PopoverTrigger> | ||
| <slots.button {...slotProps.button} /> | ||
| </PopoverTrigger> | ||
| <slots.content {...slotProps.content} /> | ||
| </slots.root> | ||
| ); | ||
| }; |
28 changes: 0 additions & 28 deletions
28
packages/react-components/react-infobutton/src/components/InfoButton/useInfoButton.ts
This file was deleted.
Oops, something went wrong.
60 changes: 60 additions & 0 deletions
60
packages/react-components/react-infobutton/src/components/InfoButton/useInfoButton.tsx
This file contains hidden or 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,60 @@ | ||
| import * as React from 'react'; | ||
| import { DefaultInfoButtonIcon } from './DefaultInfoButtonIcon'; | ||
| import { OnOpenChangeData, OpenPopoverEvents, Popover, PopoverSurface } from '@fluentui/react-popover'; | ||
| import { resolveShorthand } from '@fluentui/react-utilities'; | ||
| import { useControllableState } from '@fluentui/react-utilities'; | ||
| import type { InfoButtonProps, InfoButtonState } from './InfoButton.types'; | ||
|
|
||
| /** | ||
| * Create the state required to render InfoButton. | ||
| * | ||
| * The returned state can be modified with hooks such as useInfoButtonStyles_unstable, | ||
| * before being passed to renderInfoButton_unstable. | ||
| * | ||
| * @param props - props from this instance of InfoButton | ||
| */ | ||
| export const useInfoButton_unstable = (props: InfoButtonProps): InfoButtonState => { | ||
| const [popoverOpen, setPopoverOpen] = useControllableState({ | ||
| state: props.open, | ||
| defaultState: props.defaultOpen, | ||
| initialState: false, | ||
| }); | ||
|
|
||
| const handleOnPopoverChange = (e: OpenPopoverEvents, data: OnOpenChangeData) => { | ||
| props.onOpenChange?.(e, data); | ||
| setPopoverOpen(data.open); | ||
| }; | ||
|
|
||
| return { | ||
| popoverOpen, | ||
|
|
||
| components: { | ||
| root: Popover, | ||
| button: 'button', | ||
| content: PopoverSurface, | ||
| }, | ||
|
|
||
| root: { | ||
| children: <></>, | ||
| size: 'small', | ||
| withArrow: true, | ||
| positioning: 'above-start', | ||
| ...props, | ||
| open: popoverOpen, | ||
| onOpenChange: handleOnPopoverChange, | ||
| }, | ||
| content: resolveShorthand(props.content, { | ||
| required: true, | ||
| defaultProps: { | ||
| role: 'dialog', | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Popover requires an aria-label, this will be added in the future. |
||
| }, | ||
| }), | ||
| button: resolveShorthand(props.button, { | ||
| required: true, | ||
| defaultProps: { | ||
| children: <DefaultInfoButtonIcon />, | ||
| type: 'button', | ||
| }, | ||
| }), | ||
| }; | ||
| }; | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.