Skip to content

Commit

Permalink
add end_links to Navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelcolvin committed Feb 10, 2024
1 parent 4431809 commit 53ac8b2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion demo/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def demo_page(*components: AnyComponent, title: str | None = None) -> list[AnyCo
c.Navbar(
title='FastUI Demo',
title_event=GoToEvent(url='/'),
links=[
start_links=[
c.Link(
components=[c.Text(text='Components')],
on_click=GoToEvent(url='/components'),
Expand Down
15 changes: 13 additions & 2 deletions src/npm-fastui-bootstrap/src/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { components, useClassName, models } from 'fastui'
import BootstrapNavbar from 'react-bootstrap/Navbar'

export const Navbar: FC<models.Navbar> = (props) => {
const links = props.links.map((link) => {
const startLinks = props.startLinks.map((link) => {
link.mode = link.mode || 'navbar'
return link
})
const endLinks = props.endLinks.map((link) => {
link.mode = link.mode || 'navbar'
return link
})
Expand All @@ -14,7 +18,14 @@ export const Navbar: FC<models.Navbar> = (props) => {
<BootstrapNavbar.Toggle aria-controls="navbar-collapse" />
<BootstrapNavbar.Collapse id="navbar-collapse">
<ul className="navbar-nav me-auto">
{links.map((link, i) => (
{startLinks.map((link, i) => (
<li key={i} className="nav-item">
<components.LinkComp {...link} />
</li>
))}
</ul>
<ul className="navbar-nav ms-auto">
{endLinks.map((link, i) => (
<li key={i} className="nav-item">
<components.LinkComp {...link} />
</li>
Expand Down
11 changes: 9 additions & 2 deletions src/npm-fastui/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ import { useClassName } from '../hooks/className'
import { LinkComp, LinkRender } from './link'

export const NavbarComp = (props: Navbar) => {
const links = props.links.map((link) => {
const startLinks = props.startLinks.map((link) => {
link.mode = link.mode || 'navbar'
return link
})
const endLinks = props.endLinks.map((link) => {
link.mode = link.mode || 'navbar'
return link
})
return (
<nav className={useClassName(props)}>
<div className={useClassName(props, { el: 'contents' })}>
<NavbarTitle {...props} />
{links.map((link, i) => (
{startLinks.map((link, i) => (
<LinkComp key={i} {...link} />
))}
{endLinks.map((link, i) => (
<LinkComp key={i} {...link} />
))}
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/npm-fastui/src/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ export interface LinkList {
export interface Navbar {
title?: string
titleEvent?: PageEvent | GoToEvent | BackEvent | AuthEvent
links: Link[]
startLinks: Link[]
endLinks: Link[]
className?: ClassName
type: 'Navbar'
}
Expand Down
5 changes: 3 additions & 2 deletions src/python-fastui/fastui/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ class LinkList(_p.BaseModel, extra='forbid'):
class Navbar(_p.BaseModel, extra='forbid'):
title: _t.Union[str, None] = None
title_event: _t.Union[events.AnyEvent, None] = _p.Field(default=None, serialization_alias='titleEvent')
links: _t.List[Link] = _p.Field(default=[])
start_links: _t.List[Link] = _p.Field(default=[], serialization_alias='startLinks')
end_links: _t.List[Link] = _p.Field(default=[], serialization_alias='endLinks')
class_name: _class_name.ClassNameField = None
type: _t.Literal['Navbar'] = 'Navbar'

Expand All @@ -188,7 +189,7 @@ def __get_pydantic_json_schema__(
) -> _t.Any:
# until https://github.com/pydantic/pydantic/issues/8413 is fixed
json_schema = handler(core_schema)
json_schema.setdefault('required', []).append('links')
json_schema.setdefault('required', []).extend(['startLinks', 'endLinks'])
return json_schema


Expand Down

0 comments on commit 53ac8b2

Please sign in to comment.