Skip to content

Commit

Permalink
Merge pull request #539 from oceanbase/zhuyue-dev
Browse files Browse the repository at this point in the history
feat(codemod): Add @oceanbase/design color token map for style-to-token and less-to-token transformer
  • Loading branch information
dengfuping authored Apr 3, 2024
2 parents 6493aa8 + d8850e2 commit 6f1485f
Show file tree
Hide file tree
Showing 5 changed files with 4,552 additions and 13,481 deletions.
1 change: 1 addition & 0 deletions packages/codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"build": "father build"
},
"dependencies": {
"@oceanbase/design": "workspace:^",
"chalk": "^3.0.0",
"command-exists": "^1.2.9",
"execa": "^5.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Alert, Button, Tooltip } from '@oceanbase/design';

const Demo = () => {
const tokenList = ['rgb(0 0 0 / 45%)'];
const tokenList = ['rgb(0 0 0 / 45%)', '#006AFF', '#f3f6fc'];
return (
<div>
<Alert style={{ color: 'rgba(0, 0, 0, 0.85)', background: 'rgba(0, 0, 0,0.65)', backgroundColor: 'rgba(0,0,0,0.45)', border: '1px solid #d9d9d9' }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Alert, Button, theme, Tooltip } from '@oceanbase/design';

const Demo = () => {
const { token } = theme.useToken();
const tokenList = [token.colorTextTertiary];
const tokenList = [token.colorTextTertiary, token.colorInfo, token.colorBgLayout];
return (
(<div>
<Alert style={{ color: token.colorText, background: token.colorTextSecondary, backgroundColor: token.colorTextTertiary, border: `1px solid ${token.colorBorder}` }} />
Expand Down
35 changes: 32 additions & 3 deletions packages/codemod/transforms/utils/token.js
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');

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',
Expand Down Expand Up @@ -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',
Expand Down
Loading

0 comments on commit 6f1485f

Please sign in to comment.