-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PageTitlePreset): added component for page title with applied pr…
…eset
- Loading branch information
Showing
7 changed files
with
112 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"created by": "created by" | ||
} |
17 changes: 17 additions & 0 deletions
17
src/components/PageTitlePreset/PageTitlePreset.i18n/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* eslint-disable */ | ||
// Do not edit, use generator to update | ||
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; | ||
import getLang from '../../../utils/getLang'; | ||
|
||
import ru from './ru.json'; | ||
import en from './en.json'; | ||
|
||
export type I18nKey = keyof typeof ru & keyof typeof en; | ||
type I18nLang = 'ru' | 'en'; | ||
|
||
const keyset: I18nLangSet<I18nKey> = {}; | ||
|
||
keyset['ru'] = ru; | ||
keyset['en'] = en; | ||
|
||
export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"created by": "автор" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { useCallback } from 'react'; | ||
|
||
import { PageTitle } from '../PageTitle'; | ||
|
||
import { tr } from './PageTitlePreset.i18n'; | ||
|
||
interface PageTitlePresetProps { | ||
activityId: string; | ||
currentPresetActivityId?: string; | ||
currentPresetActivityUserName?: string | null; | ||
currentPresetTitle?: string; | ||
shadowPresetActivityId?: string; | ||
shadowPresetActivityUserName?: string | null; | ||
shadowPresetId?: string; | ||
shadowPresetTitle?: string; | ||
title?: string; | ||
setPreset: (id: string) => void; | ||
} | ||
|
||
export const PageTitlePreset: React.FC<PageTitlePresetProps> = ({ | ||
activityId, | ||
currentPresetActivityId, | ||
currentPresetActivityUserName, | ||
currentPresetTitle, | ||
shadowPresetActivityId, | ||
shadowPresetActivityUserName, | ||
shadowPresetId, | ||
shadowPresetTitle, | ||
title, | ||
setPreset, | ||
}) => { | ||
const titleDefault = <PageTitle title={title} />; | ||
const presetInfo = | ||
activityId !== currentPresetActivityId ? `${tr('created by')} ${currentPresetActivityUserName}` : undefined; | ||
const titlePreset = <PageTitle title={title} subtitle={currentPresetTitle} info={presetInfo} />; | ||
|
||
const shadowPresetInfo = | ||
activityId !== shadowPresetActivityId ? `${tr('created by')} ${shadowPresetActivityUserName}` : undefined; | ||
|
||
const onShadowPresetTitleClick = useCallback(() => { | ||
if (shadowPresetId) setPreset(shadowPresetId); | ||
}, [setPreset, shadowPresetId]); | ||
const titleShadow = ( | ||
<PageTitle | ||
title={title} | ||
subtitle={shadowPresetTitle} | ||
info={shadowPresetInfo} | ||
onClick={onShadowPresetTitleClick} | ||
/> | ||
); | ||
// eslint-disable-next-line no-nested-ternary | ||
return currentPresetTitle ? titlePreset : shadowPresetTitle ? titleShadow : titleDefault; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters