Migrating from ghl-ui Switch to HighRise Toggle
This guide will help you migrate from the ghl-ui Switch component to the new HighRise Toggle component.
Component Implementation Changes
Import Changes
diff
- import { UISwitch } from '@gohighlevel/ghl-ui'
+ import { HLToggle } from '@platform-ui/highrise'
Basic Usage Changes
diff
- <UISwitch
- v-model:value="isEnabled"
- label="Enable notifications"
- />
+ <HLToggle
+ id="notifications-toggle"
+ v-model:value="isEnabled"
+ label="Enable notifications"
+ />
Form Integration Changes
diff
- <UIForm :model="formModel">
- <UIFormItem label="Settings">
- <UISwitch
- v-model:value="formModel.notifications"
- label="Enable notifications"
- />
- </UIFormItem>
- </UIForm>
+ <HLForm :model="formModel" :rules="rules">
+ <HLFormItem
+ label="Settings"
+ path="notifications"
+ required
+ >
+ <HLToggle
+ id="notifications-toggle"
+ v-model:value="formModel.notifications"
+ label="Enable notifications"
+ />
+ </HLFormItem>
+ </HLForm>
Props Changes
ghl-ui Prop | HighRise Prop | Notes |
---|---|---|
size | size | New size options: 'sm', 'md', 'lg' |
status | status | New prop for validation status |
validation-message | validation-message | New prop for validation feedback |
Examples
Basic Toggle
vue
<template>
<HLToggle id="basic-toggle" v-model:value="isEnabled" label="Enable feature" />
</template>
<script setup>
import { ref } from 'vue'
import { HLToggle } from '@platform-ui/highrise'
const isEnabled = ref(false)
</script>
Toggle with Validation
vue
<template>
<HLForm :model="formModel" :rules="rules">
<HLFormItem label="Settings" path="notifications" required>
<HLToggle
id="notifications-toggle"
v-model:value="formModel.notifications"
label="Enable notifications"
:status="validationStatus"
:validation-message="validationMessage"
/>
</HLFormItem>
</HLForm>
</template>
<script setup>
import { ref, computed } from 'vue'
import { HLForm, HLFormItem, HLToggle } from '@platform-ui/highrise'
const formModel = ref({
notifications: false,
})
const validationStatus = computed(() => {
if (!formModel.value.notifications) return 'error'
return undefined
})
const validationMessage = computed(() => {
if (!formModel.value.notifications) return 'Please enable notifications'
return undefined
})
const rules = {
notifications: [
{
required: true,
message: 'Please enable notifications',
trigger: 'change',
},
],
}
</script>
Toggle with Different Sizes
vue
<template>
<div class="space-y-4">
<HLToggle id="toggle-lg" v-model:value="value" size="lg" label="Large Toggle" />
<HLToggle id="toggle-md" v-model:value="value" size="md" label="Medium Toggle" />
<HLToggle id="toggle-sm" v-model:value="value" size="sm" label="Small Toggle" />
</div>
</template>
<script setup>
import { ref } from 'vue'
import { HLToggle } from '@platform-ui/highrise'
const value = ref(false)
</script>
Disabled Toggle
vue
<template>
<HLToggle id="disabled-toggle" v-model:value="isEnabled" label="Disabled Toggle" disabled />
</template>
<script setup>
import { ref } from 'vue'
import { HLToggle } from '@platform-ui/highrise'
const isEnabled = ref(false)
</script>
Best Practices
- Always provide a unique
id
for accessibility - Use
v-model:value
for two-way binding - Implement proper form validation
- Use appropriate size variants
- Consider mobile responsiveness
- Add proper ARIA labels
- Handle loading states appropriately
- Use descriptive labels
- Implement proper error handling
- Consider using tooltips for additional information
- Handle disabled states properly
- Use consistent spacing and alignment
Additional Notes
- The component automatically handles focus states
- Error states are managed through validation status
- Supports keyboard navigation
- Maintains consistent styling with other form components
- Handles disabled states consistently
- Integrates seamlessly with form validation
- Maintains accessibility standards
- Supports custom styling through CSS variables
- Provides clear visual feedback for all states
- Works well on both desktop and mobile devices
- Supports both controlled and uncontrolled modes
- Includes built-in validation support