CSS variables
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
A really nice feature of some libraries I've used in the past is the ability to link JavaScript properties to CSS variables.
For example, data-flux="flux-pointer" will expose --flux-pointer-x and --flux-pointer-y relative to the container, for use within CSS. They will be scalar values from 0 to 1 so calc() can be used to transform them to any other type, such as %.
CSS variables to implement:
flux-pointerwill give the--flux-pointer-xand--flux-pointer-yvariables of the inner-most container they're found on.flux-pointer-globalwill give the--flux-pointer-global-xand--flux-pointer-global-yvariables of the screen, wherever they're used.flux-sizewill give the--flux-size-xand--flux-size-yvariables of the inner-most container they're found on.flux-visiblewill give the--flux-visiblevariable a value of1if the element is visible in its viewport, and0when not. You can use this to control the opacity, for example, withselector { opacity: calc(0.25 + var(--flux-visible) * 0.75); }so it fades as the page scrolls.flux-first-visiblewill give the--flux-first-visiblevariable a value of1when the element becomes visible for the first time, and it will never reset to0. You can use it in the same kind ofcalcasflux-visiblebut this time it will never fade out when reversing the scroll direction, for example.flux-rangewill give the--flux-rangevariable a value between0and1depending on the value of the first<input type="range" />found as a child.flux-selectwill find the first<select>element, and if the<option>values are numeric, the selected option will be given to the--flux-selectvariable.flux-colorwill find the first<input type="color" />child and the selected hex value will be given to the--flux-colorvariable. This can be manipulated with CSS's color functions to automate colour schemes by rotating hues, saturations, etc.flux-fieldwill find the first<input />or<textarea>and give the following variables:--flux-field-lengthfor the number of characters entered,--flux-field-emptyas0for content,1for no content,--flux-field-validand--flux-field-invalidboth 0 and 1 but inverse of each other,--flux-field-remainingfor the number of remaining characters ifmaxlengthis supplied, and--flux-field-filled-scalaras the scalar value between 0 and 1 for how many characters are available beforemaxlengthis hit, and--flux-field-too-shortas 1 if theminlengthfield is supplied, and--flux-field-pattern-errorif thepatterndoes not validate. There are also stateful variables:--flux-field-dirtyas 1 if the value has changed, even if they changed it back to the original, or the opposite--flux-field-clean;--flux-field-touchedfor 1 if there has ever been focus, or the opposite--flux-field-untouched; or--flux-field-changedfor 1 if the value is different, or the opposite--flux-field-unchanged.flux-formwill find the first<form>child and give the following variables:--flux-form-field-countthe total number of validatable fields are within the form;--flux-form-valid-countthe number of fields withwillvalidateas true;--flux-form-invalid-countthe number of fields withwillvalidateas false;--flux-form--all-valid1 if all fields are considered valid;--flux-form-valid-scalaras a value between 0 and 1 expressing the amount of valid fields divided by the total.flux-palettewill find the first<img>or<video>child, and give the following variables:--flux-palettea hex of the dominant colour, the mode average colour;--flux-palette-accentthe most vibrant hex code in the image/video;--flux-palette-darkthe darkest colour in the image that isn't black;--flux-palette-lightthe lightest colour in the image that isn't black;--flux-palette-averagethe mean colour;--flux-palette-tempfrom -1 (cool) to 1 (warm) how blue or red the image isflux-truncatedis applied to the actual element, and will give the following variables:--flux-truncated1 if there is any content truncated text,--flux-truncated-x1 if there is any content truncated in the X axis,--flux-truncated-y1 if there is any content truncated in the Y axis.
When I say "will find the first X child", the flux-* attribute can be added to a container, or the element itself.
To keep things performant, any "live" property updates do not need to be performed while the element is not visible - for example, while the element has been scrolled out of view, it doesn't need to continue receiving pointer updates.
Because CSS cascades, only children of the elements the attributes are added to will be affected. If you want a --flux-* variable to be available to another element's tree, add the data-flux attribute value of (flux-pointer,flux-size@footer>.some-selector). Inside the brackets, list the flux attributes that are required to be connected, followed by an at character, followed by the selector(s) that will receive these variables.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source file, test, or entry point is named. Start by locating the existing handling for data-flux attributes and scope one variable family before addressing the broader list. Done should include the specified CSS variables, visibility-aware live updates, and coverage for the relevant element and child-selection behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100