Skip to content

Commit c920a38

Browse files
terynkMitch-At-Work
andcommitted
Toast: Update Toast to use semantic tokens (#34844)
Co-authored-by: Mitch-At-Work <[email protected]>
1 parent 3995aed commit c920a38

22 files changed

+816
-12
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "feat: Export ToastContainer state and classNames nessecary for style overrides",
4+
"packageName": "@fluentui/react-toast",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-toast/library/etc/react-toast.api.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ export type ToastBodyState = ComponentState<ToastBodySlots> & {
6464
// @public (undocumented)
6565
export const toastClassNames: SlotClassNames<ToastSlots>;
6666

67+
// @public (undocumented)
68+
export const toastContainerClassNames: SlotClassNames<ToastContainerSlots>;
69+
70+
// @public
71+
export type ToastContainerState = ComponentState<ToastContainerSlots> & Pick<ToastContainerProps, 'remove' | 'close' | 'updateId' | 'visible' | 'intent'> & Pick<ToastContainerContextValue, 'titleId' | 'bodyId'> & {
72+
transitionTimeout: number;
73+
timerTimeout: number;
74+
running: boolean;
75+
onTransitionEntering: () => void;
76+
nodeRef: React_2.Ref<HTMLDivElement>;
77+
onMotionFinish?: (event: null, data: {
78+
direction: 'enter' | 'exit';
79+
}) => void;
80+
};
81+
6782
// @public
6883
export const Toaster: React_2.FC<ToasterProps>;
6984

packages/react-components/react-toast/library/src/components/ToastContainer/ToastContainer.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export type ToastContainerState = ComponentState<ToastContainerSlots> &
4242
*/
4343
onTransitionEntering: () => void;
4444
/**
45-
* @deprecated
45+
* @deprecated now merged with root ref
4646
*/
4747
nodeRef: React.Ref<HTMLDivElement>;
4848

packages/react-components/react-toast/library/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ export {
4040
toastFooterClassNames,
4141
} from './ToastFooter';
4242
export type { ToastFooterProps, ToastFooterState, ToastFooterSlots } from './ToastFooter';
43+
44+
export { toastContainerClassNames } from './ToastContainer';
45+
export type { ToastContainerState } from './ToastContainer';

packages/react-components/semantic-style-hooks-preview/library/etc/semantic-style-hooks-preview.api.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ import { TabListState } from '@fluentui/react-tabs';
6060
import { TabState } from '@fluentui/react-tabs';
6161
import { TextareaState } from '@fluentui/react-textarea';
6262
import { TextState } from '@fluentui/react-text';
63+
import { ToastBodyState } from '@fluentui/react-toast';
64+
import { ToastContainerState } from '@fluentui/react-toast';
65+
import { ToastFooterState } from '@fluentui/react-toast';
66+
import { ToastState } from '@fluentui/react-toast';
67+
import { ToastTitleState } from '@fluentui/react-toast';
6368
import { ToggleButtonState } from '@fluentui/react-button';
6469
import { ToolbarDividerState } from '@fluentui/react-toolbar';
6570
import { ToolbarGroupState } from '@fluentui/react-toolbar';
@@ -250,6 +255,21 @@ export const useSemanticTextareaStyles: (_state: unknown) => TextareaState;
250255
// @public
251256
export const useSemanticTextStyles: (_state: unknown) => TextState;
252257

258+
// @public
259+
export const useSemanticToastBodyStyles: (_state: unknown) => ToastBodyState;
260+
261+
// @public
262+
export const useSemanticToastContainerStyles: (_state: unknown) => ToastContainerState;
263+
264+
// @public
265+
export const useSemanticToastFooterStyles: (_state: unknown) => ToastFooterState;
266+
267+
// @public
268+
export const useSemanticToastStyles: (_state: unknown) => ToastState;
269+
270+
// @public
271+
export const useSemanticToastTitleStyles: (_state: unknown) => ToastTitleState;
272+
253273
// @public (undocumented)
254274
export const useSemanticToggleButtonStyles: (_state: unknown) => ToggleButtonState;
255275

packages/react-components/semantic-style-hooks-preview/library/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"@fluentui/react-text": "^9.4.36",
6262
"@fluentui/react-textarea": "^9.4.6",
6363
"@fluentui/react-theme": "^9.1.24",
64+
"@fluentui/react-toast": "^9.4.8",
6465
"@fluentui/react-toolbar": "^9.4.5",
6566
"@fluentui/react-tooltip": "^9.6.6",
6667
"@fluentui/react-tree": "^9.10.9",

packages/react-components/semantic-style-hooks-preview/library/src/component-styles/Menu/useSemanticMenuItemSwitchStyles.styles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ export const useSemanticMenuItemSwitchStyles = (_state: unknown): MenuItemSwitch
155155
useMenuItemStyles_unstable({
156156
...state,
157157
components: {
158-
// eslint-disable-next-line @typescript-eslint/no-deprecated
159158
...state.components,
160159
checkmark: 'span',
161160
submenuIndicator: 'span',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export { useSemanticToastBodyStyles } from './useSemanticToastBodyStyles.styles';
2+
export { useSemanticToastContainerStyles } from './useSemanticToastContainerStyles.styles';
3+
export { useSemanticToastFooterStyles } from './useSemanticToastFooterStyles.styles';
4+
export { useSemanticToastStyles } from './useSemanticToastStyles.styles';
5+
export { useSemanticToastTitleStyles } from './useSemanticToastTitleStyles.styles';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';
2+
import { toastBodyClassNames, type ToastBodyState } from '@fluentui/react-toast';
3+
import * as semanticTokens from '@fluentui/semantic-tokens';
4+
import { getSlotClassNameProp_unstable } from '@fluentui/react-utilities';
5+
6+
const useRootBaseClassName = makeResetStyles({
7+
gridColumnStart: 2,
8+
gridColumnEnd: 3,
9+
paddingTop: '6px', //not connected to tokens in Figma
10+
fontSize: semanticTokens.textRampItemBodyFontSize,
11+
lineHeight: semanticTokens.textRampItemBodyLineHeight,
12+
fontWeight: semanticTokens.textStyleDefaultRegularWeight,
13+
color: semanticTokens.foregroundContentNeutralPrimary,
14+
wordBreak: 'break-word',
15+
});
16+
17+
const useSubtitleBaseClassName = makeResetStyles({
18+
paddingTop: '4px', //not connected to tokens in Figma
19+
gridColumnStart: 2,
20+
gridColumnEnd: 3,
21+
fontSize: semanticTokens.textRampMetadataFontSize,
22+
lineHeight: semanticTokens.textRampMetadataLineHeight,
23+
fontWeight: semanticTokens.textStyleDefaultRegularWeight,
24+
color: semanticTokens.foregroundContentNeutralSecondary,
25+
});
26+
27+
const useInvertedStyles = makeStyles({
28+
root: {
29+
color: semanticTokens._ctrlToastBodyForegroundContentNeutralPrimary,
30+
},
31+
subtitle: {
32+
color: semanticTokens._ctrlToastBodyForegroundContentNeutralSecondary,
33+
},
34+
});
35+
36+
/**
37+
* Apply styling to the ToastBody slots based on the state
38+
*/
39+
export const useSemanticToastBodyStyles = (_state: unknown): ToastBodyState => {
40+
'use no memo';
41+
42+
const state = _state as ToastBodyState;
43+
const rootBaseClassName = useRootBaseClassName();
44+
const subtitleBaseClassName = useSubtitleBaseClassName();
45+
const invertedStyles = useInvertedStyles();
46+
state.root.className = mergeClasses(
47+
state.root.className,
48+
toastBodyClassNames.root,
49+
rootBaseClassName,
50+
state.backgroundAppearance === 'inverted' && invertedStyles.root,
51+
getSlotClassNameProp_unstable(state.root),
52+
);
53+
54+
if (state.subtitle) {
55+
state.subtitle.className = mergeClasses(
56+
state.subtitle.className,
57+
toastBodyClassNames.subtitle,
58+
subtitleBaseClassName,
59+
state.backgroundAppearance === 'inverted' && invertedStyles.subtitle,
60+
getSlotClassNameProp_unstable(state.subtitle),
61+
);
62+
}
63+
64+
return state;
65+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { makeResetStyles, mergeClasses } from '@griffel/react';
2+
import { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';
3+
import { toastContainerClassNames, type ToastContainerState } from '@fluentui/react-toast';
4+
import * as semanticTokens from '@fluentui/semantic-tokens';
5+
import { getSlotClassNameProp_unstable } from '@fluentui/react-utilities';
6+
7+
const useRootBaseClassName = makeResetStyles({
8+
boxSizing: 'border-box',
9+
marginTop: semanticTokens.gapBetweenCtrlLgDefault,
10+
pointerEvents: 'all',
11+
borderRadius: semanticTokens._ctrlToastContainerFlyoutRest,
12+
...createCustomFocusIndicatorStyle({
13+
outline: `${semanticTokens.ctrlFocusOuterStrokeWidth} solid ${semanticTokens._ctrlToastContainerCtrlFocusOuterStroke}`,
14+
}),
15+
});
16+
17+
/**
18+
* Apply styling to the ToastContainer slots based on the state
19+
*/
20+
export const useSemanticToastContainerStyles = (_state: unknown): ToastContainerState => {
21+
'use no memo';
22+
23+
const state = _state as ToastContainerState;
24+
25+
const rootBaseClassName = useRootBaseClassName();
26+
state.root.className = mergeClasses(
27+
state.root.className,
28+
toastContainerClassNames.root,
29+
rootBaseClassName,
30+
getSlotClassNameProp_unstable(state.root),
31+
);
32+
33+
return state;
34+
};

0 commit comments

Comments
 (0)