Skip to content

Commit

Permalink
[C-3811] Migrate popup to harmony (#7576)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Feb 14, 2024
1 parent a22dc7a commit 58fd090
Show file tree
Hide file tree
Showing 47 changed files with 227 additions and 1,048 deletions.
1 change: 1 addition & 0 deletions packages/harmony/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ export * from './segmented-control'
export * from './scrollbar'
export * from './radio'
export * from './radio-group'
export * from './popup-menu'
4 changes: 2 additions & 2 deletions packages/harmony/src/components/layout/Popup/Popup.module.css
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
.root {
font-family: var(--harmony-font-family);
position: absolute;
z-index: 20000;
}

.popup {
background-color: var(--harmony-white);
border-radius: var(--harmony-unit-2);
border: 1px solid var(--harmony-neutral-light-7);
box-shadow: 0 16px 20px 0 var(--harmony-tile-shadow-1-alt);
user-select: none;
}

.header {
border: none;
margin-bottom: var(--harmony-unit-1);
margin-bottom: var(--harmony-spacing-m);
padding-bottom: 0;
display: flex;
align-items: center;
Expand Down
14 changes: 9 additions & 5 deletions packages/harmony/src/components/layout/Popup/Popup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export const Popup = forwardRef<HTMLDivElement, PopupProps>(function Popup(
anchorRef,
checkIfClickInside,
children,
className,
isVisible,
onAfterClose,
onClose,
Expand All @@ -204,9 +205,11 @@ export const Popup = forwardRef<HTMLDivElement, PopupProps>(function Popup(
title,
zIndex,
containerRef,
portalLocation = document.body
portalLocation = document.body,
shadow = 'mid',
fixed
} = props
const theme = useTheme()
const { spring, shadows } = useTheme()

const handleClose = useCallback(() => {
onClose?.()
Expand Down Expand Up @@ -354,11 +357,11 @@ export const Popup = forwardRef<HTMLDivElement, PopupProps>(function Popup(
transform: `scale(0)`,
opacity: 0
},
config: theme.spring.standard,
config: spring.standard,
unique: true
})

const rootStyle = zIndex ? { zIndex } : {}
const rootStyle = { zIndex, position: fixed ? ('fixed' as const) : undefined }

const handleMouseLeave = useCallback(() => {
if (dismissOnMouseLeave) {
Expand All @@ -379,7 +382,8 @@ export const Popup = forwardRef<HTMLDivElement, PopupProps>(function Popup(
{transitions.map(({ item, key, props }) =>
item ? (
<animated.div
className={styles.popup}
className={cn(styles.popup, className)}
css={{ boxShadow: shadows[shadow] }}
ref={popupRef}
key={key}
style={{
Expand Down
1 change: 1 addition & 0 deletions packages/harmony/src/components/layout/Popup/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { Popup } from './Popup'
export type { PopupProps, Origin } from './types'
5 changes: 5 additions & 0 deletions packages/harmony/src/components/layout/Popup/types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import type { MutableRefObject, ReactChild } from 'react'

import { ShadowOptions } from 'foundations'

export type Origin = {
vertical: 'top' | 'center' | 'bottom'
horizontal: 'left' | 'center' | 'right'
}

export type PopupProps = {
className?: string
/**
* A ref to the element whose position will be used to anchor the Popup
*/
Expand Down Expand Up @@ -89,4 +92,6 @@ export type PopupProps = {
* @default document.body
*/
portalLocation?: HTMLElement
shadow?: ShadowOptions
fixed?: boolean
}
41 changes: 41 additions & 0 deletions packages/harmony/src/components/popup-menu/PopupMenu.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.popup {
margin: var(--harmony-spacing-s);
padding: var(--harmony-spacing-s);
}

.menu {
all: unset;
}

.item {
display: flex;
align-items: center;
gap: var(--harmony-unit-2);
padding: var(--harmony-unit-2) var(--harmony-unit-3);
border-radius: var(--harmony-unit);
font-size: var(--harmony-font-m);
font-weight: var(--harmony-font-demi-bold);
color: var(--harmony-neutral);
}

.item .icon {
display: flex;
align-items: center;
justify-content: center;
width: var(--harmony-unit-5);
height: var(--harmony-unit-5);
}

.item path {
fill: var(--harmony-neutral);
}

.item:hover {
cursor: pointer;
color: var(--harmony-white);
background: var(--harmony-secondary);
}

.item:hover path {
fill: var(--harmony-white);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { forwardRef, useCallback, useRef, useState, MouseEvent } from 'react'

import cn from 'classnames'

import { Popup } from 'components/Popup'
import { Popup } from '../layout/Popup'

import styles from './PopupMenu.module.css'
import { PopupMenuItem, PopupMenuProps } from './types'
Expand All @@ -16,19 +16,17 @@ export const PopupMenu = forwardRef<HTMLDivElement, PopupMenuProps>(
items,
onClose,
renderMenu,
position,
renderTrigger,
dismissOnMouseLeave,
hideCloseButton,
title,
titleClassName,
wrapperClassName,
className,
zIndex,
containerRef,
anchorOrigin,
transformOrigin,
id
id,
fixed
} = props
const clickInsideRef = useRef<any>()
const anchorRef = useRef<HTMLElement>(null)
Expand Down Expand Up @@ -81,17 +79,15 @@ export const PopupMenu = forwardRef<HTMLDivElement, PopupMenuProps>(
showHeader={Boolean(title)}
hideCloseButton={hideCloseButton}
onClose={handlePopupClose}
position={position}
ref={ref}
title={title || ''}
titleClassName={titleClassName}
zIndex={zIndex}
containerRef={containerRef}
transformOrigin={transformOrigin}
anchorOrigin={anchorOrigin}
wrapperClassName={cn(styles.popup, wrapperClassName)}
className={className}
className={cn(styles.popup, className)}
dismissOnMouseLeave={dismissOnMouseLeave}
fixed={fixed}
>
{renderMenu ? (
renderMenu(items)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { ComponentProps, MouseEvent } from 'react'

import { PopupProps } from '../Popup'
import { PopupProps } from '../layout/Popup'

type ApplicablePopupProps = Pick<
PopupProps,
| 'position'
| 'title'
| 'titleClassName'
| 'wrapperClassName'
| 'className'
| 'hideCloseButton'
| 'zIndex'
| 'containerRef'
| 'transformOrigin'
| 'anchorOrigin'
| 'fixed'
>

export type PopupMenuProps = {
Expand Down
64 changes: 0 additions & 64 deletions packages/stems/src/components/Popup/Popup.module.css

This file was deleted.

63 changes: 0 additions & 63 deletions packages/stems/src/components/Popup/Popup.stories.tsx

This file was deleted.

Loading

0 comments on commit 58fd090

Please sign in to comment.