-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(screens): initialise package #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. | ||
|
||
## 0.0.1-alpha.0 (2021-10-12) | ||
|
||
|
||
### Features | ||
|
||
* **screens:** initialise package ([8fd9526](https://github.com/limbo-works/limbo-frontend/commit/8fd952690db59071f4560c3f10291ad3e497c7d6)), closes [#1](https://github.com/limbo-works/limbo-frontend/issues/1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# `@limbo-works/screens` | ||
|
||
> A tool for parsing TailwindCSS `screens` from the standard Limbo breakpoint | ||
> format (as well as a helpful `breakpoints` object) | ||
|
||
## Installation | ||
|
||
Before installing the package, it's necessary to configure NPM with a GitHub | ||
[Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) | ||
(PAT) with the `read:packages` scope. | ||
|
||
Using your PAT, configure the `.npmrc` in the root of the project like so | ||
_before_ running the install command:- | ||
|
||
```npmrc | ||
//npm.pkg.github.com/:_authToken=${PAT} | ||
@limbo-works:registry=https://npm.pkg.github.com | ||
``` | ||
|
||
Install the package:- | ||
|
||
```shell | ||
$ yarn add @limbo-works/screens | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
// ~/frontend/assets/js/screens.js | ||
|
||
const { default: configure } = require('@limbo-works/screens'); | ||
|
||
const { breakpoints, screens } = configure([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. breakpoints and screens can be a bit confusing for people not familiar with tailwind screens. This can be alright as long as the docs show an example. (minor) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrote a comment on #1, but much to the same point - maybe naming of properties should be more explicit, like Don't know if But yeah, a lot can be explained through documentation as well. Though it will at to code readability, which is nice. |
||
{ value: 375, max: true }, | ||
{ value: 768, max: true }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we name this more explicitly? max could be confused(by me) to be something else. |
||
1024, | ||
1440, | ||
1920, | ||
]); | ||
|
||
module.exports = { breakpoints, screens }; | ||
``` | ||
|
||
```js | ||
// ~/tailwind.config.js | ||
|
||
const { screens } = require('./frontend/assets/js/screens.js'); | ||
|
||
module.exports = { | ||
themes: { | ||
screens, | ||
}, | ||
}; | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
presets: ['@babel/preset-env'], | ||
plugins: ['@babel/plugin-transform-runtime'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "@limbo-works/screens", | ||
"version": "0.0.1-alpha.0", | ||
"description": "A tool for parsing TailwindCSS `screens` from the standard Limbo breakpoint format (as well as a helpful `breakpoints` object)", | ||
"author": "Saul Hardman <sha@limbo.works>", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "ssh://git@github.com/limbo-works/limbo-frontend.git", | ||
"directory": "packages/screens" | ||
}, | ||
"publishConfig": { | ||
"registry": "https://npm.pkg.github.com/" | ||
}, | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.es.mjs", | ||
"files": [ | ||
"dist/*", | ||
"src/**/*.js" | ||
], | ||
"scripts": { | ||
"clean": "rimraf dist/", | ||
"build": "yarn clean && cross-env NODE_ENV=production rollup --config ../../rollup.config.js" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
export default (values, rootFontSize = 16) => | ||
values.reduce(({ screens = {}, breakpoints = {} }, value) => { | ||
const { value: px, min: hasMin = true, max: hasMax = false } = | ||
typeof value === 'number' ? { value } : value ?? {}; | ||
|
||
if (!px) { | ||
throw new Error(`\`value\` required: ${value}`); | ||
} | ||
|
||
const em = px / rootFontSize; | ||
const min = `${em}em`; | ||
const max = `${em - 0.01}em`; | ||
|
||
return { | ||
screens: { | ||
...screens, | ||
|
||
...(hasMin ? { [`>=${px}`]: min } : {}), | ||
|
||
...(hasMax ? { [`<${px}`]: { max } } : {}), | ||
}, | ||
|
||
breakpoints: { | ||
...breakpoints, | ||
|
||
[`${px}`]: { px, em, min, max }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. breakpoints always include max. I think this is fine, as it'll be used with js and we might need this without a css breakpoint. (very minor) |
||
}, | ||
}; | ||
}, {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Will our freelancers be able to do this?