From 6adecb337047e367de8bf0ed6f24742197714d00 Mon Sep 17 00:00:00 2001 From: habubey Date: Thu, 6 Jul 2023 10:51:05 +0300 Subject: [PATCH] Refactor #4602 - for Inplace --- components/lib/inplace/Inplace.css | 21 -------------- components/lib/inplace/Inplace.js | 29 +++++++----------- components/lib/inplace/InplaceBase.js | 42 +++++++++++++++++++++++++++ components/lib/inplace/inplace.d.ts | 7 ++++- styles/primereact.css | 2 -- 5 files changed, 58 insertions(+), 43 deletions(-) delete mode 100644 components/lib/inplace/Inplace.css diff --git a/components/lib/inplace/Inplace.css b/components/lib/inplace/Inplace.css deleted file mode 100644 index 3a2ef673fd..0000000000 --- a/components/lib/inplace/Inplace.css +++ /dev/null @@ -1,21 +0,0 @@ -.p-inplace .p-inplace-display { - display: inline; - cursor: pointer; -} - -.p-inplace .p-inplace-content { - display: inline; -} - -.p-fluid .p-inplace.p-inplace-closable .p-inplace-content { - display: flex; -} - -.p-fluid .p-inplace.p-inplace-closable .p-inplace-content > .p-inputtext { - flex: 1 1 auto; - width: 1%; -} - -.p-inplace-content-close { - margin-left: .25rem; -} diff --git a/components/lib/inplace/Inplace.js b/components/lib/inplace/Inplace.js index d5712be1c1..910c7597ee 100644 --- a/components/lib/inplace/Inplace.js +++ b/components/lib/inplace/Inplace.js @@ -1,10 +1,10 @@ import * as React from 'react'; -import { localeOption } from '../api/Api'; +import { localeOption, PrimeReactContext } from '../api/Api'; import { Button } from '../button/Button'; +import { useStyle } from '../hooks/Hooks'; import { TimesIcon } from '../icons/times'; -import { classNames, IconUtils, mergeProps, ObjectUtils } from '../utils/Utils'; +import { IconUtils, mergeProps, ObjectUtils } from '../utils/Utils'; import { InplaceBase } from './InplaceBase'; -import { PrimeReactContext } from '../api/Api'; export const InplaceDisplay = (props) => props.children; export const InplaceContent = (props) => props.children; @@ -17,7 +17,9 @@ export const Inplace = React.forwardRef((inProps, ref) => { const elementRef = React.useRef(null); const active = props.onToggle ? props.active : activeState; - const { ptm } = InplaceBase.setMetaData({ + useStyle(InplaceBase.css.styles, { name: 'primereact_inplace_style' }); + + const { ptm, cx } = InplaceBase.setMetaData({ props, state: { active: activeState @@ -62,14 +64,10 @@ export const Inplace = React.forwardRef((inProps, ref) => { }; const createDisplay = (content) => { - const className = classNames('p-inplace-display', { - 'p-disabled': props.disabled - }); - const displayProps = mergeProps( { onClick: open, - className, + className: cx('display'), onKeyDown: onDisplayKeyDown, tabIndex: props.tabIndex, 'aria-label': props.ariaLabel @@ -87,7 +85,7 @@ export const Inplace = React.forwardRef((inProps, ref) => { if (props.closable) { const closeButtonProps = mergeProps({ - className: 'p-inplace-content-close', + className: cx('closeButton'), icon: closeIcon, type: 'button', onClick: close, @@ -106,7 +104,7 @@ export const Inplace = React.forwardRef((inProps, ref) => { const contentProps = mergeProps( { - className: 'p-inplace-content' + className: cx('content') }, ptm('content') ); @@ -137,18 +135,11 @@ export const Inplace = React.forwardRef((inProps, ref) => { })); const children = createChildren(); - const className = classNames( - 'p-inplace p-component', - { - 'p-inplace-closable': props.closable - }, - props.className - ); const rootProps = mergeProps( { ref: elementRef, - className + className: cx('root') }, InplaceBase.getOtherProps(props), ptm('root') diff --git a/components/lib/inplace/InplaceBase.js b/components/lib/inplace/InplaceBase.js index 1174440e0e..1e3fe5deeb 100644 --- a/components/lib/inplace/InplaceBase.js +++ b/components/lib/inplace/InplaceBase.js @@ -1,4 +1,5 @@ import { ComponentBase } from '../componentbase/ComponentBase'; +import { classNames } from '../utils/utils'; export const InplaceDisplayBase = ComponentBase.extend({ defaultProps: { @@ -29,5 +30,46 @@ export const InplaceBase = ComponentBase.extend({ onClose: null, onToggle: null, children: undefined + }, + css: { + classes: { + display: ({ props }) => + classNames('p-inplace-display', { + 'p-disabled': props.disabled + }), + root: ({ props }) => + classNames( + 'p-inplace p-component', + { + 'p-inplace-closable': props.closable + }, + props.className + ), + closeButton: 'p-inplace-content-close', + content: 'p-inplace-content' + }, + styles: ` + .p-inplace .p-inplace-display { + display: inline; + cursor: pointer; + } + + .p-inplace .p-inplace-content { + display: inline; + } + + .p-fluid .p-inplace.p-inplace-closable .p-inplace-content { + display: flex; + } + + .p-fluid .p-inplace.p-inplace-closable .p-inplace-content > .p-inputtext { + flex: 1 1 auto; + width: 1%; + } + + .p-inplace-content-close { + margin-left: .25rem; + } + ` } }); diff --git a/components/lib/inplace/inplace.d.ts b/components/lib/inplace/inplace.d.ts index c41dd693f2..ac9a6f66c2 100644 --- a/components/lib/inplace/inplace.d.ts +++ b/components/lib/inplace/inplace.d.ts @@ -14,8 +14,8 @@ * */ import * as React from 'react'; -import { IconType, PassThroughType } from '../utils/utils'; import { ButtonPassThroughOptions } from '../button'; +import { IconType, PassThroughType } from '../utils/utils'; export declare type InplacePassThroughType = PassThroughType; /** @@ -130,6 +130,11 @@ export interface InplaceProps extends Omit