This repository has been archived by the owner on Aug 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
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
1 parent
eacff52
commit 3e7f575
Showing
14 changed files
with
207 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { directiveName } from '@/util'; | ||
import Vue from 'vue'; | ||
|
||
type Side = keyof { | ||
top: 'top', | ||
right: 'right', | ||
bottom: 'bottom', | ||
left: 'left', | ||
}; | ||
|
||
const sizeMapping = {none: 'none', tiny: 'tiny', small: 'small', medium: 'medium', large: 'large'}; | ||
type Size = keyof typeof sizeMapping; | ||
const Sizes = Object.keys(sizeMapping) as Size[]; | ||
const isSize = (value: any): value is Size | undefined => value === undefined || Sizes.includes(value); | ||
|
||
type PaddingModifiers = { | ||
top?: boolean; left?: boolean; right?: boolean; bottom?: boolean; | ||
}; | ||
|
||
type DesignClass = 'padding' | 'margin'; | ||
|
||
const designClass = (prefix: DesignClass, size: Size, side?: Side) => side == null ? `fd-has-${prefix}-${size}` : `fd-has-${prefix}-${side}-${size}`; | ||
const designClasses = (prefix: DesignClass, size: Size, modifiers: PaddingModifiers = {}): string[] => { | ||
const {top, left, right, bottom} = modifiers; | ||
if(top == null && left == null && right == null && bottom == null) { | ||
return [designClass(prefix, size)]; | ||
} | ||
const classes: string[] = []; | ||
if(top === true) { classes.push(designClass(prefix, size, 'top')); } | ||
if(bottom === true) { classes.push(designClass(prefix, size, 'bottom')); } | ||
if(left === true) { classes.push(designClass(prefix, size, 'left')); } | ||
if(right === true) { classes.push(designClass(prefix, size, 'right')); } | ||
return classes; | ||
}; | ||
const paddingClasses = (size: Size, modifiers: PaddingModifiers = {}): string[] => designClasses('padding', size, modifiers); | ||
const marginClasses = (size: Size, modifiers: PaddingModifiers = {}): string[] => designClasses('margin', size, modifiers); | ||
|
||
/* | ||
Usage: | ||
v-padding:small | ||
v-padding:small.left.right.bottom | ||
^---^ ^---------------^ | ||
arg modifiers | ||
*/ | ||
export const padding = Vue.directive(directiveName('padding'), ({ classList }, binding) => { | ||
const { arg, modifiers } = binding; | ||
if(!isSize(arg)) { return; } | ||
const size = arg; | ||
classList.add(...paddingClasses(size, modifiers)); | ||
}); | ||
|
||
export const margin = Vue.directive(directiveName('margin'), ({ classList }, binding) => { | ||
const { arg, modifiers } = binding; | ||
if(!isSize(arg)) { return; } | ||
const size = arg; | ||
classList.add(...marginClasses(size, modifiers)); | ||
}); | ||
|
||
type FontWeight = 'light' | 'bold' | 'normal'; | ||
const isFontWeight = (value: any): value is FontWeight => value === 'light' || value === 'bold' || value === 'normal'; | ||
export const fontWeight = Vue.directive(directiveName('font-weight'), ({ classList }, binding) => { | ||
const { arg } = binding; | ||
if(!isFontWeight(arg)) { return; } | ||
classList.add(`fd-has-font-weight-${arg}`); | ||
}); | ||
|
||
type FontFamily = 'body' | 'header' | 'code'; | ||
const isFontFamily = (value: any): value is FontFamily => ['body', 'header', 'code'].includes(value); | ||
export const fontFamily = Vue.directive(directiveName('font-family'), ({ classList }, binding) => { | ||
const { arg } = binding; | ||
if(!isFontFamily(arg)) { return; } | ||
classList.add(`fd-has-font-family-${arg}`); | ||
}); | ||
|
||
const typeMapping = { '-1': 'minus-1', '0': '0', '1': '1', '2': '2', '3': '3', '4': '4', '5': '5', '6': '6' }; | ||
type Type = keyof typeof typeMapping; | ||
const Types = Object.keys(typeMapping) as Type[]; | ||
const isType = (value: any): value is Type => Types.includes(value); | ||
export const type = Vue.directive(directiveName('type'), ({ classList }, binding) => { | ||
const { arg } = binding; | ||
if(!isType(arg)) { return 'fd-has-type'; } | ||
classList.add(`fd-has-type-${typeMapping[arg]}`); | ||
}); |
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,2 +1,20 @@ | ||
import { PluginObject } from 'vue'; | ||
import { hasBackgroundColor } from './has-background-color'; | ||
import { icon } from './icon'; | ||
import { padding, margin, fontWeight, fontFamily } from './design-system-utilities'; | ||
|
||
export * from './has-background-color'; | ||
export * from './icon'; | ||
export * from './design-system-utilities'; | ||
|
||
export default { | ||
install(Vue) { | ||
Vue.directive('bg', hasBackgroundColor); | ||
Vue.directive('hasBackgroundColor', hasBackgroundColor); | ||
Vue.directive('icon', icon); | ||
Vue.directive('padding', padding); | ||
Vue.directive('margin', margin); | ||
Vue.directive('font-weight', fontWeight); | ||
Vue.directive('font-family', fontFamily); | ||
}, | ||
} as PluginObject<{}>; |
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
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,21 @@ | ||
<title>Margin (mixed)</title> | ||
<tip>Supported size classes: `none`, `tiny`, `small`, `medium`, `large`. By default the size is applied to all sides. You can constrain the sides by using the modifiers `top`, `left`, `bottom` and `right`.</tip> | ||
<template> | ||
<div class="container"> | ||
<div v-margin:small> | ||
v-margin:small | ||
</div> | ||
|
||
<div v-margin:small.top.left> | ||
v-margin:small.top.left | ||
</div> | ||
|
||
<div v-margin:small.top.left v-margin:medium.bottom.right> | ||
v-margin:small.top.left v-margin:medium.bottom.right | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.container div { border: 1px solid #cccccc; font-family: monospace; background-color: #efefef; } | ||
</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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<title>Padding (mixed)</title> | ||
<tip>Supported size classes: `none`, `tiny`, `small`, `medium`, `large`. By default the size is applied to all sides. You can constrain the sides by using the modifiers `top`, `left`, `bottom` and `right`.</tip> | ||
|
||
<template> | ||
<div class="container"> | ||
<div v-padding:small> | ||
v-padding:small | ||
</div> | ||
<div v-padding:small.top.left> | ||
v-padding:small.top.left | ||
</div> | ||
<div v-padding:small.top.left v-padding:medium.bottom.right> | ||
v-padding:small.top.left v-padding:medium.bottom.right | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.container div { font-family: monospace; background-color: #efefef; border: 1px #cccccc solid; margin-block-end: 1rem; } | ||
</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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<title>Removing Padding</title> | ||
<tip>Use `v-padding` multiple times to selectively remove padding.</tip> | ||
|
||
<template> | ||
<div class="container"> | ||
<div v-padding:medium v-padding:none.left> | ||
v-padding:medium v-padding:none.left | ||
</div> | ||
<div v-padding:medium v-padding:none.left.bottom> | ||
v-padding:medium v-padding:none.left.bottom | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.container div { font-family: monospace; background-color: #efefef; border: 1px #cccccc solid; margin-block-end: 1rem; } | ||
</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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<title>Type Weight</title> | ||
|
||
<template> | ||
<div> | ||
<p v-font-weight:light>This is font with weight light</p> | ||
<p v-font-weight:normal>This is font with weight normal</p> | ||
<p v-font-weight:bold>This is font with weight bold</p> | ||
</div> | ||
</template> |
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,9 @@ | ||
<title>Type Family</title> | ||
|
||
<template> | ||
<div> | ||
<p v-font-family:body>This is body text</p> | ||
<p v-font-family:header>This is header text</p> | ||
<p v-font-family:code>This is code text</p> | ||
</div> | ||
</template> |
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,14 @@ | ||
<title>Type</title> | ||
|
||
<template> | ||
<div> | ||
<p v-type:-1>This is text type size -1</p> | ||
<p v-type:0>This is text type size 0</p> | ||
<p v-type:1>This is text type size 1</p> | ||
<p v-type:2>This is text type size 2</p> | ||
<p v-type:3>This is text type size 3</p> | ||
<p v-type:4>This is text type size 4</p> | ||
<p v-type:5>This is text type size 5</p> | ||
<p v-type:6>This is text type size 6</p> | ||
</div> | ||
</template> |
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,3 @@ | ||
import { ExampleCollectionFunction } from '../types'; | ||
|
||
export const plugin: ExampleCollectionFunction = () => ({ experimental: true, icon: 'action' }); |
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
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