0.4.33 • Published 6 months ago

mimic-css v0.4.33

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

MIMIC CSS

A design system that allows the use of standard CSS styles within the class attribute ALONG with Media Queries and Modifiers.

Advantages:

  1. No need to learn MAGIC utility names for existing CSS Styles
  2. Grow your CSS knowledge while reaping the rewards of using a Design System at the same time

Write standard CSS (No spaces though!) such as display:flex and apply a media query inline within the class

Example

<div class="large?display:flex">Some Text</div>

Generates the below class ensuring that the flex container is only applied when the screen size is greater than 1280px wide

@media (min-width: 1280px) {
  .large\?display\:flex {
    display: flex;
  }
}

Media BreakPoints

Design System

To ensure consistency there is a set of standard Tags that can be used in place of specific pixel values.

These Tags are used across the board keeping the learning curve simple

TagDescription
xsextra small
smsmall
mdmedium
lglarge
xlextra large
2xlextra extra large
<div class="padding-top:md">Some Text</div>

becomes

.padding-top\:md {
  padding-top: 8px;
}

These Tags will map to different Pixel Values depending upon the usage.

So for Fonts we have the below mapping:

TagValue
xs8px
sm12px
md16px
lg24px
xl48px
2xl92px

Whereas for Padding the mappings will be different:

TagValue
xs2px
sm4px
md8px
lg20px
xl50px
2xl200px

And then for Line height they map to percentages

TagValue
xs100%
sm120%
md140%
lg160%
xl200%
2xl240%

An example for Padding

<div class="padding-top:md">Some Text</div>

becomes

.padding-top\:md {
  padding-top: 8px;
}

And then for Font Size you will see

<div class="font-size:md">Some Text</div>
.font-size\:md {
  font-size: 16px;
}

Normal CSS will remain unchanged (bar a space inserted)

So the below:

<div class="display:flex">Some Text</div>

Becomes:

.display\:flex {
  display: flex;
}

Pseudo Classes

You can also apply pseudo class like hover and focus inline with the class attribute

<div class="background-color:blue:hover">Some Text</div>

Which will create a class for you like this

.background-color\:blue\:hover:hover {
  background-color: blue;
}

Custom Classes

To create a class in place we can use the @ symbol to combine css into a class

<div class="padding:xl@btn border-radius:md@btn btn"></div>

Generated css for the above will be:

.btn {
  padding: 50px;
  border-radius: 10px;
}

Install:

npm install --save-dev mimic-css

mimic-css is a development time process that watches for file changes to your web pages and create classes from them.

Usage

npx mimic

The app will search in the current folder (and all subfolders) for .html, .ts, .js and .astro files. Ouput will be sent to the file mimic.css which you can link:

<link rel="stylesheet" href="mimic.css" />

You can override where to base your scan for web pages using the -i flag

npx mimic-css -i ./src

You can also override where to output the generated CSS file using the -o flag

npx mimic-css -o ./styles/customname.css

Command Line Arguments

optionDefaultAlias
-i./input
-o./mimic.cssoutput
-e<N/A>exclude
-l<N/A>lit

Configuration 'mimic.config.mjs'

Customisation can be applied within a file named 'mimic.config.mjs'

Overriding Files to Search

By default mimic-css will search ".html", ".js", ".astro", ".ts" files for classes to process

So to also search jsx files in addition to the defaults we would create the below:

let config;

export default config = {
  extensions: [".html", ".js", ".astro", ".ts", ".jsx"],
};

Color Palettes

There are 4 built in Color Palettes each of which can be customised

color_palette_1 = {
  c1a: "#222831",
  c1b: "#393E46",
  c1c: "#00ADB5",
  c1d: "#EEEEEE",
};

color_palette_2 = {
  c2a: "#FFC7C7",
  c2b: "#FFE2E2",
  c2c: "#F6F6F6",
  c2d: "#8785A2",
};

color_palette_3 = {
  c3a: "#B7C4CF",
  c3b: "#EEE3CB",
  c3c: "#D7C0AE",
  c3d: "#967E76",
};

