Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: Add support for previous button on lightbox #246

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ebay-dialog-base/components/dialog-close-button.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { FC, ReactNode } from 'react'

type EbayDialogFooterProps = {
type EbayDialogCloseButtonProps = {
children?: ReactNode;
}

const EbayDialogCloseButton: FC = ({ children }: EbayDialogFooterProps) => <>{children}</>
const EbayDialogCloseButton: FC = ({ children }: EbayDialogCloseButtonProps) => <>{children}</>

export default EbayDialogCloseButton
23 changes: 23 additions & 0 deletions src/ebay-dialog-base/components/dialog-previous-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { FC, KeyboardEventHandler, MouseEventHandler } from 'react'
import classNames from 'classnames'
import { EbayIconButton } from '../../ebay-icon-button'
import { Icon } from '../../ebay-icon'

type EbayDialogPreviousButtonProps = {
icon?: Icon;
className?: string
onClick?: MouseEventHandler & KeyboardEventHandler
}

const EbayDialogPreviousButton: FC<EbayDialogPreviousButtonProps> = ({
className,
icon,
...rest
}: EbayDialogPreviousButtonProps) => (
<EbayIconButton
{...rest}
icon={icon || 'chevronLeft16'}
className={classNames(className, 'lightbox-dialog__prev')} />
)

export default EbayDialogPreviousButton
3 changes: 3 additions & 0 deletions src/ebay-dialog-base/components/dialogBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface DialogBaseProps<T> extends HTMLProps<T> {
mainId?: string;
ignoreEscape?: boolean;
closeButton?: ReactElement;
previousButton?: ReactElement;
focus?: RefObject<HTMLAnchorElement & HTMLButtonElement>;
animated?: boolean;
transitionElement?: TransitionElement;
Expand Down Expand Up @@ -74,6 +75,7 @@ export const DialogBase: FC<DialogBaseProps<HTMLElement>> = ({
onBackgroundClick = () => {},
ignoreEscape,
closeButton,
previousButton,
isModal,
role = 'dialog',
focus,
Expand Down Expand Up @@ -198,6 +200,7 @@ export const DialogBase: FC<DialogBaseProps<HTMLElement>> = ({
{top}
{dialogHeader && (
<div className={`${classPrefix}__header`}>
{previousButton}
{buttonPosition === 'right' && dialogHeader}
{buttonPosition !== 'bottom' && closeButtonContent}
{(buttonPosition === 'left' || buttonPosition === 'hidden') && dialogHeader}
Expand Down
18 changes: 16 additions & 2 deletions src/ebay-dialog-base/dialog-base-with-state.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import React, { Children, ReactElement } from 'react'
import { RemoveScroll } from 'react-remove-scroll'
import { DialogBase, DialogBaseProps } from './components/dialogBase'
import { EbayDialogCloseButton, EbayDialogFooter, EbayDialogHeader, EbayDialogActions } from './index'
import {
EbayDialogCloseButton,
EbayDialogFooter,
EbayDialogHeader,
EbayDialogActions,
EbayDialogPreviousButton
} from './index'

export const DialogBaseWithState = ({
isModal,
Expand All @@ -17,8 +23,15 @@ export const DialogBaseWithState = ({
const footer = childrenArray.find((child: ReactElement) => child.type === EbayDialogFooter)
const actions = childrenArray.find((child: ReactElement) => child.type === EbayDialogActions)
const closeButton = childrenArray.find((child: ReactElement) => child.type === EbayDialogCloseButton)
const previousButton = childrenArray.find((child: ReactElement) => child.type === EbayDialogPreviousButton)
const content = childrenArray.filter((child: ReactElement) =>
![EbayDialogHeader, EbayDialogFooter, EbayDialogCloseButton, EbayDialogActions].some(c => c === child.type))
![
EbayDialogHeader,
EbayDialogFooter,
EbayDialogCloseButton,
EbayDialogActions,
EbayDialogPreviousButton
].some(c => c === child.type))

const dialogBase = (
<DialogBase
Expand All @@ -29,6 +42,7 @@ export const DialogBaseWithState = ({
footer={footer}
actions={actions}
closeButton={closeButton}
previousButton={previousButton}
animated={animated}
>
{content}
Expand Down
1 change: 1 addition & 0 deletions src/ebay-dialog-base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { default as EbayDialogCloseButton } from './components/dialog-close-butt
export { WindowType, DialogBaseProps } from './components/dialogBase'
export { default as DialogBaseWithState } from './dialog-base-with-state'
export { default as EbayDialogActions } from './components/dialog-actions'
export { default as EbayDialogPreviousButton } from './components/dialog-previous-button'
3 changes: 3 additions & 0 deletions src/ebay-lightbox-dialog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ Will render a header content for the dialog. Will always render the header eleme

## EbayDialogFooter
Will render the footer content for the dialog. If not present then will not have any footer.

## EbayDialogPreviousButton
Will render the previous icon button. The icon can be overwritten with the `icon` attribute
106 changes: 106 additions & 0 deletions src/ebay-lightbox-dialog/__tests__/__snapshots__/index.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,109 @@ exports[`Storyshots ebay-lightbox-dialog With No Background Click 1`] = `
</div>
</DocumentFragment>
`;

exports[`Storyshots ebay-lightbox-dialog With Previous Button 1`] = `
<DocumentFragment>
<div
aria-hidden="false"
>
<p
aria-hidden="true"
>
Some outside content...
</p>
<div
aria-hidden="false"
>
<div
aria-hidden="false"
aria-labelledby="dialog-title-abc123"
arial-modal="true"
class="lightbox-dialog lightbox-dialog--mask-fade lightbox-dialog--show-init"
role="dialog"
>
<div
aria-hidden="true"
class="keyboard-trap-boundary"
tabindex="0"
/>
<div
aria-hidden="false"
class="lightbox-dialog__window lightbox-dialog__window--fade keyboard-trap--active"
>
<div
aria-hidden="true"
class="keyboard-trap-boundary"
tabindex="0"
/>
<div
class="lightbox-dialog__header"
>
<button
aria-label="Previous"
class="lightbox-dialog__prev icon-btn"
type="button"
>
<svg
aria-hidden="true"
class="icon icon--chevron-left-16"
focusable="false"
xmlns="http://www.w3.org/2000/svg"
>
<use
xlink:href="#icon-chevron-left-16"
/>
</svg>
</button>
<h2
id="dialog-title-abc123"
>
Heading
</h2>
<button
aria-label="Close dialog"
class="icon-btn lightbox-dialog__close"
type="button"
>
<svg
aria-hidden="true"
class="icon icon--close-16"
focusable="false"
xmlns="http://www.w3.org/2000/svg"
>
<use
xlink:href="#icon-close-16"
/>
</svg>
</button>
</div>
<div
class="lightbox-dialog__main"
>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p>
<a
href="http://www.ebay.com"
>
www.ebay.com
</a>
</p>
</div>
<div
aria-hidden="true"
class="keyboard-trap-boundary"
tabindex="0"
/>
</div>
<div
aria-hidden="true"
class="keyboard-trap-boundary"
tabindex="0"
/>
</div>
</div>
</div>
</DocumentFragment>
`;
14 changes: 13 additions & 1 deletion src/ebay-lightbox-dialog/__tests__/index.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react'
import { EbayDialogFooter, EbayDialogHeader } from '../../ebay-dialog-base'
import { EbayDialogFooter, EbayDialogHeader, EbayDialogPreviousButton } from '../../ebay-dialog-base'
import { EbayButton } from '../../ebay-button'
import { EbayCheckbox } from '../../ebay-checkbox'
import { EbayLabel } from '../../ebay-field'
Expand Down Expand Up @@ -159,4 +159,16 @@ export const _WithNoBackgroundClick = () => {
);
};

export const _WithPreviousButton = () => (
<div>
<p>Some outside content...</p>
<EbayLightboxDialog open a11yCloseText="Close dialog">
<EbayDialogPreviousButton aria-label="Previous" onClick={action('previous button click')}/>
<EbayDialogHeader>Heading</EbayDialogHeader>
{textParagraph}
<p><a href="http://www.ebay.com">www.ebay.com</a></p>
</EbayLightboxDialog>
</div>
);

export default story;
Loading