Skip to content

Commit

Permalink
fix: tsc noEmit
Browse files Browse the repository at this point in the history
  • Loading branch information
Layouwen committed Aug 19, 2024
1 parent 5ab5765 commit a281626
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ package-lock.json

# dumi
.dumi/tmp
.dumi/tmp-production
.dumi/tmp-production

bun.lockb
4 changes: 2 additions & 2 deletions docs/examples/arrowContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { CSSProperties } from 'react';
import Tooltip from 'rc-tooltip';
import '../../assets/bootstrap_white.less';

Expand All @@ -11,7 +11,7 @@ const styles = {
background: '#f6f6f6',
verticalAlign: 'middle',
border: '5px solid white',
};
} as CSSProperties;

const rowStyle = {
display: 'table-row',
Expand Down
11 changes: 8 additions & 3 deletions docs/examples/formError.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import React, { Component } from 'react';
import Tooltip from 'rc-tooltip';
import React, { Component } from 'react';

import '../../assets/bootstrap.less';

interface TestState {
visible: boolean;
destroy?: boolean;
}

class Test extends Component {
state = {
visible: false,
};
} as TestState;

handleDestroy = () => {
this.setState({
destroy: true,
});
};

handleChange = e => {
handleChange = (e) => {
this.setState({
visible: !e.target.value,
});
Expand Down
7 changes: 6 additions & 1 deletion docs/examples/onVisibleChange.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ function preventDefault(e) {
e.preventDefault();
}

interface TestState {
visible: boolean;
destroy?: boolean;
}

class Test extends Component {
state = {
visible: false,
};
} as TestState;

onVisibleChange = visible => {
this.setState({
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/showArrow.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { CSSProperties } from 'react';
import React from 'react';
import Tooltip from 'rc-tooltip';
import '../../assets/bootstrap_white.less';
Expand All @@ -11,7 +12,7 @@ const styles = {
background: '#f6f6f6',
verticalAlign: 'middle',
border: '5px solid white',
};
} as CSSProperties;

const rowStyle = {
display: 'table-row',
Expand Down
52 changes: 34 additions & 18 deletions docs/examples/simple.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import React, { Component } from 'react';
import type { ActionType } from '@rc-component/trigger';
import type { OffsetType } from '@rc-component/trigger/lib/interface';
import Tooltip from 'rc-tooltip';
import type { CSSProperties } from 'react';
import React, { Component } from 'react';
import '../../assets/bootstrap.less';
import { placements } from '../../src/placements';

class Test extends Component {
interface TestState {
destroyTooltipOnHide: boolean;
destroyTooltipOptions: { name: string; value: number }[];
placement: string;
transitionName: string;
trigger: Record<ActionType, number>;
offsetX?: OffsetType;
offsetY?: OffsetType;
overlayInnerStyle?: CSSProperties;
}

class Test extends Component<any, TestState> {
state = {
destroyTooltipOnHide: false,
destroyTooltipOptions: [
Expand All @@ -24,13 +38,15 @@ class Test extends Component {
transitionName: 'rc-tooltip-zoom',
trigger: {
hover: 1,
},
click: 0,
focus: 0,
} as Record<ActionType, number>,
offsetX: placements.right.offset[0],
offsetY: placements.right.offset[1],
overlayInnerStyle: undefined,
};

onPlacementChange = e => {
onPlacementChange = (e) => {
const placement = e.target.value;
const { offset } = placements[placement];
this.setState({
Expand All @@ -40,13 +56,13 @@ class Test extends Component {
});
};

onTransitionChange = e => {
onTransitionChange = (e) => {
this.setState({
transitionName: e.target.checked ? e.target.value : '',
});
};

onTriggerChange = e => {
onTriggerChange = (e) => {
const { trigger } = this.state;
if (e.target.checked) {
trigger[e.target.value] = 1;
Expand All @@ -58,38 +74,38 @@ class Test extends Component {
});
};

onOffsetXChange = e => {
onOffsetXChange = (e) => {
const targetValue = e.target.value;
this.setState({
offsetX: targetValue || undefined,
});
};

onOffsetYChange = e => {
onOffsetYChange = (e) => {
const targetValue = e.target.value;
this.setState({
offsetY: targetValue || undefined,
});
};

onVisibleChange = visible => {
onVisibleChange = (visible) => {
console.log('tooltip', visible); // eslint-disable-line no-console
};

onDestroyChange = e => {
onDestroyChange = (e) => {
const { value } = e.target;
this.setState({
destroyTooltipOnHide: [false, { keepParent: false }, { keepParent: true }][value],
destroyTooltipOnHide: [false, { keepParent: false }, { keepParent: true }][value] as boolean,
});
};

onOverlayInnerStyleChange = () => {
this.setState(prevState => ({
this.setState((prevState) => ({
overlayInnerStyle: prevState.overlayInnerStyle ? undefined : { background: 'red' },
}));
};

preventDefault = e => {
preventDefault = (e) => {
e.preventDefault();
};

Expand All @@ -102,7 +118,7 @@ class Test extends Component {
<label>
placement:
<select value={this.state.placement} onChange={this.onPlacementChange}>
{Object.keys(placements).map(p => (
{Object.keys(placements).map((p) => (
<option key={p} value={p}>
{p}
</option>
Expand Down Expand Up @@ -134,7 +150,7 @@ class Test extends Component {
<label>
<input
value="hover"
checked={trigger.hover}
checked={!!trigger.hover}
type="checkbox"
onChange={this.onTriggerChange}
/>
Expand All @@ -143,7 +159,7 @@ class Test extends Component {
<label>
<input
value="focus"
checked={trigger.focus}
checked={!!trigger.focus}
type="checkbox"
onChange={this.onTriggerChange}
/>
Expand All @@ -152,7 +168,7 @@ class Test extends Component {
<label>
<input
value="click"
checked={trigger.click}
checked={!!trigger.click}
type="checkbox"
onChange={this.onTriggerChange}
/>
Expand Down Expand Up @@ -194,7 +210,7 @@ class Test extends Component {
mouseEnterDelay={0}
mouseLeaveDelay={0.1}
destroyTooltipOnHide={this.state.destroyTooltipOnHide}
trigger={Object.keys(this.state.trigger)}
trigger={Object.keys(this.state.trigger) as ActionType[]}
onVisibleChange={this.onVisibleChange}
overlay={<div style={{ height: 50, width: 50 }}>i am a tooltip</div>}
align={{
Expand Down
1 change: 1 addition & 0 deletions src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TooltipProps
| 'mouseEnterDelay'
| 'prefixCls'
| 'forceRender'
| 'popupVisible'
> {
trigger?: ActionType | ActionType[];
defaultVisible?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('rc-tooltip', () => {
});

it('access of ref', () => {
const domRef = React.createRef();
const domRef = React.createRef<TooltipRef>();
render(
<Tooltip
trigger={['click']}
Expand Down

0 comments on commit a281626

Please sign in to comment.