tycho-components 0.29.2 → 0.29.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/configs/localization/CommentsTexts.js +9 -9
- package/dist/configs/localization/HeaderTexts.d.ts +3 -0
- package/dist/configs/localization/HeaderTexts.js +3 -0
- package/dist/configs/useMessageUtils.d.ts +1 -0
- package/dist/configs/useMessageUtils.js +32 -28
- package/dist/shell/Header/Header.d.ts +5 -1
- package/dist/shell/Header/Header.js +2 -2
- package/dist/shell/Header/HeaderButtons/HeaderButtons.d.ts +4 -1
- package/dist/shell/Header/HeaderButtons/HeaderButtons.js +2 -2
- package/dist/shell/Header/HeaderUser/HeaderUser.d.ts +3 -1
- package/dist/shell/Header/HeaderUser/HeaderUser.js +6 -3
- package/dist/shell/Header/styles.scss +6 -0
- package/dist/shell/LanguageSelector/LanguageSelector.d.ts +3 -1
- package/dist/shell/LanguageSelector/LanguageSelector.js +19 -17
- package/dist/shell/LanguageSelector/styles.scss +34 -0
- package/package.json +1 -1
|
@@ -31,24 +31,24 @@ export const CommentsTexts = {
|
|
|
31
31
|
'label.edited': 'edited',
|
|
32
32
|
},
|
|
33
33
|
'pt-BR': {
|
|
34
|
-
'label.title.comments': '
|
|
35
|
-
'placeholder.comment.text': '
|
|
34
|
+
'label.title.comments': 'Observações',
|
|
35
|
+
'placeholder.comment.text': 'Sua observação',
|
|
36
36
|
'placeholder.comment.title': 'Título (opcional)',
|
|
37
37
|
'placeholder.comment.person': 'Selecione a pessoa',
|
|
38
|
-
'label.button.add': 'Adicionar
|
|
39
|
-
'label.button.update': 'Atualizar
|
|
38
|
+
'label.button.add': 'Adicionar observação',
|
|
39
|
+
'label.button.update': 'Atualizar observação',
|
|
40
40
|
'label.requested.to': 'Enviado para:',
|
|
41
41
|
'label.posted.on': 'Postado em:',
|
|
42
|
-
'placeholder.comments.empty': '
|
|
43
|
-
'tooltip.edit': 'Editar
|
|
44
|
-
'tooltip.delete': 'Remover
|
|
42
|
+
'placeholder.comments.empty': 'Nenhuma observação disponível.',
|
|
43
|
+
'tooltip.edit': 'Editar observação',
|
|
44
|
+
'tooltip.delete': 'Remover observação',
|
|
45
45
|
'tooltip.read': 'Marcar como lido',
|
|
46
46
|
'tooltip.reply': 'Responder',
|
|
47
47
|
'modal.title.footnote': 'Editar nota de rodapé',
|
|
48
48
|
'placeholder.footnote.text': 'Entre o texto da nota de rodapé',
|
|
49
49
|
'modal.title.footnote.remove': 'Confirmação de exclusão de nota de rodapé',
|
|
50
50
|
'modal.text.footnote.remove': 'Tem certeza de que deseja remover esta nota de rodapé? Esta ação é irreversível.',
|
|
51
|
-
'button.add': 'Adicionar
|
|
51
|
+
'button.add': 'Adicionar observação',
|
|
52
52
|
'input.value': 'Comentário',
|
|
53
53
|
'input.title': 'Título',
|
|
54
54
|
'input.user': 'Enviar para usuários',
|
|
@@ -58,7 +58,7 @@ export const CommentsTexts = {
|
|
|
58
58
|
'notification.unread': 'Não lidas',
|
|
59
59
|
'notification.all': 'Lidas',
|
|
60
60
|
'notification.empty': 'Não há notificações',
|
|
61
|
-
'notification.text': '{{user}} adicionou
|
|
61
|
+
'notification.text': '{{user}} adicionou uma nova observação.',
|
|
62
62
|
'label.edited': 'editado',
|
|
63
63
|
},
|
|
64
64
|
it: {
|
|
@@ -17,6 +17,7 @@ export declare const HeaderTexts: {
|
|
|
17
17
|
'profile.label.help': string;
|
|
18
18
|
'profile.label.logout': string;
|
|
19
19
|
'profile.label.home': string;
|
|
20
|
+
'profile.label.language': string;
|
|
20
21
|
'button.sign.in': string;
|
|
21
22
|
'button.close': string;
|
|
22
23
|
};
|
|
@@ -38,6 +39,7 @@ export declare const HeaderTexts: {
|
|
|
38
39
|
'profile.label.help': string;
|
|
39
40
|
'profile.label.logout': string;
|
|
40
41
|
'profile.label.home': string;
|
|
42
|
+
'profile.label.language': string;
|
|
41
43
|
'button.sign.in': string;
|
|
42
44
|
'button.close': string;
|
|
43
45
|
};
|
|
@@ -59,6 +61,7 @@ export declare const HeaderTexts: {
|
|
|
59
61
|
'profile.label.help': string;
|
|
60
62
|
'profile.label.logout': string;
|
|
61
63
|
'profile.label.home': string;
|
|
64
|
+
'profile.label.language': string;
|
|
62
65
|
'button.sign.in': string;
|
|
63
66
|
'button.close': string;
|
|
64
67
|
};
|
|
@@ -17,6 +17,7 @@ export const HeaderTexts = {
|
|
|
17
17
|
'profile.label.help': 'Help Center',
|
|
18
18
|
'profile.label.logout': 'Logout',
|
|
19
19
|
'profile.label.home': 'My profile',
|
|
20
|
+
'profile.label.language': 'Language',
|
|
20
21
|
'button.sign.in': 'Sign In',
|
|
21
22
|
'button.close': 'Close',
|
|
22
23
|
},
|
|
@@ -38,6 +39,7 @@ export const HeaderTexts = {
|
|
|
38
39
|
'profile.label.help': 'Central de Ajuda',
|
|
39
40
|
'profile.label.logout': 'Sair da conta',
|
|
40
41
|
'profile.label.home': 'Meu perfil',
|
|
42
|
+
'profile.label.language': 'Idioma',
|
|
41
43
|
'button.sign.in': 'Entrar',
|
|
42
44
|
'button.close': 'Fechar',
|
|
43
45
|
},
|
|
@@ -59,6 +61,7 @@ export const HeaderTexts = {
|
|
|
59
61
|
'profile.label.help': 'Centro assistenza',
|
|
60
62
|
'profile.label.logout': 'Disconnetti',
|
|
61
63
|
'profile.label.home': 'Il mio profilo',
|
|
64
|
+
'profile.label.language': 'Lingua',
|
|
62
65
|
'button.sign.in': 'Accedi',
|
|
63
66
|
'button.close': 'Chiudi',
|
|
64
67
|
},
|
|
@@ -9,6 +9,7 @@ type ErrorDispatcher = {
|
|
|
9
9
|
t?: TFunction;
|
|
10
10
|
key?: string;
|
|
11
11
|
};
|
|
12
|
+
export declare const getErrorMessageValue: ({ err, t, key }: ErrorDispatcher) => string;
|
|
12
13
|
export declare const useMessageUtils: () => {
|
|
13
14
|
dispatchLoading: (val: boolean, text?: string) => void;
|
|
14
15
|
dispatchError: ({ err, t, key }: ErrorDispatcher) => void;
|
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
import { useContext } from "react";
|
|
2
2
|
import { message, silentLoading, toastLoading } from "../configs/store/actions";
|
|
3
3
|
import CommonContext from "./CommonContext";
|
|
4
|
+
const translateErrorValue = (t, namespace, rawValue) => {
|
|
5
|
+
const entry = `${namespace}:${rawValue}`;
|
|
6
|
+
const translatedValue = t(entry);
|
|
7
|
+
return translatedValue === entry ? rawValue : translatedValue;
|
|
8
|
+
};
|
|
9
|
+
export const getErrorMessageValue = ({ err, t, key }) => {
|
|
10
|
+
if (!t) {
|
|
11
|
+
return err;
|
|
12
|
+
}
|
|
13
|
+
if (!err.response) {
|
|
14
|
+
return translateErrorValue(t, key ?? "message", String(err));
|
|
15
|
+
}
|
|
16
|
+
if (err.response.status === 403) {
|
|
17
|
+
return t("error.access.authorization");
|
|
18
|
+
}
|
|
19
|
+
let errorKey = "";
|
|
20
|
+
if (err.response.data?.message) {
|
|
21
|
+
errorKey = err.response.data.message;
|
|
22
|
+
}
|
|
23
|
+
else if (err.response.data?.description) {
|
|
24
|
+
errorKey = err.response.data.description;
|
|
25
|
+
}
|
|
26
|
+
else if (err.response.data?.errors?.length > 0) {
|
|
27
|
+
errorKey = err.response.data.errors[0].description;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
key = "common";
|
|
31
|
+
errorKey = "internal.server.error";
|
|
32
|
+
}
|
|
33
|
+
return translateErrorValue(t, key ?? "message", errorKey);
|
|
34
|
+
};
|
|
4
35
|
export const useMessageUtils = () => {
|
|
5
36
|
const { state, dispatch } = useContext(CommonContext);
|
|
6
37
|
const isSilentLoading = () => {
|
|
@@ -18,34 +49,7 @@ export const useMessageUtils = () => {
|
|
|
18
49
|
: toastLoading(val));
|
|
19
50
|
};
|
|
20
51
|
const dispatchError = ({ err, t, key }) => {
|
|
21
|
-
|
|
22
|
-
dispatch(message({ value: err, type: "error" }));
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (!err.response) {
|
|
26
|
-
const value = t(`${key ?? "message"}:${err}`);
|
|
27
|
-
dispatch(message({ value, type: "error" }));
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
if (err.response.status === 403) {
|
|
31
|
-
dispatch(message({ value: t("error.access.authorization"), type: "error" }));
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
let errorKey = "";
|
|
35
|
-
if (err.response.data?.message) {
|
|
36
|
-
errorKey = err.response.data.message;
|
|
37
|
-
}
|
|
38
|
-
else if (err.response.data?.description) {
|
|
39
|
-
errorKey = err.response.data.description;
|
|
40
|
-
}
|
|
41
|
-
else if (err.response.data?.errors?.length > 0) {
|
|
42
|
-
errorKey = err.response.data.errors[0].description;
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
key = "common";
|
|
46
|
-
errorKey = "internal.server.error";
|
|
47
|
-
}
|
|
48
|
-
const value = t(`${key ?? "message"}:${errorKey}`);
|
|
52
|
+
const value = getErrorMessageValue({ err, t, key });
|
|
49
53
|
dispatch(message({ value, type: "error" }));
|
|
50
54
|
};
|
|
51
55
|
const dispatchMessage = ({ key, ns, t }) => {
|
|
@@ -18,6 +18,10 @@ type Props = {
|
|
|
18
18
|
navigateNotLogged?: () => void;
|
|
19
19
|
helpActions?: HelpAction[];
|
|
20
20
|
useOpenCorpora?: boolean;
|
|
21
|
+
hideCorpora?: boolean;
|
|
22
|
+
hideNotifications?: boolean;
|
|
23
|
+
hideLanguageSelector?: boolean;
|
|
24
|
+
hideHelpButton?: boolean;
|
|
21
25
|
};
|
|
22
|
-
export default function Header({ tool, redirect, autoload, hideKeyboard, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged, helpActions, useOpenCorpora, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
26
|
+
export default function Header({ tool, redirect, autoload, hideKeyboard, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged, helpActions, useOpenCorpora, hideCorpora, hideNotifications, hideLanguageSelector, hideHelpButton, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
23
27
|
export {};
|
|
@@ -8,10 +8,10 @@ import HeaderUser from './HeaderUser';
|
|
|
8
8
|
import './styles.scss';
|
|
9
9
|
export default function Header({ tool, redirect, autoload, hideKeyboard, customHeader, notifications, keyboardLayout, navigateHome, navigateCorpora, navigateLogout, navigateNotLogged = () => {
|
|
10
10
|
location.href = '/auth';
|
|
11
|
-
}, helpActions, useOpenCorpora = true, }) {
|
|
11
|
+
}, helpActions, useOpenCorpora = true, hideCorpora = false, hideNotifications = false, hideLanguageSelector = false, hideHelpButton = false, }) {
|
|
12
12
|
const { t } = useTranslation('header');
|
|
13
13
|
const homeTextsClass = cx('app-title', {
|
|
14
14
|
pointer: navigateHome !== undefined,
|
|
15
15
|
});
|
|
16
|
-
return (_jsxs("div", { className: "ds-header", children: [_jsxs("div", { className: "header-left", children: [_jsx(HeaderApps, { navigateLogout: navigateLogout, navigateNotLogged: navigateNotLogged, hideKeyboard: hideKeyboard, notifications: notifications, keyboardLayout: keyboardLayout, helpActions: helpActions }), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] }),
|
|
16
|
+
return (_jsxs("div", { className: "ds-header", children: [_jsxs("div", { className: "header-left", children: [_jsx(HeaderApps, { navigateLogout: navigateLogout, navigateNotLogged: navigateNotLogged, hideKeyboard: hideKeyboard, notifications: notifications, keyboardLayout: keyboardLayout, helpActions: helpActions }), _jsxs("div", { className: homeTextsClass, onClick: () => navigateHome && navigateHome(), children: [_jsx("span", { className: "title", children: t('label.platform') }), _jsx("span", { className: "subtitle", children: tool })] }), _jsxs("div", { className: "header-corpus", children: [!hideCorpora && (_jsx(HeaderCorpora, { redirect: redirect, autoload: autoload, navigateCorpora: navigateCorpora, useOpenCorpora: useOpenCorpora })), customHeader && customHeader] })] }), _jsxs("div", { className: "header-right", children: [_jsx(HeaderButtons, { hideKeyboard: hideKeyboard, notifications: notifications, keyboardLayout: keyboardLayout, helpActions: helpActions, hideNotifications: hideNotifications, hideLanguageSelector: hideLanguageSelector, hideHelpButton: hideHelpButton }), _jsx(HeaderUser, { navigateLogout: navigateLogout, navigateNotLogged: navigateNotLogged })] })] }));
|
|
17
17
|
}
|
|
@@ -11,6 +11,9 @@ type Props = {
|
|
|
11
11
|
navigateCorpora?: (uid: string) => void;
|
|
12
12
|
helpActions?: HelpAction[];
|
|
13
13
|
mobile?: boolean;
|
|
14
|
+
hideNotifications?: boolean;
|
|
15
|
+
hideLanguageSelector?: boolean;
|
|
16
|
+
hideHelpButton?: boolean;
|
|
14
17
|
};
|
|
15
|
-
export default function HeaderButtons({ hideKeyboard, notifications, keyboardLayout, helpActions, mobile, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export default function HeaderButtons({ hideKeyboard, notifications, keyboardLayout, helpActions, mobile, hideNotifications, hideLanguageSelector, hideHelpButton, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
16
19
|
export {};
|
|
@@ -9,10 +9,10 @@ import { useLoggedUtils } from '../../../configs/useLoggedUtils';
|
|
|
9
9
|
import HelpButton from '../HelpButton';
|
|
10
10
|
import './styles.scss';
|
|
11
11
|
const HeaderNotifications = lazy(() => import('../../../features/Comments/HeaderNotifications'));
|
|
12
|
-
export default function HeaderButtons({ hideKeyboard, notifications, keyboardLayout, helpActions, mobile, }) {
|
|
12
|
+
export default function HeaderButtons({ hideKeyboard, notifications, keyboardLayout, helpActions, mobile, hideNotifications = false, hideLanguageSelector = false, hideHelpButton = false, }) {
|
|
13
13
|
const { t } = useTranslation('header');
|
|
14
14
|
const { getCorpus } = useCorpusUtils();
|
|
15
15
|
const { isLogged } = useLoggedUtils();
|
|
16
16
|
const [openKeyboard, setOpenKeyboard] = useState(false);
|
|
17
|
-
return (_jsxs("div", { className: "header-buttons", children: [!hideKeyboard && (_jsx(IconButton, { onClick: () => setOpenKeyboard(!openKeyboard), name: "keyboard", size: "large", title: t('tooltip.keyboard'), mode: mobile ? 'outlined' : 'filled' })), _jsx(HelpButton, { helpActions: helpActions, mobile: mobile }), notifications && isLogged() && (_jsx(Suspense, { fallback: null, children: _jsx(HeaderNotifications, { uid: notifications.ref, mode: notifications.mode, mobile: mobile }) })), _jsx(LanguageSelector, { openToTop: mobile ? true : false, mobile: mobile }), openKeyboard && (_jsx(VirtualKeyboard, { onClose: () => setOpenKeyboard(false), closeLabel: t('button.close'), defaultLayout: keyboardLayout || getCorpus().keyboardLayout || 'english' }))] }));
|
|
17
|
+
return (_jsxs("div", { className: "header-buttons", children: [!hideKeyboard && (_jsx(IconButton, { onClick: () => setOpenKeyboard(!openKeyboard), name: "keyboard", size: "large", title: t('tooltip.keyboard'), mode: mobile ? 'outlined' : 'filled' })), !hideHelpButton && (_jsx(HelpButton, { helpActions: helpActions, mobile: mobile })), !hideNotifications && notifications && isLogged() && (_jsx(Suspense, { fallback: null, children: _jsx(HeaderNotifications, { uid: notifications.ref, mode: notifications.mode, mobile: mobile }) })), !hideLanguageSelector && (_jsx(LanguageSelector, { openToTop: mobile ? true : false, mobile: mobile })), openKeyboard && (_jsx(VirtualKeyboard, { onClose: () => setOpenKeyboard(false), closeLabel: t('button.close'), defaultLayout: keyboardLayout || getCorpus().keyboardLayout || 'english' }))] }));
|
|
18
18
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import './style.scss';
|
|
2
|
+
import { HelpAction } from '../HelpButton/HelpButton';
|
|
2
3
|
type Props = {
|
|
3
4
|
navigateLogout?: () => void;
|
|
4
5
|
navigateNotLogged: () => void;
|
|
6
|
+
helpActions?: HelpAction[];
|
|
5
7
|
};
|
|
6
|
-
export default function HeaderUser({ navigateLogout, navigateNotLogged, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export default function HeaderUser({ navigateLogout, navigateNotLogged, helpActions, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
7
9
|
export {};
|
|
@@ -3,17 +3,20 @@ import { useState } from 'react';
|
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import { Avatar, Button, Icon } from 'tycho-storybook';
|
|
5
5
|
import { useLoggedUtils } from '../../../configs/useLoggedUtils';
|
|
6
|
+
import LanguageSelector from '../../LanguageSelector';
|
|
6
7
|
import './style.scss';
|
|
7
|
-
|
|
8
|
+
import HelpModal from '../HelpButton/HelpModal';
|
|
9
|
+
export default function HeaderUser({ navigateLogout, navigateNotLogged, helpActions, }) {
|
|
8
10
|
const { t } = useTranslation('header');
|
|
9
11
|
const { isLogged, getLogged } = useLoggedUtils();
|
|
10
12
|
const [open, setOpen] = useState(false);
|
|
13
|
+
const [openHelp, setOpenHelp] = useState(false);
|
|
11
14
|
const handleProfile = () => {
|
|
12
15
|
setOpen(false);
|
|
13
16
|
window.open(import.meta.env.VITE_APP_RESERVED_URL, '_blank');
|
|
14
17
|
};
|
|
15
|
-
return (_jsxs("div", { className: "profile-container", "data-tour": "header-user", children: [isLogged() ? (_jsx("div", { onClick: () => setOpen(!open), children: _jsx(Avatar, { size: "small", src: getLogged()?.picture, title: getLogged()?.name || getLogged()?.sub }) })) : (_jsx(Button, { text: t('button.sign.in'), size: "small", onClick: navigateNotLogged })), open && isLogged() && (_jsxs("div", { className: "ds-dropdown-list", children: [_jsx("div", { className: "ds-dropdown-itemlist", children: _jsx("span", { className: "label", children: `${t('profile.label.hello')} ${getLogged()?.name || getLogged()?.sub}` }) }), _jsxs("div", { className: "ds-dropdown-itemlist d-none", children: [_jsx(Icon, { name: "colors", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.theme') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: handleProfile, children: [_jsx(Icon, { name: "person", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.home') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", children: [_jsx(Icon, { name: "live_help", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.help') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => {
|
|
18
|
+
return (_jsxs("div", { className: "profile-container", "data-tour": "header-user", children: [isLogged() ? (_jsx("div", { onClick: () => setOpen(!open), children: _jsx(Avatar, { size: "small", src: getLogged()?.picture, title: getLogged()?.name || getLogged()?.sub }) })) : (_jsx(Button, { text: t('button.sign.in'), size: "small", onClick: navigateNotLogged })), open && isLogged() && (_jsxs("div", { className: "ds-dropdown-list", children: [_jsx("div", { className: "ds-dropdown-itemlist", children: _jsx("span", { className: "label", children: `${t('profile.label.hello')} ${getLogged()?.name || getLogged()?.sub}` }) }), _jsxs("div", { className: "ds-dropdown-itemlist d-none", children: [_jsx(Icon, { name: "colors", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.theme') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: handleProfile, children: [_jsx(Icon, { name: "person", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.home') })] }), _jsx(LanguageSelector, { renderMode: "profile-menu", itemLabel: t('profile.label.language') }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => setOpenHelp(true), children: [_jsx(Icon, { name: "live_help", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.help') })] }), _jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => {
|
|
16
19
|
setOpen(false);
|
|
17
20
|
navigateLogout && navigateLogout();
|
|
18
|
-
}, children: [_jsx(Icon, { name: "logout", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.logout') })] })] }))] }));
|
|
21
|
+
}, children: [_jsx(Icon, { name: "logout", size: "x-small" }), _jsx("span", { className: "label", children: t('profile.label.logout') })] })] })), openHelp && (_jsx(HelpModal, { onClose: () => setOpenHelp(false), helpActions: helpActions }))] }));
|
|
19
22
|
}
|
|
@@ -13,10 +13,12 @@ export type Props = {
|
|
|
13
13
|
/** When true, the option list opens above the trigger instead of below. */
|
|
14
14
|
openToTop?: boolean;
|
|
15
15
|
mobile?: boolean;
|
|
16
|
+
renderMode?: 'dropdown' | 'profile-menu';
|
|
17
|
+
itemLabel?: string;
|
|
16
18
|
};
|
|
17
19
|
export type AvailableLanguage = {
|
|
18
20
|
value: string;
|
|
19
21
|
name: string;
|
|
20
22
|
};
|
|
21
23
|
export declare const AvailableLanguages: AvailableLanguage[];
|
|
22
|
-
export default function LanguageSelector({ className, color, size, showFullLanguageLabel, openToTop, mobile, }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
24
|
+
export default function LanguageSelector({ className, color, size, showFullLanguageLabel, openToTop, mobile, renderMode, itemLabel, }: Props): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import cx from 'classnames';
|
|
3
|
-
import {
|
|
3
|
+
import { useState } from 'react';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { Icon } from 'tycho-storybook';
|
|
6
6
|
import './styles.scss';
|
|
@@ -25,28 +25,30 @@ export const AvailableLanguages = [
|
|
|
25
25
|
name: 'Italiano',
|
|
26
26
|
},
|
|
27
27
|
];
|
|
28
|
-
|
|
28
|
+
const getSelectedLanguage = (languageCode) => AvailableLanguages.find((item) => item.value === languageCode) ||
|
|
29
|
+
AvailableLanguages[0];
|
|
30
|
+
export default function LanguageSelector({ className, color = 'primary', size = 'medium', showFullLanguageLabel = false, openToTop = false, mobile = false, renderMode = 'dropdown', itemLabel, }) {
|
|
31
|
+
const isProfileMenu = renderMode === 'profile-menu';
|
|
29
32
|
const getClassNames = cx('language-container', className, openToTop && 'language-container--open-top');
|
|
30
|
-
const getClassNamesDropdown = cx('ds-dropdown-button',
|
|
33
|
+
const getClassNamesDropdown = cx('ds-dropdown-button', mobile ? 'tertiary' : color, size);
|
|
31
34
|
const { i18n } = useTranslation();
|
|
32
35
|
const [open, setOpen] = useState(false);
|
|
33
|
-
const
|
|
36
|
+
const language = getSelectedLanguage(i18n.resolvedLanguage || i18n.language);
|
|
34
37
|
const changeLanguageHandler = (lang) => {
|
|
35
|
-
setLanguage(lang);
|
|
36
38
|
setOpen(false);
|
|
37
39
|
i18n.changeLanguage(lang.value);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (i18n.language &&
|
|
42
|
-
AvailableLanguages.filter((t) => t.value === i18n.language).length > 0) {
|
|
43
|
-
setLanguage(AvailableLanguages.filter((t) => t.value === i18n.language)[0]);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
setLanguage(AvailableLanguages[0]);
|
|
40
|
+
if (!isProfileMenu) {
|
|
41
|
+
document.body.click();
|
|
47
42
|
}
|
|
48
|
-
}
|
|
43
|
+
};
|
|
49
44
|
if (!language)
|
|
50
45
|
return null;
|
|
51
|
-
|
|
46
|
+
if (isProfileMenu) {
|
|
47
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { className: cx('ds-dropdown-itemlist', 'ds-dropdown-itemlist--language-toggle', open && 'ds-dropdown-itemlist--language-toggle-open'), onClick: () => setOpen(!open), children: [_jsx("span", { className: "label", children: itemLabel || language.name }), _jsx("span", { className: "sublabel", children: showFullLanguageLabel ? language.name : language.value }), _jsx(Icon, { name: "arrow_drop_down", className: "icon-arrow" })] }), open &&
|
|
48
|
+
AvailableLanguages.map((item) => (_jsxs("div", { className: cx('ds-dropdown-itemlist', 'ds-dropdown-itemlist--language-option'), onClick: (event) => {
|
|
49
|
+
event.stopPropagation();
|
|
50
|
+
changeLanguageHandler(item);
|
|
51
|
+
}, children: [_jsx("span", { className: "label", children: item.name }), _jsx("span", { className: "sublabel", children: item.value }), item.value === language.value && (_jsx(Icon, { name: "check", size: "x-small", className: "icon-check" }))] }, item.value)))] }));
|
|
52
|
+
}
|
|
53
|
+
return (_jsx("div", { className: getClassNames, "data-tour": "language-selector", children: _jsxs("div", { className: "ds-dropdown-container", children: [_jsxs("div", { className: getClassNamesDropdown, onClick: () => setOpen(!open), children: [_jsx("span", { className: "label", children: showFullLanguageLabel ? language.name : language.value }), _jsx(Icon, { name: "arrow_drop_down", className: "icon-arrow" })] }), open && (_jsx("div", { className: "ds-dropdown-list", children: AvailableLanguages.map((item) => (_jsxs("div", { className: "ds-dropdown-itemlist", onClick: () => changeLanguageHandler(item), children: [_jsx("span", { className: "label", children: item.name }), _jsx("span", { className: "sublabel", children: item.value }), item.value === language.value && (_jsx(Icon, { name: "check", size: "x-small", className: "icon-check" }))] }, item.value))) }))] }) }));
|
|
52
54
|
}
|
|
@@ -22,6 +22,40 @@
|
|
|
22
22
|
margin-left: var(--spacing-100);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
.ds-dropdown-itemlist--language-toggle {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
|
|
30
|
+
.sublabel {
|
|
31
|
+
margin-left: auto;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.icon-arrow {
|
|
35
|
+
margin-left: var(--spacing-100);
|
|
36
|
+
transition: transform 0.2s ease;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.ds-dropdown-itemlist--language-toggle-open {
|
|
40
|
+
.icon-arrow {
|
|
41
|
+
transform: rotate(180deg);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.ds-dropdown-itemlist--language-option {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
padding-left: calc(var(--spacing-200) + var(--spacing-100));
|
|
50
|
+
|
|
51
|
+
.sublabel {
|
|
52
|
+
margin-left: var(--spacing-100);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.icon-check {
|
|
56
|
+
margin-left: auto;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
25
59
|
}
|
|
26
60
|
}
|
|
27
61
|
|