Git Product home page Git Product logo

Comments (7)

atomiks avatar atomiks commented on May 15, 2024 2

Example: circle.md

The code that is actually displayed on the website is within <style>, notice, it's namespaced with .snippet-demo__ so the styles don't conflict with the global ones or other snippets.

I'm suggesting to autoscope the selectors during the build script and forget about manually creating a demo -- the demo is created via the build script using the actual code.

Current

Snippet creator manually creates the demo, repeating code

#### Demo

<div class="snippet-demo">
  <div class="snippet-demo__circle"></div>
</div>

<style>
.snippet-demo__circle {
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  background: #333;
}
</style>

New

The build script does it using the actual code within the blocks automatically.

#### Demo
<!-- Leave this blank, the build script will generate the demo -->

Generated demo

<div class="snippet-demo" data-scope="circle">
  <div class="circle"></div>
</div>

<!-- Not sure how to do this reliably -->
<style>
[data-scope="circle"] .circle {
  border-radius: 50%;
  width: 2rem;
  height: 2rem;
  background: #333;
}
</style>

Any suggestions on how to do this efficiently would be nice.

from 30-seconds-of-css.

atomiks avatar atomiks commented on May 15, 2024 2

It may be better to generate a SCSS or .less string and pass it to the parse for output because then you merely need to wrap the style with the namespace selector and it should do it for you.

Yeah I was thinking this. I thought a smart parser would be needed because my quick tries with regex were failing.

But with SCSS you can just stick everything inside a single block and it works. It shouldn't be too hard to convert the SCSS to CSS with the script.

from 30-seconds-of-css.

skatcat31 avatar skatcat31 commented on May 15, 2024

I may be misunderstanding you, but won't generating a custom scope for the styles just repeat the code itself anyways? Or are you suggesting we move the namespacing chore to the build script?

from 30-seconds-of-css.

skatcat31 avatar skatcat31 commented on May 15, 2024

prepend any CSS selector with a data scope selector?

The problem is that to understand this, the design needs to account for complex cases with several classes in the code. It may be better to generate a SCSS or .less string and pass it to the parse for output because then you merely need to wrap the style with the namespace selector and it should do it for you.

Less and SCSS generators can also be used to generate a giant demo CSS too which may be helpful instead so that the CSS loads with the page, and the demo html gets styled at render so that demo blocks don't need a style tag.

from 30-seconds-of-css.

skatcat31 avatar skatcat31 commented on May 15, 2024

either that or less, both will namespace inside the single block very similarly. It should be pretty easy and regex should be minimal. Gotta love those build tools right?

from 30-seconds-of-css.

atomiks avatar atomiks commented on May 15, 2024

Resolved in #103

from 30-seconds-of-css.

lock avatar lock commented on May 15, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for any follow-up tasks.

from 30-seconds-of-css.

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.