Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/custom theme #134

Merged
merged 25 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
be63fa6
feat(theme): add property customTheme, Theme interface
absolemDev Nov 15, 2023
9374544
feat(form): add disabled property
absolemDev Nov 15, 2023
6921103
feat(input, button): customization components, add interfaces
absolemDev Nov 16, 2023
96cd845
fix(theme-provider): add conditional render
absolemDev Nov 16, 2023
e005061
feat: test
Nelfimov Nov 17, 2023
2ec40ad
chore: deps
Nelfimov Nov 17, 2023
5398e3a
feat: add customElement property, interfaces, conditional render cust…
absolemDev Nov 20, 2023
9f9f1d8
fix: install dependencies
absolemDev Nov 20, 2023
c3e7e80
fix: imports, interfaces
absolemDev Nov 20, 2023
c9b1626
feat: add wrappers for custom elemrnts
absolemDev Nov 22, 2023
bf5c3ac
fix: interfaces
absolemDev Nov 22, 2023
2b0cd55
feat: add form provider, form context, hook useForm
absolemDev Nov 23, 2023
611572e
fix: interfaces
absolemDev Nov 23, 2023
2762700
fix(input-wrapper): transform children arguments to object
absolemDev Nov 23, 2023
e122833
feat: add disabled prop, arguments for cildren button wrapper, edit i…
absolemDev Nov 24, 2023
9ac4775
fix(form-provider): export const
absolemDev Nov 24, 2023
84addff
feat(enums): add ButtonType enum
absolemDev Nov 24, 2023
f8d6d3c
feat: add use-custom-element hook, extend form context, edit interfaces
absolemDev Nov 27, 2023
bf5b803
fix: useMemo props for custom-elements hook, use Condition in wrapper…
absolemDev Nov 28, 2023
78bbb3d
fix: add fields hook, button hook, utils
absolemDev Nov 28, 2023
4272da8
docs: add README.md
absolemDev Nov 28, 2023
cfc8b6b
docs: edit README.md
absolemDev Nov 29, 2023
759c5c0
fix: get-name-fields util
absolemDev Nov 29, 2023
6b3cc3d
docs: edit package name
absolemDev Nov 29, 2023
2da55e8
fix: yarn check
absolemDev Nov 29, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 36 additions & 43 deletions packages/payment-widget/README.md
Original file line number Diff line number Diff line change
@@ -1,68 +1,61 @@
# Применение
# @atls/react-payment-widget

