Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: Reducing bundle size of Stack by moving selector used in multiple places to local const.",
"packageName": "@fluentui/react",
"email": "[email protected]",
"dependentChangeType": "patch"
}
20 changes: 9 additions & 11 deletions packages/react/src/components/Stack/Stack.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ export const styles: IStackComponent['styles'] = (props, theme, tokens): IStackS
textOverflow: 'ellipsis',
};

const childSelector = '> ' + (enableScopedSelectors ? '.' + GlobalClassNames.child : '*');

const disableShrinkStyles = {
// flexShrink styles are applied by the StackItem
[`> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}:not(.${StackItemGlobalClassNames.root})`]: {
[`${childSelector}:not(.${StackItemGlobalClassNames.root})`]: {
flexShrink: 0,
},
};
Expand Down Expand Up @@ -99,7 +101,7 @@ export const styles: IStackComponent['styles'] = (props, theme, tokens): IStackS
width: columnGap.value === 0 ? '100%' : `calc(100% + ${columnGap.value}${columnGap.unit})`,
maxWidth: '100vw',

[`> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}`]: {
[childSelector]: {
margin: `${0.5 * rowGap.value}${rowGap.unit} ${0.5 * columnGap.value}${columnGap.unit}`,

...childStyles,
Expand All @@ -118,15 +120,15 @@ export const styles: IStackComponent['styles'] = (props, theme, tokens): IStackS
// avoid unnecessary calc() calls if vertical gap is 0
height: rowGap.value === 0 ? '100%' : `calc(100% + ${rowGap.value}${rowGap.unit})`,

[`> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}`]: {
[childSelector]: {
maxWidth: columnGap.value === 0 ? '100%' : `calc(100% - ${columnGap.value}${columnGap.unit})`,
},
},
!horizontal && {
flexDirection: reversed ? 'column-reverse' : 'column',
height: `calc(100% + ${rowGap.value}${rowGap.unit})`,

[`> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}`]: {
[childSelector]: {
maxHeight: rowGap.value === 0 ? '100%' : `calc(100% - ${rowGap.value}${rowGap.unit})`,
},
},
Expand All @@ -148,7 +150,7 @@ export const styles: IStackComponent['styles'] = (props, theme, tokens): IStackS
padding: parsePadding(padding, theme),
boxSizing: 'border-box',

[`> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}`]: childStyles,
[childSelector]: childStyles,
},
disableShrink && disableShrinkStyles,
grow && {
Expand All @@ -165,19 +167,15 @@ export const styles: IStackComponent['styles'] = (props, theme, tokens): IStackS
columnGap.value > 0 && {
// apply gap margin to every direct child except the first direct child if the direction is not reversed,
// and the last direct one if it is
[reversed
? `> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}:not(:last-child)`
: `> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}:not(:first-child)`]: {
[reversed ? `${childSelector}:not(:last-child)` : `${childSelector}:not(:first-child)`]: {
marginLeft: `${columnGap.value}${columnGap.unit}`,
},
},
!horizontal &&
rowGap.value > 0 && {
// apply gap margin to every direct child except the first direct child if the direction is not reversed,
// and the last direct one if it is
[reversed
? `> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}:not(:last-child)`
: `> ${enableScopedSelectors ? '.' + GlobalClassNames.child : '*'}:not(:first-child)`]: {
[reversed ? `${childSelector}:not(:last-child)` : `${childSelector}:not(:first-child)`]: {
marginTop: `${rowGap.value}${rowGap.unit}`,
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Stack/Stack.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export interface IStackProps

/**
* Defines if scoped style selectors are enabled for the Stack component, which greatly helps in style recalculation
* performance but requires children of the Stack to be able to accept a className prop (excluding Fragments).
* performance, but requires children of the Stack to be able to accept a className prop (excluding Fragments).
* @defaultvalue false
*/
enableScopedSelectors?: boolean;
Expand Down