forked from unocss/unocss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dark.ts
18 lines (16 loc) · 775 Bytes
/
dark.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import type { Variant } from '@unocss/core'
import type { PresetMiniOptions } from '..'
import { variantMatcher, variantParentMatcher } from '../utils'
export const variantColorsMediaOrClass = (options: PresetMiniOptions = {}): Variant[] => {
if (options?.dark === 'class' || options?.dark?.[0] === 'class') {
const { dark = '.dark', light = '.light' } = typeof options.dark === 'string' ? {} : options.dark[1]
return [
variantMatcher('dark', input => ({ prefix: `${dark} $$ ${input.prefix}` })),
variantMatcher('light', input => ({ prefix: `${light} $$ ${input.prefix}` })),
]
}
return [
variantParentMatcher('dark', '@media (prefers-color-scheme: dark)'),
variantParentMatcher('light', '@media (prefers-color-scheme: light)'),
]
}