Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 'px' complement to getSizeFromBreakpoint #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/convertors.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function pxToEmOrRem(breakpoints, ratio = 16, unit) {
for (let key in breakpoints) {
const point = breakpoints[key];

if (String(point).includes('px')) {
if (typeof point === 'number' || String(point).includes('px')) {
newBreakpoints[key] = +(parseInt(point) / ratio) + unit;
continue;
}
Expand Down
18 changes: 12 additions & 6 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ export interface MediaGenerator<Breakpoints, Theme> {
// --

export interface DefaultBreakpoints {
huge: string;
large: string;
medium: string;
small: string;
huge: string | number;
large: string | number;
medium: string | number;
small: string | number;
}

export const defaultBreakpoints: DefaultBreakpoints;
Expand All @@ -66,5 +66,11 @@ export default media;

// Convertors --

export function pxToEm<B>(breakpoints: B, ratio?: number): B;
export function pxToRem<B>(breakpoints: B, ratio?: number): B;
export function pxToEm<B extends DefaultBreakpoints>(
breakpoints: B,
ratio?: number
): B;
export function pxToRem<B extends DefaultBreakpoints>(
breakpoints: B,
ratio?: number
): B;
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export const defaultBreakpoints = {
};

function getSizeFromBreakpoint(breakpointValue, breakpoints = {}) {
if (breakpoints[breakpointValue]) {
if (typeof breakpoints[breakpointValue] === "number") {
return breakpoints[breakpointValue] + "px";
} else if (breakpoints[breakpointValue]) {
return breakpoints[breakpointValue];
} else if (parseInt(breakpointValue)) {
return breakpointValue;
Expand Down