|
1 | 1 | import styles from '@patternfly/react-styles/css/components/Toolbar/toolbar'; |
2 | 2 | import { css } from '@patternfly/react-styles'; |
3 | | -import { formatBreakpointMods, toCamel } from '../../helpers/util'; |
| 3 | +import { formatBreakpointMods, setBreakpointCssVars, toCamel } from '../../helpers/util'; |
| 4 | +import c_toolbar__item_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_Width'; |
| 5 | +import c_toolbar__item_m_w_sm_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_sm_Width'; |
| 6 | +import c_toolbar__item_m_w_md_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_md_Width'; |
| 7 | +import c_toolbar__item_m_w_lg_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_lg_Width'; |
| 8 | +import c_toolbar__item_m_w_xl_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_xl_Width'; |
| 9 | +import c_toolbar__item_m_w_2xl_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_2xl_Width'; |
| 10 | +import c_toolbar__item_m_w_3xl_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_3xl_Width'; |
| 11 | +import c_toolbar__item_m_w_4xl_Width from '@patternfly/react-tokens/dist/esm/c_toolbar__item_m_w_4xl_Width'; |
4 | 12 | import { Divider } from '../Divider'; |
5 | 13 | import { PageContext } from '../Page/PageContext'; |
6 | 14 |
|
@@ -206,6 +214,7 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({ |
206 | 214 | widths, |
207 | 215 | flexGrow, |
208 | 216 | role, |
| 217 | + style, |
209 | 218 | ...props |
210 | 219 | }: ToolbarItemProps) => { |
211 | 220 | if (variant === ToolbarItemVariant.separator) { |
@@ -243,27 +252,38 @@ export const ToolbarItem: React.FunctionComponent<ToolbarItemProps> = ({ |
243 | 252 | formatBreakpointMods(rowGap, styles, '', getBreakpoint(width)), |
244 | 253 | formatBreakpointMods(rowWrap, styles, '', getBreakpoint(width)), |
245 | 254 | className, |
246 | | - widths && |
247 | | - Object.entries(widths).reduce( |
248 | | - (acc, [bp, size]) => ({ |
249 | | - ...acc, |
250 | | - [`pf-m-w-${size}${bp !== 'default' ? `-on-${bp}` : ''}`]: true |
251 | | - }), |
252 | | - {} |
253 | | - ), |
254 | | - flexGrow && |
255 | | - Object.entries(flexGrow).reduce( |
256 | | - (acc, [bp]) => ({ |
257 | | - ...acc, |
258 | | - [`pf-m-flex-grow${bp !== 'default' ? `-on-${bp}` : ''}`]: true |
259 | | - }), |
260 | | - {} |
261 | | - ) |
| 255 | + formatBreakpointMods(flexGrow, styles, '', getBreakpoint(width)) |
262 | 256 | )} |
| 257 | + style={{ |
| 258 | + ...style, |
| 259 | + ...(widths |
| 260 | + ? setBreakpointCssVars( |
| 261 | + Object.entries(widths).reduce( |
| 262 | + (acc, [bp, size]) => { |
| 263 | + if (!size) { |
| 264 | + return acc; |
| 265 | + } |
| 266 | + const valueMap: Record<string, string> = { |
| 267 | + sm: (c_toolbar__item_m_w_sm_Width as any)?.value, |
| 268 | + md: (c_toolbar__item_m_w_md_Width as any)?.value, |
| 269 | + lg: (c_toolbar__item_m_w_lg_Width as any)?.value, |
| 270 | + xl: (c_toolbar__item_m_w_xl_Width as any)?.value, |
| 271 | + '2xl': (c_toolbar__item_m_w_2xl_Width as any)?.value, |
| 272 | + '3xl': (c_toolbar__item_m_w_3xl_Width as any)?.value, |
| 273 | + '4xl': (c_toolbar__item_m_w_4xl_Width as any)?.value |
| 274 | + }; |
| 275 | + const tokenValue = valueMap[size as keyof typeof valueMap]; |
| 276 | + return tokenValue ? { ...acc, [bp]: tokenValue } : acc; |
| 277 | + }, |
| 278 | + {} as Record<string, string> |
| 279 | + ), |
| 280 | + (c_toolbar__item_Width as any).name |
| 281 | + ) |
| 282 | + : undefined) |
| 283 | + }} |
263 | 284 | {...(variant === 'label' && { 'aria-hidden': true })} |
264 | 285 | id={id} |
265 | 286 | role={role} |
266 | | - data-testid="toolbaritem" |
267 | 287 | {...props} |
268 | 288 | > |
269 | 289 | {children} |
|
0 commit comments