Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UI #4750

Merged
merged 2 commits into from
Oct 6, 2024
Merged

Fix UI #4750

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
z-index: 2;
top: var(--space-xsmall);
right: var(--space-xsmall);
background: var(--color-background);
border-radius: var(--radius-medium);
}

/** fix control group with nested components */
Expand All @@ -21,8 +23,18 @@
box-shadow: none;
}

/** Source content */
.content {
position: relative;
z-index: 1;
height: 100%;
background: var(--color-highlight);
color: var(--color-text);
}

/** Empty / loading state */
.isEmpty .content {
pointer-events: none;
background: var(--skeleton-block-background);
opacity: var(--skeleton-opacity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ export const Default: Story = {
download: 'bundle-stats--assets.json',
},
};

export const Empty: Story = {
args: {
download: 'bundle-stats--assets.json',
},
};
49 changes: 30 additions & 19 deletions packages/ui/src/components/preview-source/preview-source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ import { Tooltip } from '../../ui/tooltip';
import { Textarea } from '../../ui/textarea';
import css from './preview-source.module.css';

const DEFAULT_ROWS = 10;

type PreviewSourceProps = {
source: string;
source?: string;
/**
* Textarea rows
*/
rows?: number;
/**
* Link download attribute
* @example
Expand All @@ -20,26 +26,31 @@ type PreviewSourceProps = {
} & ComponentProps<'div'>;

export const PreviewSource = (props: PreviewSourceProps) => {
const { className = '', source, download = false, ...restProps } = props;
const { className = '', source, rows = DEFAULT_ROWS, download = false, ...restProps } = props;

const isEmpty = !source;
const rootClassName = cx(css.root, className, isEmpty && css.isEmpty);

return (
<div className={cx(css.root, className)} {...restProps}>
<ControlGroup className={css.toolbar}>
<CopyToClipboard outline size="small" text={source} />
{download && (
<Tooltip title={`Download ${download}`} className={css.downloadTooltip}>
<Button
outline
rightGlyph={BUTTON_GLYPHS.DOWNLOAD}
size="small"
as="a"
href={`data:application/json,${encodeURIComponent(source)}`}
download={download}
/>
</Tooltip>
)}
</ControlGroup>
<Textarea previewSource readOnly rows={12} className={css.content}>
<div className={rootClassName} {...restProps}>
{source && (
<ControlGroup className={css.toolbar}>
<CopyToClipboard outline size="small" text={source} />
{download && (
<Tooltip title={`Download ${download}`} className={css.downloadTooltip}>
<Button
outline
rightGlyph={BUTTON_GLYPHS.DOWNLOAD}
size="small"
as="a"
href={`data:application/json,${encodeURIComponent(source)}`}
download={download}
/>
</Tooltip>
)}
</ControlGroup>
)}
<Textarea previewSource readOnly rows={rows} className={css.content}>
{source}
</Textarea>
</div>
Expand Down
4 changes: 4 additions & 0 deletions packages/ui/src/css/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@

--outline-hover: 0 0 0 var(--space-xxxsmall) var(--color-highlight);

--skeleton-inline-background: linear-gradient(transparent 10%, currentColor 10.1%, currentColor 89.9%, transparent 90%);
--skeleton-block-background: currentColor;
--skeleton-opacity: 0.06;

/** Layout */
--max-width: 88rem;
--entry-info-width: 64rem;
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/ui/dialog/dialog.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,19 @@

/** Width variation */
.width--narrow {
max-width: 480px;
max-width: 360px;
}

.width--medium {
max-width: 748px;
max-width: 640px;
}

.width--wide {
max-width: 1024px;
}

.width--extra-wide {
max-width: var(--max-width);
max-width: calc(var(--max-width) + 2 * var(--space-medium));
}

/** Center variation */
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/ui/skeleton/skeleton.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.root {
background: linear-gradient(transparent 10%, currentColor 10.1%, currentColor 89.9%, transparent 90%);
opacity: 0.05;
background: var(--skeleton-inline-background);
opacity: var(--skeleton-opacity);
pointer-events: none;
min-width: 6em;
border-radius: var(--radius-medium);
Expand All @@ -14,5 +14,5 @@
}

.block {
background: currentColor;
background: var(--skeleton-block-background);
}