A utility function for adding reusable media queries and breakpoints to @dash-ui styles
npm install @dash-ui/mq
> A utility function for adding reusable media queries and breakpoints to @dash-ui styles
``sh`
npm i @dash-ui/mq
---
Check out an example on CodeSandbox
`js
import mq from "@dash-ui/mq";
import { styles } from "@dash-ui/styles";
const breakpoint = mq(styles, {
// 0px
sm: "only screen and (min-width: 0em)",
// 560px
mq: "only screen and (min-width: 35em)",
// 1280px
lg: "only screen and (min-width: 80em)",
});
const box = styles.one(
breakpoint({
sm: ({ color }) => ({
width: 100,
height: 100,
backgroundColor: color.primary,
}),
md: ({ color }) => ({
width: 200,
height: 200,
backgroundColor: color.primary,
}),
lg: ({ color }) => ({
width: 400,
height: 400,
backgroundColor: color.primary,
}),
})
);
export const Component = () =>
;API
$3
A factory function that creates a utility for adding breakpoints and
media queries to Dash styles.
#### Example
`tsx
import mq from "@dash-ui/mq";
import { styles } from "@dash-ui/styles";// Creates the stored media queries
const breakpoint = mq(styles, {
sm: "only screen and (min-width: 0em)",
mq: "only screen and (min-width: 35em)",
lg: "only screen and (min-width: 80em)",
});
// Can be used as a shortcut for
@media ...
const boxOne = styles.one /**
* This box will be 400x400 when "md" breakpoint matches
*/
${breakpoint("md")} {
width: 400px;
height: 400px;
};
// Can be used like a style mapping
const boxTwo = styles.one(
breakpoint({
// This box will always have a primary color backgroundsm
default: ({ color }) => ({
backgroundColor: color.primary,
}),
// This box will be 100x100 when media query is matchedmd
sm: {
width: 100,
height: 100,
},
// This box will be 200x200 when media query is matched
md:
width: 200px;
height: 200px;
,lg
// This box will be 400x400 when media query is matched
lg:
width: 400px;
height: 400px
,
})
);
const Component = () => (
);
`
#### Arguments
`typescript`
function mq<
Tokens extends DashTokens = DashTokens,
Themes extends DashThemes = DashThemes,
QueryNames extends string = string
>(
styles: Styles
mediaQueries: MediaQueries
): {
(queryName: QueryNames): string;
(queryName: MediaQueryObject
};
| Argument | Type | Required? | Description |
| ------------ | -------------------------------------- | --------- | ------------------------------------- |
| styles | styles | Yes | A Dash styles instance |{readonly [K in QueryNames]: string}
| mediaQueries | | Yes | A map of media query name/query pairs |
#### Returns
`typescriptstring
// When a is provided as the mediaQueries argument, thisMediaQueryNameCallback
// will return a , otherwise a MediaQueryCssCallback``
function mqStyles(queryName: QueryNames): string;
function mqStyles(
queryName: MediaQueryObject
): string;
MIT