0.4.3 • Published 3 years ago

k2-media v0.4.3

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

K2-Media

A small library containing a collection of CSS3 media queries curated for use in SASS, and JavaScript (React, React/Typescript or any CSS-in-JS implementation).

The breakpoints used are based on the post "Media Queries for Standard Devices" by CSS Tricks.

Table of Contents

Getting Started

Install via npm:

npm install k2-media --save

Alternatively via yarn:

yarn add k2-media

How to use

React/JavaScript

  1. Use media (Object: IMedia) for set breakpoints

    Popular breakpoints covered media (IMedia):

    NameBreakpoint (px)Devices
    screenMd< 1200pxSmaller PCS & laptops
    tablet< 1025px (<=1024px)iPads, 8"+ Android Tablets
    screenSm< 992pxSmall tablets
    screenXs< 768px (<=767px)iPad Portrait, Standard mobile phones

    Tablet only breakpoints under media: IMedia:

    NameBreakpoint (px)Devices
    allTablets< 1281px (>169 dpi)All tablets (and smartphones) irrespective of viewport width. Unlike tablet this takes the DPI into consideration
    tabletLandscape< 1025px (<=1024px)All tablets (and smartphones) in landscape orientation
    tabletPortrait< 768pxAll tablets (and smartphones) in portrait orientation

    Less common breakpoints covered under media: IMedia:

    NameBreakpoint (px)Devices
    screenLg> 1200pxStandard PCs, laptops
    screenXxs< 481pxSmaller mobile phone screens
    screenXxs< 481pxSmaller mobile phone screens
    screenXxs< 481pxSmaller mobile phone screens
    import { media } from 'k2-media';
    
    /* in css */
    `
    width: 20%;
    
    ${ media.screenMd }{
        width: 25%;
    }
    
    ${ media.tablet }{
        width: 33%;
    }
    
    ${ media.screenSm }{
        width: 50%;
    }
    
    ${ media.screenXs }{
        width: 100%;
    }
    `
  2. For greater flexibility, use respondMax: Function, respondMin: Function or respond: Function

  • respondMax( maxWidth: string )

    import { respondMax } from 'k2-media';
    
    /* in css */
    `
    background: #f0f0f0;
    
    ${ respondMax('1000px') }{
        background: #f7f7f7;
    }
    `
  • respondMin( minWidth: string )

    import { respondMin } from 'k2-media';
    
    /* in css */
    `
    background: #f0f0f0;
    
    ${ respondMin('550px') }{
        background: #f7f7f7;
    }
    `
  • respond( minWidth: string, maxWidth: string )

    import { respond } from 'k2-media';
    
    /* in css */
    `
    background: #f0f0f0;
    
    /* styles will only be applied within these 2 breakpoints */
    ${ respond('500px','1000px') }{
        background: #f7f7f7;
    }
    `
  1. Use IMediaIos (Object: IMediaIos) for iOs only breakpoints (iOs Safari compatible)

    NameBreakpoint (px)Devices
    iPad> 767px && <1024pxall iPads (landscape or portrait)
    iPadLandscape> 767px && <1024pxall iPads (landscape)
    iPadPortrait> 767px && <1024pxall iPads (portrait)
    iPadFirst> 767px && <1024px1st Gen iPads, non-retina (landscape or portrait)
    iPadFirstLandscape> 767px && <1024px1st Gen iPads, non-retina (landscape)
    iPadFirstPotrait> 767px && <1024px1st Gen iPads, non-retina (portrait)
    iPadFirstPotrait> 767px && <1024px1st Gen iPads, non-retina (portrait)
    iPadMini> 767px && <1024pxiPadMini (landscape or portrait)
    iPadMiniLandscape> 767px && <1024pxiPadMini (landscape)
    iPadMiniPortrait> 767px && <1024pxiPadMini (portrait)
    iPadRetina> 767px && <1024pxiPad, retina screen (landscape or portrait)
    iPadRetinaLandscape> 767px && <1024pxiPad, retina screen (landscape)
    iPadRetinaPortrait> 767px && <1024pxiPad, retina screen (portrait)
    iPhone>= 320px && <481pxall iPhones (landscape or portrait)
    iPhoneFirst>= 320px && <481px1st Gen iPhone (landscape or portrait)
    iPhoneFirstLandscape>= 320px && <481px1st Gen iPhone (landscape)
    iPhoneFirstPortrait>= 320px && <481px1st Gen iPhone (portrait)
    iPhone4>= 320px && <480pxiPhone4 (landscape or portrait)
    iPhone5>= 320px && <568pxiPhone5 (landscape or portrait)
    iPhone5Landscape>= 320px && <568pxiPhone5 (landscape)
    iPhone5Portrait>= 320px && <568pxiPhone5 (portrait)
    iPhone6> 375px && <667pxiPhone6 (landscape or portrait)
    iPhone6Landscape> 375px && <667pxiPhone6 (landscape)
    iPhone6Portrait> 375px && <667pxiPhone6 (portrait)
    iPhone6Plus> 414px && <736pxiPhone6 Plus (landscape or portrait)
    iPhone6PlusLandscape> 414px && <736pxiPhone6 Plus (landscape)
    iPhone6PlusPortrait> 414px && <736pxiPhone6 Plus (portrait)
```
import { mediaIos } from 'k2-media';

/* in css */
`
display: flex;
    ${ mediaIos.screenMd }{
        display: inline-flex;
    }
`
```

SASS

TBD

Changelog

Version 0.4.0

  • :memo: Added docs
0.4.3

3 years ago

0.4.2

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.2.0-beta3

6 years ago

0.2.0-beta2

6 years ago

0.2.0-beta1

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago