{"id":24187756,"url":"https://github.com/emilmalanczak/spacing-util","last_synced_at":"2025-03-03T02:24:11.132Z","repository":{"id":57366865,"uuid":"431950874","full_name":"EmilMalanczak/spacing-util","owner":"EmilMalanczak","description":"Spacing util for css-in-js solutions","archived":false,"fork":false,"pushed_at":"2021-11-30T17:59:37.000Z","size":216,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-22T20:34:41.033Z","etag":null,"topics":["css-in-js","spacing","theming","typescript","util"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EmilMalanczak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-25T19:04:21.000Z","updated_at":"2023-03-09T01:19:27.000Z","dependencies_parsed_at":"2022-08-23T19:40:37.101Z","dependency_job_id":null,"html_url":"https://github.com/EmilMalanczak/spacing-util","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":"ryansonshine/typescript-npm-package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilMalanczak%2Fspacing-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilMalanczak%2Fspacing-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilMalanczak%2Fspacing-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EmilMalanczak%2Fspacing-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EmilMalanczak","download_url":"https://codeload.github.com/EmilMalanczak/spacing-util/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241597344,"owners_count":19988232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["css-in-js","spacing","theming","typescript","util"],"created_at":"2025-01-13T13:36:01.756Z","updated_at":"2025-03-03T02:24:11.099Z","avatar_url":"https://github.com/EmilMalanczak.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# spacing-util\n\n[![npm package][npm-img]][npm-url]\n[![Build Status][build-img]][build-url]\n[![Issues][issues-img]][issues-url]\n[![Code Coverage][codecov-img]][codecov-url]\n[![Commitizen Friendly][commitizen-img]][commitizen-url]\n[![Semantic Release][semantic-release-img]][semantic-release-url]\n\nA simple library agnostic util functions for `css-in-js` styling solutions to make your design spacing consistent\n\n## Install\n\n```bash\nnpm install spacing-util\n```\n\n## Motivation\n\n---\n\nNot every single UI library has its own `theme` or if does it might lack of `spacing` system that might fit your needs.\n\n`spacing-util` is built in customizable way to allow you create your own spacing system which can work even if your library doesn't allow rewriting/extending their theme.\n\n\u0026nbsp;\n\n## Features\n\n---\n\n\u0026nbsp;\n\n## _Spacing_\n\nSpacing usage is mentioned to be mainly used for `padding` and `margin` properties. That's why it's usage is similar to CSS syntax - you can pass up to 4 properties which will be calculated by `parser` function.\n\nPassing argument different than `number` returns it **without** any transform.\n\nDefault parser function multiplies given argument by `4` and returns as `px` unit.\n\n### Example usage\n\n```ts\nimport { spacing } from 'spacing-util';\n\nspacing(1); // 4px\nspacing(5); // 20px\nspacing(5, 6); // 20px 24px\nspacing(5, 2, 1); // 20px 8px 4px\nspacing(5, 6, 1, 6); // 20px 24px 4px 24px\n\nspacing(2, '5em'); // 8px 5em\n```\n\n### As inline style\n\n```tsx\nimport { spacing } from 'spacing-util';\n\nconst RandomBox = () =\u003e (\n  \u003cdiv\n    style={{\n      padding: spacing(4, 8),\n      borderRadius: spacing(1),\n    }}\n  \u003e\n    random box\n  \u003c/div\u003e\n);\n```\n\n### With emotion\n\n```tsx\nimport { spacing } from 'spacing-util';\nimport { css, cx } from '@emotion/css';\n\nconst RandomBox = () =\u003e (\n    \u003cdiv\n    className={css`\n      padding: ${spacing(4, 8)};\n      border-radius: ${spacing(1)};\n    `}\n  \u003e\n    random box\n  \u003c/div\u003e\n```\n\n### With styled-components\n\n```tsx\nimport { spacing } from 'spacing-util';\nimport styled from 'styled-components';\n\nconst StyledBox = styled.div`\n  padding: ${spacing(8)};\n  border-radius: ${spacing(1)};\n`;\n\nconst RandomBox = () =\u003e \u003cStyledBox\u003erandom box\u003c/StyledBox\u003e;\n```\n\n\u0026nbsp;\n\n## _Spacing generator_\n\nSometimes the default parser function might not satisfy you or your design needs. That's why you can create your own `spacing` function.\n\nYou are not limited to just one spacing across the app. It's up to you what will be the names for your spacings :)\n\n### Usage\n\n```ts\nimport { generateSpacing } from 'spacing-util';\nimport type { SpacingParser } from 'spacing-util';\n\n// Default parser function\nconst parser: SpacingParser = value =\u003e\n  typeof value === 'number' ? `${~~(value * 4)}px` : value;\n\nconst spacing = generateSpacing(parser);\n```\n\n## _Padding and margin function_\n\nIn case when you are lazy enough and feel bored of typing for example:\n\n```tsx\nconst StyledBox = styled.div`\n  padding: ${spacing(8, 4)};\n  margin: ${spacing(5)};\n`;\n```\n\nThere is a shorter way to do that by using `padding` and `margin` util functions.\n\n### Usage\n\n```tsx\nimport { padding, margin } from 'spacing-util';\n\nconst StyledBox = styled.div`\n  ${padding(8, 4)}\n  ${margin(5)}\n`;\n```\n\nBoth shares same usage as `spacing` function with 1 extra option. Instead `number` or `string` input, you can an object of type:\n\n```ts\n{\n  x: number | string;\n  y: number | string;\n  top: number | string;\n  right: number | string;\n  bottom: number | string;\n  left: number | string;\n}\n```\n\n`top, right, bottom, left` are responsible for returning just for these specific direction meanwhile `x, y` are like a shortcut for `left + right` and `top + bottom` usage. Values given for given key later on are transformed with spacing `parser` function.\n\n_Note_ - if u will use `x` shorthand with `left` together, the order matters! The value at the bottom will ovveride the previous one - behavior just like in vanilla CSS\n\n### Examples\n\n```tsx\npadding({\n  x: 4,\n  top: 5,\n});\n\n// returns\n// padding-top: 20px;\n// padding-right: 20px;\n// padding-left: 20px;\n```\n\n## _Padding and margin generator_\n\nSince margin and padding are built on top of `spacing` function and you enjoy it's usage you are able to create your own `padding` and `margin` utils by passing a parser function to it's generator function.\n\n### Usage\n\n```ts\nimport { generateMargin, generatePadding } from 'spacing-util';\nimport type { SpacingParser } from 'spacing-util';\n\n// Default parser function\nconst parser: SpacingParser = value =\u003e\n  typeof value === 'number' ? `${~~(value * 4)}px` : value;\n\nconst margin = generateMargin(parser);\nconst padding = generatePadding(parser);\n```\n\n[build-img]: https://github.com/EmilMalanczak/spacing-util/actions/workflows/release.yml/badge.svg\n[build-url]: https://github.com/EmilMalanczak/spacing-util/actions/workflows/release.yml\n[npm-img]: https://img.shields.io/npm/v/spacing-util\n[npm-url]: https://www.npmjs.com/package/spacing-util\n[issues-img]: https://img.shields.io/github/issues/EmilMalanczak/spacing-util\n[issues-url]: https://github.com/EmilMalanczak/spacing-util/issues\n[codecov-img]: https://codecov.io/gh/EmilMalanczak/spacing-util/branch/main/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/EmilMalanczak/spacing-util\n[semantic-release-img]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-release-url]: https://github.com/semantic-release/semantic-release\n[commitizen-img]: https://img.shields.io/badge/commitizen-friendly-brightgreen.svg\n[commitizen-url]: http://commitizen.github.io/cz-cli/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femilmalanczak%2Fspacing-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femilmalanczak%2Fspacing-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femilmalanczak%2Fspacing-util/lists"}