diff --git a/src/DTableModalHeader/index.js b/src/DTableModalHeader/index.js index 7af79786..f66ad64b 100644 --- a/src/DTableModalHeader/index.js +++ b/src/DTableModalHeader/index.js @@ -1,13 +1,14 @@ import React from 'react'; import { ModalHeader } from 'reactstrap'; import IconButton from '../IconButton'; +import { getLocale } from '../lang'; import './index.css'; const DTableModalHeader = ({ children, ...props }) => { const customCloseBtn = ( ); return ( diff --git a/src/DTableToolTip/index.css b/src/DTableToolTip/index.css new file mode 100644 index 00000000..f6d53d1d --- /dev/null +++ b/src/DTableToolTip/index.css @@ -0,0 +1,45 @@ +.dtable-tooltip { + position: absolute; + z-index: 99999; +} + +.dtable-tooltip .tooltip { + max-width: 242px; + min-width: max-content; + opacity: 1; +} + +.dtable-tooltip .tooltip .tooltip-inner { + font-size: 14px; + text-align: start; + background-color: var(--bs-body-color); + color: var(--bs-body-bg); + border-radius: 4px; + padding: 4px 8px; + line-height: 20px; + font-weight: normal; +} + +.dtable-tooltip-shortcut-inner { + display: flex; + align-items: center; + justify-content: space-between; + gap: 4px; + line-height: 20px; +} + +.dtable-tooltip-shortcut-keys { + display: inline-flex; + align-items: center; + gap: 4px; + flex-shrink: 0; +} + +.dtable-tooltip-shortcut-key { + display: inline-block; + padding: 2px 8px; + border: 1px solid #999; + border-radius: 4px; + white-space: nowrap; + line-height: 14px; +} diff --git a/src/DTableToolTip/index.js b/src/DTableToolTip/index.js new file mode 100644 index 00000000..83aa47ec --- /dev/null +++ b/src/DTableToolTip/index.js @@ -0,0 +1,69 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { UncontrolledTooltip } from 'reactstrap'; + +import './index.css'; + +const DTableToolTip = ({ target, placement = 'bottom', className, children, shortcut }) => { + + const hasShortcut = Boolean(shortcut); + + const renderContent = () => { + if (hasShortcut) { + return ( +
+ {children} + + {shortcut.map((key, index) => ( + + {key} + + ))} + +
+ ); + } + + return children; + }; + + const tooltipProps = { + target, + placement, + className: `dtable-tooltip ${className ? className : ''}`, + innerClassName: hasShortcut ? 'dtable-tooltip-shortcut-inner' : '', + delay: { show: 0, hide: 0 }, + hideArrow: true, + autohide: false, + modifiers: [ + { + name: 'offset', + options: { + offset: [0, -2.5], + }, + }, + { + name: 'preventOverflow', + options: { + boundariesElement: 'window', + }, + } + ], + }; + + return ( + + {renderContent()} + + ); +}; + +DTableToolTip.propTypes = { + target: PropTypes.string.isRequired, + placement: PropTypes.oneOf(['top', 'bottom', 'left', 'right']), + className: PropTypes.string, + children: PropTypes.node, + shortcut: PropTypes.arrayOf(PropTypes.string), +}; + +export default DTableToolTip; diff --git a/src/IconButton/index.js b/src/IconButton/index.js index 6398c75d..eb701207 100644 --- a/src/IconButton/index.js +++ b/src/IconButton/index.js @@ -1,13 +1,20 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import PropTypes from 'prop-types'; import classnames from 'classnames'; +import DTableToolTip from '../DTableToolTip'; + +const IconButton = ({ disabled, className, icon, children, title, ...otherProperties }) => { + const uniqueId = useMemo(() => `seatable-icon-btn-${Math.random().toString(36).substr(2, 9)}`, []); -const IconButton = ({ disabled, className, icon, children, ...otherProperties }) => { return (
+ + {title} + {icon && ()} {children}
diff --git a/src/NotificationPopover/index.js b/src/NotificationPopover/index.js index 0095647c..e9420f20 100644 --- a/src/NotificationPopover/index.js +++ b/src/NotificationPopover/index.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import { Popover } from 'reactstrap'; import IconButton from '../IconButton'; +import { getLocale } from '../lang'; import './index.css'; @@ -74,7 +75,7 @@ export default class NotificationPopover extends React.Component {
this.notificationContainerRef = ref}>
{headerText} - +
{this.props.enableWeixin && diff --git a/src/index.js b/src/index.js index 8570ec2b..181a2626 100644 --- a/src/index.js +++ b/src/index.js @@ -72,6 +72,8 @@ export { default as DTableGroupSelect } from './DTableGroupSelect/index'; export { default as DTableSelectLabel } from './DTableSelect/dtable-select-label'; export { default as DTableSwitch } from './DTableSwitch'; export { default as DTableCustomizeSelect } from './DTableCustomizeSelect'; +export { default as DTableToolTip } from './DTableToolTip'; + export { default as DTableCustomizeCollaboratorSelect } from './DTableCustomizeCollaboratorSelect'; export { default as DTableSearchInput } from './DTableSearchInput'; export { default as DTableColorPicker } from './DTableColorPicker';