TorinAsakura marked this conversation as resolved.
Show resolved Hide resolved
## С темой виджета
[//]: # 'VERSIONS'

Для корректной работы Виджета достаточно атрибуту `settings` назначить объект с ключом `storeID`:
## [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=%40atls-ui-parts%2Fbutton&message=0.0.12&labelColor=097CEB&color=0B6DCC">](https://www.npmjs.com/package/@atls-ui-parts/button/v/0.0.12) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=%40atls-ui-parts%2Fcondition&message=0.0.4&labelColor=097CEB&color=0B6DCC">](https://www.npmjs.com/package/@atls-ui-parts/condition/v/0.0.4) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=%40atls-ui-parts%2Fhidden-input&message=0.0.6&labelColor=097CEB&color=0B6DCC">](https://www.npmjs.com/package/@atls-ui-parts/hidden-input/v/0.0.6) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=%40atls-ui-parts%2Finput&message=0.0.13&labelColor=097CEB&color=0B6DCC">](https://www.npmjs.com/package/@atls-ui-parts/input/v/0.0.13) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=%40atls-ui-parts%2Flayout&message=0.0.7&labelColor=097CEB&color=0B6DCC">](https://www.npmjs.com/package/@atls-ui-parts/layout/v/0.0.7) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=%40atls-ui-parts%2Ftext&message=0.0.11&labelColor=097CEB&color=0B6DCC">](https://www.npmjs.com/package/@atls-ui-parts/layout/v/0.0.7) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=react-intl&message=6.4.4&labelColor=ECEEF5&color=D7DCEB">](https://www.npmjs.com/package/react-intl/v/6.4.4) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=react-laag&message=2.0.5&labelColor=ECEEF5&color=D7DCEB">](https://www.npmjs.com/package/react-laag) [<img src="https://img.shields.io/static/v1?style=for-the-badge&label=styled-tools&message=1.7.2&labelColor=ECEEF5&color=D7DCEB">](https://www.npmjs.com/package/styled-tools)

```tsx
import { Widget } from "@atls/react-payment-widget";
export const Form = () => <Widget settings={{ storeId: "STORE_ID" }} />;
```
**@atls/react-payment-widget** предназначен для интеграции в проекты формы, позволяющей проводить оплаты с помощью терминала "Тинькофф Касса". Реализован при помощи `styled-components` и `@emotion`.

Для добавления дополнительных полей используйте атрибут `additionalFields` который принимает в себя массив объектов с обязательным ключом `name`.
## Использование со стандартной темой

Атрибут `amount` принимает сумму платежа. Без заданного значения Виджет генерирует обязательное поле для ввода суммы.
Для корректной работы **@atls/react-payment-widget** достаточно для компонента `Widget` назначить атрибуту `settings` объект с ключом `storeID`:

```tsx
import { Widget, AdditionalFieldsType } from "@atls/react-payment-widget";
export const Form = () => (
<Widget
amount={10000}
settings={{ storeId: "STORE_ID" }}
additionalFields={[{ name: AdditionalFieldsType.Email }]}
/>
);
import { Widget } from '@atls/react-payment-widget'
export const Form = () => <Widget settings={{ storeId: 'STORE_ID' }} />
```

## С темой проекта
Основные атрибуты для компонента `Widget`:

- **`settings`** - обязательный атрибут, принимает объект с настройками для терминала.
- **`amount`** - опциональный атрибут, принимает сумму платежа.Без заданного значения `Widget` генерирует обязательное поле для ввода суммы.
- **`additionalFields`** - опциональный атрибут для добавления дополнительных полей, принимает массив объектов с обязательным ключом `name`.
- **`receipt`** - опциональный атрибут, принимает объект с настройками для генерации чека.
- **`styles`** - опциональный атрибут, принимает объект с настройками для генерации чека.
- **`disabled`** - опциональный атрибут для управлением активным состоянием кнопки, принимает булево значение.

## Использование с кастомной темой

**@atls/react-payment-widget** предусматривает возможность использования стилизованных полей ввода и кнопки из Вашего проекта. Для этого предоставляются компоненты обёртки `InputWrapper` и `ButtonWrapper`.

Если Вы хотите использовать кастомные поля и кнопку, то используйте предоставляемые Виджетом обёртки `InputWrapper` и `ButtonWrapper`. `InputWrapper` принимает обязательный атрибут `name`.
`InputWrapper` принимает обязательный атрибут `name`.

```tsx
import {
Widget,
AdditionalFieldsType,
InputWrapper,
ButtonWrapper,
} from "@atls/react-payment-widget";
import { AdditionalFieldsType } from '@atls/react-payment-widget'
import { ButtonWrapper } from '@atls/react-payment-widget'
import { InputWrapper } from '@atls/react-payment-widget'
import { Widget } from '@atls/react-payment-widget'
export const Form = () => (
<Widget
amount={amount}
settings={{ storeId: "1698844342541DEMO" }}
disabled={!privacyPolicy}
>
<InputWrapper name={AdditionalFieldsType.Email}>
{(props) => <Input {...props} placeholder={fieldToLabelMap.email} />}
</InputWrapper>
<ButtonWrapper>
{(props) => <Button {...props}>Оплатить</Button>}
</ButtonWrapper>
<Widget amount={5000} settings={{ storeId: '1698844342541DEMO' }}>
<InputWrapper name={AdditionalFieldsType.Email}>{(props) => <Input {...props} />}</InputWrapper>
<ButtonWrapper>{(props) => <Button {...props}>Оплатить</Button>}</ButtonWrapper>
</Widget>
);
)
```

> [!WARNING]
> [!WARNING]
> Не используйте атрибут `additionalFields` совместно с `InputWrapper`, это приведет к исключению.
>
> Так же, при использовании `InputWrapper` Виджет не генерирует дополнительные поля.

## Экспортируемые компоненты

**Widget** - главный компонент Виджета.
[**Widget**]() - главный компонент Виджета.

**InputWrapper** - компонент обёртка для полей ввода.
[**InputWrapper**]() - компонент обёртка для полей ввода.

**ButtonWrapper** - компонент обёртка для кнопки.
[**ButtonWrapper**]() - компонент обёртка для кнопки.

**AdditionalFieldsType** - интерфейс дополнительных полей.
[**AdditionalFieldsType**]() - интерфейс дополнительных полей.

**RequiredFieldsType** - интерфейс обязательных полей.
[**RequiredFieldsType**]() - интерфейс обязательных полей.
2 changes: 1 addition & 1 deletion packages/payment-widget/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export { useValidate } from './use-validate.hook'
export { useFieldsState } from './use-fields-state.hook'
export { useFieldsRenderer } from './use-fields-render.hook'
export { useCustomFields } from './use-custom-fields.hook'
export { useCustomButton } from './use-castom-button.hook'
export { useCustomButton } from './use-custom-button.hook'
14 changes: 7 additions & 7 deletions packages/payment-widget/src/hooks/use-custom-fields.hook.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ReactNode } from 'react'
import { isValidElement } from 'react'
import { ReactNode } from 'react'
import { isValidElement } from 'react'

