Skip to content

Commit 5e2ca0a

Browse files
committed
refactor: use providers instead of static methods
1 parent 6596cf4 commit 5e2ca0a

15 files changed

+937
-224
lines changed

src/deprecated/ColorTokens.ts

Lines changed: 0 additions & 209 deletions
This file was deleted.

src/tokens/color.ts renamed to src/deprecated/color.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import plugin from 'tailwindcss/plugin.js'
22

3+
/**
4+
* @deprecated
5+
* Use provideColor() instead of Color
6+
*/
37
export class Color {
48
public static colorPrefix = 'md-sys-color'
59
public static setDefaultVariantPrefix(prefix: string) {
@@ -205,7 +209,7 @@ export class Color {
205209
'color': `var(--${this.colorPrefix}-shadow, #000000)`,
206210
},
207211
})
208-
212+
209213
/**
210214
* Border
211215
*/
@@ -217,7 +221,7 @@ export class Color {
217221
'border-color': `var(--${this.colorPrefix}-outline-variant, #c2c6d6)`,
218222
},
219223
})
220-
224+
221225
/**
222226
* Containers, background-color only.
223227
*/
@@ -238,7 +242,7 @@ export class Color {
238242
'background-color': `var(--${this.colorPrefix}-surface-container-highest, #dfe2ef)`,
239243
},
240244
})
241-
245+
242246
/**
243247
* Fixed colors
244248
*/

src/tokens/elevation.ts renamed to src/deprecated/elevation.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import plugin from 'tailwindcss/plugin.js'
22

3+
/**
4+
* @deprecated
5+
* Use provideElevation() instead of Elevation
6+
*/
37
export class Elevation {
48

59
public static readonly plugin = plugin(({ addUtilities }) => {
@@ -25,4 +29,4 @@ export class Elevation {
2529
})
2630
})
2731

28-
}
32+
}

src/tokens/motion.ts renamed to src/deprecated/motion.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import plugin from 'tailwindcss/plugin'
22

3+
/**
4+
* @deprecated
5+
* Use provideMotion() instead of Motion
6+
*/
37
export class Motion {
48
private static motionPrefix = 'md-sys-motion'
59
public static setDefaultVariantPrefix(prefix: string) {
@@ -106,4 +110,4 @@ export class Motion {
106110
})
107111
})
108112

109-
}
113+
}

src/tokens/shape.ts renamed to src/deprecated/shape.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import plugin from 'tailwindcss/plugin'
22

3+
/**
4+
* @deprecated
5+
* Use provideShape() instead of Shape
6+
*/
37
export class Shape {
48

59
public static readonly plugin = plugin(({ addUtilities }) => {
@@ -154,4 +158,4 @@ export class Shape {
154158
})
155159
})
156160

157-
}
161+
}

src/tokens/typography.ts renamed to src/deprecated/typography.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import plugin from 'tailwindcss/plugin.js'
22

3+
/**
4+
* @deprecated
5+
* Use provideTypography() instead of Typography
6+
*/
37
export class Typography {
48

59
private static typescalePrefix = 'md-sys-typescale'
610
public static setDefaultVariantPrefix(prefix: string) {
711
this.typescalePrefix = prefix
812
return this
913
}
10-
14+
1115
public static readonly plugin = plugin(({ addComponents }) => {
1216
addComponents({
1317
'.display-large': {
@@ -106,5 +110,5 @@ export class Typography {
106110
},
107111
})
108112
})
109-
110-
}
113+
114+
}

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/**
22
* @deprecated
33
*/
4-
export * from './deprecated/ColorTokens'
4+
export * from './deprecated/color'
5+
export * from './deprecated/elevation'
6+
export * from './deprecated/motion'
7+
export * from './deprecated/shape'
8+
export * from './deprecated/typography'
59

610
export * from './tokens/index'

src/tokens/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

2-
export * from './color'
3-
export * from './elevation'
4-
export * from './shape'
5-
export * from './motion'
6-
export * from './typography'
2+
export * from './provide-all'
3+
export * from './provide-color'
4+
export * from './provide-elevation'
5+
export * from './provide-motion'
6+
export * from './provide-shape'
7+
export * from './provide-typography'

src/tokens/provide-all.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { provideColor, type TColorProviderConstructor } from "./provide-color";
2+
import { provideElevation, type TElevationProviderConstructor } from "./provide-elevation";
3+
import { provideMotion, type TMotionProviderConstructor } from "./provide-motion";
4+
import { provideShape, type TShapeProviderConstructor } from "./provide-shape";
5+
import { provideTypography, type TTypographyProviderConstructor } from "./provide-typography";
6+
7+
export function provideAll(params: {
8+
color?: TColorProviderConstructor,
9+
elevation?: TElevationProviderConstructor,
10+
motion?: TMotionProviderConstructor,
11+
shape?: TShapeProviderConstructor,
12+
typography?: TTypographyProviderConstructor,
13+
} = {
14+
color: { prefix: 'md-sys-color' },
15+
elevation: { shadowToken: 'md-sys-color-shadow' },
16+
motion: { prefix: 'md-sys-motion' },
17+
shape: { prefix: 'md-sys-shape', defaultUnit: '1' },
18+
typography: { prefix: 'md-sys-typescale' }
19+
}) {
20+
return ({
21+
color: provideColor(params.color),
22+
elevation: provideElevation(params.elevation),
23+
motion: provideMotion(params.motion),
24+
shape: provideShape(params.shape),
25+
typography: provideTypography(params.typography),
26+
allPlugins() {
27+
return ([
28+
this.color.getPlugin(),
29+
this.elevation.getPlugin(),
30+
this.motion.getPlugin(),
31+
this.shape.getPlugin(),
32+
this.typography.getPlugin(),
33+
])
34+
}
35+
})
36+
}

0 commit comments

Comments
 (0)