Skip to content

Commit 1cd081e

Browse files
committed
chore(Tab): added bg and border colors (full support WIP)
1 parent 50a5add commit 1cd081e

4 files changed

Lines changed: 61 additions & 4 deletions

File tree

src/Tabs/RadioTab.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import React, { forwardRef, ReactNode } from 'react'
22
import clsx from 'clsx'
33
import { twMerge } from 'tailwind-merge'
44

5+
import { ComponentColor } from '../types'
6+
57
export type RadioTabProps = Omit<
68
React.InputHTMLAttributes<HTMLInputElement>,
7-
'type'
9+
'type' | 'color'
810
> & {
11+
color?: ComponentColor
12+
bgColor?: string
13+
borderColor?: string
914
active?: boolean
1015
disabled?: boolean
1116
label: string
@@ -18,6 +23,9 @@ const RadioTab = forwardRef<HTMLInputElement, RadioTabProps>(
1823
{
1924
children,
2025
className,
26+
color,
27+
bgColor,
28+
borderColor,
2129
active,
2230
label,
2331
disabled,
@@ -31,6 +39,16 @@ const RadioTab = forwardRef<HTMLInputElement, RadioTabProps>(
3139
'tab',
3240
className,
3341
clsx({
42+
[`[--tab-bg:${bgColor}]`]: bgColor,
43+
[`[--tab-border-color:${borderColor}]`]: borderColor,
44+
'text-neutral': color === 'neutral',
45+
'text-primary': color === 'primary',
46+
'text-secondary': color === 'secondary',
47+
'text-accent': color === 'accent',
48+
'text-info': color === 'info',
49+
'text-success': color === 'success',
50+
'text-warning': color === 'warning',
51+
'text-error': color === 'error',
3452
'tab-active': active,
3553
'tab-disabled': disabled,
3654
})

src/Tabs/Tab.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,41 @@ import React, { forwardRef } from 'react'
22
import clsx from 'clsx'
33
import { twMerge } from 'tailwind-merge'
44

5-
export type TabProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
5+
import { ComponentColor } from '../types'
6+
7+
export type TabProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'color'> & {
8+
color?: ComponentColor
9+
bgColor?: string
10+
borderColor?: string
611
active?: boolean
712
disabled?: boolean
813
}
914

1015
const Tab = forwardRef<HTMLAnchorElement, TabProps>(
11-
({ children, className, active, disabled, ...props }, ref): JSX.Element => {
16+
({
17+
children,
18+
className,
19+
color,
20+
bgColor,
21+
borderColor,
22+
active,
23+
disabled,
24+
...props
25+
}, ref): JSX.Element => {
1226
const classes = twMerge(
1327
'tab',
1428
className,
1529
clsx({
30+
[`[--tab-bg:${bgColor}]`]: bgColor,
31+
[`[--tab-border-color:${borderColor}]`]: borderColor,
32+
'text-neutral': color === 'neutral',
33+
'text-primary': color === 'primary',
34+
'text-secondary': color === 'secondary',
35+
'text-accent': color === 'accent',
36+
'text-info': color === 'info',
37+
'text-success': color === 'success',
38+
'text-warning': color === 'warning',
39+
'text-error': color === 'error',
1640
'tab-active': active,
1741
'tab-disabled': disabled,
1842
})

src/Tabs/Tabs.stories.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,18 @@ RadioTabLifted.args = {
132132
className: 'w-full my-10 lg:mx-10',
133133
variant: 'lifted',
134134
}
135+
136+
export const TabsWithCustomColor: Story<TabsProps> = (args) => {
137+
return (
138+
<Tabs {...args}>
139+
<Tabs.Tab>Tab 1</Tabs.Tab>
140+
<Tabs.Tab color="primary" bgColor="yellow" borderColor="orange" active={true}>Tab 2</Tabs.Tab>
141+
<Tabs.Tab>Tab 3</Tabs.Tab>
142+
</Tabs>
143+
)
144+
}
145+
TabsWithCustomColor.args = {
146+
className: 'w-full my-10 lg:mx-10',
147+
variant: 'lifted',
148+
}
149+

src/Tabs/Tabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { cloneElement, forwardRef, ReactElement } from 'react'
1+
import React, { forwardRef } from 'react'
22
import clsx from 'clsx'
33
import { twMerge } from 'tailwind-merge'
44

0 commit comments

Comments
 (0)