Git Product home page Git Product logo

responsive-components's Introduction

Responsive Components

A working implementation of the strategy outlined in the article Responsive Components: a Solution to the Container Queries Problem

View Site

Viewing the Site Locally

The Responsive Components site can be built with Node.js. If you have Node.js installed on your system, you can run the following commands to build and serve a local version.

# Clone the git repository and cd into the cloned directory.
git clone https://github.com/philipwalton/responsive-components.git
cd responsive-components

# Install the dependencies
npm install

# Build and serve the site at http://localhost:8080
npm start

This starts up a local server on port 8080. To view the site in your browser, navigate to http://localhost:8080.

In addition to building the site and serving it locally, this will also listen for any changes and rebuild the site as needed. This allows you to play around with the code, refresh the browser, and see your changes instantly.

responsive-components's People

Contributors

georgecrawford avatar philipwalton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

responsive-components's Issues

hsla vs rgba

Hi Philip!

Why do you prefere use background: hsla(0, 0%, 0%, 0.1) insted of background: rgba(0, 0%, 0%, 0.1) like here? Performance?

Thanks a lot

using the _resize-observer.html with template engines

The strategy of "container requests" using Resize Observer is excellent!

Having studied the repository responsive-components, I assumed that you use the template language Nunjucks. I can not understand how you insert this script in the markup?

script

I do as follows:

project
app | > index.html (compiled)

src | > templates > layout.njk (here I connect the script)
................... parts > resize-observer.njk (script for resizeObserver)

... | > pages > index.njk (page template)

My repository: https://github.com/YuriFedorov/components

layout.njk
add block to end of the page

layout-njk

index.njk
link to the file with the script

index-njk

resize-observer.njk
script from here

resize-observer

Gulp generates error while building:

error

What am I doing wrong? When connecting HTML fragments all is well.

Error while running the project locally

`'serve' errored after 2.41 s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! responsive-components@ start: 'gulp serve'
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the responsive-components@ start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:`

I need to add a condition where the script will not execute

In your script, there is a snippet that searches for elements with the attribute data-observe-resizes:

// Observe all non-custom element containers, i.e. all elements with the
// `data-observe-resizes` attribute. Note: custom element containers
// are observed via the connectedCallback() lifecycle method.

var elements = document.querySelectorAll('[data-observe-resizes]');
for (var element, i = 0; element = elements[i]; i++) {
  ro.observe(element);
}

Is it possible to add such a condition?
If the container with the data-observe-resize attribute is inside the <pre> tags, the script should not run.

I use the SyntaxHighlighter library to style the code examples. I want that in examples there were no classes " SM MD LG XL".

demo

example in VSCode

pre

Using em units

One solution for making this work with different font sizes is to divide the widths by the font size of the root element. The way em media queries work is they are based off of the browser default, regardless of what html element font-size is set to via CSS. So one method is to get the html element's font-size as the default for this division, and then allow the user to override that if they want to.

https://github.com/philipwalton/responsive-components/blob/master/app/templates/_resize-observer.html#L31

if (entry.contentRect.width >= minWidth) {

becomes

// these could be overridable options
const rootFontSize = parseInt(getComputedStyle(document.documentElement).fontSize)
const baseFontSize = 16
// 16 is because that is default in most/all browsers, and most likely the setting when developers get their breakpoint values, but of course it can be overridden if needed
...

if (relativeSize(entry.contentRect.width) >= minWidth) {

...

function relativeSize(value, base) {
    return value * (baseFontSize / rootFontsize)
}

Hopefully that makes sense.. Running the code may make more sense.

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.