Skip to content

Commit efb22d4

Browse files
committed
feat: remove emotion
fix #6
1 parent 1965bfd commit efb22d4

File tree

10 files changed

+2380
-2561
lines changed

10 files changed

+2380
-2561
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@
6464
"typescript": "^3.1.6"
6565
},
6666
"dependencies": {
67-
"@emotion/core": "^10.0.4",
68-
"@emotion/is-prop-valid": "^0.7.3",
69-
"@emotion/styled": "^10.0.4",
7067
"rxjs": "^6.3.3"
7168
},
7269
"peerDependencies": {

src/Bar/Bar.styled.ts

Lines changed: 0 additions & 43 deletions
This file was deleted.

src/Bar/Bar.styled.tsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as React from 'react';
2+
3+
import { ExpandInteractiveArea } from '../types';
4+
5+
export type StyledBarProps = React.HTMLAttributes<HTMLDivElement> & {
6+
size?: number;
7+
};
8+
9+
export const StyledBar = React.forwardRef<HTMLDivElement, StyledBarProps>(
10+
({ size, style, ...props }, ref) => (
11+
<div
12+
{...props}
13+
ref={ref}
14+
style={{
15+
position: 'relative',
16+
flex: `0 0 ${size}px`,
17+
...style,
18+
}}
19+
/>
20+
),
21+
);
22+
23+
export type StyledInteractiveAreaProps = React.HTMLAttributes<HTMLDivElement> &
24+
ExpandInteractiveArea & {
25+
vertical: boolean;
26+
};
27+
28+
export const StyledInteractiveArea = React.forwardRef<
29+
HTMLDivElement,
30+
StyledInteractiveAreaProps
31+
>(
32+
(
33+
{ top = 0, right = 0, bottom = 0, left = 0, vertical, style, ...props },
34+
ref,
35+
) => (
36+
<div
37+
{...props}
38+
style={{
39+
position: 'absolute',
40+
top: -top,
41+
left: -left,
42+
right: -right,
43+
bottom: -bottom,
44+
cursor: vertical ? 'row-resize' : 'col-resize',
45+
WebkitTapHighlightColor: 'transparent',
46+
userSelect: 'none', // disable ios long press popup
47+
...style,
48+
}}
49+
ref={ref}
50+
/>
51+
),
52+
);

src/Bar/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {
77
ExpandInteractiveArea,
88
Omit,
99
} from '../types';
10+
import { omit } from '../utils';
1011
import { withResizerContext } from '../context';
11-
import { StyledBar, StyledInteractiveArea } from './Bar.styled';
12+
import { StyledBar, StyledInteractiveArea, StyledBarProps } from './Bar.styled';
1213
import { disablePassive } from './disablePassive';
1314

1415
type Props = React.HTMLAttributes<HTMLDivElement> &
@@ -32,6 +33,10 @@ class BarComponent extends React.PureComponent<Props> {
3233
return this.props.innerRef || this.defaultInnerRef;
3334
}
3435

36+
private get childProps(): StyledBarProps {
37+
return omit(this.props, []);
38+
}
39+
3540
private isActivated: boolean = false;
3641

3742
private onMouseDown = this.triggerMouseAction(BarActionType.ACTIVATE);
@@ -85,7 +90,7 @@ class BarComponent extends React.PureComponent<Props> {
8590

8691
render() {
8792
return (
88-
<StyledBar {...this.props} ref={this.ref}>
93+
<StyledBar {...this.childProps} ref={this.ref}>
8994
{this.props.children}
9095
<StyledInteractiveArea
9196
{...this.props.expandInteractiveArea}

src/Container/Container.styled.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
import styled from '@emotion/styled';
1+
import * as React from 'react';
22

3-
import { ignoreProps } from '../utils';
4-
5-
interface StyledContainerProps {
3+
export type StyledContainerProps = React.HTMLAttributes<HTMLDivElement> & {
64
vertical?: boolean;
7-
}
8-
9-
const customStyledContainerProps = [
10-
'vertical',
11-
'onActivate',
12-
'beforeApplyResizer',
13-
'afterResizing',
14-
];
5+
};
156

16-
export const StyledContainer = styled('div', {
17-
shouldForwardProp: ignoreProps(customStyledContainerProps),
18-
})<StyledContainerProps>(({ vertical }) => ({
19-
display: 'flex',
20-
flexDirection: vertical ? 'column' : 'row',
21-
}));
7+
export const StyledContainer = React.forwardRef<
8+
HTMLDivElement,
9+
StyledContainerProps
10+
>(({ vertical, style, ...props }, ref) => (
11+
<div
12+
{...props}
13+
ref={ref}
14+
style={{
15+
display: 'flex',
16+
flexDirection: vertical ? 'column' : 'row',
17+
...style,
18+
}}
19+
/>
20+
));

src/Container/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
ResizerContext,
1010
SizeRelatedInfo,
1111
} from '../types';
12+
import { omit } from '../utils';
1213
import { ResizerProvider } from '../context';
1314

1415
import { Resizer } from './Resizer';
@@ -19,7 +20,7 @@ import {
1920
isDisabledResponsive,
2021
isSolid,
2122
} from './utils';
22-
import { StyledContainer } from './Container.styled';
23+
import { StyledContainer, StyledContainerProps } from './Container.styled';
2324

2425
interface Props extends React.HTMLAttributes<HTMLDivElement> {
2526
vertical?: boolean;
@@ -84,14 +85,25 @@ class Container extends React.PureComponent<Props> {
8485
};
8586
}
8687

88+
private get containerProps(): StyledContainerProps {
89+
return omit(this.props, [
90+
'onActivate',
91+
'beforeApplyResizer',
92+
'afterResizing',
93+
]);
94+
}
95+
8796
componentDidMount() {
8897
this.refreshSizeInfos();
8998
}
9099

91100
render() {
92101
return (
93102
<ResizerProvider value={this.contextValue}>
94-
<StyledContainer {...this.props} vertical={this.props.vertical}>
103+
<StyledContainer
104+
{...this.containerProps}
105+
vertical={this.props.vertical}
106+
>
95107
{this.props.children}
96108
</StyledContainer>
97109
</ResizerProvider>

src/Section/Section.styled.tsx

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,43 @@
1-
import styled from '@emotion/styled';
2-
import { ChildProps } from '../types';
3-
import { ignoreProps } from '../utils';
1+
import * as React from 'react';
42

5-
interface StyledSectionProps extends ChildProps {
6-
flexGrow: number;
7-
flexShrink: number;
8-
flexBasis: number;
9-
}
3+
import { ChildProps } from '../types';
104

11-
const customProps = [
12-
'onSizeChanged',
13-
// ChildProps
14-
'size',
15-
'defaultSize',
16-
'maxSize',
17-
'minSize',
18-
'context',
19-
'disableResponsive',
20-
'innerRef',
21-
// StyledSectionProps
22-
'flexGrow',
23-
'flexShrink',
24-
'flexBasis',
25-
];
5+
export type StyledSectionProps = React.HTMLAttributes<HTMLDivElement> &
6+
Pick<ChildProps, 'context' | 'maxSize' | 'minSize'> & {
7+
flexGrow: number;
8+
flexShrink: number;
9+
flexBasis: number;
10+
};
2611

27-
export const StyledSection = styled('div', {
28-
shouldForwardProp: ignoreProps(customProps),
29-
})<StyledSectionProps>(
30-
({ context, maxSize, minSize, flexGrow, flexShrink, flexBasis }) => ({
31-
overflow: 'hidden',
32-
[context.vertical ? 'maxHeight' : 'maxWidth']: maxSize,
33-
[context.vertical ? 'minHeight' : 'minWidth']: minSize,
34-
flexGrow,
35-
flexShrink,
36-
flexBasis,
37-
}),
12+
export const StyledSection = React.forwardRef<
13+
HTMLDivElement,
14+
StyledSectionProps
15+
>(
16+
(
17+
{
18+
context,
19+
maxSize,
20+
minSize,
21+
flexGrow,
22+
flexShrink,
23+
flexBasis,
24+
style,
25+
...props
26+
},
27+
ref,
28+
) => (
29+
<div
30+
{...props}
31+
ref={ref}
32+
style={{
33+
overflow: 'hidden',
34+
[context.vertical ? 'maxHeight' : 'maxWidth']: maxSize,
35+
[context.vertical ? 'minHeight' : 'minWidth']: minSize,
36+
flexGrow,
37+
flexShrink,
38+
flexBasis,
39+
...style,
40+
}}
41+
/>
42+
),
3843
);

src/Section/index.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { filter, map, tap } from 'rxjs/operators';
44

55
import { ChildProps, SizeInfo } from '../types';
66
import { withResizerContext } from '../context';
7-
import { isValidNumber } from '../utils';
8-
import { StyledSection } from './Section.styled';
7+
import { isValidNumber, omit } from '../utils';
8+
import { StyledSection, StyledSectionProps } from './Section.styled';
99

1010
type Props = ChildProps &
1111
React.HTMLAttributes<HTMLDivElement> & {
@@ -51,6 +51,18 @@ class SectionComponent extends React.PureComponent<Props> {
5151
return this.props.innerRef || this.defaultInnerRef;
5252
}
5353

54+
private get childProps(): StyledSectionProps {
55+
return {
56+
...omit(this.props, [
57+
'defaultSize',
58+
'defaultSize',
59+
'disableResponsive',
60+
'innerRef',
61+
]),
62+
...this.getStyle(),
63+
};
64+
}
65+
5466
componentDidMount() {
5567
this.subscription.add(this.resize$.subscribe());
5668
this.props.context.populateInstance(this.id, this.ref);
@@ -61,9 +73,7 @@ class SectionComponent extends React.PureComponent<Props> {
6173
}
6274

6375
render() {
64-
return (
65-
<StyledSection {...this.props} {...this.getStyle()} ref={this.ref} />
66-
);
76+
return <StyledSection {...this.childProps} ref={this.ref} />;
6777
}
6878

6979
private onSizeChanged(currentSize: number) {

src/utils.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
import isPropValid from '@emotion/is-prop-valid';
1+
import { Omit } from './types';
22

33
export function isValidNumber(num?: number): num is number {
44
return typeof num === 'number' && num === num;
55
}
66

77
export function noop() {}
88

9-
export function ignoreProps(ignoreList: string[]) {
10-
return (propName: string) =>
11-
ignoreList.indexOf(propName) === -1 && isPropValid(propName);
9+
export function omit<P extends object, K extends keyof P>(
10+
props: P,
11+
ignoreKeys: K[],
12+
): Omit<P, K> {
13+
type IgnoreKeyMap = Partial<Record<keyof P, true>>;
14+
15+
const ignoreKeyMap = ignoreKeys.reduce<IgnoreKeyMap>(
16+
(map, key) => {
17+
map[key] = true;
18+
return map;
19+
},
20+
{} as IgnoreKeyMap,
21+
);
22+
23+
return (Object.keys(props) as (keyof P)[]).reduce(
24+
(newProps, key) => {
25+
if (ignoreKeyMap[key]) {
26+
return newProps;
27+
} else {
28+
newProps[key] = props[key];
29+
return newProps;
30+
}
31+
},
32+
{} as P,
33+
);
1234
}

0 commit comments

Comments
 (0)