Skip to content

Commit

Permalink
feat: use react-icons icons library
Browse files Browse the repository at this point in the history
  • Loading branch information
bacali95 committed Mar 12, 2022
1 parent 8936371 commit 236ba62
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 110 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
"prepublishOnly": "yarn build-components"
},
"dependencies": {
"@heroicons/react": "^1.0.5",
"@popperjs/core": "^2.11.2",
"classnames": "^2.3.1"
"@popperjs/core": "^2.11.2",
"classnames": "^2.3.1",
"react-icons": "^4.3.1"
},
"peerDependencies": {
"react": "^17",
Expand Down
47 changes: 29 additions & 18 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { FC, useState } from 'react';
import {
BadgeCheckIcon,
BellIcon,
ChevronDoubleRightIcon,
CreditCardIcon,
DotsCircleHorizontalIcon,
DuplicateIcon,
MenuAlt1Icon,
TemplateIcon,
} from '@heroicons/react/solid';
HiBadgeCheck,
HiBell,
HiChevronDoubleRight,
HiCreditCard,
HiDotsCircleHorizontal,
HiDuplicate,
HiHome,
HiMenuAlt1,
} from 'react-icons/hi';
import { BsGithub } from 'react-icons/bs';
import { Route, Routes } from 'react-router-dom';

