Skip to content

Commit

Permalink
Add popover cover position story to prevent regressions (#11771)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledurand committed Mar 21, 2024
1 parent 75e19fd commit 8d63639
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fluffy-meals-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Added cover positioning story to popover to prevent regressions
59 changes: 58 additions & 1 deletion polaris-react/src/components/Popover/Popover.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
Text,
BlockStack,
} from '@shopify/polaris';
import {SearchIcon} from '@shopify/polaris-icons';
import {SearchIcon, SelectIcon} from '@shopify/polaris-icons';

export default {
component: Popover,
Expand Down Expand Up @@ -77,6 +77,13 @@ export function All() {
</Text>
<WithLoadingSmallerContent />
</BlockStack>

<BlockStack gap="200">
<Text as="h2" variant="headingXl">
With preferredPosition cover
</Text>
<WithCoverPositioning />
</BlockStack>
</BlockStack>
);
}
Expand Down Expand Up @@ -832,6 +839,56 @@ export function WithSubduedPane() {
);
}

export function WithCoverPositioning() {
const [popoverActive, setPopoverActive] = useState(true);

const togglePopoverActive = useCallback(
() => setPopoverActive((popoverActive) => !popoverActive),
[],
);

const activator = (
<button
onClick={() => {
togglePopoverActive();
}}
style={{
display: 'flex',
alignItems: 'center',
gap: 'var(--p-space-200)',
padding: 'var(--p-space-200) var(--p-space-300)',
borderRadius: 'var(--p-border-radius-300)',
border: 'var(--p-border-width-025) solid var(--p-color-border)',
background: 'var(--p-color-bg-surface)',
}}
>
Show popover
<Icon source={SelectIcon} tone="base" />
</button>
);

return (
<div style={{height: '280px'}}>
<Popover
active={popoverActive}
activator={activator}
onClose={togglePopoverActive}
preferredPosition="cover"
>
<Popover.Pane>
<Box padding="200" paddingInline="300">
<Text as="p">Popover content</Text>
</Box>

<Box padding="200" paddingInline="300">
<Text as="p">Popover content</Text>
</Box>
</Popover.Pane>
</Popover>
</div>
);
}

const StopPropagation = ({children}: React.PropsWithChildren<any>) => {
const stopEventPropagation = (event: React.MouseEvent | React.TouchEvent) => {
event.stopPropagation();
Expand Down

0 comments on commit 8d63639

Please sign in to comment.