From 720f5e6b77fd765ff71d98884d07824a46d4397e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 19 Sep 2025 17:42:32 +0800 Subject: [PATCH 1/4] feat: add postOptions --- src/UniqueProvider/index.tsx | 41 +++++++++++++++++++++++------------- tests/unique.test.tsx | 24 +++++++++++++++++++++ 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/UniqueProvider/index.tsx b/src/UniqueProvider/index.tsx index 78643a8f..830f54ee 100644 --- a/src/UniqueProvider/index.tsx +++ b/src/UniqueProvider/index.tsx @@ -18,11 +18,22 @@ import { getAlignPopupClassName } from '../util'; export interface UniqueProviderProps { children: React.ReactNode; + /** Additional handle options data to do the customize info */ + postOptions?: (options: UniqueShowOptions) => UniqueShowOptions; } -const UniqueProvider = ({ children }: UniqueProviderProps) => { +const UniqueProvider = ({ children, postOptions }: UniqueProviderProps) => { const [trigger, open, options, onTargetVisibleChanged] = useTargetState(); + // ========================== Options =========================== + const mergedOptions = React.useMemo(() => { + if (!options || !postOptions) { + return options; + } + + return postOptions(options); + }, [options, postOptions]); + // =========================== Popup ============================ const [popupEle, setPopupEle] = React.useState(null); const [popupSize, setPopupSize] = React.useState<{ @@ -155,7 +166,7 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => { ); // =========================== Render =========================== - const prefixCls = options?.prefixCls; + const prefixCls = mergedOptions?.prefixCls; return ( @@ -166,14 +177,14 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => { ref={setPopupRef} portal={Portal} prefixCls={prefixCls} - popup={options.popup} + popup={mergedOptions.popup} className={classNames( - options.popupClassName, + mergedOptions.popupClassName, alignedClassName, `${prefixCls}-unique-controlled`, )} - style={options.popupStyle} - target={options.target} + style={mergedOptions.popupStyle} + target={mergedOptions.target} open={open} keepDom={true} fresh={true} @@ -197,12 +208,12 @@ const UniqueProvider = ({ children }: UniqueProviderProps) => { y: arrowY, }} align={alignInfo} - zIndex={options.zIndex} - mask={options.mask} - arrow={options.arrow} - motion={options.popupMotion} - maskMotion={options.maskMotion} - // getPopupContainer={options.getPopupContainer} + zIndex={mergedOptions.zIndex} + mask={mergedOptions.mask} + arrow={mergedOptions.arrow} + motion={mergedOptions.popupMotion} + maskMotion={mergedOptions.maskMotion} + getPopupContainer={mergedOptions.getPopupContainer} > { y: arrowY, }} popupSize={popupSize} - motion={options.popupMotion} + motion={mergedOptions.popupMotion} uniqueBgClassName={classNames( - options.uniqueBgClassName, + mergedOptions.uniqueBgClassName, alignedClassName, )} - uniqueBgStyle={options.uniqueBgStyle} + uniqueBgStyle={mergedOptions.uniqueBgStyle} /> diff --git a/tests/unique.test.tsx b/tests/unique.test.tsx index 86bd09e3..af839260 100644 --- a/tests/unique.test.tsx +++ b/tests/unique.test.tsx @@ -3,6 +3,7 @@ import React from 'react'; import Trigger, { UniqueProvider } from '../src'; import { awaitFakeTimer } from './util'; import type { TriggerProps } from '../src'; +import classNames from 'classnames'; // Mock UniqueBody to check if open props changed global.openChangeLog = []; @@ -254,4 +255,27 @@ describe('Trigger.Unique', () => { expect(computedStyle.getPropertyValue('--arrow-x')).not.toBe(''); expect(computedStyle.getPropertyValue('--arrow-y')).not.toBe(''); }); + + it('should apply postOptions to customize options', async () => { + const postOptions = (options: any) => ({ + ...options, + popupClassName: classNames(options.popupClassName, 'custom-post-options-class'), + }); + + render( + + tooltip} + unique + popupVisible + > +
click me
+
+
, + ); + + // Check that the custom class from postOptions is applied + expect(document.querySelector('.rc-trigger-popup')).toHaveClass('custom-post-options-class'); + }); }); From 0b8304fb735fcc84e29e4fefe65df887bdf0f2d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 19 Sep 2025 17:44:29 +0800 Subject: [PATCH 2/4] chore: rename --- src/UniqueProvider/index.tsx | 10 +++++----- tests/unique.test.tsx | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/UniqueProvider/index.tsx b/src/UniqueProvider/index.tsx index 830f54ee..a29fee3c 100644 --- a/src/UniqueProvider/index.tsx +++ b/src/UniqueProvider/index.tsx @@ -19,20 +19,20 @@ import { getAlignPopupClassName } from '../util'; export interface UniqueProviderProps { children: React.ReactNode; /** Additional handle options data to do the customize info */ - postOptions?: (options: UniqueShowOptions) => UniqueShowOptions; + postTriggerProps?: (options: UniqueShowOptions) => UniqueShowOptions; } -const UniqueProvider = ({ children, postOptions }: UniqueProviderProps) => { +const UniqueProvider = ({ children, postTriggerProps }: UniqueProviderProps) => { const [trigger, open, options, onTargetVisibleChanged] = useTargetState(); // ========================== Options =========================== const mergedOptions = React.useMemo(() => { - if (!options || !postOptions) { + if (!options || !postTriggerProps) { return options; } - return postOptions(options); - }, [options, postOptions]); + return postTriggerProps(options); + }, [options, postTriggerProps]); // =========================== Popup ============================ const [popupEle, setPopupEle] = React.useState(null); diff --git a/tests/unique.test.tsx b/tests/unique.test.tsx index af839260..a443deef 100644 --- a/tests/unique.test.tsx +++ b/tests/unique.test.tsx @@ -256,14 +256,14 @@ describe('Trigger.Unique', () => { expect(computedStyle.getPropertyValue('--arrow-y')).not.toBe(''); }); - it('should apply postOptions to customize options', async () => { - const postOptions = (options: any) => ({ + it('should apply postTriggerProps to customize options', async () => { + const postTriggerProps = (options: any) => ({ ...options, popupClassName: classNames(options.popupClassName, 'custom-post-options-class'), }); render( - + tooltip} @@ -275,7 +275,7 @@ describe('Trigger.Unique', () => { , ); - // Check that the custom class from postOptions is applied + // Check that the custom class from postTriggerProps is applied expect(document.querySelector('.rc-trigger-popup')).toHaveClass('custom-post-options-class'); }); }); From 5b5bd77cac4691270693ef386233dd5b22fefcc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 19 Sep 2025 17:47:56 +0800 Subject: [PATCH 3/4] chore: fix ts --- src/index.tsx | 4 +++- tests/unique.test.tsx | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index ece9fefd..268990d6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,7 +32,9 @@ export type { BuildInPlacements, }; -export { default as UniqueProvider } from './UniqueProvider'; +import UniqueProvider, { type UniqueProviderProps } from './UniqueProvider'; + +export { UniqueProvider, UniqueProviderProps }; export interface TriggerRef { nativeElement: HTMLElement; diff --git a/tests/unique.test.tsx b/tests/unique.test.tsx index a443deef..a5ff3c9c 100644 --- a/tests/unique.test.tsx +++ b/tests/unique.test.tsx @@ -1,6 +1,6 @@ import { cleanup, fireEvent, render } from '@testing-library/react'; import React from 'react'; -import Trigger, { UniqueProvider } from '../src'; +import Trigger, { UniqueProvider, type UniqueProviderProps } from '../src'; import { awaitFakeTimer } from './util'; import type { TriggerProps } from '../src'; import classNames from 'classnames'; @@ -257,9 +257,14 @@ describe('Trigger.Unique', () => { }); it('should apply postTriggerProps to customize options', async () => { - const postTriggerProps = (options: any) => ({ + const postTriggerProps: UniqueProviderProps['postTriggerProps'] = ( + options, + ) => ({ ...options, - popupClassName: classNames(options.popupClassName, 'custom-post-options-class'), + popupClassName: classNames( + options.popupClassName, + 'custom-post-options-class', + ), }); render( @@ -276,6 +281,8 @@ describe('Trigger.Unique', () => { ); // Check that the custom class from postTriggerProps is applied - expect(document.querySelector('.rc-trigger-popup')).toHaveClass('custom-post-options-class'); + expect(document.querySelector('.rc-trigger-popup')).toHaveClass( + 'custom-post-options-class', + ); }); }); From d80ad3f9e7d256418a529ec79abdf7485e55e894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 19 Sep 2025 17:51:27 +0800 Subject: [PATCH 4/4] chore: fix ts --- src/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/index.tsx b/src/index.tsx index 268990d6..905694f4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -34,7 +34,8 @@ export type { import UniqueProvider, { type UniqueProviderProps } from './UniqueProvider'; -export { UniqueProvider, UniqueProviderProps }; +export { UniqueProvider }; +export type { UniqueProviderProps }; export interface TriggerRef { nativeElement: HTMLElement;