-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: update settings ui with react router
- Loading branch information
1 parent
6182596
commit 2b01d51
Showing
29 changed files
with
1,045 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,39 @@ | ||
import { useNavigate } from 'react-router-dom' | ||
import { observer } from 'mobx-react-lite' | ||
import { Breadcrumbs, BreadcrumbItem } from '@nextui-org/react' | ||
import _ from 'lodash' | ||
|
||
export type BreadcrumbType = { | ||
isSelected: boolean | ||
label: string | ||
onClick: () => void | ||
path: string | ||
} | ||
|
||
const BreadcrumbBar = observer( | ||
({ breadcrumbs }: { breadcrumbs: Array<BreadcrumbType | undefined | false> }) => { | ||
return ( | ||
<Breadcrumbs className="mb-2"> | ||
{_.compact(breadcrumbs).map(breadcrumb => ( | ||
<BreadcrumbItem | ||
className={ | ||
breadcrumb.isSelected | ||
? ' [&>*]:!text-primary' | ||
: 'scale-90 [&>*]:!text-base-content/70' | ||
} | ||
isCurrent={breadcrumb.isSelected} | ||
onPress={breadcrumb.onClick} | ||
key={breadcrumb.label} | ||
> | ||
{breadcrumb.label} | ||
</BreadcrumbItem> | ||
))} | ||
</Breadcrumbs> | ||
) | ||
}, | ||
) | ||
type BreadcrumbBarProps = { | ||
breadcrumbs: BreadcrumbType[] | ||
} | ||
|
||
// Gets a list of crumbs and paths and determines the selected one (might be overkill and maybe I should just use the last index) | ||
const BreadcrumbBar = observer(({ breadcrumbs }: BreadcrumbBarProps) => { | ||
const navigate = useNavigate() | ||
|
||
return ( | ||
<Breadcrumbs className="mt-2 place-self-center rounded-lg bg-base-content/10 p-2"> | ||
{breadcrumbs.map((breadcrumb, index) => ( | ||
<BreadcrumbItem | ||
className={ | ||
index === breadcrumbs.length - 1 | ||
? ' [&>*]:!text-primary' | ||
: 'underline decoration-base-content/70 [&>*]:!text-base-content/70' | ||
} | ||
isCurrent={index === breadcrumbs.length - 1} | ||
key={breadcrumb.label} | ||
onClick={() => navigate(breadcrumb.path)} | ||
> | ||
{breadcrumb.label} | ||
</BreadcrumbItem> | ||
))} | ||
</Breadcrumbs> | ||
) | ||
}) | ||
|
||
export default BreadcrumbBar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { MouseEventHandler } from 'react' | ||
import { To, useNavigate } from 'react-router-dom' | ||
|
||
type NavButtonProps<T = Element> = React.HTMLAttributes<T> & { | ||
to: To | ||
replace?: boolean | ||
disabled?: boolean | ||
} | ||
|
||
export const NavButton = ({ | ||
to, | ||
replace = false, | ||
onClick, | ||
...rest | ||
}: NavButtonProps<HTMLButtonElement>) => { | ||
const navigate = useNavigate() | ||
|
||
const handleClick: MouseEventHandler<HTMLButtonElement> = e => { | ||
onClick?.(e) | ||
|
||
if (!e.isDefaultPrevented()) { | ||
navigate(to, { replace }) | ||
} | ||
} | ||
|
||
return <button type="button" {...rest} onClick={handleClick} /> | ||
} | ||
|
||
export const NavButtonDiv = ({ | ||
to, | ||
replace = false, | ||
onClick, | ||
...rest | ||
}: Omit<NavButtonProps<HTMLDivElement>, 'disabled'>) => { | ||
const navigate = useNavigate() | ||
|
||
const handleClick: MouseEventHandler<HTMLDivElement> = e => { | ||
onClick?.(e) | ||
|
||
if (!e.isDefaultPrevented()) { | ||
navigate(to, { replace }) | ||
} | ||
} | ||
|
||
return <div role="button" {...rest} onClick={handleClick} /> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.