{"id":15688143,"url":"https://github.com/rajasegar/styled-web-components","last_synced_at":"2025-10-05T19:19:48.784Z","repository":{"id":143781041,"uuid":"413621479","full_name":"rajasegar/styled-web-components","owner":"rajasegar","description":"Style property primitives for Web components inspired by styled-system","archived":false,"fork":false,"pushed_at":"2021-10-13T09:52:20.000Z","size":128,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-28T12:07:44.392Z","etag":null,"topics":["customelements","webcomponent","webcomponents"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/rajasegar.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-05T00:14:56.000Z","updated_at":"2022-04-08T06:26:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"118c488e-e99e-4ea4-95d1-721aec9eebdc","html_url":"https://github.com/rajasegar/styled-web-components","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/rajasegar/styled-web-components","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fstyled-web-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fstyled-web-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fstyled-web-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fstyled-web-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rajasegar","download_url":"https://codeload.github.com/rajasegar/styled-web-components/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajasegar%2Fstyled-web-components/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278505349,"owners_count":25998110,"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","status":"online","status_checked_at":"2025-10-05T02:00:06.059Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["customelements","webcomponent","webcomponents"],"created_at":"2024-10-03T17:55:31.167Z","updated_at":"2025-10-05T19:19:48.765Z","avatar_url":"https://github.com/rajasegar.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :art: styled-web-components\n\n[![npm version](http://img.shields.io/npm/v/@rajasegar/styled-web-components.svg?style=flat)](https://npmjs.org/package/@rajasegar/styled-web-components \"View this project on npm\")\n\nStyle property primitives for Web components inspired by [styled-system](https://styled-system.com)\n\n- Zero dependencies :package:\n- Light weight ( just 1.9 KB gzipped ) :leaves:\n- Convenient and shorthand property names like (m,p, mx, px, etc.,) :wrench: :hammer:\n- No build or compilation required :zap:\n\n## Installation\n```\nnpm install @rajasegar/styled-web-components\n```\n\nvia CDN:\n\n```\n\u003cscript src=\"https://unpkg.com/@rajasegar/styled-web-components@2.0.0/dist/styled-web-components.min.js\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n\nCreate your own Custom element with composing props \n\n```js\nimport { SpaceProps, ColorProps, TypographyProps } from 'styled-web-components'\n\nclass SWBox extends HTMLElement {\n  constructor() {\n    super()\n    this.attachShadow({ mode: 'open' })\n    const template = document.createElement('template')\n\n    // This is very important, your template should have a style tag with :host selector\n    template.innerHTML = `\u003cstyle\u003e\n    :host { display: block; }\n    \u003cstyle\u003e\n    \u003cslot\u003e\u003c/slot\u003e`\n    this.shadowRoot.appendChild(template.content.cloneNode(true))\n\n  }\n}\n\ncustomElements.define('sw-box', TypographyProps(ColorProps(SpaceProps(SWBox))))\n```\n\nUse your newly defined custom element in your HTML\n\n```html\n  \u003csw-box py=\"2em\" color=\"red\" bg=\"yellow\" font-family=\"sans-serif\"\u003e\n  \u003ch1\u003eHello world\u003c/h1\u003e\n  \u003c/sw-box\u003e\n```\n\n### Flex box custom component\n```js\nimport { FlexboxProps } from 'styled-web-components'\n\nclass SWFlex extends HTMLElement {\n  constructor() {\n    super()\n    this.attachShadow({ mode: 'open' })\n    const template = document.createElement('template')\n    template.innerHTML = `\u003cstyle\u003e\n    :host { display: flex; }\n    \u003c/style\u003e\n    \u003cslot\u003e\u003c/slot\u003e`\n    this.shadowRoot.appendChild(template.content.cloneNode(true))\n  }\n}\n\ncustomElements.define('sw-flex', FlexboxProps(SWFlex))\n\n```\n\n#### Usage\n```html\n\n\u003csw-flex justify-content=\"center\" flex-direction=\"row-reverse\"\u003e\n  \u003csw-box m=\"1em\" width=\"500px\" py=\"2em\" color=\"red\" bg=\"yellow\" font-family=\"sans-serif\" text-align=\"center\"\u003e\n    \u003ch3\u003eSection 1\u003c/h3\u003e\n  \u003c/sw-box\u003e\n  \u003csw-box m=\"1em\"  width=\"500px\" py=\"2em\" color=\"red\" bg=\"yellow\" font-family=\"sans-serif\" text-align=\"center\"\u003e\n    \u003ch3\u003eSection 2\u003c/h3\u003e\n  \u003c/sw-box\u003e\n\u003c/sw-flex\u003e\n\n```\n\n### Grid custom component\n\n```js\nimport { GridProps } from 'styled-web-components'\n\nclass SWGrid extends HTMLElement {\n  constructor() {\n    super()\n    this.attachShadow({ mode: 'open' })\n    const template = document.createElement('template')\n    template.innerHTML = `\u003cstyle\u003e\n    :host { display: grid; }\n    \u003c/style\u003e\n    \u003cslot\u003e\u003c/slot\u003e`\n    this.shadowRoot.appendChild(template.content.cloneNode(true))\n  }\n}\n\ncustomElements.define('sw-grid', GridProps(SWGrid))\n```\n\n#### Usage\n```html\n  \u003ch2\u003eGrid demo\u003c/h2\u003e\n  \u003csw-box m=\"2em\"\u003e\n  \u003csw-grid grid-template-columns='100px 100px 100px' grid-gap=\"10px\"\u003e\n    \u003csw-box bg=\"#444\" color=\"#fff\" border-radius=\"5px\" p=\"20px\" font-size=\"150%\"\u003eA\u003c/sw-box\u003e\n    \u003csw-box bg=\"#444\" color=\"#fff\" border-radius=\"5px\" p=\"20px\" font-size=\"150%\"\u003eB\u003c/sw-box\u003e\n    \u003csw-box bg=\"#444\" color=\"#fff\" border-radius=\"5px\" p=\"20px\" font-size=\"150%\"\u003eC\u003c/sw-box\u003e\n    \u003csw-box bg=\"#444\" color=\"#fff\" border-radius=\"5px\" p=\"20px\" font-size=\"150%\"\u003eD\u003c/sw-box\u003e\n    \u003csw-box bg=\"#444\" color=\"#fff\" border-radius=\"5px\" p=\"20px\" font-size=\"150%\"\u003eE\u003c/sw-box\u003e\n    \u003csw-box bg=\"#444\" color=\"#fff\" border-radius=\"5px\" p=\"20px\" font-size=\"150%\"\u003eF\u003c/sw-box\u003e\n  \u003c/sw-grid\u003e\n  \u003c/sw-box\u003e\n```\n\n\n\nFor more examples, see the [demo](demo/) folder.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fstyled-web-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajasegar%2Fstyled-web-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajasegar%2Fstyled-web-components/lists"}