Skip to content

Commit

Permalink
feat(Box): adjust ts & docs &test close alibaba-fusion#4566
Browse files Browse the repository at this point in the history
  • Loading branch information
WB01081293 committed Dec 27, 2023
1 parent b39a8d4 commit 9a9f15e
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 277 deletions.
2 changes: 1 addition & 1 deletion components/box/__docs__/demo/wrap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class BoxDemo extends React.Component {
state = {
wrap: true,
};
onSwitchChange = checked => {
onSwitchChange = (checked: boolean) => {
this.setState({
wrap: checked,
});
Expand Down
76 changes: 0 additions & 76 deletions components/box/__docs__/theme/index.jsx

This file was deleted.

93 changes: 93 additions & 0 deletions components/box/__docs__/theme/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import '../../../demo-helper/style';
import { Demo, DemoGroup, initDemo, DemoFunctionDefineForObject } from '../../../demo-helper';
import ConfigProvider from '../../../config-provider';
import zhCN from '../../../locale/zh-cn';
import enUS from '../../../locale/en-us';
import '../../style';
import Box from '../../index';

const i18nMap = {
'zh-cn': {
box: '弹性布局',
normal: '正常',
},
'en-us': {
box: 'Box',
normal: 'Normal',
},
};
interface RenderBoxState {
demoFunction: Record<string, DemoFunctionDefineForObject>;
}

interface RenderBoxProps {
i18nMap: { [index: string]: string };
}
class RenderBox extends React.Component<RenderBoxProps, RenderBoxState> {
constructor(props: RenderBoxProps) {
super(props);
this.state = {
demoFunction: {
hasChildren: {
label: 'Box使用',
value: 'false',
enum: [
{
label: '不独立使用',
value: false,
},
{
label: '独立使用',
value: true,
},
],
},
},
};
}

onFunctionChange = (demoFunction: any) => {
this.setState({ demoFunction });
};

render() {
const { i18nMap } = this.props;
const { demoFunction } = this.state;
const hasChildren = demoFunction ? demoFunction.hasChildren.value === 'true' : null;

return (
<Demo
title={i18nMap.box}
demoFunction={demoFunction}
onFunctionChange={this.onFunctionChange}
>
<Demo title={i18nMap.box}>
<DemoGroup label={i18nMap.normal}>
<Box children={hasChildren} />
</DemoGroup>
</Demo>
</Demo>
);
}
}

function render(i18nMap: { box: string; normal: string }, lang: string) {
ReactDOM.render(
<ConfigProvider locale={lang === 'en-us' ? enUS : zhCN}>
<div className="demo-container">
<RenderBox i18nMap={i18nMap} />
</div>
</ConfigProvider>,
document.getElementById('container')
);
}

window.renderDemo = function (lang = 'en-us') {
render(i18nMap[lang], lang);
};

renderDemo();

initDemo('box');
26 changes: 0 additions & 26 deletions components/box/__tests__/a11y-spec.js

This file was deleted.

12 changes: 12 additions & 0 deletions components/box/__tests__/a11y-spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import Box from '../index';
import '../style';
import { testReact } from '../../util/__tests__/a11y/validate';

describe('Box A11y', () => {
describe('Box A11y', () => {
it('should render', async () => {
await testReact(<Box />);
});
});
});
95 changes: 0 additions & 95 deletions components/box/__tests__/index-spec.js

This file was deleted.

51 changes: 51 additions & 0 deletions components/box/__tests__/index-spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as React from 'react';
import Box from '../index';
import '../style';

describe('Box', () => {
it('should render', () => {
cy.mount(
<Box direction="row" wrap className="border-box" spacing={30}>
<Box
className="border-box height-100 width-150"
direction="row"
wrap
spacing={8}
padding={10}
>
<Box className="border-box height-30 width-30 dashed" />
<Box className="border-box height-30 width-30" />
<Box className="border-box height-30 width-30" />
<Box className="border-box height-30 width-30" />
<Box
className="border-box height-30 width-30 dashed"
margin={[3, 6]}
style={{ marginRight: 10 }}
/>
<Box className="border-box height-30 width-30" />
</Box>

<Box className="border-box height-100 width-150" />
<Box className="border-box height-100 width-150" />
<Box className="border-box height-100 width-150" />
<Box className="border-box height-100 width-150" />
<Box className="border-box height-100 width-150" />
<Box className="border-box height-100 width-150" />
<Box className="border-box height-100 width-150" />
</Box>
);
cy.get('.next-box').should('exist');
});

it('justify should work when wrap and spacing setted', () => {
cy.mount(
<Box className="test" wrap spacing={20} direction="row" justify="center">
<Box className="box-180-50" />
<Box className="box-180-50" />
<Box className="box-180-50" />
<Box className="box-180-50" />
</Box>
);
cy.get('.test').should('have.css', 'justify-content', 'center');
});
});
Loading

0 comments on commit 9a9f15e

Please sign in to comment.