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

Commit 62b86e7

Browse files
committed
feat: create tabs
1 parent 11cf984 commit 62b86e7

File tree

14 files changed

+153
-50
lines changed

14 files changed

+153
-50
lines changed

@types/components.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* This is a generated file. Do not edit it's contents.
88
*
9-
* This file was generated on 2023-03-28T16:40:42.002Z
9+
* This file was generated on 2023-03-28T18:16:17.195Z
1010
*/
1111

1212
import { ChakraProps, chakra } from "@chakra-ui/vue-system"
@@ -169,9 +169,16 @@ declare module "@vue/runtime-core" {
169169
CStack: typeof import("@chakra-ui/vue-next")["CStack"]
170170
CStackDivider: typeof import("@chakra-ui/vue-next")["CStackDivider"]
171171
CStackItem: typeof import("@chakra-ui/vue-next")["CStackItem"]
172+
CTab: typeof import("@chakra-ui/vue-next")["CTab"]
173+
CTabIndicator: typeof import("@chakra-ui/vue-next")["CTabIndicator"]
174+
CTabList: typeof import("@chakra-ui/vue-next")["CTabList"]
175+
CTabPanel: typeof import("@chakra-ui/vue-next")["CTabPanel"]
176+
CTabPanels: typeof import("@chakra-ui/vue-next")["CTabPanels"]
177+
CTabTrigger: typeof import("@chakra-ui/vue-next")["CTabTrigger"]
172178
CTable: typeof import("@chakra-ui/vue-next")["CTable"]
173179
CTableCaption: typeof import("@chakra-ui/vue-next")["CTableCaption"]
174180
CTableContainer: typeof import("@chakra-ui/vue-next")["CTableContainer"]
181+
CTabs: typeof import("@chakra-ui/vue-next")["CTabs"]
175182
CTbody: typeof import("@chakra-ui/vue-next")["CTbody"]
176183
CTd: typeof import("@chakra-ui/vue-next")["CTd"]
177184
CText: typeof import("@chakra-ui/vue-next")["CText"]

components.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* This is a generated file. Do not edit it's contents.
88
*
9-
* This file was generated on 2023-03-28T16:40:42.002Z
9+
* This file was generated on 2023-03-28T18:16:17.195Z
1010
*/
1111

1212
import { ChakraProps, chakra } from "@chakra-ui/vue-system"
@@ -169,9 +169,16 @@ declare module "@vue/runtime-core" {
169169
CStack: typeof import("@chakra-ui/vue-next")["CStack"]
170170
CStackDivider: typeof import("@chakra-ui/vue-next")["CStackDivider"]
171171
CStackItem: typeof import("@chakra-ui/vue-next")["CStackItem"]
172+
CTab: typeof import("@chakra-ui/vue-next")["CTab"]
173+
CTabIndicator: typeof import("@chakra-ui/vue-next")["CTabIndicator"]
174+
CTabList: typeof import("@chakra-ui/vue-next")["CTabList"]
175+
CTabPanel: typeof import("@chakra-ui/vue-next")["CTabPanel"]
176+
CTabPanels: typeof import("@chakra-ui/vue-next")["CTabPanels"]
177+
CTabTrigger: typeof import("@chakra-ui/vue-next")["CTabTrigger"]
172178
CTable: typeof import("@chakra-ui/vue-next")["CTable"]
173179
CTableCaption: typeof import("@chakra-ui/vue-next")["CTableCaption"]
174180
CTableContainer: typeof import("@chakra-ui/vue-next")["CTableContainer"]
181+
CTabs: typeof import("@chakra-ui/vue-next")["CTabs"]
175182
CTbody: typeof import("@chakra-ui/vue-next")["CTbody"]
176183
CTd: typeof import("@chakra-ui/vue-next")["CTd"]
177184
CText: typeof import("@chakra-ui/vue-next")["CText"]

modules/nuxt/playground/pages/tabs.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<chakra.div data-testid="simple-tabs-example">
3-
<c-tabs default-value="two">
3+
<c-tabs v-model="value">
44
<c-tab-list>
55
<c-tab value="one"> Item One </c-tab>
66
<c-tab value="two"> Item Two </c-tab>
@@ -26,5 +26,6 @@ import {
2626
CTabPanel,
2727
CTabPanels,
2828
CTabIndicator,
29-
} from "../../../../packages/c-tabs/src"
29+
} from "@chakra-ui/vue-next"
30+
const value = ref("two")
3031
</script>

modules/nuxt/src/runtime/chakra.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type * as NuxtAppTypes from "nuxt/app"
22
import { defineNuxtPlugin, useAppConfig } from "#imports"
33
import {
44
cookieStorageManagerSSR,
5+
localStorageManager,
56
ColorModeConstants,
67
extendTheme,
78
ColorModeScriptProps,
@@ -61,9 +62,9 @@ export default defineNuxtPlugin((nuxtApp) => {
6162
: ssrColorMode,
6263
},
6364
}),
64-
colorModeManager: cookieStorageManagerSSR(
65-
ColorModeConstants.CookieStorageKey
66-
),
65+
colorModeManager: !!ssrColorMode
66+
? cookieStorageManagerSSR(ColorModeConstants.CookieStorageKey)
67+
: localStorageManager,
6768
icons: chakraConfig.icons,
6869
})
6970

