Skip to content

Commit

Permalink
Refactor #4602 - Add parentMetadata to related components
Browse files Browse the repository at this point in the history
  • Loading branch information
habubey committed Sep 12, 2023
1 parent fcbeb00 commit adef94d
Show file tree
Hide file tree
Showing 48 changed files with 267 additions and 101 deletions.
21 changes: 18 additions & 3 deletions components/lib/autocomplete/AutoComplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ export const AutoComplete = React.memo(
const [searchingState, setSearchingState] = React.useState(false);
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const { ptm, cx, sx, isUnstyled } = AutoCompleteBase.setMetaData({

const metaData = {
props,
state: {
id: idState,
searching: searchingState,
focused: focusedState,
overlayVisible: overlayVisibleState
}
});
};

const { ptm, cx, sx, isUnstyled } = AutoCompleteBase.setMetaData(metaData);

useHandleStyle(AutoCompleteBase.css.styles, isUnstyled, { name: 'autocomplete' });
const elementRef = React.useRef(null);
Expand Down Expand Up @@ -551,6 +554,7 @@ export const AutoComplete = React.memo(
onDoubleClick={props.onDblClick}
pt={ptm('input')}
{...ariaProps}
__parentMetadata={{ parent: metaData }}
/>
);
};
Expand Down Expand Up @@ -667,7 +671,18 @@ export const AutoComplete = React.memo(
if (props.dropdown) {
const ariaLabel = props.dropdownAriaLabel || props.placeholder || localeOption('choose');

return <Button type="button" icon={props.dropdownIcon || <ChevronDownIcon />} className={cx('dropdownButton')} disabled={props.disabled} onClick={onDropdownClick} aria-label={ariaLabel} pt={ptm('dropdownButton')} />;
return (
<Button
type="button"
icon={props.dropdownIcon || <ChevronDownIcon />}
className={cx('dropdownButton')}
disabled={props.disabled}
onClick={onDropdownClick}
aria-label={ariaLabel}
pt={ptm('dropdownButton')}
__parentMetadata={{ parent: metaData }}
/>
);
}

return null;
Expand Down
3 changes: 2 additions & 1 deletion components/lib/badge/Badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const Badge = React.memo(
const props = BadgeBase.getProps(inProps, context);

const { ptm, cx, isUnstyled } = BadgeBase.setMetaData({
props
props,
...props.__parentMetadata
});

useHandleStyle(BadgeBase.css.styles, isUnstyled, { name: 'badge' });
Expand Down
1 change: 1 addition & 0 deletions components/lib/badge/BadgeBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const styles = `
export const BadgeBase = ComponentBase.extend({
defaultProps: {
__TYPE: 'Badge',
__parentMetadata: null,
value: null,
severity: null,
size: null,
Expand Down
11 changes: 7 additions & 4 deletions components/lib/button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export const Button = React.memo(
const props = ButtonBase.getProps(inProps, context);
const disabled = props.disabled || props.loading;

const { ptm, cx, isUnstyled } = ButtonBase.setMetaData({
const metaData = {
props,
...inProps.__parentMetadata,
...props.__parentMetadata,
context: {
disabled
}
});
};

const { ptm, cx, isUnstyled } = ButtonBase.setMetaData(metaData);

useHandleStyle(ButtonBase.css.styles, isUnstyled, { name: 'button', styled: true });

Expand Down Expand Up @@ -83,7 +85,8 @@ export const Button = React.memo(
{
className: classNames(props.badgeClassName),
value: props.badge,
unstyled: props.unstyled
unstyled: props.unstyled,
__parentMetadata: { parent: metaData }
},
ptm('badge')
);
Expand Down
8 changes: 5 additions & 3 deletions components/lib/calendar/Calendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ export const Calendar = React.memo(
const [focusedState, setFocusedState] = React.useState(false);
const [overlayVisibleState, setOverlayVisibleState] = React.useState(false);
const [viewDateState, setViewDateState] = React.useState(null);
const { ptm, cx, isUnstyled } = CalendarBase.setMetaData({
const metaData = {
props,
state: {
focused: focusedState,
overlayVisible: overlayVisibleState,
viewDate: viewDateState
}
});
};
const { ptm, cx, isUnstyled } = CalendarBase.setMetaData(metaData);

useHandleStyle(CalendarBase.css.styles, isUnstyled, { name: 'calendar' });
const elementRef = React.useRef(null);
Expand Down Expand Up @@ -3539,6 +3540,7 @@ export const Calendar = React.memo(
tooltip={props.tooltip}
tooltipOptions={props.tooltipOptions}
pt={ptm('input')}
__parentMetadata={{ parent: metaData }}
/>
);
}
Expand All @@ -3548,7 +3550,7 @@ export const Calendar = React.memo(

const createButton = () => {
if (props.showIcon) {
return <Button type="button" icon={props.icon || <CalendarIcon />} onClick={onButtonClick} tabIndex="-1" disabled={props.disabled} className={cx('dropdownButton')} pt={ptm('dropdownButton')} />;
return <Button type="button" icon={props.icon || <CalendarIcon />} onClick={onButtonClick} tabIndex="-1" disabled={props.disabled} className={cx('dropdownButton')} pt={ptm('dropdownButton')} __parentMetadata={{ parent: metaData }} />;
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion components/lib/componentbase/ComponentBase.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect } from 'react';
import PrimeReact from '../api/Api';
import { useStyle } from '../hooks/Hooks';
import { ObjectUtils } from '../utils/Utils';
import { Tailwind } from '../passthrough/tailwind';
import { mergeProps } from '../utils/MergeProps';
import { ObjectUtils } from '../utils/Utils';

const buttonStyles = `
.p-button {
Expand Down
20 changes: 15 additions & 5 deletions components/lib/confirmdialog/ConfirmDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ export const ConfirmDialog = React.memo(
const acceptLabel = getPropValue('acceptLabel') || localeOption('accept');
const rejectLabel = getPropValue('rejectLabel') || localeOption('reject');

const { ptm, cx } = ConfirmDialogBase.setMetaData({
const metaData = {
props,
state: {
visible: visibleState
}
});
};
const { ptm, cx } = ConfirmDialogBase.setMetaData(metaData);

const accept = () => {
if (!isCallbackExecuting.current) {
Expand Down Expand Up @@ -140,7 +141,10 @@ export const ConfirmDialog = React.memo(
className: classNames(getPropValue('rejectClassName'), cx('rejectButton', { getPropValue })),
onClick: reject,
pt: ptm('rejectButton'),
unstyled: props.unstyled
unstyled: props.unstyled,
__parentMetadata: {
parent: metaData
}
};

const acceptButtonProps = mergeProps(
Expand All @@ -149,7 +153,10 @@ export const ConfirmDialog = React.memo(
icon: getPropValue('acceptIcon'),
className: classNames(getPropValue('acceptClassName'), cx('acceptButton')),
onClick: accept,
unstyled: props.unstyled
unstyled: props.unstyled,
__parentMetadata: {
parent: metaData
}
},
ptm('acceptButton')
);
Expand Down Expand Up @@ -209,7 +216,10 @@ export const ConfirmDialog = React.memo(
breakpoints: getPropValue('breakpoints'),
pt: currentProps.pt,
unstyled: props.unstyled,
appendTo: getPropValue('appendTo')
appendTo: getPropValue('appendTo'),
__parentMetadata: {
parent: metaData
}
},
ConfirmDialogBase.getOtherProps(currentProps)
);
Expand Down
17 changes: 12 additions & 5 deletions components/lib/confirmpopup/ConfirmPopup.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from 'react';
import PrimeReact, { PrimeReactContext, localeOption } from '../api/Api';
import { Button } from '../button/Button';
import { useHandleStyle } from '../componentbase/ComponentBase';
import { CSSTransition } from '../csstransition/CSSTransition';
import { useOverlayListener, useUnmountEffect, useUpdateEffect } from '../hooks/Hooks';
import { OverlayService } from '../overlayservice/OverlayService';
import { Portal } from '../portal/Portal';
import { DomHandler, IconUtils, ObjectUtils, ZIndexUtils, classNames, mergeProps } from '../utils/Utils';
import { ConfirmPopupBase } from './ConfirmPopupBase';
import { useHandleStyle } from '../componentbase/ComponentBase';

export const confirmPopup = (props = {}) => {
props = { ...props, ...{ visible: props.visible === undefined ? true : props.visible } };
Expand All @@ -31,13 +31,14 @@ export const ConfirmPopup = React.memo(

const [visibleState, setVisibleState] = React.useState(props.visible);
const [reshowState, setReshowState] = React.useState(false);
const { ptm, cx, isUnstyled } = ConfirmPopupBase.setMetaData({
const metaData = {
props,
state: {
visible: visibleState,
reshow: reshowState
}
});
};
const { ptm, cx, isUnstyled } = ConfirmPopupBase.setMetaData(metaData);

useHandleStyle(ConfirmPopupBase.css.styles, isUnstyled, { name: 'confirmpopup' });

Expand Down Expand Up @@ -279,7 +280,10 @@ export const ConfirmPopup = React.memo(
className: cx('rejectButton', { getPropValue }),
onClick: reject,
pt: ptm('rejectButton'),
unstyled: props.unstyled
unstyled: props.unstyled,
__parentMetadata: {
parent: metaData
}
});

const acceptButtonProps = mergeProps({
Expand All @@ -289,7 +293,10 @@ export const ConfirmPopup = React.memo(
className: cx('acceptButton', { getPropValue }),
onClick: accept,
pt: ptm('acceptButton'),
unstyled: props.unstyled
unstyled: props.unstyled,
__parentMetadata: {
parent: metaData
}
});

const content = (
Expand Down
12 changes: 11 additions & 1 deletion components/lib/datatable/ColumnFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ export const ColumnFilter = React.memo((props) => {
maxLength={getColumnProp('filterMaxLength')}
aria-label={getColumnProp('filterPlaceholder')}
unstyled={props.unstyled}
__parentMetadata={{ parent: props.metaData }}
/>
);
};
Expand Down Expand Up @@ -669,7 +670,15 @@ export const ColumnFilter = React.memo((props) => {

return (
<div {...filterOperatorProps}>
<Dropdown options={options} value={value} onChange={onOperatorChange} className="p-column-filter-operator-dropdown" pt={getColumnPTOptions('filterOperatorDropdown')} unstyled={props.unstyled} />
<Dropdown
options={options}
value={value}
onChange={onOperatorChange}
className="p-column-filter-operator-dropdown"
pt={getColumnPTOptions('filterOperatorDropdown')}
unstyled={props.unstyled}
__parentMetadata={{ parent: props.metaData }}
/>
</div>
);
}
Expand Down Expand Up @@ -709,6 +718,7 @@ export const ColumnFilter = React.memo((props) => {
label={removeRuleLabel}
pt={getColumnPTOptions('filterRemoveButton')}
unstyled={props.unstyled}
__parentMetadata={{ parent: props.metaData }}
/>
);
}
Expand Down
6 changes: 4 additions & 2 deletions components/lib/dataview/DataView.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ export const DataView = React.memo(
const props = DataViewBase.getProps(inProps, context);
const [firstState, setFirstState] = React.useState(props.first);
const [rowsState, setRowsState] = React.useState(props.rows);
const { ptm, cx, isUnstyled } = DataViewBase.setMetaData({
const metaData = {
props,
state: {
first: firstState,
rows: rowsState
}
});
};
const { ptm, cx, isUnstyled } = DataViewBase.setMetaData(metaData);

useHandleStyle(DataViewBase.css.styles, isUnstyled, { name: 'dataview' });

Expand Down Expand Up @@ -123,6 +124,7 @@ export const DataView = React.memo(
dropdownAppendTo={props.paginatorDropdownAppendTo}
ptm={ptm('paginator')}
unstyled={props.unstyled}
__parentMetadata={{ parent: metaData }}
/>
);
};
Expand Down
1 change: 1 addition & 0 deletions components/lib/dialog/Dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const Dialog = React.forwardRef((inProps, ref) => {

const { ptm, cx, sx, isUnstyled } = DialogBase.setMetaData({
props,
...props.__parentMetadata,
state: {
id: idState,
maximized: maximized,
Expand Down
1 change: 1 addition & 0 deletions components/lib/dialog/DialogBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ const inlineStyles = {
export const DialogBase = ComponentBase.extend({
defaultProps: {
__TYPE: 'Dialog',
__parentMetadata: null,
appendTo: null,
ariaCloseIconLabel: null,
baseZIndex: 0,
Expand Down
1 change: 1 addition & 0 deletions components/lib/dropdown/Dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const Dropdown = React.memo(
const appendTo = props.appendTo || (context && context.appendTo) || PrimeReact.appendTo;
const { ptm, cx, sx, isUnstyled } = DropdownBase.setMetaData({
props,
...props.__parentMetadata,
state: {
filter: filterState,
focused: focusedState,
Expand Down
1 change: 1 addition & 0 deletions components/lib/dropdown/DropdownBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const inlineStyles = {
export const DropdownBase = ComponentBase.extend({
defaultProps: {
__TYPE: 'Dropdown',
__parentMetadata: null,
appendTo: null,
ariaLabel: null,
ariaLabelledBy: null,
Expand Down
Loading

0 comments on commit adef94d

Please sign in to comment.