Skip to content

Commit

Permalink
components: Update popover to no longer use g2
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Apr 26, 2021
1 parent 930b435 commit b3dfda5
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 32 deletions.
7 changes: 4 additions & 3 deletions packages/components/src/ui/popover/component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* External dependencies
*/
import { contextConnect, useContextSystem } from '@wp-g2/context';
import { noop, useUpdateEffect } from '@wp-g2/utils';
import { noop } from 'lodash';
// eslint-disable-next-line no-restricted-imports
import { PopoverDisclosure, usePopoverState, Portal } from 'reakit';

Expand All @@ -14,13 +13,15 @@ import { useCallback, useMemo, cloneElement } from '@wordpress/element';
/**
* Internal dependencies
*/
import { contextConnect, useContextSystem } from '../context';
import { PopoverContext } from './context';
import { usePopoverResizeUpdater } from './utils';
import PopoverContent from './content';
import { useUpdateEffect } from '../../utils/hooks';

/**
*
* @param {import('@wp-g2/create-styles').ViewOwnProps<import('./types').Props, 'div'>} props
* @param {import('../context').ViewOwnProps<import('./types').Props, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function Popover( props, forwardedRef ) {
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/ui/popover/content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
* External dependencies
*/
import { contextConnect, useContextSystem } from '@wp-g2/context';
import { css, cx } from '@wp-g2/styles';
import { css, cx } from 'emotion';
// eslint-disable-next-line no-restricted-imports
import { Popover as ReakitPopover } from 'reakit';

Expand All @@ -13,10 +12,11 @@ import { Card } from '../card';
import { View } from '../view';
import { usePopoverContext } from './context';
import * as styles from './styles';
import { contextConnect, useContextSystem } from '../context';

