Giter VIP home page Giter VIP logo

Comments (2)

endigo9740 avatar endigo9740 commented on May 16, 2024

Some interesting gotchas with using SVG with an <img> tag, you can't style the interior contents of the SVG this way!

https://css-tricks.com/using-svg/

The problem with both img and background-image…
Is that you don’t get to control the innards of the SVG with CSS like you can with the following two ways. Read on!

I have no idea how I didn't already know this, probably one of those things I've learned but forgot. However, this means the idea of using that method kind of goes out the window.

from skeleton.

endigo9740 avatar endigo9740 commented on May 16, 2024

@niktek @thomasbjespersen

So I came up with a great solution for handling SVGs that I think bridges the best ideas from both Nik and myself.

The notable changes include:

  1. I've introduced a new standardized component called SvgIcon:
    https://github.com/Brain-Bones/skeleton/blob/dev/src/lib/SvgIcon/SvgIcon.svelte
  2. I've bundled all SVG path data into a single definition file called icons.ts:
    https://github.com/Brain-Bones/skeleton/blob/dev/src/lib/SvgIcon/icons.ts
  3. I've updated all instances of SVG icons throughout the project to utilize this new component.

The combines Nik's idea of leaning into a Svelte component, plus my idea of documenting in a single file, while creating a brand new component that follows the Skeleton conventions for props, including passthrough attributes, Tailwind styles, generic styles, and A11y support. Plus icon.ts allows us to add the missing Font Awesome attribution.

Additionally, this can still be used with standard SVG child content - you just drop any any code that would normally live between the <svg>...</svg> tags in as the default slot value.

I've documented the component here:
https://github.com/Brain-Bones/skeleton/blob/dev/src/routes/components/svg-icons/%2Bpage.svelte

Though please note this doc page is currently hidden from the nav bar. I would like to dogfood the component for a bit before we release it to the public. The biggest drawback is the canned set of icons are pretty limited (just what we use in components and docs). However, the ability to build your own is pretty nice. The fact the component comes with default sizes and styling is really nice. Plus there's a default icon shown if you don't provide a name or slot value.

This has been merged into dev if you would like to test it yourselves.

Screen Shot 2022-08-18 at 3 38 10 PM

Screen Shot 2022-08-18 at 3 38 15 PM

from skeleton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.