New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@digitaliseringsbyran/tailwindcss-screens-in-dom

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@digitaliseringsbyran/tailwindcss-screens-in-dom

Expose the active tailwind screen to the DOM.

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

tailwindcss-screens-in-dom

Expose the active tailwind screen (like sm, md) in body:before, allowing you to use the value in Javascript. Read more

Installation

$ npm install @digitaliseringsbyran/tailwindcss-screens-in-dom --save-dev

Usage

Add the plugin to the plugins array in your tailwind config.

plugins: [
  // ...
  require('@digitaliseringsbyran/tailwindcss-screens-in-dom')()
]

Options

You can pass an object to override the default settings.

// Default options

plugins: [
  require('@digitaliseringsbyran/tailwindcss-screens-in-dom')({
    noScreen: 'xs' // Viewports below the smallest defined screen.
  })
]

Access the active screen in Javascript

Accessing the value in plain Javascript is explained here.

React

A example hook that returns the active screen as a string:

useTailwindScreen.js
import { useState, useEffect } from 'react'

export default () => {
  const isClient = typeof window === 'object'

  function getScreen() {
    return window
      .getComputedStyle(document.querySelector('body'), ':before')
      .getPropertyValue('content')
      .replace(/"|'/g, '')
  }

  const initialState = isClient ? getScreen() : ''
  const [screen, setScreen] = useState(initialState)

  useEffect(() => {
    if (!isClient) {
      return false
    }

    function handleResize() {
      setScreen(getScreen())
    }

    window.addEventListener('resize', handleResize)
    return () => window.removeEventListener('resize', handleResize)
  }, [])

  return screen
}
Component
import React from 'react'
import useTailwindBreakpoint from './useTailwindBreakpoint'

const ActiveScreen => {
  const screen = useTailwindBreakpoint()
  
  return (
      <span>{screen}</span>
  )
}

export default ActiveScreen

Keywords

FAQs

Package last updated on 15 Aug 2019

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc