Skip to content

Commit 51012ac

Browse files
committed
fix(theme-generator): slider position not correct
1 parent d2e44bd commit 51012ac

File tree

5 files changed

+37
-146
lines changed

5 files changed

+37
-146
lines changed

packages/theme-generator/src/common/components/SegmentSelection/index.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
:min="1"
1919
:disabled="disabled"
2020
:max="selectOptions.length - 1"
21-
:value="step"
21+
:value="sliderValue"
2222
@change="handleSliderChange"
2323
:label="renderLabel"
2424
:tooltipProps="{ attach: handleAttach }"
@@ -76,6 +76,13 @@ export default {
7676
innerSelectOptions: this.selectOptions,
7777
};
7878
},
79+
computed: {
80+
sliderValue() {
81+
const maxValue = this.selectOptions.length - 1;
82+
// 如果 step 超过 max(自定义选项),依旧显示 max 值
83+
return this.step > maxValue ? maxValue : this.step;
84+
},
85+
},
7986
watch: {
8087
value(val) {
8188
this.step = val;

packages/theme-generator/src/font-panel/components/FontSizeAdjust.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
<div>
33
<!-- 顶部调整 -->
44
<SegmentSelection
5+
v-model="step"
56
:selectOptions="FONT_SIZE_OPTIONS"
67
:suspendedLabels="FONT_SIZE_LABELS"
7-
v-model="step"
88
:disabled="segmentSelectionDisabled"
9-
@enable="segmentSelectionDisabled = false"
109
>
1110
<template v-slot:left>
1211
<div class="font-panel__round-tag-left">Aa</div>

packages/theme-generator/src/font-panel/components/LineHeightAdjust.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
<div>
33
<!-- 顶部调整 -->
44
<SegmentSelection
5-
:style="{ margin: '8px 0' }"
65
v-if="tokenType === 'plus'"
76
v-model="step"
7+
:style="{ margin: '8px 0' }"
88
:selectOptions="lineHeightOptions"
99
:suspendedLabels="lineHeightLabels"
1010
:disabled="segmentSelectionDisabled"
11-
@enable="segmentSelectionDisabled = false"
1211
>
1312
<template v-slot:left>
1413
<div class="font-panel__round-tag-left"><p>Aa</p></div>

packages/theme-generator/src/radius-panel/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
<div class="radius-content__main">
1212
<p class="radius-content__title">{{ lang.borerRadius.radiusSize }}</p>
1313
<SegmentSelection
14+
v-model="step"
1415
:selectOptions="RADIUS_OPTIONS"
1516
:suspendedLabels="RADIUS_LABELS"
16-
v-model="step"
1717
:disabled="segmentSelectionDisabled"
18-
@enable="segmentSelectionDisabled = false"
1918
>
2019
<template v-slot:left>
2120
<div class="radius-content__round-tag-left" :class="{ disabled: segmentSelectionDisabled }"></div>

packages/theme-generator/src/shadow-panel/index.vue

Lines changed: 26 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,19 @@
1010
<div class="shadow-content__content" :style="contentStyle">
1111
<div class="shadow-content__main">
1212
<p class="shadow-content__title">{{ lang.shadow.title }}</p>
13-
<!-- 顶部调整 -->
14-
<div :style="{ display: 'flex' }">
15-
<div class="shadow-panel__round">
16-
<div class="shadow-panel__round-tag">
17-
<div class="shadow-panel__round-box" :style="{ 'box-shadow': leftShadow }"></div>
18-
</div>
19-
<div class="shadow-panel__round-slider">
20-
<div
21-
class="slider-split"
22-
:key="i"
23-
:style="{
24-
opacity: i == 0 || i === selectOptions.length - 2 ? 0 : 1,
25-
}"
26-
v-for="(v, i) in selectOptions.slice(0, selectOptions.length - 1)"
27-
></div>
28-
29-
<t-slider
30-
:min="0"
31-
:max="selectOptions.length - 2"
32-
:value="step"
33-
:label="renderLabel"
34-
:disabled="forbidden"
35-
:tooltipProps="{ attach: handleAttach }"
36-
@change="handleSliderChange"
37-
></t-slider>
38-
</div>
39-
<div class="shadow-panel__round-tag">
40-
<div class="shadow-panel__round-box" :style="{ 'box-shadow': rightShadow }"></div>
41-
</div>
42-
</div>
43-
<t-select
44-
class="shadow-panel__select"
45-
:options="selectOptions"
46-
v-model="step"
47-
:keys="isEn ? { label: 'enLabel' } : null"
48-
:popup-props="{ attach: handleAttach }"
49-
style="width: 82px"
50-
></t-select>
51-
</div>
13+
<SegmentSelection
14+
v-model="step"
15+
:selectOptions="selectOptions"
16+
:suspendedLabels="suspendedLabels"
17+
:disabled="forbidden"
18+
>
19+
<template #left>
20+
<div class="shadow-panel__round-box" :style="{ 'box-shadow': leftShadow }"></div>
21+
</template>
22+
<template #right>
23+
<div class="shadow-panel__round-box" :style="{ 'box-shadow': rightShadow }"></div>
24+
</template>
25+
</SegmentSelection>
5226
<shadow-card
5327
v-for="(shadow, i) in shadowPalette"
5428
:key="i"
@@ -63,11 +37,10 @@
6337
</template>
6438

6539
<script lang="jsx">
66-
import { Select as TSelect, Slider as TSlider } from 'tdesign-vue';
67-
40+
import { SegmentSelection } from '@/common/components';
6841
import { langMixin } from '@/common/i18n';
6942
import { getOptionFromLocal, modifyToken, updateLocalOption } from '@/common/themes';
70-
import { getTokenValue, handleAttach } from '@/common/utils';
43+
import { getTokenValue } from '@/common/utils';
7144
7245
import {
7346
ShadowSelect,
@@ -84,8 +57,7 @@ export default {
8457
top: Number,
8558
},
8659
components: {
87-
TSlider,
88-
TSelect,
60+
SegmentSelection,
8961
ShadowCard,
9062
},
9163
mixins: [langMixin],
@@ -95,10 +67,15 @@ export default {
9567
selectOptions: ShadowSelect,
9668
selfDefined: ShadowSelectType,
9769
step: getOptionFromLocal('shadow') || ShadowSelectType.Default,
70+
suspendedLabels: {},
9871
};
9972
},
10073
created() {
10174
this.shadowTypeDetail = ShadowTypeDetail;
75+
this.suspendedLabels = this.selectOptions.reduce((acc, option) => {
76+
acc[option.value] = this.isEn ? option.enLabel : option.label;
77+
return acc;
78+
}, {});
10279
},
10380
computed: {
10481
contentStyle() {
@@ -155,14 +132,6 @@ export default {
155132
},
156133
},
157134
methods: {
158-
handleAttach,
159-
handleSliderChange(v) {
160-
if (this.forbidden) return;
161-
this.step = v;
162-
},
163-
renderLabel() {
164-
return this.selectOptions[this.step].label;
165-
},
166135
// 拆分 box-shadow 的值 0 1px 10px rgba(0, 0, 0, 0.05), 0 4px 5px rgba(0, 0, 0, 8%), 0 2px 4px -1px rgba(0, 0, 0, 12%)
167136
splitShadowValue(data) {
168137
const tempData = `${data},`;
@@ -248,93 +217,11 @@ export default {
248217
}
249218
}
250219
.shadow-panel {
251-
&__round {
252-
display: flex;
253-
height: 32px;
254-
> div {
255-
display: flex;
256-
background-color: var(--bg-color-theme-secondary);
257-
margin-right: 2px;
258-
align-items: center;
259-
justify-content: center;
260-
}
261-
&-tag {
262-
height: 100%;
263-
width: 32px;
264-
color: var(--text-primary);
265-
&:first-child {
266-
border-radius: 9px 0px 0px 9px;
267-
}
268-
&:last-child {
269-
border-radius: 0px 9px 9px 0px;
270-
margin-right: 0;
271-
}
272-
}
273-
&-box {
274-
width: 20px;
275-
height: 20px;
276-
background: var(--bg-color-theme-surface);
277-
border-radius: 3px;
278-
}
279-
&-slider {
280-
width: 76px;
281-
padding: 6px;
282-
position: relative;
283-
display: flex;
284-
justify-content: space-between !important;
285-
.slider-split {
286-
background-color: var(--bg-color-theme-secondary);
287-
width: 2px;
288-
height: 8px;
289-
z-index: 2;
290-
}
291-
/deep/ .t-slider__container {
292-
position: absolute;
293-
top: 6px;
294-
width: 60px;
295-
left: 8px;
296-
}
297-
/deep/ .t-slider {
298-
padding: 6px 0;
299-
}
300-
/deep/ .t-slider__rail {
301-
height: 8px;
302-
background-color: var(--bg-color-theme-tertiary);
303-
}
304-
/deep/ .t-slider__track {
305-
height: 8px;
306-
}
307-
/deep/ .t-slider__button {
308-
box-shadow: var(--shadow-1);
309-
border-color: var(--bg-color-tag);
310-
}
311-
}
312-
}
313-
&__select {
314-
text-align: center;
315-
padding: 0;
316-
margin-left: 8px;
317-
/deep/ .t-input {
318-
background: var(--bg-color-theme-secondary);
319-
border: 1px solid transparent;
320-
height: 32px;
321-
border-radius: 9px;
322-
padding: 0 8px;
323-
transition: border-color 0.2s;
324-
}
325-
/deep/ .t-select:hover {
326-
border-color: var(--component-border);
327-
}
328-
/deep/ .t-is-active {
329-
border-color: var(--brand-main) !important;
330-
}
331-
/deep/ .t-select__right-icon {
332-
color: var(--text-placeholder) !important;
333-
}
334-
335-
/deep/ .t-select__single {
336-
margin-left: 0;
337-
}
220+
&__round-box {
221+
width: 20px;
222+
height: 20px;
223+
background: var(--bg-color-theme-surface);
224+
border-radius: 3px;
338225
}
339226
}
340227
</style>

0 commit comments

Comments
 (0)