Skip to content

Commit 2b0ddcd

Browse files
authored
Merge pull request #2 from DeepFundAI/codex/add-automatic-light-color-calculation
feat(theme): toggle primary light color auto calc
2 parents 6f9eedb + 2276d0a commit 2b0ddcd

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

eslint.config.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,10 @@ export default defineConfigWithVueTs(
2424
...pluginVitest.configs.recommended,
2525
files: ['src/**/__tests__/*'],
2626
},
27+
{
28+
rules: {
29+
'vue/multi-word-component-names': 'off',
30+
},
31+
},
2732
skipFormatting,
2833
)

src/views/ThemeEditor.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@
1616
:inactive-icon="Sunny"
1717
style="margin-right: 10px"
1818
/>
19+
<el-switch
20+
v-model="autoPrimaryLight"
21+
active-text="自动色值"
22+
inactive-text="手动"
23+
style="margin-right: 10px"
24+
/>
1925
<el-button @click="saveObjectAsCss('cssVar.css')">导出</el-button>
2026
<!-- <el-button>编辑</el-button> -->
2127
<el-button type="primary">保存</el-button>
@@ -348,6 +354,7 @@ import Github from '@/components/icons/Github.vue'
348354
const activeName = ref('first')
349355
const activeNames = ref(['1'])
350356
const modifyCssVar: Ref<Record<string, string>> = ref({})
357+
const autoPrimaryLight = ref(true)
351358
352359
const isDark = useDark({
353360
selector: 'html',
@@ -358,10 +365,38 @@ const isDark = useDark({
358365
storage: localStorage,
359366
})
360367
368+
const mixColor = (color1: string, color2: string, weight: number) => {
369+
const w = Math.max(Math.min(weight, 1), 0)
370+
const toHex = (color: string) => color.replace('#', '')
371+
const c1 = toHex(color1)
372+
const c2 = toHex(color2)
373+
const r = Math.round(parseInt(c1.slice(0, 2), 16) * w + parseInt(c2.slice(0, 2), 16) * (1 - w))
374+
const g = Math.round(parseInt(c1.slice(2, 4), 16) * w + parseInt(c2.slice(2, 4), 16) * (1 - w))
375+
const b = Math.round(parseInt(c1.slice(4, 6), 16) * w + parseInt(c2.slice(4, 6), 16) * (1 - w))
376+
return `#${r.toString(16).padStart(2, '0')}${g
377+
.toString(16)
378+
.padStart(2, '0')}${b.toString(16).padStart(2, '0')}`
379+
}
380+
361381
const updateCssVar = (props: CssVarInfo) => {
362382
const value = props.value + props.unit
363383
setCssVarValue(props.cssVar, value)
364384
modifyCssVar.value[props.cssVar] = value
385+
386+
if (props.cssVar === '--el-color-primary' && autoPrimaryLight.value) {
387+
const primaryGroup = color.find((c) => c.type === 'primary')?.data ?? []
388+
const computeLight = (light: number) => {
389+
const cssVar = `--el-color-primary-light-${light}`
390+
const target = primaryGroup.find((d) => d.cssVar === cssVar)
391+
if (target) {
392+
const mix = mixColor('#ffffff', props.value, light / 10)
393+
target.value = mix
394+
setCssVarValue(cssVar, mix)
395+
modifyCssVar.value[cssVar] = mix
396+
}
397+
}
398+
;[3, 5, 7, 8, 9].forEach(computeLight)
399+
}
365400
}
366401
367402
const setCssVarValue = (name: string, value: string) => {

src/views/components/data/Tree.vue

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,28 @@
2424
</template>
2525
<script lang="ts" setup>
2626
import type Node from 'element-plus/es/components/tree/src/model/node'
27-
import type { DragEvents } from 'element-plus/es/components/tree/src/model/useDragNode'
2827
import type { AllowDropType, NodeDropType } from 'element-plus/es/components/tree/src/tree.type'
2928
30-
const handleDragStart = (node: Node, ev: DragEvents) => {
29+
const handleDragStart = (node: Node) => {
3130
console.log('drag start', node)
3231
}
33-
const handleDragEnter = (draggingNode: Node, dropNode: Node, ev: DragEvents) => {
32+
const handleDragEnter = (draggingNode: Node, dropNode: Node) => {
3433
console.log('tree drag enter:', dropNode.label)
3534
}
36-
const handleDragLeave = (draggingNode: Node, dropNode: Node, ev: DragEvents) => {
35+
const handleDragLeave = (draggingNode: Node, dropNode: Node) => {
3736
console.log('tree drag leave:', dropNode.label)
3837
}
39-
const handleDragOver = (draggingNode: Node, dropNode: Node, ev: DragEvents) => {
38+
const handleDragOver = (draggingNode: Node, dropNode: Node) => {
4039
console.log('tree drag over:', dropNode.label)
4140
}
4241
const handleDragEnd = (
4342
draggingNode: Node,
4443
dropNode: Node,
45-
dropType: NodeDropType,
46-
ev: DragEvents
44+
dropType: NodeDropType
4745
) => {
4846
console.log('tree drag end:', dropNode && dropNode.label, dropType)
4947
}
50-
const handleDrop = (draggingNode: Node, dropNode: Node, dropType: NodeDropType, ev: DragEvents) => {
48+
const handleDrop = (draggingNode: Node, dropNode: Node, dropType: NodeDropType) => {
5149
console.log('tree drop:', dropNode.label, dropType)
5250
}
5351
const allowDrop = (draggingNode: Node, dropNode: Node, type: AllowDropType) => {

src/views/components/form/Upload.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const handleExceed: UploadProps['onExceed'] = (files, uploadFiles) => {
9090
)
9191
}
9292
93-
const beforeRemove: UploadProps['beforeRemove'] = (uploadFile, uploadFiles) => {
93+
const beforeRemove: UploadProps['beforeRemove'] = (uploadFile) => {
9494
return ElMessageBox.confirm(`Cancel the transfer of ${uploadFile.name} ?`).then(
9595
() => true,
9696
() => false

tailwind.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,8 @@ export default {
290290
'justify-content': 'space-between',
291291
'align-items': 'center',
292292
},
293-
}),
294-
addVariant('black', '.dark &')
293+
})
294+
addVariant('black', '.dark &')
295295
}),
296296
],
297297
}

0 commit comments

Comments
 (0)