Skip to content

Commit bea3fa2

Browse files
SutuSebastianSebastian Sutu
authored andcommitted
NextJS 13 App router / RSC support (themesberg#994)
* feat: nextJS 13 RSC support; initial approach - ditch `useTheme` react context, use polymorphic singleton (cross env: client/server) BETA IDEA * add missing `'use client';` * add more missing `'use client';` * refactor: remove `ThemeContext`; create `useThemeMode` hook and persist in LS; polymorphic custom theme init (server/client) * refactor: `useThemeMode` - cleanup; change LS key name to be specific * simplify theme init * fix: `Flowbite` test * remove redundant TS HTMLDivElement types to `Flowbite` component * fix: build failure due to variable not being used * update: RSC demo page * fix: import types * fix: SSR error * feat: sync all tabs with the latest theme mode value * abstract away hook * refactor: import/export hierarchy; simplify package dependency graph, avoid circular imports errors * keep `useThemeMode` state in sync inbetween instances * update demo RSC page * fix: conflicts after merge with main * refactor: `Flowbite` exports * fix: `FloatingLabel` export * fix: `FloatingLabel` imports + use new `getTheme` function * refactor: allow mutation of `getTheme` return object; abstract `cloneDeep` and `isObject` * refactor: theme init; theme mode hook: add `auto` mode as well + extend API * fix: performance improvements: improve for loops, lower garbage collector size; add some tests * fix: `use-client` spacing * refactor: inline fallback return * fix: strict type imports * fix: build - add `ts-expect-error` description * refactor: embed `mode` into theme init flow * remove demo page * fix `FloatingLabel` imports/exports * fix: flowbite test * fix: `blockquote` imports * fix: export `Blockquote` * fix: import type * refactor: rename `useWatchLSValue` to be more explicit: `useWatchLocalStorageValue` --------- Co-authored-by: Sebastian Sutu <sebastian.sutu@sensidev.com>
1 parent 232de5a commit bea3fa2

File tree

158 files changed

+1036
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

158 files changed

+1036
-712
lines changed

app/docs/forms/floating-label/floating-label.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { FloatingLabel } from '~/src/components/FloatingLabel/FloatingLabel';
2-
import { theme } from '~/src';
31
import { CodePreview } from '~/app/components/code-preview';
2+
import { theme, FloatingLabel } from '~/src';
43

54
## Table of Contents
65

src/components/Accordion/Accordion.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import userEvent from '@testing-library/user-event';
33
import type { FC } from 'react';
44
import { HiOutlineArrowCircleDown } from 'react-icons/hi';
55
import { describe, expect, it } from 'vitest';
6-
import { Flowbite } from '../../';
6+
import { Flowbite } from '../Flowbite';
77
import type { AccordionProps } from './Accordion';
88
import { Accordion } from './Accordion';
99

src/components/Accordion/Accordion.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
'use client';
2+
13
import type { ComponentProps, FC, PropsWithChildren, ReactElement } from 'react';
24
import { Children, cloneElement, useMemo, useState } from 'react';
35
import { HiChevronDown } from 'react-icons/hi';
46
import { twMerge } from 'tailwind-merge';
5-
import type { DeepPartial, FlowbiteBoolean } from '../../';
6-
import { useTheme } from '../../';
7-
import { mergeDeep } from '../../helpers/merge-deep';
7+
import { mergeDeep } from '~/src/helpers/merge-deep';
8+
import { getTheme } from '~/src/theme-store';
9+
import type { DeepPartial } from '~/src/types';
10+
import type { FlowbiteBoolean } from '../Flowbite';
811
import type { FlowbiteAccordionComponentTheme } from './AccordionContent';
912
import { AccordionContent } from './AccordionContent';
1013
import type { AccordionPanelProps } from './AccordionPanel';
@@ -58,7 +61,7 @@ const AccordionComponent: FC<AccordionProps> = ({
5861
[alwaysOpen, arrowIcon, children, flush, isOpen],
5962
);
6063

61-
const theme = mergeDeep(useTheme().theme.accordion.root, customTheme);
64+
const theme = mergeDeep(getTheme().accordion.root, customTheme);
6265

6366
return (
6467
<div

src/components/Accordion/AccordionContent.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
'use client';
2+
13
import type { ComponentProps, FC, PropsWithChildren } from 'react';
24
import { twMerge } from 'tailwind-merge';
3-
import type { DeepPartial } from '../../';
4-
import { useTheme } from '../../';
5-
import { mergeDeep } from '../../helpers/merge-deep';
5+
import { mergeDeep } from '~/src/helpers/merge-deep';
6+
import { getTheme } from '~/src/theme-store';
7+
import type { DeepPartial } from '~/src/types';
68
import { useAccordionContext } from './AccordionPanelContext';
79

810
export interface FlowbiteAccordionComponentTheme {
@@ -21,7 +23,7 @@ export const AccordionContent: FC<AccordionContentProps> = ({
2123
}) => {
2224
const { isOpen } = useAccordionContext();
2325

24-
const theme = mergeDeep(useTheme().theme.accordion.content, customTheme);
26+
const theme = mergeDeep(getTheme().accordion.content, customTheme);
2527

2628
return (
2729
<div

src/components/Accordion/AccordionPanel.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import type { FC, PropsWithChildren } from 'react';
24
import { useState } from 'react';
35
import type { AccordionProps } from './Accordion';

src/components/Accordion/AccordionPanelContext.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import { createContext, useContext } from 'react';
24
import type { AccordionPanelProps } from './AccordionPanel';
35

src/components/Accordion/AccordionTitle.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
'use client';
2+
13
import type { ComponentProps, FC } from 'react';
24
import { twMerge } from 'tailwind-merge';
3-
import type { DeepPartial, FlowbiteBoolean, FlowbiteHeadingLevel } from '../../';
4-
import { useTheme } from '../../';
5-
import { mergeDeep } from '../../helpers/merge-deep';
5+
import { mergeDeep } from '~/src/helpers/merge-deep';
6+
import { getTheme } from '~/src/theme-store';
7+
import type { DeepPartial } from '~/src/types';
8+
import type { FlowbiteBoolean, FlowbiteHeadingLevel } from '../Flowbite';
69
import { useAccordionContext } from './AccordionPanelContext';
710

811
export interface FlowbiteAccordionTitleTheme {
@@ -32,7 +35,7 @@ export const AccordionTitle: FC<AccordionTitleProps> = ({
3235
const { arrowIcon: ArrowIcon, flush, isOpen, setOpen } = useAccordionContext();
3336
const onClick = () => typeof setOpen !== 'undefined' && setOpen();
3437

35-
const theme = mergeDeep(useTheme().theme.accordion.title, customTheme);
38+
const theme = mergeDeep(getTheme().accordion.title, customTheme);
3639

3740
return (
3841
<button

src/components/Alert/Alert.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { FC } from 'react';
44
import { useState } from 'react';
55
import { HiEye, HiHeart, HiInformationCircle } from 'react-icons/hi';
66
import { describe, expect, it, vi } from 'vitest';
7-
import { Flowbite } from '../../';
7+
import { Flowbite } from '../Flowbite';
88

99
import type { AlertProps } from './Alert';
1010
import { Alert } from './Alert';

src/components/Alert/Alert.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Meta, StoryFn } from '@storybook/react';
22
import { HiEye, HiInformationCircle } from 'react-icons/hi';
3-
import { theme } from '../../';
3+
import { theme } from '~/src/theme';
44
import type { AlertProps } from './Alert';
55
import { Alert } from './Alert';
66

src/components/Alert/Alert.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { ComponentProps, FC, PropsWithChildren, ReactNode } from 'react';
22
import { HiX } from 'react-icons/hi';
33
import { twMerge } from 'tailwind-merge';
4-
import type { DeepPartial, FlowbiteColors } from '../../';
5-
import { useTheme } from '../../';
6-
import { mergeDeep } from '../../helpers/merge-deep';
4+
import { mergeDeep } from '~/src/helpers/merge-deep';
5+
import { getTheme } from '~/src/theme-store';
6+
import type { DeepPartial } from '~/src/types';
7+
import type { FlowbiteColors } from '../Flowbite';
78

89
export interface FlowbiteAlertTheme {
910
base: string;
@@ -43,7 +44,7 @@ export const Alert: FC<AlertProps> = ({
4344
withBorderAccent,
4445
...props
4546
}) => {
46-
const theme = mergeDeep(useTheme().theme.alert, customTheme);
47+
const theme = mergeDeep(getTheme().alert, customTheme);
4748

4849
return (
4950
<div

0 commit comments

Comments
 (0)