No More Posting New Topics!

If you have a question or an issue, please start a thread in our Github Discussions Forum.
This forum is closed for new threads/ topics.

Navigation

    Quasar Framework

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to match a string to a color?

    Help
    3
    6
    150
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wpq last edited by

      I have tags (via q-badge) that I would like to automatically color, ideally in a predictable way.

      Right now I have a fixed color for all the tags and their number will change dynamically. I have a vague idea about how to manage this non-predictably (somehow get the list of colors, shuffle it and while I am building my list of tags, pop a color and attach it to the definition).

      I would love to have a way to give a HEX value to a tag (I found a way to do “string → hash → set of 3 hex values”), but it seems that this is not possible?

      I metalsadman 2 Replies Last reply Reply Quote 0
      • I
        Ilia @wpq last edited by

        @wpq Generally,
        Every HEX colour can be converted to decimal meaning that you can map your number range to the colours range, that would be the best way to go.

        hex #000000 - #ffffff
        decimal 0 - 16777216

        Of course, you can convert hex to decimal and vice-versa 🙂

        That’s what I would play with if you are talking about the dynamic numbers.

        Another idea would be to utilize numbers Quasar has (like grey-1 to grey-14, orange-1 to orange-14, etc.)

        W 1 Reply Last reply Reply Quote 0
        • metalsadman
          metalsadman @wpq last edited by metalsadman

          @wpq checkout color utils, you can make your own color brands programmatically https://quasar.dev/quasar-utils/color-utils#Introduction.

          W 1 Reply Last reply Reply Quote 0
          • W
            wpq @Ilia last edited by

            @ilia said in How to match a string to a color?:

            That’s what I would play with if you are talking about the dynamic numbers.

            Thanks - but is there a way to use these numbers? (this is exactly what I was intending to do, just did not find where to actually plus the hex - all I found are the pre-configured colors)

            I 1 Reply Last reply Reply Quote 0
            • W
              wpq @metalsadman last edited by

              @metalsadman said in How to match a string to a color?:

              you can make your own color brands programmatically

              Yes, but in that case, I would need to programmatically ass CSS styles (because my colors are generated from the names of the tags)

              1 Reply Last reply Reply Quote 0
              • I
                Ilia @wpq last edited by

                @wpq You have a range between 0 and 16777216, map these to your numbers (like multiply by some constant number or use any other formula you would like) and then convert the computed number to hex code. Then, just add style=“background-color: #computed-hex” on that tag.

                ** you can map hex directly, but would require some extra coding.

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post