Skip to content
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

CB-4038 add action icon button #2064

Merged
merged 5 commits into from
Oct 17, 2023
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
19 changes: 19 additions & 0 deletions webapp/packages/core-blocks/src/ActionIconButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2023 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 { observer } from 'mobx-react-lite';

import style from './ActionIconButton.m.css';
import { IconButton, type IconButtonProps } from './IconButton';
import { s } from './s';
import { useS } from './useS';

export const ActionIconButton: React.FC<IconButtonProps> = observer(function ActionIconButton(props) {
const styles = useS(style);

return <IconButton {...props} className={s(styles, { actionIconButton: true }, props.className)} />;
});
10 changes: 7 additions & 3 deletions webapp/packages/core-blocks/src/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
* Licensed under the Apache License, Version 2.0.
* you may not use this file except in compliance with the License.
*/
import { observer } from 'mobx-react-lite';
import type React from 'react';
import { Button, ButtonProps } from 'reakit/Button';
import styled from 'reshadow';

import type { ComponentStyle } from '@cloudbeaver/core-theming';

import { Icon } from './Icon';
import IconButtonStyles from './IconButton.m.css';
import { s } from './s';
import { StaticImage } from './StaticImage';
import { useS } from './useS';
import { useStyles } from './useStyles';
import IconButtonStyles from './IconButton.m.css';

