Skip to content

Commit 36bcaae

Browse files
authored
Add variable.less to support css variable (ant-design#31496)
* chore: use varaible.less * chore: basic primary varaible * chore: Move to variable * chore: align active color * chore: global fix of css variable * chore: primary colors * chore: button danger * chore: btn default error color * chore: button series * chore: More examples * chore: More components * chore: Form demo * chore: form style * fix: Tag & Alert variable * chore: update footer * chore: rm tmp code * chore: transfer * fix: picker column active color * chore: Adjust active bg color * chore: table hover color * chore: all css variables * chore: Global using variables * chore: Test case * chore: Update test logic * chore: back of default less * chore: entry of site use proxy style * chore: update entry * chore: split of variables * refactor: quick dist speed * fix: site use variable version * chore: Update less config * chore: add mv script * chore: Update repalcement script * chore: Add inject variables * chore: Update script * fix: script path * chore: Move to component instead * chore: fix condition * chore: update config * chore: Update in less transform * chore: Modify logic * chore: change to variables * chore: Update name * fix: script name * chore: do inject * revert: back of path * chore: 2 way of generate * bump tools * chore: Add auto replacement script * chore: auto genrate less file * chore: fix test * test: More test case * chore: Update limit config * test: coverage * docs: Update doc
1 parent 9c17f94 commit 36bcaae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2657
-171
lines changed

Diff for: .antd-tools.config.js

+49
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ function finalizeDist() {
9090
buildThemeFile('default', defaultVars);
9191
buildThemeFile('dark', darkVars);
9292
buildThemeFile('compact', compactVars);
93+
buildThemeFile('variable', {});
9394
fs.writeFileSync(
9495
path.join(process.cwd(), 'dist', `theme.js`),
9596
`
@@ -125,8 +126,56 @@ module.exports = {
125126
}
126127
}
127128

129+
function isComponentStyle(file) {
130+
return file.path.match(/style(\/|\\)index\.tsx/);
131+
}
132+
133+
function needTransformStyle(content) {
134+
return content.includes('./index.less');
135+
}
136+
128137
module.exports = {
129138
compile: {
139+
transformTSFile(file) {
140+
if (isComponentStyle(file)) {
141+
let content = file.contents.toString();
142+
143+
if (needTransformStyle(content)) {
144+
const cloneFile = file.clone();
145+
146+
// Origin
147+
content = content.replace('./index.less', './index-default.less');
148+
cloneFile.contents = Buffer.from(content);
149+
150+
return cloneFile;
151+
}
152+
}
153+
},
154+
transformFile(file) {
155+
if (isComponentStyle(file)) {
156+
const content = file.contents.toString();
157+
158+
if (needTransformStyle(content)) {
159+
const cloneFile = file.clone();
160+
cloneFile.contents = Buffer.from(
161+
[
162+
// Inject variable
163+
'@root-entry-name: default',
164+
// Point to origin file
165+
"@import './index';",
166+
].join('\n\n'),
167+
);
168+
cloneFile.path = cloneFile.path.replace('index.tsx', 'index-default.less');
169+
return cloneFile;
170+
}
171+
}
172+
return [];
173+
},
174+
lessConfig: {
175+
modifyVars: {
176+
'root-entry-name': 'default',
177+
},
178+
},
130179
finalize: finalizeCompile,
131180
},
132181
dist: {

Diff for: components/affix/__tests__/Affix.test.tsx

+3-6
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,8 @@ describe('Affix Render', () => {
206206

207207
// Mock trigger resize
208208
updateCalled.mockReset();
209-
const resizeObserverInstance: ReactWrapper<
210-
HTMLAttributes,
211-
unknown,
212-
ResizeObserverImpl
213-
> = affixMounterWrapper.find('ResizeObserver') as any;
209+
const resizeObserverInstance: ReactWrapper<HTMLAttributes, unknown, ResizeObserverImpl> =
210+
affixMounterWrapper.find('ResizeObserver') as any;
214211
resizeObserverInstance
215212
.at(index)
216213
.instance()
@@ -225,7 +222,7 @@ describe('Affix Render', () => {
225222
contentBoxSize: [],
226223
},
227224
],
228-
({} as unknown) as ResizeObserver,
225+
{} as unknown as ResizeObserver,
229226
);
230227
await sleep(20);
231228

Diff for: components/button/style/index.less

+4-4
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,19 @@
207207
}
208208

209209
&-background-ghost&-primary {
210-
.button-variant-ghost(@btn-primary-bg);
210+
.button-variant-ghost(@btn-primary-bg, @btn-primary-bg, @primary-color-hover, @primary-color-active);
211211
}
212212

213213
&-background-ghost&-danger {
214-
.button-variant-ghost(@btn-danger-border);
214+
.button-variant-ghost(@btn-danger-border, @btn-danger-border, @error-color-hover, @error-color-active);
215215
}
216216

217217
&-background-ghost&-dangerous {
218-
.button-variant-ghost(@btn-danger-border);
218+
.button-variant-ghost(@btn-danger-border, @btn-danger-border, @error-color-hover, @error-color-active);
219219
}
220220

221221
&-background-ghost&-dangerous&-link {
222-
.button-variant-ghost(@btn-danger-border, transparent);
222+
.button-variant-ghost(@btn-danger-border, transparent, @error-color-hover, @error-color-active);
223223
}
224224

225225
&-two-chinese-chars::first-letter {

0 commit comments

Comments
 (0)