Skip to content

Commit

Permalink
Add Fieldset icon templating support Related - #4226
Browse files Browse the repository at this point in the history
  • Loading branch information
ulasturann committed Apr 12, 2023
1 parent 26d6817 commit 7a4dba8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
14 changes: 8 additions & 6 deletions components/lib/fieldset/Fieldset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import * as React from 'react';
import { CSSTransition } from '../csstransition/CSSTransition';
import { useMountEffect } from '../hooks/Hooks';
import { Ripple } from '../ripple/Ripple';
import { classNames, UniqueComponentId } from '../utils/Utils';
import { classNames, IconUtils, UniqueComponentId } from '../utils/Utils';
import { FieldsetBase } from './FieldsetBase';
import { PlusIcon } from '../icon/plus';
import { MinusIcon } from '../icon/minus';

export const Fieldset = React.forwardRef((inProps, ref) => {
const props = FieldsetBase.getProps(inProps);
Expand Down Expand Up @@ -65,12 +67,12 @@ export const Fieldset = React.forwardRef((inProps, ref) => {

const createToggleIcon = () => {
if (props.toggleable) {
const className = classNames('p-fieldset-toggler pi', {
'pi-plus': collapsed,
'pi-minus': !collapsed
});
const iconClassName = "p-fieldset-toggler";

return <span className={className}></span>;
const icon = collapsed ? props.expandIcon || <PlusIcon className={iconClassName} /> : props.collapseIcon || <MinusIcon className={iconClassName} />;
const toggleIcon = IconUtils.getJSXIcon(icon, { className: iconClassName }, { props });

return toggleIcon;
}

return null;
Expand Down
2 changes: 2 additions & 0 deletions components/lib/fieldset/FieldsetBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const FieldsetBase = {
style: null,
toggleable: null,
collapsed: null,
collapseIcon: null,
transitionOptions: null,
expandIcon: null,
onExpand: null,
onCollapse: null,
onToggle: null,
Expand Down
9 changes: 9 additions & 0 deletions components/lib/fieldset/fieldset.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
import * as React from 'react';
import { CSSTransitionProps } from '../csstransition';
import { IconType } from '../utils/utils';

/**
* Custom toggle event.
Expand Down Expand Up @@ -45,11 +46,19 @@ export interface FieldsetProps extends Omit<React.DetailedHTMLProps<React.HTMLAt
* @defaultValue false
*/
collapsed?: boolean | undefined;
/**
* Icon of an expanded tab.
*/
collapseIcon?: IconType<FieldsetProps> | undefined;
/**
* The properties of CSSTransition can be customized, except for "nodeRef" and "in" properties.
* @type {CSSTransitionProps}
*/
transitionOptions?: CSSTransitionProps | undefined;
/**
* Icon of an collapsed tab.
*/
expandIcon?: IconType<FieldsetProps> | undefined;
/**
* Callback to invoke when a tab gets expanded.
* @param {React.MouseEvent<HTMLElement>} event - Browser event.
Expand Down

0 comments on commit 7a4dba8

Please sign in to comment.