interface Props {
name: string;
Expand All @@ -24,7 +26,9 @@ interface Props {
style?: ComponentStyle;
}

export function IconButton({ name, img, viewBox, style, className, ...rest }: Props & ButtonProps) {
export type IconButtonProps = Props & ButtonProps;

export const IconButton: React.FC<IconButtonProps> = observer(function IconButton({ name, img, viewBox, style, className, ...rest }) {
const styles = useS(IconButtonStyles);

return styled(useStyles(style))(
Expand All @@ -33,4 +37,4 @@ export function IconButton({ name, img, viewBox, style, className, ...rest }: Pr
{!img && <Icon className={s(styles, { icon: true })} name={name} viewBox={viewBox} />}
</Button>,
);
}
});
21 changes: 0 additions & 21 deletions webapp/packages/core-blocks/src/Menu/ACTION_ICON_BUTTON_STYLES.ts

This file was deleted.

4 changes: 2 additions & 2 deletions webapp/packages/core-blocks/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ export * from './localization/useTranslate';
export * from './ConnectionImageWithMask/ConnectionImageWithMask';
export { default as ConnectionImageWithMaskSvgStyles } from './ConnectionImageWithMask/ConnectionImageWithMaskSvg.m.css';

export * from './Menu/ACTION_ICON_BUTTON_STYLES';
export { default as ActionIconButtonStyles } from './ActionIconButton.m.css';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export { default as ActionIconButtonStyles } from './ActionIconButton.m.css';
please keep it so we can use it in SContext if needed

export * from './Menu/Menu';
export { default as MenuStyles } from './Menu/Menu.m.css';
export * from './Menu/MenuBarSmallItem';
Expand Down Expand Up @@ -182,7 +180,9 @@ export * from './ExceptionMessage';
export { default as ExceptionMessageStyles } from './ExceptionMessage.m.css';
export * from './getComputed';
export * from './IconButton';
export * from './ActionIconButton';
export { default as IconButtonStyles } from './IconButton.m.css';
export { default as ActionIconButtonStyles } from './ActionIconButton.m.css';
export * from './IconOrImage';
export * from './s';
export * from './SContext';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { action, computed, observable } from 'mobx';
import { observer } from 'mobx-react-lite';

import { ActionIconButtonStyles, Button, Container, Fill, IconButton, s, useObservableRef, useS, useTranslate } from '@cloudbeaver/core-blocks';
import { ActionIconButton, Button, Container, Fill, s, useObservableRef, useS, useTranslate } from '@cloudbeaver/core-blocks';
import { selectFiles } from '@cloudbeaver/core-browser';
import { useService } from '@cloudbeaver/core-di';
import { NotificationService } from '@cloudbeaver/core-events';
Expand Down Expand Up @@ -44,33 +44,14 @@ const Tools = observer<IToolsProps>(function Tools({ loading, stretch, onToggleS
return (
<Container gap dense keepSize>
<Container keepSize flexStart center>
{onSave && (
<IconButton
title={translate('ui_download')}
className={ActionIconButtonStyles.actionIconButton}
name="/icons/export.svg"
disabled={loading}
img
onClick={onSave}
/>
)}
{onUpload && (
<IconButton
title={translate('ui_upload')}
className={ActionIconButtonStyles.actionIconButton}
name="/icons/import.svg"
disabled={loading}
img
onClick={onUpload}
/>
)}
{onSave && <ActionIconButton title={translate('ui_download')} name="/icons/export.svg" disabled={loading} img onClick={onSave} />}
{onUpload && <ActionIconButton title={translate('ui_upload')} name="/icons/import.svg" disabled={loading} img onClick={onUpload} />}
</Container>
<Fill />
{onToggleStretch && (
<Container keepSize flexEnd center>
<IconButton
<ActionIconButton
title={translate(stretch ? 'data_viewer_presentation_value_image_original_size' : 'data_viewer_presentation_value_image_fit')}
className={ActionIconButtonStyles.actionIconButton}
name={stretch ? 'img-original-size' : 'img-fit-size'}
onClick={onToggleStretch}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
import { observer } from 'mobx-react-lite';

import { ActionIconButtonStyles, IconButton, s, TableColumnValue, TableItem, useS } from '@cloudbeaver/core-blocks';
import { ActionIconButton, s, TableColumnValue, TableItem, useS } from '@cloudbeaver/core-blocks';

import styles from './FiltersTableItem.m.css';

Expand All @@ -20,13 +20,13 @@ interface Props {
}

export const FiltersTableItem = observer<Props>(function FiltersTableItem({ id, name, disabled, className, onDelete }) {
const style = useS(ActionIconButtonStyles, styles);
const style = useS(styles);

return (
<TableItem className={s(style, { tableItem: true }, className)} item={id} title={name} disabled={disabled} selectDisabled={disabled}>
<TableColumnValue>{name}</TableColumnValue>
<TableColumnValue className={s(style, { deleteColumnCell: true })} flex>
<IconButton className={s(ActionIconButtonStyles, { actionIconButton: true })} name="cross-bold" onClick={() => onDelete(id)} />
<ActionIconButton name="cross-bold" onClick={() => onDelete(id)} />
</TableColumnValue>
</TableItem>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import React, { useState } from 'react';
import styled from 'reshadow';

import {
ActionIconButtonStyles,
ActionIconButton,
Fill,
IconButton,
IconButtonStyles,
PlaceholderElement,
s,
Expand Down Expand Up @@ -56,7 +55,7 @@ export const ElementsTreeTools = observer<React.PropsWithChildren<Props>>(functi
const translate = useTranslate();
const [opened, setOpen] = useState(false);
const deprecatedStyles = useStyles(style);
const styles = useS(ElementsTreeToolsStyles, ElementsTreeToolsIconButtonStyles, ActionIconButtonStyles);
const styles = useS(ElementsTreeToolsStyles, ElementsTreeToolsIconButtonStyles);

useCaptureViewContext(context => {
context?.set(DATA_CONTEXT_NAV_TREE_ROOT, tree.baseRoot);
Expand All @@ -70,21 +69,21 @@ export const ElementsTreeTools = observer<React.PropsWithChildren<Props>>(functi
<div className={s(styles, { tools: true })}>
<div className={s(styles, { actions: true })}>
{tree.settings?.configurable && (
<IconButton
<ActionIconButton
name="/icons/settings_cog_sm.svg"
title={translate('ui_settings')}
className={s(styles, { primary: true, actionIconButton: true, opened })}
className={s(styles, { primary: true, opened })}
img
onClick={() => setOpen(!opened)}
/>
)}
<Fill />
<ElementsTreeToolsMenu tree={tree} />
<IconButton
<ActionIconButton
name="/icons/refresh_sm.svg#root"
title={translate('app_navigationTree_refresh')}
disabled={loading}
className={s(styles, { primary: true, actionIconButton: true, loading })}
className={s(styles, { primary: true, loading })}
img
onClick={() => tree.refresh(root)}
/>
Expand Down
Loading