1
0
Fork 0
mirror of https://github.com/muerwre/vault-frontend.git synced 2025-04-25 12:56:41 +07:00

added button tooltips

This commit is contained in:
Fedor Katurov 2021-02-26 15:36:05 +07:00
parent 5cf3d22466
commit b23c136cbe
5 changed files with 75 additions and 5 deletions

View file

@ -19,6 +19,8 @@
.buttons { .buttons {
@include outer_shadow(); @include outer_shadow();
position: relative;
z-index: 1;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
background: transparentize(black, 0.8); background: transparentize(black, 0.8);

View file

@ -24,6 +24,7 @@ const CommentFormFormatButtons: FC<IProps> = ({ element, handler }) => {
color="gray" color="gray"
iconOnly iconOnly
type="button" type="button"
label="Жирный"
/> />
<Button <Button
@ -33,6 +34,7 @@ const CommentFormFormatButtons: FC<IProps> = ({ element, handler }) => {
color="gray" color="gray"
iconOnly iconOnly
type="button" type="button"
label="Наклонный"
/> />
<Button <Button
@ -42,6 +44,7 @@ const CommentFormFormatButtons: FC<IProps> = ({ element, handler }) => {
color="gray" color="gray"
iconOnly iconOnly
type="button" type="button"
label="Заголовок"
/> />
<Button <Button
@ -51,7 +54,19 @@ const CommentFormFormatButtons: FC<IProps> = ({ element, handler }) => {
color="gray" color="gray"
iconOnly iconOnly
type="button" type="button"
label="Ссылка"
/> />
<Button
onClick={wrap('// ')}
size="small"
color="gray"
iconOnly
type="button"
label="Коммент"
>
{`/ /`}
</Button>
</ButtonGroup> </ButtonGroup>
); );
}; };

View file

@ -4,5 +4,4 @@
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
height: 32px; height: 32px;
overflow: hidden;
} }

View file

@ -1,8 +1,16 @@
import classnames from 'classnames'; import classnames from 'classnames';
import React, { ButtonHTMLAttributes, DetailedHTMLProps, FC, createElement, memo } from 'react'; import React, {
ButtonHTMLAttributes,
DetailedHTMLProps,
FC,
createElement,
memo,
useRef,
} from 'react';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
import { Icon } from '~/components/input/Icon'; import { Icon } from '~/components/input/Icon';
import { IIcon } from '~/redux/types'; import { IIcon } from '~/redux/types';
import { usePopper } from 'react-popper';
type IButtonProps = DetailedHTMLProps< type IButtonProps = DetailedHTMLProps<
ButtonHTMLAttributes<HTMLButtonElement>, ButtonHTMLAttributes<HTMLButtonElement>,
@ -19,6 +27,7 @@ type IButtonProps = DetailedHTMLProps<
is_loading?: boolean; is_loading?: boolean;
stretchy?: boolean; stretchy?: boolean;
iconOnly?: boolean; iconOnly?: boolean;
label?: string;
}; };
const Button: FC<IButtonProps> = memo( const Button: FC<IButtonProps> = memo(
@ -37,9 +46,24 @@ const Button: FC<IButtonProps> = memo(
stretchy, stretchy,
disabled, disabled,
iconOnly, iconOnly,
label,
ref,
...props ...props
}) => }) => {
createElement( const tooltip = useRef<HTMLSpanElement>();
const pop = usePopper(tooltip?.current?.parentElement, tooltip.current, {
placement: 'top',
modifiers: [
{
name: 'offset',
options: {
offset: [0, 5],
},
},
],
});
return createElement(
seamless || non_submitting ? 'div' : 'button', seamless || non_submitting ? 'div' : 'button',
{ {
className: classnames(styles.button, className, styles[size], styles[color], { className: classnames(styles.button, className, styles[size], styles[color], {
@ -58,8 +82,19 @@ const Button: FC<IButtonProps> = memo(
iconLeft && <Icon icon={iconLeft} size={20} key={0} className={styles.icon_left} />, iconLeft && <Icon icon={iconLeft} size={20} key={0} className={styles.icon_left} />,
title ? <span>{title}</span> : children || null, title ? <span>{title}</span> : children || null,
iconRight && <Icon icon={iconRight} size={20} key={2} className={styles.icon_right} />, iconRight && <Icon icon={iconRight} size={20} key={2} className={styles.icon_right} />,
!!label && (
<span
ref={tooltip}
className={styles.tooltip}
style={pop.styles.popper}
{...pop.attributes.popper}
>
{label}
</span>
),
] ]
) );
}
); );
export { Button }; export { Button };

View file

@ -10,6 +10,7 @@
} }
.button { .button {
position: relative;
height: $input_height; height: $input_height;
border: none; border: none;
box-sizing: border-box; box-sizing: border-box;
@ -235,3 +236,21 @@
width: 20px; width: 20px;
height: 20px; height: 20px;
} }
.tooltip {
padding: 5px 10px;
background-color: darken($content_bg, 4%);
z-index: 2;
border-radius: $input_radius;
text-transform: none;
opacity: 0;
pointer-events: none;
touch-action: none;
transition: opacity 0.1s;
border: 1px solid transparentize(white, 0.9);
.button:hover & {
opacity: 1;
font: $font_14_semibold;
}
}