Skip to content

Commit 6a345aa

Browse files
refactor(popover): update popover usage and implementation (#10952)
* refactor(popover): update popover usage and implementation * test(react): update public api snapshot * docs(react): remove light prop from storybook Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 729879c commit 6a345aa

File tree

6 files changed

+81
-34
lines changed

6 files changed

+81
-34
lines changed

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8669,9 +8669,6 @@ Map {
86698669
"highContrast": Object {
86708670
"type": "bool",
86718671
},
8672-
"light": Object {
8673-
"type": "bool",
8674-
},
86758672
"open": Object {
86768673
"isRequired": true,
86778674
"type": "bool",

packages/react/src/components/Popover/index.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const Popover = React.forwardRef(function Popover(props, ref) {
1919
children,
2020
dropShadow = true,
2121
highContrast = false,
22-
light = false,
2322
open,
2423
...rest
2524
} = props;
@@ -29,7 +28,6 @@ const Popover = React.forwardRef(function Popover(props, ref) {
2928
[`${prefix}--popover--caret`]: caret,
3029
[`${prefix}--popover--drop-shadow`]: dropShadow,
3130
[`${prefix}--popover--high-contrast`]: highContrast,
32-
[`${prefix}--popover--light`]: light,
3331
[`${prefix}--popover--open`]: open,
3432
[`${prefix}--popover--${align}`]: true,
3533
[customClassName]: !!customClassName,
@@ -42,6 +40,12 @@ const Popover = React.forwardRef(function Popover(props, ref) {
4240
);
4341
});
4442

43+
// Note: this displayName is temporarily set so that Storybook ArgTable
44+
// correctly displays the name of this component
45+
if (__DEV__) {
46+
Popover.displayName = 'Popover';
47+
}
48+
4549
Popover.propTypes = {
4650
/**
4751
* Specify how the popover should align with the trigger element
@@ -96,11 +100,6 @@ Popover.propTypes = {
96100
*/
97101
highContrast: PropTypes.bool,
98102

99-
/**
100-
* Render the component using the light variant
101-
*/
102-
light: PropTypes.bool,
103-
104103
/**
105104
* Specify whether the component is currently open or closed
106105
*/

packages/react/src/components/Popover/next/Popover.mdx

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
import { Preview, Props, Story } from '@storybook/addon-docs/blocks';
1+
import { ArgsTable, Canvas, Story } from '@storybook/addon-docs/blocks';
22

3-
# [Unstable] Popover
3+
# Popover
44

55
[Source code](https://github.com/carbon-design-system/carbon/tree/main/packages/react/src/components/Popover)
6+
&nbsp;|&nbsp;
7+
[Usage guidelines](https://www.carbondesignsystem.com/components/popover/usage)
8+
&nbsp;|&nbsp;
69

710
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
811
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -17,14 +20,77 @@ import { Preview, Props, Story } from '@storybook/addon-docs/blocks';
1720

1821
## Overview
1922

20-
**Note: this component is currently experimental and does not follow semver.**
23+
`Popover` is a primitive component used to build custom components which render
24+
over other elements on the page. For example, `Popover` is used to build
25+
our popover components in Carbon.
2126

22-
The Popover component is used to build layers that appear on top of the current
23-
surface.
27+
The `Popover` component accepts two items as `children`: a trigger element and
28+
a `PopoverContent` component which contains the content to be rendered inside of the
29+
`Popover`.
30+
31+
```jsx
32+
import { Popover, PopoverContent } from '@carbon/react';
33+
import React from 'react';
34+
35+
function CustomComponent() {
36+
const [open, setOpen] = React.useState(false);
37+
38+
return (
39+
<Popover open={open}>
40+
<button
41+
type="button"
42+
onClick={() => {
43+
setOpen(!open);
44+
}}>
45+
Toggle
46+
</button>
47+
<PopoverContent>
48+
The content that is revealed by interacting with the Toggle button
49+
</PopoverContent>
50+
</Popover>
51+
);
52+
}
53+
```
54+
55+
## Visibility
56+
57+
The `open` prop allows you to control the visibility of the `Popover`. This is
58+
often tracked in state and is toggled based on the trigger render inside of the
59+
`Popover`. A trigger must be an interactive element and in most cases it will be
60+
a `<button>`.
61+
62+
## Alignment
63+
64+
The `align` prop allows you to specify where your content should be placed
65+
relative to the popover. For example, if you provide `align="top"` to the
66+
`Popover` component then the popover will render above your component.
67+
Similarly, if you provide `align="bottom"` then the popover will render below
68+
your component.
69+
70+
You can also configure the placement of the caret, if it is enabled, by choosing
71+
between `left` and `right` or `bottom` and `top`, depending on where your
72+
popover is being rendered.
73+
74+
If you are using `align="top"`, then you can choose between `align="top-left"`
75+
and `align="top-right"`. These options will place the caret closer to the left
76+
or right edges of the popover.
77+
78+
If you are using `align="left"` or `align="right"`, you can use `top` or
79+
`bottom` to control this alignment.
80+
81+
## Appearance
82+
83+
The `Popover` component has several props which you can use to customize its
84+
appearance, including:
85+
86+
- `caret`: to conditionally display a `caret` or render the popover directly
87+
beside the trigger element
88+
- `dropShadow`: to display a drop shadow on the popover content
89+
- `highContrast`: to display a high contrast variant of the popover
2490

2591
## Component API
2692

27-
<Props />
93+
<ArgsTable />
2894

2995
## Feedback
3096

packages/react/src/components/Popover/next/Popover.stories.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ export default {
5050
};
5151

5252
const PlaygroundStory = (props) => {
53-
const { align, caret, dropShadow, highContrast, light, open } = props;
53+
const { align, caret, dropShadow, highContrast, open } = props;
5454
return (
5555
<Popover
5656
align={align}
5757
caret={caret}
5858
dropShadow={dropShadow}
5959
highContrast={highContrast}
60-
light={light}
6160
open={open}>
6261
<div className="playground-trigger">
6362
<Checkbox16 />
@@ -115,12 +114,6 @@ Playground.argTypes = {
115114
},
116115
defaultValue: false,
117116
},
118-
light: {
119-
control: {
120-
type: 'boolean',
121-
},
122-
defaultValue: false,
123-
},
124117
open: {
125118
control: {
126119
type: 'boolean',

packages/react/src/components/Popover/next/story.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@
8484
}
8585

8686
.popover-title {
87-
@include type.type-style('productive-heading-01');
87+
@include type.type-style('heading-compact-01');
8888
margin-bottom: spacing.$spacing-01;
8989
}
9090

9191
.popover-details {
92-
@include type.type-style('body-short-01');
92+
@include type.type-style('body-compact-01');
9393
}
9494

9595
.popover-story {

packages/styles/scss/components/popover/_popover.scss

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,6 @@ $popover-caret-height: custom-property.get-var(
7979

8080
/// Modifiers
8181

82-
// Light modifier
83-
.#{$prefix}--popover--light .#{$prefix}--popover-content {
84-
@include custom-property.declaration(
85-
'popover-background-color',
86-
theme.$layer-02
87-
);
88-
}
89-
9082
// High contrast modifier
9183
.#{$prefix}--popover--high-contrast .#{$prefix}--popover {
9284
@include custom-property.declaration(

0 commit comments

Comments
 (0)