npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@v3layout/vue-resizable

v0.0.2

Published

Vue resizable component

Downloads

59

Readme

Vue3 Resizable

✨ Features

  • Compatibility: Compatible with server-rendered apps, PC, and mobile devices.

  • Resizable Component: Allows elements to be resized with optional constraints. It supports the following features:

    • Customizable axis of resizing (x, y, or both).
    • Optional locking of aspect ratio.
    • Minimum and maximum size constraints.
    • Customizable handles for resizing, including the ability to use custom Vue components or functions as handles.
    • Integration with a draggable component (DraggableCore) for smooth resizing.
    • Emits events for resize start, resize, and resize stop, allowing for custom logic and integration.
    • Supports transform scale adjustments, useful for elements within transformed parents.
  • ResizableBox Component: A higher-level component that wraps the Resizable component, providing a simpler interface for common use cases. It includes:

    • All features of the Resizable component.
    • Direct control over the size of the box through reactive state, automatically updating the size during resize actions.
    • Easy integration with slots to place custom content inside the resizable box.
    • Predefined styles for immediate use, with the option to override or extend these styles via props.

Quick Start

Step 1: Installation

First, you need to install the package. Run the following command in your project directory:

npm install @v3layout/vue-resizable

or if you prefer using Yarn:

yarn add @v3layout/vue-resizable

or if you prefer using Pnpm:

pnpm add @v3layout/vue-resizable

Step 2: Importing

In your Vue component, import @v3layout/vue-resizable:

import { ResizableBox, Resizable } from "@v3layout/vue-resizable";

Step 3: Using @v3layout/vue-resizable

Now, you can use the Draggable component in your Vue application. Wrap any element with <Draggable> to make it draggable:

<template>
  <ResizableBox className="box" :width="200" :height="200">
    <span class="text">I can now resize the box</span>
  </ResizableBox>
</template>

<script>
import { ResizableBox } from "@v3layout/vue-resizable";

export default {
  components: {
    ResizableBox,
  },
};
</script>

<style></style>

Step 4: Enjoy!

That's it! You've successfully integrated resizable functionality into your Vue application. Customize it further according to your needs.

A simple component for making elements resizable box.

<ResizableBox className="box" :width="200" :height="200">
  <span class="text">{{"<ResizableBox>"}}</span>
</ResizableBox>

<Resizable>

const {Resizable} = require('@v3layout/vue-resizable');

// ES6
import { Resizable } from '@v3layout/vue-resizable';

const Example = defineComponent({
  const state = reactive({
    width: 200,
    height: 200
  });
  setup () {
    const onResize = (event, {node, size, handle}) => {
    state.width = size.width
    state.height = size.height
    };
    return () => (
      <Resizable height={this.state.height} width={this.state.width} fnResize={this.onResize}>
        <div className="box" style={{width: this.state.width + 'px', height: this.state.height + 'px'}}>
          <span>Contents</span>
        </div>
      </Resizable>
    )
  }
})

<ResizableBox>

const {ResizableBox} = require('@v3layout/vue-resizable');

// ES6
import { ResizableBox } from '@v3layout/vue-resizable';

const Example = defineComponent({
  const state = reactive({
    width: 200,
    height: 200
  });
  setup () {
    const onResize = (event, {node, size, handle}) => {
    state.width = size.width
    state.height = size.height
    };
    return () => (
      <ResizableBox width={200} height={200} draggableOpts={{grid: [25, 25]}}
          minConstraints={[100, 100]} maxConstraints={[300, 300]}>
        <span>Contents</span>
      </ResizableBox>
    )
  }
})

Props

These props apply to both <Resizable> and <ResizableBox>. Unknown props that are not in the list below will be passed to the child component.

type ResizeCallbackData = {
  node: HTMLElement,
  size: {width: number, height: number},
  handle: ResizeHandleAxis
};
type ResizeHandleAxis = 's' | 'w' | 'e' | 'n' | 'sw' | 'nw' | 'se' | 'ne';

type ResizableProps {
    axis: 'both' | 'x' | 'y' | 'none' = 'both',
    className?: string,
    draggableOpts?: Object,
    handle?: ((resizeHandleAxis: ResizeHandleAxis) => VNode) | VNode,
    handleSize: [number, number],
    lockAspectRatio: boolean,
    minConstraints: [number, number],
    maxConstraints: [number, number],
    fnResizeStop?: (e: Event, data: ResizeCallbackData) => void,
    fnResizeStart?: (e: Event, data: ResizeCallbackData) => void,
    fnResize?: (e: Event, data: ResizeCallbackData) => void,
    resizeHandles: ResizeHandleAxis[],
    transformScale: number,
    width: number,
    height: number,
    hoverHandles?: boolean
  }

The following props can also be used on <ResizableBox>:

{
  style?: Object
}

If a width or height is passed to <ResizableBox>'s style prop, it will be ignored as it is required for internal function.

Resize Handle

If you override the resize handle, we expect that any ref passed to your new handle with represent the underlying DOM element.

This is required, as vue-resizable must be able to access the underlying DOM node to attach handlers and measure position deltas.

There are a few ways to do this:

Native DOM Element

This requires no special treatment.

<Resizable handle={<div class="foo" />} />
Custom Function

You can define a function as a handle, which will simply receive an axis (see above ResizeHandleAxis type) and ref. This may be more clear to read, depending on your coding style.

const MyHandle = (props) => {
  return <div ref={props.innerRef} className="foo" {...props} />;
};

<Resizable
  handle={(handleAxis, ref) => (
    <MyHandle
      innerRef={ref}
      className={`foo handle-${handleAxis}`}
      {...props}
    />
  )}
/>;