Skip to content

Commit

Permalink
1247 configure/review page redesign (#1252)
Browse files Browse the repository at this point in the history
## Description

This PR introduces some updates to the `configure` and `review` pages,
tweaking the section header components. To accomplish this, two new
complex components were introduced:

- `Tooltip` - powered by [Floating UI](https://floating-ui.com/)
(popperJS 3.0)

In addition to the above, there are some refactoring on how theming
works across Zarf UI, with the introduction of using the `html`
`data-theme` property until such time that Unicorn UI's theming is fully
mature.

## Related Issue

Fixes #1247 

## Type of change

- [x] New feature (non-breaking change which adds functionality)

## Checklist before merging

- [ ] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://github.com/defenseunicorns/zarf/blob/main/CONTRIBUTING.md#developer-workflow)
followed
  • Loading branch information
Noxsios authored Jan 25, 2023
1 parent 1106130 commit 62a70b6
Show file tree
Hide file tree
Showing 15 changed files with 339 additions and 131 deletions.
27 changes: 27 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@defense-unicorns/unicorn-ui": "0.0.32",
"@floating-ui/dom": "^1.1.0",
"@fontsource/roboto": "4.5.8",
"@material/card": "14.0.0",
"@material/data-table": "14.0.0",
Expand Down
6 changes: 1 addition & 5 deletions src/ui/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ body > div {
.page .actionButtonsContainer {
display: flex;
justify-content: space-between;
margin-top: 2rem;
}
.page .page-section {
gap: 20px;
gap: 4px;
display: flex;
flex-direction: column;
}
.page .page-header {
margin-top: 2rem;
}

/* Shorthand Classes */
.invisible {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/lib/components/header.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
display: flex;
align-items: center;
background-color: #0d133d;
color: var(--mdc-theme-text-secondary-on-dark);
color: rgba(255, 255, 255, 0.7);
padding: 0.5rem 1rem;
justify-content: space-between;
}
Expand Down
18 changes: 8 additions & 10 deletions src/ui/lib/components/icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
-->
<script lang="ts">
import { Box } from '@ui';
import type { MaterialSymbol } from 'material-symbols';
import { themeStore } from '$lib/store';
<script lang="ts" context="module">
const zarfSymbols = ['package', 'component'];
type ZarfSymbol = (typeof zarfSymbols)[number];
export type IconVariant = MaterialSymbol | ZarfSymbol;
</script>

export let variant: MaterialSymbol | ZarfSymbol;
<script lang="ts">
import { Box } from '@ui';
import type { MaterialSymbol } from 'material-symbols';
export let variant: IconVariant;
export let element = 'span';
let extraClasses = '';
export { extraClasses as class };
$: stroke = $themeStore === 'dark' ? 'var(--mdc-theme-on-background)' : '#0D133D';
</script>

{#if zarfSymbols.includes(variant)}
Expand All @@ -31,7 +31,6 @@
>
<path
d="M26.0213 4.10413L18.0005 7.02079M26.0213 4.10413L18.0005 1.91663L9.97965 4.10413M26.0213 4.10413V15.0416M18.0005 7.02079L9.97965 4.10413M18.0005 7.02079V17.9583M9.97965 4.10413V15.0416M26.0213 15.0416L18.0005 17.9583M26.0213 15.0416L34.0422 17.9583M18.0005 17.9583L9.97965 15.0416M18.0005 17.9583V27.4375M18.0005 17.9583L26.0213 20.875M18.0005 17.9583L9.25049 20.875M9.97965 15.0416L1.22965 17.9583M18.0005 27.4375L26.0213 31.0833M18.0005 27.4375L9.25049 31.0833M26.0213 31.0833V20.875M26.0213 31.0833L34.0422 26.7083V17.9583M26.0213 20.875L34.0422 17.9583M9.25049 31.0833L1.22965 26.7083V17.9583M9.25049 31.0833V20.875M1.22965 17.9583L9.25049 20.875"
{stroke}
stroke-width="2"
/>
</svg>
Expand All @@ -45,7 +44,6 @@
>
<path
d="M17.4236 5.62058L13.6364 1.83337L4.16834 3.96368L7.95554 8.46099M17.4236 5.62058L21.6842 1.83337L31.3889 4.67378L27.1283 8.46099M17.4236 5.62058L7.95554 8.46099M17.4236 5.62058L27.1283 8.46099M27.1283 8.46099L32.0833 12.25L22.6042 16.4167L17.2581 12.25M27.1283 8.46099L17.2581 12.25M17.2581 12.25L12.3958 16.4167L2.91667 11.5556L7.95554 8.46099M17.2581 12.25L7.95554 8.46099M8.42894 14.618V22.663L17.6603 26.2135L27.1283 22.4263V14.618"
{stroke}
stroke-width="2"
/>
</svg>
Expand Down
4 changes: 4 additions & 0 deletions src/ui/lib/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import Hero from './hero.svelte';
import Icon from './icon.svelte';
import PackageComponentAccordion from './package-component-accordion.svelte';
import PackageDetailsCard from './package-details-card.svelte';
import PackageErrNotFound from './package-err-not-found.svelte';
import PackageSectionHeader from './package-section-header.svelte';
import Spinner from './spinner.svelte';
import ThemeToggle from './theme-toggle.svelte';
import YamlCode from './yaml-code.svelte';
Expand All @@ -20,6 +22,8 @@ export {
Icon,
PackageComponentAccordion,
PackageDetailsCard,
PackageErrNotFound,
PackageSectionHeader,
Spinner,
ThemeToggle,
YamlCode
Expand Down
40 changes: 40 additions & 0 deletions src/ui/lib/components/package-err-not-found.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
-->
<script lang="ts">
import { Dialog, Typography, Button } from '@ui';
import bigZarf from '@images/zarf-bubbles-right.png';
export let pkgName: string;
</script>

<Dialog open clickAway={false}>
<div slot="content" class="dialog-content">
<!-- @Noxsios TODO: replace w/ sad zarf -->
<img class="zarf-logo" width={60} height={60} src={bigZarf} alt="zarf-logo" />
<Typography variant="h6">Package Not Found</Typography>
<Typography variant="body2">
Make sure the following package is in the current working directory:
</Typography>
<Typography variant="code"><code>{pkgName}</code></Typography>
<div class="actions">
<Button href="/" color="secondary" variant="flat"
>Return Home</Button
>
</div>
</div>
</Dialog>

<style>
.dialog-content {
display: flex;
gap: 1rem;
flex-direction: column;
align-items: center;
}
.actions {
display: flex;
width: 100%;
justify-content: flex-end;
}
</style>
61 changes: 61 additions & 0 deletions src/ui/lib/components/package-section-header.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!--
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
-->
<script lang="ts">
import Icon from './icon.svelte';
import Tooltip from './tooltip.svelte';
import type { IconVariant } from './icon.svelte';
export let icon: IconVariant = 'package';
</script>

<div class="pkg-section-header">
<div class="pkg-section-header-title">
<Icon variant={icon} />
<slot name="title" />
{#if $$slots.tooltip}
<div class="tooltip-container"><Tooltip><slot name="tooltip" /></Tooltip></div>
{/if}
</div>
{#if $$slots.actions}
<div class="pkg-section-header-actions">
<slot name="actions" />
</div>
{/if}
</div>

<style>
.pkg-section-header-title {
display: flex;
align-items: center;
gap: 0.75rem;
}
.pkg-section-header {
display: flex;
justify-content: space-between;
background-color: var(--mdc-theme-paper);
color: var(--mdc-theme-on-secondary);
stroke: var(--mdc-theme-on-secondary);
padding: 0.75rem 2rem;
}
:global(:root[data-theme='dark']) .pkg-section-header {
background-color: var(--mdc-theme-surface);
}
.pkg-section-header-actions {
display: flex;
align-items: center;
}
.tooltip-container {
display: inline-flex;
align-items: center;
}
:global(.tooltip-container .tooltip-trigger) {
color: rgba(255, 255, 255, 0.56);
}
:global(.tooltip-container .tooltip) {
color: var(--mdc-theme-on-primary);
}
:global(:root[data-theme='dark'] .tooltip-container .tooltip) {
color: var(--mdc-theme-on-secondary);
}
</style>
121 changes: 121 additions & 0 deletions src/ui/lib/components/tooltip.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!--
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2021-Present The Zarf Authors
-->
<script lang="ts">
import Icon from './icon.svelte';
import { computePosition, flip, shift, offset, arrow, autoUpdate } from '@floating-ui/dom';
import { onDestroy, onMount } from 'svelte';
let tooltip: HTMLElement;
let icon: HTMLElement;
let arrowRef: HTMLElement;
type Placement =
| 'top'
| 'bottom'
| 'left'
| 'right'
| 'top-start'
| 'top-end'
| 'bottom-start'
| 'bottom-end'
| 'left-start'
| 'left-end'
| 'right-start'
| 'right-end';
export let placement: Placement = 'top';
function update() {
computePosition(icon, tooltip, {
placement,
middleware: [offset(6), flip(), shift(), arrow({ element: arrowRef })]
}).then(({ x, y, placement, middlewareData }) => {
Object.assign(tooltip.style, {
left: `${x}px`,
top: `${y}px`
});
const arrowX = middlewareData.arrow?.x;
const arrowY = middlewareData.arrow?.y;
const staticSide: any = {
top: 'bottom',
right: 'left',
bottom: 'top',
left: 'right'
}[placement.split('-')[0]];
Object.assign(arrowRef.style, {
left: arrowX != undefined ? `${arrowX}px` : '',
top: arrowY != undefined ? `${arrowY}px` : '',
right: '',
bottom: '',
[staticSide]: '-4px'
});
});
}
function showTooltip() {
tooltip.style.display = 'block';
update();
}
function hideTooltip() {
tooltip.style.display = '';
}
let cleanup: () => void;
onMount(() => {
cleanup = autoUpdate(icon, tooltip, update);
});
onDestroy(() => {
cleanup();
});
</script>

<button
aria-describedby="tooltip"
bind:this={icon}
on:mouseenter={showTooltip}
on:mouseleave={hideTooltip}
on:focus={showTooltip}
on:blur={hideTooltip}
class="tooltip-trigger"
>
<Icon variant="info" /></button
>
<div role="tooltip" bind:this={tooltip} class="tooltip">
<slot />
<div bind:this={arrowRef} class="arrow" />
</div>

<style>
.tooltip {
display: none;
width: max-content;
position: absolute;
top: 0;
left: 0;
background: var(--mdc-theme-surface);
border: 1px solid var(--mdc-theme-on-surface);
font-weight: bold;
padding: 5px;
border-radius: 4px;
font-size: 90%;
}
.arrow {
position: absolute;
background: var(--mdc-theme-surface);
border-bottom: 1px solid var(--mdc-theme-on-surface);
border-right: 1px solid var(--mdc-theme-on-surface);
width: 8px;
height: 8px;
transform: rotate(45deg);
}
.tooltip-trigger {
background: inherit;
border: none;
padding: 0;
}
</style>
Loading

0 comments on commit 62a70b6

Please sign in to comment.