{"id":15287094,"url":"https://github.com/nainemom/vue-component-style","last_synced_at":"2025-10-14T23:41:15.352Z","repository":{"id":36466961,"uuid":"224738826","full_name":"nainemom/vue-component-style","owner":"nainemom","description":"A Vue mixin to add style section to components.","archived":false,"fork":false,"pushed_at":"2023-01-05T02:09:07.000Z","size":507,"stargazers_count":19,"open_issues_count":16,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T21:52:41.077Z","etag":null,"topics":["component","css","cssinjs","jss","mixin","nuxt","style","vue"],"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/nainemom.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":"2019-11-28T22:28:41.000Z","updated_at":"2024-10-26T13:23:30.000Z","dependencies_parsed_at":"2023-01-17T01:45:07.338Z","dependency_job_id":null,"html_url":"https://github.com/nainemom/vue-component-style","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nainemom%2Fvue-component-style","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nainemom%2Fvue-component-style/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nainemom%2Fvue-component-style/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nainemom%2Fvue-component-style/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nainemom","download_url":"https://codeload.github.com/nainemom/vue-component-style/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665748,"owners_count":21142123,"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":["component","css","cssinjs","jss","mixin","nuxt","style","vue"],"created_at":"2024-09-30T15:24:15.351Z","updated_at":"2025-10-14T23:41:10.296Z","avatar_url":"https://github.com/nainemom.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Vue Component Style\n![npm](https://img.shields.io/npm/dm/vue-component-style)\n![npm](https://img.shields.io/npm/v/vue-component-style)\n![NPM](https://img.shields.io/npm/l/vue-component-style)\n\nA `Vue` mixin to add `style` section to components.\n\n## Features\n\n- Zero Dependency\n- Tiny (~1kb gzipped)\n- Simple Setup and Usage\n- Nested Support\n- Pseudo Selector Support\n- SSR Support\n- Scoped to Component\n\n## Install\n\n```bash\nnpm i vue-component-style\n```\n\n## Setup\n\n### Vue App\n\n```javascript\nimport Vue from 'vue';\nimport VueComponentStyle from 'vue-component-style';\n\nVue.use(VueComponentStyle);\n```\n\n### Nuxt App\n\n_nuxt.config.js_:\n```javascript\nmodule.exports = {\n  modules: [\n    'vue-component-style/nuxt'\n  ],\n}\n```\n\nNote that You don't need to do anything else with your webpack config or whatever.\n\n## Usage\n\n_component.vue_:\n```html\n\u003ctemplate\u003e\n  \u003cdiv\u003e\n    \u003ch1 :class=\"$style.title\"\u003e Title \u003c/h1\u003e\n    \u003cdiv :class=\"$style.content\"\u003e\n      Content \u003ca\u003e Link \u003c/a\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n\u003c/template\u003e\n\n\u003cscript\u003e\nexport default {\n  props: {\n    size: {\n      type: Number,\n      default: 8\n    },\n    color: {\n      type: String,\n      default: 'red'\n    }\n  },\n  style({ className }) {\n    return [\n      className('title', {\n        color: this.color,\n        fontWeight: 'bold',\n      }),\n      className('content', {\n        color: 'gray',\n        marginBottom: `${this.size}px`,\n        '\u0026 \u003e a': {\n          color: this.color,\n          '\u0026:visited': {\n            textDecoration: 'underline',\n          },\n        },\n      }),\n    ];\n  }\n}\n\u003c/script\u003e\n```\n\n---\n\n## API Documentions\n\n### 1 - Define Style\n\n    Function this.style(helper)\n\nAfter activating **VueComponentStyle**, all components can have their js **style** section. Just like **data** section, you have to pass normal function that returning an Array. This function will invoke automatically with [`helper`](#helper) util object as first argument.\n\n### 2 - Use Defined Styles\n\n    Object this.$style\n\nAfter you defining **style** prop in your component, all your classes defined by [`style()`](#1-define-style)s are accessable with **$style** computed object inside your component instance.\n\n### 3 - Notice When Styles Updated\n\n    VueEvent 'styleChange'\n\n**styleChange** event fires when your style changes and applied to DOM.\n\n\n---\n\n### Helper\n\nYou can use [`helper()`](#helper) object from first parameter of [`style()`](#1-define-style) function to defining your stylesheet. Helper object has these functions\n\n- [`className()`](#class-name)\n- [`mediaQuery()`](#media-query)\n- [`keyFrames()`](#key-frames)\n- [`custom()`](#custom)\n\n#### Class Name\n\n    Function helper.className(name, content)\n\nTo define your scopped css class styles, use this helper function.\n\n| Param | Type | Default | Description |\n| - | - | - | - |\n| name | String | | Name of your class. All of your defined names will be accessable via $style Object later. |\n| content | Object | {} | Your sass-style class properties. You can also style nested. |\n\n##### Example\n\n```javascript\nstyle({ className }) {\n  return [\n    className('customClass', {\n      color: 'red',\n      fontWeight: 'bold',\n      borderRadius: `${this.size}px`,\n      '\u0026 \u003e div': {\n        color: 'blue',\n      },\n    }),\n  ];\n}\n```\n\n#### Media Query\n\n    Function helper.mediaQuery(mediaFeature, content)\n\nTo define your customized style to different screen sizes, use this helper function. \n\n| Param | Type | Default | Description |\n| - | - | - | - |\n| mediaFeature | Object | | Media features. Common keys on this object are 'minWidth' and 'maxWidth'. |\n| content | Array | [] | List of [`className()`](#class-name)s that you need to redefine. |\n\n##### Example\n\n```javascript\nstyle({ mediaQuery, className }) {\n  return [\n    className('responsiveClass', {\n      width: '50%',\n    }),\n    mediaQuery({ maxWidth: '320px' }, [\n      className('responsiveClass', {\n        width: '100%',\n      }),     \n    ]),\n  ];\n}\n```\n\n#### Key Frames\n\n    Function helper.keyFrames(name, content)\n\nTo define your scopped keyframes animation with specefic name, use this helper function. \n\n| Param | Type | Default | Description |\n| - | - | - | - |\n| name | String | | Keyframes name. |\n| content | Object | | Keyframes properties. If you don't pass this prop, calculated hash name of already generated keyframes will be returns. |\n\n##### Example\n\n```javascript\nstyle({ keyFrames, className }) {\n  return [\n    className('animatedThing', {\n      color: 'blue',\n      animationName: keyFrames('myAnimation'),\n      animationDuration: '2s',\n    }),\n    keyFrames('myAnimation', {\n      from: {\n        color: 'blue',\n      },\n      to: {\n        color: 'red',\n      },\n    ]),\n  ];\n}\n```\n\n#### Custom\n\n    Function helper.custom(rule, content)\n\nTo define your custom css style sections, use this helper function. **Note that styles generated by this helper function are not scopped!**\n\n| Param | Type | Default | Description |\n| - | - | - | - |\n| rule | String | | Rule name. |\n| content | Object | | Style properties. |\n\n##### Example\n\n```javascript\nstyle({ custom }) {\n  return [\n    custom('@font-face', {\n      fontFamily: 'globalFont',\n      src: 'url(global_font.woff)',\n    }),\n  ];\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnainemom%2Fvue-component-style","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnainemom%2Fvue-component-style","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnainemom%2Fvue-component-style/lists"}