diff --git a/packages/action/src/Action.ts b/packages/action/src/Action.ts deleted file mode 100644 index 694ff35ba..000000000 --- a/packages/action/src/Action.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { withClickId } from '@axa-fr/react-toolkit-core'; -import { ComponentProps } from 'react'; -import ActionCore from './ActionCore'; - -const Action = withClickId>({ - event: ['onClick'], -})(ActionCore); - -export default Action; diff --git a/packages/action/src/Action.tsx b/packages/action/src/Action.tsx new file mode 100644 index 000000000..bc09bb441 --- /dev/null +++ b/packages/action/src/Action.tsx @@ -0,0 +1,25 @@ +import React, { ComponentProps, EventHandler, SyntheticEvent } from 'react'; + +import ActionCore from './ActionCore'; + +interface MyEvent extends React.SyntheticEvent { + id: string; +} + +export type ActionProps = Omit, 'onClick'> & { + onClick: React.EventHandler; +}; + +function useWithEventId(fn: EventHandler) { + return (event: T) => { + fn({ ...event, id: event.currentTarget.id }); + }; +} + +const Action = ({ onClick, ...rest }: ActionProps) => { + const onClickCustom = useWithEventId(onClick); + + return ; +}; + +export default Action; diff --git a/packages/all/package.json b/packages/all/package.json index e9b04fbab..d984def09 100644 --- a/packages/all/package.json +++ b/packages/all/package.json @@ -5,6 +5,7 @@ "module": "esm/index.js", "types": "esm/index.d.ts", "private": false, + "sideEffects": false, "scripts": { "prebuild": "rimraf ./component & rimraf ./esm", "build": "tsc -p tsconfig.json & tsc -p tsconfig-cjs.json" diff --git a/packages/button/src/Button.tsx b/packages/button/src/Button.tsx index 7ff3f72e3..1903ac728 100644 --- a/packages/button/src/Button.tsx +++ b/packages/button/src/Button.tsx @@ -1,21 +1,32 @@ -import { - withClickId, - WithClickIdProps, - compose, - identity, -} from '@axa-fr/react-toolkit-core'; -import { ComponentPropsWithoutRef } from 'react'; +import React, { ComponentPropsWithoutRef } from 'react'; import ButtonCore from './ButtonCore'; -type ButtonCoreProps = ComponentPropsWithoutRef; -export type ButtonProps = WithClickIdProps; +interface MyEvent extends React.MouseEvent { + id: string; +} -const Button = compose( - identity(), - withClickId({ event: ['onClick'] }) -)(ButtonCore); +export type ButtonProps = Omit< + ComponentPropsWithoutRef, + 'onClick' +> & { + onClick: React.EventHandler; +}; + +const Button = (props: ButtonProps) => { + const customOnClick = ( + e: React.MouseEvent, + onClick: React.EventHandler + ) => { + return onClick({ ...e, id: props.id }); + }; + + return ( + customOnClick(e, props.onClick)} /> + ); +}; Button.displayName = 'Button'; export default Button; +export { ButtonCore };