Git Product home page Git Product logo

drupal-breakpoints-css's Introduction

Drupal breakpoints to CSS

Drupal Logo

To eliminate the need for different places for breakpoints and only maintain a single source of truth for those, this node_module extracts the breakpoints defined in the currently used Drupal themes breakpoint file and generates grouped customProperties and a separate js object with all necessary parameters.

If the draft @custom-media or PostCSS with Custom Media plugin is already used, media queries can be written with customProperties. So any declaration of media queries within stylesheets is omitted and maintainability is increased.

Installation

Install as a devDependency with yarn or npm like:

yarn add --dev @factorial/drupal-breakpoints-css
# or
npm install --sav-dev @factorial/drupal-breakpoints-css

Configuration

In your themes root folder, besides your already defined breakpoints file from Drupal, add a breakpoints.config.yml configuration file. The following properties are mandatory:

// ./lib/types.d.ts
export interface UserConfig {
  drupal: {
    breakpointsPath: string;
    themeName: string;
  };
  prettier?: {
    configPath: string;
  };
  js?: {
    enabled?: boolean;
    path?: string;
    type?: "commonjs" | "module";
  };
  css?: {
    enabled?: boolean;
    path?: string;
    element?: string;
    customMedia?: boolean;
    customProperty?: boolean;
  };
  options?: {
    mediaQuery?: boolean;
    resolution?: boolean;
    minWidth?: boolean;
    maxWidth?: boolean;
  };
}

Schema Validation

You could validate your configuration files with the help of JSON Schema Store and e.g Visual Studio Code YAML Extension.

Prettier

To respect your local Prettier formatting rules please add the path to the configuration file to prettier.path.

Usage

Just run yarn drupal-breakpoints-css start or npm run drupal-breakpoints-css start. Thats it :)

Examples

# Durpal breakpoints file
theme_name.s:
  label: small
  mediaQuery: "only screen and (max-width: 47.9375rem)"
  weight: 0
  multipliers:
    - 1x
    - 2x
theme_name.md:
  label: medium
  mediaQuery: "only screen and (min-width: 48rem) and (max-width: 63.9375rem)"
  weight: 2
  multipliers:
    - 1x
    - 2x
theme_name.lg:
  label: large
  mediaQuery: "only screen and (min-width: 64rem) and (max-width: 89.9375rem)"
  weight: 3
  group: theme_name.group
  multipliers:
    - 1x
    - 2x
/* Generated CSS file */
@custom-media --Themename-small-mediaQuery (only screen and (max-width: 47.9375rem));
@custom-media --Themename-small-resolution (resolution: 2x);
@custom-media --Themename-small-maxWidth (max-width: 47.9375rem);

:root {
  --ThemeName-small-mediaQuery: "only screen and (max-width: 47.9375rem)";
  --ThemeName-small-resolution: "2x";
  --ThemeName-small-maxWidth: "47.9375rem";
}
// Generated JS file
const BREAKPOINTS = {
  "ThemeName-small-mediaQuery--raw": "only screen and (max-width: 47.9375rem)",
  "ThemeName-small-resolution--raw": "2x",
  "ThemeName-small-resolution": "resolution: 2x",
  "ThemeName-small-maxWidth--raw": "47.9375rem",
  "ThemeName-small-maxWidth": "max-width: 47.9375rem",
};
export default BREAKPOINTS;

Acknowledgements

This Script uses open source software and would not have been possible without the excellent work of the Drupal, Eslint, deepmerge and Prettier teams! Thanks a lot!

Sponsored by

Factorial

drupal-breakpoints-css's People

Contributors

dnnsjrng avatar mvsde avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

drupal-breakpoints-css's Issues

Add runtime dependencies to `dependencies`

The package depends on deepmerge and prettier (v2) but doesn’t add them to dependencies. They’re only in devDependencies.

Both deepmerge and the required prettier version should be added to dependencies so the package no longer relies on consumers to install those packages themselves.

Upgrade to async API

Some methods are already asynchronous. All others should be upgraded as well.

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.