Skip to content

Commit

Permalink
chore(*): update balloon component documentation and types, add displ…
Browse files Browse the repository at this point in the history
…ay names, add dialog ssr test case
  • Loading branch information
eternalsky committed Sep 10, 2024
1 parent 718025e commit 2bb459e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 38 deletions.
8 changes: 4 additions & 4 deletions components/balloon/__docs__/index.en-us.md

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions components/balloon/__docs__/index.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions components/balloon/balloon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ let alignMap = normalMap;

class Balloon extends React.Component<BalloonProps, BalloonState> {
readonly props: BalloonV1Props & BalloonV2Props;
static displayName = 'Balloon';
static contextTypes = {
prefix: PropTypes.string,
};
Expand Down
6 changes: 5 additions & 1 deletion components/balloon/tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const { Popup } = Overlay;
let alignMap = normalMap;
/** Balloon.Tooltip */
export default class Tooltip extends Component<TooltipProps, TooltipState> {
readonly props: TooltipV1Props & TooltipV2Props;
static displayName = 'Tooltip';

static propTypes = {
prefix: PropTypes.string,
className: PropTypes.string,
Expand Down Expand Up @@ -52,6 +53,7 @@ export default class Tooltip extends Component<TooltipProps, TooltipState> {
v2: PropTypes.bool,
arrowPointToCenter: PropTypes.bool,
};

static defaultProps = {
triggerType: 'hover',
prefix: 'next-',
Expand All @@ -61,6 +63,8 @@ export default class Tooltip extends Component<TooltipProps, TooltipState> {
arrowPointToCenter: false,
};

readonly props: TooltipV1Props & TooltipV2Props;

constructor(props: TooltipProps) {
super(props);
this.state = {
Expand Down
50 changes: 24 additions & 26 deletions components/balloon/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ interface HTMLAttributesWeak extends Omit<React.HTMLAttributes<HTMLElement>, 'ti
* @order 0
*/
export interface BalloonV2Props extends HTMLAttributesWeak, CommonProps {
/**
* 开启 v2 版本
* @en Enable v2
* @version 1.25
*/
v2?: true;
/**
* 是否 pure render
* @en Whether to pure render
Expand Down Expand Up @@ -96,13 +102,6 @@ export interface BalloonV2Props extends HTMLAttributesWeak, CommonProps {
*/
onVisibleChange?: (visible: boolean, type: string) => void;

/**
* 开启 v2 版本
* @en Enable v2
* @version 1.25
*/
v2?: true;

/**
* [v2] 箭头是否指向目标元素的中心
* @en Whether the arrow points to the center of the target element
Expand Down Expand Up @@ -319,6 +318,12 @@ export type BalloonProps = BalloonV1Props | BalloonV2Props;
* @order 1
*/
export interface BalloonV1Props extends HTMLAttributesWeak, CommonProps {
/**
* 开启 v2 版本
* @en Enable v2
* @version 1.25
*/
v2?: false | undefined;
/**
* 是否 pure render
* @en Whether to pure render
Expand Down Expand Up @@ -397,13 +402,6 @@ export interface BalloonV1Props extends HTMLAttributesWeak, CommonProps {
*/
onVisibleChange?: (visible: boolean, type: string) => void;

/**
* 开启 v2 版本
* @en Enable v2
* @version 1.25
*/
v2?: false | undefined;

/**
* 弹出层对齐方式
* @en Popup alignment
Expand Down Expand Up @@ -599,6 +597,12 @@ export interface BalloonV1Props extends HTMLAttributesWeak, CommonProps {
* @order 2
*/
export interface TooltipV2Props extends HTMLAttributesWeak, CommonProps {
/**
* 开启 v2
* @en Enable v2
*/
v2?: true;

/**
* 自定义内联样式
* @en Custom inline style
Expand Down Expand Up @@ -690,12 +694,6 @@ export interface TooltipV2Props extends HTMLAttributesWeak, CommonProps {
*/
delay?: number;

/**
* 开启 v2
* @en Enable v2
*/
v2?: true;

/**
* 鼠标放置后的延时显示,单位毫秒 ms
* @en Delay display after mouse
Expand Down Expand Up @@ -766,6 +764,12 @@ export interface TooltipV2Props extends HTMLAttributesWeak, CommonProps {
* @order 3
*/
export interface TooltipV1Props extends HTMLAttributesWeak, CommonProps {
/**
* 开启 v2
* @en Enable v2
*/
v2?: false | undefined;

/**
* 自定义内联样式
* @en Custom inline style
Expand Down Expand Up @@ -857,12 +861,6 @@ export interface TooltipV1Props extends HTMLAttributesWeak, CommonProps {
*/
delay?: number;

/**
* 开启 v2
* @en Enable v2
*/
v2?: false | undefined;

/**
* 鼠标放置后的延时显示,单位毫秒 ms
* @en Delay display after mouse
Expand Down
15 changes: 15 additions & 0 deletions components/dialog/__tests__/ssr-node.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { renderToStaticMarkup } from 'react-dom/server';
import React from 'react';
import { expect } from 'chai';
import Dialog from '../index';

describe('ssr-node', () => {
it('should be ok', () => {
const html = renderToStaticMarkup(<Dialog visible />);
expect(html).to.equal('');
});
it('[v2] should be ok', () => {
const html = renderToStaticMarkup(<Dialog v2 visible />);
expect(html).to.equal('');
});
});
7 changes: 5 additions & 2 deletions components/dialog/dialog-v2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Dialog = (props: DialogV2Props) => {
animation = { in: 'fadeInUp', out: 'fadeOutUp' },
cache,
wrapperStyle,
popupContainer = document.body,
popupContainer = typeof document !== 'undefined' ? document.body : null,
dialogRender,
centered,
top = centered ? 40 : 100,
Expand Down Expand Up @@ -135,7 +135,10 @@ const Dialog = (props: DialogV2Props) => {
if (dom.hasScroll(document.body)) {
const scrollWidth = dom.scrollbar().width;
if (scrollWidth) {
style.paddingRight = `${(dom.getStyle(document.body, 'paddingRight') as number) + dom.scrollbar().width}px`;
style.paddingRight = `${
(dom.getStyle(document.body, 'paddingRight') as number) +
dom.scrollbar().width
}px`;
}
}
locker.current = scrollLocker.lock(document.body, style);
Expand Down
2 changes: 1 addition & 1 deletion components/dialog/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import zhCN from '../locale/zh-cn';
import { focus, obj, func, events, dom, env } from '../util';
import Inner from './inner';
import { type CustomCSSStyleKey } from '../util/dom';
import { DialogV1Props } from './types';
import type { DialogV1Props } from './types';

const noop = () => {};
const { limitTabRange } = focus;
Expand Down

0 comments on commit 2bb459e

Please sign in to comment.