Skip to content

Commit

Permalink
fix: only fallback for not defined breakpoint values
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaoste committed Sep 10, 2024
1 parent d53a8d2 commit 100fd98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/core/src/utils/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ const builtInStylesWithDesignTokens = [
'cfMaxWidth',
];

const isValidBreakpointValue = (value: PrimitiveValue) => {
return value !== undefined && value !== null && value !== '';
};

export const getValueForBreakpoint = (
valuesByBreakpoint: ValuesByBreakpoint,
breakpoints: Breakpoint[],
Expand All @@ -110,19 +114,20 @@ export const getValueForBreakpoint = (
// Assume that the values are sorted by media query to apply the cascading CSS logic
for (let index = activeBreakpointIndex; index >= 0; index--) {
const breakpointId = breakpoints[index]?.id;
if (valuesByBreakpoint[breakpointId]) {
if (isValidBreakpointValue(valuesByBreakpoint[breakpointId])) {
// If the value is defined, we use it and stop the breakpoints cascade
return eventuallyResolveDesignTokens(valuesByBreakpoint[breakpointId]);
}
}
// If no breakpoint matched, we search and apply the fallback breakpoint
const fallbackBreakpointIndex = getFallbackBreakpointIndex(breakpoints);
const fallbackBreakpointId = breakpoints[fallbackBreakpointIndex]?.id;
if (valuesByBreakpoint[fallbackBreakpointId]) {
if (isValidBreakpointValue(valuesByBreakpoint[fallbackBreakpointId])) {
return eventuallyResolveDesignTokens(valuesByBreakpoint[fallbackBreakpointId]);
}
} else {
// Old design properties did not support breakpoints, keep for backward compatibility
return valuesByBreakpoint;
}
return undefined;
};
2 changes: 1 addition & 1 deletion packages/core/src/utils/styleUtils/styleTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const transformVisibility = (value?: boolean): CSSProperties => {
return {};
};

// Keep this for backwards compatilibity - deleting this would be a breaking change
// Keep this for backwards compatibility - deleting this would be a breaking change
// because existing components on a users experience will have the width value as fill
// rather than 100%
export const transformFill = (value?: string) => (value === 'fill' ? '100%' : value);
Expand Down

0 comments on commit 100fd98

Please sign in to comment.