Skip to content

Commit 0d10706

Browse files
committed
feat: opacity from theme
1 parent 308346c commit 0d10706

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/createFile.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
import fs from 'fs';
44
import isEmpty from 'lodash.isempty';
5-
import { baseTemplateString, defaultColors, defaultScreens, defaultSpacing, generateTypes } from './utils';
5+
import {
6+
baseTemplateString,
7+
defaultColors,
8+
defaultScreens,
9+
defaultSpacing,
10+
defaultOpacities,
11+
generateTypes,
12+
} from './utils';
613

714
interface IOptions {
815
configFilename: string;
@@ -58,6 +65,11 @@ export function createFileWithGeneratedTypes({ configFilename, outputFilename }:
5865
}
5966
}
6067

68+
const themeOpacities = isEmpty(THEME_CONFIG?.opacity) ? defaultOpacities : THEME_CONFIG?.opacity;
69+
const extendedThemeOpacities = THEME_CONFIG?.extend?.opacity;
70+
const allOpacities = extendedThemeOpacities ? { ...themeOpacities, ...extendedThemeOpacities } : themeOpacities;
71+
const opacities = Object.keys(allOpacities).map(opacity => `${prefix}opacity-${opacity}`);
72+
6173
const themeBreakpoints = isEmpty(THEME_CONFIG?.screens) ? defaultScreens : THEME_CONFIG?.screens;
6274
const extendedThemeBreakpoints = THEME_CONFIG?.extend?.screens;
6375
const breakpoints = extendedThemeBreakpoints
@@ -121,7 +133,8 @@ export function createFileWithGeneratedTypes({ configFilename, outputFilename }:
121133
.replace(/BACKGROUND_COLORS/g, generateTypes(backgroundColors))
122134
.replace(/PLACEHOLDER_COLORS/g, generateTypes(placeholderColors))
123135
.replace(/BORDER_COLORS/g, generateTypes(borderColors))
124-
.replace(/TEXT_COLORS/g, generateTypes(textColors));
136+
.replace(/TEXT_COLORS/g, generateTypes(textColors))
137+
.replace(/OPACITIES/g, generateTypes(opacities));
125138

126139
fs.writeFile(`${outputFilename}`, result, 'utf8', error => {
127140
if (error) {

src/utils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ export const defaultSpacing = {
151151
'64': '16rem',
152152
};
153153

154+
export const defaultOpacities = {
155+
'0': '0',
156+
'25': '0.25',
157+
'50': '0.5',
158+
'75': '0.75',
159+
'100': '1',
160+
};
161+
154162
export const baseTemplateString = `
155163
import classnamesLib from 'classnames';
156164
@@ -755,7 +763,7 @@ export type TBoxShadow =
755763
| '_PREFIX_shadow-outline'
756764
| '_PREFIX_shadow-none';
757765
758-
export type TOpacity = '_PREFIX_opacity-100' | '_PREFIX_opacity-75' | '_PREFIX_opacity-50' | '_PREFIX_opacity-25' | '_PREFIX_opacity-0';
766+
export type TOpacity =OPACITIES;
759767
760768
export type TEffects = TBoxShadow | TOpacity;
761769

0 commit comments

Comments
 (0)