Skip to content

Commit

Permalink
feat(docs): rewrite installation/Customization in TS (#400)
Browse files Browse the repository at this point in the history
Rewrites `src/pages/installation/Customization.vue` in TypeScript.

Fixes the issue that Vite complained about the missing `buefy` package,
which was not actually used. This was caused by the code snippets in
`Customization.vue`, which Vite conufsed with the actual code and tried
to translate them. Moves these code snippets to a separate TypeScript
file `usage/customization.ts`.

Here is a tip for TypeScript migration:
- Explicitly import and register Buefy components so that they are
  type-checked. Note that no type-checking is performed for globally
  registered components.
  • Loading branch information
kikuomax authored Jan 16, 2025
1 parent 33b0e65 commit 02b2962
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 92 deletions.
111 changes: 19 additions & 92 deletions packages/docs/src/pages/installation/Customization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,103 +49,30 @@
</div>
</template>

<script>
import { preformat } from '@/utils'
export default {
data() {
return {
sass: `
// Import Bulma's core
@import "~bulma/sass/utilities/_all";
// Set your colors
$primary: #8c67ef;
$primary-light: findLightColor($primary);
$primary-dark: findDarkColor($primary);
$primary-invert: findColorInvert($primary);
$twitter: #4099FF;
$twitter-invert: findColorInvert($twitter);
<script lang="ts">
import { defineComponent } from 'vue'
// Lists and maps
$custom-colors: null !default;
$custom-shades: null !default;
// Setup $colors to use as bulma classes (e.g. 'is-twitter')
$colors: mergeColorMaps(
(
"white": (
$white,
$black,
),
"black": (
$black,
$white,
),
"light": (
$light,
$light-invert,
),
"dark": (
$dark,
$dark-invert,
),
"primary": (
$primary,
$primary-invert,
$primary-light,
$primary-dark,
),
"link": (
$link,
$link-invert,
$link-light,
$link-dark,
),
"info": (
$info,
$info-invert,
$info-light,
$info-dark,
),
"success": (
$success,
$success-invert,
$success-light,
$success-dark,
),
"warning": (
$warning,
$warning-invert,
$warning-light,
$warning-dark,
),
"danger": (
$danger,
$danger-invert,
$danger-light,
$danger-dark,
),
),
$custom-colors
);
import { BMessage } from '@ntohq/buefy-next'
// Links
$link: $primary;
$link-invert: $primary-invert;
$link-focus-border: $primary;
import CodeView from '@/components/CodeView.vue'
import { preformat } from '@/utils'
// Import Bulma and Buefy styles
@import "~bulma";
@import "~buefy/src/scss/buefy";
`,
importing: `
import Vue from 'vue'
import Buefy from 'buefy'
import {
importing,
sass
} from './usage/customization'
Vue.use(Buefy)`
export default defineComponent({
components: {
BMessage,
CodeView
},
data() {
return {
sass,
importing
}
},
methods: { preformat }
}
})
</script>
95 changes: 95 additions & 0 deletions packages/docs/src/pages/installation/usage/customization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Code snippets used in the `Customization` component.
//
// Vite may confuse these examples with the legitimate code and try to compile
// them, if they are in the component (.vue) file.

export const sass = `
// Import Bulma's core
@import "~bulma/sass/utilities/_all";
// Set your colors
$primary: #8c67ef;
$primary-light: findLightColor($primary);
$primary-dark: findDarkColor($primary);
$primary-invert: findColorInvert($primary);
$twitter: #4099FF;
$twitter-invert: findColorInvert($twitter);
// Lists and maps
$custom-colors: null !default;
$custom-shades: null !default;
// Setup $colors to use as bulma classes (e.g. 'is-twitter')
$colors: mergeColorMaps(
(
"white": (
$white,
$black,
),
"black": (
$black,
$white,
),
"light": (
$light,
$light-invert,
),
"dark": (
$dark,
$dark-invert,
),
"primary": (
$primary,
$primary-invert,
$primary-light,
$primary-dark,
),
"link": (
$link,
$link-invert,
$link-light,
$link-dark,
),
"info": (
$info,
$info-invert,
$info-light,
$info-dark,
),
"success": (
$success,
$success-invert,
$success-light,
$success-dark,
),
"warning": (
$warning,
$warning-invert,
$warning-light,
$warning-dark,
),
"danger": (
$danger,
$danger-invert,
$danger-light,
$danger-dark,
),
),
$custom-colors
);
// Links
$link: $primary;
$link-invert: $primary-invert;
$link-focus-border: $primary;
// Import Bulma and Buefy styles
@import "~bulma";
@import "~buefy/src/scss/buefy";
`

export const importing = `
import Vue from 'vue'
import Buefy from 'buefy'
Vue.use(Buefy)`

0 comments on commit 02b2962

Please sign in to comment.