Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.
Draft
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
9 changes: 0 additions & 9 deletions packages/action/src/Action.ts

This file was deleted.

25 changes: 25 additions & 0 deletions packages/action/src/Action.tsx
Original file line number Diff line number Diff line change
@@ -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<ComponentProps<typeof ActionCore>, 'onClick'> & {
onClick: React.EventHandler<MyEvent>;
};

function useWithEventId<T extends SyntheticEvent>(fn: EventHandler<MyEvent>) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pourquoi le nommer comme un hook React alors que ce n'est pas un hook, c'est trompeur :(

return (event: T) => {
fn({ ...event, id: event.currentTarget.id });
};
}

const Action = ({ onClick, ...rest }: ActionProps) => {
const onClickCustom = useWithEventId(onClick);

return <ActionCore {...rest} onClick={onClickCustom} />;
};

export default Action;
1 change: 1 addition & 0 deletions packages/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
37 changes: 24 additions & 13 deletions packages/button/src/Button.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof ButtonCore>;
export type ButtonProps = WithClickIdProps<ButtonCoreProps, 'onClick'>;
interface MyEvent extends React.MouseEvent<HTMLButtonElement> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: renommer l'événement en ButtonEvent ou autre, WithIdButtonEvent , ...

id: string;
}

const Button = compose(
identity<ButtonCoreProps>(),
withClickId({ event: ['onClick'] })
)(ButtonCore);
export type ButtonProps = Omit<
ComponentPropsWithoutRef<typeof ButtonCore>,
'onClick'
> & {
onClick: React.EventHandler<MyEvent>;
};

const Button = (props: ButtonProps) => {
const customOnClick = (
e: React.MouseEvent<HTMLButtonElement, MouseEvent>,
onClick: React.EventHandler<MyEvent>
) => {
return onClick({ ...e, id: props.id });
};

return (
<ButtonCore {...props} onClick={(e) => customOnClick(e, props.onClick)} />
);
};

Button.displayName = 'Button';

export default Button;
export { ButtonCore };