From 56d9ed88f051187b16d8423158e2bc95b21f9217 Mon Sep 17 00:00:00 2001 From: jbpenrath Date: Tue, 7 Jan 2025 23:28:47 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5(react)=20upgrade=20to=20React=2019?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://react.dev/blog/2024/04/25/react-19-upgrade-guide https://react.dev/blog/2024/12/05/react-19 --- .changeset/gorgeous-clocks-wash.md | 5 + .../react/src/components/Button/index.tsx | 130 ++--- .../src/components/Forms/Checkbox/index.tsx | 121 ++-- .../components/Forms/DatePicker/Calendar.tsx | 536 +++++++++--------- .../Forms/DatePicker/DatePickerAux.tsx | 245 ++++---- .../Forms/FileUploader/DropZone.tsx | 268 +++++---- .../Forms/FileUploader/FileUploaderMono.tsx | 18 +- .../Forms/FileUploader/FileUploaderMulti.tsx | 19 +- .../components/Forms/FileUploader/index.tsx | 33 +- .../components/Forms/Input/InputPassword.tsx | 10 +- .../src/components/Forms/Input/index.tsx | 217 ++++--- .../src/components/Forms/Radio/index.tsx | 57 +- .../src/components/Forms/Select/index.tsx | 13 +- .../Forms/Select/mono-searchable.tsx | 259 +++++---- .../components/Forms/Select/mono-simple.tsx | 73 ++- .../src/components/Forms/Select/mono.tsx | 114 ++-- .../components/Forms/Select/multi-menu.tsx | 2 +- .../Forms/Select/multi-searchable.tsx | 303 +++++----- .../components/Forms/Select/multi-simple.tsx | 240 ++++---- .../src/components/Forms/Select/multi.tsx | 108 ++-- .../components/Forms/Select/select-menu.tsx | 2 +- .../src/components/Forms/Switch/index.tsx | 82 +-- .../src/components/Forms/TextArea/index.tsx | 165 +++--- .../react/src/components/Popover/index.tsx | 4 +- packages/react/src/components/Toast/index.tsx | 4 +- .../react/src/components/Tooltip/index.tsx | 13 +- .../react/src/hooks/useHandleClickOutside.ts | 2 +- 27 files changed, 1497 insertions(+), 1546 deletions(-) create mode 100644 .changeset/gorgeous-clocks-wash.md diff --git a/.changeset/gorgeous-clocks-wash.md b/.changeset/gorgeous-clocks-wash.md new file mode 100644 index 0000000..81b21db --- /dev/null +++ b/.changeset/gorgeous-clocks-wash.md @@ -0,0 +1,5 @@ +--- +"@openfun/cunningham-react": major +--- + +Upgrade to React 19 diff --git a/packages/react/src/components/Button/index.tsx b/packages/react/src/components/Button/index.tsx index a513e98..0ff2802 100644 --- a/packages/react/src/components/Button/index.tsx +++ b/packages/react/src/components/Button/index.tsx @@ -2,80 +2,76 @@ import React, { AnchorHTMLAttributes, ButtonHTMLAttributes, createElement, - forwardRef, ReactNode, + RefAttributes, } from "react"; type DomProps = ButtonHTMLAttributes & AnchorHTMLAttributes; -export type ButtonProps = Omit & { - size?: "medium" | "small" | "nano"; - color?: - | "primary" - | "primary-text" - | "secondary" - | "tertiary" - | "tertiary-text" - | "danger"; - icon?: ReactNode; - iconPosition?: "left" | "right"; - active?: boolean; - fullWidth?: boolean; -}; - export type ButtonElement = HTMLButtonElement & HTMLAnchorElement; +export type ButtonProps = Omit & + RefAttributes & { + size?: "medium" | "small" | "nano"; + color?: + | "primary" + | "primary-text" + | "secondary" + | "tertiary" + | "tertiary-text" + | "danger"; + icon?: ReactNode; + iconPosition?: "left" | "right"; + active?: boolean; + fullWidth?: boolean; + }; -export const Button = forwardRef( - ( +export const Button = ({ + children, + color = "primary", + size = "medium", + iconPosition = "left", + icon, + active, + className, + fullWidth, + ref, + ...props +}: ButtonProps) => { + const classes = [ + "c__button", + "c__button--" + color, + "c__button--" + size, + className, + ]; + if (icon && children) { + classes.push("c__button--with-icon--" + iconPosition); + } + if (icon && !children) { + classes.push("c__button--icon-only"); + } + if (active) { + classes.push("c__button--active"); + } + if (fullWidth) { + classes.push("c__button--full-width"); + } + if (["primary-text", "tertiary-text"].includes(color)) { + classes.push("c__button--text"); + } + const iconElement = {icon}; + const tagName = props.href ? "a" : "button"; + return createElement( + tagName, { - children, - color = "primary", - size = "medium", - iconPosition = "left", - icon, - active, - className, - fullWidth, - ...props + className: classes.join(" "), + ...props, + ref, }, - ref, - ) => { - const classes = [ - "c__button", - "c__button--" + color, - "c__button--" + size, - className, - ]; - if (icon && children) { - classes.push("c__button--with-icon--" + iconPosition); - } - if (icon && !children) { - classes.push("c__button--icon-only"); - } - if (active) { - classes.push("c__button--active"); - } - if (fullWidth) { - classes.push("c__button--full-width"); - } - if (["primary-text", "tertiary-text"].includes(color)) { - classes.push("c__button--text"); - } - const iconElement = {icon}; - const tagName = props.href ? "a" : "button"; - return createElement( - tagName, - { - className: classes.join(" "), - ...props, - ref, - }, - <> - {!!icon && iconPosition === "left" && iconElement} - {children} - {!!icon && iconPosition === "right" && iconElement} - , - ); - }, -); + <> + {!!icon && iconPosition === "left" && iconElement} + {children} + {!!icon && iconPosition === "right" && iconElement} + , + ); +}; diff --git a/packages/react/src/components/Forms/Checkbox/index.tsx b/packages/react/src/components/Forms/Checkbox/index.tsx index 98a914d..85ae329 100644 --- a/packages/react/src/components/Forms/Checkbox/index.tsx +++ b/packages/react/src/components/Forms/Checkbox/index.tsx @@ -1,11 +1,11 @@ import React, { InputHTMLAttributes, PropsWithChildren, - forwardRef, useEffect, useRef, useState, ReactNode, + RefAttributes, } from "react"; import classNames from "classnames"; import { Field, FieldProps } from ":/components/Forms/Field"; @@ -16,72 +16,75 @@ export type CheckboxOnlyProps = { }; export type CheckboxProps = InputHTMLAttributes & + RefAttributes & FieldProps & CheckboxOnlyProps; -export const Checkbox = forwardRef( - ( - { indeterminate, className = "", checked, label, ...props }: CheckboxProps, - ref, - ) => { - const inputRef = useRef(); - const [value, setValue] = useState(!!checked); +export const Checkbox = ({ + indeterminate, + className = "", + checked, + label, + ref, + ...props +}: CheckboxProps) => { + const inputRef = useRef(null); + const [value, setValue] = useState(!!checked); - useEffect(() => { - setValue(!!checked); - }, [checked]); + useEffect(() => { + setValue(!!checked); + }, [checked]); - useEffect(() => { - if (inputRef.current) { - inputRef.current.indeterminate = !!indeterminate; - } - }, [indeterminate]); + useEffect(() => { + if (inputRef.current) { + inputRef.current.indeterminate = !!indeterminate; + } + }, [indeterminate]); - const { - compact, - fullWidth, - rightText, - state, - text, - textItems, - ...inputProps - } = props; + const { + compact, + fullWidth, + rightText, + state, + text, + textItems, + ...inputProps + } = props; - return ( -