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

refactor(hoc): rewrite and clean some HOCs #1007

Merged
merged 2 commits into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions packages/Form/Input/card/src/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React, {
ReactElement,
ReactNode,
} from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import CardHeader from './CardHeader';
/**
* Get a duplicate component from a children. If not, return null
Expand Down Expand Up @@ -109,7 +109,7 @@ const Card = ({
})
);

const className = ClassManager.getComponentClassName(
const className = getComponentClassName(
null,
`${cardClassModifier || ''}${isChecked ? ' active' : ''}${
disabled ? ' disabled' : ''
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/card/src/CardGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentProps } from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import { withInput } from '@axa-fr/react-toolkit-form-core';
import CardGroupStateless from './CardGroupStateless';

Expand All @@ -15,7 +15,7 @@ const CardGroup = ({
value,
...otherProps
}: Props) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-rccard-group'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/date/src/Date.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ChangeEvent, ComponentPropsWithRef, forwardRef } from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import { withInput } from '@axa-fr/react-toolkit-form-core';

type Props = Omit<ComponentPropsWithRef<'input'>, 'value'> & {
Expand All @@ -11,7 +11,7 @@ type Props = Omit<ComponentPropsWithRef<'input'>, 'value'> & {

const Date = forwardRef<HTMLInputElement, Props>(
({ className, classModifier, value, ...otherProps }, ref) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__input-date'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/file/src/File.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
FileRejection,
useDropzone,
} from 'react-dropzone';
import { createId, useComponentClassName } from '@axa-fr/react-toolkit-core';
import { createId, getComponentClassName } from '@axa-fr/react-toolkit-core';
import Button from '@axa-fr/react-toolkit-button';
import { withInput } from '@axa-fr/react-toolkit-form-core';

Expand Down Expand Up @@ -43,7 +43,7 @@ const File = ({
disabled,
});

const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__file-input'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/file/src/FileLine.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import Button from '@axa-fr/react-toolkit-button';
import Popover from '@axa-fr/react-toolkit-popover';
import { CustomFile } from './File';
Expand Down Expand Up @@ -46,7 +46,7 @@ const FileLine = ({
id,
onClick,
}: Props) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__file-line'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/file/src/FileTable.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentPropsWithoutRef } from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import { FileRejection } from 'react-dropzone';
import LineFile from './FileLine';
import { CustomFile } from './File';
Expand Down Expand Up @@ -35,7 +35,7 @@ const FileTable = ({
disabled,
onClick,
}: Props) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'custom-table-file af-file-table'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/number/src/Number.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ChangeEvent, ComponentPropsWithRef, forwardRef } from 'react';
import { useId, useComponentClassName } from '@axa-fr/react-toolkit-core';
import { useId, getComponentClassName } from '@axa-fr/react-toolkit-core';
import { withInput } from '@axa-fr/react-toolkit-form-core';

type Props = ComponentPropsWithRef<'input'> & {
Expand All @@ -8,7 +8,7 @@ type Props = ComponentPropsWithRef<'input'> & {
const CustomNumber = forwardRef<HTMLInputElement, Props>(
({ id, className, classModifier, ...otherProps }, inputRef) => {
const inputId = useId(id);
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__input-text'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/pass/src/Pass.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { ComponentPropsWithRef, forwardRef, MouseEvent } from 'react';
import { withInput } from '@axa-fr/react-toolkit-form-core';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

type Props = Omit<ComponentPropsWithRef<'input'>, 'type' | 'role'> & {
type?: 'text' | 'password';
Expand All @@ -19,7 +19,7 @@ const Pass = forwardRef<HTMLInputElement, Props>(
},
inputRef
) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__pass'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/select/src/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentPropsWithRef, useState } from 'react';
import { useComponentClassName, useId } from '@axa-fr/react-toolkit-core';
import { getComponentClassName, useId } from '@axa-fr/react-toolkit-core';
import { withInput } from '@axa-fr/react-toolkit-form-core';
import SelectBase from './SelectBase';

Expand All @@ -22,7 +22,7 @@ const SelectDefault = ({
}: Props) => {
const [hasHandleChangeOnce, setHasHandleChangeOnce] = useState(false);

const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__select-container'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/slider/src/Slider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { ComponentProps, ReactNode } from 'react';
import RcSlider from 'rc-slider';
import { withInput } from '@axa-fr/react-toolkit-form-core';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import 'rc-slider/assets/index.css';

type RcSliderProps = ComponentProps<typeof RcSlider>;
Expand Down Expand Up @@ -34,7 +34,7 @@ const Slider = ({
{} as Marks
);

const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__slider'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/text/src/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentPropsWithRef, forwardRef } from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import { withInput } from '@axa-fr/react-toolkit-form-core';

type Props = ComponentPropsWithRef<'input'> & {
Expand All @@ -8,7 +8,7 @@ type Props = ComponentPropsWithRef<'input'> & {

const Text = forwardRef<HTMLInputElement, Props>(
({ className, classModifier, ...otherProps }, inputRef) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__input-text'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/Input/textarea/src/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { ComponentPropsWithoutRef, forwardRef } from 'react';
import { withInput } from '@axa-fr/react-toolkit-form-core';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

type Props = ComponentPropsWithoutRef<'textarea'> & {
classModifier?: string;
};

const Textarea = forwardRef<HTMLTextAreaElement, Props>(
({ className, classModifier, ...otherProps }, inputRef) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-form__input-textarea'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/core/src/Field.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ComponentPropsWithoutRef, ReactNode } from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import FieldError from './FieldError';
import MessageTypes from './MessageTypes';
import FieldForm from './FieldForm';
Expand Down Expand Up @@ -34,7 +34,7 @@ const Field = ({
return null;
}

const componentClassName = ClassManager.getComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'row af-form__group'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/core/src/FieldError.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import MessageTypes from './MessageTypes';

const DEFAULT_CLASS_NAME = 'af-form__message';
Expand All @@ -13,7 +13,7 @@ const FieldError = ({
message = null,
messageType = MessageTypes.error,
}: FieldProps) => {
const className = ClassManager.getComponentClassName(
const className = getComponentClassName(
DEFAULT_CLASS_NAME,
messageType,
DEFAULT_CLASS_NAME
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/core/src/FieldForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
isValidElement,
ReactNode,
} from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';
import MessageTypes from './MessageTypes';
import FormClassManager from './FormClassManager';

Expand Down Expand Up @@ -122,7 +122,7 @@ const FieldForm = ({
...getMessageInfo({ ...state, forceDisplayMessage, message, messageType }),
});

const subComponentClassName = useComponentClassName(
const subComponentClassName = getComponentClassName(
className,
classModifier,
defaultClassName
Expand Down
8 changes: 2 additions & 6 deletions packages/Form/core/src/FieldInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

type FieldProps = {
isVisible?: boolean;
Expand All @@ -18,11 +18,7 @@ const FieldInput = ({
return null;
}

const newClassName = ClassManager.getComponentClassName(
className,
classModifier,
''
);
const newClassName = getComponentClassName(className, classModifier, '');
return <div className={newClassName}>{children}</div>;
};

Expand Down
4 changes: 2 additions & 2 deletions packages/Form/core/src/getOptionClassName.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

export function getOptionClassName(
className: string,
Expand All @@ -13,7 +13,7 @@ export function getOptionClassName(
.filter((c) => !!c)
.join(' ');

return ClassManager.getComponentClassName(
return getComponentClassName(
className,
classModifierWithDisabled,
defaultClassName
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/core/src/withInput.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { BaseSyntheticEvent, ComponentType } from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

/**
* @remarks - Will be remove into v2.1.x
Expand Down Expand Up @@ -39,7 +39,7 @@ const defaultWithProps = ({
className?: string;
classModifier?: string;
}) => ({
className: ClassManager.getComponentClassName(className, classModifier, ''),
className: getComponentClassName(className, classModifier, ''),
});

type Handler<H extends { [key: string]: (...args: any[]) => any }> = {
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/steps/src/StepBase.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

type Props = {
id: string;
Expand All @@ -9,7 +9,7 @@ type Props = {
classModifier?: string;
};
const StepBase = ({ children, id, title, className, classModifier }: Props) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-steps-list-step'
Expand Down
4 changes: 2 additions & 2 deletions packages/Form/steps/src/Steps.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { useComponentClassName } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

const defaultClassName = 'af-steps';

Expand All @@ -13,7 +13,7 @@ const Steps = ({
className = defaultClassName,
classModifier,
}: Props) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
defaultClassName
Expand Down
4 changes: 2 additions & 2 deletions packages/Layout/footer-client/src/FooterClient.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

const defaultClassName = 'af-footer-client';

Expand All @@ -17,7 +17,7 @@ const FooterClient = ({
classModifier,
copyright = 'Policy Privacy © 2018 AXA All Rights Reserved',
}: Props) => {
const componentClassName = ClassManager.getComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
defaultClassName
Expand Down
4 changes: 2 additions & 2 deletions packages/Layout/header/src/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ReactNode } from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

type Props = {
children: ReactNode;
Expand All @@ -9,7 +9,7 @@ type Props = {

const Header = (props: Props) => {
const { classModifier, className, children } = props;
const componentClassName = ClassManager.getComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
'af-header'
Expand Down
4 changes: 2 additions & 2 deletions packages/Layout/header/src/Infos/Infos.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Fragment, ReactNode } from 'react';
import { useComponentClassName, useId } from '@axa-fr/react-toolkit-core';
import { getComponentClassName, useId } from '@axa-fr/react-toolkit-core';

const defaultClassName = 'af-contrat';
type TInfo = { id?: string; word: ReactNode; definition: ReactNode };
Expand All @@ -10,7 +10,7 @@ type InfosProps = {
};

const Infos = ({ infos, className, classModifier }: InfosProps) => {
const componentClassName = useComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
defaultClassName
Expand Down
4 changes: 2 additions & 2 deletions packages/Layout/header/src/Name/Name.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { MouseEvent } from 'react';
import { ClassManager } from '@axa-fr/react-toolkit-core';
import { getComponentClassName } from '@axa-fr/react-toolkit-core';

const defaultClassName = 'af-header__name';

Expand All @@ -21,7 +21,7 @@ const Name = ({
classModifier,
onClick,
}: Props) => {
const componentClassName = ClassManager.getComponentClassName(
const componentClassName = getComponentClassName(
className,
classModifier,
defaultClassName
Expand Down
Loading