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

Is is possible to make custom sliders? #94

Closed
joshua7v opened this issue Jan 8, 2020 · 10 comments
Closed

Is is possible to make custom sliders? #94

joshua7v opened this issue Jan 8, 2020 · 10 comments

Comments

@joshua7v
Copy link

joshua7v commented Jan 8, 2020

hi,

currently, with v4, is there a way to build a custom slider which can update the color on wheel properly?
basicly it means can i control the wheel with the api exposed?

maybe write a custom plugin could work, but it feels like not necessary to write a plugin to make it work.

@jaames
Copy link
Owner

jaames commented Jan 8, 2020

What type of slider are you looking to implement? I was considering adding some kind of custom slider support in v5, but I'm not sure how it will work yet.

@joshua7v
Copy link
Author

joshua7v commented Jan 8, 2020

In my case, the slider could be any type.
So, what i need here, is to control the wheel with js, all the sliders are just other components which can listen and emit events.
The built-in sliders aren't customisable, so it would be great to provide such api.

@jaames
Copy link
Owner

jaames commented Jan 8, 2020

If you want to just use iro.js' color wheel and implement your own slider controls, you can use the custom layouts feature to remove all components besides the wheel:

const colorPicker = new iro.ColorPicker({
  ...
  layout: [
    {
      component: iro.ui.Wheel,
      options: {}
    },
  ]
});

And then implement sliders however you'd like...


My plans for 'customisable' sliders in iro.js would be pretty basic. You'd be able to customise the slider gradient and how it handles input changes, kinda like this:

const colorPicker = new iro.ColorPicker({
  ...
  layout: [
    ...
    {
      component: iro.ui.Slider,
      options: {
        ...
        // getGradient takes the current color and returns an array of [offset, color] to be used for drawing the slider gradient
        getGradient(color) {
          return [
            [0, '#fff'],
            [100, '#000']
          ];
        },
        // onChange is called with the current slider value (as a percentage) when it has changed 
        onChange(value, color) {
          // do something with the new slider value
        }
      }
    },
  ]
});

@joshua7v would that cover your needs?

@joshua7v
Copy link
Author

joshua7v commented Jan 9, 2020

@jaames thanks a lot.

My original question is actually perfectly answered by the upper part of your reply.
The issue is I cannot figure out how 😂
Before asking, I'm not even sure is it possible without making a custom plugin.
I read through the docs, but cannot find any event could move the handle programmaticly.

@jaames
Copy link
Owner

jaames commented Jan 9, 2020

@joshua7v I'm not really sure that I understand what you're trying to do?

@joshua7v
Copy link
Author

joshua7v commented Jan 9, 2020

@jaames ok, sorry about that
I just realized how silly i am.
Yeah, no issues any more.
What i'm asking here is already provided by directly set colorPicker.color.hexString.
not colorPicker.color = new iro.Color()

@joshua7v joshua7v closed this as completed Jan 9, 2020
@jaames
Copy link
Owner

jaames commented Jan 9, 2020

Ah, no worries :)

@ile
Copy link

ile commented Sep 22, 2020

Hi,

Did you get around to implement this, @jaames?

I'm looking to create a slider which can be used to create gradient type color combinations, like this:

image

So, the slider would have multiple handles/indexes, with a certain position and value (color/hue).

@jaames
Copy link
Owner

jaames commented Sep 24, 2020

@ile That's a little different, but I think gradient support could be cool, and it would play nicely with iro's multicolor support :) Could you maybe open a new request for that?

@ile
Copy link

ile commented Sep 24, 2020

Hi there, did it here: #134

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

3 participants