styled-px2vw-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

styled-px2vw-plugin

Extension of styled-components with features for convert px to vw units.

based on styled-px2vw

Installation

yarn:

yarn add styled-px2vw-plugin

npm:

npm i styled-px2vw-plugin -S
import styled, { initStyledConfig } from 'styled-px2vw-plugin';
// 初始化配置设计稿宽度、过滤属性 (可选)
initStyledConfig({ viewportWidth: 750, ignoreAttrs: ['font-size', /.*font-size.*/] });

// 默认值
{
  viewportWidth: 750,
  ignoreAttrs: ['font-size'],
}

from

import styled from 'styled-components';

const TestDiv = styled.div`
  height: 100%;
  font-size: 24px;
  padding: 0 20px;
  a {
    color: white;
  }
  @media screen and (min-width: ${() => 900 + 'px'}) {
    width: 900px;
  }
`;

to

import styled from 'styled-px2vw';

const TestDiv = styled.div`
  height: 100%;
  font-size: 24px;
  padding: 0 20px; /** px2vw_ignore */
  padding: 0 20px;
  a {
    color: white;
  }
  @media screen and (min-width: ${() => 900 + 'px /** px2vw_ignore */'}) {
    width: 900px; /** px2vw_ignore */
  }
`;

output

converted

Package Sidebar

Install

npm i styled-px2vw-plugin

Weekly Downloads

15

Version

1.0.1

License

MIT

Unpacked Size

9.95 kB

Total Files

6

Last publish

Collaborators

  • wwilll