mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-06-06 00:18:51 +08:00
feat(components): segmented
组件新增block
属性,可使其适合父元素宽度 (#997)
* feat: `segmented`组件新增`block`属性,可将宽度调整为父元素宽度
This commit is contained in:
parent
17d36f6b9a
commit
bf128f183f
@ -8,6 +8,21 @@
|
|||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pure-segmented-block {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pure-segmented-block .pure-segmented-item {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.pure-segmented-block .pure-segmented-item > .pure-segmented-item-label > span {
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
.pure-segmented-group {
|
.pure-segmented-group {
|
||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -67,6 +82,7 @@
|
|||||||
.pure-segmented-item-label {
|
.pure-segmented-item-label {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.pure-segmented-item-icon svg {
|
.pure-segmented-item-icon svg {
|
||||||
|
@ -10,7 +10,12 @@ import {
|
|||||||
} from "vue";
|
} from "vue";
|
||||||
import type { OptionsType } from "./type";
|
import type { OptionsType } from "./type";
|
||||||
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
|
||||||
import { isFunction, isNumber, useDark } from "@pureadmin/utils";
|
import {
|
||||||
|
isFunction,
|
||||||
|
isNumber,
|
||||||
|
useDark,
|
||||||
|
useResizeObserver
|
||||||
|
} from "@pureadmin/utils";
|
||||||
|
|
||||||
const props = {
|
const props = {
|
||||||
options: {
|
options: {
|
||||||
@ -22,6 +27,11 @@ const props = {
|
|||||||
type: undefined,
|
type: undefined,
|
||||||
require: false,
|
require: false,
|
||||||
default: "0"
|
default: "0"
|
||||||
|
},
|
||||||
|
/** 将宽度调整为父元素宽度 */
|
||||||
|
block: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,6 +87,14 @@ export default defineComponent({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props.block) {
|
||||||
|
useResizeObserver(".pure-segmented", () => {
|
||||||
|
nextTick(() => {
|
||||||
|
handleInit(curIndex.value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => curIndex.value,
|
() => curIndex.value,
|
||||||
index => {
|
index => {
|
||||||
@ -148,7 +166,9 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return () => (
|
return () => (
|
||||||
<div class="pure-segmented">
|
<div
|
||||||
|
class={["pure-segmented", props.block ? "pure-segmented-block" : ""]}
|
||||||
|
>
|
||||||
<div class="pure-segmented-group">
|
<div class="pure-segmented-group">
|
||||||
<div
|
<div
|
||||||
class="pure-segmented-item-selected"
|
class="pure-segmented-item-selected"
|
||||||
|
@ -75,6 +75,26 @@ const optionsDisabled: Array<OptionsType> = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/** block */
|
||||||
|
const optionsBlock: Array<OptionsType> = [
|
||||||
|
{
|
||||||
|
label: "周一"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "周二"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "周三"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "周四"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "周五喜悦,收尾归档,周末倒计时",
|
||||||
|
tip: "周五喜悦,收尾归档,周末倒计时"
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
/** 可设置图标 */
|
/** 可设置图标 */
|
||||||
const optionsIcon: Array<OptionsType> = [
|
const optionsIcon: Array<OptionsType> = [
|
||||||
{
|
{
|
||||||
@ -198,6 +218,9 @@ function onChange({ index, option }) {
|
|||||||
<p class="mb-2">禁用</p>
|
<p class="mb-2">禁用</p>
|
||||||
<Segmented :options="optionsDisabled" />
|
<Segmented :options="optionsDisabled" />
|
||||||
<el-divider />
|
<el-divider />
|
||||||
|
<p class="mb-2">block 属性(将宽度调整为父元素宽度)</p>
|
||||||
|
<Segmented :options="optionsBlock" block />
|
||||||
|
<el-divider />
|
||||||
<p class="mb-2">可设置图标</p>
|
<p class="mb-2">可设置图标</p>
|
||||||
<Segmented :options="optionsIcon" />
|
<Segmented :options="optionsIcon" />
|
||||||
<el-divider />
|
<el-divider />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user