Skip to content

Commit 136d726

Browse files
committed
refactor: Refactor AppBar component
1 parent 79bb2c4 commit 136d726

File tree

6 files changed

+40
-32
lines changed

6 files changed

+40
-32
lines changed

apps/solid/src/layout/app-bars/bottom-app-bar.component.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,14 @@ import { AppBar, Button } from '@spuxx/solid';
22

33
export const BottomAppBar = () => {
44
return (
5-
<AppBar
6-
position="bottom"
7-
tag="footer"
8-
center={
5+
<AppBar position="bottom" tag="footer">
6+
<AppBar.Section>
97
<a href="https://spuxx.dev">
108
<Button variant="colored" color="text-default" rounded>
119
Made with ❤️ by spuxx
1210
</Button>
1311
</a>
14-
}
15-
/>
12+
</AppBar.Section>
13+
</AppBar>
1614
);
1715
};

apps/solid/src/layout/app-bars/top-app-bar.component.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import { AppBar, Button } from '@spuxx/solid';
22

33
export const TopAppBar = () => {
44
return (
5-
<AppBar
6-
left={<Button icon="mdi:menu" title="Menu" variant="colored" color="text-default" rounded />}
7-
center={
5+
<AppBar>
6+
<AppBar.Section>
7+
<a href="/">
8+
<Button icon="mdi:menu" title="Menu" variant="colored" color="text-default" rounded />
9+
</a>
10+
</AppBar.Section>
11+
<AppBar.Section>
812
<a href="/">
913
<Button title="Home" variant="colored" color="text-default" rounded>
1014
@spuxx/solid
1115
</Button>
1216
</a>
13-
}
14-
right={
17+
</AppBar.Section>
18+
<AppBar.Section>
1519
<a href="https://github.com/spuxx-dev/jslibs" target="_blank">
1620
<Button icon="mdi:github" title="GitHub" variant="colored" color="text-default" rounded />
1721
</a>
18-
}
19-
/>
22+
</AppBar.Section>
23+
</AppBar>
2024
);
2125
};

packages/browser-utils/src/styles/components/layout/app-bar.css

+3-8
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@
2121
bottom: 0;
2222
}
2323

24-
/* .spx-app-bar-left,
25-
.spx-app-bar-right,
26-
.spx-app-bar-center {
27-
> .spx-button {
28-
height: var(--spx-app-bar-height);
29-
font-size: x-large;
30-
}
31-
} */
24+
&:has(.spx-app-bar-section:only-child) {
25+
justify-content: center;
26+
}
3227
}

packages/solid/src/components/layout/app-bar/app-bar.component.test.tsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ describe('AppBar', () => {
1010
expect(appBar.tagName).toBe('HEADER');
1111
expect(appBar).toHaveClass('spx', 'spx-app-bar');
1212
expect(appBar).toHaveAttribute('spx-position', 'top');
13-
expect(appBar.children).toHaveLength(3);
14-
expect(appBar.children[0]).toHaveClass('spx', 'spx-app-bar-left');
15-
expect(appBar.children[1]).toHaveClass('spx', 'spx-app-bar-center');
16-
expect(appBar.children[2]).toHaveClass('spx', 'spx-app-bar-right');
13+
expect(appBar.children).toHaveLength(0);
1714
});
1815

1916
it('should render with custom values', () => {
@@ -27,7 +24,11 @@ describe('AppBar', () => {
2724

2825
it('should render with children', () => {
2926
const { getByRole } = render(() => (
30-
<AppBar left={<div>Left</div>} center={<div>Center</div>} right={<div>Right</div>} />
27+
<AppBar>
28+
<AppBar.Section>Left</AppBar.Section>
29+
<AppBar.Section>Center</AppBar.Section>
30+
<AppBar.Section>Right</AppBar.Section>
31+
</AppBar>
3132
));
3233
const appBar = getByRole('banner');
3334
expect(appBar).toBeInTheDocument();
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import { AppBarProps, attributes, classNames } from '@src/main';
2-
import { Component } from 'solid-js';
2+
import { Component, ParentProps } from 'solid-js';
33
import { Dynamic } from 'solid-js/web';
44

5-
export const AppBar: Component<AppBarProps> = (props) => {
5+
const Section: Component<ParentProps> = (props) => (
6+
<div {...classNames('spx-app-bar-section')}>{props.children}</div>
7+
);
8+
9+
const AppBar: Component<AppBarProps> & {
10+
Section: Component<ParentProps>;
11+
} = ((props) => {
612
const { position = 'top', tag = 'header' } = props;
713

814
return (
@@ -12,9 +18,12 @@ export const AppBar: Component<AppBarProps> = (props) => {
1218
component={tag}
1319
spx-position={position}
1420
>
15-
<div {...classNames('spx-app-bar-left')}>{props.left}</div>
16-
<div {...classNames('spx-app-bar-center')}>{props.center}</div>
17-
<div {...classNames('spx-app-bar-right')}>{props.right}</div>
21+
{props.children}
1822
</Dynamic>
1923
);
24+
}) as Component<AppBarProps> & {
25+
Section: Component<ParentProps>;
2026
};
27+
AppBar.Section = Section;
28+
29+
export { AppBar };

packages/solid/src/components/layout/app-bar/app-bar.types.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { ComponentProps } from '@src/main';
2+
import { ParentProps } from 'solid-js';
23
import { JSX } from 'solid-js/jsx-runtime';
34

45
/**
56
* The AppBar component properties.
67
*/
7-
export interface AppBarProps extends ComponentProps<JSX.HTMLAttributes<HTMLElement>> {
8+
export interface AppBarProps extends ComponentProps<JSX.HTMLAttributes<HTMLElement>>, ParentProps {
89
/**
910
* The position of the app bar.
1011
* @default 'top'

0 commit comments

Comments
 (0)