diff --git a/packages/vue/src/accordion/accordion.tsx b/packages/vue/src/accordion/accordion.tsx index 1766f3c141..9708456448 100644 --- a/packages/vue/src/accordion/accordion.tsx +++ b/packages/vue/src/accordion/accordion.tsx @@ -1,40 +1,46 @@ +import { type Context } from '@zag-js/accordion' import { defineComponent, type PropType } from 'vue' import { ark, type HTMLArkProps } from '../factory' -import { type Assign } from '../types' -import { type ComponentWithProps } from '../utils' +import { type Assign, type Optional } from '../types' +import { createVueProps, type ComponentWithProps } from '../utils' import { AccordionProvider } from './accordion-context' -import { useAccordion, type UseAccordionContext } from './use-accordion' +import { useAccordion } from './use-accordion' -export type AccordionProps = Assign, UseAccordionContext> +export type AccordionContext = Context & { modelValue?: AccordionContext['value'] } -const VueAccordionProps = { +export type UseAccordionProps = Assign, AccordionContext> + +const VueAccordionProps = createVueProps({ + id: { + type: String as PropType, + }, modelValue: { - type: [String, Object] as PropType, + type: [String, Object] as PropType, }, collapsible: { - type: Boolean as PropType, + type: Boolean as PropType, default: false, }, multiple: { - type: Boolean as PropType, + type: Boolean as PropType, default: false, }, disabled: { - type: Boolean as PropType, + type: Boolean as PropType, default: false, }, ids: { - type: Object as PropType, + type: Object as PropType, }, getRootNode: { - type: Function as PropType, + type: Function as PropType, }, orientation: { - type: String as PropType, + type: String as PropType, }, -} +}) -export const Accordion: ComponentWithProps = defineComponent({ +export const Accordion: ComponentWithProps> = defineComponent({ name: 'Accordion', emits: ['change', 'update:modelValue'], props: VueAccordionProps, @@ -45,8 +51,10 @@ export const Accordion: ComponentWithProps = defineComponent({ return () => ( - {slots?.default?.()} + {slots?.default?.(api.value)} ) }, }) + +export type AccordionProps = Optional diff --git a/packages/vue/src/accordion/docs/accordion.types.json b/packages/vue/src/accordion/docs/accordion.types.json index c8cc49cc96..4b2b5fe384 100644 --- a/packages/vue/src/accordion/docs/accordion.types.json +++ b/packages/vue/src/accordion/docs/accordion.types.json @@ -16,10 +16,15 @@ "description": "Whether the accordion items are disabled" }, "getRootNode": { - "type": "() => Node | ShadowRoot | Document", + "type": "() => ShadowRoot | Node | Document", "isRequired": false, "description": "A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron." }, + "id": { + "type": "string", + "isRequired": false, + "description": "The unique identifier of the machine." + }, "ids": { "type": "Partial<{\n root: string\n item(value: string): string\n content(value: string): string\n trigger(value: string): string\n}>", "isRequired": false, diff --git a/packages/vue/src/accordion/use-accordion.ts b/packages/vue/src/accordion/use-accordion.ts index 9ef39e3334..068e5c9c71 100644 --- a/packages/vue/src/accordion/use-accordion.ts +++ b/packages/vue/src/accordion/use-accordion.ts @@ -1,20 +1,20 @@ -import { connect, machine, type Context as AccordionContext } from '@zag-js/accordion' +import { connect, machine } from '@zag-js/accordion' import { normalizeProps, useMachine } from '@zag-js/vue' -import { computed, reactive, watch } from 'vue' +import { computed, reactive, watch, type ExtractPropTypes } from 'vue' import { useId } from '../utils' +import type { AccordionContext } from './accordion' -export interface UseAccordionContext extends Omit { - modelValue?: AccordionContext['value'] -} - -export const useAccordion = (emit: CallableFunction, context: UseAccordionContext) => { +export const useAccordion = >( + emit: CallableFunction, + context: T, +) => { const reactiveContext = reactive(context) const [state, send] = useMachine( machine({ ...reactiveContext, value: reactiveContext.modelValue ?? reactiveContext.value, - id: useId().value, + id: reactiveContext.id || useId().value, onChange: (details) => { emit('change', details.value) emit( @@ -37,5 +37,3 @@ export const useAccordion = (emit: CallableFunction, context: UseAccordionContex return { api } } - -export type UseAccordionReturn = ReturnType diff --git a/packages/vue/src/checkbox/checkbox.tsx b/packages/vue/src/checkbox/checkbox.tsx index 63489ccf11..bc91622426 100644 --- a/packages/vue/src/checkbox/checkbox.tsx +++ b/packages/vue/src/checkbox/checkbox.tsx @@ -1,51 +1,76 @@ +import { type Context } from '@zag-js/checkbox' import { defineComponent, type PropType } from 'vue' import { ark, type HTMLArkProps } from '../factory' -import { type Assign } from '../types' -import { type ComponentWithProps } from '../utils' +import { type Assign, type Optional } from '../types' +import { createVueProps, type ComponentWithProps } from '../utils' import { CheckboxProvider } from './checkbox-context' -import { useCheckbox, type UseCheckboxContext } from './use-checkbox' +import { useCheckbox } from './use-checkbox' -export type CheckboxProps = Assign, UseCheckboxContext> +export type CheckboxContext = Context & { + modelValue?: Context['checked'] +} +export type UseCheckboxProps = Assign, CheckboxContext> -const VueCheckboxProps = { +export const VueCheckboxProps = createVueProps({ + id: { + type: String as PropType, + }, + 'aria-describedby': { + type: String as PropType, + }, + 'aria-label': { + type: String as PropType, + }, + 'aria-labelledby': { + type: String as PropType, + }, checked: { - type: Boolean as PropType, + type: Boolean as PropType, default: false, }, dir: { - type: String as PropType, + type: String as PropType, }, disabled: { - type: Boolean as PropType, + type: Boolean as PropType, + }, + focusable: { + type: Boolean as PropType, }, form: { - type: String as PropType, + type: String as PropType, }, getRootNode: { - type: Function as PropType, + type: Function as PropType, }, ids: { - type: Object as PropType, + type: Object as PropType, + }, + indeterminate: { + type: Boolean as PropType, }, invalid: { - type: Boolean as PropType, + type: Boolean as PropType, }, modelValue: { - type: Boolean as PropType, + type: [Boolean, String] as PropType, default: undefined, }, name: { - type: String as PropType, + type: String as PropType, + }, + readOnly: { + type: Boolean as PropType, }, required: { - type: Boolean as PropType, + type: Boolean as PropType, }, value: { - type: String as PropType, + type: String as PropType, }, -} +}) -export const Checkbox: ComponentWithProps = defineComponent({ +export const Checkbox: ComponentWithProps> = defineComponent({ name: 'Checkbox', emits: ['change', 'update:modelValue'], props: VueCheckboxProps, @@ -61,3 +86,5 @@ export const Checkbox: ComponentWithProps = defineComponent({ ) }, }) + +export type CheckboxProps = Optional diff --git a/packages/vue/src/checkbox/docs/checkbox.types.json b/packages/vue/src/checkbox/docs/checkbox.types.json index ca9b1b454e..f2421b9d18 100644 --- a/packages/vue/src/checkbox/docs/checkbox.types.json +++ b/packages/vue/src/checkbox/docs/checkbox.types.json @@ -21,10 +21,15 @@ "description": "The id of the form that the checkbox belongs to." }, "getRootNode": { - "type": "() => Node | ShadowRoot | Document", + "type": "() => ShadowRoot | Node | Document", "isRequired": false, "description": "A root node to correctly resolve document in custom environments. E.x.: Iframes, Electron." }, + "id": { + "type": "string", + "isRequired": false, + "description": "The unique identifier of the machine." + }, "ids": { "type": "Partial<{ root: string; input: string; control: string; label: string }>", "isRequired": false, diff --git a/packages/vue/src/checkbox/stories/basic.stories.vue b/packages/vue/src/checkbox/stories/basic.stories.vue index 5fcf1e8249..85fecce547 100644 --- a/packages/vue/src/checkbox/stories/basic.stories.vue +++ b/packages/vue/src/checkbox/stories/basic.stories.vue @@ -3,7 +3,9 @@ import { ref } from 'vue' import { Checkbox, CheckboxControl, CheckboxInput, CheckboxLabel } from '..' import '../checkbox.css' -const checkboxRef = ref(true) +const props = defineProps(['modelValue']) + +const checkboxRef = ref(props.modelValue || true)