Media queries

Media queries

Media query functions

import media from "@kiwicom/orbit-components/lib/utils/mediaQuery";
import styled, { css } from "styled-components";
const StyledComponent = styled.div`
width: 100%;
${media.desktop(css`
width: 50%;
`)};
`;
import media from "@kiwicom/orbit-components/lib/utils/mediaQuery";
import styled, { css } from "styled-components";
import OrbitProvider from "@kiwicom/orbit-components/lib/OrbitProvider";
import defaultTheme from "@kiwicom/orbit-components/lib/defaultTheme";
const StyledComponent = styled.div`
width: 100%;
${media.desktop(css`
width: 50%;
`)};
`;
function App() {
return (
<OrbitProvider useId={React.useId} theme={defaultTheme}>
<StyledComponent>This div will be styled.</StyledComponent>
</OrbitProvider>
);
}
NameApplies from width
mediumMobile414px
largeMobile576px
tablet768px
desktop992px
largeDesktop1200px

Breakpoints for testing purposes

const StyledComponent = styled.div`
width: 100%;
${media.desktop(css`
width: 50%;
`)};
import * as React from "react";
import { render } from "@testing-library/react";
import theme from "@kiwicom/orbit-components/lib/defaultTheme";
import { getBreakpointWidth } from "@kiwicom/orbit-components/lib/utils/mediaQuery";
import StyledComponent from "./";
describe("StyledComponent", () => {
it("should have 100% width by default", () => {
render(<StyledComponent data-test="test" />);
expect(screen.getByTestId("test")).toHaveStyleRule("width", "100%");
});
it("should have a width of 50% on a desktop viewport", () => {
render(<StyledComponent data-test="test" />);
expect(screen.getByTestId("test")).toHaveStyleRule("width", "50%", {
media: getBreakpointWidth("desktop", theme),
});
});
});