color_palette_4 = {
  c4a: "#F9ED69",
  c4b: "#F08A5D",
  c4c: "#B83B5E",
  c4d: "#6A2C70",
};

Overriding Line Height Snapping

let config;

export default config = {
  extensions: [".html"],
  lineHeightSnapping: {
    xs: "60%",
    sm: "120%",
    md: "140%",
    lg: "160%",
    xl: "200%",
    xl2: "240%",
  },
};

Overriding Media Breakpoints

To change the pixel values for each of the media breakpoints specify the new values in the 'mediaBreakPointsValueOverride' object of the mimic.config.js file. No need to add the 'px' suffix here as this will automatically be added by mimic-css for us.

Example:

let config;

export default config = {
  mediaBreakPointsValueOverride: {
    extrasmall: "1000",
    small: "1010",
    medium: "1020",
    large: "1030",
    extralarge: "1040",
  },
};

Overriding Media Tags

To change the text that is used to specify a Media breakpoint use the 'MediaBreakPointsTextOverride' object in the mimic.config.js file

Example:

let config;

export default config = {
  MediaBreakPointsTextOverride: {
    extrasmall: "xsmall",
    small: "sm",
    medium: "normal",
    large: "big",
    extralarge: "vbig",
  },
};

Overriding Snapping Tags

To change the text that is used on the snapping tags use the 'SnappingOverride' object in the mimic.config.js file.

  SnappingOverride: {
    xs: "xsmall",
    sm: "small",
    md: "medium",
    lg: "big",
    xl: "verybig",
    xl2: "crazybig",
  },

Creating Classes

To create a class in place we can use the @ symbol to combine css into a class

<div class="padding:xl@btn border-radius:md@btn btn"></div>

Generated css for the above will be:

.btn { padding: 50px; border-radius: 10px; }

Specify folders to exclude

Lit Integration

To include CSS in LitElements a good approach to take is Constructable Style Sheets. These require the CSS to be in a JS string and mimic-css provide this output in the file mimic.css.js for us when using the -l flag.

The generated file can be imported to a LitElement using the below syntax

import { TWStyles } from "../styles/mimic.css.js";

