Can the RangeControl component be set to range between decimals?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I am building (and learning as I go) a hero image block for Gutenberg. I am following a tutorial on it, and it works fine so far.
But I want to use a RangeControl component (in the Gutenberg Editor Inspector Controls), to control the opacity of a hero overlay. That also works, but can only set a range with integers (ie from 1 to 10). Is it possible to use decimals instead (so the range will be 0.0 to 1.0) ?
Of course I can use integers and convert them to decimals afterwards, but it is not the best UX.



I use the (very fine) create-guten-block boilerplate, and here is the code for the block (NOTE: I am aware that I haven't completed the save() method yet!):



block.js



registerBlockType('configit-blocks/hero', {
title: 'Hero Image',
icon: 'format-image',
category: 'common',
attributes: {
textString: {
type: 'array',
source: 'children',
selector: 'h2',
},
fontColor: {
type: 'string',
default: 'black'
},
overlayOpacity: {
type: 'decimalPoint',
default: 0.0
}
},

edit(props) {

const {
setAttributes,
attributes,
className,
focus
} = props;
const { fontColor } = props.attributes;
const { overlayOpacity } = props.attributes;

function onTextChange(changes) {
setAttributes({
textString: changes
});
}

function onTextColorChange(changes) {
setAttributes({
fontColor: changes
})
}
function onOverlayOpacity(changes) {
setAttributes({
overlayOpacity: changes
})
}

return ([
<InspectorControls>
<div>
<strong>Select a font color:</strong>

<ColorPalette
value={fontColor}
onChange={onTextColorChange}
/>
</div>
<div>
<RangeControl
label="Overlay Opacity"
value={ overlayOpacity }
onChange={ onOverlayOpacity }
min={ 0.0 }
max={ 1.0 }
/>
</div>
</InspectorControls>,
<div className={className}
style={{
backgroundImage: `url('http://placehold.it/1440x700')`,
backgroundSize: 'cover',
backgroundPosition: 'center'
}}>

<div className="overlay" />
<RichText
tagName="h2"
className="content"
value={attributes.textString}
onChange={onTextChange}
placeholder="Enter your text here!"
style={{color: fontColor}}
allowReset={false}
/>
</div>
]);
},

save(props) {

const { attributes, className } = props;
const { fontColor } = props.attributes;

return (
<div className={className}
style={{
backgroundImage: "url('http://placehold.it/1440x700')",
backgroundSize: "cover",
backgroundPosition: "center"
}}>

<div className="overlay"/>
<h2 className="content" style={{color: fontColor}}>{attributes.textString}</h2>
</div>
);
}


} );










share|improve this question





























    0















    I am building (and learning as I go) a hero image block for Gutenberg. I am following a tutorial on it, and it works fine so far.
    But I want to use a RangeControl component (in the Gutenberg Editor Inspector Controls), to control the opacity of a hero overlay. That also works, but can only set a range with integers (ie from 1 to 10). Is it possible to use decimals instead (so the range will be 0.0 to 1.0) ?
    Of course I can use integers and convert them to decimals afterwards, but it is not the best UX.



    I use the (very fine) create-guten-block boilerplate, and here is the code for the block (NOTE: I am aware that I haven't completed the save() method yet!):



    block.js



    registerBlockType('configit-blocks/hero', {
    title: 'Hero Image',
    icon: 'format-image',
    category: 'common',
    attributes: {
    textString: {
    type: 'array',
    source: 'children',
    selector: 'h2',
    },
    fontColor: {
    type: 'string',
    default: 'black'
    },
    overlayOpacity: {
    type: 'decimalPoint',
    default: 0.0
    }
    },

    edit(props) {

    const {
    setAttributes,
    attributes,
    className,
    focus
    } = props;
    const { fontColor } = props.attributes;
    const { overlayOpacity } = props.attributes;

    function onTextChange(changes) {
    setAttributes({
    textString: changes
    });
    }

    function onTextColorChange(changes) {
    setAttributes({
    fontColor: changes
    })
    }
    function onOverlayOpacity(changes) {
    setAttributes({
    overlayOpacity: changes
    })
    }

    return ([
    <InspectorControls>
    <div>
    <strong>Select a font color:</strong>

    <ColorPalette
    value={fontColor}
    onChange={onTextColorChange}
    />
    </div>
    <div>
    <RangeControl
    label="Overlay Opacity"
    value={ overlayOpacity }
    onChange={ onOverlayOpacity }
    min={ 0.0 }
    max={ 1.0 }
    />
    </div>
    </InspectorControls>,
    <div className={className}
    style={{
    backgroundImage: `url('http://placehold.it/1440x700')`,
    backgroundSize: 'cover',
    backgroundPosition: 'center'
    }}>

    <div className="overlay" />
    <RichText
    tagName="h2"
    className="content"
    value={attributes.textString}
    onChange={onTextChange}
    placeholder="Enter your text here!"
    style={{color: fontColor}}
    allowReset={false}
    />
    </div>
    ]);
    },

    save(props) {

    const { attributes, className } = props;
    const { fontColor } = props.attributes;

    return (
    <div className={className}
    style={{
    backgroundImage: "url('http://placehold.it/1440x700')",
    backgroundSize: "cover",
    backgroundPosition: "center"
    }}>

    <div className="overlay"/>
    <h2 className="content" style={{color: fontColor}}>{attributes.textString}</h2>
    </div>
    );
    }


    } );










    share|improve this question

























      0












      0








      0


      1






      I am building (and learning as I go) a hero image block for Gutenberg. I am following a tutorial on it, and it works fine so far.
      But I want to use a RangeControl component (in the Gutenberg Editor Inspector Controls), to control the opacity of a hero overlay. That also works, but can only set a range with integers (ie from 1 to 10). Is it possible to use decimals instead (so the range will be 0.0 to 1.0) ?
      Of course I can use integers and convert them to decimals afterwards, but it is not the best UX.



      I use the (very fine) create-guten-block boilerplate, and here is the code for the block (NOTE: I am aware that I haven't completed the save() method yet!):



      block.js



      registerBlockType('configit-blocks/hero', {
      title: 'Hero Image',
      icon: 'format-image',
      category: 'common',
      attributes: {
      textString: {
      type: 'array',
      source: 'children',
      selector: 'h2',
      },
      fontColor: {
      type: 'string',
      default: 'black'
      },
      overlayOpacity: {
      type: 'decimalPoint',
      default: 0.0
      }
      },

      edit(props) {

      const {
      setAttributes,
      attributes,
      className,
      focus
      } = props;
      const { fontColor } = props.attributes;
      const { overlayOpacity } = props.attributes;

      function onTextChange(changes) {
      setAttributes({
      textString: changes
      });
      }

      function onTextColorChange(changes) {
      setAttributes({
      fontColor: changes
      })
      }
      function onOverlayOpacity(changes) {
      setAttributes({
      overlayOpacity: changes
      })
      }

      return ([
      <InspectorControls>
      <div>
      <strong>Select a font color:</strong>

      <ColorPalette
      value={fontColor}
      onChange={onTextColorChange}
      />
      </div>
      <div>
      <RangeControl
      label="Overlay Opacity"
      value={ overlayOpacity }
      onChange={ onOverlayOpacity }
      min={ 0.0 }
      max={ 1.0 }
      />
      </div>
      </InspectorControls>,
      <div className={className}
      style={{
      backgroundImage: `url('http://placehold.it/1440x700')`,
      backgroundSize: 'cover',
      backgroundPosition: 'center'
      }}>

      <div className="overlay" />
      <RichText
      tagName="h2"
      className="content"
      value={attributes.textString}
      onChange={onTextChange}
      placeholder="Enter your text here!"
      style={{color: fontColor}}
      allowReset={false}
      />
      </div>
      ]);
      },

      save(props) {

      const { attributes, className } = props;
      const { fontColor } = props.attributes;

      return (
      <div className={className}
      style={{
      backgroundImage: "url('http://placehold.it/1440x700')",
      backgroundSize: "cover",
      backgroundPosition: "center"
      }}>

      <div className="overlay"/>
      <h2 className="content" style={{color: fontColor}}>{attributes.textString}</h2>
      </div>
      );
      }


      } );










      share|improve this question














      I am building (and learning as I go) a hero image block for Gutenberg. I am following a tutorial on it, and it works fine so far.
      But I want to use a RangeControl component (in the Gutenberg Editor Inspector Controls), to control the opacity of a hero overlay. That also works, but can only set a range with integers (ie from 1 to 10). Is it possible to use decimals instead (so the range will be 0.0 to 1.0) ?
      Of course I can use integers and convert them to decimals afterwards, but it is not the best UX.



      I use the (very fine) create-guten-block boilerplate, and here is the code for the block (NOTE: I am aware that I haven't completed the save() method yet!):



      block.js



      registerBlockType('configit-blocks/hero', {
      title: 'Hero Image',
      icon: 'format-image',
      category: 'common',
      attributes: {
      textString: {
      type: 'array',
      source: 'children',
      selector: 'h2',
      },
      fontColor: {
      type: 'string',
      default: 'black'
      },
      overlayOpacity: {
      type: 'decimalPoint',
      default: 0.0
      }
      },

      edit(props) {

      const {
      setAttributes,
      attributes,
      className,
      focus
      } = props;
      const { fontColor } = props.attributes;
      const { overlayOpacity } = props.attributes;

      function onTextChange(changes) {
      setAttributes({
      textString: changes
      });
      }

      function onTextColorChange(changes) {
      setAttributes({
      fontColor: changes
      })
      }
      function onOverlayOpacity(changes) {
      setAttributes({
      overlayOpacity: changes
      })
      }

      return ([
      <InspectorControls>
      <div>
      <strong>Select a font color:</strong>

      <ColorPalette
      value={fontColor}
      onChange={onTextColorChange}
      />
      </div>
      <div>
      <RangeControl
      label="Overlay Opacity"
      value={ overlayOpacity }
      onChange={ onOverlayOpacity }
      min={ 0.0 }
      max={ 1.0 }
      />
      </div>
      </InspectorControls>,
      <div className={className}
      style={{
      backgroundImage: `url('http://placehold.it/1440x700')`,
      backgroundSize: 'cover',
      backgroundPosition: 'center'
      }}>

      <div className="overlay" />
      <RichText
      tagName="h2"
      className="content"
      value={attributes.textString}
      onChange={onTextChange}
      placeholder="Enter your text here!"
      style={{color: fontColor}}
      allowReset={false}
      />
      </div>
      ]);
      },

      save(props) {

      const { attributes, className } = props;
      const { fontColor } = props.attributes;

      return (
      <div className={className}
      style={{
      backgroundImage: "url('http://placehold.it/1440x700')",
      backgroundSize: "cover",
      backgroundPosition: "center"
      }}>

      <div className="overlay"/>
      <h2 className="content" style={{color: fontColor}}>{attributes.textString}</h2>
      </div>
      );
      }


      } );







      wordpress-gutenberg






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 16 '18 at 13:55









      Jeppe RJeppe R

      63




      63
























          0






          active

          oldest

          votes












          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339258%2fcan-the-rangecontrol-component-be-set-to-range-between-decimals%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53339258%2fcan-the-rangecontrol-component-be-set-to-range-between-decimals%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          List item for chat from Array inside array React Native

          Thiostrepton

          Caerphilly