Skip to content

Commit

Permalink
Menu impl + build fixes (#4)
Browse files Browse the repository at this point in the history
* make mount helper types more accurate; make shallow false by default

* Add layout and menu feature

* update postcss/tailwind configs

* move image to component utilizing it

* add more layout plugins to naive.ts

* initial layout for main page

* add media query for dark mode

* position fix the side layer

* separate test tsconfig from build; create separate vitest config; add babel types
  • Loading branch information
ChronosMasterOfAllTime authored Apr 7, 2022
1 parent 43670a2 commit 709aa16
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 77 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"vue-router": "^4.0.12"
},
"devDependencies": {
"@babel/types": "^7.17.0",
"@pinia/testing": "^0.0.9",
"@tailwindcss/aspect-ratio": "^0.4.0",
"@tailwindcss/forms": "^0.4.0",
Expand All @@ -40,8 +41,9 @@
"eslint-plugin-vue": "^8.5.0",
"happy-dom": "^2.41.0",
"naive-ui": "^2.27.0",
"postcss": "^8.4.6",
"postcss": "^8.4.12",
"postcss-scss": "^4.0.3",
"postcss-import": "^14.1.0",
"prettier": "^2.5.1",
"sass": "^1.49.8",
"stylelint": "^14.5.1",
Expand Down
10 changes: 6 additions & 4 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
plugins: [
require('postcss-import'),
require('tailwindcss/nesting'),
require('tailwindcss'),
require('autoprefixer')
]
}
51 changes: 38 additions & 13 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
<script setup lang="ts">
// This starter template is using Vue 3 <script setup> SFCs
// Check out https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup
// another good resource: https://learnvue.co/2021/05/explaining-the-new-script-setup-type-in-vue-3-major-takeaways-from-the-rfc/
import { darkTheme, lightTheme } from 'naive-ui'
import { computed, ref } from 'vue'
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches
const mode = ref<'dark' | 'light'>(prefersDark ? 'dark' : 'light')
const theme = computed(() => (mode.value === 'dark' ? darkTheme : lightTheme))
const collapsed = ref(true)
</script>

<template>
<div
class="bg-white dark:bg-gray-800 dark:text-white text-gray-800 text-center h-screen w-screen"
>
<img
class="pt-10 mx-auto mb-4"
alt="Chronos logo"
src="./assets/chronos.jpg"
/>
<router-view />
</div>
<n-config-provider :theme="theme">
<n-layout position="absolute">
<n-layout-header style="height: 64px; padding: 24px" bordered>
Layout Header
</n-layout-header>
<n-layout
class="bg-white dark:bg-gray-800 dark:text-white text-gray-800 text-center h-screen w-screen"
has-sider
position="absolute"
style="top: 64px; bottom: 64px"
>
<n-layout-sider
class="fixed h-full"
collapse-mode="transform"
:width="240"
@mouseover="collapsed = false"
@mouseleave="collapsed = true"
:collapsed="collapsed"
:native-scrollbar="false"
bordered
>
<n-h2>Layout Sider</n-h2>
</n-layout-sider>
<n-layout-content :native-scrollbar="false">
<router-view />
</n-layout-content>
</n-layout>
</n-layout>
</n-config-provider>
</template>

<style lang="sass">
Expand Down
40 changes: 37 additions & 3 deletions src/components/global/vendor/naive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
import { create, NButton } from 'naive-ui'
// import { Plugin } from 'vue'
import {
create,
NButton,
NConfigProvider,
NH1,
NH2,
NH3,
NH4,
NH5,
NH6,
NHr,
NLayout,
NLayoutContent,
NLayoutFooter,
NLayoutHeader,
NLayoutSider,
NMenu,
NScrollbar
} from 'naive-ui'

export default create({
components: [NButton]
components: [
NButton,
NConfigProvider,
NH1,
NH2,
NH3,
NH4,
NH5,
NH6,
NHr,
NLayout,
NLayoutHeader,
NLayoutContent,
NLayoutFooter,
NLayoutSider,
NMenu,
NScrollbar
]
})
55 changes: 30 additions & 25 deletions src/views/HelloWorld.vue
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
<script setup lang="ts">
import { useMainStore } from '@/store'
import { computed } from 'vue'
defineProps<{ msg: string }>()
const main = useMainStore()
const { incrementCounter } = main
const message = computed(() => {
if (main.count >= 60) return "It's broken!"
if (main.count > 50) return 'Uh-oh'
if (main.count > 30) return 'Slow Down..'
if (main.count > 10) return 'Great Job!'
return 'Click Me'
})
const variant = computed(() => {
if (main.count >= 60) return 'error'
if (main.count > 10) return 'success'
return 'default'
})
</script>

