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 11 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
13 changes: 9 additions & 4 deletions packages/payment-widget/src/hooks/use-fields-state.hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import { HandleChangeField } from '../interfaces'
import { FieldsNames } from '../interfaces'
import { ValidateField } from '../interfaces'

export const useFieldsState = (fields: Field[], validateField: ValidateField) => {
const initialState = fields.reduce((acc, field) => ({ ...acc, [field.name]: '' }), {})
const [fieldsState, setFieldsState] = useState<FieldState>(initialState as FieldState)
export const useFieldsState = (validateField: ValidateField, fields?: Field[]) => {
Nelfimov marked this conversation as resolved.
Show resolved Hide resolved
const initialState = fields
? fields.reduce((acc, field) => ({ ...acc, [field.name]: '' }), {})
: ''
const [fieldsState, setFieldsState] = useState<FieldState | string>(
initialState as FieldState | string
)

const handleChange: HandleChangeField = useCallback(
(e: FormEvent<HTMLInputElement>) => {
const name = e.currentTarget.name as FieldsNames
const { value } = e.currentTarget
setFieldsState((prevFields) => ({ ...prevFields, [name]: value }))
setFieldsState((prevFields) =>
typeof prevFields === 'object' ? { ...prevFields, [name]: value } : value)
},
[setFieldsState]
)
Expand Down
2 changes: 1 addition & 1 deletion packages/payment-widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { Widget } from './ui'
export { Widget, InputWrapper, ButtonWrapper } from './ui'
export {
Settings,
Styles,
Expand Down
7 changes: 7 additions & 0 deletions packages/payment-widget/src/interfaces/button.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from 'react'

export interface CustomButtonProps {
type: string
disabled: boolean
children?: React.ReactNode
}
9 changes: 9 additions & 0 deletions packages/payment-widget/src/interfaces/form.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

import { WidgetProps } from './widget.interfaces'

export interface FormProps extends WidgetProps {
useCustomButton: boolean
isGenerateReceipt: boolean
children: React.ReactNode
}
6 changes: 6 additions & 0 deletions packages/payment-widget/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ export * from './fields.interfaces'
export * from './settings.interfaces'
export * from './receipt.interfaces'
export * from './styles.interfaces'
export * from './theme.interfaces'
export * from './button.interfaces'
export * from './input.interfaces'
export * from './theme.interfaces'
TorinAsakura marked this conversation as resolved.
Show resolved Hide resolved
export * from './form.interfaces'
export * from './wrappers.interfaces'
13 changes: 13 additions & 0 deletions packages/payment-widget/src/interfaces/input.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { HandleBlurField } from './fields.interfaces'
import { HandleChangeField } from './fields.interfaces'

export interface CustomInputProps {
type: string
name: string
placeholder: string
required: boolean
value: string
errorText: string
onChangeNative: HandleChangeField
onBlur: HandleBlurField
}
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,5 @@
import React from 'react'

import { AdditionalField } from './fields.interfaces'
import { ReceiptSettings } from './receipt.interfaces'
import { Settings } from './settings.interfaces'
Expand All @@ -9,4 +11,5 @@ export interface WidgetProps {
receipt?: ReceiptSettings
styles?: Styles
additionalFields?: AdditionalField[]
children: React.ReactNode
}
18 changes: 18 additions & 0 deletions packages/payment-widget/src/interfaces/wrappers.interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { FormEvent } from 'react'
import { ReactElement } from 'react'

type OnCallback = (event: FormEvent<HTMLInputElement> | string | any) => void

export interface InputWrapperProps {
name: string
children: (
value: string,
onChange: OnCallback,
onBlur: OnCallback,
errorText: string
) => ReactElement<any>
}

export interface ButtonWrapperProps {
children: () => ReactElement<any>
}
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'
import { appearanceStyles } from './button.styles'
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
5 changes: 3 additions & 2 deletions packages/payment-widget/src/ui/fields.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Row } from '@atls-ui-parts/layout'
import React from 'react'

import { RequiredFieldsType } from '../enums'
import { FieldState } from '../interfaces'
import { FieldsProps } from '../interfaces'
import { DirectionFields } from '../interfaces'
import { requiredFields } from '../data'
Expand All @@ -28,11 +29,11 @@ export const Fields = ({
? addReceiptFieldsUtil(additionalFields)
: additionalFields
const fields = !amount ? [...requiredFields, ...processedFields] : [...processedFields]
const { fieldsState, handleChange, handleBlur } = useFieldsState(fields, validateField)
const { fieldsState, handleChange, handleBlur } = useFieldsState(validateField, fields)
const renderedFields = useFieldsRenderer(
fields,
errors,
fieldsState,
fieldsState as FieldState,
handleChange,
handleBlur,
inputGaps
Expand Down
Loading
Loading