CheckboxGroup

A set of checklist buttons to select multiple option from a list.

Usage

Use the v-model directive to control the value of the CheckboxGroup or the default-value prop to set the initial value when you do not need to control its state.

Items

Use the items prop as an array of strings or numbers:

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
const value = ref(['System'])
</script>

<template>
  <PCheckboxGroup v-model="value" :items="items" />
</template>

You can also pass an array of objects with the following properties:

  • label?: string
  • description?: string
  • value?: string
  • disabled?: boolean
  • class?: any
  • pohon?: { item?: ClassNameValue, container?: ClassNameValue, base?: ClassNameValue, 'indicator'?: ClassNameValue, icon?: ClassNameValue, wrapper?: ClassNameValue, label?: ClassNameValue, description?: ClassNameValue }

This is the first option.

This is the second option.

This is the third option.

<script setup lang="ts">
import type { PCheckboxGroupItem } from 'pohon-ui'


const items = ref<PCheckboxGroupItem[]>([
  {
    label: 'System',
    description: 'This is the first option.',
    value: 'system'
  },
  {
    label: 'Light',
    description: 'This is the second option.',
    value: 'light'
  },
  {
    label: 'Dark',
    description: 'This is the third option.',
    value: 'dark'
  }
])
const value = ref([
  'system'
])
</script>

<template>
  <PCheckboxGroup v-model="value" :items="items" />
</template>
When using objects, you need to reference the value property of the object in the v-model directive or the default-value prop.

Value Key

You can change the property that is used to set the value by using the value-key prop. Defaults to value.

This is the first option.

This is the second option.

This is the third option.

<script setup lang="ts">
import type { PCheckboxGroupItem } from 'pohon-ui'


const items = ref<PCheckboxGroupItem[]>([
  {
    label: 'System',
    description: 'This is the first option.',
    id: 'system'
  },
  {
    label: 'Light',
    description: 'This is the second option.',
    id: 'light'
  },
  {
    label: 'Dark',
    description: 'This is the third option.',
    id: 'dark'
  }
])
const value = ref([
  'light'
])
</script>

<template>
  <PCheckboxGroup v-model="value" value-key="id" :items="items" />
</template>

Legend

Use the legend prop to set the legend of the CheckboxGroup.

Theme
<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup legend="Theme" :default-value="['System']" :items="items" />
</template>

Color

Use the color prop to change the color of the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup color="neutral" :default-value="['System']" :items="items" />
</template>

Variant

Use the variant prop to change the variant of the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup color="primary" variant="card" :default-value="['System']" :items="items" />
</template>

Size

Use the size prop to change the size of the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup size="xl" variant="list" :default-value="['System']" :items="items" />
</template>

Orientation

Use the orientation prop to change the orientation of the CheckboxGroup. Defaults to vertical.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup
    orientation="horizontal"
    variant="list"
    :default-value="['System']"
    :items="items"
  />
</template>

Indicator

Use the indicator prop to change the position or hide the indicator. Defaults to start.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup indicator="end" variant="card" :default-value="['System']" :items="items" />
</template>

Disabled

Use the disabled prop to disable the CheckboxGroup.

<script setup lang="ts">
const items = ref(['System', 'Light', 'Dark'])
</script>

<template>
  <PCheckboxGroup disabled :default-value="['System']" :items="items" />
</template>

API

Props

Prop Default Type

Slots

Slot Type

Emits

Event Type

Theme

We use unocss-variants to customize the theme. Read more about it in the theming guide.

Below is the theme configuration skeleton for the PCheckboxGroup. Since the component is provided unstyled by default, you will need to fill in these values to apply your own custom look and feel. If you prefer to use our pre-built, opinionated styling, you can instead use our UnoCSS preset, this docs is using it as well.

app.config.ts
export default defineAppConfig({
  pohon: {
    checkboxGroup: {
      slots: {
        root: '',
        fieldset: '',
        legend: '',
        item: ''
      },
      variants: {
        orientation: {
          horizontal: {
            fieldset: ''
          },
          vertical: {
            fieldset: ''
          }
        },
        color: {
          primary: {},
          secondary: {},
          success: {},
          info: {},
          warning: {},
          error: {},
          neutral: {}
        },
        variant: {
          list: {},
          card: {},
          table: {
            item: ''
          }
        },
        size: {
          xs: {
            fieldset: '',
            legend: ''
          },
          sm: {
            fieldset: '',
            legend: ''
          },
          md: {
            fieldset: '',
            legend: ''
          },
          lg: {
            fieldset: '',
            legend: ''
          },
          xl: {
            fieldset: '',
            legend: ''
          }
        },
        required: {
          true: {
            legend: ''
          }
        },
        disabled: {
          true: {}
        }
      },
      compoundVariants: [],
      defaultVariants: {
        size: 'md',
        variant: 'list',
        color: 'primary'
      }
    }
  }
};
vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import pohon from 'pohon-ui/vite'

export default defineAppConfig({
  pohon: {
    checkboxGroup: {
      slots: {
        root: '',
        fieldset: '',
        legend: '',
        item: ''
      },
      variants: {
        orientation: {
          horizontal: {
            fieldset: ''
          },
          vertical: {
            fieldset: ''
          }
        },
        color: {
          primary: {},
          secondary: {},
          success: {},
          info: {},
          warning: {},
          error: {},
          neutral: {}
        },
        variant: {
          list: {},
          card: {},
          table: {
            item: ''
          }
        },
        size: {
          xs: {
            fieldset: '',
            legend: ''
          },
          sm: {
            fieldset: '',
            legend: ''
          },
          md: {
            fieldset: '',
            legend: ''
          },
          lg: {
            fieldset: '',
            legend: ''
          },
          xl: {
            fieldset: '',
            legend: ''
          }
        },
        required: {
          true: {
            legend: ''
          }
        },
        disabled: {
          true: {}
        }
      },
      compoundVariants: [],
      defaultVariants: {
        size: 'md',
        variant: 'list',
        color: 'primary'
      }
    }
  }
};

Changelog

No recent changes