<template>
<img
class="pt-10 mx-auto mb-4"
alt="Chronos logo"
src="@/assets/chronos.jpg"
/>
<h1>{{ msg }}</h1>
<p>
Recommended IDE setup:
Expand Down Expand Up @@ -74,6 +54,31 @@ const variant = computed(() => {
</p>
</template>

<script setup lang="ts">
import { useMainStore } from '@/store'
import { computed } from 'vue'
defineProps<{ msg: string }>()
const main = useMainStore()
const { incrementCounter } = main
const message = computed(() => {
if (main.count >= 60) return "It's broken!"
if (main.count > 50) return 'Uh-oh'
if (main.count > 30) return 'Slow Down..'
if (main.count > 10) return 'Great Job!'
return 'Click Me'
})
const variant = computed(() => {
if (main.count >= 60) return 'error'
if (main.count > 10) return 'success'
return 'default'
})
</script>

<style lang="sass" scoped>
a
color: #42b983
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = {
content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
darkMode: 'media', // false, 'media' or 'class'
mode: 'jit',
theme: {
extend: {}
},
Expand Down
8 changes: 4 additions & 4 deletions test/unit/testhelper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { mount, MountingOptions } from '@vue/test-utils'
import { createTestingPinia } from '@pinia/testing'
import { DefineComponent, Plugin } from 'vue'
import { ComponentPublicInstance, Plugin } from 'vue'
import { globalComponents } from '@/components'
import { createPinia, setActivePinia } from 'pinia'

export function mountComponent<T extends InstanceType<DefineComponent>>(
export function mountComponent<T extends ComponentPublicInstance>(
component: T,
options: MountingOptions<T> = { shallow: true },
options: MountingOptions<T> = { shallow: false },
mockStore = false
) {
const pinia = mockStore
Expand All @@ -25,5 +25,5 @@ export function mountComponent<T extends InstanceType<DefineComponent>>(
}
}

return mount(component, options)
return mount<T>(component, options)
}
21 changes: 21 additions & 0 deletions test/unit/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"types": ["vite/client", "vitest/globals", "naive-ui/volar", "node"],
"paths": {
"@/*": ["src/*"],
"@test/*": ["test/*"]
},
"baseUrl": "../.."
},
"include": [
"../../src/**/*.ts",
"../../src/**/*.d.ts",
"../../src/**/*.tsx",
"../../src/**/*.vue",
"**/*.ts",
"**/*.d.ts",
"**/*.tsx",
"**/*.vue"
]
}
6 changes: 3 additions & 3 deletions test/unit/views/HelloWorld.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import HelloWorld from '@/views/HelloWorld.vue'
import { mountComponent } from '@test/unit/testhelper'
import { VueWrapper } from '@vue/test-utils'
import { NButton } from 'naive-ui'
import { ComponentPublicInstance } from 'vue'

describe('HelloWorld.vue', () => {
let wrapper: VueWrapper<InstanceType<typeof HelloWorld>>
let wrapper: VueWrapper<ComponentPublicInstance<typeof HelloWorld>>
beforeEach(() => {
wrapper = mountComponent<InstanceType<typeof HelloWorld>>(HelloWorld, {
props: { msg: 'foo bar' },
shallow: false
props: { msg: 'foo bar' }
})
})

Expand Down
11 changes: 3 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,16 @@
"sourceMap": true,
"baseUrl": ".",
"lib": ["esnext", "dom"],
"types": ["vite/client", "vitest/globals", "naive-ui/volar", "node"],
"types": ["vite/client", "naive-ui/volar", "node"],
"paths": {
"@/*": ["src/*"],
"@test/*": ["test/*"]
"@/*": ["src/*"]
}
},
"include": [
"src/**/*.ts",
"src/**/*.d.ts",
"src/**/*.tsx",
"src/**/*.vue",
"test/unit/**/*.ts",
"test/unit/**/*.d.ts",
"test/unit/**/*.tsx",
"test/unit/**/*.vue"
"src/**/*.vue"
],
"exclude": ["node_modules", "dist/**/*"]
}
8 changes: 2 additions & 6 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { defineConfig } from 'vitest/config'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import tsconfigPaths from 'vite-tsconfig-paths'

const plugins = [vue(), tsconfigPaths()]

// https://vitejs.dev/config/
export default defineConfig({
plugins,
test: {
environment: 'happy-dom',
globals: true
}
plugins
})
14 changes: 14 additions & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import tsconfigPaths from 'vite-tsconfig-paths'

const plugins = [vue(), tsconfigPaths({ root: 'test/unit' })]

// https://vitejs.dev/config/
export default defineConfig({
plugins,
test: {
environment: 'happy-dom',
globals: true
}
})
Loading

0 comments on commit 709aa16

Please sign in to comment.