Skip to content
This repository was archived by the owner on Sep 20, 2024. It is now read-only.

Commit 4de0122

Browse files
committed
fix(playground): fix accordion and form group issues
Signed-off-by: Shyrro <[email protected]>
1 parent edf5d6d commit 4de0122

File tree

3 files changed

+45
-49
lines changed

3 files changed

+45
-49
lines changed

packages/c-accordion/src/accordion.tsx

Lines changed: 23 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
import {
2-
h,
3-
defineComponent,
4-
PropType,
5-
computed,
6-
ComputedRef,
7-
ref,
8-
onMounted,
9-
Fragment,
10-
onBeforeMount,
11-
watchEffect,
12-
} from "vue"
1+
import { h, defineComponent, PropType, computed, ComputedRef, ref } from "vue"
132
import * as accordion from "@zag-js/accordion"
143
import { normalizeProps, useMachine, useSetup } from "@zag-js/vue"
154
import {
@@ -24,7 +13,13 @@ import {
2413
DeepPartial,
2514
} from "@chakra-ui/vue-system"
2615
import { useIds, useId } from "@chakra-ui/vue-composables"
27-
import { createContext, genId, vueThemingProps } from "@chakra-ui/vue-utils"
16+
import {
17+
createContext,
18+
genId,
19+
SNAO,
20+
getValidChildren,
21+
vueThemingProps,
22+
} from "@chakra-ui/vue-utils"
2823
import { filterUndefined, mergeWith } from "@chakra-ui/utils"
2924
import { SystemStyleObject } from "@chakra-ui/styled-system"
3025
import { CCollapse } from "@chakra-ui/c-motion"
@@ -47,6 +42,7 @@ export interface CAccordionProps
4742
* The index(es) of the expanded accordion item
4843
*/
4944
index?: ExpandedValues
45+
defaultIndex?: ExpandedValues
5046
/**
5147
* The initial index(es) of the expanded accordion item
5248
*/
@@ -78,8 +74,8 @@ export const CAccordion: ComponentWithProps<DeepPartial<CAccordionProps>> =
7874
},
7975
allowMultiple: Boolean as PropType<CAccordionProps["allowMultiple"]>,
8076
allowToggle: Boolean as PropType<CAccordionProps["allowToggle"]>,
81-
index: Number as PropType<CAccordionProps["index"]>,
82-
defaultIndex: Number as PropType<CAccordionProps["defaultIndex"]>,
77+
index: SNAO as PropType<CAccordionProps["index"]>,
78+
defaultIndex: SNAO as PropType<CAccordionProps["defaultIndex"]>,
8379
reduceMotion: {
8480
type: Boolean as PropType<CAccordionProps["reduceMotion"]>,
8581
default: false,
@@ -134,11 +130,9 @@ export const CAccordion: ComponentWithProps<DeepPartial<CAccordionProps>> =
134130
}}
135131
>
136132
{() => (
137-
<>
138-
<div ref={accordionRef} {...api.rootProps}>
139-
{slots}
140-
</div>
141-
</>
133+
<div ref={accordionRef} {...api.rootProps}>
134+
{getValidChildren(slots)}
135+
</div>
142136
)}
143137
</chakra.div>
144138
)
@@ -202,7 +196,7 @@ export const CAccordionItem: ComponentWithProps<CAccordionItemProps> =
202196
})}
203197
{...attrs}
204198
>
205-
{slots}
199+
{getValidChildren(slots)}
206200
</chakra.div>
207201
)
208202
},
@@ -239,7 +233,7 @@ export const CAccordionButton: ComponentWithProps<CAccordionButtonProps> =
239233
__css={buttonStyles.value}
240234
{...attrs}
241235
>
242-
{slots}
236+
{getValidChildren(slots)}
243237
</chakra.button>
244238
)
245239
},
@@ -266,15 +260,9 @@ export const CAccordionPanel: ComponentWithProps<CAccordionPanelProps> =
266260
})
267261
return (
268262
<CCollapse isOpen={isOpen.value}>
269-
{() => (
270-
<chakra.div
271-
{...contentProps}
272-
__css={styles.value.panel}
273-
{...attrs}
274-
>
275-
{slots}
276-
</chakra.div>
277-
)}
263+
<chakra.div {...contentProps} __css={styles.value.panel} {...attrs}>
264+
{getValidChildren(slots)}
265+
</chakra.div>
278266
</CCollapse>
279267
)
280268
}
@@ -305,14 +293,10 @@ export const CAccordionIcon: ComponentWithProps<CAccordionIconProps> =
305293
__css={iconStyles.value}
306294
{...attrs}
307295
>
308-
{() => (
309-
<>
310-
<path
311-
fill="currentColor"
312-
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
313-
/>
314-
</>
315-
)}
296+
<path
297+
fill="currentColor"
298+
d="M16.59 8.59L12 13.17 7.41 8.59 6 10l6 6 6-6z"
299+
/>
316300
</CIcon>
317301
)
318302
},

packages/c-form-control/examples/select-example.vue

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,38 @@
1414
</c-form-control>
1515
</template>
1616

17-
<script lang="tsx" setup>
18-
import { h, defineComponent, computed, toRefs } from 'vue'
17+
<script lang="tsx">
18+
import { h, defineComponent, computed, toRefs } from "vue"
1919
import {
2020
chakra,
2121
useMultiStyleConfig,
2222
omitThemingProps,
23-
} from '@chakra-ui/vue-system'
24-
import { useFormControl } from '@chakra-ui/c-form-control'
25-
import { vueThemingProps } from '@chakra-ui/vue-utils'
23+
} from "@chakra-ui/vue-system"
24+
import { filterUndefined } from "@chakra-ui/utils"
25+
import { useFormControl } from "@chakra-ui/c-form-control"
26+
import { getValidChildren, vueThemingProps } from "@chakra-ui/vue-utils"
2627
2728
const CSelect = defineComponent({
28-
props: vueThemingProps,
29-
setup(props, { slots }) {
30-
const styles = useMultiStyleConfig('Select', props)
29+
props: { ...vueThemingProps },
30+
setup(props, { slots, attrs }) {
31+
const themingProps = computed<ThemingProps>(() =>
32+
filterUndefined({
33+
colorScheme: props.colorScheme,
34+
variant: props.variant,
35+
size: props.size,
36+
styleConfig: props.styleConfig,
37+
})
38+
)
39+
const styles = useMultiStyleConfig("Select", themingProps.value)
3140
const _props = computed(() => toRefs(omitThemingProps(props)))
3241
const inputProps = useFormControl(_props.value)
3342
return () => (
3443
<chakra.select __css={styles.value.field} {...inputProps.value}>
35-
{slots}
44+
{() => getValidChildren(slots)}
3645
</chakra.select>
3746
)
3847
},
3948
})
49+
50+
export default CSelect
4051
</script>

packages/c-form-control/examples/textarea-example.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</c-form-control>
1111
</template>
1212

13-
<script lang="tsx" setup>
13+
<script lang="tsx">
1414
import { h, defineComponent, computed, toRefs } from "vue"
1515
import {
1616
chakra,
@@ -29,4 +29,5 @@ const CTextarea = defineComponent({
2929
return () => <chakra.textarea __css={styles.value} {...inputProps.value} />
3030
},
3131
})
32+
export default CTextarea
3233
</script>

0 commit comments

Comments
 (0)