diff --git a/active-rfcs/0000-sfc-style-variables.md b/active-rfcs/0000-sfc-style-variables.md new file mode 100644 index 00000000..c68bcaa9 --- /dev/null +++ b/active-rfcs/0000-sfc-style-variables.md @@ -0,0 +1,100 @@ +- Start Date: 2020-06-29 +- Target Major Version: 2.x & 3.x +- Reference Issues: N/A +- Implementation PR: N/A + +# Summary + +Support injecting component-state-driven CSS variables into Single File Components styles. + +# Basic example + +```html + + + + + +``` + +# Motivation + +Vue SFC styles provide straightforward CSS collocation and encapsulation, but it is purely static - which means up to this point we have no capability of dynamically updating the styles at runtime based on the component's state. + +Now with [most modern browsers supporting native CSS variables](https://caniuse.com/#feat=css-variables), we can leverage it to easily connect the component's state and styles. + +# Detailed design + +The ` +``` + +The inner CSS will be compiled into: + +```css +h1 { + color: var(--6b53742-color); +} +``` + +**Note that when `scoped` and `vars` are both present, all CSS variables are considered to be local.** In order to reference a global CSS variable here, use the `global:` prefix: + +```html + +``` + +The above compiles into: + +```css +h1 { + color: var(--6b53742-color); + font-size: var(--fontSize); +} +``` + +When there is only `scoped` and no `vars`, CSS variables are untouched. This preserves backwards compatibility. + +# Adoption strategy + +This is a fully backwards compatible new feature. However, we should make it clear that it relies on native CSS variables so the user needs to be aware of the browser support range.