import { AdditionalFieldsType } from '../enums'
import { AdditionalFieldsType } from '../enums'
import { NameWrapperComponent } from '../enums'
import { RequiredFieldsType } from '../enums'
import { CustomFields } from '../interfaces'
import { CustomFieldsProps } from '../interfaces'
import { isCustomElement } from '../utils'
import { RequiredFieldsType } from '../enums'
import { CustomFields } from '../interfaces'
import { CustomFieldsProps } from '../interfaces'
import { isCustomElement } from '../utils'

export const useCustomFields = ({
existAmount,
Expand Down
24 changes: 12 additions & 12 deletions packages/payment-widget/src/ui/widget.component.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as messagesRu from '../locales/ru.json'
import * as messagesEn from '../locales/en.json'
import * as messagesRu from '../locales/ru.json'
import * as messagesEn from '../locales/en.json'

import React from 'react'
import { Children } from 'react'
import { IntlProvider } from 'react-intl'
import { useMemo } from 'react'
import React from 'react'
import { Children } from 'react'
import { IntlProvider } from 'react-intl'
import { useMemo } from 'react'

import { LanguagesType } from '../enums'
import { WidgetProps } from '../interfaces'
import { Form } from './form'
import { FormProvider } from './form/form.provider'
import { useCustomButton } from '../hooks'
import { LanguagesType } from '../enums'
import { WidgetProps } from '../interfaces'
import { Form } from './form'
import { FormProvider } from './form/form.provider'
import { useCustomButton } from '../hooks'
import { useCustomFields } from '../hooks'
import { getNameFields } from '../utils'
import { getNameFields } from '../utils'

const messages = {
[LanguagesType.RUSSIAN]: messagesRu,
Expand Down
11 changes: 5 additions & 6 deletions packages/payment-widget/src/utils/get-name-fields.util.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ReactNode } from 'react'
import { ReactNode } from 'react'
import { isValidElement } from 'react'

import { isValidElement } from 'react'

import { AdditionalFieldsType } from '../enums'
import { RequiredFieldsType } from '../enums'
import { Field } from '../interfaces'
import { AdditionalFieldsType } from '../enums'
import { RequiredFieldsType } from '../enums'
import { Field } from '../interfaces'

export const getNameFields = (customFields: ReactNode[]) =>
customFields.reduce<Field[]>((acc, field) => {
Expand Down
Loading