-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(MessageBar): Initial implementation #29313
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 16 commits into
microsoft:master
from
ling1726:react-message-bar/feat/initial-implementation
Sep 28, 2023
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
102759c
feat: Initial implementation
ling1726 35d1189
resolve conflict
ling1726 a75a536
remove TODOs
ling1726 aeacd98
fix multiline alignment
ling1726 cf9c216
fix slot type misalign
ling1726 b482283
fix tests
ling1726 91ffc5e
rename to secondaryActions
ling1726 824404f
fix warnings
ling1726 dbc3145
break out into components
ling1726 0c03bfa
remove stories
ling1726 038781d
revert tsconfig changes
ling1726 47d8d31
Merge remote-tracking branch 'origin/master' into react-message-bar/f…
ling1726 c58ee70
remove outdated keyborg cypress test
ling1726 823248d
add keyborg test again
ling1726 e328ff0
add tsconfig paths to cypress
ling1726 eaca078
Merge remote-tracking branch 'origin/master' into react-message-bar/f…
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/MessageBar.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/MessageBar/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-message-bar-preview/src/MessageBarActions.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/MessageBarActions/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-message-bar-preview/src/MessageBarBody.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/MessageBarBody/index'; |
1 change: 1 addition & 0 deletions
1
packages/react-components/react-message-bar-preview/src/MessageBarTitle.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/MessageBarTitle/index'; |
27 changes: 27 additions & 0 deletions
27
.../react-components/react-message-bar-preview/src/components/MessageBar/MessageBar.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,27 @@ | ||
| import * as React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import { isConformant } from '../../testing/isConformant'; | ||
| import { MessageBar } from './MessageBar'; | ||
|
|
||
| describe('MessageBar', () => { | ||
| isConformant({ | ||
| Component: MessageBar, | ||
| displayName: 'MessageBar', | ||
| testOptions: { | ||
| 'has-static-classnames': [ | ||
| { | ||
| props: { | ||
| icon: 'Icon', | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| // TODO add more tests here, and create visual regression tests in /apps/vr-tests | ||
|
|
||
| it('renders a default state', () => { | ||
| const result = render(<MessageBar>Default MessageBar</MessageBar>); | ||
| expect(result.container).toMatchSnapshot(); | ||
| }); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
packages/react-components/react-message-bar-preview/src/components/MessageBar/MessageBar.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,19 @@ | ||
| import * as React from 'react'; | ||
| import type { ForwardRefComponent } from '@fluentui/react-utilities'; | ||
| import { useMessageBar_unstable } from './useMessageBar'; | ||
| import { renderMessageBar_unstable } from './renderMessageBar'; | ||
| import { useMessageBarStyles_unstable } from './useMessageBarStyles.styles'; | ||
| import type { MessageBarProps } from './MessageBar.types'; | ||
| import { useMessageBarContextValue_unstable } from './useMessageBarContextValues'; | ||
|
|
||
| /** | ||
| * MessageBar component | ||
| */ | ||
| export const MessageBar: ForwardRefComponent<MessageBarProps> = React.forwardRef((props, ref) => { | ||
| const state = useMessageBar_unstable(props, ref); | ||
|
|
||
| useMessageBarStyles_unstable(state); | ||
| return renderMessageBar_unstable(state, useMessageBarContextValue_unstable(state)); | ||
| }); | ||
|
|
||
| MessageBar.displayName = 'MessageBar'; |
25 changes: 25 additions & 0 deletions
25
.../react-components/react-message-bar-preview/src/components/MessageBar/MessageBar.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,25 @@ | ||
| import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities'; | ||
| import { MessageBarContextValue } from '../../contexts/messageBarContext'; | ||
|
|
||
| export type MessageBarSlots = { | ||
| root: Slot<'div'>; | ||
| icon?: Slot<'div'>; | ||
| }; | ||
|
|
||
| export type MessageBarContextValues = { | ||
| messageBar: MessageBarContextValue; | ||
| }; | ||
|
|
||
| /** | ||
| * MessageBar Props | ||
| */ | ||
| export type MessageBarProps = ComponentProps<MessageBarSlots> & | ||
| Pick<MessageBarContextValue, 'layout'> & { | ||
| multiline?: boolean; | ||
| intent?: 'info' | 'success' | 'warning' | 'error'; | ||
| }; | ||
|
|
||
| /** | ||
| * State used in rendering MessageBar | ||
| */ | ||
| export type MessageBarState = ComponentState<MessageBarSlots> & Required<Pick<MessageBarProps, 'layout' | 'intent'>>; | ||
29 changes: 29 additions & 0 deletions
29
...eact-message-bar-preview/src/components/MessageBar/__snapshots__/MessageBar.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,29 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`MessageBar renders a default state 1`] = ` | ||
| <div> | ||
| <div | ||
| class="fui-MessageBar" | ||
| > | ||
| <div | ||
| class="fui-MessageBar__icon" | ||
| > | ||
| <svg | ||
| aria-hidden="true" | ||
| class="" | ||
| fill="currentColor" | ||
| height="1em" | ||
| viewBox="0 0 20 20" | ||
| width="1em" | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| > | ||
| <path | ||
| d="M18 10a8 8 0 1 0-16 0 8 8 0 0 0 16 0ZM9.5 8.91a.5.5 0 0 1 1 0V13.6a.5.5 0 0 1-1 0V8.9Zm-.25-2.16a.75.75 0 1 1 1.5 0 .75.75 0 0 1-1.5 0Z" | ||
| fill="currentColor" | ||
| /> | ||
| </svg> | ||
| </div> | ||
| Default MessageBar | ||
| </div> | ||
| </div> | ||
| `; |
19 changes: 19 additions & 0 deletions
19
...es/react-components/react-message-bar-preview/src/components/MessageBar/getIntentIcon.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,19 @@ | ||
| import * as React from 'react'; | ||
| import { MessageBarProps } from './MessageBar.types'; | ||
| import { CheckmarkCircleFilled, InfoFilled, WarningFilled, ErrorCircleFilled } from '@fluentui/react-icons'; | ||
|
|
||
| export function getIntentIcon(intent: MessageBarProps['intent']) { | ||
| switch (intent) { | ||
| case 'info': | ||
| return <InfoFilled />; | ||
| case 'warning': | ||
| return <WarningFilled />; | ||
| case 'error': | ||
| return <ErrorCircleFilled />; | ||
| case 'success': | ||
| return <CheckmarkCircleFilled />; | ||
|
|
||
| default: | ||
| return null; | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/react-components/react-message-bar-preview/src/components/MessageBar/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 './MessageBar'; | ||
| export * from './MessageBar.types'; | ||
| export * from './renderMessageBar'; | ||
| export * from './useMessageBar'; | ||
| export * from './useMessageBarStyles.styles'; |
22 changes: 22 additions & 0 deletions
22
...react-components/react-message-bar-preview/src/components/MessageBar/renderMessageBar.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 @@ | ||
| /** @jsxRuntime automatic */ | ||
| /** @jsxImportSource @fluentui/react-jsx-runtime */ | ||
|
|
||
| import { assertSlots } from '@fluentui/react-utilities'; | ||
| import type { MessageBarState, MessageBarSlots, MessageBarContextValues } from './MessageBar.types'; | ||
| import { MessageBarContextProvider } from '../../contexts/messageBarContext'; | ||
|
|
||
| /** | ||
| * Render the final JSX of MessageBar | ||
| */ | ||
| export const renderMessageBar_unstable = (state: MessageBarState, contexts: MessageBarContextValues) => { | ||
| assertSlots<MessageBarSlots>(state); | ||
|
|
||
| return ( | ||
| <MessageBarContextProvider value={contexts.messageBar}> | ||
| <state.root> | ||
| {state.icon && <state.icon />} | ||
| {state.root.children} | ||
| </state.root> | ||
| </MessageBarContextProvider> | ||
| ); | ||
| }; |
39 changes: 39 additions & 0 deletions
39
...ges/react-components/react-message-bar-preview/src/components/MessageBar/useMessageBar.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,39 @@ | ||
| import * as React from 'react'; | ||
| import { getNativeElementProps, slot } from '@fluentui/react-utilities'; | ||
| import type { MessageBarProps, MessageBarState } from './MessageBar.types'; | ||
| import { getIntentIcon } from './getIntentIcon'; | ||
|
|
||
| /** | ||
| * Create the state required to render MessageBar. | ||
| * | ||
| * The returned state can be modified with hooks such as useMessageBarStyles_unstable, | ||
| * before being passed to renderMessageBar_unstable. | ||
| * | ||
| * @param props - props from this instance of MessageBar | ||
| * @param ref - reference to root HTMLElement of MessageBar | ||
| */ | ||
| export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HTMLElement>): MessageBarState => { | ||
| const { layout = 'singleline', intent = 'info' } = props; | ||
|
|
||
| return { | ||
| components: { | ||
| root: 'div', | ||
| icon: 'div', | ||
| }, | ||
| root: slot.always( | ||
| getNativeElementProps('div', { | ||
| ref, | ||
| ...props, | ||
| }), | ||
| { elementType: 'div' }, | ||
| ), | ||
|
|
||
| icon: slot.optional(props.icon, { | ||
| renderByDefault: true, | ||
| elementType: 'div', | ||
| defaultProps: { children: getIntentIcon(intent) }, | ||
| }), | ||
| layout, | ||
| intent, | ||
| }; | ||
| }; |
17 changes: 17 additions & 0 deletions
17
...ponents/react-message-bar-preview/src/components/MessageBar/useMessageBarContextValues.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,17 @@ | ||
| import * as React from 'react'; | ||
| import { MessageBarContextValues, MessageBarState } from './MessageBar.types'; | ||
|
|
||
| export function useMessageBarContextValue_unstable(state: MessageBarState): MessageBarContextValues { | ||
| const { layout } = state; | ||
|
|
||
| const messageBarContext = React.useMemo( | ||
| () => ({ | ||
| layout, | ||
| }), | ||
| [layout], | ||
| ); | ||
|
|
||
| return { | ||
| messageBar: messageBarContext, | ||
| }; | ||
| } |
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.
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.
Cruft?
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.
yeah removed in #29328