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 for RTL icon in component sandbox #215

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion public/locales/en/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"title": "Components",
"searchPlaceholder": "Search by component name",
"color-input_validation-format-error": "Incorrect format",
"maintainers": "Maintainers:"
"maintainers": "Maintainers:",
"theme": "Switch theme",
"rtlOn": "Switch RTL on",
"rtlOff": "Switch RTL off",
"rtlNotSupported": "RTL not supported"
}
7 changes: 6 additions & 1 deletion public/locales/ru/component.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
"actions_openInFigma": "Открыть в Figma",
"title": "Компоненты",
"searchPlaceholder": "Поиск по названию",
"color-input_validation-format-error": "Неверный формат"
"color-input_validation-format-error": "Неверный формат",
"maintainers": "Maintainers:",
"theme": "Переключить тему",
"rtlOn": "Включить RTL",
"rtlOff": "Выключить RTL",
"rtlNotSupported": "RTL не поддерживается"
}
85 changes: 51 additions & 34 deletions src/components/SandboxBlock/SandboxBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {ChevronsCollapseUpRight, ChevronsExpandUpRight, TextAlignRight} from '@gravity-ui/icons';
import {
ChevronsCollapseUpRight,
ChevronsExpandUpRight,
TextAlignLeft,
TextAlignRight,
} from '@gravity-ui/icons';
import {
Col,
Direction,
Expand All @@ -13,6 +18,7 @@ import {
Theme,
Tooltip,
} from '@gravity-ui/uikit';
import {useTranslation} from 'next-i18next';
import React from 'react';

import themeIcon from '../../assets/icons/theme.svg';
Expand All @@ -29,6 +35,8 @@ const SandboxBlock: React.FC<SandboxBlockTypes> = ({
sandboxConfig,
isSupportRTL,
}) => {
const {t} = useTranslation('component');

const [props, setProps] = React.useState({});

const [isIframeLoaded, setIsIframeLoaded] = React.useState(false);
Expand Down Expand Up @@ -178,6 +186,10 @@ const SandboxBlock: React.FC<SandboxBlockTypes> = ({
}
}, [isIframeLoaded, props, iframeTheme, iframeDirection]);

const isRtl = iframeDirection === 'rtl';

const rtlIcon = isRtl ? TextAlignRight : TextAlignLeft;

return (
<div className={b({'full-screen': isFullScreen})}>
<Row space="0">
Expand All @@ -193,39 +205,44 @@ const SandboxBlock: React.FC<SandboxBlockTypes> = ({
<Col s="12" l="4" m="4">
<div className={b('top-actions')}>
<div className={b('top-actions-wrapper')}>
<div
tabIndex={0}
role="button"
className={b('control-icon')}
onClick={() => {
setIframeTheme(iframeTheme === 'dark' ? 'light' : 'dark');
}}
>
<Icon data={themeIcon} size={18} />
</div>
<div
tabIndex={0}
role="button"
className={
isSupportRTL ? b('control-icon') : b('control-icon-disabled')
}
onClick={() => {
if (isSupportRTL) {
setIframeDirection(
iframeDirection === 'ltr' ? 'rtl' : 'ltr',
);
}
}}
>
{isSupportRTL && (
<Icon className={b('icon')} data={TextAlignRight} size={18} />
)}
{!isSupportRTL && (
<Tooltip content={'RTL not supported'}>
<Icon data={TextAlignRight} size={18} />
</Tooltip>
)}
</div>
<Tooltip content={t('theme')}>
<div
tabIndex={0}
role="button"
className={b('control-icon')}
onClick={() => {
setIframeTheme(iframeTheme === 'dark' ? 'light' : 'dark');
}}
>
<Icon data={themeIcon} size={18} />
</div>
</Tooltip>

{isSupportRTL && (
<Tooltip content={isRtl ? t('rtlOff') : t('rtlOn')}>
<div
tabIndex={0}
role="button"
className={b('control-icon')}
onClick={() => {
setIframeDirection(isRtl ? 'ltr' : 'rtl');
}}
>
<Icon className={b('icon')} data={rtlIcon} size={18} />
</div>
</Tooltip>
)}
{!isSupportRTL && (
<Tooltip content={t('rtlNotSupported')}>
<div
tabIndex={0}
role="button"
className={b('control-icon-disabled')}
>
<Icon data={rtlIcon} size={18} />
</div>
</Tooltip>
)}
</div>
<div
tabIndex={0}
Expand Down
Loading