hiendv / octicons-modular

GitHub Octicons with tree-shaking support and icon-per-file style.
MIT License
24 stars 10 forks source link

Allow to set float number as scale value #30

Closed ghost closed 7 years ago

ghost commented 7 years ago

Icon scales to the default value when I set scale between 0 and 1.

alert.svg({ scale: .5 })

I think, the issue is here:

  // any icon source file generated from icon.hbs template
  ...
  attrScale (attrs, scale) {
    let actualScale = scale === 0 ? 0 : parseInt(scale) || 1 // ?
    attrs['width'] = actualScale * parseInt(attrs['width'])
    attrs['height'] = actualScale * parseInt(attrs['height'])
    delete attrs['scale']
  },
  ...

For example:

parseInt(.6) // returns 0
parseInt(1.99) // returns 1

I'm already fix it in my forked repository: link If my solution is right, it may be able to pull request. All icon sources was rebuilt using the new template on fix-float-sclae branch.

ghost commented 7 years ago

P.S Icon scales too large if scale value is less than 0: demo

hiendv commented 7 years ago

Working on this.

hiendv commented 7 years ago

@andpawlenko Please fire your PR to fix this :+1:

hiendv commented 7 years ago

@andpawlenko Regarding your second concern, it's a normal behavior. Without specifying width and height while the viewBox attribute presents, an SVG will scale to their container size. SVGs are fluid.

ghost commented 7 years ago

@hiendv so, the issue may be closed I think :+1:

hiendv commented 7 years ago

@andpawlenko Could you provide some tests with floats for your changes. Thank you!

ghost commented 7 years ago

@hiendv okay, wait for pull request

hiendv commented 7 years ago

@andpawlenko Love it!