Skip to content

Commit

Permalink
Add variable.less to support css variable (#31496)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zombieJ committed Sep 1, 2021
1 parent 9c17f94 commit 36bcaae
Show file tree
Hide file tree
Showing 60 changed files with 2,657 additions and 171 deletions.
49 changes: 49 additions & 0 deletions .antd-tools.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function finalizeDist() {
buildThemeFile('default', defaultVars);
buildThemeFile('dark', darkVars);
buildThemeFile('compact', compactVars);
buildThemeFile('variable', {});
fs.writeFileSync(
path.join(process.cwd(), 'dist', `theme.js`),
`
Expand Down Expand Up @@ -125,8 +126,56 @@ module.exports = {
}
}

function isComponentStyle(file) {
return file.path.match(/style(\/|\\)index\.tsx/);
}

function needTransformStyle(content) {
return content.includes('./index.less');
}

module.exports = {
compile: {
transformTSFile(file) {
if (isComponentStyle(file)) {
let content = file.contents.toString();

if (needTransformStyle(content)) {
const cloneFile = file.clone();

// Origin
content = content.replace('./index.less', './index-default.less');
cloneFile.contents = Buffer.from(content);

return cloneFile;
}
}
},
transformFile(file) {
if (isComponentStyle(file)) {
const content = file.contents.toString();

if (needTransformStyle(content)) {
const cloneFile = file.clone();
cloneFile.contents = Buffer.from(
[
// Inject variable
'@root-entry-name: default',
// Point to origin file
"@import './index';",
].join('\n\n'),
);
cloneFile.path = cloneFile.path.replace('index.tsx', 'index-default.less');
return cloneFile;
}
}
return [];
},
lessConfig: {
modifyVars: {
'root-entry-name': 'default',
},
},
finalize: finalizeCompile,
},
dist: {
Expand Down
9 changes: 3 additions & 6 deletions components/affix/__tests__/Affix.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,8 @@ describe('Affix Render', () => {

// Mock trigger resize
updateCalled.mockReset();
const resizeObserverInstance: ReactWrapper<
HTMLAttributes,
unknown,
ResizeObserverImpl
> = affixMounterWrapper.find('ResizeObserver') as any;
const resizeObserverInstance: ReactWrapper<HTMLAttributes, unknown, ResizeObserverImpl> =
affixMounterWrapper.find('ResizeObserver') as any;
resizeObserverInstance
.at(index)
.instance()
Expand All @@ -225,7 +222,7 @@ describe('Affix Render', () => {
contentBoxSize: [],
},
],
({} as unknown) as ResizeObserver,
{} as unknown as ResizeObserver,
);
await sleep(20);

Expand Down
8 changes: 4 additions & 4 deletions components/button/style/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,19 @@
}

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

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

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

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

&-two-chinese-chars::first-letter {
Expand Down
Loading

0 comments on commit 36bcaae

Please sign in to comment.