-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<template> | ||
<div | ||
styleName="@button :disabled mini=isMini" | ||
@click="disabled=!disabled"> | ||
BUTTON | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'demo-button-4', | ||
data() { | ||
return { | ||
disabled: false | ||
} | ||
}, | ||
computed: { | ||
isMini() { | ||
return this.disabled | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style module> | ||
.button { | ||
display: inline-block; | ||
font-size: 18px; | ||
padding: 10px; | ||
border: 1px solid green; | ||
} | ||
.disabled { | ||
opacity: .5; | ||
} | ||
.mini { | ||
font-size: 12px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
export const INJECTED = '__CSSModules__' | ||
|
||
export const INJECT_ATTR = 'styleName' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
/* eslint camelcase: 0 */ | ||
import createElement from './create-element' | ||
import { INJECTED } from './config' | ||
|
||
export default styles => { | ||
return { | ||
beforeCreate() { | ||
if (this[INJECTED]) return | ||
|
||
this[INJECTED] = true | ||
|
||
this.$createElement = createElement.bind(this, { | ||
createElement: this.$createElement, | ||
context: this, | ||
styles | ||
}) | ||
this._c = createElement.bind(this, { | ||
createElement: this._c, | ||
context: this, | ||
styles | ||
}) | ||
} | ||
const CSSModules = styles => ({ | ||
beforeCreate() { | ||
this.original$createElement = this.original$createElement || this.$createElement | ||
this.original_c = this.original_c || this._c | ||
this.$createElement = createElement.bind(this, { | ||
createElement: this.original$createElement, | ||
context: this, | ||
styles | ||
}) | ||
this._c = createElement.bind(this, { | ||
createElement: this.original_c, | ||
context: this, | ||
styles | ||
}) | ||
} | ||
}) | ||
|
||
CSSModules.install = Vue => { | ||
Vue.mixin(CSSModules()) | ||
} | ||
|
||
export default CSSModules |