Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/screens/CHANGELOG.md
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)
54 changes: 54 additions & 0 deletions packages/screens/README.md
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
Copy link
Member

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?

[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([
Copy link
Member

Choose a reason for hiding this comment

The 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)

Copy link
Member

Choose a reason for hiding this comment

The 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 twScreens or something similar as suggested on the issue?

Don't know if breakpoints should be renamed to breakpointData or rawBreakpointData or something like that as well, or if breakpoints covers it well enough (very minor). But the tailwind specification would at the very least be nice.

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 },
Copy link
Member

Choose a reason for hiding this comment

The 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.
"includeMaxWidth" or maybe "includeMaxScreen" since breakpoints always has both (minor)

1024,
1440,
1920,
]);

module.exports = { breakpoints, screens };
```

```js
// ~/tailwind.config.js

const { screens } = require('./frontend/assets/js/screens.js');

module.exports = {
themes: {
screens,
},
};
```
4 changes: 4 additions & 0 deletions packages/screens/babel.config.js
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'],
};
28 changes: 28 additions & 0 deletions packages/screens/package.json
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"
}
}
29 changes: 29 additions & 0 deletions packages/screens/src/index.js
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 },
Copy link
Member

Choose a reason for hiding this comment

The 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)

},
};
}, {});
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export default [
'@babel/preset-env',
{
targets: [
'node >= 14',
'node >= 10',
'last 2 chrome version',
'last 2 firefox versions',
'last 2 safari versions',
Expand Down Expand Up @@ -104,7 +104,7 @@ export default [
[
'@babel/preset-env',
{
targets: 'node >= 14',
targets: 'node >= 10',
},
],
],
Expand Down