Migrating from ghl-ui Checkbox to HighRise Checkbox
This guide will help you migrate from the ghl-ui Checkbox component to the new HighRise Checkbox component.
Component Implementation Changes
Import Changes
diff
- import { UICheckbox } from '@gohighlevel/ghl-ui'
+ import { HLCheckbox } from '@platform-ui/highrise'
Basic Usage Changes
diff
- <UICheckbox
- v-model:checked="checked"
- label="Accept terms"
- />
+ <HLCheckbox
+ id="terms-checkbox"
+ v-model:checked="checked"
+ label="Accept terms"
+ />
Form Integration Changes
diff
- <UIForm :model="formModel">
- <UIFormItem label="Preferences">
- <UICheckbox
- v-model:checked="formModel.acceptTerms"
- label="Accept terms and conditions"
- />
- </UIFormItem>
- </UIForm>
+ <HLForm :model="formModel" :rules="rules">
+ <HLFormItem
+ label="Preferences"
+ path="acceptTerms"
+ required
+ >
+ <HLCheckbox
+ id="terms-checkbox"
+ v-model:checked="formModel.acceptTerms"
+ label="Accept terms and conditions"
+ />
+ </HLFormItem>
+ </HLForm>
Props Changes
ghl-ui Prop | HighRise Prop | Notes |
---|---|---|
size | size | 'lg' | 'md' | 'sm' | 'xs' | '2xs' | '3xs' Extended size options |
Examples
Basic Checkbox
vue
<template>
<HLCheckbox id="basic-checkbox" v-model:checked="checked" label="Accept terms and conditions" />
</template>
<script setup>
import { ref } from 'vue'
import { HLCheckbox } from '@platform-ui/highrise'
const checked = ref(false)
</script>
Checkbox with Validation
vue
<template>
<HLForm :model="formModel" :rules="rules">
<HLFormItem label="Terms" path="acceptTerms" required>
<HLCheckbox
id="terms-checkbox"
v-model:checked="formModel.acceptTerms"
label="Accept terms and conditions"
:status="validationStatus"
:validation-message="validationMessage"
/>
</HLFormItem>
</HLForm>
</template>
<script setup>
import { ref, computed } from 'vue'
import { HLForm, HLFormItem, HLCheckbox } from '@platform-ui/highrise'
const formModel = ref({
acceptTerms: false,
})
const validationStatus = computed(() => {
if (!formModel.value.acceptTerms) return 'error'
return undefined
})
const validationMessage = computed(() => {
if (!formModel.value.acceptTerms) return 'You must accept the terms'
return undefined
})
const rules = {
acceptTerms: [
{
required: true,
message: 'You must accept the terms',
trigger: 'change',
},
],
}
</script>
Indeterminate Checkbox
vue
<template>
<div class="space-y-4">
<HLCheckbox
id="parent-checkbox"
v-model:checked="parentChecked"
v-model:indeterminate="indeterminate"
label="Select all"
@change="handleParentChange"
/>
<div class="ml-6 space-y-2">
<HLCheckbox
v-for="option in options"
:key="option.value"
:id="`child-${option.value}`"
v-model:checked="option.checked"
:label="option.label"
@change="handleChildChange"
/>
</div>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
import { HLCheckbox } from '@platform-ui/highrise'
const parentChecked = ref(false)
const indeterminate = ref(false)
const options = ref([
{ label: 'Option 1', value: '1', checked: false },
{ label: 'Option 2', value: '2', checked: false },
{ label: 'Option 3', value: '3', checked: false },
])
const handleParentChange = checked => {
options.value.forEach(option => {
option.checked = checked
})
indeterminate.value = false
}
const handleChildChange = () => {
const checkedCount = options.value.filter(option => option.checked).length
parentChecked.value = checkedCount === options.value.length
indeterminate.value = checkedCount > 0 && checkedCount < options.value.length
}
</script>
Best Practices
- Always provide a unique
id
for accessibility - Use
v-model:checked
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
- Group related checkboxes logically
- Use indeterminate state for parent-child relationships
- 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