Skip to content

Commit

Permalink
feat: dashkit and action panel toggle animations properties
Browse files Browse the repository at this point in the history
  • Loading branch information
flops committed Jan 30, 2024
1 parent 9f896cb commit ef55821
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 38 deletions.
32 changes: 19 additions & 13 deletions src/components/ActionPanel/ActionPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ export type ActionPanelItem = {
export type ActionPanelProps = {
items: ActionPanelItem[];
className?: string;
enable?: boolean;
disable?: boolean;
toggleAnimation?: boolean;
};

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

export const ActionPanel = (props: ActionPanelProps) => {
const isHidden = !props.enable;
const isDisabled = props.disable ?? false;
const isAnimated = props.toggleAnimation ?? false;
const nodeRef = React.useRef<HTMLDivElement | null>(null);

const content = (
Expand All @@ -47,15 +49,19 @@ export const ActionPanel = (props: ActionPanelProps) => {
</div>
);

return (
<CSSTransition
in={!isHidden}
nodeRef={nodeRef}
classNames={b(null)}
timeout={600}
unmountOnExit
>
{content}
</CSSTransition>
);
if (isAnimated) {
return (
<CSSTransition
in={!isDisabled}
nodeRef={nodeRef}
classNames={b(null)}
timeout={300}
unmountOnExit
>
{content}
</CSSTransition>
);
} else {
return isDisabled ? null : content;
}
};
1 change: 1 addition & 0 deletions src/components/DashKit/DashKit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ interface DashKitGeneralProps {
editMode: boolean;
draggableHandleClassName?: string;
overlayControls?: Record<string, OverlayControlItem[]>;
editModeAnimation?: boolean;
}

interface DashKitDefaultProps {
Expand Down
2 changes: 1 addition & 1 deletion src/components/DashKit/__stories__/CssApiShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const CssApiShowcase: React.FC = () => {
</style>
<Demo title="CSS API">
<DemoRow title="Component view">
<ActionPanel enable={true} items={items} />
<ActionPanel items={items} />
<DashKit editMode={true} config={getConfig()} />
</DemoRow>
</Demo>
Expand Down
21 changes: 20 additions & 1 deletion src/components/DashKit/__stories__/DashKitShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type DashKitDemoState = {
customControlsActionData: number;
showCustomMenu: boolean;
enableActionPanel: boolean;
enableAnimations: boolean;
};

export class DashKitShowcase extends React.Component<{}, DashKitDemoState> {
Expand All @@ -53,6 +54,7 @@ export class DashKitShowcase extends React.Component<{}, DashKitDemoState> {
customControlsActionData: 0,
showCustomMenu: true,
enableActionPanel: false,
enableAnimations: true,
};

private dashKitRef = React.createRef<DashKit>();
Expand Down Expand Up @@ -107,6 +109,17 @@ export class DashKitShowcase extends React.Component<{}, DashKitDemoState> {
{editMode ? 'Disable editMode' : 'Enable editMode'}
</Button>
<div className={b('controls-line')}>
<Button
view="normal"
size="m"
onClick={() => this.toggleAnimations()}
className={b('btn-contol')}
disabled={!editMode}
>
{this.state.enableAnimations
? 'Disable animations'
: 'Enable animations'}
</Button>
<Button
view="normal"
size="m"
Expand Down Expand Up @@ -175,12 +188,14 @@ export class DashKitShowcase extends React.Component<{}, DashKitDemoState> {
<DemoRow title="Last action in DashKit">{this.state.lastAction}</DemoRow>
<DemoRow title="Component view">
<ActionPanel
enable={editMode ? this.state.enableActionPanel : false}
items={this.getActionPanelItems()}
toggleAnimation={this.state.enableAnimations}
disable={editMode ? !this.state.enableActionPanel : true}
/>
<DashKit
config={this.state.config}
editMode={editMode}
editModeAnimation={this.state.enableAnimations}
itemsStateAndParams={this.state.itemsStateAndParams}
defaultGlobalParams={this.state.defaultGlobalParams}
globalParams={this.state.globalParams}
Expand Down Expand Up @@ -367,6 +382,10 @@ export class DashKitShowcase extends React.Component<{}, DashKitDemoState> {
this.setState({enableActionPanel: !this.state.enableActionPanel});
}

private toggleAnimations() {
this.setState({enableAnimations: !this.state.enableAnimations});
}

private getActionPanelItems() {
return [
{
Expand Down
66 changes: 43 additions & 23 deletions src/components/GridItem/GridItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,40 +43,55 @@ class GridItem extends React.PureComponent {

renderOverlay() {
const {overlayControls} = this.props;
const {editMode} = this.context;
const {editMode, editModeAnimation} = this.context;
const isHidden = !editMode || this.props.item.data._editActive;

const {item} = this.props;
const controls = overlayControls && overlayControls[item.type];

return (
<>
<CSSTransition
in={!isHidden}
nodeRef={this.overlayRef}
classNames={b('overlay')}
timeout={300}
unmountOnExit
>
if (editModeAnimation) {
return (
<>
<CSSTransition
in={!isHidden}
nodeRef={this.overlayRef}
classNames={b('overlay')}
timeout={300}
unmountOnExit
>
<div ref={this.overlayRef} className={b('overlay')} />
</CSSTransition>
<CSSTransition
in={!isHidden}
nodeRef={this.controlsRef}
classNames={b('controls')}
timeout={300}
unmountOnExit
>
<OverlayControls
ref={this.controlsRef}
configItem={item}
items={controls}
overlayControls={overlayControls}
className={b('controls')}
/>
</CSSTransition>
</>
);
} else {
return isHidden ? null : (
<>
<div ref={this.overlayRef} className={b('overlay')} />
</CSSTransition>
<CSSTransition
in={!isHidden}
nodeRef={this.controlsRef}
classNames={b('controls')}
timeout={300}
unmountOnExit
>
<OverlayControls
ref={this.controlsRef}
configItem={item}
items={controls}
overlayControls={overlayControls}
className={b('controls')}
/>
</CSSTransition>
</>
);
</>
);
}
}

render() {
Expand All @@ -94,7 +109,7 @@ class GridItem extends React.PureComponent {
noOverlay,
withCustomHandle,
} = this.props;
const {editMode} = this.context;
const {editMode, editModeAnimation} = this.context;
const width = Number.parseInt(style.width, 10);
const height = Number.parseInt(style.height, 10);
const transform = style.transform;
Expand All @@ -120,7 +135,12 @@ class GridItem extends React.PureComponent {
ref={this.props.forwardedRef}
{...reactGridLayoutProps}
>
<div className={b('item', {editMode: editMode && !_editActive && !noOverlay})}>
<div
className={b('item', {
editMode: editMode && !_editActive && !noOverlay,
animate: editModeAnimation,
})}
>
<Item
id={this.props.id}
item={this.props.item}
Expand Down
2 changes: 2 additions & 0 deletions src/hocs/withContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ function useMemoStateContext(props) {
revertToOriginalLayout,
forwardedMetaRef: props.forwardedMetaRef,
draggableHandleClassName: props.draggableHandleClassName,
editModeAnimation: props.editModeAnimation,
}),
[
resultLayout,
Expand All @@ -221,6 +222,7 @@ function useMemoStateContext(props) {
revertToOriginalLayout,
props.forwardedMetaRef,
props.draggableHandleClassName,
props.editModeAnimation,
],
);
}
Expand Down

0 comments on commit ef55821

Please sign in to comment.