Skip to content

Commit 21daa3c

Browse files
authored
Feat/theming (#450)
* refactor(flowbitetheme.ts): decomposits FlofbiteTheme interface to component pieces * refactor: moves components theme interfaces from Flowbyte.ts to their main files * test(flowbite): adds test cases for the flowbite theme provider and useTheme hook #443 * feat(helpers/mergedeep): updates the mergeDeep logic to make deep copy as well #443
1 parent ae95b9b commit 21daa3c

File tree

33 files changed

+720
-575
lines changed

33 files changed

+720
-575
lines changed

src/lib/components/Accordion/Accordion.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,34 @@ import classNames from 'classnames';
22
import type { ComponentProps, FC, PropsWithChildren, ReactElement } from 'react';
33
import { Children, cloneElement, useMemo, useState } from 'react';
44
import { HiChevronDown } from 'react-icons/hi';
5+
import { FlowbiteBoolean } from '../Flowbite/FlowbiteTheme';
56
import { useTheme } from '../Flowbite/ThemeContext';
67
import { AccordionContent } from './AccordionContent';
78
import type { AccordionPanelProps } from './AccordionPanel';
89
import { AccordionPanel } from './AccordionPanel';
910
import { AccordionTitle } from './AccordionTitle';
1011

12+
export interface FlowbiteAccordionTheme {
13+
base: string;
14+
content: {
15+
base: string;
16+
};
17+
flush: FlowbiteBoolean;
18+
title: {
19+
arrow: {
20+
base: string;
21+
open: {
22+
off: string;
23+
on: string;
24+
};
25+
};
26+
base: string;
27+
flush: FlowbiteBoolean;
28+
heading: string;
29+
open: FlowbiteBoolean;
30+
};
31+
}
32+
1133
export interface AccordionProps extends PropsWithChildren<ComponentProps<'div'>> {
1234
alwaysOpen?: boolean;
1335
arrowIcon?: FC<ComponentProps<'svg'>>;

src/lib/components/Alert/Alert.tsx

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,24 @@ import { HiX } from 'react-icons/hi';
44
import type { FlowbiteColors } from '../Flowbite/FlowbiteTheme';
55
import { useTheme } from '../Flowbite/ThemeContext';
66

7+
export interface FlowbiteAlertTheme {
8+
base: string;
9+
borderAccent: string;
10+
wrapper: string;
11+
closeButton: {
12+
base: string;
13+
icon: string;
14+
color: AlertColors;
15+
};
16+
color: AlertColors;
17+
icon: string;
18+
rounded: string;
19+
}
20+
21+
export interface AlertColors extends Pick<FlowbiteColors, 'failure' | 'gray' | 'info' | 'success' | 'warning'> {
22+
[key: string]: string;
23+
}
24+
725
export interface AlertProps extends PropsWithChildren<Omit<ComponentProps<'div'>, 'color'>> {
826
additionalContent?: ReactNode;
927
color?: keyof AlertColors;
@@ -13,10 +31,6 @@ export interface AlertProps extends PropsWithChildren<Omit<ComponentProps<'div'>
1331
withBorderAccent?: boolean;
1432
}
1533

16-
export interface AlertColors extends Pick<FlowbiteColors, 'failure' | 'gray' | 'info' | 'success' | 'warning'> {
17-
[key: string]: string;
18-
}
19-
2034
export const Alert: FC<AlertProps> = ({
2135
additionalContent,
2236
children,

src/lib/components/Avatar/Avatar.tsx

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,41 @@ import { useTheme } from '../Flowbite/ThemeContext';
55
import AvatarGroup from './AvatarGroup';
66
import AvatarGroupCounter from './AvatarGroupCounter';
77

8+
export interface FlowbiteAvatarTheme {
9+
base: string;
10+
bordered: string;
11+
img: {
12+
off: string;
13+
on: string;
14+
placeholder: string;
15+
};
16+
color: AvatarColors;
17+
rounded: string;
18+
size: AvatarSizes;
19+
stacked: string;
20+
status: {
21+
away: string;
22+
base: string;
23+
busy: string;
24+
offline: string;
25+
online: string;
26+
};
27+
statusPosition: FlowbitePositions;
28+
initials: {
29+
base: string;
30+
text: string;
31+
};
32+
}
33+
34+
export interface AvatarColors
35+
extends Pick<FlowbiteColors, 'failure' | 'gray' | 'info' | 'pink' | 'purple' | 'success' | 'warning'> {
36+
[key: string]: string;
37+
}
38+
39+
export interface AvatarSizes extends Pick<FlowbiteSizes, 'xs' | 'sm' | 'md' | 'lg' | 'xl'> {
40+
[key: string]: string;
41+
}
42+
843
export interface AvatarProps extends PropsWithChildren<Omit<ComponentProps<'div'>, 'color'>> {
944
alt?: string;
1045
bordered?: boolean;
@@ -18,15 +53,6 @@ export interface AvatarProps extends PropsWithChildren<Omit<ComponentProps<'div'
1853
placeholderInitials?: string;
1954
}
2055

21-
export interface AvatarColors
22-
extends Pick<FlowbiteColors, 'failure' | 'gray' | 'info' | 'pink' | 'purple' | 'success' | 'warning'> {
23-
[key: string]: string;
24-
}
25-
26-
export interface AvatarSizes extends Pick<FlowbiteSizes, 'xs' | 'sm' | 'md' | 'lg' | 'xl'> {
27-
[key: string]: string;
28-
}
29-
3056
const AvatarComponent: FC<AvatarProps> = ({
3157
alt = '',
3258
bordered = false,

src/lib/components/Avatar/AvatarGroup.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type { ComponentProps, PropsWithChildren } from 'react';
33
import React from 'react';
44
import { useTheme } from '../Flowbite';
55

6+
export interface FlowbiteAvatarGroupTheme {
7+
base: string;
8+
}
9+
610
export type AvatarGroupProps = PropsWithChildren<ComponentProps<'div'>>;
711

812
const AvatarGroup: React.FC<AvatarGroupProps> = ({ children, className }) => {

src/lib/components/Avatar/AvatarGroupCounter.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type { ComponentProps, PropsWithChildren } from 'react';
33
import React from 'react';
44
import { useTheme } from '../Flowbite';
55

6+
export interface FlowbiteAvatarGroupCounterTheme {
7+
base: string;
8+
}
9+
610
export interface AvatarGroupdCounterProps extends PropsWithChildren<ComponentProps<'a'>> {
711
total?: number;
812
}

src/lib/components/Avatar/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
export * from './Avatar';
2-
export type { AvatarGroupProps } from './AvatarGroup';
3-
export type { AvatarGroupdCounterProps } from './AvatarGroupCounter';
2+
export type { AvatarGroupProps, FlowbiteAvatarGroupTheme } from './AvatarGroup';
3+
export type { AvatarGroupdCounterProps, FlowbiteAvatarGroupCounterTheme } from './AvatarGroupCounter';

src/lib/components/Badge/Badge.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import type { ComponentProps, FC, PropsWithChildren } from 'react';
33
import type { FlowbiteColors, FlowbiteSizes } from '../Flowbite/FlowbiteTheme';
44
import { useTheme } from '../Flowbite/ThemeContext';
55

6-
export interface BadgeProps extends PropsWithChildren<Omit<ComponentProps<'span'>, 'color'>> {
7-
color?: keyof BadgeColors;
8-
href?: string;
9-
icon?: FC<ComponentProps<'svg'>>;
10-
size?: keyof BadgeSizes;
6+
export interface FlowbiteBadgeTheme {
7+
base: string;
8+
color: BadgeColors;
9+
href: string;
10+
icon: {
11+
off: string;
12+
on: string;
13+
size: BadgeSizes;
14+
};
15+
size: BadgeSizes;
1116
}
1217

1318
export interface BadgeColors
@@ -19,6 +24,13 @@ export interface BadgeSizes extends Pick<FlowbiteSizes, 'xs' | 'sm'> {
1924
[key: string]: string;
2025
}
2126

27+
export interface BadgeProps extends PropsWithChildren<Omit<ComponentProps<'span'>, 'color'>> {
28+
color?: keyof BadgeColors;
29+
href?: string;
30+
icon?: FC<ComponentProps<'svg'>>;
31+
size?: keyof BadgeSizes;
32+
}
33+
2234
export const Badge: FC<BadgeProps> = ({
2335
children,
2436
color = 'info',

src/lib/components/Breadcrumb/Breadcrumb.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@ import type { ComponentProps, FC } from 'react';
22
import { useTheme } from '../Flowbite/ThemeContext';
33
import BreadcrumbItem from './BreadcrumbItem';
44

5+
export interface FlowbiteBreadcrumbTheme {
6+
item: {
7+
base: string;
8+
chevron: string;
9+
href: {
10+
off: string;
11+
on: string;
12+
};
13+
icon: string;
14+
};
15+
list: string;
16+
}
17+
518
const BreadcrumbComponent: FC<ComponentProps<'nav'>> = ({ children, ...props }) => {
619
const theme = useTheme().theme.breadcrumb;
720

src/lib/components/Button/Button.tsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import classNames from 'classnames';
22
import { forwardRef, type ComponentProps, type ReactNode } from 'react';
33
import type {
4+
FlowbiteBoolean,
45
FlowbiteColors,
56
FlowbiteGradientColors,
67
FlowbiteGradientDuoToneColors,
@@ -10,17 +11,25 @@ import { useTheme } from '../Flowbite/ThemeContext';
1011
import type { PositionInButtonGroup } from './ButtonGroup';
1112
import ButtonGroup from './ButtonGroup';
1213

13-
export interface ButtonProps extends Omit<ComponentProps<'button'>, 'color' | 'ref'> {
14-
color?: keyof ButtonColors;
15-
gradientDuoTone?: keyof ButtonGradientDuoToneColors;
16-
gradientMonochrome?: keyof ButtonGradientColors;
17-
href?: string;
18-
label?: ReactNode;
19-
outline?: boolean;
20-
fullSized?: boolean;
21-
pill?: boolean;
22-
positionInGroup?: keyof PositionInButtonGroup;
23-
size?: keyof ButtonSizes;
14+
export interface FlowbiteButtonTheme {
15+
base: string;
16+
fullSized: string;
17+
color: ButtonColors;
18+
disabled: string;
19+
gradient: ButtonGradientColors;
20+
gradientDuoTone: ButtonGradientDuoToneColors;
21+
inner: {
22+
base: string;
23+
position: PositionInButtonGroup;
24+
outline: string;
25+
};
26+
label: string;
27+
outline: FlowbiteBoolean & {
28+
color: ButtonOutlineColors;
29+
pill: FlowbiteBoolean;
30+
};
31+
pill: FlowbiteBoolean;
32+
size: ButtonSizes;
2433
}
2534

2635
export interface ButtonColors
@@ -44,6 +53,19 @@ export interface ButtonSizes extends Pick<FlowbiteSizes, 'xs' | 'sm' | 'lg' | 'x
4453
[key: string]: string;
4554
}
4655

56+
export interface ButtonProps extends Omit<ComponentProps<'button'>, 'color' | 'ref'> {
57+
color?: keyof ButtonColors;
58+
gradientDuoTone?: keyof ButtonGradientDuoToneColors;
59+
gradientMonochrome?: keyof ButtonGradientColors;
60+
href?: string;
61+
label?: ReactNode;
62+
outline?: boolean;
63+
fullSized?: boolean;
64+
pill?: boolean;
65+
positionInGroup?: keyof PositionInButtonGroup;
66+
size?: keyof ButtonSizes;
67+
}
68+
4769
const ButtonComponent = forwardRef<HTMLButtonElement | HTMLAnchorElement, ButtonProps>(
4870
(
4971
{

src/lib/components/Button/ButtonGroup.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { Children, cloneElement, useMemo } from 'react';
44
import type { ButtonProps } from '../Button';
55
import { useTheme } from '../Flowbite/ThemeContext';
66

7-
export type ButtonGroupProps = PropsWithChildren<ComponentProps<'div'> & Pick<ButtonProps, 'outline' | 'pill'>>;
7+
export interface FlowbiteButtonGroupTheme {
8+
base: string;
9+
position: PositionInButtonGroup;
10+
}
811

912
export interface PositionInButtonGroup {
1013
none: string;
@@ -13,6 +16,8 @@ export interface PositionInButtonGroup {
1316
end: string;
1417
}
1518

19+
export type ButtonGroupProps = PropsWithChildren<ComponentProps<'div'> & Pick<ButtonProps, 'outline' | 'pill'>>;
20+
1621
const ButtonGroup: FC<ButtonGroupProps> = ({
1722
children,
1823
outline,

0 commit comments

Comments
 (0)