Docker / Docker Buildx (push) Has been cancelled
Build Debian package / Build package (release) Has been cancelled
Build and Deploy / prepare (release) Has been cancelled
Deploy release / Deploy to Cloudflare Pages (release) Has been cancelled
Build and Deploy / Trigger Pro pipeline (release) Has been cancelled
Build and Deploy / Windows arm64 (release) Has been cancelled
Build and Deploy / Windows x64 (release) Has been cancelled
Build and Deploy / macOS (release) Has been cancelled
Build and Deploy / Linux amd64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / Linux arm64 (sqlcipher static) (release) Has been cancelled
Build and Deploy / ${{ needs.prepare.outputs.deploy == 'true' && 'Deploy' || 'Deploy (dry-run)' }} (release) Has been cancelled
Build and Deploy / Deploy builds to ESS (release) Has been cancelled
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>
|
|
);
|
|
},
|
|
};
|