Progress Component Design Documentation
Overview
The Progress component is a core component in this library used for displaying progress bars. It adheres to the library's consistent design philosophy of "Separation of Concerns" and "Logic Abstraction." Through reactive computation and dynamic style control, it provides a complete and user-friendly progress bar solution.
The Progress component focuses on handling progress bar display, state management, and text formatting functionality. It supports multiple states (success, warning, exception) and dynamic percentage display, offering users a powerful and flexible progress bar management tool.
Design Philosophy
Layered Architecture
The Progress component is strictly designed with a three-layer architecture:
- Structure Layer (
progress.vue) - Responsible for the component's DOM structure and basic layout. - Logic Layer (
progress.ts) - Handles complex reactive computations and interaction logic. - Presentation Layer (
progress.scss) - Defines the component's visual presentation and style rules.
Logic Abstraction
The Progress component abstracts complex logic into core functions and computed properties:
normalizedPercentage- Handles percentage range clamping (0-100).statusClass- Dynamically generates status class names.displayText- Dynamically generates display text.
This design allows the component itself to simply declare the required logic, while the specific computations are handled by the logic functions.
Core Feature Design
Structured Props Design
The props design for the Progress component is clean and straightforward:
export const progressProps = {
/** Current progress percentage */
percentage: {
type: [Number, String],
default: 50,
},
/** Progress bar status */
status: {
type: String as PropType<ProgressStatus | ''>,
default: '',
},
/** Custom text formatting function */
format: {
type: Function as PropType<ProgressFormat>,
default: undefined,
},
}Parameter Descriptions:
- percentage: Supports number or string type, default is
50. - status: Supports
success,warning,exception, or empty string. - format: Allows users to customize the progress bar text format.
Percentage Normalization
The Progress component normalizes the percentage via a computed property:
const normalizedPercentage = computed(() =>
Math.min(100, Math.max(0, Number(props.percentage)))
)This logic ensures the percentage always stays within the 0-100 range, avoiding display issues caused by invalid values.
Style System Design
CSS Variable Control
The Progress component achieves style control through SCSS:
--bar-height- Progress bar height.--bar-radius- Progress bar border radius.--text-color- Text color.
Layout System
The Progress component supports flexible layout control:
- Horizontal Layout - Default Flexbox layout.
- *Padding Control - Adjusts padding via SCSS variables.
State Styles
The Progress component provides corresponding styles for different states:
- Default State - Blue progress bar
#409eff) - Success State - Green progress bar(
#67c23a) - Warning State - Yellow progress bar(
#e6a23c) - Excption State - Red progress bar(
#f56c6c)
Component Structure Design
Overall Structure
The overall structure of the Progress component is as follows:
<div class="my-progress">
<div class="my-progress__bar">
<div class="my-progress__bar-inner" :style="{ width: `${normalizedPercentage}%` }" :class="statusClass"></div>
</div>
<div class="my-progress__text">{{ displayText }}</div>
</div>Component Hierarchy
The Progress component consists of two main parts:
Container- .my-progress - Wraps the entire progress bar.Progress Bar- .my-progress__bar - Contains the progress bar background and inner fill.Progress Bar Inner Fill- .my-progress__bar-inner - Dynamic width and status color.Text Area- .my-progress__text - Displays the current progress text.
Interaction Design
Dynamic Text Formatting
The Progress component supports custom text formatting via the format property:
const displayText = computed(() =>
typeof props.format === 'function'
? props.format(normalizedPercentage.value)
: `${normalizedPercentage.value}%`
)State Switching
The Progress component supports dynamic state switching via the status property:
const statusClass = computed(() => ({
'my-progress__bar-inner--success': props.status === 'success',
'my-progress__bar-inner--warning': props.status === 'warning',
'my-progress__bar-inner--exception': props.status === 'exception',
}))Extensibility Design
The Progress component offers excellent extensibility:
- Data Binding: Dynamically updates progress via the percentage property.
- State Management: Controls progress bar color via the status property.
- Text Formatting: Customizes display text via the format property.
- Style Customization: Adjusts component styles via SCSS variables.
Style Details
The Progress component features the following style handling characteristics:
- Responsive Design: Supports flexible layout adaptation.
- Consistency: Maintains style consistency with other library components.
- Animation Effects: Smooth transition effects when progress bar width changes.
- Accessibility Design: Supports screen readers recognizing progress information.
Performance Optimization
Performance is optimized through:
- Caching computation results using computed properties.
- Moving complex logic into independent functions.
- Avoiding unnecessary re-renders.
- Leveraging Vue 3 Composition API for runtime efficiency.
Design Value
The Progress component embodies the design philosophy of our component library:
- Separation of Concerns: Complete decoupling of structure, style, and logic.
- High Reusability: Abstracting common logic via functions.
- Ease of Maintenance: Clear code structure and naming conventions.
- Strong Extensibility: Support for rich customization options.
- Consistency: Maintains a consistent design language with other components like Button and Alert.