Skip to content

Commit

Permalink
chore: Code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 27, 2020
1 parent 0a63a3b commit 62cc627
Show file tree
Hide file tree
Showing 328 changed files with 4,594 additions and 2,117 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
package.json
dist
build
packages/doc/web
website/uiw/build
lib
node_modules
16 changes: 3 additions & 13 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
{
"packages": [
"packages/*",
"website/*"
],
"packages": ["packages/*", "website/*"],
"version": "independent",
"command": {
"publish": {
"ignoreChanges": [
"*.md",
"*.test.js",
"*.test.tsx"
]
"ignoreChanges": ["*.md", "*.test.js", "*.test.tsx"]
},
"create": {
"license": "MIT",
Expand All @@ -21,10 +14,7 @@
}
},
"bootstrap": {
"yarnClientArgs": [
"--no-yarn-lock",
"--no-package-lock"
],
"yarnClientArgs": ["--no-yarn-lock", "--no-package-lock"],
"forceLocal": true
}
}
Expand Down
34 changes: 20 additions & 14 deletions packages/doc/script/released.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,34 @@ const docRepoPath = join(process.cwd(), '..', 'doc');
const uiwPkg = join(libPath, 'package.json');
const docPkg = join(docRepoPath, 'package.json');

;(async () => {
(async () => {
try {

// Modify document version data.
const uiwPkgContent = await fs.readJson(uiwPkg);
console.log(`> Publish ${uiwPkgContent.version} v${uiwPkgContent.version}`);
/**
* Create a document website for `package.json`
* path => `packages/doc/package.json`
*/
await fs.writeFile(docPkg, JSON.stringify({
"name": "@uiw/doc",
"version": uiwPkgContent.version,
"description": "UIW documentation website.",
"homepage": uiwPkgContent.homepage,
"authors": uiwPkgContent.authors,
"files": [ "web" ],
"repository": uiwPkgContent.repository,
"keywords": uiwPkgContent.keywords,
"author": uiwPkgContent.author,
"license": uiwPkgContent.license
}, null, 2) + '\n');
await fs.writeFile(
docPkg,
JSON.stringify(
{
name: '@uiw/doc',
version: uiwPkgContent.version,
description: 'UIW documentation website.',
homepage: uiwPkgContent.homepage,
authors: uiwPkgContent.authors,
files: ['web'],
repository: uiwPkgContent.repository,
keywords: uiwPkgContent.keywords,
author: uiwPkgContent.author,
license: uiwPkgContent.license,
},
null,
2,
) + '\n',
);
await fs.emptyDir(join(docRepoPath, 'web'));
await fs.copy(docsPath, join(docRepoPath, 'web'));
} catch (error) {
Expand Down
35 changes: 26 additions & 9 deletions packages/react-affix/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ export interface IAffixState {
}

function getTargetRect(target: HTMLElement | Window | null): ClientRect {
return target !== window ? (target as HTMLElement).getBoundingClientRect() : ({ top: 0, left: 0, bottom: 0 }) as ClientRect;
return target !== window
? (target as HTMLElement).getBoundingClientRect()
: ({ top: 0, left: 0, bottom: 0 } as ClientRect);
}

function getOffset(element: HTMLElement, target: HTMLElement | Window | null) {
Expand All @@ -45,7 +47,7 @@ function getOffset(element: HTMLElement, target: HTMLElement | Window | null) {
};
}

function noop() { }
function noop() {}

function getDefaultTarget() {
return typeof window !== 'undefined' ? window : null;
Expand All @@ -55,11 +57,11 @@ export default class Affix extends React.Component<AffixProps, IAffixState> {
public static defaultProps: AffixProps = {
prefixCls: 'w-affix',
onChange: noop,
}
};
public state: IAffixState = {
placeholderStyle: undefined,
affixStyle: undefined,
}
};
private box: any;
private target!: Window | HTMLElement | null;
private readonly events = [
Expand Down Expand Up @@ -109,7 +111,8 @@ export default class Affix extends React.Component<AffixProps, IAffixState> {
}
const elemOffset = getOffset(this.box, this.target);
const box = this.box.getBoundingClientRect();
const bottom = document.documentElement.clientHeight - box.y - elemOffset.height;
const bottom =
document.documentElement.clientHeight - box.y - elemOffset.height;
if (offsetMode.top && box.y < 0) {
this.setPlaceholderStyle({ ...elemSize });
this.setAffixStyle({
Expand Down Expand Up @@ -146,7 +149,8 @@ export default class Affix extends React.Component<AffixProps, IAffixState> {
this.clearEventListeners();
this.events.forEach((eventName) => {
this.eventHandlers[eventName] = this.updatePosition;
this.target && this.target.addEventListener(eventName, this.updatePosition, false);
this.target &&
this.target.addEventListener(eventName, this.updatePosition, false);
});
}
clearEventListeners() {
Expand All @@ -159,12 +163,25 @@ export default class Affix extends React.Component<AffixProps, IAffixState> {
if (node) {
this.box = node;
}
}
};
public render() {
const { prefixCls, className, children, offsetTop, offsetBottom, target, onChange, ...resetProps } = this.props;
const {
prefixCls,
className,
children,
offsetTop,
offsetBottom,
target,
onChange,
...resetProps
} = this.props;
const cls = classnames(className, `${prefixCls}`);
return (
<div {...resetProps} ref={this.getInstance} style={{ ...this.state.placeholderStyle, ...this.props.style }}>
<div
{...resetProps}
ref={this.getInstance}
style={{ ...this.state.placeholderStyle, ...this.props.style }}
>
<div className={cls} style={this.state.affixStyle}>
{children}
</div>
Expand Down
4 changes: 1 addition & 3 deletions packages/react-affix/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
"baseUrl": "./src",
"jsx": "react"
},
"include": [
"src/**/*"
]
"include": ["src/**/*"]
}
2 changes: 1 addition & 1 deletion packages/react-alert/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ export default (props: AlertProps = {}) => {
{props.children}
</Modal>
);
}
};
7 changes: 4 additions & 3 deletions packages/react-alert/src/style/index.less
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@alert-prefix: ~"w-alert";
@alert-prefix: ~'w-alert';

.@{alert-prefix} {
.w-modal-header, .w-modal-body {
.w-modal-header,
.w-modal-body {
display: table-cell;
}
.w-modal-header {
Expand All @@ -20,7 +21,7 @@
vertical-align: top;
}
&.primary .w-modal-header > .w-icon {
color: #008EF0;
color: #008ef0;
}
&.success .w-modal-header > .w-icon {
color: #28a745;
Expand Down
4 changes: 1 addition & 3 deletions packages/react-alert/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
"baseUrl": "./src",
"jsx": "react"
},
"include": [
"src/**/*"
]
"include": ["src/**/*"]
}
16 changes: 10 additions & 6 deletions packages/react-avatar/src/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import Avatar from '../';

describe('<Avatar />', () => {
it('Should output a Avatar', () => {
const component = TestRenderer.create(
<Avatar icon="user" />
);
const component = TestRenderer.create(<Avatar icon="user" />);
let tree = component.toJSON();
if (tree) {
expect(tree.type).toBe('span');
expect(tree.props.className).toBe('w-avatar w-avatar-default w-avatar-circle');
expect(tree.props.className).toBe(
'w-avatar w-avatar-default w-avatar-circle',
);
expect(tree.children).toHaveLength(1);
if (tree.children && tree.children[0]) {
expect((tree.children[0] as any).type).toBe('span');
expect((tree.children[0] as any).props.className).toBe('w-icon w-icon-middle');
expect((tree.children[0] as any).props.style).toEqual({ fill: 'currentColor' });
expect((tree.children[0] as any).props.className).toBe(
'w-icon w-icon-middle',
);
expect((tree.children[0] as any).props.style).toEqual({
fill: 'currentColor',
});
}
}

Expand Down
16 changes: 12 additions & 4 deletions packages/react-avatar/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export interface AvatarProps extends HTMLSpanProps {
size?: 'large' | 'default' | 'small' | 'mini';
shape?: 'square' | 'circle';
onError?: (event: React.SyntheticEvent<HTMLImageElement, Event>) => boolean;

}

export interface AvatarState {
Expand All @@ -26,10 +25,10 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
prefixCls: 'w-avatar',
shape: 'circle',
size: 'default',
}
};
public state: AvatarState = {
isImgExist: true,
}
};

componentDidUpdate(prevProps: AvatarProps) {
if (prevProps.src !== this.props.src) {
Expand All @@ -45,7 +44,16 @@ export default class Avatar extends React.Component<AvatarProps, AvatarState> {
}
}
render() {
const { prefixCls, className, size, shape, src, alt, icon, ...resetProps } = this.props;
const {
prefixCls,
className,
size,
shape,
src,
alt,
icon,
...resetProps
} = this.props;
let children = this.props.children;
const cls = classnames(prefixCls, className, {
[`${prefixCls}-${size}`]: size,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-avatar/src/style/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@w-avatar:~"w-avatar";
@w-avatar:~ "w-avatar";

.@{w-avatar} {
display: inline-block;
Expand Down Expand Up @@ -41,4 +41,4 @@
height: 100%;
display: block;
}
}
}
4 changes: 1 addition & 3 deletions packages/react-avatar/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
"baseUrl": "./src",
"jsx": "react"
},
"include": [
"src/**/*"
]
"include": ["src/**/*"]
}
25 changes: 19 additions & 6 deletions packages/react-back-top/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,19 @@ export interface IBackTopState {
}

export default (props: BackTopProps = {}) => {
const { prefixCls = 'w-back-top', className, content, children, offsetTop = 0, fixed = true, speed = 100, showBelow = 1, clickable = true, ...other } = props;
const topShowBelow = !fixed ? 0 : (showBelow || 0);
const {
prefixCls = 'w-back-top',
className,
content,
children,
offsetTop = 0,
fixed = true,
speed = 100,
showBelow = 1,
clickable = true,
...other
} = props;
const topShowBelow = !fixed ? 0 : showBelow || 0;
const [percent, setPercent] = useState(0);
const [current, setCurrent] = useState(0);
const visible = percent >= topShowBelow;
Expand All @@ -34,9 +45,9 @@ export default (props: BackTopProps = {}) => {
});
useEffect(() => {
window && window.addEventListener('scroll', onScroll);
return function() {
return function () {
window && window.removeEventListener('scroll', onScroll);
}
};
});
function onScroll() {
setPercent(getScrollPercent(offsetTop));
Expand All @@ -48,7 +59,9 @@ export default (props: BackTopProps = {}) => {
return (
<div onClick={() => clickable && scrollToTop()} className={cls} {...other}>
{content}
{typeof children !== 'function' ? children : children({ percent, current, scrollToTop: scrollToTop })}
{typeof children !== 'function'
? children
: children({ percent, current, scrollToTop: scrollToTop })}
</div>
);
}
};
10 changes: 5 additions & 5 deletions packages/react-back-top/src/style/index.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@w-back-top:~"w-back-top";
@w-back-top:~ "w-back-top";

.@{w-back-top} {
position: fixed;
Expand All @@ -11,12 +11,12 @@
cursor: auto;
position: static;
}
&-hide{
&-hide {
transition: all 1s;
opacity: 0;
height: 0px;
height: 0px;
}
&-show{
&-show {
opacity: 1;
}
}
}
Loading

0 comments on commit 62cc627

Please sign in to comment.