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

feat: add slide animation for ActionPanel #110

Merged
merged 8 commits into from
Feb 1, 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
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,63 @@ type MenuItem = {
DashKit.setSettings({menu: [] as Array<MenuItem>});
```

### CSS API

| Name | Description |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add some caption? Like CSS Api. And would be good to add some recommendations how to use it.

|-:----------------------------------------------|-:---------------------|
| Action panel variables | |
| `--dashkit-action-panel-color` | Background color |
| `--dashkit-action-panel-border-color` | Border color |
| `--dashkit-action-panel-border-radius` | Border radius |
| Action panel item variables | |
| `--dashkit-action-panel-item-color` | Backgroud color |
| `--dashkit-action-panel-item-text-color` | Text color |
| `--dashkit-action-panel-item-color-hover` | Hover backgroud color |
| `--dashkit-action-panel-item-text-color-hover` | Hover text color |
| Overlay variables | |
| `--dashkit-overlay-border-color` | Border color |
| `--dashkit-overlay-color` | Background color |
| `--dashkit-overlay-opacity` | Opacity |
| Grid item variables | |
| `--dashkit-grid-item-edit-opacity` | Opacity |
| `--dashkit-grid-item-border-radius` | Border radius |
| Placeholder variables | |
| `--dashkit-placeholder-color` | Background color |
| `--dashkit-placeholder-opacity` | Opacity |

#### Usage example


```css
.custom-theme-wrapper {
--dashkit-grid-item-edit-opacit: 1;
--dashkit-overlay-color: var(--g-color-base-float);
--dashkit-overlay-border-color: var(--g-color-base-float);
--dashkit-overlay-opacity: 0.5;

--dashkit-action-panel-border-color: var(--g-color-line-info);
--dashkit-action-panel-color: var(--g-color-base-float-accent);
--dashkit-action-panel-border-radius: var(--g-border-radius-xxl);
}
```

```tsx
// ....

const CustomThemeWrapper = (props: {
dashkitProps: DashkitProps;
actionPanelProps: ActionPanelProps;
}) => {
return (
<div className="custom-theme-wrapper">
<Dashkit {...props.dashkitProps} />
<ActionPanel {...props.actionPanelProps} />
</div>
);
};
```


## Development

### Build & watch
Expand Down
8 changes: 2 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"@gravity-ui/i18n": "^1.0.0",
"hashids": "^2.2.8",
"immutability-helper": "^3.1.1",
"react-grid-layout": "^1.3.4"
"react-grid-layout": "^1.3.4",
"react-transition-group": "^4.4.5"
},
"peerDependencies": {
"@bem-react/classname": "^1.6.0",
Expand Down
63 changes: 57 additions & 6 deletions src/components/ActionPanel/ActionPanel.scss
Original file line number Diff line number Diff line change
@@ -1,33 +1,84 @@
.dashkit-action-panel {
background-color: var(--g-color-base-float);
box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
$show_panel_transform: translateX(-50%) translateY(0);
$hide_panel_transform: translateX(-50%) translateY(calc(100% + 20px));

--_--dashkit-action-panel-color: var(--dashkit-action-panel-color, var(--g-color-base-float));
--_--dashkit-action-panel-border-color: var(
--dashkit-action-panel-border-color,
var(--g-color-base-brand)
);
--_--dashkit-action-panel-border-radius: var(
--dashkit-action-panel-border-radius,
var(--g-border-radius-xl)
);

background-color: var(--_--dashkit-action-panel-color);
position: fixed;
bottom: 20px;
display: flex;
border-radius: 8px;
border-radius: var(--_--dashkit-action-panel-border-radius);
border: 2px solid var(--_--dashkit-action-panel-border-color);
padding: 8px;
gap: 0;
left: 50%;
transform: translateX(-50%);
transform: $show_panel_transform;
z-index: 1;

&-enter {
transform: $hide_panel_transform;
will-change: transform;

&-active {
transform: $show_panel_transform;
transition: transform 300ms ease;
}
}

&-exit {
transform: $show_panel_transform;
will-change: transform;

&-active {
transform: $hide_panel_transform;
transition: transform 300ms ease;
}
}

&__item {
--_--dashkit-action-panel-item-color: var(--dashkit-action-panel-item-color, transparent);
--_--dashkit-action-panel-item-text-color: var(
--dashkit-action-panel-item-text-color,
var(--g-color-text-primary)
);
--_--dashkit-action-panel-item-color-hover: var(
--dashkit-action-panel-item-color-hover,
var(--g-color-base-simple-hover)
);
--_--dashkit-action-panel-item-text-color-hover: var(
--dashkit-action-panel-item-text-color-hover,
var(--g-color-text-primary)
);

height: 68px;
width: 98px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
transition: 0.3s background-color ease-in-out;
transition: 300ms color ease-in-out, 300ms background-color ease-in-out;
border-radius: 6px;
padding: 0 12px;
box-sizing: border-box;
white-space: nowrap;
overflow: hidden;
background-color: var(--_--dashkit-action-panel-item-color);
color: var(--_--dashkit-action-panel-item-text-color);
will-change: color, backgroung-color;

&:hover {
cursor: pointer;
background-color: var(--g-color-base-simple-hover);
background-color: var(--_--dashkit-action-panel-item-color-hover);
color: var(--_--dashkit-action-panel-item-text-color-hover);
}
}

Expand Down
27 changes: 25 additions & 2 deletions src/components/ActionPanel/ActionPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import {CSSTransition} from 'react-transition-group';

import {cn} from '../../utils/cn';

Expand All @@ -16,13 +17,19 @@ export type ActionPanelItem = {
export type ActionPanelProps = {
items: ActionPanelItem[];
className?: string;
disable?: boolean;
toggleAnimation?: boolean;
};

const b = cn('dashkit-action-panel');

export const ActionPanel = (props: ActionPanelProps) => {
return (
<div className={b(null, props.className)}>
const isDisabled = props.disable ?? false;
const isAnimated = props.toggleAnimation ?? false;
const nodeRef = React.useRef<HTMLDivElement | null>(null);

const content = (
<div ref={nodeRef} className={b(null, props.className)}>
{props.items.map((item) => {
return (
<div
Expand All @@ -41,4 +48,20 @@ export const ActionPanel = (props: ActionPanelProps) => {
})}
</div>
);

if (isAnimated) {
return (
<CSSTransition
in={!isDisabled}
nodeRef={nodeRef}
classNames={b(null)}
timeout={300}
unmountOnExit
>
{content}
</CSSTransition>
);
} else {
return isDisabled ? null : content;
}
};
113 changes: 113 additions & 0 deletions src/components/DashKit/__stories__/CssApiShowcase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import React from 'react';
import {Icon} from '@gravity-ui/uikit';
import {
ChartColumn,
Heading,
Layers3Diagonal,
PlugConnection,
Sliders,
TextAlignLeft,
} from '@gravity-ui/icons';

import {Demo, DemoRow} from './Demo';
import {getConfig} from './utils';
import {DashKit, ActionPanel, MenuItems} from '../../..';
import i18n from '../../../i18n';
import {CogIcon} from '../../../icons/CogIcon';
import {CopyIcon} from '../../../icons/CopyIcon';
import {DeleteIcon} from '../../../icons/DeleteIcon';

export const CssApiShowcase: React.FC = () => {
React.useEffect(() => {
DashKit.setSettings({
menu: [
{
id: 'settings',
title: 'Menu setting text',
icon: <Icon data={CogIcon} size={16} />,
},
{
id: MenuItems.Copy,
title: 'Menu setting copy',
icon: <Icon data={CopyIcon} size={16} />,
},
{
id: MenuItems.Delete,
title: i18n('label_delete'), // for language change check
icon: <Icon data={DeleteIcon} size={16} />,
className: 'dashkit-overlay-controls__item_danger',
},
],
});
}, []);

const items = React.useMemo(
() => [
{
id: 'chart',
icon: <Icon data={ChartColumn} />,
title: 'Chart',
className: 'test',
qa: 'chart',
},
{
id: 'selector',
icon: <Icon data={Sliders} />,
title: 'Selector',
qa: 'selector',
},
{
id: 'text',
icon: <Icon data={TextAlignLeft} />,
title: 'Text',
},
{
id: 'header',
icon: <Icon data={Heading} />,
title: 'Header',
},
{
id: 'links',
icon: <Icon data={PlugConnection} />,
title: 'Links',
},
{
id: 'tabs',
icon: <Icon data={Layers3Diagonal} />,
title: 'Tabs',
},
],
[],
);

return (
<>
<style>
{`.g-root {
--dashkit-action-panel-border-color: var(--g-color-line-info);
--dashkit-action-panel-color: var(--g-color-base-float-accent);
--dashkit-action-panel-border-radius: var(--g-border-radius-xxl);

--dashkit-action-panel-item-color: transparent;
--dashkit-action-panel-item-text-color: var(--g-color-text-primary);

--dashkit-action-panel-item-color-hover: var(--g-color-line-info);
--dashkit-action-panel-item-text-color-hover: white;

--dashkit-overlay-color: var(--g-color-line-info);
--dashkit-overlay-border-color: var(--g-color-line-info);
--dashkit-overlay-opacity: 0.5;

--dashkit-placeholder-color: var(--g-color-line-positive);
--dashkit-placeholder-opacity: 1;
}`}
</style>
<Demo title="CSS API">
<DemoRow title="Component view">
<ActionPanel items={items} />
<DashKit editMode={true} config={getConfig()} />
</DemoRow>
</Demo>
</>
);
};
4 changes: 4 additions & 0 deletions src/components/DashKit/__stories__/DashKit.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {DashKit, DashKitProps} from '../DashKit';
import pluginTitle from '../../../plugins/Title/Title';
import pluginText from '../../../plugins/Text/Text';
import {DashKitShowcase} from './DashKitShowcase';
import {CssApiShowcase} from './CssApiShowcase';
import {getConfig} from './utils';
import './DashKit.stories.scss';

Expand Down Expand Up @@ -69,3 +70,6 @@ export const Default = DefaultTemplate.bind({});

const ShowcaseTemplate: Story = () => <DashKitShowcase />;
export const Showcase = ShowcaseTemplate.bind({});

const CssApiShowcaseTemplate: Story<DashKitProps> = () => <CssApiShowcase />;
export const CSS_API = CssApiShowcaseTemplate.bind({});
Loading
Loading