npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@hellojh/easy-media-calc

v1.1.3

Published

반응형 스타일링에서 calc를 반복적으로 사용하게 되면 가독성이 떨어집니다. 이 라이브러리는 코드의 양을 줄이고 가독성을 높이기 위하여 만들었습니다. 저는 주로 React styled-components에서 사용합니다.

Downloads

13

Readme

Easy Media Calc

반응형 스타일링에서 calc를 반복적으로 사용하게 되면 가독성이 떨어집니다.
이 라이브러리는 코드의 양을 줄이고 가독성을 높이기 위하여 만들었습니다.
저는 주로 React styled-components에서 사용합니다.

사용하시면 깃허브에 ⭐ 한 번만 눌러주시면 감사하겠습니다!!
오류가 있거나 문의할게 있으면 Issues 혹은 이메일로 연락 부탁드립니다.

사용 예시


// 라이브러리 사용 전
@media (max-width: 1024px) {
    width: calc(100vw * (300/428));
    margin: calc(100vw * (10/428)) calc(100vw * (15/428)) calc(100vw * (20/428)) calc(100vw * (30/428));
    font-size: calc(100vw * (15, 428));
    display:flex;
}

// 라이브러리 사용 후
import { FontSize, Margin, Media, Px, Width } from '@hellojh/easy-media-calc';
const mediaPxMb = 1024;
const mbSize = 428;
.
.
.
${Media(mediaPxMb,[
    Width(400, mbSize),
    Margin(10, 15, 20, 30, mbSize),
    FontSize(15, mbSize),
    "display:flex",
])}

단어는 ";"가 아닌 ","로 처리해야 합니다.
위 코드와 같이 일반 css는 문자열처럼 넣어야 합니다.

최상단에 분기 사이즈를 변수로 지정해두면 나중에 수정을 할 때 용이합니다.

종류


|라이브러리 사용| 출력 코드 | |------|-----| |Media(1024,[]) |@media(max-width: 1024px){} | |Px(100, 428) |calc(100vw * (100/428))| |Width(100, 428)| width:calc(100vw * (100/428));| |Height(100, 428)|height:calc(100vw * (100/428));| |Top(100, 428)|top:calc(100vw * (100/428));| |Bottom(100, 428)|bottom:calc(100vw * (100/428));| |Left(100, 428)|left:calc(100vw * (100/428));| |Right(100, 428)|right:calc(100vw * (100/428));| |FontSize(100, 428)|font-size:calc(100vw * (100/428));| |MT(100, 428)|margin-top:calc(100vw * (100/428));| |MB(100, 428)|margin-bottom:calc(100vw * (100/428));| |ML(100, 428)|margin-left:calc(100vw * (100/428));| |MR(100, 428)|margin-right:calc(100vw * (100/428));| |PT(100, 428)|padding-top:calc(100vw * (100/428));| |PB(100, 428)|padding-bottom:calc(100vw * (100/428));| |PL(100, 428)|padding-left:calc(100vw * (100/428));| |PR(100, 428)|padding-right:calc(100vw * (100/428));| |LineH(100, 428)|line-height:calc(100vw * (100/428));| |BgColor(100, 428)|background-size:calc(100vw*(100/428));| |BgColor(100, 50, 428)|background-size:calc(100vw*(100/428)) calc(100vw*(50/428));|

Margin, Padding

마진과 패딩 같은 경우 축약형을 많이 사용합니다.
확장성을 좋게 하기 위하여 하나의 함수안에서 분기 처리를 하였습니다.

코드는 아래를 참고하시면 됩니다.
margin에서 auto를 사용할 경우 문자열로 auto를 넣으시면 됩니다.

|라이브러리 사용| 출력 코드 | |------|-----| |Margin(100, 50, 100, 50, 428)|margin:calc(100vw * (100/428)) calc(100vw * (50/428)) calc(100vw * (100/428)) calc(100vw * (50/428))| |Margin(100, 50, 100, 428)|margin:calc(100vw * (100/428)) calc(100vw * (50/428)) calc(100vw * (100/428))| |Margin(100, "auto", 100, 428)|margin:calc(100vw * (100/428)) "auto" calc(100vw * (100/428))| |Margin(100, 50, 428)|margin:calc(100vw * (100/428)) calc(100vw * (50/428))| |Margin(100, "auto", 428)|margin:calc(100vw * (100/428)) "auto"| |Padding(100, 50, 100, 50, 428)|padding:calc(100vw * (100/428)) calc(100vw * (50/428)) calc(100vw * (100/428)) calc(100vw * (50/428))| |Padding(100, 50, 100, 428)|padding:calc(100vw * (100/428)) calc(100vw * (50/428)) calc(100vw * (100/428))| |Padding(100, 50, 428)|padding:calc(100vw * (100/428)) calc(100vw * (50/428))|

styled-components 조건문 처리

만약 반응형 분기가 2번있고 조건에 따라 스타일링이 달라진다면 아래 코드와 같이 하시면 됩니다.

import { Media, Width } from '@hellojh/easy-media-calc';
const mediaPxTb = 1000;
const tbSize = 1000;

const mediaPxMb = 500;
const mbSize = 500;
function App() {
  return (
      <Test bool={true}>
        qwe
      </Test>
  );
}

export default App;

const Test = styled.div`
  width: 100vw;
  background-color:slategray;

  ${({bool}) =>
    Media(mediaPxTb,[
      "background-color:slateblue",
      Width(bool?1000:500, tbSize),
    ])
    + 
    Media(mediaPxMb,[
      "background-color:salmon",
      Width(bool?500:250, mbSize),
    ])
  }
`