Skip to content

Conversation

obdulia-losantos
Copy link
Contributor

@obdulia-losantos obdulia-losantos commented Apr 7, 2025


name: Replace jscolors with coloris
about: Replace jscolors with coloris library
assignees: fabiocaccamo


Describe your changes
Replaced JSColor library with Coloris

Related issue
#168

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

@fabiocaccamo fabiocaccamo added dependencies Pull requests that update a dependency file enhancement New feature or request labels Apr 7, 2025
@fabiocaccamo fabiocaccamo self-requested a review April 7, 2025 16:36
@fabiocaccamo fabiocaccamo moved this to Todo in Open Source Apr 7, 2025
Copy link

codecov bot commented Apr 7, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 1 line in your changes missing coverage. Please review.

Project coverage is 94.50%. Comparing base (ff121f6) to head (4868c65).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
colorfield/widgets.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #223      +/-   ##
==========================================
+ Coverage   93.67%   94.50%   +0.82%     
==========================================
  Files           8        8              
  Lines         174      182       +8     
==========================================
+ Hits          163      172       +9     
+ Misses         11       10       -1     
Flag Coverage Δ
unittests 94.50% <92.30%> (+0.82%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@obdulia-losantos obdulia-losantos force-pushed the build-coloris branch 2 times, most recently from a156d3d to 9ce1860 Compare April 8, 2025 13:54
@obdulia-losantos obdulia-losantos marked this pull request as draft April 9, 2025 08:37
@fabiocaccamo
Copy link
Owner

@obdulia-losantos thank you for this PR, is there still some work you want to do on it before marking it as ready?

@obdulia-losantos
Copy link
Contributor Author

@obdulia-losantos thank you for this PR, is there still some work you want to do on it before marking it as ready?

Yes, I tested it locally and the swatches were not displayed and the format is always hex with alpha... I think I need to make more adjustments to the library.

@obdulia-losantos obdulia-losantos marked this pull request as ready for review April 11, 2025 12:59
@obdulia-losantos
Copy link
Contributor Author

@fabiocaccamo ready! Sadly I cannot add the example app I used to test it locally. Should I remove that commit?

@obdulia-losantos
Copy link
Contributor Author

@fabiocaccamo any feedback?

@fabiocaccamo fabiocaccamo moved this from Todo to In Progress in Open Source Apr 28, 2025
@obdulia-losantos obdulia-losantos force-pushed the build-coloris branch 6 times, most recently from 1678e76 to 30ad624 Compare April 29, 2025 07:37
@obdulia-losantos
Copy link
Contributor Author

@fabiocaccamo requested changes made

Copy link
Owner

@fabiocaccamo fabiocaccamo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest retouches and it's ready, thanks for your collaboration and patience!

@fabiocaccamo fabiocaccamo merged commit a1b2796 into fabiocaccamo:main Apr 30, 2025
25 of 26 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Open Source Apr 30, 2025
@obdulia-losantos obdulia-losantos deleted the build-coloris branch May 1, 2025 09:09
@dadokkio
Copy link

dadokkio commented May 12, 2025

Yes, I tested it locally and the swatches were not displayed and the format is always hex with alpha... I think I need to make more adjustments to the library.

I've similar issue with new release, there is a different configuration to remove alpha and re-enable swatches?
I tried with:

COLOR_PALETTE = [("#9A6324", "Brown",), ("#e6194B", "Red",),("#3cb44b", "Green", )]
color = ColorField(default=random_color, samples=COLOR_PALETTE, format="hex")

but result is:
image

@fabiocaccamo
Copy link
Owner

@obdulia-losantos the alpha control should not be visible if color format doesn't support alpha, could you double-check it?

@obdulia-losantos
Copy link
Contributor Author

I cannot reproduce the error in the admin page with a form.

I'm seeing that you are using the login page. Could you check if in your template all the scripts are loaded or if there is an error in the browser console?

@dadokkio , @fabiocaccamo

COLOR_PALETTE = [("#9A6324", "Brown",), ("#e6194B", "Red",),("#3cb44b", "Green", )]
color_choices = ColorField(blank=True, choices=COLOR_PALETTE, format="hex")

image

color_samples = ColorField(blank=True, samples=COLOR_PALETTE, format="hex")

image

@dadokkio
Copy link

I've no error in console and the loaded js are:
image

It seems that every time I made a crud request that has a color input a block like this is permanently added to the page:

<div id="clr-picker" class="clr-picker clr-open" style="left: 323.891px; top: 272px; color: rgb(0, 81, 255);"><input id="clr-color-value" name="clr-color-value" class="clr-color" type="text" value="" spellcheck="false" aria-label="Color value field"><div id="clr-color-area" class="clr-gradient" role="application" aria-label="Saturation and brightness selector. Use up, down, left and right arrow keys to select." style=""><div id="clr-color-marker" class="clr-marker" tabindex="0" aria-label="Saturation: 74.5. Brightness: 24." style="color: rgb(16, 30, 61); left: 149px; top: 76px;"></div></div><div class="clr-hue"><input id="clr-hue-slider" name="clr-hue-slider" type="range" min="0" max="360" step="1" aria-label="Hue slider"><div id="clr-hue-marker" style="left: 61.3889%;"></div></div><div class="clr-alpha" style="color: rgb(16, 30, 61);"><input id="clr-alpha-slider" name="clr-alpha-slider" type="range" min="0" max="100" step="1" aria-label="Opacity slider"><div id="clr-alpha-marker" style="color: rgb(16, 30, 61); left: 100%;"></div><span style=""></span></div><div id="clr-format" class="clr-format"><fieldset class="clr-segmented"><legend>Color format</legend><input id="clr-f1" type="radio" name="clr-format" value="hex"><label for="clr-f1">Hex</label><input id="clr-f2" type="radio" name="clr-format" value="rgb"><label for="clr-f2">RGB</label><input id="clr-f3" type="radio" name="clr-format" value="hsl"><label for="clr-f3">HSL</label><span></span></fieldset></div><div id="clr-swatches" class="clr-swatches"></div><button type="button" id="clr-clear" class="clr-clear" aria-label="Clear the selected color">Clear</button><div id="clr-color-preview" class="clr-preview" style="color: rgb(16, 30, 61);"><button type="button" id="clr-close" class="clr-close" aria-label="Close color picker">Close</button></div><span id="clr-open-label" hidden="">Open color picker</span><span id="clr-swatch-label" hidden="">Color swatch</span></div>

So the first time the input is working but with default settings. Then color input in the edit or new panel is not working anymore and multiple dot selector are present in color area (like it's rendered multiple time):
image

So probably the error is related on how the form is loading its js. I'll let you know.

In the admin everything is working properly:
image

@dadokkio
Copy link

dadokkio commented Jul 1, 2025

Sorry for the delay.
as a quick workaround I had to override coloris.js and check in init if the color picker was already been initialized.

  /**
   * Init the color picker.
   */
  function init() {
    picker = document.getElementById("clr-picker");
    if (picker) {
      // If picker exists, just reference UI elements and return
      colorArea = getEl("clr-color-area");
      colorMarker = getEl("clr-color-marker");
      clearButton = getEl("clr-clear");
      closeButton = getEl("clr-close");
      colorPreview = getEl("clr-color-preview");
      colorValue = getEl("clr-color-value");
      hueSlider = getEl("clr-hue-slider");
      hueMarker = getEl("clr-hue-marker");
      alphaSlider = getEl("clr-alpha-slider");
      alphaMarker = getEl("clr-alpha-marker");
      return;
    }
..

In this way all the input works without issue for the single page application.

The only minor issue is that only the first input has the full styling with color on the right then all the other ones have only text value.

But in my case that is better because styled one was not rendered like other form-control on a new line.
[eg here that password input is below text like all the other form fields while color is near on the right]
image

Add comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants