mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-05 20:26:19 +02:00
* Fix compound.css - it is not pcss Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Improve types in shared-components storybook Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Update i18n:sort script and remove patch-package --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
60 lines
2.1 KiB
TypeScript
60 lines
2.1 KiB
TypeScript
/*
|
|
* Copyright 2025 New Vector Ltd.
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
* Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import { Addon, types, useGlobals } from "storybook/manager-api";
|
|
import { WithTooltip, IconButton, TooltipLinkList } from "storybook/internal/components";
|
|
import React from "react";
|
|
import { GlobeIcon } from "@storybook/icons";
|
|
|
|
const languages: string[] = JSON.parse(process.env.STORYBOOK_LANGUAGES!);
|
|
|
|
/**
|
|
* Returns the title of a language in the user's locale.
|
|
*/
|
|
function languageTitle(language: string): string {
|
|
const normalisedLang = language.toLowerCase().replace("_", "-");
|
|
return new Intl.DisplayNames([normalisedLang], { type: "language", style: "short" }).of(normalisedLang) || language;
|
|
}
|
|
|
|
export const languageAddon: Addon = {
|
|
title: "Language Selector",
|
|
type: types.TOOL,
|
|
render: ({ active }) => {
|
|
const [globals, updateGlobals] = useGlobals();
|
|
const selectedLanguage = globals.language || "en";
|
|
|
|
return (
|
|
<WithTooltip
|
|
placement="top"
|
|
trigger="click"
|
|
closeOnOutsideClick
|
|
tooltip={({ onHide }) => {
|
|
return (
|
|
<TooltipLinkList
|
|
links={languages.map((language) => ({
|
|
id: language,
|
|
title: languageTitle(language),
|
|
active: selectedLanguage === language,
|
|
onClick: async () => {
|
|
// Update the global state with the selected language
|
|
updateGlobals({ language });
|
|
onHide();
|
|
},
|
|
}))}
|
|
/>
|
|
);
|
|
}}
|
|
>
|
|
<IconButton title="Language">
|
|
<GlobeIcon />
|
|
{languageTitle(selectedLanguage)}
|
|
</IconButton>
|
|
</WithTooltip>
|
|
);
|
|
},
|
|
};
|