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

Added custom classNameMergeFunction configuration to ptOptions #5215

Closed
wants to merge 7 commits into from
Closed
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
6 changes: 6 additions & 0 deletions components/doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -39160,6 +39160,12 @@
"optional": true,
"readonly": false,
"type": "boolean"
},
{
"name": "classNameMergeFunction",
"optional": true,
"readonly": false,
"type": "Function"
}
],
"callbacks": []
Expand Down
4 changes: 4 additions & 0 deletions components/doc/passthrough/usepassthroughdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ const CustomTailwind = usePassThrough(
The <i>mergeSections</i> defines whether the sections from the main configuration gets added and the <i>mergeProps</i> controls whether to override or merge the defined props. Defaults are <i>true</i> for <i>mergeSections</i> and
<i>false</i> for <i>mergeProps</i>.
</p>
<p>
Some CSS libraries, such as <i>Tailwind</i>, require that class names be merged in a non-conflicting manner. In order to support them a <i>classNameMergeFunction</i> may be passed as part of the <i>ptOptions</i> object to manually
define how class names will be merged.
</p>
</DocSectionText>
<DocSectionCode code={code2} hideToggleCode import hideCodeSandbox hideStackBlitz />
<DocSectionCode code={code3} hideToggleCode import hideCodeSandbox hideStackBlitz />
Expand Down
25 changes: 24 additions & 1 deletion components/doc/tailwind/unstyledmode/setupdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ return(
const code3 = {
basic: `
import { PrimeReactProvider } from "primereact/api";
import { twMerge } from 'tailwind-merge';

...
return(
<PrimeReactProvider value={{ unstyled: true, pt: {}, ptOptions: { mergeSections: true, mergeProps: true, classNameMergeFunction: twMerge } }}>
<App />
</PrimeReactProvider>
)

`
};

const code4 = {
basic: `
import { PrimeReactProvider } from "primereact/api";

export default function MyApp({ Component, pageProps }) {

Expand Down Expand Up @@ -124,12 +139,20 @@ export default function MyApp({ Component, pageProps }) {
<DocSectionCode code={code2} hideToggleCode import hideCodeSandbox hideStackBlitz />
<p className="flex align-items-start gap-2">
<Badge value="3"></Badge>
<span>
<b>Optional:</b> specify the classNameMergeFunction as <i>twMerge</i> to resolve className conflicts via <a href="https://www.npmjs.com/package/tailwind-merge">tailwind-merge</a>. This will prevent classNames specified in the
global pass through from overriding those specified via pass through in your application.
</span>
</p>
<DocSectionCode code={code3} hideToggleCode import hideCodeSandbox hideStackBlitz />
<p className="flex align-items-start gap-2">
<Badge value="4"></Badge>
<span>
At the final step, component styles are provided via a pass through configuration that utilizes Tailwind CSS. The default preset of each component is available at the Tailwind part under theming section of each component so
you'll able to copy paste instead of starting from scratch. Example below styles, inputtext and panel components;
</span>
</p>
<DocSectionCode code={code3} hideToggleCode import hideCodeSandbox hideStackBlitz />
<DocSectionCode code={code4} hideToggleCode import hideCodeSandbox hideStackBlitz />
<p>Voilà 💙, you now have 90+ awesome React UI components styled with Tailwind that will work in harmony with the rest of your application. Time to customize it to bring in your own style with Tailwind.</p>
</DocSectionText>
</>
Expand Down
3 changes: 2 additions & 1 deletion components/lib/accordion/Accordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { ariaLabel, PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { CSSTransition } from '../csstransition/CSSTransition';
import { useMountEffect } from '../hooks/Hooks';
import { classNames, IconUtils, useMergeProps, ObjectUtils, UniqueComponentId } from '../utils/Utils';
import { ChevronDownIcon } from '../icons/chevrondown';
import { ChevronRightIcon } from '../icons/chevronright';
import { classNames, IconUtils, mergeProps, ObjectUtils, UniqueComponentId } from '../utils/Utils';
import { AccordionBase, AccordionTabBase } from './AccordionBase';

export const AccordionTab = () => {};
Expand All @@ -25,6 +25,7 @@ export const Accordion = React.forwardRef((inProps, ref) => {
activeIndex: activeIndexState
}
};
const mergeProps = useMergeProps();

const { ptm, ptmo, cx, sx, isUnstyled } = AccordionBase.setMetaData({
...metaData
Expand Down
3 changes: 2 additions & 1 deletion components/lib/autocomplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import { TimesCircleIcon } from '../icons/timescircle';
import { InputText } from '../inputtext/InputText';
import { OverlayService } from '../overlayservice/OverlayService';
import { Tooltip } from '../tooltip/Tooltip';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, classNames, useMergeProps } from '../utils/Utils';
import { AutoCompleteBase } from './AutoCompleteBase';
import { AutoCompletePanel } from './AutoCompletePanel';

export const AutoComplete = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = AutoCompleteBase.getProps(inProps, context);
const [idState, setIdState] = React.useState(props.id);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/autocomplete/AutoCompletePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { localeOption, PrimeReactContext } from '../api/Api';
import { CSSTransition } from '../csstransition/CSSTransition';
import { Portal } from '../portal/Portal';
import { Ripple } from '../ripple/Ripple';
import { classNames, mergeProps, ObjectUtils } from '../utils/Utils';
import { classNames, useMergeProps, ObjectUtils } from '../utils/Utils';
import { VirtualScroller } from '../virtualscroller/VirtualScroller';

export const AutoCompletePanel = React.memo(
React.forwardRef((props, ref) => {
const mergeProps = useMergeProps();
const { ptm, cx } = props;
const context = React.useContext(PrimeReactContext);

Expand Down
3 changes: 2 additions & 1 deletion components/lib/avatar/Avatar.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { DomHandler, IconUtils, ObjectUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, classNames, useMergeProps } from '../utils/Utils';
import { AvatarBase } from './AvatarBase';

export const Avatar = React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = AvatarBase.getProps(inProps, context);

Expand Down
3 changes: 2 additions & 1 deletion components/lib/avatargroup/AvatarGroup.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { classNames, mergeProps } from '../utils/Utils';
import { classNames, useMergeProps } from '../utils/Utils';
import { AvatarGroupBase } from './AvatarGroupBase';

export const AvatarGroup = React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = AvatarGroupBase.getProps(inProps, context);

Expand Down
3 changes: 2 additions & 1 deletion components/lib/badge/Badge.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { classNames, mergeProps } from '../utils/Utils';
import { classNames, useMergeProps } from '../utils/Utils';
import { BadgeBase } from './BadgeBase';

export const Badge = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = BadgeBase.getProps(inProps, context);

Expand Down
3 changes: 2 additions & 1 deletion components/lib/blockui/BlockUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import PrimeReact, { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMountEffect, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { Portal } from '../portal/Portal';
import { DomHandler, ObjectUtils, ZIndexUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, ObjectUtils, ZIndexUtils, classNames, useMergeProps } from '../utils/Utils';
import { BlockUIBase } from './BlockUIBase';

export const BlockUI = React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = BlockUIBase.getProps(inProps, context);

Expand Down
3 changes: 2 additions & 1 deletion components/lib/breadcrumb/BreadCrumb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { useMountEffect } from '../hooks/Hooks';
import { ChevronRightIcon } from '../icons/chevronright';
import { IconUtils, mergeProps, ObjectUtils, UniqueComponentId } from '../utils/Utils';
import { IconUtils, useMergeProps, ObjectUtils, UniqueComponentId } from '../utils/Utils';
import { BreadCrumbBase } from './BreadCrumbBase';

export const BreadCrumb = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = BreadCrumbBase.getProps(inProps, context);
const [idState, setIdState] = React.useState(props.id);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { useHandleStyle } from '../componentbase/ComponentBase';
import { SpinnerIcon } from '../icons/spinner';
import { Ripple } from '../ripple/Ripple';
import { Tooltip } from '../tooltip/Tooltip';
import { IconUtils, ObjectUtils, classNames, mergeProps } from '../utils/Utils';
import { IconUtils, ObjectUtils, classNames, useMergeProps } from '../utils/Utils';
import { ButtonBase } from './ButtonBase';

export const Button = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = ButtonBase.getProps(inProps, context);
const disabled = props.disabled || props.loading;
Expand Down
3 changes: 2 additions & 1 deletion components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { ChevronUpIcon } from '../icons/chevronup';
import { InputText } from '../inputtext/InputText';
import { OverlayService } from '../overlayservice/OverlayService';
import { Ripple } from '../ripple/Ripple';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, classNames, mask, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, classNames, mask, useMergeProps } from '../utils/Utils';
import { CalendarBase } from './CalendarBase';
import { CalendarPanel } from './CalendarPanel';

export const Calendar = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = CalendarBase.getProps(inProps, context);
const [focusedState, setFocusedState] = React.useState(false);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/calendar/CalendarPanel.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { CSSTransition } from '../csstransition/CSSTransition';
import { Portal } from '../portal/Portal';
import { mergeProps } from '../utils/Utils';
import { useMergeProps } from '../utils/Utils';

export const CalendarPanel = React.forwardRef((props, ref) => {
const cx = props.cx;
const mergeProps = useMergeProps();

const createElement = () => {
const panelProps = mergeProps(
Expand Down
3 changes: 2 additions & 1 deletion components/lib/card/Card.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as React from 'react';
import { ObjectUtils, mergeProps } from '../utils/Utils';
import { ObjectUtils, useMergeProps } from '../utils/Utils';
import { CardBase } from './CardBase';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';

export const Card = React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = CardBase.getProps(inProps, context);

Expand Down
4 changes: 3 additions & 1 deletion components/lib/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { ChevronLeftIcon } from '../icons/chevronleft';
import { ChevronRightIcon } from '../icons/chevronright';
import { ChevronUpIcon } from '../icons/chevronup';
import { Ripple } from '../ripple/Ripple';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, classNames, useMergeProps } from '../utils/Utils';
import { CarouselBase } from './CarouselBase';

const CarouselItem = React.memo((props) => {
const mergeProps = useMergeProps();
const { ptm, cx } = props;
const key = props.className && props.className === 'p-carousel-item-cloned' ? 'itemCloned' : 'item';
const content = props.template(props.item);
Expand All @@ -31,6 +32,7 @@ export const Carousel = React.memo(
React.forwardRef((inProps, ref) => {
const context = React.useContext(PrimeReactContext);
const props = CarouselBase.getProps(inProps, context);
const mergeProps = useMergeProps();

const [numVisibleState, setNumVisibleState] = React.useState(props.numVisible);
const [numScrollState, setNumScrollState] = React.useState(props.numScroll);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/cascadeselect/CascadeSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { ESC_KEY_HANDLING_PRIORITIES, useDisplayOrder, useGlobalOnEscapeKey, use
import { ChevronDownIcon } from '../icons/chevrondown';
import { OverlayService } from '../overlayservice/OverlayService';
import { Portal } from '../portal/Portal';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, UniqueComponentId, ZIndexUtils, useMergeProps } from '../utils/Utils';
import { CascadeSelectBase } from './CascadeSelectBase';
import { CascadeSelectSub } from './CascadeSelectSub';

export const CascadeSelect = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = CascadeSelectBase.getProps(inProps, context);
const [focusedState, setFocusedState] = React.useState(false);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/cascadeselect/CascadeSelectSub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { PrimeReactContext } from '../api/Api';
import { useMountEffect, useUpdateEffect } from '../hooks/Hooks';
import { AngleRightIcon } from '../icons/angleright';
import { Ripple } from '../ripple/Ripple';
import { DomHandler, IconUtils, ObjectUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, classNames, useMergeProps } from '../utils/Utils';
export const CascadeSelectSub = React.memo((props) => {
const mergeProps = useMergeProps();
const [activeOptionState, setActiveOptionState] = React.useState(null);
const elementRef = React.useRef(null);
const context = React.useContext(PrimeReactContext);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/chart/Chart.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useUnmountEffect } from '../hooks/Hooks';
import { mergeProps } from '../utils/Utils';
import { useMergeProps } from '../utils/Utils';
import { ChartBase } from './ChartBase';
import { useHandleStyle } from '../componentbase/ComponentBase';

Expand All @@ -16,6 +16,7 @@ const ChartJS = (function () {

const PrimeReactChart = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = ChartBase.getProps(inProps, context);

Expand Down
3 changes: 2 additions & 1 deletion components/lib/checkbox/Checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { PrimeReactContext } from '../api/Api';
import { useMountEffect, useUpdateEffect } from '../hooks/Hooks';
import { CheckIcon } from '../icons/check';
import { Tooltip } from '../tooltip/Tooltip';
import { DomHandler, IconUtils, ObjectUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, classNames, useMergeProps } from '../utils/Utils';
import { CheckboxBase } from './CheckboxBase';
import { useHandleStyle } from '../componentbase/ComponentBase';

export const Checkbox = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = CheckboxBase.getProps(inProps, context);
const [focusedState, setFocusedState] = React.useState(false);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/chip/Chip.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { TimesCircleIcon } from '../icons/timescircle';
import { classNames, IconUtils, mergeProps, ObjectUtils } from '../utils/Utils';
import { classNames, IconUtils, useMergeProps, ObjectUtils } from '../utils/Utils';
import { ChipBase } from './ChipBase';

export const Chip = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = ChipBase.getProps(inProps, context);
const elementRef = React.useRef(null);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/chips/Chips.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import { useMountEffect } from '../hooks/Hooks';
import { TimesCircleIcon } from '../icons/timescircle';
import { KeyFilter } from '../keyfilter/KeyFilter';
import { Tooltip } from '../tooltip/Tooltip';
import { DomHandler, IconUtils, ObjectUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ObjectUtils, classNames, useMergeProps } from '../utils/Utils';
import { ChipsBase } from './ChipsBase';

export const Chips = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = ChipsBase.getProps(inProps, context);
const [focusedState, setFocusedState] = React.useState(false);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/colorpicker/ColorPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { useHandleStyle } from '../componentbase/ComponentBase';
import { useEventListener, useMountEffect, useOverlayListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { OverlayService } from '../overlayservice/OverlayService';
import { Tooltip } from '../tooltip/Tooltip';
import { DomHandler, ObjectUtils, ZIndexUtils, mergeProps } from '../utils/Utils';
import { DomHandler, ObjectUtils, ZIndexUtils, useMergeProps } from '../utils/Utils';
import { ColorPickerBase } from './ColorPickerBase';
import { ColorPickerPanel } from './ColorPickerPanel';

export const ColorPicker = React.memo(
React.forwardRef((inProps, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const props = ColorPickerBase.getProps(inProps, context);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
Expand Down
3 changes: 2 additions & 1 deletion components/lib/colorpicker/ColorPickerPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import { CSSTransition } from '../csstransition/CSSTransition';
import { Portal } from '../portal/Portal';
import { mergeProps } from '../utils/Utils';
import { useMergeProps } from '../utils/Utils';

export const ColorPickerPanel = React.forwardRef((props, ref) => {
const mergeProps = useMergeProps();
const context = React.useContext(PrimeReactContext);
const { ptm, cx } = props;

Expand Down
Loading
Loading