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 8 commits
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
91 changes: 89 additions & 2 deletions .pnp.cjs

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

17 changes: 17 additions & 0 deletions .run/test-unit.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="test-unit" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="yarn test unit" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="/bin/zsh" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions packages/payment-widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
"styled-tools": "1.7.2"
},
"devDependencies": {
"@emotion/jest": "11.9.4",
"@emotion/react": "11.9.3",
"@emotion/styled": "11.9.3",
"@testing-library/react": "14.1.0",
"@types/react": "18.2.20",
"@types/react-dom": "18",
"@types/styled-system": "5.1.16",
"csstype": "3.1.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"styled-system": "5.1.5"
},
"peerDependencies": {
Expand Down
25 changes: 14 additions & 11 deletions packages/payment-widget/src/hooks/use-fields-render.hook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { HandleBlurField } from '../interfaces'
import { FieldState } from '../interfaces'
import { HandleChangeField } from '../interfaces'
import { FieldsErrors } from '../interfaces'
import { CustomInput } from '../interfaces/custom-elements.interfaces'
Nelfimov marked this conversation as resolved.
Show resolved Hide resolved
import { MemoizedInput } from '../ui'
import { translate } from '../utils/translate.util'

Expand All @@ -18,27 +19,29 @@ export const useFieldsRenderer = (
fieldsState: FieldState,
handleChange: HandleChangeField,
handleBlur: HandleBlurField,
inputGaps: number
inputGaps: number,
customInput: CustomInput | undefined
Nelfimov marked this conversation as resolved.
Show resolved Hide resolved
) => {
const intl = useIntl()

return fields.map((field, index, currentFields) => {
const translatePlaceholder = translate(intl, field.placeholder, field.placeholder)
const translateError = translate(intl, errors[field.name], errors[field.name])
const isNotLastField = index !== currentFields.length - 1
const inputProps = {
type: field.type ?? 'text',
name: field.name,
placeholder: translatePlaceholder,
required: field.required ?? false,
value: fieldsState[field.name],
errorText: translateError,
onChangeNative: handleChange,
onBlur: handleBlur,
}

return (
<React.Fragment key={field.name}>
<MemoizedInput
type={field.type ?? 'text'}
name={field.name}
placeholder={translatePlaceholder}
required={field.required ?? false}
value={fieldsState[field.name]}
errorText={translateError}
onChangeNative={handleChange}
onBlur={handleBlur}
/>
{customInput ? customInput(inputProps) : <MemoizedInput {...inputProps} />}
<Condition match={isNotLastField}>
<Layout flexBasis={inputGaps} flexShrink={0} />
</Condition>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react'
import { FC } from 'react'

import { HandleBlurField } from './fields.interfaces'
import { HandleChangeField } from './fields.interfaces'

interface CustomInputProps {
type: string
name: string
placeholder: string
required: boolean
value: string
errorText: string
onChangeNative: HandleChangeField
onBlur: HandleBlurField
}

export interface CustomButtonProps {
type: string
disabled: boolean
children?: React.ReactNode
}
Nelfimov marked this conversation as resolved.
Show resolved Hide resolved

export type CustomInput = FC<CustomInputProps>
export type CustomButton = FC<CustomButtonProps>

export interface CustomElements {
input?: CustomInput
button?: CustomButton
}
Nelfimov marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions packages/payment-widget/src/interfaces/fields.interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HTMLInputTypeAttribute } from 'react'

import { AdditionalFieldsType } from '../enums'
import { RequiredFieldsType } from '../enums'
import { CustomInput } from './custom-elements.interfaces'
import { DirectionFields } from './styles.interfaces'

export type FieldsNames = RequiredFieldsType | AdditionalFieldsType
Expand Down Expand Up @@ -38,4 +39,5 @@ export interface FieldsProps {
inputGaps?: number
isGenerateReceipt?: boolean
additionalFields?: AdditionalField[]
customInput?: CustomInput
}
6 changes: 6 additions & 0 deletions packages/payment-widget/src/interfaces/theme.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react'

export interface ThemeProps {
useCustomTheme: boolean
children: React.ReactNode
}
3 changes: 3 additions & 0 deletions packages/payment-widget/src/interfaces/widget.interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CustomElements } from './custom-elements.interfaces'
import { AdditionalField } from './fields.interfaces'
import { ReceiptSettings } from './receipt.interfaces'
import { Settings } from './settings.interfaces'
Expand All @@ -9,4 +10,6 @@ export interface WidgetProps {
receipt?: ReceiptSettings
styles?: Styles
additionalFields?: AdditionalField[]
disabled?: boolean
customElements?: CustomElements
}
20 changes: 10 additions & 10 deletions packages/payment-widget/src/ui/button/button.component.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import styled from '@emotion/styled'
import { ButtonProps } from '@atls-ui-parts/button'
import styled from '@emotion/styled'

import React from 'react'
import { FC } from 'react'
import { useHover } from 'react-laag'
import React from 'react'
import { FC } from 'react'
import { useHover } from 'react-laag'

import { appearanceStyles } from './button.styles'
import { contentStyles } from './button.styles'
import { baseStyles } from './button.styles'
import { shapeStyles } from './button.styles'
import { CustomButtonProps } from '../../interfaces/custom-elements.interfaces'
import { appearanceStyles } from './button.styles'
Nelfimov marked this conversation as resolved.
Show resolved Hide resolved
import { contentStyles } from './button.styles'
import { baseStyles } from './button.styles'
import { shapeStyles } from './button.styles'

const ButtonElement = styled('button')<any>(
baseStyles,
Expand All @@ -17,7 +17,7 @@ const ButtonElement = styled('button')<any>(
shapeStyles
)

export const Button: FC<ButtonProps> = ({ children, ...props }) => {
export const Button: FC<CustomButtonProps> = ({ children, ...props }) => {
const [hover, hoverProps] = useHover()
return (
<ButtonElement hover={hover} {...hoverProps} {...props}>
Expand Down
4 changes: 3 additions & 1 deletion packages/payment-widget/src/ui/fields.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const Fields = ({
isGenerateReceipt = false,
direction = DirectionFields.Column,
inputGaps = 16,
customInput,
}: FieldsProps) => {
const processedFields = isGenerateReceipt
? addReceiptFieldsUtil(additionalFields)
Expand All @@ -35,7 +36,8 @@ export const Fields = ({
fieldsState,
handleChange,
handleBlur,
inputGaps
inputGaps,
customInput
)
const Direction = direction === DirectionFields.Column ? Column : Row

Expand Down
Loading
Loading