Skip to content

Commit

Permalink
fix: Extend Lang type by string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
3y3 committed Nov 12, 2024
1 parent 36e3548 commit 447ee7b
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
"devDependencies": {
"@diplodoc/babel-preset": "^1.0.3",
"@diplodoc/components": "^4.15.4",
"@diplodoc/components": "^4.17.1",
"@diplodoc/lint": "^1.1.1",
"@diplodoc/openapi-extension": "^2.3.3",
"@diplodoc/tsconfig": "^1.0.2",
Expand Down
4 changes: 2 additions & 2 deletions src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export type DocAnalytics = {
};

export interface AppProps {
lang: Lang;
langs: Lang[];
lang: `${Lang}` | Lang;
langs: (`${Lang}` | Lang)[];
router: RouterConfig;
search?: SearchConfig;
analytics?: DocAnalytics;
Expand Down
2 changes: 1 addition & 1 deletion src/components/App/useLangs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {useCallback, useMemo} from 'react';

export function useLangs({router, lang, langs}: AppProps) {
const onChangeLang = useCallback(
(lang: Lang) => {
(lang: `${Lang}` | Lang) => {
const path = getLangPath(router, lang);
window.location.replace(path);
},
Expand Down
6 changes: 3 additions & 3 deletions src/components/HeaderControls/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ export type Props = {
onChangeWideFormat: OnChangeCallback;
showMiniToc: boolean;
onChangeShowMiniToc: OnChangeCallback;
lang: Lang;
langs: Lang[];
onChangeLang?: (lang: Lang) => void;
lang: Lang | `${Lang}`;
langs: (Lang | `${Lang}`)[];
onChangeLang?: (lang: `${Lang}` | Lang) => void;
};

export const HeaderControls = memo<Props>(
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLang.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createContext, useContext} from 'react';
import {Lang} from '@diplodoc/components';

const LangContext = createContext<Lang>(Lang.En);
const LangContext = createContext<`${Lang}` | Lang>(Lang.En);

LangContext.displayName = 'Lang';

Expand Down
4 changes: 2 additions & 2 deletions src/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type NavigationData = PageContent<ConstructorNavigaitonData>;
export type ConfigData = ConstructorPageContent | NavigationData;

export interface PreloadParams {
lang: Lang;
lang: `${Lang}` | Lang;
pageName: string;
pageReferer?: string;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ function replaceTransformer(config: BlocksConfig, newTransformer: TransformerRaw

function transformBlocks(
blocks: ConstructorBlock[],
lang: Lang,
lang: `${Lang}` | Lang,
customYfmTransformer: TransformerRaw,
) {
const customConfig = replaceTransformer(config, customYfmTransformer);
Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function updateRootClassName(states: {
});
}

export function getDirection(lang: Lang): TextDirection {
export function getDirection(lang: `${Lang}` | Lang): TextDirection {
const isRTL = RTL_LANGS.includes(lang);

return isRTL ? TextDirection.RTL : TextDirection.LTR;
Expand Down

0 comments on commit 447ee7b

Please sign in to comment.