packages/c-alert/src/alert.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const CAlert = defineComponent({
8484
)
8585

8686
const themingProps = computed<ThemingProps>(() => ({
87+
styleConfig: props.styleConfig,
8788
colorScheme: colorScheme.value,
8889
variant: props.variant,
8990
}))

packages/c-popover/src/c-popover.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type * as ZT from "@zag-js/types"
1717
import { useId } from "@chakra-ui/vue-composables"
1818
import { useMotions } from "@vueuse/motion"
1919
import { useMultiStyleConfig } from "@chakra-ui/vue-system"
20+
import { vueThemingProps } from "@chakra-ui/vue-utils"
2021

2122
type PopoverPropsContext = UsePopoverProps["context"]
2223

@@ -65,6 +66,7 @@ const VuePopoverProps = {
6566
type: String as PropType<CPopoverProps["trigger"]>,
6667
default: "click",
6768
},
69+
...vueThemingProps,
6870
}
6971

7072
export const CPopover = defineComponent({

packages/c-tabs/src/c-tab-indicator.tsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,33 @@
11
import { HTMLChakraProps, chakra } from "@chakra-ui/vue-system"
2-
import { defineComponent } from "vue"
2+
import { computed, defineComponent } from "vue"
33
import { useTabsContext } from "./tabs.context"
44

55
export type CTabIndicatorProps = HTMLChakraProps<"div">
66
export const CTabIndicator = defineComponent({
77
name: "CTabIndicator",
8+
inheritAttrs: false,
89
setup(_, { attrs, slots }) {
910
const api = useTabsContext()
11+
const tabIndicatorProps = computed(() => {
12+
const { indicatorStyles, ...otherProps } = api.value.indicatorProps || {}
13+
const { style, ...otherAttrs } = attrs || {}
14+
return {
15+
style: {
16+
...(indicatorStyles || {}),
17+
...(style || {}),
18+
},
19+
others: {
20+
...otherProps,
21+
...otherAttrs,
22+
},
23+
}
24+
})
1025
return () => (
11-
<chakra.div {...api.value.indicatorProps} {...attrs}>
26+
<chakra.div
27+
style={tabIndicatorProps.value.style}
28+
{...tabIndicatorProps.value.others}
29+
{...attrs}
30+
>
1231
{slots.default?.()}
1332
</chakra.div>
1433
)

packages/c-tabs/src/c-tab-list.tsx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
import { HTMLChakraProps, chakra } from "@chakra-ui/vue-system"
2-
import { defineComponent, watchEffect } from "vue"
3-
import { useTabsContext } from "./tabs.context"
1+
import {
2+
HTMLChakraProps,
3+
SystemStyleObject,
4+
chakra,
5+
} from "@chakra-ui/vue-system"
6+
import { computed, defineComponent, watchEffect } from "vue"
7+
import { useTabsContext, useTabsStyles } from "./tabs.context"
48

59
export type CTabListProps = HTMLChakraProps<"div">
610

@@ -12,8 +16,20 @@ export const CTabList = defineComponent({
1216
setup(_, { attrs, slots }) {
1317
const api = useTabsContext()
1418

19+
const styles = useTabsStyles()
20+
21+
const tablistStyles = computed<SystemStyleObject>(() => ({
22+
display: "flex",
23+
...styles.value.tablist,
24+
}))
25+
1526
return () => (
16-
<chakra.div {...api.value.tablistProps} {...attrs}>
27+
<chakra.div
28+
__label="tabs__tablist"
29+
__css={tablistStyles.value}
30+
{...api.value.tablistProps}
31+
{...attrs}
32+
>
1733
{slots.default?.()}
1834
</chakra.div>
1935
)

packages/c-tabs/src/c-tab-panel.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
type PropType,
1010
defineComponent,
1111
} from "vue"
12-
import { useTabsContext } from "./tabs.context"
12+
import { useTabsContext, useTabsStyles } from "./tabs.context"
1313
import type { connect } from "@zag-js/tabs"
1414

1515
type GetContentProps = Parameters<
@@ -34,11 +34,14 @@ export const CTabPanel = defineComponent({
3434
},
3535
setup(props, { attrs, slots }) {
3636
const api = useTabsContext()
37+
const styles = useTabsStyles()
3738

3839
return () => (
3940
<chakra.div
4041
as={props.as}
4142
{...api.value.getContentProps({ value: props.value })}
43+
__label="tabs__tabpanel"
44+
__css={styles.value.tabpanel}
4245
{...attrs}
4346
>
4447
{slots.default?.()}

packages/c-tabs/src/c-tab-panels.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
import { HTMLChakraProps, chakra } from "@chakra-ui/vue-system"
22
import { defineComponent } from "vue"
3-
import { useTabsContext } from "./tabs.context"
3+
import { useTabsContext, useTabsStyles } from "./tabs.context"
44

55
export type CTabPanelsProps = HTMLChakraProps<"div">
66
export const CTabPanels = defineComponent({
77
name: "CTabPanels",
88
setup(_, { attrs, slots }) {
99
const api = useTabsContext()
10+
const styles = useTabsStyles()
1011
return () => (
11-
<chakra.div {...attrs} {...api.value.contentGroupProps}>
12+
<chakra.div
13+
{...api.value.contentGroupProps}
14+
__label="tabs__tabpanels"
15+
__css={styles.value.tabpanels}
16+
{...attrs}
17+
>
1218
{slots.default?.()}
1319
</chakra.div>
1420
)

0 commit comments

Comments
 (0)