UNPKG

tdesign-vue-next

Version:
222 lines (218 loc) 8.89 kB
/** * tdesign v1.11.5 * (c) 2025 tdesign * @license MIT */ import _defineProperty from '@babel/runtime/helpers/defineProperty'; import { defineComponent, computed, createVNode } from 'vue'; import { CloseCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseIcon, CheckIcon, ErrorIcon } from 'tdesign-icons-vue-next'; import { c as getBackgroundColor } from '../_chunks/dep-56c3d46e.js'; import { CIRCLE_SIZE_PX, PRO_THEME, CIRCLE_FONT_SIZE_RATIO, CIRCLE_SIZE, STATUS_ICON } from './consts/index.js'; import props from './props.js'; import { usePrefixClass } from '../hooks/useConfig.js'; import { useGlobalIcon } from '../hooks/useGlobalIcon.js'; import { u as useTNodeJSX } from '../_chunks/dep-7c56a7f5.js'; import { isString, isObject } from 'lodash-es'; import '@babel/runtime/helpers/toConsumableArray'; import '@babel/runtime/helpers/objectWithoutProperties'; import '@babel/runtime/helpers/slicedToArray'; import '../config-provider/hooks/useConfig.js'; import '../config-provider/utils/context.js'; import '../_chunks/dep-c75b9b8e.js'; import '@babel/runtime/helpers/typeof'; import '../_chunks/dep-caecb55d.js'; import 'dayjs'; import '../utils/render-tnode.js'; var _Progress = defineComponent({ name: "TProgress", props: props, setup: function setup(props2) { var renderTNodeJSX = useTNodeJSX(); var COMPONENT_NAME = usePrefixClass("progress"); var _useGlobalIcon = useGlobalIcon({ CloseCircleFilledIcon: CloseCircleFilledIcon, CheckCircleFilledIcon: CheckCircleFilledIcon, ErrorCircleFilledIcon: ErrorCircleFilledIcon, CloseIcon: CloseIcon, CheckIcon: CheckIcon, ErrorIcon: ErrorIcon }), CloseCircleFilledIcon$1 = _useGlobalIcon.CloseCircleFilledIcon, CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon, ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon, CloseIcon$1 = _useGlobalIcon.CloseIcon, CheckIcon$1 = _useGlobalIcon.CheckIcon, ErrorIcon$1 = _useGlobalIcon.ErrorIcon; var statusStyle = computed(function () { if (!props2.status && props2.percentage >= 100) { return "success"; } return props2.status || "default"; }); var trackBgStyle = computed(function () { var style = {}; if (props2.strokeWidth) { var height = isString(props2.strokeWidth) ? props2.strokeWidth : "".concat(props2.strokeWidth, "px"); style.height = height; style.borderRadius = height; } if (props2.trackColor) { style.backgroundColor = props2.trackColor; } return style; }); var barStyle = computed(function () { return { width: "".concat(props2.percentage, "%"), background: props2.color && getBackgroundColor(props2.color) }; }); var circlePathStyle = computed(function () { var strokeColor = isObject(props2.color) ? "" : props2.color; return { stroke: strokeColor }; }); var circleOuterStyle = computed(function () { var strokeColor = isObject(props2.trackColor) ? "" : props2.trackColor; return { stroke: strokeColor }; }); var diameter = computed(function () { var diameter2 = CIRCLE_SIZE_PX.MEDIUM; if (!props2.size) { return diameter2; } var SMALL = CIRCLE_SIZE.SMALL, LARGE = CIRCLE_SIZE.LARGE, MEDIUM = CIRCLE_SIZE.MEDIUM; switch (props2.size) { case SMALL: diameter2 = CIRCLE_SIZE_PX.SMALL; break; case MEDIUM: diameter2 = CIRCLE_SIZE_PX.MEDIUM; break; case LARGE: diameter2 = CIRCLE_SIZE_PX.LARGE; break; default: diameter2 = Number(props2.size); break; } return diameter2; }); var rPoints = computed(function () { return diameter.value / 2; }); var radius = computed(function () { return rPoints.value - circleStrokeWidth.value / 2; }); var circleStyle = computed(function () { if (props2.theme !== PRO_THEME.CIRCLE) { return {}; } var fontSize = diameter.value * CIRCLE_FONT_SIZE_RATIO.MEDIUM; if (diameter.value <= CIRCLE_SIZE_PX.SMALL) { fontSize = diameter.value * CIRCLE_FONT_SIZE_RATIO.SMALL; } else if (diameter.value >= CIRCLE_SIZE_PX.LARGE) { fontSize = diameter.value * CIRCLE_FONT_SIZE_RATIO.LARGE; } return { width: "".concat(diameter.value, "px"), height: "".concat(diameter.value, "px"), fontSize: "".concat(fontSize, "px") }; }); var circleStrokeWidth = computed(function () { var defaultWidth = props2.size === CIRCLE_SIZE.SMALL ? 4 : 6; return props2.strokeWidth ? Number(props2.strokeWidth) : defaultWidth; }); var strokeDashArr = computed(function () { var radius2 = (diameter.value - circleStrokeWidth.value) / 2; var perimeter = Math.PI * 2 * radius2; var percent = props2.percentage / 100; return "".concat(perimeter * percent, " ").concat(perimeter * (1 - percent)); }); var getIconMap = function getIconMap() { var CIRCLE_ICONS = { success: CheckIcon$1, warning: ErrorIcon$1, error: CloseIcon$1 }; var NORMAL_ICONS = { success: CheckCircleFilledIcon$1, warning: ErrorCircleFilledIcon$1, error: CloseCircleFilledIcon$1 }; return props2.theme === PRO_THEME.CIRCLE ? CIRCLE_ICONS : NORMAL_ICONS; }; var getLabelContent = function getLabelContent() { var labelContent = "".concat(props2.percentage, "%"); var status = props2.status || ""; if (STATUS_ICON.includes(status) && props2.theme !== PRO_THEME.PLUMP) { var components = getIconMap(); var component = components[status]; if (component) { labelContent = createVNode(component, { "class": ["".concat(COMPONENT_NAME.value, "__icon")] }, null); } } return labelContent; }; return function () { var labelContent = createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__info") }, [renderTNodeJSX("label", getLabelContent())]); var PLUMP_SEPARATE = 10; var separateClasses = props2.percentage > PLUMP_SEPARATE ? "".concat(COMPONENT_NAME.value, "--over-ten") : "".concat(COMPONENT_NAME.value, "--under-ten"); return createVNode("div", { "class": COMPONENT_NAME.value }, [props2.theme === PRO_THEME.LINE && createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "--thin ").concat(COMPONENT_NAME.value, "--status--").concat(statusStyle.value) }, [createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__bar"), "style": trackBgStyle.value }, [createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__inner"), "style": barStyle.value }, null)]), labelContent]), props2.theme === PRO_THEME.PLUMP && createVNode("div", { "class": ["".concat(COMPONENT_NAME.value, "__bar ").concat(COMPONENT_NAME.value, "--plump ").concat(separateClasses), _defineProperty({}, "".concat(COMPONENT_NAME.value, "--status--").concat(statusStyle.value), statusStyle.value)], "style": trackBgStyle.value }, [createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "__inner"), "style": barStyle.value }, [props2.percentage > PLUMP_SEPARATE && labelContent]), props2.percentage <= PLUMP_SEPARATE && labelContent]), props2.theme === PRO_THEME.CIRCLE && createVNode("div", { "class": "".concat(COMPONENT_NAME.value, "--circle ").concat(COMPONENT_NAME.value, "--status--").concat(statusStyle.value), "style": circleStyle.value }, [labelContent, createVNode("svg", { "width": diameter.value, "height": diameter.value, "viewBox": "0 0 ".concat(diameter.value, " ").concat(diameter.value) }, [createVNode("circle", { "cx": rPoints.value, "cy": rPoints.value, "r": radius.value, "stroke-width": circleStrokeWidth.value, "fill": "none", "class": ["".concat(COMPONENT_NAME.value, "__circle-outer")], "style": circleOuterStyle.value }, null), props2.percentage > 0 && createVNode("circle", { "cx": rPoints.value, "cy": rPoints.value, "r": radius.value, "stroke-width": circleStrokeWidth.value, "fill": "none", "stroke-linecap": "round", "class": ["".concat(COMPONENT_NAME.value, "__circle-inner")], "transform": "matrix(0,-1,1,0,0,".concat(diameter.value, ")"), "stroke-dasharray": strokeDashArr.value, "style": circlePathStyle.value }, null)])])]); }; } }); export { _Progress as default }; //# sourceMappingURL=progress.js.map