Skip to content

Commit d3bfa81

Browse files
etudieMitch-At-Work
andcommitted
Extended Tokens: Search (#34842)
Co-authored-by: Mitch-At-Work <[email protected]>
1 parent 1aaa6fd commit d3bfa81

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { ProgressBarState } from '@fluentui/react-progress';
5858
import { RadioState } from '@fluentui/react-radio';
5959
import { RatingDisplayState } from '@fluentui/react-rating';
6060
import { RatingItemState } from '@fluentui/react-rating';
61+
import { SearchBoxState } from '@fluentui/react-search';
6162
import { SliderState } from '@fluentui/react-slider';
6263
import { SpinButtonState } from '@fluentui/react-spinbutton';
6364
import { SpinnerState } from '@fluentui/react-spinner';
@@ -257,6 +258,9 @@ export const useSemanticRatingDisplayStyles: (_state: unknown) => RatingDisplayS
257258
// @public
258259
export const useSemanticRatingItemStyles: (_state: unknown) => RatingItemState;
259260

261+
// @public
262+
export const useSemanticSearchBoxStyles: (_state: unknown) => SearchBoxState;
263+
260264
// @public
261265
export const useSemanticSliderStyles: (_state: unknown) => SliderState;
262266

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@fluentui/react-provider": "^9.20.6",
5252
"@fluentui/react-radio": "^9.3.6",
5353
"@fluentui/react-rating": "^9.1.6",
54+
"@fluentui/react-search": "^9.1.6",
5455
"@fluentui/react-shared-contexts": "^9.23.1",
5556
"@fluentui/react-slider": "^9.3.7",
5657
"@fluentui/react-spinbutton": "^9.3.6",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { useSemanticSearchBoxStyles } from './useSemanticSearchStyles.styles';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
import { makeResetStyles, makeStyles, mergeClasses } from '@griffel/react';
2+
import { getSlotClassNameProp_unstable } from '@fluentui/react-utilities';
3+
import { tokens } from '@fluentui/react-theme';
4+
import { useSemanticInputStyles } from '../Input';
5+
import { type SearchBoxState, searchBoxClassNames } from '@fluentui/react-search';
6+
import * as semanticTokens from '@fluentui/semantic-tokens';
7+
8+
/**
9+
* Styles for the root slot
10+
*/
11+
const useRootStyles = makeStyles({
12+
small: {
13+
columnGap: 0,
14+
maxWidth: '468px',
15+
16+
paddingLeft: tokens.spacingHorizontalSNudge,
17+
paddingRight: tokens.spacingHorizontalSNudge,
18+
},
19+
medium: {
20+
columnGap: 0,
21+
maxWidth: '468px',
22+
23+
paddingLeft: tokens.spacingHorizontalS,
24+
paddingRight: tokens.spacingHorizontalS,
25+
},
26+
large: {
27+
columnGap: 0,
28+
maxWidth: '468px',
29+
30+
paddingLeft: tokens.spacingHorizontalMNudge,
31+
paddingRight: tokens.spacingHorizontalMNudge,
32+
},
33+
34+
input: {
35+
paddingLeft: tokens.spacingHorizontalSNudge,
36+
paddingRight: 0,
37+
38+
// removes the WebKit pseudoelement styling
39+
'::-webkit-search-decoration': {
40+
display: 'none',
41+
},
42+
'::-webkit-search-cancel-button': {
43+
display: 'none',
44+
},
45+
},
46+
47+
unfocusedNoContentAfter: {
48+
paddingRight: 0,
49+
},
50+
});
51+
52+
const useInputStyles = makeStyles({
53+
small: {
54+
paddingRight: tokens.spacingHorizontalSNudge,
55+
},
56+
medium: {
57+
paddingRight: tokens.spacingHorizontalS,
58+
},
59+
large: {
60+
paddingRight: tokens.spacingHorizontalMNudge,
61+
},
62+
});
63+
64+
const useContentAfterStyles = makeStyles({
65+
contentAfter: {
66+
paddingLeft: tokens.spacingHorizontalM,
67+
columnGap: tokens.spacingHorizontalXS,
68+
},
69+
rest: {
70+
height: 0,
71+
width: 0,
72+
paddingLeft: 0,
73+
overflow: 'hidden',
74+
},
75+
});
76+
77+
const useDismissClassName = makeResetStyles({
78+
boxSizing: 'border-box',
79+
color: semanticTokens.foregroundCtrlIconOnNeutralRest, // "icon color" in design spec
80+
display: 'flex',
81+
// special case styling for icons (most common case) to ensure they're centered vertically
82+
// size: medium (default)
83+
'> svg': { fontSize: '20px' },
84+
cursor: 'pointer',
85+
});
86+
87+
const useDismissStyles = makeStyles({
88+
disabled: {
89+
color: semanticTokens.backgroundCtrlSubtleRest,
90+
},
91+
// Ensure resizable icons show up with the proper font size
92+
small: {
93+
'> svg': { fontSize: '16px' },
94+
},
95+
medium: {
96+
// included in useDismissClassName
97+
},
98+
large: {
99+
'> svg': { fontSize: '24px' },
100+
},
101+
});
102+
103+
/**
104+
* Apply styling to the SearchBox slots based on the state
105+
*/
106+
export const useSemanticSearchBoxStyles = (_state: unknown): SearchBoxState => {
107+
'use no memo';
108+
109+
const state = _state as SearchBoxState;
110+
111+
const { disabled, focused, size } = state;
112+
113+
const rootStyles = useRootStyles();
114+
const inputStyles = useInputStyles();
115+
const contentAfterStyles = useContentAfterStyles();
116+
const dismissClassName = useDismissClassName();
117+
const dismissStyles = useDismissStyles();
118+
119+
state.root.className = mergeClasses(
120+
state.root.className,
121+
searchBoxClassNames.root,
122+
rootStyles[size],
123+
!focused && rootStyles.unfocusedNoContentAfter,
124+
getSlotClassNameProp_unstable(state.root),
125+
);
126+
127+
state.input.className = mergeClasses(
128+
state.input.className,
129+
searchBoxClassNames.input,
130+
rootStyles.input,
131+
!focused && inputStyles[size],
132+
getSlotClassNameProp_unstable(state.input),
133+
);
134+
135+
if (state.dismiss) {
136+
state.dismiss.className = mergeClasses(
137+
state.dismiss.className,
138+
searchBoxClassNames.dismiss,
139+
dismissClassName,
140+
disabled && dismissStyles.disabled,
141+
dismissStyles[size],
142+
getSlotClassNameProp_unstable(state.dismiss),
143+
);
144+
}
145+
146+
if (state.contentBefore) {
147+
state.contentBefore.className = mergeClasses(
148+
state.contentBefore.className,
149+
searchBoxClassNames.contentBefore,
150+
getSlotClassNameProp_unstable(state.contentBefore),
151+
);
152+
}
153+
154+
if (state.contentAfter) {
155+
state.contentAfter.className = mergeClasses(
156+
state.contentAfter.className,
157+
searchBoxClassNames.contentAfter,
158+
contentAfterStyles.contentAfter,
159+
!focused && contentAfterStyles.rest,
160+
getSlotClassNameProp_unstable(state.contentAfter),
161+
);
162+
} else if (state.dismiss) {
163+
state.dismiss.className = mergeClasses(
164+
contentAfterStyles.contentAfter,
165+
state.dismiss.className,
166+
getSlotClassNameProp_unstable(state.dismiss),
167+
);
168+
}
169+
170+
useSemanticInputStyles(state);
171+
172+
return state;
173+
};

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import {
107107
useSemanticToastStyles,
108108
useSemanticToastTitleStyles,
109109
} from './Toast';
110+
import { useSemanticSearchBoxStyles } from './Search';
110111

111112
export const SEMANTIC_STYLE_HOOKS: FluentProviderCustomStyleHooks = {
112113
// Accordion styles
@@ -183,6 +184,8 @@ export const SEMANTIC_STYLE_HOOKS: FluentProviderCustomStyleHooks = {
183184
useRadioStyles_unstable: useSemanticRadioStyles,
184185
// Persona styles
185186
usePersonaStyles_unstable: useSemanticPersonaStyles,
187+
// Search styles
188+
useSearchBoxStyles_unstable: useSemanticSearchBoxStyles,
186189
// Checkbox styles
187190
useCheckboxStyles_unstable: useSemanticCheckboxStyles,
188191
// Breadcrumb styles

packages/react-components/semantic-style-hooks-preview/library/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ export {
110110
useSemanticToastStyles,
111111
useSemanticToastTitleStyles,
112112
} from './component-styles/Toast';
113+
export { useSemanticSearchBoxStyles } from './component-styles/Search';

0 commit comments

Comments
 (0)