1.0.3 • Published 1 year ago

ngx-resize-directive v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

NgxResizeDirective

An Angular directive to make any HTML element resizeable by dragging on its sides or corners. Fully compatible with CDK Drag and Drop, making it easy to create a resizable and dragabble component.

Designed to be a drop-in solution for resizable components, yet customizable.

Install

npm install ngx-resize-directive

In your global styles.scss add:

@import url("node_modules/ngx-resize-directive/styles/ngx-resize-directive.style.scss");

Import the NgxResizeDirectiveModule module.

Usage

<div resizable>Resizable</div>

Combine with CDK Drag and Drop

<div
  resizable
  cdkDrag
  #resize="resizeDir"
  [cdkDragFreeDragPosition]="{ x: resize.newPosX, y: resize.newPosY }"
> </div>

Watch out! The lines

  #resize="resizeDir"
  [cdkDragFreeDragPosition]="{ x: resize.newPosX, y: resize.newPosY }"

are mandatory to notify the cdkDrag directive about any repositioning done by top-to-bottom or left-to-right resizing.

Properties

Property          Default ValueDescription                                                                                                                                                                                                                                                                                                                                                                    
resizeHandleTag        ALL_HANDLES  A list of the resize handles to create. Valid elements are: 'top','bottom','right','left','cornerSe','cornerNw','cornerSw','cornerNe'                                                                                                                                                                                                          
resizeApplyChanges      true          The directive applies the resize to the host element by changing the height and width style properties, and applies reposition by changing the transform style property. In case an other approach is necessary, this property can be set to false and the changes can be implemented by the user, reacting to the resize and reposition events emitted by the directive.
resizeApplyReposition  true          The application of reposition on top-to-bottom or left-to-right resize can be disabled separatley.                                                                                                                                                                                                                                                                            
resizeRootElementundefined    This is analogous to the cdkDrag cdkDragRootElement Selector that will be used to determine the root draggable element, starting from the resizable element and going up the DOM. Passing an alternate root element is useful when trying to enable resize on an element that you might not have access to.                                                          
resizeBoundry    undefined    This is analogous to the cdkDrag cdkDragBoundary Selector that will be used to determine the element to which the resizable position and size will be constrained. It'll be matched starting from the element's parent and going up the DOM until a match has been found.                                                                                              
resizeDisable    false        Disable all resize                                                                                                                                                                                                                                                                                                                                                            
resizeDisableTags      []            List of tags of handles to disable. Valid values are the same as for resizeHandleTag                                                                                                                                                                                                                                                                                              

Events

Event                Type                                    Description                                                                                                    
resizeWidth          {diff: number;    newWidth: number;  }On horizontal resize, emits the amount of resize and the new width                                            
resizeHeight        {diff: number;    newWidth: number;  }On vertical resize, emits the amount of resize and the new width                                              
repositionHorizontal{diff: number;    newPosX: number;  }  On left-to-right resize, emits the amount of reposition (same as the amount of resize) and the new X transform
repositionVertical  {diff: number;    newPosY: number;  }  On top-to-bottom resize, emits the amount of reposition (same as the amount of resize) and the new Y transform
resizeStart          MouseEvent                              Emits the mouse down event that starts a resize                                                                
resizeEnd            MouseEvent                              Emits the mouse up event that ends a resize                                                                    

Public fields

Field  Description
newPosXContains the X transformation after the last resize event. This field is public for easier integration with CDK Drag (see Combine with CDK Drag and Drop)
newPosYContains the Y transformation after the last resize event. This field is public for easier integration with CDK Drag (see Compbine with CDK Drag and Drop)

Styling

Style class  Component
.resizable-containerIs added to all containers with the resizable directive
.resize-handleAll side and corner resize handles
.resize-handle-topTop resize handle
.resize-handle-bottomBottom resize handle
.resize-handle-rightRight resize handle
.resize-handle-leftLeft resize handle
.resize-handle-corner-neTop-right corner resize handle
.resize-handle-corner-nwTop-left corner resize handle
.resize-handle-corner-seBottom-right corner resize handle
.resize-handle-corner-swBottom-left corner resize handle
1.0.2

1 year ago

1.0.1

1 year ago

1.0.3

1 year ago

1.0.0

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago