Skip to content

Added Switch to show/hide scrollBar #1080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions client/packages/lowcoder-design/src/components/ScrollBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@ import { DebouncedFunc } from 'lodash'; // Assuming you're using lodash's Deboun

// import 'simplebar-react/dist/simplebar.min.css';

const ScrollBarWrapper = styled.div<{ $hideplaceholder?: boolean }>`
const ScrollBarWrapper = styled.div<{
$hideplaceholder?: boolean;
$overflow?: string;
}>`
min-height: 0;
height: 100%;
height: ${props => props.$overflow? props.$overflow === 'scroll' ? '300px' : '100%':'100%'
};
width: 100%;
overflow:${props=>props.$overflow};

.simplebar-scrollbar::before {
background: rgba(139, 143, 163, 0.5) !important;
Expand Down Expand Up @@ -37,7 +42,9 @@ const ScrollBarWrapper = styled.div<{ $hideplaceholder?: boolean }>`
bottom: 10px;
}

${props => Boolean(props.$hideplaceholder) && `
${(props) =>
Boolean(props.$hideplaceholder) &&
`
.simplebar-placeholder {
display: none !important;
}
Expand All @@ -50,6 +57,7 @@ interface IProps {
children: React.ReactNode;
className?: string;
height?: string;
overflow?:string,
style?: React.CSSProperties; // Add this line to include a style prop
scrollableNodeProps?: {
onScroll: DebouncedFunc<(e: any) => void>;
Expand All @@ -64,6 +72,7 @@ export const ScrollBar = ({
className,
children,
style,
overflow,
scrollableNodeProps,
hideScrollbar = false,
$hideplaceholder = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function convertOldContainerParams(params: CompParams<any>) {
// old params
if (container && (container.hasOwnProperty("layout") || container.hasOwnProperty("items"))) {
const autoHeight = tempParams.value.autoHeight;
const scrollbars = tempParams.value.scrollbars;
const scrollbars = tempParams.value.showVerticalScrollbar;
return {
...tempParams,
value: {
Expand Down
16 changes: 11 additions & 5 deletions client/packages/lowcoder/src/comps/comps/listViewComp/listView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { ContextContainerComp } from "./contextContainerComp";
import { ListViewImplComp } from "./listViewComp";
import { getCurrentItemParams, getData } from "./listViewUtils";
import { useMergeCompStyles } from "@lowcoder-ee/util/hooks";
import { childrenToProps } from "@lowcoder-ee/comps/generators/multi";
import { AnimationStyleType } from "@lowcoder-ee/comps/controls/styleControlConstants";

Expand All @@ -29,6 +30,7 @@ const ListViewWrapper = styled.div<{ $style: any; $paddingWidth: string,$animati
rotate: ${(props) => props.$style.rotation};
background-color: ${(props) => props.$style.background};
${props=>props.$animationStyle}

`;

const FooterWrapper = styled.div`
Expand All @@ -39,7 +41,8 @@ const FooterWrapper = styled.div`
`;

const BodyWrapper = styled.div<{ $autoHeight: boolean }>`
height: ${(props) => (props.$autoHeight ? "100%" : "calc(100% - 32px)")};
overflow: ${(props) => (!props.$autoHeight ? "auto" : "hidden")};
height: ${(props) => (props.$autoHeight ? "auto" : "calc(100% - 32px)")};
`;

const FlexWrapper = styled.div`
Expand All @@ -56,8 +59,7 @@ const ListOrientationWrapper = styled.div<{
}>`
height: ${(props) => (props.$autoHeight ? "auto" : "100%")};
display: flex;
flex-direction: ${(props) => (props.$isHorizontal && !props.$isGrid ? "row" : "column")};
height: 100%;
flex-direction: ${(props) => (props.$isHorizontal ? "row" : "column")};
`;

type MinHorizontalWidthContextType = {
Expand Down Expand Up @@ -189,7 +191,8 @@ export function ListView(props: Props) {
);
const horizontalGridCells = useMemo(() => children.horizontalGridCells.getView(), [children.horizontalGridCells]);
const autoHeight = useMemo(() => children.autoHeight.getView(), [children.autoHeight]);
const scrollbars = useMemo(() => children.scrollbars.getView(), [children.scrollbars]);
const showHorizontalScrollbar = useMemo(() => children.showHorizontalScrollbar.getView(), [children.showHorizontalScrollbar]);
const showVerticalScrollbar = useMemo(() => children.showVerticalScrollbar.getView(), [children.showVerticalScrollbar])
const horizontal = useMemo(() => children.horizontal.getView(), [children.horizontal]);
const minHorizontalWidth = useMemo(() => children.minHorizontalWidth.getView(), [children.minHorizontalWidth]);
const noOfColumns = useMemo(
Expand Down Expand Up @@ -283,12 +286,14 @@ export function ListView(props: Props) {

const childrenProps = childrenToProps(comp.children);

useMergeCompStyles(childrenProps, comp.dispatch);

// log.debug("renders: ", renders);
return (
<BackgroundColorContext.Provider value={style.background}>
<ListViewWrapper $style={style} $paddingWidth={paddingWidth} $animationStyle={animationStyle}>
<BodyWrapper ref={ref} $autoHeight={autoHeight}>
<ScrollBar style={{ height: autoHeight ? "auto" : "100%", margin: "0px", padding: "0px" }} hideScrollbar={!scrollbars}>
<ScrollBar style={{ height: autoHeight ? "auto" : "100%", margin: "0px", padding: "0px" }} hideScrollbar={horizontal ? !showHorizontalScrollbar : !showVerticalScrollbar} overflow={autoHeight ? horizontal ? 'scroll' : 'hidden' : 'scroll'}>
<ReactResizeDetector
onResize={(width?: number, height?: number) => {
if (height) setListHeight(height);
Expand All @@ -314,3 +319,4 @@ export function ListView(props: Props) {
</BackgroundColorContext.Provider>
);
}

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const childrenMap = {
heightUnitOfRow: withDefault(NumberControl, 1),
container: ContextContainerComp,
autoHeight: AutoHeightControl,
showVerticalScrollbar: withDefault(BoolControl, false),
showHorizontalScrollbar: withDefault(BoolControl, false),
horizontalGridCells: SliderControl,
scrollbars: withDefault(BoolControl, false),
showBorder: BoolControl,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ export function listPropertyView(compType: ListCompType) {
label: trans('prop.horizontalGridCells'),
})}
{children.autoHeight.getPropertyView()}
{(!children.autoHeight.getView() || children.horizontal.getView()) &&
children.scrollbars.propertyView({
label: trans("prop.scrollbar"),
{(!children.autoHeight.getView()) && !children.horizontal.getView()&&
children.showVerticalScrollbar.propertyView({
label: trans("prop.showVerticalScrollbar"),
}
)}
{(children.horizontal.getView()) &&
children.showHorizontalScrollbar.propertyView({
label: trans("prop.showHorizontalScrollbar"),
}
)}
{children.horizontal.propertyView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export class PageLayoutComp extends layoutBaseComp implements IContainer {
return [
this.children.autoHeight.getPropertyView(),
this.children.siderScrollbars.propertyView({ label: trans("prop.siderScrollbar")}),
(!this.children.autoHeight.getView()) && this.children.contentScrollbars.propertyView({ label: trans("prop.contentScrollbar") }),
(!this.children.autoHeight.getView()) && this.children.contentScrollbars.propertyView({ label: trans("prop.showVerticalScrollbar") }),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function ShapeTriContainer(props: TriContainerProps) {
// const { showHeader, showFooter } = container;
// When the header and footer are not displayed, the body must be displayed
const showBody = true;
const scrollbars = container.scrollbars;
const showVerticalScrollbar = container.showVerticalScrollbar;

const { items: bodyItems, ...otherBodyProps } =
container.body["0"].children.view.getView();
Expand Down Expand Up @@ -120,7 +120,7 @@ export function ShapeTriContainer(props: TriContainerProps) {
margin: "0px",
padding: "0px",
}}
hideScrollbar={!scrollbars}
hideScrollbar={!showVerticalScrollbar}
>
<div style={{ position: "relative", height: "100%" }}>
<StylesShape
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const childrenMap = {
1: { layout: {}, items: {} },
}),
autoHeight: AutoHeightControl,
showVerticalScrollbar: withDefault(BoolControl, false),
horizontalGridCells: SliderControl,
scrollbars: withDefault(BoolControl, false),
placement: withDefault(PositionControl, "top"),
Expand Down Expand Up @@ -237,11 +238,11 @@ const TabbedContainer = (props: TabbedContainerProps) => {
);
return {
label,
key: tab.key,
key: tab.key,
forceRender: true,
children: (
<BackgroundColorContext.Provider value={bodyStyle.background}>
<ScrollBar style={{ height: props.autoHeight ? "100%" : "auto", margin: "0px", padding: "0px" }} hideScrollbar={!props.scrollbars}>
<ScrollBar style={{ height: props.autoHeight ? "auto" : "100%", margin: "0px", padding: "0px" }} hideScrollbar={!props.showVerticalScrollbar} overflow={props.autoHeight ? 'hidden':'scroll'}>
<ContainerInTab
layout={containerProps.layout.getView()}
items={gridItemCompToGridItems(containerProps.items.getView())}
Expand All @@ -258,8 +259,7 @@ const TabbedContainer = (props: TabbedContainerProps) => {
})

return (
<ScrollBar style={{ height: props.autoHeight ? "100%" : "auto", margin: "0px", padding: "0px" }} hideScrollbar={!props.scrollbars}>
<div style={{padding: props.style.margin, height: props.autoHeight ? "100%" : "auto"}}>
<div style={{padding: props.style.margin, height: props.autoHeight ? "auto" : "100%"}}>
<BackgroundColorContext.Provider value={headerStyle.headerBackground}>
<StyledTabs
$animationStyle={props.animationStyle}
Expand All @@ -285,7 +285,6 @@ const TabbedContainer = (props: TabbedContainerProps) => {
</StyledTabs>
</BackgroundColorContext.Provider>
</div>
</ScrollBar>
);
};

Expand Down Expand Up @@ -329,8 +328,8 @@ export const TabbedContainerBaseComp = (function () {
})}
{children.autoHeight.getPropertyView()}
{!children.autoHeight.getView() && (
children.scrollbars.propertyView({
label: trans("prop.scrollbar"),
children.showVerticalScrollbar.propertyView({
label: trans("prop.showVerticalScrollbar"),
})
)}
</Section>
Expand Down Expand Up @@ -465,3 +464,4 @@ export const TabbedContainerComp = withExposingConfigs(TabbedContainerImplComp,
new NameConfig("selectedTabKey", trans("tabbedContainer.selectedTabKeyDesc")),
NameConfigHidden,
]);

Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function TriContainer(props: TriContainerProps) {
const { showHeader, showFooter, horizontalGridCells } = container;
// When the header and footer are not displayed, the body must be displayed
const showBody = container.showBody || (!showHeader && !showFooter);
const scrollbars = container.scrollbars;
const showVerticalScrollbar = container.showVerticalScrollbar;

const { items: headerItems, ...otherHeaderProps } = container.header;
const { items: bodyItems, ...otherBodyProps } = container.body["0"].children.view.getView();
Expand Down Expand Up @@ -151,7 +151,7 @@ export function TriContainer(props: TriContainerProps) {
)}
{showBody && (
<BackgroundColorContext.Provider value={bodyStyle.background}>
<ScrollBar style={{ height: container.autoHeight ? "auto" : "100%", margin: "0px", padding: "0px" }} hideScrollbar={!scrollbars}>
<ScrollBar style={{ height: container.autoHeight ? "auto" : "100%", margin: "0px", padding: "0px" }} hideScrollbar={!showVerticalScrollbar} overflow={container.autoHeight?'hidden':'scroll'}>
<BodyInnerGrid
$showBorder={showHeader}
{...otherBodyProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const childrenMap = {
showBody: BoolControl.DEFAULT_TRUE,
showFooter: BoolControl,
autoHeight: AutoHeightControl,
showVerticalScrollbar: withDefault(BoolControl, false),
horizontalGridCells: SliderControl,
scrollbars: withDefault(BoolControl, false),
style: withDefault(styleControl(ContainerStyle, 'style'),{borderWidth:'1px'}),
Expand Down Expand Up @@ -138,7 +139,7 @@ export class TriContainerComp extends TriContainerBaseComp implements IContainer
heightPropertyView() {
return [
this.children.autoHeight.getPropertyView(),
(!this.children.autoHeight.getView()) && this.children.scrollbars.propertyView({ label: trans("prop.scrollbar") })
(!this.children.autoHeight.getView()) && this.children.showVerticalScrollbar.propertyView({ label: trans("prop.showVerticalScrollbar") })
];
}

Expand Down
6 changes: 3 additions & 3 deletions client/packages/lowcoder/src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,9 @@ export const en = {
"toggleClose": "Enable Close Button",
"showMask": "Show Mask",
"textOverflow": "Text Overflow",
"scrollbar": "Show Scrollbars",
"scrollbar" : "Show Scrollbars",
"showVerticalScrollbar" : "Show Vertical Scrollbar",
"showHorizontalScrollbar" : "Show Horizontal Scrollbar",
"siderScrollbar" : "Show Scrollbars in Sider",
"siderRight" : "Show sider on the Right",
"siderWidth" : "Sider Width",
Expand All @@ -221,8 +223,6 @@ export const en = {
"preventOverwriting": "Prevent overwriting styles",
"color": "Color",
"horizontalGridCells": "Horizontal Grid Cells",
"showHorizontalScrollbar": "Show Horizontal Scrollbar",
"showVerticalScrollbar": "Show Vertical Scrollbar",
"timeZone": "TimeZone",
},
"autoHeightProp": {
Expand Down
Loading