export class Header extends
  LitElement { static styles = [css``, TWStyles];
0.4.31

6 months ago

0.4.32

6 months ago

0.4.30

6 months ago

0.4.33

6 months ago

0.4.28

6 months ago

0.4.29

6 months ago

0.4.26

6 months ago

0.4.27

6 months ago

0.4.9

10 months ago

0.4.8

10 months ago

0.3.0

10 months ago

0.3.6

10 months ago

0.3.5

10 months ago

0.3.8

10 months ago

0.3.7

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.4.20

9 months ago

0.4.21

9 months ago

0.4.24

9 months ago

0.4.25

9 months ago

0.4.22

9 months ago

0.4.23

9 months ago

0.4.19

9 months ago

0.4.10

9 months ago

0.4.17

9 months ago

0.4.18

9 months ago

0.4.15

9 months ago

0.4.16

9 months ago

0.4.13

9 months ago

0.4.14

9 months ago

0.4.11

9 months ago

0.4.12

9 months ago

0.4.5

10 months ago

0.4.4

10 months ago

0.4.7

10 months ago

0.4.6

10 months ago

0.4.1

10 months ago

0.4.0

10 months ago

0.4.3

10 months ago

0.1.9-alpha

10 months ago

0.0.91-alpha

1 year ago

0.0.98-alpha

11 months ago

0.0.99-alpha

11 months ago

0.1.8-alpha

10 months ago

0.0.86-alpha

1 year ago

0.1.1-alpha

10 months ago

0.0.92-alpha

1 year ago

0.0.90-alpha

1 year ago

0.0.85-alpha

1 year ago

0.0.93-alpha

1 year ago

0.1.0-alpha

10 months ago

0.1.3-alpha

10 months ago

0.1.10-alpha

10 months ago

0.1.6-alpha

10 months ago

0.1.13-alpha

10 months ago

0.0.95-alpha

1 year ago

0.1.12-alpha

10 months ago

0.1.5-alpha

10 months ago

0.0.83-alpha

1 year ago

0.0.89-alpha

1 year ago

0.0.96-alpha

1 year ago

0.1.11-alpha

10 months ago

0.1.14-alpha

10 months ago

0.1.4-alpha

10 months ago

0.1.7-alpha

10 months ago

0.0.94-alpha

1 year ago

0.0.84-alpha

1 year ago

0.0.97-alpha

1 year ago

0.2.1

10 months ago

0.2.0

10 months ago

0.0.87-alpha

1 year ago

0.2.6

10 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.5

10 months ago

0.2.4

10 months ago

0.0.80-alpha

1 year ago

0.0.82-alpha

1 year ago

0.0.81-alpha

1 year ago

0.0.78-alpha

1 year ago

0.0.79-alpha

1 year ago

0.0.77-alpha

1 year ago

0.0.75-alpha

1 year ago

0.0.69-alpha

1 year ago

0.0.76-alpha

1 year ago

0.0.72-alpha

1 year ago

0.0.70-alpha

1 year ago

0.0.73-alpha

1 year ago

0.0.74-alpha

1 year ago

0.0.71-alpha

1 year ago

0.0.68-alpha

1 year ago

0.0.67-alpha

1 year ago

0.0.63-alpha

1 year ago

0.0.66-alpha

1 year ago

0.0.65-alpha

1 year ago

0.0.64-alpha

1 year ago

0.0.58-alpha

1 year ago

0.0.60-alpha

1 year ago

0.0.59-alpha

1 year ago

0.0.62-alpha

1 year ago

0.0.61-alpha

1 year ago

0.0.55-alpha

1 year ago

0.0.47-alpha

1 year ago

0.0.43-alpha

1 year ago

0.0.49-alpha

1 year ago

0.0.46-alpha

1 year ago

0.0.56-alpha

1 year ago

0.0.52-alpha

1 year ago

0.0.42-alpha

1 year ago

0.0.50-alpha

1 year ago

0.0.45-alpha

1 year ago

0.0.48-alpha

1 year ago

0.0.53-alpha

1 year ago

0.0.51-alpha

1 year ago

0.0.41-alpha

1 year ago

0.0.57-alpha

1 year ago

0.0.54-alpha

1 year ago

0.0.44-alpha

1 year ago

0.0.40-alpha

1 year ago

0.0.39-alpha

1 year ago

0.0.35-alpha

1 year ago

0.0.38-alpha

1 year ago

0.0.37-alpha

1 year ago

0.0.36-alpha

1 year ago

0.0.34-alpha

1 year ago

0.0.30-alpha

1 year ago

0.0.32-alpha

1 year ago

0.0.33-alpha

1 year ago

0.0.29-alpha

1 year ago

0.0.31-alpha

1 year ago

0.0.28-alpha

1 year ago

0.0.27-alpha

1 year ago

0.0.25-alpha

1 year ago

0.0.26-alpha

1 year ago

0.0.23-alpha

1 year ago

0.0.24-alpha

1 year ago

0.0.21-alpha

1 year ago

0.0.22-alpha

1 year ago

0.0.20-alpha

1 year ago

0.0.15-alpha

1 year ago

0.0.19-alpha

1 year ago

0.0.10-alpha

1 year ago

0.0.11-alpha

1 year ago

0.0.9-alpha

1 year ago

0.0.14-alpha

1 year ago

0.0.18-alpha

1 year ago

0.0.12-alpha

1 year ago

0.0.17-alpha

1 year ago

0.0.13-alpha

1 year ago

0.0.16-alpha

1 year ago

0.0.8-alpha

1 year ago

0.0.7-alpha

1 year ago

0.0.6-alpha

1 year ago

0.0.5-alpha

1 year ago

0.0.4-alpha

1 year ago

0.0.2-alpha

1 year ago

0.0.1-alpha

1 year ago