Skip to content

Commit 6ff8800

Browse files
authored
Contextual Help Documentation #2352 (#2831)
1 parent 68d1882 commit 6ff8800

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
{/* Copyright 2022 Adobe. All rights reserved.
2+
This file is licensed to you under the Apache License, Version 2.0 (the "License");
3+
you may not use this file except in compliance with the License. You may obtain a copy
4+
of the License at http://www.apache.org/licenses/LICENSE-2.0
5+
Unless required by applicable law or agreed to in writing, software distributed under
6+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
7+
OF ANY KIND, either express or implied. See the License for the specific language
8+
governing permissions and limitations under the License. */}
9+
10+
import {Layout} from '@react-spectrum/docs';
11+
export default Layout;
12+
13+
import docs from 'docs:@react-spectrum/contextualhelp';
14+
import {HeaderInfo, PropTable, PageDescription} from '@react-spectrum/docs';
15+
import packageData from '@react-spectrum/contextualhelp/package.json';
16+
17+
```jsx import
18+
import {ContextualHelp} from '@react-spectrum/contextualhelp';
19+
import {Content, Footer} from '@react-spectrum/view';
20+
import {Heading, Text} from '@react-spectrum/text';
21+
import {Link} from '@react-spectrum/link';
22+
import {Flex} from '@react-spectrum/layout';
23+
```
24+
25+
---
26+
category: Overlays
27+
keywords: [popover, field, input]
28+
after_version: 3.0.0-alpha.1
29+
---
30+
31+
# ContextualHelp
32+
33+
<PageDescription>{docs.exports.ContextualHelp.description}</PageDescription>
34+
35+
<HeaderInfo
36+
packageData={packageData}
37+
componentNames={['ContextualHelp']}
38+
sourceData={[]} />
39+
40+
## Example
41+
42+
```tsx example
43+
<ContextualHelp variant="info">
44+
<Heading>Need help?</Heading>
45+
<Content><Text>If you're having issues accessing your account, contact our customer support team for help.</Text></Content>
46+
</ContextualHelp>
47+
```
48+
49+
## Content
50+
51+
Unlike [Dialog](Dialog.html), the layout in ContextualHelp is very deliberate. Every ContextualHelp component is triggered as a popover where the
52+
trigger element is a quiet action button with either a help or info icon. Much like [Dialog](Dialog.html), however, ContextualHelp has sections that
53+
can be populated by providing the following components to your ContextualHelp as children:
54+
[Heading](Heading.html) (title), [Content](Content.html) (body), and [Footer](Footer.html) (link).
55+
Each of these components are required in a Spectrum compliant ContextualHelp except for `Footer` since including a link is optional.
56+
57+
```tsx example
58+
<ContextualHelp variant="help">
59+
<Heading>What is a segment?</Heading>
60+
<Content><Text>Segments identify who your visitors are, what devices and services they use, where they navigated from, and much more.</Text></Content>
61+
<Footer><Link>Learn more about segments</Link></Footer>
62+
</ContextualHelp>
63+
```
64+
65+
## Placement
66+
67+
ContextualHelp supports [Dialog placement](./DialogTrigger.html#dialog-placement) options for when the positioning of the popover needs to customized.
68+
69+
```tsx example
70+
<ContextualHelp variant="info" placement="top start">
71+
<Heading>Placement</Heading>
72+
<Content><Text>The placement of this contextual help popover has been customized to use top start.</Text></Content>
73+
</ContextualHelp>
74+
```
75+
76+
## Events
77+
78+
ContextualHelp accepts an `onOpenChange` prop, triggered when the ContextualHelp's popover opens or closes.
79+
80+
The example below uses `onOpenChange` to update a separate element with the current open state of the Dialog.
81+
82+
```tsx example
83+
function Example() {
84+
let [state, setState] = React.useState(false);
85+
86+
return (
87+
<Flex alignItems="center" gap="size-100">
88+
<ContextualHelp variant="info" onOpenChange={(isOpen) => setState(isOpen)}>
89+
<Heading>Permission required</Heading>
90+
<Content><Text>Your admin must grant you permission before you can create a segment.</Text></Content>
91+
</ContextualHelp>
92+
<Text>Current open state: {state.toString()}</Text>
93+
</Flex>
94+
);
95+
}
96+
```
97+
98+
## Props
99+
100+
<PropTable component={docs.exports.ContextualHelp} links={docs.links} />
101+
102+
## Visual options
103+
104+
### Info
105+
106+
Use the info icon for brief, specific, contextual guidance. This is best for supplemental or nice-to-know information,
107+
in-line with a label or a component (if there is no label). The content for an info icon’s popover should be [instructive](https://spectrum.adobe.com/page/voice-and-tone/#Tone-spectrum) in tone.
108+
109+
```tsx example
110+
<ContextualHelp variant="info">
111+
<Heading>Permission required</Heading>
112+
<Content><Text>Your admin must grant you permission before you can create a segment.</Text></Content>
113+
</ContextualHelp>
114+
```
115+
116+
### Help
117+
118+
Use the help icon for content that offers more detailed, in-depth guidance about a task, UI element, tool, or keyboard shortcuts.
119+
This may include an image, video, or link and should be [helpful](https://spectrum.adobe.com/page/voice-and-tone/#Tone-spectrum) in tone.
120+
121+
```tsx example
122+
<ContextualHelp variant="help">
123+
<Heading>What is a segment?</Heading>
124+
<Content><Text>Segments identify who your visitors are, what devices and services they use, where they navigated from, and much more.</Text></Content>
125+
<Footer><Link>Learn more about segments</Link></Footer>
126+
</ContextualHelp>
127+
```
128+

packages/@react-spectrum/contextualhelp/src/contextualhelp.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
}
3232

33-
.react-spectrum-ContextualHelp-dialog {
33+
.react-spectrum-ContextualHelp-dialog.react-spectrum-ContextualHelp-dialog {
3434
width: var(--spectrum-contexualhelp-dialog-width);
3535
--spectrum-dialog-padding-x: var(--spectrum-contextualhelp-dialog-padding);
3636
--spectrum-dialog-padding-y: var(--spectrum-contextualhelp-dialog-padding);

0 commit comments

Comments
 (0)