-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Implement motion for MessageBar #29339
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
ling1726
merged 7 commits into
microsoft:master
from
ling1726:react-message-bar/feat/motion
Oct 2, 2023
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d5f5f6c
feat: Implement motion for MessageBar
ling1726 18b81d2
Add MessageBarGroup
ling1726 f50e4ac
remove TODO
ling1726 f967a9d
update package versions
ling1726 132b7b1
address issues
ling1726 f0e7151
avoid findDOMNode
ling1726 7884909
pass nodeRef through context
ling1726 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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-message-bar-preview/src/MessageBarGroup.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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export * from './components/MessageBarGroup/index'; |
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
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
22 changes: 22 additions & 0 deletions
22
...ponents/react-message-bar-preview/src/components/MessageBarGroup/MessageBarGroup.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 |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
| import { MessageBarGroup } from './MessageBarGroup'; | ||
|
|
||
| describe('MessageBarGroup', () => { | ||
| isConformant({ | ||
| Component: MessageBarGroup, | ||
| displayName: 'MessageBarGroup', | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render( | ||
| <MessageBarGroup> | ||
| <span>Default MessageBarGroup</span> | ||
| </MessageBarGroup>, | ||
| ); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
18 changes: 18 additions & 0 deletions
18
...t-components/react-message-bar-preview/src/components/MessageBarGroup/MessageBarGroup.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,18 @@ | ||
| import * as React from 'react'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import { useMessageBarGroup_unstable } from './useMessageBarGroup'; | ||
| import { renderMessageBarGroup_unstable } from './renderMessageBarGroup'; | ||
| import { useMessageBarGroupStyles_unstable } from './useMessageBarGroupStyles.styles'; | ||
| import type { MessageBarGroupProps } from './MessageBarGroup.types'; | ||
|
|
||
| /** | ||
| * MessageBarGroup component | ||
| */ | ||
| export const MessageBarGroup: ForwardRefComponent<MessageBarGroupProps> = React.forwardRef((props, ref) => { | ||
| const state = useMessageBarGroup_unstable(props, ref); | ||
|
|
||
| useMessageBarGroupStyles_unstable(state); | ||
| return renderMessageBarGroup_unstable(state); | ||
| }); | ||
|
|
||
| MessageBarGroup.displayName = 'MessageBarGroup'; |
24 changes: 24 additions & 0 deletions
24
...ponents/react-message-bar-preview/src/components/MessageBarGroup/MessageBarGroup.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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import * as React from 'react'; | ||
|
|
||
| export type MessageBarGroupSlots = { | ||
| root: Slot<'div'>; | ||
| }; | ||
|
|
||
| /** | ||
| * MessageBarGroup Props | ||
| */ | ||
| export type MessageBarGroupProps = ComponentProps<MessageBarGroupSlots> & { | ||
| children: React.ReactElement[] | React.ReactElement; | ||
| animate?: 'exit-only' | 'both'; | ||
| }; | ||
|
|
||
| /** | ||
| * State used in rendering MessageBarGroup | ||
| */ | ||
| export type MessageBarGroupState = ComponentState<MessageBarGroupSlots> & | ||
| Pick<MessageBarGroupProps, 'animate'> & { | ||
| enterStyles: string; | ||
| exitStyles: string; | ||
| children: React.ReactElement[]; | ||
| }; |
41 changes: 41 additions & 0 deletions
41
...ponents/react-message-bar-preview/src/components/MessageBarGroup/MessageBarTransition.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,41 @@ | ||
| import * as React from 'react'; | ||
| import { Transition, TransitionStatus } from 'react-transition-group'; | ||
| import { MessageBarTransitionContextProvider } from '../../contexts/messageBarTransitionContext'; | ||
| import { MessageBarGroupProps } from './MessageBarGroup.types'; | ||
|
|
||
| const getClassName = ( | ||
| status: TransitionStatus, | ||
| enterClassName: string, | ||
| exitClassName: string, | ||
| animate: MessageBarGroupProps['animate'], | ||
| ) => { | ||
| switch (status) { | ||
| case 'entering': | ||
| case 'entered': | ||
| return animate === 'both' ? enterClassName : ''; | ||
| case 'exiting': | ||
| case 'exited': | ||
| return exitClassName; | ||
| } | ||
| }; | ||
|
|
||
| /** | ||
| * Internal component that controls the animation transition for MessageBar components | ||
| * @internal | ||
| */ | ||
| export const MessageBarTransition: React.FC<{ | ||
| children: React.ReactNode; | ||
| enterClassName: string; | ||
| exitClassName: string; | ||
| animate: MessageBarGroupProps['animate']; | ||
| }> = ({ children, enterClassName, exitClassName, animate, ...rest }) => { | ||
| return ( | ||
| <Transition timeout={250} {...rest}> | ||
|
ling1726 marked this conversation as resolved.
Outdated
|
||
| {state => ( | ||
| <MessageBarTransitionContextProvider value={getClassName(state, enterClassName, exitClassName, animate)}> | ||
| {children} | ||
| </MessageBarTransitionContextProvider> | ||
| )} | ||
| </Transition> | ||
| ); | ||
| }; | ||
13 changes: 13 additions & 0 deletions
13
...ge-bar-preview/src/components/MessageBarGroup/__snapshots__/MessageBarGroup.test.tsx.snap
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,13 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`MessageBarGroup renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-MessageBarGroup" | ||
| > | ||
| <span> | ||
| Default MessageBarGroup | ||
| </span> | ||
| </div> | ||
| </div> | ||
| `; |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-message-bar-preview/src/components/MessageBarGroup/index.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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export * from './MessageBarGroup'; | ||
| export * from './MessageBarGroup.types'; | ||
| export * from './renderMessageBarGroup'; | ||
| export * from './useMessageBarGroup'; | ||
| export * from './useMessageBarGroupStyles.styles'; |
31 changes: 31 additions & 0 deletions
31
...onents/react-message-bar-preview/src/components/MessageBarGroup/renderMessageBarGroup.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,31 @@ | ||
| /** @jsxRuntime automatic */ | ||
| /** @jsxImportSource @fluentui/react-jsx-runtime */ | ||
|
|
||
| import { assertSlots } from '@fluentui/react-utilities'; | ||
| import type { MessageBarGroupState, MessageBarGroupSlots } from './MessageBarGroup.types'; | ||
| import { TransitionGroup } from 'react-transition-group'; | ||
| import { MessageBarTransition } from './MessageBarTransition'; | ||
|
|
||
| /** | ||
| * Render the final JSX of MessageBarGroup | ||
| */ | ||
| export const renderMessageBarGroup_unstable = (state: MessageBarGroupState) => { | ||
| assertSlots<MessageBarGroupSlots>(state); | ||
|
|
||
| return ( | ||
| <state.root> | ||
| <TransitionGroup component={null}> | ||
| {state.children.map(child => ( | ||
| <MessageBarTransition | ||
| animate={state.animate} | ||
| key={child.key} | ||
| enterClassName={state.enterStyles} | ||
| exitClassName={state.exitStyles} | ||
| > | ||
| {child} | ||
| </MessageBarTransition> | ||
| ))} | ||
| </TransitionGroup> | ||
| </state.root> | ||
| ); | ||
| }; |
47 changes: 47 additions & 0 deletions
47
...components/react-message-bar-preview/src/components/MessageBarGroup/useMessageBarGroup.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 |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import * as React from 'react'; | ||
| import type { MessageBarGroupProps, MessageBarGroupState } from './MessageBarGroup.types'; | ||
| import { getNativeElementProps, slot } from '@fluentui/react-utilities'; | ||
|
|
||
| /** | ||
| * Create the state required to render MessageBarGroup. | ||
| * | ||
| * The returned state can be modified with hooks such as useMessageBarGroupStyles_unstable, | ||
| * before being passed to renderMessageBarGroup_unstable. | ||
| * | ||
| * @param props - props from this instance of MessageBarGroup | ||
| * @param ref - reference to root HTMLElement of MessageBarGroup | ||
| */ | ||
| export const useMessageBarGroup_unstable = ( | ||
| props: MessageBarGroupProps, | ||
| ref: React.Ref<HTMLElement>, | ||
| ): MessageBarGroupState => { | ||
| if (process.env.NODE_ENV !== 'production') { | ||
| React.Children.forEach(props.children, c => { | ||
| if (!React.isValidElement(c) || c.type === React.Fragment) { | ||
| throw new Error( | ||
| "MessageBarGroup: children must be valid React elements. Please ensure you're not using fragments. ", | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| const children = React.Children.map(props.children ?? [], c => (React.isValidElement(c) ? c : null)); | ||
|
|
||
| return { | ||
| components: { | ||
| root: 'div', | ||
| }, | ||
|
|
||
| root: slot.always( | ||
| getNativeElementProps('div', { | ||
| ref, | ||
| ...props, | ||
| }), | ||
| { elementType: 'div' }, | ||
| ), | ||
| children, | ||
| animate: props.animate ?? 'exit-only', | ||
| enterStyles: '', | ||
| exitStyles: '', | ||
| }; | ||
| }; |
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.