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

(Suggestion) addWidget to accept object instead of bunch of parameters #907

Closed
n1ghtie opened this issue Jun 1, 2018 · 3 comments
Closed

Comments

@n1ghtie
Copy link

n1ghtie commented Jun 1, 2018

Hi, first of all THANK YOU for amazing plugin, loving it so far.
Working on a project that allows to create custom dashboards and need to create widgets dynamically (grid-stack-items).
I would be great that instead of putting each parameters separately, maybe to do an object so addWidget would look like this?

var options = {
    x: 10,
    y: 10,
    width: 5,
    height: 5,
    ...
}
addWidget(el, options);

Why? Well lets say that if i want to have min-height, with current structure I need to supply min-width and max-width, and i don't really want that.

@kylehovey
Copy link

kylehovey commented Aug 18, 2018

In the mean time, here is a snippet that I use in my code:

const genId = () => Math.random().toString(36).substr(2, 9);

const widget = stack => ({
  id = genId(),
  element,
  xPos = 0,
  yPos = 0,
  width = 1,
  height = 1,
  minWidth = 0,
  maxWidth = 10,
  minHeight = 0,
  maxHeight = 10,
  autoPos = false
} = {}) => stack.addWidget(
  element,
  xPos,
  yPos,
  width,
  height,
  autoPos,
  minWidth,
  maxWidth,
  minHeight,
  maxHeight,
  id
);

Usage:

const constructWidget = widget(stack);
constructWidget({ width : 2, height : 2, autoPos : true });

@adumesny
Copy link
Member

@n1ghtie I agree. We should add it soon.

@adumesny
Copy link
Member

in the upcoming 0.5.2 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants