Skip to content

Commit

Permalink
feat: Add shape prop to MessageBar (#29426)
Browse files Browse the repository at this point in the history
* feat: Add shape prop to MessageBar

Adds the shape prop to MessageBar to support both `square` and `rounded`
shapes.

Addresses 22579

* changefile
  • Loading branch information
ling1726 authored Oct 6, 2023
1 parent 3d2e809 commit 60a911e
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,18 @@ export const Auto = () => {
</div>
);
};

export const Square = () => {
return (
<MessageBar shape="square">
<MessageBarBody>
<MessageBarTitle>Title</MessageBarTitle>
Message providing information to the user with actionable insights. <Link>Link</Link>
</MessageBarBody>
<MessageBarActions containerAction={<Button appearance="transparent" icon={<DismissRegular />} />}>
<Button>Action</Button>
<Button>Action</Button>
</MessageBarActions>
</MessageBar>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "feat: Add shape prop to MessageBar",
"packageName": "@fluentui/react-message-bar-preview",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export type MessageBarIntent = 'info' | 'success' | 'warning' | 'error';
export type MessageBarProps = ComponentProps<MessageBarSlots> & Pick<Partial<MessageBarContextValue>, 'layout'> & {
intent?: MessageBarIntent;
politeness?: 'assertive' | 'polite';
shape?: 'square' | 'rounded';
};

// @public (undocumented)
Expand All @@ -106,7 +107,7 @@ export type MessageBarSlots = {
};

// @public
export type MessageBarState = ComponentState<MessageBarSlots> & Required<Pick<MessageBarProps, 'layout' | 'intent'>> & Pick<MessageBarContextValue, 'actionsRef' | 'bodyRef' | 'titleId'> & {
export type MessageBarState = ComponentState<MessageBarSlots> & Required<Pick<MessageBarProps, 'layout' | 'intent' | 'shape'>> & Pick<MessageBarContextValue, 'actionsRef' | 'bodyRef' | 'titleId'> & {
transitionClassName: string;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@ export type MessageBarProps = ComponentProps<MessageBarSlots> &
Pick<Partial<MessageBarContextValue>, 'layout'> & {
/**
* Default designs announcement presets
* @default info
*/
intent?: MessageBarIntent;
/**
* @see https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Live_Regions
*/
politeness?: 'assertive' | 'polite';
/**
* Use squal for page level messages and rounded for component level messages
* @default rounded
*/
shape?: 'square' | 'rounded';
};

/**
* State used in rendering MessageBar
*/
export type MessageBarState = ComponentState<MessageBarSlots> &
Required<Pick<MessageBarProps, 'layout' | 'intent'>> &
Required<Pick<MessageBarProps, 'layout' | 'intent' | 'shape'>> &
Pick<MessageBarContextValue, 'actionsRef' | 'bodyRef' | 'titleId'> & {
transitionClassName: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useMessageBarTransitionContext } from '../../contexts/messageBarTransit
* @param ref - reference to root HTMLElement of MessageBar
*/
export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HTMLDivElement>): MessageBarState => {
const { layout = 'auto', intent = 'info', politeness } = props;
const { layout = 'auto', intent = 'info', politeness, shape = 'rounded' } = props;
const computedPolitness = politeness ?? intent === 'info' ? 'polite' : 'assertive';
const autoReflow = layout === 'auto';
const { ref: reflowRef, reflowing } = useMessageBarReflow(autoReflow);
Expand Down Expand Up @@ -61,5 +61,6 @@ export const useMessageBar_unstable = (props: MessageBarProps, ref: React.Ref<HT
actionsRef,
bodyRef,
titleId,
shape,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const useIconBaseStyles = makeResetStyles({
color: tokens.colorNeutralForeground3,
});

const useMultilineStyles = makeStyles({
const useStyles = makeStyles({
rootMultiline: {
whiteSpace: 'normal',
alignItems: 'start',
Expand All @@ -48,6 +48,10 @@ const useMultilineStyles = makeStyles({
marginBottom: tokens.spacingVerticalS,
marginRight: '0px',
},

square: {
...shorthands.borderRadius(0),
},
});

const useIconIntentStyles = makeStyles({
Expand Down Expand Up @@ -89,14 +93,15 @@ const useRootIntentStyles = makeStyles({
export const useMessageBarStyles_unstable = (state: MessageBarState): MessageBarState => {
const rootBaseStyles = useRootBaseStyles();
const iconBaseStyles = useIconBaseStyles();
const multilineStyles = useMultilineStyles();
const iconIntentStyles = useIconIntentStyles();
const rootIntentStyles = useRootIntentStyles();
const styles = useStyles();

state.root.className = mergeClasses(
messageBarClassNames.root,
rootBaseStyles,
state.layout === 'multiline' && multilineStyles.rootMultiline,
state.layout === 'multiline' && styles.rootMultiline,
state.shape === 'square' && styles.square,
rootIntentStyles[state.intent],
state.transitionClassName,
state.root.className,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as React from 'react';
import { Button, Field, Link, Radio, RadioGroup } from '@fluentui/react-components';
import { DismissRegular } from '@fluentui/react-icons';
import {
MessageBar,
MessageBarActions,
MessageBarTitle,
MessageBarBody,
MessageBarProps,
} from '@fluentui/react-message-bar-preview';

export const Shapes = () => {
const [shape, setShape] = React.useState<MessageBarProps['shape']>('rounded');

return (
<>
<Field label="Select shape">
<RadioGroup value={shape} onChange={(e, { value }) => setShape(value as MessageBarProps['shape'])}>
<Radio value="rounded" label="Rounded" />
<Radio value="square" label="Square" />
</RadioGroup>
</Field>
<MessageBar shape={shape}>
<MessageBarBody>
<MessageBarTitle>Descriptive title</MessageBarTitle>
Message providing information to the user with actionable insights. <Link>Link</Link>
</MessageBarBody>
<MessageBarActions containerAction={<Button appearance="transparent" icon={<DismissRegular />} />}>
<Button>Action</Button>
<Button>Action</Button>
</MessageBarActions>
</MessageBar>
</>
);
};

Shapes.parameters = {
docs: {
description: {
story: [
'MessageBar can have either rounded or square corners, please follow the usage guidance for these shapes:',
'- **_rounded_** used for component level message bars',
'- **_square_** used for page/app level message bars',
].join('\n'),
},
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import bestPracticesMd from './MessageBarBestPractices.md';

export { Default } from './Default.stories';
export { Intent } from './Intent.stories';
export { Shapes } from './Shapes.stories';
export { Dismiss } from './Dismiss.stories';
export { Animation } from './Animation.stories';
export { Reflow } from './Reflow.stories';
Expand Down

0 comments on commit 60a911e

Please sign in to comment.