Component Documentation¶
This document provides documentation for the UI components used in the Elome Frontend project.
Overview¶
The Elome Frontend uses Vue.js components organized by feature and following atomic design principles. Components are located in the components/ directory and are organized into subdirectories based on their functionality.
Component Organization¶
Components are organized into the following categories:
- Feature-based components: Located in feature-specific directories (e.g.,
cart/,product/) - UI components: Reusable UI elements located in the
ui/directory - Layout components: Components that define the layout of the application
Cart Components¶
FreeShippingNotice¶
Displays a notice about free shipping eligibility based on the cart total.
Location: components/cart/FreeShippingNotice.vue
Props: None (uses composables for data)
Usage:
Behavior:
- Shows a success message when free shipping is unlocked
- Shows the remaining amount needed to qualify for free shipping when not unlocked
- Conditionally renders based on whether free shipping is enabled and the cart has items
Overlay¶
Displays the cart overlay with cart items, totals, and checkout button.
Location: components/cart/Overlay.vue
Props: None (uses stores for data)
Usage:
Behavior:
- Shows a list of cart items
- Displays cart totals including subtotal, shipping, and total
- Provides buttons for checkout and continuing shopping
- Can be toggled open/closed
UI Components¶
The UI components follow atomic design principles and are organized into:
- Atoms: Basic building blocks (buttons, inputs, icons)
- Molecules: Groups of atoms functioning together (form fields, search bars)
- Organisms: Complex UI components composed of molecules and atoms (navigation menus, product cards)
UiText¶
A text component with various typography styles.
Location: components/ui/atoms/UiText.vue
Props:
variant(String): The typography variant to use (e.g., 'h1', 'h2', 'b1', 'b2')tag(String): The HTML tag to use (defaults based on variant)
Usage:
<template>
<UiText variant="h1">Heading 1</UiText>
<UiText variant="b1" tag="span">Body text</UiText>
</template>
Component Best Practices¶
-
Props Validation: Always define props with proper validation
-
Composables: Use composables for reusable logic
-
Emit Events: Use emit for component communication
-
Slots: Use slots for flexible content
-
Styling: Use scoped styles and CSS variables
Creating New Components¶
When creating new components:
- Place the component in the appropriate directory based on its functionality
- Use the
.vueextension - Include proper documentation using JSDoc comments
- Define props with validation
- Use TypeScript for type safety
- Include unit tests in the
tests/components/directory
Example Component Structure:
<script lang="ts" setup>
/**
* Button component with various styles and sizes
*/
interface Props {
/**
* The button variant
* @default 'primary'
*/
variant?: 'primary' | 'secondary' | 'tertiary';
/**
* The button size
* @default 'md'
*/
size?: 'sm' | 'md' | 'lg';
/**
* Whether the button is disabled
* @default false
*/
disabled?: boolean;
}
const props = withDefaults(defineProps<Props>(), {
variant: 'primary',
size: 'md',
disabled: false
});
const emit = defineEmits<{
(e: 'click', event: MouseEvent): void
}>();
const handleClick = (event: MouseEvent) => {
if (!props.disabled) {
emit('click', event);
}
};
</script>
<template>
<button
:class="[`btn-${variant}`, `btn-${size}`, { 'btn-disabled': disabled }]"
:disabled="disabled"
@click="handleClick"
>
<slot></slot>
</button>
</template>
<style scoped>
.btn-primary {
background-color: var(--color-primary);
color: white;
}
.btn-secondary {
background-color: var(--color-secondary);
color: white;
}
.btn-tertiary {
background-color: transparent;
color: var(--color-primary);
}
.btn-sm {
padding: 0.25rem 0.5rem;
font-size: 0.875rem;
}
.btn-md {
padding: 0.5rem 1rem;
font-size: 1rem;
}
.btn-lg {
padding: 0.75rem 1.5rem;
font-size: 1.125rem;
}
.btn-disabled {
opacity: 0.5;
cursor: not-allowed;
}
</style>