Skip to content

Commit 886fc86

Browse files
committed
Add option to disable specific features
1 parent 09b26dd commit 886fc86

File tree

4 files changed

+94
-12
lines changed

4 files changed

+94
-12
lines changed

src/preset.ts

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,56 @@ const largerThanMixin = (_mixin: string, breakpoint: string) => ({
127127
},
128128
});
129129

130-
interface Options {
130+
export interface Options {
131131
autoRem?: boolean;
132132
mixins?: Record<string, any>;
133+
features?: {
134+
lightDarkFunction?: boolean;
135+
nested?: boolean;
136+
colorMixAlpha?: boolean;
137+
remEmFunctions?: boolean;
138+
mixins?: boolean;
139+
};
133140
}
134141

142+
const defaultFeatures = {
143+
lightDarkFunction: true,
144+
nested: true,
145+
colorMixAlpha: true,
146+
remEmFunctions: true,
147+
mixins: true,
148+
};
149+
135150
module.exports = (options: Options = {}) => {
151+
const features = {
152+
...defaultFeatures,
153+
...(options.features || {}),
154+
};
155+
136156
const plugins = [];
137157

138158
if (options.autoRem) {
139159
plugins.push(autorem());
140160
}
141161

142-
return {
143-
postcssPlugin: 'postcss-preset-mantine',
144-
plugins: [
145-
lightDark(),
146-
nested(),
147-
colorMixAlpha(),
148-
remEm(),
149-
...plugins,
162+
if (features.lightDarkFunction) {
163+
plugins.push(lightDark());
164+
}
165+
166+
if (features.nested) {
167+
plugins.push(nested());
168+
}
169+
170+
if (features.colorMixAlpha) {
171+
plugins.push(colorMixAlpha());
172+
}
173+
174+
if (features.remEmFunctions) {
175+
plugins.push(remEm());
176+
}
177+
178+
if (features.mixins) {
179+
plugins.push(
150180
mixins({
151181
mixins: {
152182
light: colorSchemeMixin('light'),
@@ -171,8 +201,13 @@ module.exports = (options: Options = {}) => {
171201
'larger-than': largerThanMixin,
172202
...(options.mixins || {}),
173203
},
174-
}),
175-
],
204+
})
205+
);
206+
}
207+
208+
return {
209+
postcssPlugin: 'postcss-preset-mantine',
210+
plugins,
176211
};
177212
};
178213

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`disabled-features does not transform light/dark if lightDarkFunction is disabled 1`] = `
4+
"
5+
.card {
6+
color: light-dark(#000, #fff);
7+
}
8+
"
9+
`;
10+
11+
exports[`disabled-features does not transform rem if rem function is disabled 1`] = `
12+
"
13+
.card {
14+
padding: rem(32px);
15+
}
16+
"
17+
`;

src/tests/disabled-features.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { testTransform } from './utils';
2+
3+
const rem = `
4+
.card {
5+
padding: rem(32px);
6+
}
7+
`;
8+
9+
const lightDark = `
10+
.card {
11+
color: light-dark(#000, #fff);
12+
}
13+
`;
14+
15+
describe('disabled-features', () => {
16+
it('does not transform rem if rem function is disabled', async () => {
17+
const res = await testTransform(rem, {
18+
features: { remEmFunctions: false },
19+
});
20+
expect(res.css).toMatchSnapshot();
21+
});
22+
23+
it('does not transform light/dark if lightDarkFunction is disabled', async () => {
24+
const res = await testTransform(lightDark, {
25+
features: { lightDarkFunction: false },
26+
});
27+
expect(res.css).toMatchSnapshot();
28+
});
29+
});

src/tests/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import postcss from 'postcss';
2+
import type { Options } from '../preset';
23
const preset = require('../preset');
34

4-
export function testTransform(input: string, options?: Record<string, any>) {
5+
export function testTransform(input: string, options?: Options) {
56
return postcss([preset(options)]).process(input, { from: undefined });
67
}

0 commit comments

Comments
 (0)