Skip to content

Commit

Permalink
wip: adding more components
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Oct 29, 2024
1 parent 4c75474 commit 94a35ff
Show file tree
Hide file tree
Showing 20 changed files with 432 additions and 85 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/check-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
branches:
- main
paths:
- "**"
- "!README.md"
- '**'
- '!README.md'

jobs:
lint:
Expand Down Expand Up @@ -53,4 +53,4 @@ jobs:
permissions:
contents: read
pull-requests: read
checks: write
checks: write
2 changes: 1 addition & 1 deletion src/components/account-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type AvatarButtonProps = {
const AvatarButton = forwardRef<AvatarButtonProps, 'div'>(
({ name, picture, isActive, hasBadge, ...props }, ref) => (
<div ref={ref} {...props} className={cx('cursor-pointer')}>
<ActiveCircle>
<ActiveCircle isActive={isActive}>
<NotificationBadge hasBadge={hasBadge}>
<Avatar
name={name}
Expand Down
8 changes: 5 additions & 3 deletions src/components/app-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { ReactElement } from 'react'
import cx from 'classnames'

export type AppBarProps = {
bar: ReactElement
buttons: ReactElement
bar?: ReactElement
buttons?: ReactElement
}

export const AppBar = ({ bar, buttons }: AppBarProps) => (
Expand All @@ -18,7 +18,9 @@ export const AppBar = ({ bar, buttons }: AppBarProps) => (
'w-full',
)}
>
<div className={cx('grow')}>{bar}</div>
<div className={cx('flex', 'flex-row', 'items-center', 'gap-1.5', 'grow')}>
{bar}
</div>
<div className={cx('flex', 'flex-row', 'items-center', 'gap-1.5')}>
{buttons}
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/components/auxiliary-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const AuxiliaryDrawer = ({
}: AuxiliaryDrawerProps) => {
const buttonRef = useRef<HTMLButtonElement>(null)
return (
<>
<div className="inline-block">
<NotificationBadge hasBadge={hasBadge}>
<IconButton
ref={buttonRef}
Expand All @@ -59,6 +59,6 @@ export const AuxiliaryDrawer = ({
<DrawerFooter>{footer}</DrawerFooter>
</DrawerContent>
</Drawer>
</>
</div>
)
}
2 changes: 1 addition & 1 deletion src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ export * from './text'
export * from './logo'
export * from './app-bar'
export * from './auxiliary-drawer'
export * from './navigation-item'
export * from './nav-bar'
export * from './search-bar'
export * from './account-menu'
4 changes: 2 additions & 2 deletions src/components/layout-drawer/layout-drawer-context.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { createContext } from 'react'

export type DrawerContextType = {
export type LayoutDrawerContextType = {
isCollapsed: boolean | undefined
isTouched: boolean
}

export const LayoutDrawerContext = createContext<DrawerContextType>({
export const LayoutDrawerContext = createContext<LayoutDrawerContextType>({
isCollapsed: undefined,
isTouched: false,
})
1 change: 0 additions & 1 deletion src/components/layout-drawer/layout-drawer-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export type DrawerItemProps = {
href: string
primaryText: string
secondaryText: string
isActive?: boolean
pathnameFn: () => string
navigateFn: (href: string) => void
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/layout-drawer/layout-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { StorageOptions } from '../../types'
import { IconChevronLeft, IconChevronRight } from '../icons'
import { LayoutDrawerContext } from './layout-drawer-context'

export type DrawerProps = {
export type LayoutDrawerProps = {
children?: ReactNode
logo?: ReactNode
storage?: StorageOptions
Expand All @@ -19,7 +19,7 @@ export const LayoutDrawer = ({
logo,
homeHref,
navigateFn,
}: DrawerProps) => {
}: LayoutDrawerProps) => {
const [isCollapsed, setIsCollapsed] = useState<boolean | undefined>(undefined)
const [isTouched, setIsTouched] = useState(false)
const localStorageCollapsedKey = useMemo(
Expand Down
85 changes: 85 additions & 0 deletions src/components/nav-bar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { useEffect, useState } from 'react'
import { Link as ChakraLink } from '@chakra-ui/react'
import cx from 'classnames'

export type NavBarProps = {
items: NavItem[]
pathnameFn: () => string
navigateFn: (href: string) => void
}

export type NavItem = {
title: string
href: string
isActive?: boolean
}

export const NavBar = ({ items, pathnameFn, navigateFn }: NavBarProps) => {
return (
<div className={cx('flex', 'flex-row', 'gap-1.5')}>
{items
? items.map((item, index) => (
<Item
key={index}
title={item.title}
href={item.href}
pathnameFn={pathnameFn}
navigateFn={navigateFn}
/>
))
: null}
</div>
)
}

type ItemProps = {
title: string
href: string
pathnameFn: () => string
navigateFn: (href: string) => void
}

const Item = ({ title, href, pathnameFn, navigateFn }: ItemProps) => {
const pathname = pathnameFn()
const [isActive, setIsActive] = useState(false)

useEffect(() => {
if (
(href === '/' && pathname === '/') ||
(href !== '/' && pathname.startsWith(href))
) {
setIsActive(true)
} else {
setIsActive(false)
}
}, [pathname, href])

return (
<ChakraLink
variant="no-underline"
className={cx(
'flex',
'items-center',
'opacity-100',
'hover:opacity-80',
'h-[40px]',
'rounded-xl',
'pt-0',
'pr-[20px]',
'pb-0',
'pl-[20px]',
'font-semibold',
{
'text-white': isActive,
'dark:text-gray-600': isActive,
'bg-black': isActive,
'dark:bg-white': isActive,
'bg-transparent': !isActive,
},
)}
onClick={() => navigateFn(href)}
>
{title}
</ChakraLink>
)
}
42 changes: 0 additions & 42 deletions src/components/navigation-item.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/search-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const SearchBar = ({
}, [])

return (
<div className={cx('flex', 'flex-row', 'gap-0.5')}>
<div className={cx('flex', 'flex-row', 'gap-0.5', 'grow')}>
<InputGroup>
<InputLeftElement pointerEvents="none">
<Icon as={IconSearch} className={cx('text-gray-300')} />
Expand Down
40 changes: 21 additions & 19 deletions src/components/shell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ import cx from 'classnames'
import { StorageOptions } from '../types'
import { LayoutDrawer, LayoutDrawerItem } from './layout-drawer'

export type ShellItem = {
href: string
icon: ReactElement
primaryText: string
secondaryText: string
}

export type ShellProps = {
storage?: StorageOptions
logo: ReactElement
topBar: ReactElement
items: ShellItem[]
items?: ShellItem[]
children?: ReactElement
onContentClick?: (event: MouseEvent) => void
pathnameFn: () => string
navigateFn: (href: string) => void
}

export type ShellItem = {
href: string
icon: ReactElement
primaryText: string
secondaryText: string
}

export const Shell = ({
logo,
topBar,
Expand All @@ -33,17 +33,19 @@ export const Shell = ({
}: ShellProps) => (
<div className={cx('flex', 'flex-row', 'items-center', 'gap-0', 'h-full')}>
<LayoutDrawer storage={storage} logo={logo} navigateFn={navigateFn}>
{items.map((item, index) => (
<LayoutDrawerItem
key={index}
href={item.href}
icon={item.icon}
primaryText={item.primaryText}
secondaryText={item.secondaryText}
pathnameFn={pathnameFn}
navigateFn={navigateFn}
/>
))}
{items
? items.map((item, index) => (
<LayoutDrawerItem
key={index}
href={item.href}
icon={item.icon}
primaryText={item.primaryText}
secondaryText={item.secondaryText}
pathnameFn={pathnameFn}
navigateFn={navigateFn}
/>
))
: null}
</LayoutDrawer>
<div
className={cx('flex', 'flex-col', 'items-center', 'h-full', 'w-full')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import {
NumberTag,
SearchBar,
Shell,
} from '../components'
} from '../../components'

const meta: Meta<typeof Shell> = {
title: 'Components/Shell',
title: 'Bundles/Layout',
component: Shell,
parameters: {
layout: 'fullscreen',
Expand All @@ -32,7 +32,7 @@ const meta: Meta<typeof Shell> = {
export default meta
type Story = StoryObj<typeof Shell>

export const Default: Story = {
export const ShellWithAppBar: Story = {
render: () => {
const location = useLocation()
const navigate = useNavigate()
Expand All @@ -42,7 +42,7 @@ export const Default: Story = {

return (
<Shell
storage={{ prefix: 'lorem-ipsum', namespace: 'main' }}
storage={{ prefix: 'layout', namespace: 'main' }}
logo={<Logo type="voltaserve" size="sm" />}
topBar={
<AppBar
Expand Down Expand Up @@ -124,7 +124,7 @@ export const Default: Story = {
}
items={[
{
href: '/workspace',
href: '/',
icon: <IconWorkspaces />,
primaryText: 'Workspaces',
secondaryText: 'Isolated containers for files and folders.',
Expand All @@ -143,7 +143,7 @@ export const Default: Story = {
},
]}
pathnameFn={() => location.pathname}
navigateFn={(href: string) => navigate(href)}
navigateFn={navigate}
></Shell>
)
},
Expand Down
Loading

0 comments on commit 94a35ff

Please sign in to comment.