Skip to content

Commit

Permalink
use: typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
vikdiesel committed Sep 12, 2022
1 parent dccbf65 commit 838e745
Show file tree
Hide file tree
Showing 58 changed files with 659 additions and 286 deletions.
11 changes: 10 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
{
"extends": ["next/core-web-vitals", "prettier"]
"extends": ["next/core-web-vitals", "prettier"],
"no-restricted-imports": "off",
"@typescript-eslint/no-restricted-imports": [
"warn",
{
"name": "react-redux",
"importNames": ["useSelector", "useDispatch"],
"message": "Use typed hooks `useAppDispatch` and `useAppSelector` instead."
}
]
}
5 changes: 3 additions & 2 deletions components/asideMenu.js → components/AsideMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import AsideMenuLayer from './asideMenuLayer'
import OverlayLayer from './overlayLayer'
import React from 'react'
import AsideMenuLayer from './AsideMenuLayer'
import OverlayLayer from './OverlayLayer'

export default function AsideMenu({
menu,
Expand Down
21 changes: 14 additions & 7 deletions components/asideMenuItem.js → components/AsideMenuItem.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import { useState } from 'react'

import React, { useState } from 'react'
import { mdiMinus, mdiPlus } from '@mdi/js'
import BaseIcon from './baseIcon'
import BaseIcon from './BaseIcon'
import Link from 'next/link'
import { getButtonColor } from '../src/colors'
import { useSelector } from 'react-redux'
import AsideMenuList from './asideMenuList'
import AsideMenuList from './AsideMenuList'
import { MenuAsideItem } from '../interfaces'
import { useAppSelector } from '../src/stores/hooks'

type Props = {
item: MenuAsideItem,
isDropdownList?: boolean
}

export default function AsideMenuItem({ item, isDropdownList = false }) {
export default function AsideMenuItem({ item, isDropdownList = false }: Props) {
const [isDropdownActive, setIsDropdownActive] = useState(false)
const asideMenuItemStyle = useSelector((state) => state.style.asideMenuItemStyle)
const asideMenuDropdownStyle = useSelector((state) => state.style.asideMenuDropdownStyle)
const asideMenuItemStyle = useAppSelector((state) => state.style.asideMenuItemStyle)
const asideMenuDropdownStyle = useAppSelector((state) => state.style.asideMenuDropdownStyle)

const asideMenuItemInnerContents = (
<>
Expand Down
27 changes: 17 additions & 10 deletions components/asideMenuLayer.js → components/AsideMenuLayer.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { useSelector } from 'react-redux'
import React from 'react'
import { mdiLogout, mdiClose } from '@mdi/js'
import BaseIcon from './baseIcon'
import AsideMenuItem from './asideMenuItem'
import AsideMenuList from './asideMenuList'
import BaseIcon from './BaseIcon'
import AsideMenuItem from './AsideMenuItem'
import AsideMenuList from './AsideMenuList'
import { MenuAsideItem } from '../interfaces'
import { useAppSelector } from '../src/stores/hooks'

export default function AsideMenuLayer({ menu, className }) {
const asideStyle = useSelector((state) => state.style.asideStyle)
const asideBrandStyle = useSelector((state) => state.style.asideBrandStyle)
const asideScrollbarsStyle = useSelector((state) => state.style.asideScrollbarsStyle)
const darkMode = useSelector((state) => state.style.darkMode)
type Props = {
menu: MenuAsideItem[],
className?: string
}

export default function AsideMenuLayer({ menu, className='' }: Props) {
const asideStyle = useAppSelector((state) => state.style.asideStyle)
const asideBrandStyle = useAppSelector((state) => state.style.asideBrandStyle)
const asideScrollbarsStyle = useAppSelector((state) => state.style.asideScrollbarsStyle)
const darkMode = useAppSelector((state) => state.style.darkMode)

const logoutItem = {
const logoutItem: MenuAsideItem = {
label: 'Logout',
icon: mdiLogout,
color: 'info',
Expand Down
12 changes: 10 additions & 2 deletions components/asideMenuList.js → components/AsideMenuList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import AsideMenuItem from './asideMenuItem'
import React from 'react'
import { MenuAsideItem } from '../interfaces'
import AsideMenuItem from './AsideMenuItem'

export default function AsideMenuList({ menu, isDropdownList = false, className = '' }) {
type Props = {
menu: MenuAsideItem[],
isDropdownList?: boolean,
className?: string
}

export default function AsideMenuList({ menu, isDropdownList = false, className = '' }: Props) {
return (
<ul className={className}>
{menu.map((item, index) => (
Expand Down
38 changes: 28 additions & 10 deletions components/baseButton.js → components/BaseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,44 @@
import React from 'react'
import Link from 'next/link'
import { getButtonColor } from '../src/colors'
import BaseIcon from './baseIcon'
import BaseIcon from './BaseIcon'
import { ColorButtonKey } from '../interfaces'

type Props = {
label?: string,
icon?: string,
iconSize?: string|number,
href?: string,
target?: string,
type?: string,
color?: ColorButtonKey,
className?: string,
asAnchor?: boolean,
small?: boolean,
outline?: boolean,
active?: boolean,
disabled?: boolean,
roundedFull?: boolean
}

export default function BaseButton({
label,
icon,
iconSize,
href,
target,
type = null,
color,
type,
color='white',
className='',
asAnchor = false,
className,
small = false,
outline = false,
active = false,
disabled = false,
roundedFull = false,
}) {
}: Props) {
const componentClass = [
'inline-flex',
'cursor-pointer',
'justify-center',
'items-center',
'whitespace-nowrap',
Expand All @@ -30,6 +47,7 @@ export default function BaseButton({
'focus:ring',
'duration-150',
'border',
disabled ? 'cursor-not-allowed' : 'cursor-pointer',
roundedFull ? 'rounded-full' : 'rounded',
getButtonColor(color, outline, !disabled, active),
className,
Expand All @@ -44,7 +62,7 @@ export default function BaseButton({
}

if (disabled) {
componentClass.push('cursor-not-allowed', outline ? 'opacity-50' : 'opacity-70')
componentClass.push(outline ? 'opacity-50' : 'opacity-70')
}

const componentClassString = componentClass.join(' ')
Expand All @@ -56,10 +74,10 @@ export default function BaseButton({
</>
)

if (href) {
if (href && !disabled) {
return (
<Link href={href} target={target} disabled={disabled} passHref>
<a className={componentClassString} disabled={disabled}>
<Link href={href} target={target} passHref>
<a className={componentClassString}>
{componentChildren}
</a>
</Link>
Expand Down
19 changes: 19 additions & 0 deletions components/BaseButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { ReactNode } from 'react'

type Props = {
type?: string,
mb?: string,
noWrap: boolean,
children: ReactNode
}

export default function BaseButtons({
type = 'justify-start',
mb = '-mb-3',
noWrap = false,
children,
}: Props) {
const parentClass = `flex items-center ${type} ${mb} ${noWrap ? 'flex-nowrap' : 'flex-wrap'}`

return <div className={parentClass}>{children}</div>
}
8 changes: 7 additions & 1 deletion components/baseDivider.js → components/BaseDivider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
export default function BaseDivider({ navBar = false }) {
import React from "react"

type Props = {
navBar?: boolean
}

export default function BaseDivider({ navBar = false }: Props) {
const classAddon = navBar
? 'hidden lg:block lg:my-0.5 dark:border-slate-700'
: 'my-6 -mx-6 dark:border-slate-800'
Expand Down
12 changes: 11 additions & 1 deletion components/baseIcon.js → components/BaseIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
export default function BaseIcon({ path, w = 'w-6', h = 'h-6', size, className }) {
import React from "react"

type Props = {
path: string,
w?: string,
h?: string,
size?: string|number|null,
className?: string
}

export default function BaseIcon({ path, w = 'w-6', h = 'h-6', size=null, className='' }: Props) {
const iconSize = size ?? 16

return (
Expand Down
10 changes: 9 additions & 1 deletion components/baseLevel.js → components/BaseLevel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
export default function BaseLevel({ mobile = false, type = 'justify-between', children }) {
import React, { ReactNode } from "react"

type Props = {
mobile?: boolean,
type?: string,
children?: ReactNode
}

export default function BaseLevel({ mobile = false, type = 'justify-between', children }: Props) {
const parentClass = `${type} items-center`

const parentMobileClass = 'flex'
Expand Down
31 changes: 22 additions & 9 deletions components/cardBox.js → components/CardBox.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
import React from 'react'
import CardBoxComponentBody from './cardBoxComponentBody'
import CardBoxComponentFooter from './cardBoxComponentFooter'
import React, { ReactNode } from 'react'
import CardBoxComponentBody from './CardBoxComponentBody'
import CardBoxComponentFooter from './CardBoxComponentFooter'

type Props = {
rounded?: string,
flex?: string,
className?: string,
hasComponentLayout?: boolean,
hasTable?: boolean,
isForm?: boolean,
isHoverable?: boolean,
isModal?: boolean,
children: ReactNode,
footer?: ReactNode
}

export default function CardBox({
rounded = 'rounded-2xl',
flex = 'flex-col',
className = '',
hasComponentLayout,
hasTable,
isForm,
isHoverable,
isModal,
hasComponentLayout=false,
hasTable=false,
isForm=false,
isHoverable=false,
isModal=false,
children,
footer,
}) {
}: Props) {
const componentClass = [
'bg-white flex',
className,
Expand Down
10 changes: 10 additions & 0 deletions components/CardBoxComponentBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React, { ReactNode } from "react"

type Props = {
noPadding?: boolean,
children?: ReactNode
}

export default function CardBoxComponentBody({ noPadding=false, children }: Props) {
return <div className={`flex-1 ${noPadding ? '' : 'p-6'}`}>{children}</div>
}
9 changes: 9 additions & 0 deletions components/CardBoxComponentFooter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React, { ReactNode } from "react"

type Props = {
children?: ReactNode
}

export default function CardBoxComponentFooter({ children }: Props) {
return <footer className="p-6">{children}</footer>
}
Empty file added components/CardBoxWIdget.tsx
Empty file.
11 changes: 8 additions & 3 deletions components/footerBar.js → components/FooterBar.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React, { ReactNode } from 'react'
import { containerMaxW } from '../src/config'
import BaseLevel from './baseLevel'
import JustboilLogo from './justboil/logo'
import BaseLevel from './BaseLevel'
import JustboilLogo from './justboil/Logo'

export default function FooterBar({ children }) {
type Props = {
children: ReactNode
}

export default function FooterBar({ children }: Props) {
const year = new Date().getFullYear()

return (
Expand Down
15 changes: 13 additions & 2 deletions components/iconRounded.js → components/IconRounded.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
import React from 'react'
import { ColorKey } from '../interfaces'
import { colorsBgLight, colorsText } from '../src/colors'
import BaseIcon from './baseIcon'
import BaseIcon from './BaseIcon'

type Props = {
icon: string,
color: ColorKey,
w?: string,
h?: string,
bg?: boolean,
className?: string
}

export default function IconRounded({
icon,
Expand All @@ -8,7 +19,7 @@ export default function IconRounded({
h = 'h-12',
bg = false,
className = '',
}) {
}: Props) {
const classAddon = bg ? colorsBgLight[color] : `${colorsText[color]} bg-gray-50 dark:bg-slate-800`

return (
Expand Down
20 changes: 14 additions & 6 deletions components/navBar.js → components/NavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
import { useState } from 'react'
import React, { ReactNode, useState } from 'react'
import { mdiClose, mdiDotsVertical } from '@mdi/js'
import { containerMaxW } from '../src/config'
import BaseIcon from './baseIcon'
import NavBarItemPlain from './navBarItemPlain'
import NavBarMenuList from './navBarMenuList'
import BaseIcon from './BaseIcon'
import NavBarItemPlain from './NavBarItemPlain'
import NavBarMenuList from './NavBarMenuList'
import { MenuNavBarItem } from '../interfaces'

export default function NavBar({ menu, handleMenuClick, className, children }) {
type Props = {
menu: MenuNavBarItem[],
handleMenuClick: Function,
className: string,
children: ReactNode
}

export default function NavBar({ menu, handleMenuClick, className='', children }: Props) {
const [isMenuNavBarActive, setIsMenuNavBarActive] = useState(false)

const handleMenuNavBarToggleClick = (e) => {
const handleMenuNavBarToggleClick = (e: MouseEvent) => {
e.preventDefault()

setIsMenuNavBarActive(!isMenuNavBarActive)
Expand Down
Loading

0 comments on commit 838e745

Please sign in to comment.