Responsive Adaptation
Vue 3 Widget includes a complete responsive adaptation solution, components automatically adjust layout and styles according to screen size.
Breakpoint Definitions
| Breakpoint | Width Range | Description |
|---|---|---|
| mobile | < 768px | Mobile devices |
| tablet | 768px - 1024px | Tablet devices |
| desktop | > 1024px | Desktop devices |
variant Property
All responsive-aware components provide the variant property:
type Variant = 'auto' | 'mobile' | 'desktop';
| Value | Description |
|---|---|
'auto' | Automatically detect screen size, dynamic switching (default value) |
'mobile' | Force use mobile style |
'desktop' | Force use desktop style |
Usage Example
<template>
<!-- Automatic adaptation (default) -->
<ControlPanel variant="auto" />
<!-- Force mobile style -->
<ControlPanel variant="mobile" />
<!-- Force desktop style -->
<ConversationList variant="desktop" />
</template>
Application Scenarios
- Embedded scenarios: Force use
mobilemode when embedding in small size areas of PC pages - Debugging scenarios: Test specific platform style performance
- Fixed layout: When you don't want components to change with screen
Responsive Composables
Widget exports responsive detection composables:
<script setup lang="ts">
import {
useIsMobile,
useIsTablet,
useIsDesktop,
useResponsive
} from '@bdky/aaas-pilot-kit-vue3-widget';
</script>
useIsMobile
Detect if it's mobile:
<script setup lang="ts">
import {useIsMobile} from '@bdky/aaas-pilot-kit-vue3-widget';
const isMobile = useIsMobile();
</script>
<template>
<div>
{{ isMobile ? 'Mobile View' : 'Desktop View' }}
</div>
</template>
useIsTablet
Detect if it's tablet:
<script setup lang="ts">
import {useIsTablet} from '@bdky/aaas-pilot-kit-vue3-widget';
const isTablet = useIsTablet();
</script>
<template>
<TabletLayout v-if="isTablet" />
<!-- ... -->
</template>
useIsDesktop
Detect if it's desktop:
<script setup lang="ts">
import {useIsDesktop} from '@bdky/aaas-pilot-kit-vue3-widget';
const isDesktop = useIsDesktop();
</script>
<template>
<div :style="{width: isDesktop ? '800px' : '100%'}">
Content
</div>
</template>
useResponsive
Get complete responsive information:
<script setup lang="ts">
import {useResponsive} from '@bdky/aaas-pilot-kit-vue3-widget';
const {isMobile, isTablet, isDesktop} = useResponsive();
</script>
<template>
<div :class="{
'layout-mobile': isMobile,
'layout-tablet': isTablet,
'layout-desktop': isDesktop
}">
Content
</div>
</template>
CSS Class Name Conventions
Components automatically add corresponding CSS class names based on current mode:
| Class Suffix | Description |
|---|---|
--mobile | Mobile mode |
--desktop | Desktop mode |
/* Example: Customize mobile style */
.apk-control-panel--mobile {
padding: 10px;
}
/* Example: Customize desktop style */
.apk-control-panel--desktop {
padding: 20px;
}
Component Differences Quick Reference
ConversationList
| Feature | PC | Mobile |
|---|---|---|
| Conversation Display | Show all history | Show only latest one |
| Close Button | Visible | Hidden |
| Scroll Follow Button | Visible | Hidden |
| Position | Absolute positioning on left | Relative positioning |
ControlPanel
| Feature | PC | Mobile |
|---|---|---|
| Input Width | 479px fixed | 100% adaptive |
| Button Size | 54-55px | 50px |
| Layout | Centered absolute positioning | Full-width flex |
| Hangup Button | Optional display | Always display |
Input
| Feature | PC | Mobile |
|---|---|---|
| Width | 479px | 100% |
| Height | 55px | 50px |
| Border Radius | 28px | 20px |
| Padding | 24px | 16px |
RecommendedQuestions
| Feature | PC | Mobile |
|---|---|---|
| Layout | Horizontal arrangement | Vertical arrangement |
| Background | Semi-transparent capsule | Transparent |
| Question Item | Text + arrow | Card style |
| Title | Visible | Hidden by default |
| Divider | Visible | Hidden |
StatusOverlay
| Feature | PC | Mobile |
|---|---|---|
| Content Alignment | Vertical center | Top alignment + padding |
| Avatar Size | 120px | 100px |
| Font Size | 16px | 14px |
Conversation
| Feature | PC | Mobile |
|---|---|---|
| Border Radius | 20px | Different border radius for different directions |
| Margin | Left/right 30px | Left/right 39px |
| Background | Semi-transparent | Darker semi-transparent |
Best Practices
1. Prioritize Auto Mode
Unless there are special requirements, recommend using default auto mode to let components automatically adapt:
<template>
<!-- Recommended -->
<ControlPanel />
<!-- Only specify when necessary -->
<ControlPanel variant="mobile" />
</template>
2. Conditional Rendering Optimization
For completely different layouts, use conditional rendering instead of style switching:
<script setup lang="ts">
import {useIsMobile} from '@bdky/aaas-pilot-kit-vue3-widget';
const isMobile = useIsMobile();
</script>
<template>
<!-- Recommended: Completely different component structure -->
<MobileLayout v-if="isMobile">
<ConversationList />
<ControlPanel />
</MobileLayout>
<DesktopLayout v-else>
<Sidebar>
<ConversationList />
</Sidebar>
<Main>
<Subtitle />
<ControlPanel />
</Main>
</DesktopLayout>
</template>
3. Combine Using variant
Keep parent and child component variants consistent:
<script setup lang="ts">
const variant = 'mobile'; // Or get from props/state
</script>
<template>
<Layout direction="vertical">
<ConversationList :variant="variant" />
<ControlPanel :variant="variant" />
</Layout>
</template>
4. Custom Responsive Styles
Use CSS class name hooks to add custom responsive styles:
/* Basic styles */
.apk-control-panel {
transition: all 0.3s ease;
}
/* Mobile special styles */
.apk-control-panel--mobile {
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
}
/* Desktop special styles */
.apk-control-panel--desktop {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
5. Combine with Media Queries
When needing finer control, combine with CSS media queries:
@media (max-width: 768px) {
.my-custom-layout {
flex-direction: column;
}
}
@media (min-width: 769px) and (max-width: 1024px) {
.my-custom-layout {
padding: 20px;
}
}
@media (min-width: 1025px) {
.my-custom-layout {
max-width: 1200px;
margin: 0 auto;
}
}
Related
- PilotKit - Core container component
- Control Components - Control panel responsive details
- Message Components - Message list responsive details
- Style Customization - Custom style guide