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

Updates to headers alignment #4473

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions .changeset/poor-scissors-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@salt-ds/lab": patch
---

Overlay and Dialog headers fix alignment for titles spanning into multiple lines, wrap preheader and headers in H2.
1 change: 1 addition & 0 deletions packages/core/src/dialog/DialogHeader.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/* Styles applied to the status indicator icon overriding its default size */
.saltDialogHeader .saltStatusIndicator.saltIcon {
--icon-size: var(--salt-text-h2-lineHeight);
padding-top: calc((var(--salt-size-base) - var(--salt-text-h2-lineHeight)) / 2);
}

/* Styles applied to DialogHeader when accent={true} */
Expand Down
4 changes: 3 additions & 1 deletion packages/lab/src/dialog/DialogHeader.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
padding-bottom: var(--salt-spacing-300);
padding-left: var(--salt-spacing-300);
padding-right: var(--salt-spacing-300);
align-items: center;
display: flex;
flex-direction: row;
gap: var(--salt-spacing-100);
box-sizing: border-box;
}
.saltDialogHeader-header {
margin: 0;
}

.saltDialogHeader-container {
flex-grow: 1;
Expand Down
9 changes: 4 additions & 5 deletions packages/lab/src/dialog/DialogHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
H2,
StatusIndicator,
Text,
type ValidationStatus,
Expand Down Expand Up @@ -82,12 +83,10 @@ export const DialogHeader = forwardRef<HTMLDivElement, DialogHeaderProps>(
>
{status && <StatusIndicator status={status} />}
<div className={withBaseName("container")}>
<div className={withBaseName("header")}>
{preheader && (
<Text className={withBaseName("preheader")}>{preheader}</Text>
)}
<H2 className={withBaseName("header")}>
joshwooding marked this conversation as resolved.
Show resolved Hide resolved
{preheader && <Text color="primary">{preheader}</Text>}
{header}
</div>
</H2>
{description && (
<Text color="secondary" className={withBaseName("description")}>
{description}
Expand Down
1 change: 0 additions & 1 deletion packages/lab/src/overlay/OverlayHeader.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.saltOverlayHeader {
padding: var(--salt-spacing-100);
width: 100%;
align-items: center;
display: flex;
flex-direction: row;
justify-content: stretch;
Expand Down
10 changes: 4 additions & 6 deletions packages/lab/src/overlay/OverlayHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Text, makePrefixer } from "@salt-ds/core";
import { H2, Text, makePrefixer } from "@salt-ds/core";
import { useComponentCssInjection } from "@salt-ds/styles";
import { useWindow } from "@salt-ds/window";
import { clsx } from "clsx";
Expand Down Expand Up @@ -45,12 +45,10 @@ export const OverlayHeader = forwardRef<HTMLDivElement, OverlayHeaderProps>(
return (
<div className={clsx(withBaseName(), className)} {...rest} ref={ref}>
<div className={withBaseName("container")}>
<div className={withBaseName("header")}>
{preheader && (
<Text className={withBaseName("preheader")}>{preheader}</Text>
)}
<H2 styleAs="h4" className={withBaseName("header")}>
{preheader && <Text color="primary">{preheader}</Text>}
joshwooding marked this conversation as resolved.
Show resolved Hide resolved
{header}
</div>
</H2>
{description && (
<Text color="secondary" className={withBaseName("description")}>
{description}
Expand Down
28 changes: 18 additions & 10 deletions packages/lab/stories/dialog/dialog.qa.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dialog, H2 } from "@salt-ds/core";
import { Button, Dialog } from "@salt-ds/core";
import { CloseIcon } from "@salt-ds/icons";
import { DialogHeader } from "@salt-ds/lab";
import type { Meta, StoryFn } from "@storybook/react";
import { QAContainer, type QAContainerProps } from "docs/components";
Expand All @@ -11,7 +12,7 @@ export default {
export const DialogHeaders: StoryFn<QAContainerProps> = () => (
<QAContainer height={600} cols={1} itemPadding={5} width={1200}>
<DialogHeader
header={<H2>Terms and conditions</H2>}
header="Terms and conditions"
style={{
width: 600,
}}
Expand All @@ -20,40 +21,47 @@ export const DialogHeaders: StoryFn<QAContainerProps> = () => (
style={{
width: 600,
}}
header={<H2>Terms and conditions</H2>}
header="Terms and conditions"
preheader="Ensure you read and agree to these Terms"
/>
<DialogHeader
style={{
width: 600,
}}
header={<H2>Terms and conditions</H2>}
header="Terms and conditions"
preheader="Ensure you read and agree to these Terms"
description="Effective date: August 29, 2024"
/>
<DialogHeader
status="info"
header={<H2>Terms and conditions</H2>}
header="Terms and conditions"
style={{
width: 600,
}}
/>
<DialogHeader
actions={
<Button aria-label="Close dialog" appearance="transparent">
<CloseIcon aria-hidden />
</Button>
}
status="info"
style={{
width: 600,
}}
header={<H2>Terms and conditions</H2>}
preheader="Ensure you read and agree to these Terms"
header="Terms and conditions"
/>
<DialogHeader
actions={
<Button aria-label="Close dialog" appearance="transparent">
<CloseIcon aria-hidden />
</Button>
}
status="info"
style={{
width: 600,
}}
header={<H2>Terms and conditions</H2>}
preheader="Ensure you read and agree to these Terms"
description="Effective date: August 29, 2024"
header="Complete terms and conditions for using the services provided by our company"
/>
</QAContainer>
);
Expand Down
17 changes: 11 additions & 6 deletions packages/lab/stories/dialog/dialog.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
DialogContent,
type DialogContentProps,
type DialogProps,
H2,
SplitLayout,
StackLayout,
} from "@salt-ds/core";
Expand All @@ -24,7 +23,7 @@ export default {
component: Dialog,
args: {
preheader: "Settlements",
header: <H2>Terms and conditions</H2>,
header: "Terms and conditions",
description: "Effective date: August 29, 2024",
content:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
Expand Down Expand Up @@ -145,6 +144,12 @@ export const Default = DialogTemplate.bind({});
Default.args = {
id: "Default",
};
export const LongTitle = DialogTemplate.bind({});
LongTitle.args = {
id: "LongTitle",
header:
"Complete terms and conditions for using the services provided by our company",
};

const AlertDialogTemplate: StoryFn<
DialogProps & { header: ReactNode; content: ReactNode }
Expand Down Expand Up @@ -201,23 +206,23 @@ const AlertDialogTemplate: StoryFn<
export const InfoStatus = AlertDialogTemplate.bind({});
InfoStatus.args = {
status: "info",
header: <H2>Info</H2>,
header: "Info",
};

export const SuccessStatus = AlertDialogTemplate.bind({});
SuccessStatus.args = {
status: "success",
header: <H2>Success</H2>,
header: "Success",
};

export const WarningStatus = AlertDialogTemplate.bind({});
WarningStatus.args = {
status: "warning",
header: <H2>Warning</H2>,
header: "Warning",
};

export const ErrorStatus = AlertDialogTemplate.bind({});
ErrorStatus.args = {
status: "error",
header: <H2>Error</H2>,
header: "Error",
};
13 changes: 8 additions & 5 deletions packages/lab/stories/overlay/overlay.qa.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Button,
H4,
Overlay,
OverlayPanel,
OverlayPanelContent,
Expand Down Expand Up @@ -29,8 +28,8 @@ export const Default: StoryFn<QAContainerProps> = (props) => {
return (
<QAContainer
height={800}
cols={5}
itemPadding={50}
cols={1}
itemPadding={80}
itemWidthAuto
width={1200}
{...props}
Expand All @@ -39,11 +38,15 @@ export const Default: StoryFn<QAContainerProps> = (props) => {
<OverlayTrigger>
<Button>Show Overlay</Button>
</OverlayTrigger>
<OverlayPanel>
<OverlayPanel
style={{
width: "30ch",
}}
>
<OverlayHeader
preheader="Preheader"
description="Description"
header={<H4>Header block</H4>}
header="Guidelines for optimal use of our application"
actions={<CloseButton />}
/>
<OverlayPanelContent>
Expand Down
32 changes: 22 additions & 10 deletions packages/lab/stories/overlay/overlay.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
Button,
H4,
Overlay,
OverlayPanel,
OverlayPanelContent,
Expand All @@ -9,20 +8,18 @@ import {
StackLayout,
Text,
Tooltip,
useId,
} from "@salt-ds/core";
import { CloseIcon } from "@salt-ds/icons";
import { OverlayHeader } from "@salt-ds/lab";
import type { Meta } from "@storybook/react";
import type { Meta, StoryFn } from "@storybook/react";
import { useState } from "react";

export default {
title: "Lab/Overlay Header",
} as Meta<typeof Overlay>;

export const Header = ({ onOpenChange }: OverlayProps) => {
const HeaderTemplate: StoryFn = ({ onOpenChange, ...props }: OverlayProps) => {
const [open, setOpen] = useState(false);
const id = useId();

const onChange = (newOpen: boolean) => {
setOpen(newOpen);
Expand All @@ -35,12 +32,11 @@ export const Header = ({ onOpenChange }: OverlayProps) => {
<Button>Show Overlay</Button>
</OverlayTrigger>
<OverlayPanel
aria-labelledby={id}
style={{
width: 500,
}}
>
<OverlayHeader header={<H4 id={id}>Header block</H4>} />
<OverlayHeader header="Header block" {...props} />
<OverlayPanelContent>
<StackLayout gap={1}>
<Text>
Expand All @@ -62,9 +58,26 @@ export const Header = ({ onOpenChange }: OverlayProps) => {
);
};

export const Header = HeaderTemplate.bind({});
Header.args = {};

export const LongHeader = HeaderTemplate.bind({});
LongHeader.args = {
header:
"Comprehensive guidelines and detailed instructions for the optimal use and application of our services to ensure maximum efficiency and user satisfaction",
actions: (
<Button
aria-label="Close overlay"
appearance="transparent"
sentiment="neutral"
>
<CloseIcon aria-hidden />
</Button>
),
};

export const HeaderWithCloseButton = ({ onOpenChange }: OverlayProps) => {
const [open, setOpen] = useState(false);
const id = useId();

const onChange = (newOpen: boolean) => {
setOpen(newOpen);
Expand All @@ -90,15 +103,14 @@ export const HeaderWithCloseButton = ({ onOpenChange }: OverlayProps) => {
<Button>Show Overlay</Button>
</OverlayTrigger>
<OverlayPanel
aria-labelledby={id}
style={{
width: 500,
}}
>
<OverlayHeader
preheader="Preheader"
description="Description"
header={<H4 id={id}>Header block</H4>}
header="Header block"
actions={<CloseButton />}
/>
<OverlayPanelContent>
Expand Down
3 changes: 1 addition & 2 deletions site/src/examples/dialog/WithHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
Dialog,
DialogActions,
DialogContent,
H2,
H3,
StackLayout,
useId,
Expand Down Expand Up @@ -44,7 +43,7 @@ export const WithHeader = (): ReactElement => {
<Dialog open={open} onOpenChange={onOpenChange} id={id}>
<DialogHeader
preheader="Settlements"
header={<H2>Terms and conditions</H2>}
header="Terms and conditions"
description="Effective date: August 29, 2024"
actions={closeButton}
/>
Expand Down
9 changes: 2 additions & 7 deletions site/src/examples/overlay/WithHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import {
OverlayPanel,
OverlayPanelContent,
OverlayTrigger,
useId,
} from "@salt-ds/core";
import { CloseIcon } from "@salt-ds/icons";
import { OverlayHeader } from "@salt-ds/lab";
import { type ReactElement, useState } from "react";

export const WithHeader = (): ReactElement => {
const [open, setOpen] = useState(false);
const id = useId();

const onOpenChange = (newOpen: boolean) => setOpen(newOpen);

Expand All @@ -32,11 +30,8 @@ export const WithHeader = (): ReactElement => {
<OverlayTrigger>
<Button>Show Overlay</Button>
</OverlayTrigger>
<OverlayPanel aria-labelledby={id}>
<OverlayHeader
header={<h4 id={id}>Title</h4>}
actions={headerActions}
/>
<OverlayPanel>
<OverlayHeader header="Title" actions={headerActions} />
<OverlayPanelContent>
<div>Content of Overlay</div>
</OverlayPanelContent>
Expand Down
Loading