-
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.
feat(MessageBar): Initial implementation (#29313)
* feat: Initial implementation Adds an initial implementation of MessageBar that includes design for different intents and multiline handling. * remove TODOs * fix multiline alignment * fix slot type misalign * fix tests * rename to secondaryActions * fix warnings * break out into components * remove stories * revert tsconfig changes * remove outdated keyborg cypress test * add keyborg test again * add tsconfig paths to cypress
- Loading branch information
Showing
47 changed files
with
1,043 additions
and
1 deletion.
There are no files selected for viewing
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
1 change: 1 addition & 0 deletions
1
packages/react-components/react-message-bar-preview/src/MessageBar.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 @@ | ||
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 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 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 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 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 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 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 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 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 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 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 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 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.