Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This styled-components util function is now removed as we move away from Styled Components. BREAKING CHANGE: mediaQueries function is no longer available. This was a styled-components util function that is now no longer meant to be used. Tokens and breakpoint values are still accessible.
- Loading branch information
Showing
8 changed files
with
103 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/orbit-components/src/utils/mediaQuery/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Theme from "../../../defaultTheme"; | ||
import { getBreakpointWidth, QUERIES } from ".."; | ||
|
||
describe("getBreakpointWidth", () => { | ||
const theme = Theme; | ||
|
||
it("should return correct value as string for each query", () => { | ||
expect(getBreakpointWidth(QUERIES.MEDIUMMOBILE, theme)).toBe( | ||
`(min-width: ${theme.orbit.widthBreakpointMediumMobile}px)`, | ||
); | ||
expect(getBreakpointWidth(QUERIES.LARGEMOBILE, theme)).toBe( | ||
`(min-width: ${theme.orbit.widthBreakpointLargeMobile}px)`, | ||
); | ||
expect(getBreakpointWidth(QUERIES.TABLET, theme)).toBe( | ||
`(min-width: ${theme.orbit.widthBreakpointTablet}px)`, | ||
); | ||
expect(getBreakpointWidth(QUERIES.DESKTOP, theme)).toBe( | ||
`(min-width: ${theme.orbit.widthBreakpointDesktop}px)`, | ||
); | ||
expect(getBreakpointWidth(QUERIES.LARGEDESKTOP, theme)).toBe( | ||
`(min-width: ${theme.orbit.widthBreakpointLargeDesktop}px)`, | ||
); | ||
}); | ||
|
||
it("should return correct value for each query when pure is true", () => { | ||
expect(getBreakpointWidth(QUERIES.MEDIUMMOBILE, theme, true)).toBe( | ||
theme.orbit.widthBreakpointMediumMobile, | ||
); | ||
expect(getBreakpointWidth(QUERIES.LARGEMOBILE, theme, true)).toBe( | ||
theme.orbit.widthBreakpointLargeMobile, | ||
); | ||
expect(getBreakpointWidth(QUERIES.TABLET, theme, true)).toBe(theme.orbit.widthBreakpointTablet); | ||
expect(getBreakpointWidth(QUERIES.DESKTOP, theme, true)).toBe( | ||
theme.orbit.widthBreakpointDesktop, | ||
); | ||
expect(getBreakpointWidth(QUERIES.LARGEDESKTOP, theme, true)).toBe( | ||
theme.orbit.widthBreakpointLargeDesktop, | ||
); | ||
}); | ||
}); |
14 changes: 0 additions & 14 deletions
14
packages/orbit-components/src/utils/mediaQuery/__typetests__/index.ts
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
import { css } from "styled-components"; | ||
|
||
import type { Theme } from "../../defaultTheme"; | ||
import { QUERIES } from "./consts"; | ||
import type { MediaQueries } from "./types"; | ||
|
||
export type Devices = | ||
| "largeDesktop" | ||
| "desktop" | ||
| "tablet" | ||
| "largeMobile" | ||
| "mediumMobile" | ||
| "smallMobile"; | ||
|
||
export enum QUERIES { | ||
MEDIUMMOBILE = "mediumMobile", | ||
LARGEMOBILE = "largeMobile", | ||
TABLET = "tablet", | ||
DESKTOP = "desktop", | ||
LARGEDESKTOP = "largeDesktop", | ||
} | ||
|
||
export const TOKEN = { | ||
mediumMobile: "widthBreakpointMediumMobile", | ||
largeMobile: "widthBreakpointLargeMobile", | ||
tablet: "widthBreakpointTablet", | ||
desktop: "widthBreakpointDesktop", | ||
largeDesktop: "widthBreakpointLargeDesktop", | ||
}; | ||
} as const; | ||
|
||
export const getBreakpointWidth = ( | ||
name: keyof typeof TOKEN, | ||
export interface GetBreakpointWidth { | ||
(name: keyof typeof TOKEN, theme: Theme): string; | ||
(name: keyof typeof TOKEN, theme: Theme, pure: false): string; | ||
(name: keyof typeof TOKEN, theme: Theme, pure: true): number; | ||
} | ||
|
||
export const getBreakpointWidth: GetBreakpointWidth = ( | ||
name: string, | ||
theme: Theme, | ||
pure?: boolean, | ||
): string => { | ||
) => { | ||
return pure ? theme.orbit[TOKEN[name]] : `(min-width: ${theme.orbit[TOKEN[name]]}px)`; | ||
}; | ||
|
||
const mediaQueries = Object.values(QUERIES).reduce<MediaQueries>( | ||
(acc: MediaQueries, device: keyof typeof TOKEN) => { | ||
acc[device] = style => css` | ||
@media ${({ theme }) => getBreakpointWidth(device, theme)} { | ||
${style}; | ||
} | ||
`; | ||
|
||
return acc; | ||
}, | ||
{ mediumMobile: {}, largeMobile: {}, tablet: {}, desktop: {}, largeDesktop: {} } as MediaQueries, | ||
); | ||
|
||
export default mediaQueries; |
This file was deleted.
Oops, something went wrong.