Skip to content

Commit

Permalink
refactor(system): remove unused function
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed May 21, 2022
1 parent 50c4d2e commit b918fc0
Showing 1 changed file with 0 additions and 91 deletions.
91 changes: 0 additions & 91 deletions packages/system/src/breakpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,94 +148,3 @@ export function resolveBreakpointValues<K extends string>(data: {
return acc;
}, {} as { [k in K]: number });
}

export function generateColStyle(theme: Theme, props: Record<string, any>) {
let size: number | boolean | "auto";
const breakpoints = Object.keys(
theme.breakpoints.values
) as (keyof typeof props)[];
return breakpoints.reduce((globalStyles, breakpoint) => {
// Use side effect over immutability for better performance.
let styles: SxPropsObject = {};
if (props[breakpoint]) {
size = props[breakpoint] as any;
}
if (!size) {
return globalStyles;
}

if (size === true) {
// For the auto layouting
styles = {
flexBasis: 0,
flexGrow: 1,
maxWidth: "100%",
};
} else if (size === "auto") {
styles = {
flexBasis: "auto",
flexGrow: 0,
flexShrink: 0,
maxWidth: "none",
width: "auto",
};
} else {
const columnsBreakpointValues = resolveBreakpointValues({
values: props.columns,
breakpoints: theme.breakpoints.values,
});

const columnValue =
typeof columnsBreakpointValues === "object"
? columnsBreakpointValues[
breakpoint as keyof typeof columnsBreakpointValues
]
: columnsBreakpointValues;

if (columnValue === undefined || columnValue === null) {
return globalStyles;
}
// Keep 7 significant numbers.
const width = `${Math.round((size / columnValue) * 10e7) / 10e5}%`;
const more: CSSProps = {};

if (
props.container &&
props.item &&
typeof props.columnSpacing === "number" &&
props.columnSpacing !== 0
) {
const themeSpacing = theme.spacing(props.columnSpacing);
if (themeSpacing !== "0px") {
more.flexBasis = more.maxWidth = `calc(${width} + ${getOffset(
themeSpacing
)})`;
}
}

// Close to the bootstrap implementation:
// https://github.com/twbs/bootstrap/blob/8fccaa2439e97ec72a4b7dc42ccc1f649790adb0/scss/mixins/_grid.scss#L41
styles = {
flexBasis: width,
flexGrow: 0,
maxWidth: width,
...more,
};
}

// No need for a media query for the first size.
if (
theme.breakpoints.values[
breakpoint as keyof typeof theme.breakpoints.values
] === 0
) {
Object.assign(globalStyles, styles);
} else {
globalStyles = {
...globalStyles,
...theme.breakpoints.up(breakpoint as any, styles as SxPropsObject),
};
}
return globalStyles;
}, {});
}

0 comments on commit b918fc0

Please sign in to comment.