-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
…en and less-to-token transformer
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,36 @@ | ||
const { toLower } = require('lodash'); | ||
const { isString, fromPairs, toLower } = require('lodash'); | ||
const { default: defaultTheme } = require('@oceanbase/design/lib/theme/default'); | ||
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/less-to-token.test.ts
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/function-component" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/class-component" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/block-statement" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/nested-block-statement" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/existed-useToken" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/top-identifier" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/style-to-token.test.ts > style-to-token > style-to-token > transforms correctly using "style-to-token/case-insensitive" data
Check failure on line 2 in packages/codemod/transforms/utils/token.js GitHub Actions / test (16.x, ubuntu-latest)transforms/__tests__/token.test.ts
|
||
|
||
const token = defaultTheme.token; | ||
|
||
const tokenMap = fromPairs( | ||
Object.keys(token) | ||
.filter(key => | ||
// filter token by token key | ||
key.startsWith('color') | ||
) | ||
.filter( | ||
key => | ||
// filter token by token value | ||
isString(token[key]) && !!token[key] | ||
) | ||
.map(key => { | ||
return [token[key], key]; | ||
}) | ||
// sort by token value and token key length | ||
.sort((a, b) => { | ||
if (a[0] > b[0]) { | ||
return 1; | ||
} else if (a[0] < b[0]) { | ||
return -1; | ||
} | ||
return a[1]?.length > b[1]?.length ? -1 : a[1]?.length < b[1]?.length ? 1 : 0; | ||
}) | ||
); | ||
|
||
const TOKEN_MAP = { | ||
// obui 3.x style => token | ||
...tokenMap, | ||
// antd style => token | ||
'#1677ff': 'colorInfo', | ||
'#1890ff': 'colorInfo', | ||
|
@@ -51,8 +81,7 @@ const TOKEN_MAP = { | |
'rgba(0,0,0,0.04)': 'colorBgLayout', | ||
'#f5f6fa': 'colorBgLayout', | ||
'#edeff2': 'colorBgLayout', | ||
// obui style => token | ||
'#006aff': 'colorInfo', | ||
// obui legacy style => token | ||
'#086fff': 'colorInfo', | ||
'rgba(24,144,255,0.1)': 'colorInfoBg', | ||
'rgba(95,149,255,0.10)': 'colorInfoBg', | ||
|