Skip to content
This repository has been archived by the owner on Aug 30, 2020. It is now read-only.

Commit

Permalink
dev: refactor components to tsx files (#47)
Browse files Browse the repository at this point in the history
Some benefits:
- Better editor and tooling support
- No need for `h: CreateElement` in any `render()`
- Can format/lint the code
- In the future, can remove usage of `components` if vuejs/vue#9379 is merged
- Use single css classes (copied from tachyons) to style components, since most of the styling can be done with Vuetify, also remove `sass` and `sass-loader`
  • Loading branch information
baocancode committed Apr 5, 2019
1 parent f4091cc commit 25485cf
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 182 deletions.
86 changes: 0 additions & 86 deletions package-lock.json

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

9 changes: 2 additions & 7 deletions packages/web/nuxt.config.ts
@@ -1,5 +1,4 @@
import path from 'path'
import sass from 'sass'

export const rootDir = __dirname

Expand All @@ -11,7 +10,7 @@ export const server = {

export const plugins = [path.join(__dirname, 'src/plugins/vuetify.ts')]

export const css = ['vuetify/dist/vuetify.css']
export const css = ['vuetify/dist/vuetify.css', path.join(__dirname, 'src/assets/common.css')]

export const head = {
titleTemplate: (title: string): string => {
Expand All @@ -38,11 +37,7 @@ export const head = {
}

export const build = {
loaders: {
scss: {
implementation: sass,
},
},
extractCSS: true,
extend (config: any) {
// Allow to mock dependencies
config.resolve.modules.unshift(path.join(__dirname, 'mock_dependencies'))
Expand Down
5 changes: 1 addition & 4 deletions packages/web/package.json
Expand Up @@ -26,10 +26,7 @@
"devDependencies": {
"@nuxt/typescript": "^2.5.1",
"@types/luxon": "^1.11.1",
"@types/sass": "^1.16.0",
"@webok/dev": "^0.0.0",
"nuxt": "^2.5.1",
"sass": "^1.17.3",
"sass-loader": "^7.1.0"
"nuxt": "^2.5.1"
}
}
3 changes: 3 additions & 0 deletions packages/web/src/assets/common.css
@@ -0,0 +1,3 @@
/* https://tachyons.io/docs/typography/text-decoration/ */

.no-underline { text-decoration: none; }
@@ -1,10 +1,8 @@
<script lang='tsx'>
import { Component, Vue, Prop } from 'vue-property-decorator'
import { CreateElement } from 'vue'
import { DateTime } from 'luxon'

@Component({})
export default class Datetime extends Vue {
export class Datetime extends Vue {
@Prop({ type: String, required: true })
private readonly value!: string

Expand All @@ -16,7 +14,7 @@ export default class Datetime extends Vue {
return DateTime.fromISO(this.value).setLocale('en-US').toLocaleString(format)
}

render (h: CreateElement) {
render () {
return (
// Use no-ssr because server does not know client timezone
<no-ssr>
Expand All @@ -26,4 +24,3 @@ export default class Datetime extends Vue {
)
}
}
</script>
@@ -1,20 +1,18 @@
<script lang='tsx'>
import { Component, Vue, Prop } from 'vue-property-decorator'
import { CreateElement } from 'vue'

@Component({})
export default class ExternalLink extends Vue {
export class ExternalLink extends Vue {
@Prop({ type: String, required: true })
private readonly to!: string

@Prop(String)
private readonly label!: string

render (h: CreateElement) {
render () {
return (
<a
href={this.to}
class='link'
class='no-underline'
target='_blank'
>
<v-icon
Expand All @@ -25,10 +23,3 @@ export default class ExternalLink extends Vue {
)
}
}
</script>

<style lang="scss" scoped>
.link {
text-decoration: none;
}
</style>
@@ -1,15 +1,10 @@
<script lang='tsx'>
import { Component, Vue } from 'vue-property-decorator'
import { CreateElement } from 'vue'

@Component({})
export default class FormCard extends Vue {
render (h: CreateElement) {
export class FormCard extends Vue {
render () {
return (
<v-card
class="mt-2"
raised
>
<v-card raised>
<v-card-title
class='pb-0'
primary-title
Expand All @@ -27,4 +22,3 @@ export default class FormCard extends Vue {
)
}
}
</script>
4 changes: 4 additions & 0 deletions packages/web/src/components/common/index.ts
@@ -0,0 +1,4 @@
export * from './form-card'
export * from './section-block'
export * from './external-link'
export * from './datetime'
@@ -1,13 +1,11 @@
<script lang='tsx'>
import { Component, Vue, Prop } from 'vue-property-decorator'
import { CreateElement } from 'vue'

@Component({})
export default class SectionBlock extends Vue {
export class SectionBlock extends Vue {
@Prop({ type: String, required: true })
private readonly title!: string

render (h: CreateElement) {
render () {
return (
<div class='my-2'>
<strong>{this.title}</strong>
Expand All @@ -16,4 +14,3 @@ export default class SectionBlock extends Vue {
)
}
}
</script>
4 changes: 4 additions & 0 deletions packages/web/src/components/page/index.ts
@@ -0,0 +1,4 @@
export * from './page-new-form'
export * from './page-details'
export * from './page-edit-form'
export * from './page-delete-button'
@@ -1,15 +1,13 @@
<script lang='tsx'>
import { Component, Vue, Prop, Emit } from 'vue-property-decorator'
import { CreateElement } from 'vue'
import { PageDto } from '@webok/core/es6/page'
import FormCard from '../common/form-card.vue'
import { FormCard } from '../common'

@Component({
components: {
FormCard,
},
})
export default class PageDeleteButton extends Vue {
export class PageDeleteButton extends Vue {
@Prop({ type: Object, required: true })
private readonly pageDto!: PageDto

Expand All @@ -30,7 +28,7 @@ export default class PageDeleteButton extends Vue {
this.deletingPage = false
}

render (h: CreateElement) {
render () {
return (
<v-dialog
value={this.deletingPage}
Expand All @@ -47,22 +45,21 @@ export default class PageDeleteButton extends Vue {
slot='title'
class='headline'
>Delete Page</div>
<p class="subheading mt-3">
<p class='subheading mt-3'>
Are you sure you want to delete the page '{this.pageDto.name}'?
</p>
<template slot='actions'>
<v-btn
flat
on={{ click: this.cancel }}
>Cancel</v-btn>
<v-btn
color='error'
on={{ click: this.submit }}
>Delete</v-btn>
</template>
<v-btn
flat
on={{ click: this.cancel }}
>Cancel</v-btn>
<v-btn
color='error'
on={{ click: this.submit }}
>Delete</v-btn>
</template>
</form-card>
</v-dialog>
)
}
}
</script>
@@ -1,10 +1,6 @@
<script lang='tsx'>
import { Component, Vue, Prop } from 'vue-property-decorator'
import { CreateElement } from 'vue'
import { PageDto } from '@webok/core/es6/page'
import SectionBlock from '../common/section-block.vue'
import ExternalLink from '../common/external-link.vue'
import Datetime from '../common/datetime.vue'
import { SectionBlock, ExternalLink, Datetime } from '../common'

@Component({
components: {
Expand All @@ -13,11 +9,11 @@ import Datetime from '../common/datetime.vue'
Datetime,
},
})
export default class PageDetails extends Vue {
export class PageDetails extends Vue {
@Prop({ type: Object, required: true })
private readonly pageDto!: PageDto

render (h: CreateElement) {
render () {
return (
<div>
<section-block title='Name'>
Expand All @@ -33,4 +29,3 @@ export default class PageDetails extends Vue {
)
}
}
</script>

0 comments on commit 25485cf

Please sign in to comment.