Skip to content

Commit

Permalink
CB-5437 use flex component instead of container (#2818)
Browse files Browse the repository at this point in the history
* CB-5437 use flex component instead of container

* CB-5437 use data attributes to apply styles

* CB-5437 simplify logic

---------

Co-authored-by: Daria Marutkina <[email protected]>
  • Loading branch information
devnaumov and dariamarutkina authored Aug 7, 2024
1 parent 6ca587a commit 12b5b2b
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 3 deletions.
100 changes: 100 additions & 0 deletions webapp/packages/core-blocks/src/Flex/Flex.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/

.flex {
display: flex;
flex: 1 1 100%;

&.overflow {
overflow: auto;
}

&[data-s-gap='xs'] {
gap: 8px;
}

&[data-s-gap='md'] {
gap: 16px;
}

&[data-s-gap='lg'] {
gap: 24px;
}

&[data-s-wrap='wrap'] {
flex-wrap: wrap;
}

&[data-s-wrap='nowrap'] {
flex-wrap: nowrap;
}

&[data-s-wrap='wrap-reverse'] {
flex-wrap: wrap-reverse;
}

&[data-s-direction='row'] {
flex-direction: row;
}

&[data-s-direction='column'] {
flex-direction: column;
}

&[data-s-direction='row-reverse'] {
flex-direction: row-reverse;
}

&[data-s-direction='column-reverse'] {
flex-direction: column-reverse;
}

&[data-s-align='start'] {
align-items: flex-start;
}

&[data-s-align='center'] {
align-items: center;
}

&[data-s-align='end'] {
align-items: flex-end;
}

&[data-s-align='stretch'] {
align-items: stretch;
}

&[data-s-justify='start'] {
justify-content: flex-start;
}

&[data-s-justify='center'] {
justify-content: center;
}

&[data-s-justify='end'] {
justify-content: flex-end;
}

&[data-s-justify='space-between'] {
justify-content: space-between;
}

&[data-s-justify='space-around'] {
justify-content: space-around;
}

&[data-s-justify='space-evenly'] {
justify-content: space-evenly;
}

&[data-s-justify='stretch'] {
justify-content: stretch;
}
}
40 changes: 40 additions & 0 deletions webapp/packages/core-blocks/src/Flex/Flex.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 DBeaver Corp and others
*
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { forwardRef } from 'react';

import { s } from '../s';
import classes from './Flex.module.css';

interface Props extends React.HTMLAttributes<HTMLDivElement> {
overflow?: boolean;
gap?: 'xs' | 'md' | 'lg';
wrap?: React.CSSProperties['flexWrap'];
direction?: React.CSSProperties['flexDirection'];
align?: React.CSSProperties['alignItems'];
justify?: React.CSSProperties['justifyContent'];
}

export const Flex = forwardRef<HTMLDivElement, Props>(function Flex(
{ overflow, gap, wrap, direction, align, justify, className, children, ...rest },
ref,
) {
return (
<div
ref={ref}
{...rest}
className={s(classes, { flex: true, overflow }, className)}
data-s-gap={gap}
data-s-wrap={wrap}
data-s-direction={direction}
data-s-align={align}
data-s-justify={justify}
>
{children}
</div>
);
});
1 change: 1 addition & 0 deletions webapp/packages/core-blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,4 @@ export * from './manifest';
export * from './importLazyComponent';
export * from './ClickableLoader';
export * from './FormControls/TagsComboboxLoader';
export * from './Flex/Flex';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { observer } from 'mobx-react-lite';

import { Container, useTranslate } from '@cloudbeaver/core-blocks';
import { Flex, useTranslate } from '@cloudbeaver/core-blocks';
import type { TabContainerPanelComponent } from '@cloudbeaver/core-ui';
import { ResourceManagerTree } from '@cloudbeaver/plugin-navigation-tree-rm';

Expand All @@ -17,10 +17,10 @@ export const ResourceManagerScripts: TabContainerPanelComponent = observer(funct
const translate = useTranslate();

return (
<Container vertical overflow>
<Flex direction="column" overflow>
<ResourceManagerTree resourceTypeId={SCRIPTS_TYPE_ID}>
{translate('plugin_resource_manager_scripts_no_resources_placeholder')}
</ResourceManagerTree>
</Container>
</Flex>
);
});

0 comments on commit 12b5b2b

Please sign in to comment.