Skip to content

Commit

Permalink
chore(Tab): added bg and border colors (full support WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjitrosch committed Jul 26, 2024
1 parent 50a5add commit 1cd081e
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 4 deletions.
20 changes: 19 additions & 1 deletion src/Tabs/RadioTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import React, { forwardRef, ReactNode } from 'react'
import clsx from 'clsx'
import { twMerge } from 'tailwind-merge'

import { ComponentColor } from '../types'

export type RadioTabProps = Omit<
React.InputHTMLAttributes<HTMLInputElement>,
'type'
'type' | 'color'
> & {
color?: ComponentColor
bgColor?: string
borderColor?: string
active?: boolean
disabled?: boolean
label: string
Expand All @@ -18,6 +23,9 @@ const RadioTab = forwardRef<HTMLInputElement, RadioTabProps>(
{
children,
className,
color,
bgColor,
borderColor,
active,
label,
disabled,
Expand All @@ -31,6 +39,16 @@ const RadioTab = forwardRef<HTMLInputElement, RadioTabProps>(
'tab',
className,
clsx({
[`[--tab-bg:${bgColor}]`]: bgColor,
[`[--tab-border-color:${borderColor}]`]: borderColor,
'text-neutral': color === 'neutral',
'text-primary': color === 'primary',
'text-secondary': color === 'secondary',
'text-accent': color === 'accent',
'text-info': color === 'info',
'text-success': color === 'success',
'text-warning': color === 'warning',
'text-error': color === 'error',
'tab-active': active,
'tab-disabled': disabled,
})
Expand Down
28 changes: 26 additions & 2 deletions src/Tabs/Tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,41 @@ import React, { forwardRef } from 'react'
import clsx from 'clsx'
import { twMerge } from 'tailwind-merge'

export type TabProps = React.AnchorHTMLAttributes<HTMLAnchorElement> & {
import { ComponentColor } from '../types'

export type TabProps = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'color'> & {
color?: ComponentColor
bgColor?: string
borderColor?: string
active?: boolean
disabled?: boolean
}

const Tab = forwardRef<HTMLAnchorElement, TabProps>(
({ children, className, active, disabled, ...props }, ref): JSX.Element => {
({
children,
className,
color,
bgColor,
borderColor,
active,
disabled,
...props
}, ref): JSX.Element => {
const classes = twMerge(
'tab',
className,
clsx({
[`[--tab-bg:${bgColor}]`]: bgColor,
[`[--tab-border-color:${borderColor}]`]: borderColor,
'text-neutral': color === 'neutral',
'text-primary': color === 'primary',
'text-secondary': color === 'secondary',
'text-accent': color === 'accent',
'text-info': color === 'info',
'text-success': color === 'success',
'text-warning': color === 'warning',
'text-error': color === 'error',
'tab-active': active,
'tab-disabled': disabled,
})
Expand Down
15 changes: 15 additions & 0 deletions src/Tabs/Tabs.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,18 @@ RadioTabLifted.args = {
className: 'w-full my-10 lg:mx-10',
variant: 'lifted',
}

export const TabsWithCustomColor: Story<TabsProps> = (args) => {
return (
<Tabs {...args}>
<Tabs.Tab>Tab 1</Tabs.Tab>
<Tabs.Tab color="primary" bgColor="yellow" borderColor="orange" active={true}>Tab 2</Tabs.Tab>
<Tabs.Tab>Tab 3</Tabs.Tab>
</Tabs>
)
}
TabsWithCustomColor.args = {
className: 'w-full my-10 lg:mx-10',
variant: 'lifted',
}

2 changes: 1 addition & 1 deletion src/Tabs/Tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { cloneElement, forwardRef, ReactElement } from 'react'
import React, { forwardRef } from 'react'
import clsx from 'clsx'
import { twMerge } from 'tailwind-merge'

Expand Down

0 comments on commit 1cd081e

Please sign in to comment.