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

force update of color object #29

Closed
dasDaniel opened this issue Dec 15, 2016 · 7 comments
Closed

force update of color object #29

dasDaniel opened this issue Dec 15, 2016 · 7 comments

Comments

@dasDaniel
Copy link

Is there a way to update the color externally?

@lumberman
Copy link

Looking forward to have this feature as well.

@AleksanderGrzybowski
Copy link

Is there any way to do this? I am making some forms with color input from the user, and it seems there is no way to set the color from the outside. Very good plugin, but this is just strange.

@maxcelos
Copy link

Same problem here...

@lumberman
Copy link

@xiaokaike can you please introduce publicly accessible colorChange method or any other way for us to hard refresh the current color values? Something similar to what you have in EditableInput.vue. Any help or hack in this direction will greatly help us.

Thank you!

@lumberman
Copy link

If it's not possible or hard to do, can we at least have component re-fresh method? This way we can at least re-render component with updated color form outside.

@lumberman
Copy link

lumberman commented May 31, 2017

Looks like I found a solution!

Color picker will not respond if you change any color model other than hex and opacity. If I change color like this in my methods it will update the color picker properly:

<input
	type="text"
	v-model="colorValue"
	v-on:keyup="updateColor" >

methods: {
	updateColor() {
		let newAlpha = 1
		let newColor = {
			hex: this.colorValue,
			a: newAlpha
		}

		this.colors = newColor
	}
}

Again colorValue (from the input field) should be in HEX format #aabbcc. In my app I use RGBA, so it requires an extra conversion from RGBA to HEX to make it work (I don't show it here for simplicity).

Good luck with your projects!

@linx4200
Copy link
Collaborator

linx4200 commented Jan 30, 2018

Actually, when initialize colors, can just pass hex or rgba or hsl or hsv:

new Vue({
  el: '#app',
  components: {
    'photoshop-picker': photoshop
  },
  data () {
    return {
      colors: {
        h: 50,
        s: 0.5,
        l: 0.2
      }
    }
  },
})

or

new Vue({
  el: '#app',
  components: {
    'photoshop-picker': photoshop
  },
  data () {
    return {
      colors: '#ff0000'
    }
  },
})

etc.

Then you can also update hsl and it will re-render component(s).

updateColor() {
  this.colors = {
    h: 100,
    s: 0.5,
    l: 0.2
  }
}

Please be aware that you must change the whole colors. It would not take any effect by this.colors.h = 100.

I will update the README in the next release.

Thanks.

linx4200 added a commit that referenced this issue Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants