mint icon indicating copy to clipboard operation
mint copied to clipboard

Defining the viewbox property with the SVG directive

Open Vechro opened this issue 3 years ago • 6 comments

One of the only things you can't define in CSS for SVG is the viewbox property. I'd like to request a feature to pass a (perhaps optional) argument to the @svg directive that lets you define the viewbox size.

Vechro avatar Sep 14 '20 07:09 Vechro

We could also allow overwriting, the width and height attributes: https://github.com/mint-lang/mint/blob/master/src/compilers/directives/svg.cr#L18

s0kil avatar Sep 21 '20 05:09 s0kil

Are those three the most important, or should we add all possible <svg> attributes? https://developer.mozilla.org/en-US/docs/Web/SVG/Element/svg#Attributes

It seems these six are the most relevant: preserveAspectRatio, viewBox, height, width, x, y

s0kil avatar Sep 21 '20 05:09 s0kil

Are those three the most important, or should we add all possible <svg> attributes?

Yes we can add other attributes as well, it might come in handy for some use cases.

gdotdesign avatar Sep 21 '20 06:09 gdotdesign

We currently raise an issue, when the width, height, viewBox attributes are not defined on the SVG, is this required?

s0kil avatar Sep 21 '20 12:09 s0kil

We currently raise an issue, when the width, height, viewBox attributes are not defined on the SVG, is this required?

With the current implementation yes they are required because we use them.

I don't see any reason why we could not make them optional (only use them when they are present), and overridable.

I guess I made them required because it is a good practice to have them.

gdotdesign avatar Sep 21 '20 12:09 gdotdesign

const ALERT = @svg(../public/tiger.svg,
  preserveAspectRatio = "xMidYMid meet",
  viewBox = "0 0 100 100",
  width = 100,
  height = 100,
  x = 0,
  y = 0)

s0kil avatar Sep 23 '20 03:09 s0kil