Skip to content

Commit 4fea433

Browse files
committed
feat: add helpText to the Sidebar
- Add a helpText and a renderHelpText props to the Sidebar component.
1 parent ff6ab3f commit 4fea433

File tree

2 files changed

+99
-19
lines changed

2 files changed

+99
-19
lines changed

src/Layout/Sidebar.story.tsx

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111
Select,
1212
PrimaryButton,
1313
Box,
14+
Textarea,
15+
Text,
16+
Flex,
17+
Button,
18+
Heading3,
1419
} from "..";
1520

1621
const primaryMenu = [
@@ -439,3 +444,61 @@ export const WithDifferentWidths = () => {
439444
</Sidebar>
440445
);
441446
};
447+
448+
export const WithHelpText = () => {
449+
const [helpText, setHelpText] = useState(
450+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus tempor lacus nec finibus egestas."
451+
);
452+
453+
return (
454+
<Sidebar hideCloseButton top={0} height="100%" isOpen title="With help text" helpText={helpText}>
455+
<Textarea
456+
value={helpText}
457+
labelText="Help Text"
458+
placeholder="Enter some text..."
459+
onChange={(event) => {
460+
setHelpText(event.target.value);
461+
}}
462+
/>
463+
</Sidebar>
464+
);
465+
};
466+
export const WithOtherElementsInHelpText = () => {
467+
return (
468+
<Sidebar
469+
hideCloseButton
470+
top={0}
471+
height="100%"
472+
isOpen
473+
title="With help text"
474+
helpText={
475+
<>
476+
Carry over remaining quantity to a future PO line item.{" "}
477+
<Link underline={false} href="/">
478+
Learn more
479+
</Link>{" "}
480+
</>
481+
}
482+
></Sidebar>
483+
);
484+
};
485+
486+
export const WithARenderedHelpText = () => {
487+
return (
488+
<Sidebar
489+
hideCloseButton
490+
top={0}
491+
height="100%"
492+
isOpen
493+
title="With help text"
494+
renderHelpText={() => (
495+
<Heading3 color="red" fontWeight="bold">
496+
This is a custom help text{" "}
497+
<Link href="/" underline={false}>
498+
Learn more
499+
</Link>
500+
</Heading3>
501+
)}
502+
></Sidebar>
503+
);
504+
};

src/Layout/Sidebar.tsx

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import { useTranslation } from "react-i18next";
44
import { Box } from "../Box";
55
import { Flex } from "../Flex";
66
import { IconicButton } from "../Button";
7-
import { Heading3 } from "../Type";
7+
import { Heading3, Text } from "../Type";
88
import { AnimatedBoxProps, AnimatedBox } from "../Box/Box";
99
import { NAVBAR_HEIGHT } from "../BrandedNavBar/NavBar";
1010
import { PreventBodyElementScrolling } from "../utils";
11+
import { Divider } from "../Divider";
1112

1213
type PredefinedSidebarWidth = "xs" | "s" | "m" | "l" | "xl";
1314

@@ -41,6 +42,8 @@ type SidebarProps = Omit<AnimatedBoxProps, "width"> & {
4142
disableScroll?: boolean;
4243
hideCloseButton?: boolean;
4344
width?: SidebarWidth;
45+
helpText?: React.ReactNode;
46+
renderHelpText?: () => React.ReactNode;
4447
};
4548

4649
const focusFirstElement = () => {
@@ -69,7 +72,7 @@ const SidebarOverlay = ({ transitionDuration, top, transparent, zIndex = 799 as
6972
/>
7073
);
7174
function Sidebar({
72-
p = "x3",
75+
p = "x2",
7376
width = "xs",
7477
children,
7578
onClose,
@@ -87,6 +90,8 @@ function Sidebar({
8790
disableScroll = true,
8891
hideCloseButton = false,
8992
zIndex = "sidebar" as any,
93+
helpText,
94+
renderHelpText,
9095
...props
9196
}: SidebarProps) {
9297
const closeButton = useRef(null);
@@ -191,24 +196,36 @@ function Sidebar({
191196
flexDirection="column"
192197
style={{ overflowBehaviour: "contain" } as any}
193198
>
194-
<Flex justifyContent="space-between" alignItems="flex-start" pb="x3">
195-
{title && (
196-
<Flex alignItems="center" height="100%">
197-
<Heading3 mb={0}>{title}</Heading3>
199+
<Flex flexDirection="column" pb="x3">
200+
<Flex flexDirection="column" pb="x2">
201+
<Flex justifyContent="space-between" alignItems="flex-start">
202+
{title && (
203+
<Flex alignItems="center" height="100%">
204+
<Heading3 mb={0}>{title}</Heading3>
205+
</Flex>
206+
)}
207+
{!hideCloseButton && (
208+
<Box marginLeft="x2">
209+
<IconicButton
210+
type="button"
211+
ref={closeButton}
212+
icon="close"
213+
onClick={onClose}
214+
data-testid={closeButtonTestId}
215+
aria-label={closeButtonAriaLabel || t("close")}
216+
/>
217+
</Box>
218+
)}
198219
</Flex>
199-
)}
200-
{!hideCloseButton && (
201-
<Box marginLeft="x2">
202-
<IconicButton
203-
type="button"
204-
ref={closeButton}
205-
icon="close"
206-
onClick={onClose}
207-
data-testid={closeButtonTestId}
208-
aria-label={closeButtonAriaLabel || t("close")}
209-
/>
210-
</Box>
211-
)}
220+
{renderHelpText
221+
? renderHelpText()
222+
: helpText && (
223+
<Text pt="x1" color="midGrey">
224+
{helpText}
225+
</Text>
226+
)}
227+
</Flex>
228+
<Divider m="0 -8px" width="calc(100% + 16px)" />
212229
</Flex>
213230
<AnimatedBox
214231
variants={childVariants}

0 commit comments

Comments
 (0)