/**
*
* @param {import('@wp-g2/create-styles').ViewOwnProps<import('./types').ContentProps, 'div'>} props
* @param {import('../context').ViewOwnProps<import('./types').ContentProps, 'div'>} props
* @param {import('react').Ref<any>} forwardedRef
*/
function PopoverContent( props, forwardedRef ) {
Expand Down
6 changes: 2 additions & 4 deletions packages/components/src/ui/popover/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/**
* Internal dependencies
*/
/**
* External dependencies
*/
import { Button, CardBody, CardHeader } from '@wp-g2/components';
import { CardBody, CardHeader } from '../../card';
import Button from '../../../button';
import { Popover } from '..';

export default {
Expand Down
9 changes: 6 additions & 3 deletions packages/components/src/ui/popover/styles.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
/**
* External dependencies
*/
import { css, ui } from '@wp-g2/styles';
import { css } from 'emotion';

/**
* Internal dependencies
*/
import { CardBody } from '../card';
import * as ZIndex from '../../utils/z-index';
import CONFIG from '../../utils/config-values';

export const PopoverContent = css`
${ ui.zIndex( 'Popover', 10000 ) };
z-index: ${ ZIndex.Popover };
box-sizing: border-box;
opacity: 0;
outline: none;
position: relative;
transform-origin: center center;
transition: opacity ${ ui.get( 'transitionDurationFastest' ) } linear;
transition: opacity ${ CONFIG.transitionDurationFastest } linear;
width: 100%;
&[data-enter] {
Expand Down
28 changes: 14 additions & 14 deletions packages/components/src/ui/popover/test/__snapshots__/index.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ exports[`props should render correctly 1`] = `
--wp-g2-surface-background-size-dotted: 11px;
}
.emotion-17.emotion-17.emotion-17.emotion-17.emotion-17.emotion-17.emotion-17 .components-card-body {
max-height: 80vh;
}
.emotion-1.emotion-1.emotion-1.emotion-1.emotion-1.emotion-1.emotion-1 {
height: 100%;
overflow-x: hidden;
Expand Down Expand Up @@ -96,14 +92,18 @@ exports[`props should render correctly 1`] = `
border-radius: 2px;
}
.emotion-16 .components-card-body {
max-height: 80vh;
}
.emotion-8 {
border-radius: 2px;
}
.emotion-0 {
height: auto;
max-height: 100%;
padding: 24px,24px;
padding: calc(4px * 3) calc(4px * 3);
}
.emotion-0:first-of-type {
Expand Down Expand Up @@ -165,17 +165,17 @@ Snapshot Diff:
<div
- aria-label="show"
+ aria-label="popover-base-popover"
class="components-popover-content wp-components-popover-content components-popover wp-components-popover ic-fzg5i9 ic-1o22l1x css-xnf55w css-1mm2cvy-View egi4jkx0"
class="components-popover-content components-popover css-u2yev2-PopoverContent-classes css-1mm2cvy-View egi4jkx0"
data-dialog="true"
data-g2-c16t="true"
data-g2-component="Popover"
data-wp-c16t="true"
data-wp-component="Popover"
- id="labelled-popover"
+ id="base-popover"
role="dialog"
tabindex="-1"
>
<div
class="components-surface components-card css-1tf68oj-Card-rounded css-1wit8k9 css-1mm2cvy-View egi4jkx0"
class="components-surface components-card css-hy95ag-Card-rounded-cardStyle css-10jei3p css-1mm2cvy-View egi4jkx0"
`;
exports[`props should render without content 1`] = `
Expand All @@ -187,25 +187,25 @@ Snapshot Diff:
<div
- aria-label="popover-contentless-popover"
+ aria-label="popover-base-popover"
class="components-popover-content wp-components-popover-content components-popover wp-components-popover ic-fzg5i9 ic-1o22l1x css-xnf55w css-1mm2cvy-View egi4jkx0"
class="components-popover-content components-popover css-u2yev2-PopoverContent-classes css-1mm2cvy-View egi4jkx0"
data-dialog="true"
data-g2-c16t="true"
data-g2-component="Popover"
data-wp-c16t="true"
data-wp-component="Popover"
- id="contentless-popover"
+ id="base-popover"
role="dialog"
tabindex="-1"
>
<div
class="components-surface components-card css-1tf68oj-Card-rounded css-1wit8k9 css-1mm2cvy-View egi4jkx0"
class="components-surface components-card css-hy95ag-Card-rounded-cardStyle css-10jei3p css-1mm2cvy-View egi4jkx0"
@@ -21,10 +21,19 @@
frameborder="0"
src="about:blank"
style="display: block; opacity: 0; position: absolute; top: 0px; left: 0px; height: 100%; width: 100%; overflow: hidden; pointer-events: none; z-index: -1;"
tabindex="-1"
/>
+ <div
+ class="components-scrollable wp-components-scrollable components-card-body css-aej86y-Body-borderRadius ic-y3p1xi css-1jyvxqk css-1mm2cvy-View egi4jkx0"
+ class="components-scrollable wp-components-scrollable components-card-body css-3sz8a0-Body-borderRadius ic-y3p1xi css-1jyvxqk css-1mm2cvy-View egi4jkx0"
+ data-g2-c16t="true"
+ data-g2-component="Scrollable"
+ data-wp-c16t="true"
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/ui/popover/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import { Button } from '@wp-g2/components';

/**
* Internal dependencies
*/
import Button from '../../../button';
import { CardBody } from '../../card';
import { Popover } from '../index';

Expand Down
5 changes: 3 additions & 2 deletions packages/components/src/ui/utils/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import type { ReactText } from 'react';
/**
* Internal dependencies
*/
import { CONFIG } from '../../utils';

const GRID_BASE = '4px';

export function space( value: ReactText ): string {
return typeof value === 'number'
? `calc(${ CONFIG.gridBase } * ${ value })`
? `calc(${ GRID_BASE } * ${ value })`
: value;
}
10 changes: 8 additions & 2 deletions packages/components/src/utils/config-values.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Internal dependencies
*/
import { space } from './space';
import { space } from '../ui/utils/space';

const CONTROL_HEIGHT = '30px';
const CARD_PADDING_X = space( 3 );
Expand Down Expand Up @@ -36,8 +36,14 @@ export default {
cardBorderRadius: '2px',
cardPaddingX: CARD_PADDING_X,
cardPaddingY: CARD_PADDING_Y,
cardPadding: `${ CARD_PADDING_X }, ${ CARD_PADDING_Y }`,
cardPadding: `${ CARD_PADDING_X } ${ CARD_PADDING_Y }`,
cardHeaderFooterPaddingY: space( 1 ),
cardHeaderHeight: '44px',
surfaceBorderColor: 'rgba(0, 0, 0, 0.1)',
transitionDuration: '200ms',
transitionDurationFast: '160ms',
transitionDurationFaster: '120ms',
transitionDurationFastest: '100ms',
transitionTimingFunction: 'cubic-bezier(0.08, 0.52, 0.52, 1)',
transitionTimingFunctionControl: 'cubic-bezier(0.12, 0.8, 0.32, 1)',
};
1 change: 1 addition & 0 deletions packages/components/src/utils/z-index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const Popover = 10000;

0 comments on commit b3dfda5

Please sign in to comment.