feat: 自行开发设计 ui样式优化 超管端-控制台 相关的页面
This commit is contained in:
@@ -28,7 +28,10 @@ import { renderToStaticMarkup } from 'react-dom/server';
|
||||
import * as Ant from 'antd';
|
||||
import { transformWithEsbuild } from 'vite';
|
||||
|
||||
const css = readFileSync(new URL('../src/styles/prototype.css', import.meta.url), 'utf8');
|
||||
const css = readFileSync(
|
||||
new URL('../src/styles/prototype.css', import.meta.url),
|
||||
'utf8',
|
||||
);
|
||||
const root = postcss.parse(css);
|
||||
|
||||
const normalizeSelector = (selector) => selector.replace(/\s+/g, ' ').trim();
|
||||
@@ -70,14 +73,18 @@ test('standard modal bodies only scroll vertically', () => {
|
||||
});
|
||||
|
||||
test('fixed-width modal shells stay inside the viewport', () => {
|
||||
assert.equal(declarations(findRule('.ant-modal'))['max-width'], 'calc(100vw - 32px)');
|
||||
assert.equal(declarations(findRule('.viewport-preview-modal.ant-modal'))['max-width'], '100vw');
|
||||
assert.equal(
|
||||
declarations(findRule('.ant-modal'))['max-width'],
|
||||
'calc(100vw - 32px)',
|
||||
);
|
||||
assert.equal(
|
||||
declarations(findRule('.viewport-preview-modal.ant-modal'))['max-width'],
|
||||
'100vw',
|
||||
);
|
||||
});
|
||||
|
||||
test('headerless viewport previews override standard body overflow', () => {
|
||||
const rule = findRule(
|
||||
'.viewport-preview-modal .ant-modal-body',
|
||||
);
|
||||
const rule = findRule('.viewport-preview-modal .ant-modal-body');
|
||||
assert.deepEqual(
|
||||
{
|
||||
maxWidth: declarations(rule)['max-width'],
|
||||
@@ -89,28 +96,64 @@ test('headerless viewport previews override standard body overflow', () => {
|
||||
});
|
||||
|
||||
const file = new URL('../src/components/ui/form.jsx', import.meta.url);
|
||||
const { code } = await transformWithEsbuild(await readFile(file, 'utf8'), file.pathname, {
|
||||
loader: 'jsx', format: 'cjs', jsx: 'transform',
|
||||
});
|
||||
const { code } = await transformWithEsbuild(
|
||||
await readFile(file, 'utf8'),
|
||||
file.pathname,
|
||||
{
|
||||
loader: 'jsx',
|
||||
format: 'cjs',
|
||||
jsx: 'transform',
|
||||
},
|
||||
);
|
||||
const module = { exports: {} };
|
||||
runInNewContext(code, {
|
||||
module, exports: module.exports,
|
||||
module,
|
||||
exports: module.exports,
|
||||
require(name) {
|
||||
if (name === 'react') return React;
|
||||
if (name === 'antd') return Ant;
|
||||
if (name === './controls') return Object.fromEntries(
|
||||
['Input', 'TextArea', 'InputNumber', 'Select', 'DatePicker', 'TimePicker', 'RadioGroup', 'CheckboxGroup', 'TagInput', 'TreeSelect', 'AutoComplete', 'Upload', 'Switch'].map(key => [key, Ant.Input]),
|
||||
);
|
||||
if (name === '../console/ConsoleContext')
|
||||
return { useConsolePage: () => null };
|
||||
if (name === '../console/ConsolePrimitives') return {};
|
||||
if (name === './controls')
|
||||
return Object.fromEntries(
|
||||
[
|
||||
'Input',
|
||||
'TextArea',
|
||||
'InputNumber',
|
||||
'Select',
|
||||
'DatePicker',
|
||||
'TimePicker',
|
||||
'RadioGroup',
|
||||
'CheckboxGroup',
|
||||
'TagInput',
|
||||
'TreeSelect',
|
||||
'AutoComplete',
|
||||
'Upload',
|
||||
'Switch',
|
||||
].map((key) => [key, Ant.Input]),
|
||||
);
|
||||
throw new Error(`Unexpected dependency: ${name}`);
|
||||
},
|
||||
});
|
||||
const { Form } = module.exports;
|
||||
const render = (props) => renderToStaticMarkup(
|
||||
React.createElement(Form, { labelPosition: 'left', ...props },
|
||||
React.createElement(Form.Input, { field: 'sample', label: 'Setting label' })),
|
||||
);
|
||||
const render = (props) =>
|
||||
renderToStaticMarkup(
|
||||
React.createElement(
|
||||
Form,
|
||||
{ labelPosition: 'left', ...props },
|
||||
React.createElement(Form.Input, {
|
||||
field: 'sample',
|
||||
label: 'Setting label',
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
for (const [width, css] of [[180, '180px'], ['120px', '120px'], ['25%', '25%']]) {
|
||||
for (const [width, css] of [
|
||||
[180, '180px'],
|
||||
['120px', '120px'],
|
||||
['25%', '25%'],
|
||||
]) {
|
||||
test(`form label width ${width} keeps its unit and cannot grow across the row`, () => {
|
||||
const html = render({ labelWidth: width });
|
||||
assert.ok(html.includes(`flex:0 0 ${css}`));
|
||||
@@ -118,7 +161,11 @@ for (const [width, css] of [[180, '180px'], ['120px', '120px'], ['25%', '25%']])
|
||||
});
|
||||
}
|
||||
test('explicit Ant Design column settings take precedence over legacy labelWidth', () => {
|
||||
const html = render({ labelWidth: 180, labelCol: { flex: '0 0 96px' }, wrapperCol: { flex: '1 1 240px' } });
|
||||
const html = render({
|
||||
labelWidth: 180,
|
||||
labelCol: { flex: '0 0 96px' },
|
||||
wrapperCol: { flex: '1 1 240px' },
|
||||
});
|
||||
assert.ok(html.includes('flex:0 0 96px'));
|
||||
assert.ok(html.includes('flex:1 1 240px'));
|
||||
assert.ok(!html.includes('flex:0 0 180px'));
|
||||
@@ -129,20 +176,44 @@ test('vertical forms without label widths keep the default Ant layout', () => {
|
||||
assert.ok(!html.includes('flex:0 0'));
|
||||
});
|
||||
|
||||
const stylesheet = postcss.parse(await readFile(new URL('../src/pages/Setting/Setting.css', import.meta.url), 'utf8'));
|
||||
const stylesheet = postcss.parse(
|
||||
await readFile(
|
||||
new URL('../src/pages/Setting/Setting.css', import.meta.url),
|
||||
'utf8',
|
||||
),
|
||||
);
|
||||
test('settings labels stack on narrow screens without overriding inline flex declarations', () => {
|
||||
let mobileRule;
|
||||
stylesheet.walkRules(rule => {
|
||||
if (rule.selectors.includes('.settings-page .ant-form-horizontal .ant-form-item-row')) mobileRule = rule;
|
||||
stylesheet.walkRules((rule) => {
|
||||
if (
|
||||
rule.selectors.includes(
|
||||
'.settings-page .ant-form-horizontal .ant-form-item-row',
|
||||
)
|
||||
)
|
||||
mobileRule = rule;
|
||||
});
|
||||
assert.ok(mobileRule.selectors.includes('.settings-form-dialog .ant-form-horizontal .ant-form-item-row'));
|
||||
assert.ok(
|
||||
mobileRule.selectors.includes(
|
||||
'.settings-form-dialog .ant-form-horizontal .ant-form-item-row',
|
||||
),
|
||||
);
|
||||
assert.match(mobileRule.parent.params, /max-width: 767px/);
|
||||
assert.ok(mobileRule.nodes.some(node => node.prop === 'display' && node.value === 'block'));
|
||||
assert.ok(
|
||||
mobileRule.nodes.some(
|
||||
(node) => node.prop === 'display' && node.value === 'block',
|
||||
),
|
||||
);
|
||||
});
|
||||
test('settings layout rules stay scoped and use the existing scrollbar policy', () => {
|
||||
stylesheet.walkRules(rule => {
|
||||
assert.ok(rule.selectors.every(selector => selector.startsWith('.settings-page') || selector.startsWith('.settings-form-dialog')));
|
||||
rule.walkDecls(decl => {
|
||||
stylesheet.walkRules((rule) => {
|
||||
assert.ok(
|
||||
rule.selectors.every(
|
||||
(selector) =>
|
||||
selector.startsWith('.settings-page') ||
|
||||
selector.startsWith('.settings-form-dialog'),
|
||||
),
|
||||
);
|
||||
rule.walkDecls((decl) => {
|
||||
assert.equal(Boolean(decl.important), false);
|
||||
assert.ok(!['scrollbar-width', 'scrollbar-color'].includes(decl.prop));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user