New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

tailwindcss-margin-safe

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tailwindcss-margin-safe

Tailwind CSS plugin to generate margin utilities with safe-area-inset.

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
23
Maintainers
1
Weekly downloads
 
Created
Source

Tailwind CSS Margin Safe Plugin

This plugin is based on the tailwindcss framework. Usage is similar to the core margin plugin, but outputs mx-[value]-safe margin, instead of mx-[value].

This packaged is an edited fork from the excellent work at https://github.com/desaintflorent/tailwindcss-padding-safe

Installation

npm install tailwindcss-margin-safe

Usage

// In your Tailwind JS config
{
	plugins: [require("tailwindcss-margin-safe")()]
}

This plugin generates the following utilities:

/* Default rules for browser without max() support same as core margin generated rules */

.m-[value]-safe {
	margin: [value]rem;
}
.my-[value]-safe {
	margin-top: [value]rem;
	margin-bottom: [value]rem;
}
.mx-[value]-safe {
	margin-left: [value]rem;
	margin-right: [value]rem;
}
.mt-[value]-safe {
	margin-top: [value]rem;
}
.mb-[value]-safe {
	margin-bottom: [value]rem;
}
.ml-[value]-safe {
	margin-left: [value]rem;
}
.mr-[value]-safe {
	margin-right: [value]rem;
}

/* Safe area rules for browser with max() support */

@supports (margin: max(0px)) {
	.p-[value]-safe {
		margin-top: max([value]rem, env(safe-area-inset-top));
		margin-bottom: max([value]rem, env(safe-area-inset-bottom));
		margin-left: max([value]rem, env(safe-area-inset-left));
		margin-right: max([value]rem, env(safe-area-inset-right));
	}
	.py-[value]-safe {
		margin-top: max([value]rem, env(safe-area-inset-top));
		margin-bottom: max([value]rem, env(safe-area-inset-bottom));
	}
	.px-[value]-safe {
		margin-left: max([value]rem, env(safe-area-inset-left));
		margin-right: max([value]rem, env(safe-area-inset-right));
	}
	.pt-[value]-safe {
		margin-top: max([value]rem, env(safe-area-inset-top));
	}
	.pb-[value]-safe {
		margin-bottom: max([value]rem, env(safe-area-inset-bottom));
	}
	.pl-[value]-safe {
		margin-left: max([value]rem, env(safe-area-inset-left));
	}
	.pr-[value]-safe {
		margin-right: max([value]rem, env(safe-area-inset-right));
	}
}

Options

It's working out of the box with your current margin options ! ( Pro tip : use purgecss ) But if you need, you can set options in your tailwindcss.js like this :

// In your Tailwind CSS config
theme: {
    marginSafe:{
      margin: {
        '1': '1rem',
      },
      suffix: {
        'notch'
      },
      onlySupportsRules : true
    },
},
variants: {
  marginSafe: [ 'responsive' ],
},

theme.marginSafe.margin is optional and it defaults to theme.margin theme.marginSafe.suffix is optional and it defaults to "safe" theme.marginSafe.onlySupportsRules is optional and it defaults to false variants.marginSafe is optional and it defaults to variants.margin

Use it in your html like this :

<div class="pt-1-safe">Example of block</div>

If you don't want to generate default rules for browser without support for max(), you can set the onlySupportsRules option to true. But then, you will not get any margin for browser without support, so you should add default core margin too :

<div class="pt-1 pt-1-safe">Example of block</div>

Warning

Unitless values inside max() are considered invalid. So if you define custom value in your theme option, keep in mind that you need to use a unit with your value like this :

   '1': '1rem', //not '1': '1'

Or

   '0': '0px', //not '0': '0'

Keywords

tailwindcss

FAQs

Package last updated on 05 Nov 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts