GoogleChromeLabs / houdini.how

A community-driven gathering place for CSS Houdini worklets and resources.
https://houdini.how
Apache License 2.0
152 stars 39 forks source link

Add support steps in config worklets #100

Closed nucliweb closed 3 years ago

nucliweb commented 3 years ago

Motivation

Now, for the properties type number in worklets, we only change the value with default step 1.

Possible solution

Add step as attribute on Demo component, in type number and range.

        <input
          id={id}
          class={CardStyle.inputVal}
          type="number"
          min={definition.range && definition.range[0]}
          max={definition.range && definition.range[1]}
          step={definition?.step ? definition.step : 1}  πŸ‘ˆπŸΌ
          value={value}
          onChange={setValue}
        />

And we can add step on customProps.

  ...
  "customProps": {
    "--static-gradient-direction" : {
      "type": "string",
      "default": "to-top",
      "options": ["to-bottom", "to-top", "to-right", "to-left"]
    },
    "--static-gradient-color" : {
      "type": "color",
      "default": "#ff69b4"
    },
    "--static-gradient-size": {
      "type": "number",
      "default": 2,
      "step": "0.5",   πŸ‘ˆπŸΌ
      "range": [1, 30]
    }
  },
  ...

And add the instruction on CONTRIBUTING file.

  // CSS custom properties used by the worklet:
  "customProps": {
    "<propertyName>" : {
      "type": "number",  // property type (string, number, color, percentage, etc.)
      "default": 30,  // default property value
      "range": [0, 100],  // array of property range
      "step": 0.5 // if type is number you can define the step value (optional, default value is 1)  πŸ‘ˆπŸΌ
      }
      // ...
  },

Demo

steps

I can send a PR to test it in a branch

una commented 3 years ago

I like this solution for optional step count. It will be 1 by default, and if steps is specified, it will be whatever steps means. I'm merging #93 so a PR would be great. We should add "step": 0.05 to parallelowow-probability