Skip to content

Commit

Permalink
feat(select): auto-inject css with js, don't need to import separatel…
Browse files Browse the repository at this point in the history
…y the css file
  • Loading branch information
TotomInc committed Jun 29, 2024
1 parent 360c45f commit e7f3602
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 30 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ Use it in your Vue 3 app:
import { ref } from "vue";
import VueSelect from "vue3-select-component";
import "vue3-select-component/dist/style.css";
const option = ref("");
</script>
Expand Down Expand Up @@ -77,8 +75,6 @@ It also leverages the power of generics to provide types for additional properti
import { ref } from "vue";
import VueSelect, { type Option } from "vue3-select-component";
import "vue3-select-component/dist/style.css";
type UserOption = Option<number> & { username: string };
const selectedUser = ref<number>();
Expand Down
2 changes: 0 additions & 2 deletions docs/demo/custom-option-slot.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const selected = ref("");

```vue
<script setup lang="ts">
import "vue3-select-component/dist/style.css";
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
2 changes: 0 additions & 2 deletions docs/demo/multiple-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Selected value(s): **{{ selected.length ? selected.join(", ") : "none" }}**

```vue
<script setup lang="ts">
import "vue3-select-component/dist/style.css";
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
4 changes: 1 addition & 3 deletions docs/demo/pre-selected-values.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ const multiSelected = ref(["option_3", "option_5"]);
## Demo source-code

```vue
<script setup>
import "vue3-select-component/dist/style.css";
<script setup lang="ts">
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
2 changes: 0 additions & 2 deletions docs/demo/single-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ Selected value: **{{ selected || "none" }}**

```vue
<script setup lang="ts">
import "vue3-select-component/dist/style.css";
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
2 changes: 0 additions & 2 deletions docs/demo/with-complex-menu-filter.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ function switchFilter() {

```vue
<script setup lang="ts">
import "vue3-select-component/dist/style.css";
import { computed, ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
2 changes: 0 additions & 2 deletions docs/demo/with-menu-header.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const selected = ref("");

```vue
<script setup>
import "vue3-select-component/dist/style.css";
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
4 changes: 0 additions & 4 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Import the component with the styling, and use it in your Vue 3 application:

```vue
<script setup lang="ts">
import "vue3-select-component/dist/style.css";
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down Expand Up @@ -70,8 +68,6 @@ To enable the multiselect feature, all you need to do is:

```vue
<script setup>
import "vue3-select-component/dist/style.css";
import { ref } from "vue";
import VueSelect from "vue3-select-component";
Expand Down
4 changes: 4 additions & 0 deletions docs/styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ title: 'Styling'

Vue 3 Select Component provides 2 types of customization available in the component.

::: tip
The default component styling is already included with the VueSelect component, you don't need to import any CSS file to make it work.
:::

## CSS variables

CSS variables is the easiest way to customize the component style but provides less flexibility over your design. When importing the component, you will notice that CSS variables are injected into the `:root` scope and are prefixed with `--vs-select-[...]`.
Expand Down
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.es.js",
"require": "./dist/index.umd.js"
},
"./dist/style.css": {
"types": "./dist/style.css",
"import": "./dist/style.css",
"require": "./dist/style.css"
}
},
"main": "dist/index.umd.js",
Expand Down Expand Up @@ -65,6 +60,7 @@
"sass": "1.77.6",
"typescript": "5.5.2",
"vite": "5.3.2",
"vite-plugin-css-injected-by-js": "3.5.1",
"vite-plugin-dts": "3.9.1",
"vite-plugin-vue-devtools": "7.3.5",
"vitepress": "1.2.3",
Expand Down
8 changes: 4 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import { type UserConfig, defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueDevtools from "vite-plugin-vue-devtools";
import dts from "vite-plugin-dts";
import cssInject from "vite-plugin-css-injected-by-js";

const resolve = (path: string) => fileURLToPath(new URL(path, import.meta.url));

// https://vitejs.dev/config/
export default defineConfig((configEnv) => {
// Default shared config by all modes.
// Default config shared config by all modes.
const config: UserConfig = {
plugins: [vue()],
resolve: {
alias: { "@": resolve("./src") },
},
resolve: { alias: { "@": resolve("./src") } },
};

// When running vitest, add the test config.
Expand All @@ -36,6 +35,7 @@ export default defineConfig((configEnv) => {

plugins: [
...config.plugins!,
cssInject(),
dts({ tsconfigPath: "tsconfig.build.json", cleanVueFileName: true }),
],

Expand Down

0 comments on commit e7f3602

Please sign in to comment.