Skip to content

Commit

Permalink
feat: add disabled prop
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaClin committed Jun 17, 2021
1 parent e605845 commit 44ecb46
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
23 changes: 12 additions & 11 deletions packages/react-styled-ui/src/Scrollbar/Scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,29 @@ let scrollbarWidth = false;

const Scrollbar = forwardRef((
{
onScroll,
onUpdate,
scrollbarVisibility = 'auto',
autoHideDelay = 1000,
thumbSize,
minThumbSize = 30,
minHeight = 'auto',
children,
disabled,
maxHeight = 'auto',
minHeight = 'auto',
minThumbSize = 30,
onScroll,
onUpdate,
renderView = renderViewDefault,
renderHorizontalTrack = renderTrackHorizontalDefault,
renderHorizontalThumb = renderThumbHorizontalDefault,
renderVerticalTrack = renderTrackVerticalDefault,
renderVerticalThumb = renderThumbVerticalDefault,
scrollbarVisibility = 'auto',
style,
children,
thumbSize,
...reset
},
ref,
) => {
const autoHeight = (maxHeight !== 'auto');
const horizontalScrollbarVisibility = scrollbarVisibility;
const verticalScrollbarVisibility = scrollbarVisibility;
const horizontalScrollbarVisibility = disabled ? 'hidden' : scrollbarVisibility;
const verticalScrollbarVisibility = disabled ? 'hidden' : scrollbarVisibility;
let hideHorizontalTrackTimeout;
let hideVerticalTrackTimeout;
let viewScrollLeft = 0;
Expand All @@ -58,7 +59,7 @@ const Scrollbar = forwardRef((
const thumbVerticalRef = useRef(null);

const containerStyle = useContainerStyle({ autoHeight, minHeight, maxHeight, style });
const viewStyle = useViewStyle({ scrollbarWidth, autoHeight, minHeight, maxHeight });
const viewStyle = useViewStyle({ scrollbarWidth, autoHeight, minHeight, maxHeight, disabled });
const trackHorizontalStyle = useTrackHorizontalStyle({ scrollbarWidth, horizontalScrollbarVisibility });
const trackVerticalStyle = useTrackVerticalStyle({ scrollbarWidth, verticalScrollbarVisibility });
const thumbHorizontalStyle = useThumbHorizontalStyle();
Expand Down Expand Up @@ -86,7 +87,7 @@ const Scrollbar = forwardRef((
};
const update = (callback) => {
const scrollbarWidth = getScrollbarWidth();
if (!scrollbarWidth) {
if (!scrollbarWidth || disabled) {
return;
}
const values = getValues();
Expand Down
5 changes: 2 additions & 3 deletions packages/react-styled-ui/src/Scrollbar/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ const useContainerStyle = props => ({
...props.style,
});

const useViewStyle = props => {
const { scrollbarWidth, autoHeight, minHeight, maxHeight } = props;
const useViewStyle = ({ scrollbarWidth, autoHeight, minHeight, maxHeight, disabled }) => {
return {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
overflow: 'scroll',
overflow: disabled ? 'hidden' : 'scroll',
WebkitOverflowScrolling: 'touch',
// Hide scrollbars by setting a negative margin
marginRight: scrollbarWidth ? -scrollbarWidth : 0,
Expand Down
8 changes: 3 additions & 5 deletions packages/styled-ui-docs/pages/scrollbar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ function StickyTable() {

const tableHeaderRef = React.createRef();

const [showHorizontalScrollbar, setShowHorizontalScrollbar] = React.useState(0);
const [showVerticalScrollbar, setShowVerticalScrollbar] = React.useState(0);
const [showHorizontalScrollbar, setShowHorizontalScrollbar] = React.useState(false);
const [showVerticalScrollbar, setShowVerticalScrollbar] = React.useState(false);

const onScroll = (e) => {
const scrollLeft = e.target.scrollLeft;
Expand All @@ -118,9 +118,6 @@ function StickyTable() {
};

const onUpdate = ({ hasHorizontalScrollbar, hasVerticalScrollbar, ...props }) => {
if (showHorizontalScrollbar !== 0 && showHorizontalScrollbar !== 0) {
return;
}
setShowHorizontalScrollbar(hasHorizontalScrollbar);
setShowVerticalScrollbar(hasVerticalScrollbar);
};
Expand Down Expand Up @@ -261,6 +258,7 @@ render(
| Name | Type | Default | Description |
| :--- | :--- | :------ | :---------- |
| autoHideDelay | number | 1000 | Hide delay in ms. |
| disabled | boolean | | If `true`, the overflow is clipped, and the rest of the content is hidden. |
| maxHeight | number \| string | 'auto' | Set a minimum height (in pixels) for auto-height mode. If `maxHeight` is not `'auto'`, activate auto height mode. |
| minHeight | number \| string | 'auto' | Set a maximum height (in pixels) for auto-height mode. |
| minThumbSize | number | 30 | Minimal thumb size in pixels. |
Expand Down

0 comments on commit 44ecb46

Please sign in to comment.