Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tooltip #164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 46 additions & 40 deletions src/components/ToolbarButton.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,64 @@
import React, { FunctionComponent } from 'react'
import IconButton from '@material-ui/core/IconButton'
import { TToolbarComponentProps, TToolbarButtonSize } from './Toolbar'
import React, { FunctionComponent } from 'react';
import IconButton from '@material-ui/core/IconButton';
import Tooltip from '@material-ui/core/Tooltip';
import { TToolbarComponentProps, TToolbarButtonSize } from './Toolbar';

interface IToolbarButtonProps {
id?: string
editorId?: string
label: string
style: string
type: string
active?: boolean
icon?: JSX.Element
onClick?: any
inlineMode?: boolean
disabled?: boolean
size?: TToolbarButtonSize
component?: FunctionComponent<TToolbarComponentProps>
id?: string;
editorId?: string;
label: string;
style: string;
type: string;
active?: boolean;
icon?: JSX.Element;
onClick?: any;
inlineMode?: boolean;
disabled?: boolean;
size?: TToolbarButtonSize;
component?: FunctionComponent<TToolbarComponentProps>;
}

const ToolbarButton: FunctionComponent<IToolbarButtonProps> = (props) => {
const size = !props.inlineMode ? (props.size || "medium") : "small"
const toolbarId = props.inlineMode ? "-toolbar" : ""
const editorId = props.editorId || "mui-rte"
const elemId = editorId + "-" + (props.id || props.label) + "-button" + toolbarId
const size = !props.inlineMode ? props.size || 'medium' : 'small';
const toolbarId = props.inlineMode ? '-toolbar' : '';
const editorId = props.editorId || 'mui-rte';
const elemId =
editorId + '-' + (props.id || props.label) + '-button' + toolbarId;
const sharedProps = {
id: elemId,
onMouseDown: (e: React.MouseEvent) => {
e.preventDefault()
e.preventDefault();
if (props.onClick) {
props.onClick(props.style, props.type, elemId, props.inlineMode)
props.onClick(
props.style,
props.type,
elemId,
props.inlineMode
);
}
},
disabled: props.disabled || false
}
disabled: props.disabled || false,
};
if (props.icon) {
return (
<IconButton
{...sharedProps}
aria-label={props.label}
color={props.active ? "primary" : "default"}
size={size}
>
{props.icon}
</IconButton>
)
<Tooltip title={props.label}>
<IconButton
{...sharedProps}
aria-label={props.label}
color={props.active ? 'primary' : 'default'}
size={size}
>
{props.icon}
</IconButton>
</Tooltip>
);
}
if (props.component) {
return (
<props.component
{...sharedProps}
active={props.active || false}
/>
)
<props.component {...sharedProps} active={props.active || false} />
);
}
return null
}
return null;
};

export default ToolbarButton
export default ToolbarButton;