Skip to content

Commit

Permalink
docs: add info about providers (#34)
Browse files Browse the repository at this point in the history
* docs: add info about providers

* docs: fix typos
  • Loading branch information
NikitaCG authored Apr 20, 2023
1 parent 3b42a55 commit ff2c014
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"position": "before"
},
{
"pattern": "{@yandex-**,@gravity-ui,@doc-tools}/**",
"pattern": "{@gravity-ui,@doc-tools}/**",
"group": "external",
"position": "after"
},
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ import {BlogPostPage, BlogConstructorProvider} from '@gravity-ui/blog-constructo

```

Documentation about [providerProps](./src/constructor/README.md).

Also blog-constructor have server components to help you transform your data if you need

```jsx
Expand Down
89 changes: 89 additions & 0 deletions src/constructor/README.md
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
16 changes: 2 additions & 14 deletions src/contexts/UserContext.ts
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);

0 comments on commit ff2c014

Please sign in to comment.