-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add info about providers (#34)
* docs: add info about providers * docs: fix typos
- Loading branch information
Showing
4 changed files
with
94 additions
and
15 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,89 @@ | ||
# Blog Constructor Provider | ||
|
||
It combines contexts that are used to push data into lower-level components. Each one is configured via the corresponding prop. About them further. | ||
|
||
```jsx | ||
interface BlogConstructorProviderProps { | ||
isMobile?: boolean; | ||
locale?: Locale; | ||
router?: RouterContextProps; | ||
theme?: ThemeValueType; | ||
user?: UserContextProps; | ||
device?: DeviceContextProps; | ||
analytics?: AnalyticsContextProps; | ||
children?: React.ReactNode; | ||
} | ||
``` | ||
|
||
### `isMobile` - boolean flag | ||
|
||
### `Locale` - information about site localization | ||
|
||
```jsx | ||
/* | ||
lang - 'ru' | 'en | ||
langName - string, 'English' for example | ||
pathPrefix - string, 'en' - for example | ||
code - string, 'en' - for example | ||
*/ | ||
interface Locale | ||
extends Partial<Pick<LangData, 'langName'>>, | ||
Pick<LangData, 'lang'>, | ||
Partial<Pick<LangData, 'pathPrefix'>>, | ||
Partial<Pick<LocaleData, 'code'>> {} | ||
``` | ||
|
||
### `Router` - information for page routing | ||
|
||
```jsx | ||
type Query = Record<string, number | string | null>; | ||
|
||
interface RouterContextProps { | ||
pathname: string; | ||
as: string; | ||
hostname: string; | ||
query?: Query; | ||
updateQueryCallback: (query: Query) => void; | ||
} | ||
``` | ||
|
||
**!!! Most important thing** - your `updateQueryCallback` callback should update the routing in replace mode and with the shallow option | ||
|
||
### `Theme` - theme settings | ||
|
||
```jsx | ||
type ThemeValueType = 'light' | 'dark'; | ||
``` | ||
|
||
### `User` - info about user | ||
|
||
```jsx | ||
interface UserAccount { | ||
uid: string; | ||
} | ||
``` | ||
|
||
### `Device` - information about device | ||
|
||
```jsx | ||
import {IBrowser, IDevice} from 'ua-parser-js'; | ||
|
||
export interface DeviceContextProps { | ||
device?: IDevice; | ||
browser?: IBrowser; | ||
isRobot: boolean; | ||
} | ||
``` | ||
|
||
### `Analytics` - analytics settings | ||
|
||
```jsx | ||
interface AnalyticsContextProps { | ||
sendEvents?: (events: AnalyticsEvent[]) => void; | ||
autoEvents?: boolean; | ||
} | ||
``` | ||
|
||
**!!! Important thing** - We throw analytics settings in blog constructor provide, if we need analytics from only-blog components. If we need analytics in page-constructor blocks we need to throw analytics settings in [page settings props](../containers/BlogPage/README.md) | ||
|
||
### `Children` - children react component |
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 |
---|---|---|
@@ -1,22 +1,10 @@ | ||
import React from 'react'; | ||
|
||
//TODO refactor user context | ||
export interface UserAccount { | ||
uid: string; | ||
login: string; | ||
avatarId: string; | ||
displayName?: string; | ||
lang?: string; | ||
hasStaffLogin?: boolean; | ||
} | ||
|
||
export interface User extends UserAccount { | ||
accounts: UserAccount[]; | ||
passportHost: string; | ||
avatarHost: string; | ||
status: string; | ||
yandexuid: string; | ||
} | ||
|
||
export type UserContextProps = Partial<User>; | ||
export type UserContextProps = Partial<UserAccount>; | ||
|
||
export const UserContext = React.createContext<UserContextProps>({} as UserContextProps); |