From b599407b6701f0c9824611ee0042a28a125166ad Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Sun, 29 Sep 2024 19:18:25 +0300 Subject: [PATCH] Shadows work now --- .../tabs/style_tab/style_tab.js | 37 +++++++++++++++++-- .../tabs/style_tab/style_tab.vue | 11 +++--- src/services/theme_data/css_utils.js | 3 ++ 3 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.js b/src/components/settings_modal/tabs/style_tab/style_tab.js index 6589dc4d..df535c1c 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.js +++ b/src/components/settings_modal/tabs/style_tab/style_tab.js @@ -259,6 +259,7 @@ export default { } }) + // All the editable stuff for the component const editedBackgroundColor = getEditedElement(null, 'background') const editedOpacity = getEditedElement(null, 'opacity') const editedTextColor = getEditedElement('Text', 'textColor') @@ -267,6 +268,34 @@ export default { const editedIconColor = getEditedElement('Icon', 'textColor') const editedShadow = getEditedElement(null, 'shadow') + // Shadow is partially edited outside the ShadowControl + // for better space utilization + const editedSubShadowId = ref(null) + const editedSubShadow = computed(() => { + if (editedShadow.value == null || editedSubShadowId.value == null) return null + return editedShadow.value[editedSubShadowId.value] + }) + + const updateSubShadow = (axis, value) => { + if (!editedSubShadow.value || editedSubShadowId.value == null) return + const newEditedShadow = [...editedShadow.value] + + newEditedShadow[editedSubShadowId.value] = { + ...newEditedShadow[editedSubShadowId.value], + [axis]: value + } + + editedShadow.value = newEditedShadow + } + + const onSubShadow = (id) => { + if (id != null) { + editedSubShadowId.value = id + } else { + editedSubShadow.value = null + } + } + const isBackgroundColorPresent = isElementPresent(null, 'background', '#FFFFFF') const isOpacityPresent = isElementPresent(null, 'opacity', 1) const isTextColorPresent = isElementPresent('Text', 'textColor', '#000000') @@ -293,7 +322,6 @@ export default { directives: stateData.directives || {} } - console.log('PARENT', parent) if (parent) { result.parent = { component: parent @@ -311,8 +339,6 @@ export default { } convert(selectedComponentName.value, allEditedRules[selectedComponentName.value]) - console.log(toValue(allEditedRules)) - console.log(toValue(resultRules)) return resultRules }) @@ -351,13 +377,13 @@ export default { // TODO this is VERY primitive right now, need to make it // support variables, fallbacks etc. const getContrast = (bg, text) => { - console.log('CONTRAST', bg, text) try { const bgRgb = hex2rgb(bg) const textRgb = hex2rgb(text) const ratio = getContrastRatio(bgRgb, textRgb) return { + // TODO this ideally should be part of ratio, text: ratio.toPrecision(3) + ':1', // AA level, AAA level @@ -406,6 +432,9 @@ export default { editedLinkColor, editedIconColor, editedShadow, + editedSubShadow, + onSubShadow, + updateSubShadow, getContrast, isBackgroundColorPresent, isOpacityPresent, diff --git a/src/components/settings_modal/tabs/style_tab/style_tab.vue b/src/components/settings_modal/tabs/style_tab/style_tab.vue index bfe809f4..e4c7d6d4 100644 --- a/src/components/settings_modal/tabs/style_tab/style_tab.vue +++ b/src/components/settings_modal/tabs/style_tab/style_tab.vue @@ -123,11 +123,11 @@ class="component-preview" :showText="componentHas('Text')" :shadowControl="isShadowTabOpen" - :shadow="editedShadow" :previewClass="previewClass" :previewStyle="editorHintStyle" - :disabled="!isShadowPresent" - @update:shadow="({ axis, value }) => updateProperty(axis, value)" + :disabled="!editedSubShadow" + :shadow="editedSubShadow" + @update:shadow="({ axis, value }) => updateSubShadow(axis, value)" />