File tree Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Expand file tree Collapse file tree 3 files changed +24
-14
lines changed Original file line number Diff line number Diff line change 1
- import type { DefaultColors } from 'tailwindcss/types/generated/colors'
1
+ import { Colors } from './type'
2
+
2
3
export { defineColorVariables } from './plugin'
3
4
4
5
type VariableColors = {
5
- [ key in keyof DefaultColors ] : DefaultColors [ key ] extends `#${string } `
6
+ [ key in keyof Colors ] : Colors [ key ] extends `#${string } `
6
7
? `rgb(var(--tw-color-${key } ) / <alpha-value>)`
7
- : DefaultColors [ key ] extends string
8
+ : Colors [ key ] extends string
8
9
? // has no uppercase letter
9
- DefaultColors [ key ] extends Lowercase < DefaultColors [ key ] >
10
+ Colors [ key ] extends Lowercase < Colors [ key ] >
10
11
? key
11
- : DefaultColors [ key ]
12
+ : Colors [ key ]
12
13
: {
13
- [ level in keyof DefaultColors [ key ] ] : level extends string | number
14
+ [ level in keyof Colors [ key ] ] : level extends string | number
14
15
? `rgb(var(--tw-color-${key } -${level } ) / <alpha-value>)`
15
16
: never
16
17
}
17
18
}
18
19
19
- export function createVariableColors ( colors : DefaultColors ) {
20
+ export function createVariableColors < T extends Colors > ( colors : T ) {
20
21
const variableColors = { } as any
21
22
22
23
for ( const [ key , value ] of Object . entries ( colors ) ) {
@@ -26,9 +27,7 @@ export function createVariableColors(colors: DefaultColors) {
26
27
variableColors [ key ] = value
27
28
} else {
28
29
// key color
29
- variableColors [
30
- key
31
- ] = `rgb(var(--tw-color-${ key } ) / <alpha-value>)`
30
+ variableColors [ key ] = `rgb(var(--tw-color-${ key } ) / <alpha-value>)`
32
31
}
33
32
} else {
34
33
// tonal palette
Original file line number Diff line number Diff line change 1
1
import plugin from 'tailwindcss/plugin'
2
- import { DefaultColors } from 'tailwindcss/types/generated/colors'
3
2
import {
4
3
argbFromHex ,
5
4
redFromArgb ,
6
5
greenFromArgb ,
7
6
blueFromArgb ,
8
7
} from '@material/material-color-utilities'
8
+ import { Colors } from './type'
9
9
10
10
interface Options {
11
11
mode ?: 'invert'
12
12
}
13
- export function defineColorVariables (
14
- colors : DefaultColors ,
13
+ export function defineColorVariables < T extends Colors > (
14
+ colors : T ,
15
15
options : Options = { } ,
16
16
) {
17
17
return plugin ( ( { addBase } ) => {
@@ -21,7 +21,7 @@ export function defineColorVariables(
21
21
} )
22
22
}
23
23
24
- export function createColorVariables ( colors : DefaultColors ) {
24
+ export function createColorVariables < T extends Colors > ( colors : T ) {
25
25
const colorVariables = { } as any
26
26
const darkColorVariables = { } as any
27
27
Original file line number Diff line number Diff line change
1
+ import { DefaultColors } from 'tailwindcss/types/generated/colors'
2
+
3
+ type T = {
4
+ [ key : string ] : string
5
+ }
6
+
7
+ export type Colors =
8
+ | DefaultColors
9
+ | {
10
+ [ key : string ] : string | T
11
+ }
You can’t perform that action at this time.
0 commit comments