Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(component): theme support to darkthemetoggle #199

Merged
merged 3 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/lib/components/DarkThemeToggle/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
import type { FC } from 'react';
import type { ComponentProps, FC } from 'react';
import { useContext } from 'react';
import { HiMoon, HiSun } from 'react-icons/hi';
import { ThemeContext } from '../Flowbite/ThemeContext';
import { excludeClassName } from '../../helpers/exclude';
import { ThemeContext, useTheme } from '../Flowbite/ThemeContext';

export const DarkThemeToggle: FC = () => {
export type DarkThemeToggleProps = Omit<ComponentProps<'button'>, 'className'>;

export const DarkThemeToggle: FC<DarkThemeToggleProps> = (props) => {
const theirProps = excludeClassName(props);
const theme = useTheme().theme.darkthemetoggle;
const { mode, toggleMode } = useContext(ThemeContext);

return (
<button
className="rounded-lg p-2.5 text-sm text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-700"
className={theme.base}
data-testid="dark-theme-toggle"
onClick={toggleMode}
type="button"
aria-label="Toggle dark mode"
{...theirProps}
>
<span className="sr-only">Toggle dark mode</span>
{mode === 'dark' ? (
<HiSun className="h-5 w-5" data-testid="dark-theme-toggle-disabled" />
<HiSun className={theme.icon} data-testid="dark-theme-toggle-disabled" />
) : (
<HiMoon className="h-5 w-5" data-testid="dark-theme-toggle-enabled" />
<HiMoon className={theme.icon} data-testid="dark-theme-toggle-enabled" />
rluders marked this conversation as resolved.
Show resolved Hide resolved
)}
</button>
);
Expand Down
4 changes: 4 additions & 0 deletions src/lib/components/Flowbite/FlowbiteTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ export interface FlowbiteTheme {
snap: string;
};
};
darkthemetoggle: {
rluders marked this conversation as resolved.
Show resolved Hide resolved
base: string;
icon: string;
};
rating: {
base: string;
star: {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/theme/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ export default {
snap: 'snap-x',
},
},
darkthemetoggle: {
base: 'rounded-lg p-2.5 text-sm text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-700',
icon: 'h-5 w-5',
},
rating: {
base: 'flex items-center',
star: {
Expand Down