import { DarkThemeToggle, Navbar, Sidebar, SidebarItem } from './components';
Expand All @@ -26,43 +27,43 @@ export const Root: FC = () => {
[
{
group: false,
icon: TemplateIcon,
icon: HiHome,
title: 'Dashboard',
href: '/',
},
{
group: false,
icon: BellIcon,
icon: HiBell,
title: 'Alerts',
href: '/alerts',
},
{
group: false,
icon: CreditCardIcon,
icon: HiCreditCard,
title: 'Accordion',
href: '/accordion',
},
{
group: false,
icon: BadgeCheckIcon,
icon: HiBadgeCheck,
title: 'Badges',
href: '/badges',
},
{
group: false,
icon: ChevronDoubleRightIcon,
icon: HiChevronDoubleRight,
title: 'Breadcrumb',
href: '/breadcrumb',
},
{
group: false,
icon: DuplicateIcon,
icon: HiDuplicate,
title: 'Buttons',
href: '/buttons',
},
{
group: false,
icon: DotsCircleHorizontalIcon,
icon: HiDotsCircleHorizontal,
title: 'Tooltips',
href: '/tooltips',
},
Expand All @@ -73,13 +74,23 @@ export const Root: FC = () => {
<div className="flex flex-col w-full h-screen overflow-hidden">
<Navbar>
<div className="flex items-center">
<MenuAlt1Icon
<HiMenuAlt1
className="w-6 h-6 mr-6 cursor-pointer text-gray-600 dark:text-gray-400"
onClick={() => setCollapsed(!collapsed)}
/>
<span className="text-xl font-semibold dark:text-white">Flowbite React Components</span>
</div>
<DarkThemeToggle />
<div className="flex gap-2 items-center">
<a
className="cursor-pointer text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-2.5"
href="https://github.com/bacali95/flowbite-react"
target="_blank"
rel="noreferrer"
>
<BsGithub className="w-5 h-5" />
</a>
<DarkThemeToggle />
</div>
</Navbar>
<div className="flex h-full overflow-hidden bg-gray-50 dark:bg-gray-900">
<Sidebar collapsed={collapsed} itemsGroups={itemsGroups} />
Expand Down
8 changes: 4 additions & 4 deletions src/components/Accordion.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentProps, FC, Fragment, ReactNode, useState } from 'react';
import { ChevronDownIcon } from '@heroicons/react/solid';
import { HiChevronDown } from 'react-icons/hi';
import classNames from 'classnames';

export type AccordionItem = {
Expand All @@ -14,11 +14,11 @@ export type AccordionProps = {
arrowIcon?: FC<ComponentProps<'svg'>>;
};

export const Accordion: FC<AccordionProps> = ({ items, flush, arrowIcon: ArrowIcon = ChevronDownIcon }) => {
export const Accordion: FC<AccordionProps> = ({ items, flush, arrowIcon: ArrowIcon = HiChevronDown }) => {
const [openItems, setOpenItems] = useState<(boolean | undefined)[]>(items.map((item) => item.open));

return (
<>
<div>
{items.map((item, index) => (
<Fragment key={index}>
<h2>
Expand Down Expand Up @@ -59,6 +59,6 @@ export const Accordion: FC<AccordionProps> = ({ items, flush, arrowIcon: ArrowIc
</div>
</Fragment>
))}
</>
</div>
);
};
4 changes: 2 additions & 2 deletions src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentProps, FC, ReactNode } from 'react';
import classNames from 'classnames';
import { XIcon } from '@heroicons/react/solid';
import { HiX } from 'react-icons/hi';

export type AlertProps = {
color?: 'blue' | 'red' | 'green' | 'yellow' | 'gray';
Expand Down Expand Up @@ -58,7 +58,7 @@ export const Alert: FC<AlertProps> = ({
onClick={onDismiss}
>
<span className="sr-only">Close</span>
<XIcon className="w-5 h-5" />
<HiX className="w-5 h-5" />
</button>
)}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ComponentProps, FC } from 'react';
import { ChevronRightIcon } from '@heroicons/react/outline';
import { HiOutlineChevronRight } from 'react-icons/hi';

export type BreadcrumbItem = {
icon?: FC<ComponentProps<'svg'>>;
Expand All @@ -17,7 +17,7 @@ export const Breadcrumb: FC<BreadcrumbProps> = ({ items }) => {
<ol className="flex items-center">
{items.map((item, index) => (
<li key={index} className="flex items-center">
{index > 0 && <ChevronRightIcon className="w-6 h-6 mx-1 md:mx-2 text-gray-400" />}
{index > 0 && <HiOutlineChevronRight className="w-6 h-6 mx-1 md:mx-2 text-gray-400" />}
{index < items.length - 1 ? (
<a
className="flex items-center text-sm font-medium text-gray-700 hover:text-gray-900 dark:text-gray-400 dark:hover:text-white"
Expand Down
61 changes: 20 additions & 41 deletions src/components/DarkThemeToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,63 +1,42 @@
import { FC, useEffect } from 'react';
import { MoonIcon, SunIcon } from '@heroicons/react/solid';
import { FC, useEffect, useState } from 'react';
import { HiMoon, HiSun } from 'react-icons/hi';

export type Theme = 'dark' | 'light';

export const DarkThemeToggle: FC = () => {
useEffect(() => {
const themeToggleDarkIcon = document.getElementById('theme-toggle-dark-icon');
const themeToggleLightIcon = document.getElementById('theme-toggle-light-icon');
const [theme, setTheme] = useState<Theme>();

// Change the icons inside the button based on previous settings
useEffect(() => {
if (
localStorage.getItem('color-theme') === 'dark' ||
(!('color-theme' in localStorage) && window.matchMedia('(prefers-color-scheme: dark)').matches)
) {
themeToggleLightIcon?.classList.remove('hidden');
setTheme('dark');
} else {
themeToggleDarkIcon?.classList.remove('hidden');
setTheme('light');
}
}, []);

const themeToggleBtn = document.getElementById('theme-toggle');

const listener = () => {
// toggle icons inside button
themeToggleDarkIcon?.classList.toggle('hidden');
themeToggleLightIcon?.classList.toggle('hidden');

// if set via local storage previously
if (localStorage.getItem('color-theme')) {
if (localStorage.getItem('color-theme') === 'light') {
document.documentElement.classList.add('dark');
localStorage.setItem('color-theme', 'dark');
} else {
document.documentElement.classList.remove('dark');
localStorage.setItem('color-theme', 'light');
}

// if NOT set via local storage previously
useEffect(() => {
if (theme) {
localStorage.setItem('color-theme', theme);
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
if (document.documentElement.classList.contains('dark')) {
document.documentElement.classList.remove('dark');
localStorage.setItem('color-theme', 'light');
} else {
document.documentElement.classList.add('dark');
localStorage.setItem('color-theme', 'dark');
}
document.documentElement.classList.remove('dark');
}
};

themeToggleBtn?.addEventListener('click', listener);
}
}, [theme]);

return () => themeToggleBtn?.removeEventListener('click', listener);
}, []);
const toggleTheme = () => setTheme(theme === 'dark' ? 'light' : 'dark');

return (
<button
id="theme-toggle"
type="button"
className="text-gray-500 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 focus:outline-none focus:ring-4 focus:ring-gray-200 dark:focus:ring-gray-700 rounded-lg text-sm p-2.5"
onClick={toggleTheme}
>
<MoonIcon id="theme-toggle-dark-icon" className="hidden w-5 h-5" />
<SunIcon id="theme-toggle-light-icon" className="hidden w-5 h-5" />
{theme === 'light' ? <HiMoon className="w-5 h-5" /> : <HiSun className="w-5 h-5" />}
</button>
);
};
4 changes: 2 additions & 2 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentProps, FC, useState } from 'react';
import classNames from 'classnames';
import { ChevronDownIcon } from '@heroicons/react/solid';
import { Link, useLocation } from 'react-router-dom';
import { HiChevronDown } from 'react-icons/hi';

export type SidebarItem = {
icon: FC<ComponentProps<'svg'>>;
Expand Down Expand Up @@ -84,7 +84,7 @@ export const Sidebar: FC<SidebarProps> = ({ collapsed, itemsGroups }) => {
{!collapsed && (
<>
<span className="flex-1 ml-3 text-left whitespace-nowrap">{item.title}</span>
<ChevronDownIcon className="w-6 h-6" />
<HiChevronDown className="w-6 h-6" />
</>
)}
</button>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/AccordionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { ArrowCircleDownIcon } from '@heroicons/react/outline';
import { HiOutlineArrowCircleDown } from 'react-icons/hi';
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter';
import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx';

Expand Down Expand Up @@ -147,9 +147,9 @@ const items = [
<div className="flex flex-col gap-2">
<span className="text-2xl font-bold">Arrow style</span>
<Card className="dark:!bg-gray-900">
<Accordion items={items} arrowIcon={ArrowCircleDownIcon} />
<Accordion items={items} arrowIcon={HiOutlineArrowCircleDown} />
<SyntaxHighlighter language="tsx" style={dracula}>
{`<Accordion items={items} arrowIcon={ArrowCircleDownIcon} />`}
{`<Accordion items={items} arrowIcon={HiOutlineArrowCircleDown} />`}
</SyntaxHighlighter>
</Card>
</div>
Expand Down
22 changes: 11 additions & 11 deletions src/pages/AlertsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { EyeIcon, InformationCircleIcon } from '@heroicons/react/solid';
import { HiEye, HiInformationCircle } from 'react-icons/hi';
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter';
import { dracula } from 'react-syntax-highlighter/dist/esm/styles/prism';
import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx';
Expand Down Expand Up @@ -32,12 +32,12 @@ export const AlertsPage: FC = () => {
<div className="flex flex-col gap-2">
<span className="text-2xl font-bold">Alerts with icon</span>
<Card>
<Alert color="red" Icon={InformationCircleIcon}>
<Alert color="red" Icon={HiInformationCircle}>
{alertText}
</Alert>
<SyntaxHighlighter language="tsx" style={dracula}>
{`
<Alert color="red" Icon={InformationCircleIcon}>
<Alert color="red" Icon={HiInformationCircle}>
<span className="font-medium">Info alert!</span> Change a few things...
</Alert>`.trim()}
</SyntaxHighlighter>
Expand Down Expand Up @@ -101,7 +101,7 @@ export const AlertsPage: FC = () => {
type="button"
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-xs px-3 py-1.5 mr-2 text-center inline-flex items-center dark:bg-blue-800 dark:hover:bg-blue-900"
>
<EyeIcon className="-ml-0.5 mr-2 h-4 w-4" />
<HiEye className="-ml-0.5 mr-2 h-4 w-4" />
View more
</button>
<button
Expand All @@ -113,7 +113,7 @@ export const AlertsPage: FC = () => {
</div>
</>
}
Icon={InformationCircleIcon}
Icon={HiInformationCircle}
>
<h3 className="text-lg font-medium text-blue-700 dark:text-blue-800">This is a info alert</h3>
</Alert>
Expand All @@ -133,7 +133,7 @@ export const AlertsPage: FC = () => {
type="button"
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-xs px-3 py-1.5 mr-2 text-center inline-flex items-center dark:bg-blue-800 dark:hover:bg-blue-900"
>
<EyeIcon className="-ml-0.5 mr-2 h-4 w-4" />
<HiEye className="-ml-0.5 mr-2 h-4 w-4" />
View more
</button>
<button
Expand All @@ -145,7 +145,7 @@ export const AlertsPage: FC = () => {
</div>
</>
}
Icon={InformationCircleIcon}
Icon={HiInformationCircle}
>
<h3 className="text-lg font-medium text-blue-700 dark:text-blue-800">
This is a info alert
Expand Down Expand Up @@ -173,7 +173,7 @@ export const AlertsPage: FC = () => {
type="button"
className="text-white bg-green-700 hover:bg-green-800 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-xs px-3 py-1.5 mr-2 text-center inline-flex items-center dark:bg-green-800 dark:hover:bg-green-900"
>
<EyeIcon className="-ml-0.5 mr-2 h-4 w-4" />
<HiEye className="-ml-0.5 mr-2 h-4 w-4" />
View more
</button>
<button
Expand All @@ -185,7 +185,7 @@ export const AlertsPage: FC = () => {
</div>
</>
}
Icon={InformationCircleIcon}
Icon={HiInformationCircle}
>
<h3 className="text-lg font-medium text-green-700 dark:text-green-800">This is a info alert</h3>
</Alert>
Expand All @@ -208,7 +208,7 @@ export const AlertsPage: FC = () => {
type="button"
className="text-white bg-green-700 hover:bg-green-800 focus:ring-4 focus:ring-green-300 font-medium rounded-lg text-xs px-3 py-1.5 mr-2 text-center inline-flex items-center dark:bg-green-800 dark:hover:bg-green-900"
>
<EyeIcon className="-ml-0.5 mr-2 h-4 w-4" />
<HiEye className="-ml-0.5 mr-2 h-4 w-4" />
View more
</button>
<button
Expand All @@ -220,7 +220,7 @@ export const AlertsPage: FC = () => {
</div>
</>
}
Icon={InformationCircleIcon}
Icon={HiInformationCircle}
>
<h3 className="text-lg font-medium text-green-700 dark:text-green-800">
This is a info alert
Expand Down
Loading

0 comments on commit 236ba62

Please sign in to comment.