Skip to content

Commit

Permalink
Refactor #4602 - for ScrollTop
Browse files Browse the repository at this point in the history
  • Loading branch information
habubey committed Jul 6, 2023
1 parent 5f1f3ea commit 92f60b8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 55 deletions.
38 changes: 0 additions & 38 deletions components/lib/scrolltop/ScrollTop.css

This file was deleted.

25 changes: 9 additions & 16 deletions components/lib/scrolltop/ScrollTop.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import * as React from 'react';
import { PrimeReactContext } from '../api/Api';
import PrimeReact, { PrimeReactContext } from '../api/Api';
import { CSSTransition } from '../csstransition/CSSTransition';
import { useEventListener, useUnmountEffect } from '../hooks/Hooks';
import { useEventListener, useStyle, useUnmountEffect } from '../hooks/Hooks';
import { ChevronUpIcon } from '../icons/chevronup';
import { Ripple } from '../ripple/Ripple';
import { DomHandler, IconUtils, ZIndexUtils, classNames, mergeProps } from '../utils/Utils';
import { DomHandler, IconUtils, ZIndexUtils, mergeProps } from '../utils/Utils';
import { ScrollTopBase } from './ScrollTopBase';
import PrimeReact from '../api/Api';

export const ScrollTop = React.memo(
React.forwardRef((inProps, ref) => {
const [visibleState, setVisibleState] = React.useState(false);
const context = React.useContext(PrimeReactContext);

useStyle(ScrollTopBase.css.styles, { name: 'primereact_scrolltop_style' });

const props = ScrollTopBase.getProps(inProps, context);
const { ptm } = ScrollTopBase.setMetaData({
const { ptm, cx } = ScrollTopBase.setMetaData({
props,
state: {
visible: visibleState
Expand Down Expand Up @@ -81,18 +83,9 @@ export const ScrollTop = React.memo(
ZIndexUtils.clear(scrollElementRef.current);
});

const className = classNames(
'p-scrolltop p-link p-component',
{
'p-scrolltop-sticky': props.target !== 'window'
},
props.className
);

const iconClassName = 'p-scrolltop-icon';
const iconProps = mergeProps(
{
className: iconClassName
className: cx('icon')
},
ptm('icon')
);
Expand All @@ -102,7 +95,7 @@ export const ScrollTop = React.memo(
{
ref: scrollElementRef,
type: 'button',
className,
className: cx('root'),
style: props.style,
onClick
},
Expand Down
54 changes: 54 additions & 0 deletions components/lib/scrolltop/ScrollTopBase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ComponentBase } from '../componentbase/ComponentBase';
import { classNames } from '../utils/utils';

export const ScrollTopBase = ComponentBase.extend({
defaultProps: {
Expand All @@ -13,5 +14,58 @@ export const ScrollTopBase = ComponentBase.extend({
onShow: null,
onHide: null,
children: undefined
},
css: {
classes: {
root: ({ props }) =>
classNames(
'p-scrolltop p-link p-component',
{
'p-scrolltop-sticky': props.target !== 'window'
},
props.className
),
icon: 'p-scrolltop-icon'
},
styles: `
.p-scrolltop {
position: fixed;
bottom: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.p-scrolltop-sticky {
position: sticky;
}
.p-scrolltop-sticky.p-link {
margin-left: auto;
}
.p-scrolltop-helper {
display: none !important;
}
.p-scrolltop-enter {
opacity: 0;
}
.p-scrolltop-enter-active {
opacity: 1;
transition: opacity .15s;
}
.p-scrolltop-exit {
opacity: 1;
}
.p-scrolltop-exit-active {
opacity: 0;
transition: opacity .15s;
}
`
}
});
5 changes: 5 additions & 0 deletions components/lib/scrolltop/scrolltop.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export interface ScrollTopProps {
* @type {ScrollTopPassThroughOptions}
*/
pt?: ScrollTopPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}

/**
Expand Down
1 change: 0 additions & 1 deletion styles/primereact.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
@import "../components/lib/knob/Knob.css";
@import "../components/lib/splitter/Splitter.css";
@import "../components/lib/confirmpopup/ConfirmPopup.css";
@import "../components/lib/scrolltop/ScrollTop.css";
@import "../components/lib/cascadeselect/CascadeSelect.css";
@import "../components/lib/treeselect/TreeSelect.css";
@import "../components/lib/virtualscroller/VirtualScroller.css";
Expand Down

0 comments on commit 92f60b8

Please sign in to comment.