forked from morfeojs/morfeo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added slices and optimizations to dev tool
- Loading branch information
Showing
12 changed files
with
186 additions
and
80 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 |
---|---|---|
@@ -1,26 +1,9 @@ | ||
import { theme } from '@morfeo/web'; | ||
import { injectStyle } from './injectStyle'; | ||
import { makeRow } from './makeRow'; | ||
|
||
export function colors() { | ||
const { colors } = theme.get(); | ||
const colorKeys = Object.keys(colors); | ||
const colorSlice = document.getElementById('colors'); | ||
colorKeys.forEach(key => { | ||
const colorBlock = document.createElement('div'); | ||
colorBlock.classList.add('item', 'column', 'centered'); | ||
const colorBall = document.createElement('div'); | ||
colorBall.classList.add('circle'); | ||
const colorName = document.createElement('span'); | ||
const colorValue = document.createElement('span'); | ||
|
||
injectStyle(colorBall, { bg: key }); | ||
|
||
colorName.innerHTML = key; | ||
colorValue.innerHTML = theme.getValue('colors', key); | ||
|
||
colorBlock.appendChild(colorName); | ||
colorBlock.appendChild(colorBall); | ||
colorBlock.appendChild(colorValue); | ||
colorSlice.appendChild(colorBlock); | ||
makeRow({ | ||
slice: 'colors', | ||
property: 'bg', | ||
kind: 'circle', | ||
}); | ||
} |
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,13 @@ | ||
import { theme } from '@morfeo/web'; | ||
import { injectStyle } from './injectStyle'; | ||
import { parsers } from '@morfeo/web'; | ||
import { makeRow } from './makeRow'; | ||
|
||
export function gradients() { | ||
const gradients = theme.getSlice('gradients'); | ||
const gradientKeys = Object.keys(gradients); | ||
const gradientSlice = document.getElementById('gradients'); | ||
gradientKeys.forEach(key => { | ||
const gradientBlock = document.createElement('div'); | ||
gradientBlock.classList.add('item', 'column', 'centered'); | ||
const circle = document.createElement('div'); | ||
circle.classList.add('circle'); | ||
const gradientName = document.createElement('span'); | ||
|
||
injectStyle(circle, { gradient: key }); | ||
|
||
gradientName.innerHTML = key; | ||
|
||
gradientBlock.appendChild(gradientName); | ||
gradientBlock.appendChild(circle); | ||
gradientSlice.appendChild(gradientBlock); | ||
makeRow({ | ||
slice: 'gradients', | ||
property: 'gradient', | ||
kind: 'circle', | ||
getValue(_, value) { | ||
return parsers.resolve({ gradient: value })['background']; | ||
}, | ||
}); | ||
} |
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,4 +1,22 @@ | ||
import { radii } from './radii'; | ||
import { colors } from './colors'; | ||
import { gradients } from './gradients'; | ||
import { sizes, spaces } from './sizes'; | ||
import { components } from './components'; | ||
import { shadows } from './shadows'; | ||
|
||
export * from './sizes'; | ||
export * from './radii'; | ||
export * from './colors'; | ||
export * from './gradients'; | ||
export * from './components'; | ||
|
||
export const all = [ | ||
colors, | ||
sizes, | ||
radii, | ||
spaces, | ||
shadows, | ||
gradients, | ||
components, | ||
]; |
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,39 @@ | ||
import { theme } from '@morfeo/web'; | ||
import { injectStyle } from './injectStyle'; | ||
|
||
export function makeRow({ | ||
slice, | ||
kind = 'square', | ||
property, | ||
showValue = true, | ||
getValue, | ||
style = {}, | ||
}) { | ||
const themeSlice = theme.getSlice(slice); | ||
const sliceKeys = Object.keys(themeSlice); | ||
const sliceElement = document.getElementById(slice); | ||
sliceKeys.forEach(key => { | ||
const block = document.createElement('div'); | ||
block.classList.add('item', 'column', 'centered'); | ||
const element = document.createElement('div'); | ||
element.classList.add(kind); | ||
const elementName = document.createElement('span'); | ||
|
||
injectStyle(element, { ...style, [property]: key }); | ||
|
||
elementName.innerHTML = key; | ||
|
||
block.appendChild(elementName); | ||
block.appendChild(element); | ||
|
||
if (showValue) { | ||
const elementValue = document.createElement('span'); | ||
elementValue.innerHTML = getValue | ||
? getValue(slice, key) | ||
: theme.getValue(slice, key); | ||
block.appendChild(elementValue); | ||
} | ||
|
||
sliceElement.appendChild(block); | ||
}); | ||
} |
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,8 @@ | ||
import { makeRow } from './makeRow'; | ||
|
||
export function radii() { | ||
makeRow({ | ||
slice: 'radii', | ||
property: 'borderRadius', | ||
}); | ||
} |
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,12 @@ | ||
import { parsers } from '@morfeo/web'; | ||
import { makeRow } from './makeRow'; | ||
|
||
export function shadows() { | ||
makeRow({ | ||
slice: 'shadows', | ||
property: 'shadow', | ||
getValue(_, value) { | ||
return parsers.resolve({ shadow: value })['boxShadow']; | ||
}, | ||
}); | ||
} |
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,37 +1,9 @@ | ||
import { theme } from '@morfeo/web'; | ||
import { injectStyle } from './injectStyle'; | ||
|
||
function makeRow(themeKey, pageClass) { | ||
const values = theme.getSlice(themeKey); | ||
const keys = Object.keys(values); | ||
const slice = document.getElementById(pageClass); | ||
keys.forEach(key => { | ||
const block = document.createElement('div'); | ||
block.classList.add('item', 'column', 'centered'); | ||
const square = document.createElement('div'); | ||
square.classList.add('square'); | ||
const name = document.createElement('span'); | ||
const value = document.createElement('span'); | ||
|
||
injectStyle(square, { | ||
bg: '#2c3e50', | ||
width: theme.getValue(themeKey, key), | ||
}); | ||
|
||
name.innerHTML = key; | ||
value.innerHTML = theme.getValue(themeKey, key); | ||
|
||
block.appendChild(name); | ||
block.appendChild(square); | ||
block.appendChild(value); | ||
slice.appendChild(block); | ||
}); | ||
} | ||
import { makeRow } from './makeRow'; | ||
|
||
export function spaces() { | ||
makeRow('space', 'spaces'); | ||
makeRow({ slice: 'space', property: 'width' }); | ||
} | ||
|
||
export function sizes() { | ||
makeRow('sizes', 'sizes'); | ||
makeRow({ slice: 'sizes', property: 'width' }); | ||
} |
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 @@ | ||
const collapseButtons = document.querySelectorAll('.collapse'); | ||
|
||
collapseButtons.forEach(button => { | ||
button.addEventListener('click', e => { | ||
const target = button.getAttribute('data-target'); | ||
|
||
const collapsible = document.getElementById(target); | ||
if (!collapsible) { | ||
return; | ||
} | ||
|
||
if (collapsible.classList.contains('collapsed')) { | ||
collapsible.classList.remove('collapsed'); | ||
button.innerHTML = `▲`; | ||
} else { | ||
collapsible.classList.add('collapsed'); | ||
button.innerHTML = `▼`; | ||
} | ||
}); | ||
}); |
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