Skip to content

Commit

Permalink
Merge pull request #892 from openSUSE/section-improvements-20231127
Browse files Browse the repository at this point in the history
[web] Agama/Section fixes and improvements
  • Loading branch information
dgdavid authored Nov 30, 2023
2 parents 97944c1 + e1dd886 commit c47fc31
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 15 deletions.
6 changes: 6 additions & 0 deletions web/package/cockpit-agama.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Nov 29 13:01:04 UTC 2023 - David Diaz <[email protected]>

- UI: improve the look and feel by fine tunning the sections spacing,
alignment, and icon sizes (gh#openSUSE/agama#892).

-------------------------------------------------------------------
Tue Nov 21 15:21:06 UTC 2023 - David Diaz <[email protected]>

Expand Down
10 changes: 9 additions & 1 deletion web/src/assets/styles/blocks.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// section layouts.
section:not([class^="pf-c"]) {
display: grid;
grid-template-columns: min-content 1fr;
grid-template-columns: var(--section-icon-size) 1fr;
grid-template-areas:
"icon title"
".... content";
gap: var(--spacer-small);
padding-inline-start: calc(
var(--header-icon-size) - var(--section-icon-size)
);
padding-inline-end: var(--section-icon-size);
}

section:not(:last-child, [class^="pf-c"]) {
Expand All @@ -16,6 +20,8 @@ section:not(:last-child, [class^="pf-c"]) {

section > svg {
grid-area: icon;
block-size: var(--section-icon-size);
inline-size: var(--section-icon-size);
}

section > h2 {
Expand Down Expand Up @@ -84,6 +90,7 @@ section > .content {
right: 0;
z-index: 1000;
inline-size: 70%;
min-inline-size: min-content;
box-shadow: -10px 10px 20px 0 var(--color-primary);
}

Expand Down Expand Up @@ -140,6 +147,7 @@ section > .content {
.sidebar[data-state="hidden"] {
transition: all 0.04s ease-in-out;
inline-size: 0;
min-inline-size: 0;
box-shadow: none;
}

Expand Down
4 changes: 3 additions & 1 deletion web/src/assets/styles/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,16 @@

svg {
color: white;
block-size: var(--header-icon-size);
inline-size: var(--header-icon-size);
}
}

.wrapper > main {
grid-area: content;
overflow-y: auto; // Sadly, only Firefox supports overflow-block at this moment (Jan 2023)
overflow-block: auto;
padding: var(--spacer-medium);
padding: var(--spacer-medium) var(--spacer-small);
}

.wrapper > footer {
Expand Down
5 changes: 5 additions & 0 deletions web/src/assets/styles/utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@
height: 24px;
}

.icon-size-28 {
width: 28px;
height: 28px;
}

.icon-size-32 {
width: 32px;
height: 32px;
Expand Down
5 changes: 3 additions & 2 deletions web/src/assets/styles/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
--stack-gutter: var(--spacer-normal);
--split-gutter: var(--spacer-small);

--wrapper-padding: var(--spacer-normal);
--wrapper-padding: var(--spacer-small);
--wrapper-background: white;

--color-primary: #0c322c;
Expand Down Expand Up @@ -60,7 +60,8 @@
--gradient-border-start-color: var(--color-gray);
--gradient-border-end-color: transparent;

--icon-size-m: 32px;
--header-icon-size: 32px;
--section-icon-size: 28px;

--header-block-size: auto;
--footer-block-size: auto;
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/core/Page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function Page({
return (
<>
{ title && <Title>{title}</Title> }
{ icon && <PageIcon><Icon name={icon} /></PageIcon> }
{ icon && <PageIcon><Icon name={icon} size="32" /></PageIcon> }
<MainActions>
{ action ||
<Button size="lg" variant={actionVariant} onClick={pageAction}>
Expand Down
8 changes: 5 additions & 3 deletions web/src/components/core/Section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,14 @@ export default function Section({
const Header = () => {
if (!title?.trim()) return;

const header = !path?.trim() ? <>{title}</> : <Link to={path}>{title}</Link>;
const iconName = loading ? "loading" : icon;
const headerIcon = iconName ? <Icon name={iconName} /> : null;
const headerText = !path?.trim() ? title : <Link to={path}>{title}</Link>;

return (
<>
<Icon name={loading ? "loading" : icon} />
<h2 id={headerId}>{header}</h2>
{headerIcon}
<h2 id={headerId}>{headerText}</h2>
</>
);
};
Expand Down
9 changes: 3 additions & 6 deletions web/src/components/core/Section.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ describe("Section", () => {
const { container } = plainRender(<Section title="Settings" />);
const icon = container.querySelector("svg");
expect(icon).toBeNull();
// Check that <Icon /> component was not mounted with 'undefined'
expect(console.error).not.toHaveBeenCalled();
});

it("does not render an icon if not valid icon name is given", () => {
Expand All @@ -70,12 +72,6 @@ describe("Section", () => {
const icon = container.querySelector("svg");
expect(icon).toBeNull();
});

it("does not render the loading icon", () => {
const { container } = plainRender(<Section loading />);
const icon = container.querySelector("svg");
expect(icon).toBeNull();
});
});

describe("when aria-label is given", () => {
Expand Down Expand Up @@ -166,6 +162,7 @@ describe("Section", () => {
expect(icon).toBeNull();
});
});

describe("when path is given", () => {
it("renders a link for navigating to it", async () => {
installerRender(<Section title="Settings" path="/settings" />);
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/layout/Icon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ const icons = {
* @param {object} [props.otherProps] Other props sent to SVG icon.
*
*/
export default function Icon({ name, className = "", size = 32, ...otherProps }) {
export default function Icon({ name, className = "", size = 28, ...otherProps }) {
if (!name) {
console.error(`Icon called without name. '${name}' given instead. Rendering nothing.`);
return null;
Expand Down

0 comments on commit c47fc31

Please sign in to comment.