1.3.2 • Published 6 years ago

fish-tacos v1.3.2

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Fish Tacos :tropical_fish: :fish: :blowfish:

What

This module complements the react and styled-components libraries to create an API that removes the cognitive load and arduous boilerplate associated with responsive scenarios.

Build Status npm version

depends on styled-components typescript code style prettier

commitizen friendly semantic-release

Why

Setting a min-width and max-width on your elements is a great way to create fluid layouts that adhere to responsive methodologies.

Unfortunately min-* and max-* declarations are not supported natively in CSS for things like font-size, padding, margin, etc. These properties would benefit greatly from this functionality to help make content more accessible to a wider range of device sizes.

This module addresses the scenarios where:

  • Users can experience jarring layout reflows as various breakpoints are triggered forcing abrupt changes to CSS values.

  • Percentage based values (referencing things like viewport or an element container) can encounter cases where values scale to exaggerated limits (both big and small) due to the absence of Minimum and Maximum thresholds.

Demo

This demo retro fits several Bootstrap components with the fluid resizing system this module offers. Resize the window to see the responsive measurement declarations scale up / down while staying within the limits of their thresholds.

fish-tacos

Installation

Install the module from NPM .

npm install --save fish-tacos

Import the module into your project.

import ft from "fish-tacos";

Usage

The API is very simple. Specify the CSS property that you want to change and supply a Minimum and Maximum threshold to restrict scaling.

Because designers like to supply their measurements in pixel based units our API uses pixels as the base target and converts them into REM's in the final output. This gives styles an enhanced level of accessibility (with dynamic font scaling) while making design and development collaboration easier.

The result is pure, static CSS. This means the fluid scaling is based on native browser functionality and therefore performant.

Basic

ft("font-size", [20, 32]);

The above declaration will create the following vanilla CSS:

font-size: 1.25rem;

@media (min-width: 30rem) {
  font-size: 4.166666666666667vw;
}

@media (min-width: 48rem) {
  font-size: 2rem;
}

Verbose

If you want to target a property that uses top, right, bottom and left references for more granularity you can use the more verbose permutation below.

ft("margin", { top: [30, 60], bottom: [10, 30] });

The above declaration will create the following vanilla CSS:

margin-top: 1.875rem;

@media (min-width: 30rem) {
  margin-top: 6.25vw;
}

@media (min-width: 60rem) {
  margin-top: 3.75rem;
}

margin-bottom: 0.625rem;

@media (min-width: 30rem) {
  margin-bottom: 2.0833333333333335vw;
}

@media (min-width: 90rem) {
  margin-bottom: 1.875rem;
}

Static

As of release 1.2.0 you can now pass in a static number or string and have it be included as a non-fluid measurement :smiley:.

  • String: Will be included verbatim.
  • Number: Should be supplied as a pixel reference and will be converted to REM's.
ft("margin", { top: 50, right: "auto", bottom: 20, left: "auto" });

The above declaration will create the following vanilla CSS:

margin-top: 3.125rem;

margin-right: auto;

margin-bottom: 1.25rem;

margin-left: auto;

Consolidation

As of release 1.3.0 you can now consolidate verbose references that share the same values into a single declaration by comma separating their keys :thumbsup:.

ft("margin", { "top,bottom": [20, 50], "right,left": "auto" });

The above declaration will create the following vanilla CSS:

margin-top: 1.25rem;

@media (min-width: 30rem) {
  margin-top: 4.166666666666667vw;
}

@media (min-width: 75rem) {
  margin-top: 3.125rem;
}

margin-bottom: 1.25rem;

@media (min-width: 30rem) {
  margin-bottom: 4.166666666666667vw;
}

@media (min-width: 75rem) {
  margin-bottom: 3.125rem;
}

margin-right: auto;

margin-left: auto;

Example

Integrating this module into your existing workflow is as easy as swapping out a standard CSS property / value declaration for the new API.

import React from "react";
import ReactDOM from "react-dom";
import styled from "styled-components";
import ft from "fish-tacos";

const Heading1 = styled.h1`
  ${ft("font-size", [30, 50])}
  ${ft("margin", { top: [30, 60], "right,left": "auto", bottom: 20 })};
`;

ReactDOM.render(
  <Heading1>Hello World 👋</Heading1>,
  document.getElementById("app")
);

License

MIT

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago