(mediaQuery: MediaQuery, ...objects: (NestedCSSProperties | undefined | null | false)[])
| 73 | * ``` |
| 74 | */ |
| 75 | export const media = (mediaQuery: MediaQuery, ...objects: (NestedCSSProperties | undefined | null | false)[]): NestedCSSProperties => { |
| 76 | const mediaQuerySections: string[] = []; |
| 77 | if (mediaQuery.type) mediaQuerySections.push(mediaQuery.type); |
| 78 | if (mediaQuery.orientation) mediaQuerySections.push(`(orientation: ${mediaQuery.orientation})`); |
| 79 | if (mediaQuery.minWidth) mediaQuerySections.push(`(min-width: ${mediaLength(mediaQuery.minWidth)})`); |
| 80 | if (mediaQuery.maxWidth) mediaQuerySections.push(`(max-width: ${mediaLength(mediaQuery.maxWidth)})`); |
| 81 | if (mediaQuery.minHeight) mediaQuerySections.push(`(min-height: ${mediaLength(mediaQuery.minHeight)})`); |
| 82 | if (mediaQuery.maxHeight) mediaQuerySections.push(`(max-height: ${mediaLength(mediaQuery.maxHeight)})`); |
| 83 | if (mediaQuery.prefersColorScheme) mediaQuerySections.push(`(prefers-color-scheme: ${mediaQuery.prefersColorScheme})`); |
| 84 | |
| 85 | const stringMediaQuery = `@media ${mediaQuerySections.join(' and ')}`; |
| 86 | |
| 87 | const object: NestedCSSProperties = { |
| 88 | $nest: { |
| 89 | [stringMediaQuery]: extend(...objects) |
| 90 | } |
| 91 | }; |
| 92 | return object; |
| 93 | } |
| 94 | |
| 95 | const mediaLength = (value: number | string) => |
| 96 | typeof value === 'string' ? value : `${value}px`; |
no test coverage detected
searching dependent graphs…