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

Fix/dialog beta #3833

Merged
merged 19 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 5 additions & 1 deletion src/components/AuthMethodFeed/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@
}

.info {
padding: 0 var(--spacing-base) var(--spacing-loose);
padding: 0 var(--spacing-base);
color: var(--color-grey);
text-align: center;

@media (--sm-up) {
padding-bottom: var(--spacing-loose);
}

.errorHint {
margin-bottom: var(--spacing-base);
font-size: var(--font-size-sm);
Expand Down
128 changes: 128 additions & 0 deletions src/components/DialogBeta/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import { forwardRef } from 'react'

import { TextId } from '~/common/enums'
import {
Button,
ButtonProps,
IconSpinner16,
TextIcon,
Translate,
} from '~/components'

export type DialogTextButtonProps = {
text: TextId | React.ReactNode
color?: 'greyDarker' | 'green' | 'red'
loading?: boolean
} & ButtonProps

export const TextButton: React.FC<DialogTextButtonProps> = ({
text,
color = 'green',
loading,
...restProps
}) => {
let buttonProps: ButtonProps = restProps

switch (color) {
case 'greyDarker':
buttonProps = {
...buttonProps,
textColor: 'greyDarker',
textActiveColor: 'black',
}
break
case 'green':
buttonProps = {
...buttonProps,
textColor: 'green',
textActiveColor: 'greenDark',
}
break
case 'red':
buttonProps = {
...buttonProps,
textColor: 'red',
textActiveColor: 'redDark',
}
break
}

return (
<Button {...buttonProps}>
<TextIcon
size="md"
weight="md"
icon={loading && <IconSpinner16 size="sm" />}
>
{!loading ? (
typeof text === 'string' ? (
<Translate id={text as TextId} />
) : (
text
)
) : null}
</TextIcon>
</Button>
)
}

export type DialogRoundedButtonProps = {
text: TextId | React.ReactNode
color?: 'greyDarker' | 'green' | 'red'
icon?: React.ReactNode
loading?: boolean
} & ButtonProps

export const RoundedButton: React.FC<
React.PropsWithChildren<DialogRoundedButtonProps>
> = forwardRef(
({ text, color = 'green', loading, icon, disabled, ...restProps }, ref) => {
let buttonProps: ButtonProps = restProps

switch (color) {
case 'greyDarker':
buttonProps = {
...buttonProps,
borderColor: 'greyDarker',
textColor: 'greyDarker',
}
break
case 'green':
buttonProps = {
...buttonProps,
borderColor: 'green',
textColor: 'green',
}
break
case 'red':
buttonProps = { ...buttonProps, borderColor: 'red', textColor: 'red' }
break
}

return (
<Button
size={['100%', '3rem']}
disabled={disabled || loading}
ref={ref}
{...buttonProps}
>
<TextIcon
icon={icon || (loading && <IconSpinner16 size="md" />)}
size="xm"
weight="md"
textPlacement="left"
>
{!loading ? (
typeof text === 'string' ? (
<Translate id={text as TextId} />
) : (
text
)
) : null}
</TextIcon>
</Button>
)
}
)

RoundedButton.displayName = 'RoundedButton'
42 changes: 42 additions & 0 deletions src/components/DialogBeta/Content/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import classNames from 'classnames'

import Message from '../Message'
import styles from './styles.module.css'

interface DialogContentProps {
noSpacing?: boolean
smExtraSpacing?: boolean
fixedHeight?: boolean
noSpacingBottom?: boolean
noMaxHeight?: boolean
}

const DialogContent: React.FC<React.PropsWithChildren<DialogContentProps>> & {
Message: typeof Message
} = ({
noSpacing,
smExtraSpacing = true,
noSpacingBottom,
noMaxHeight,
fixedHeight,
children,
}) => {
const contentClasses = classNames({
[styles.content]: true,
[styles.spacing]: !noSpacing,
[styles.smExtraSpacing]: smExtraSpacing,
[styles.fixedHeight]: !!fixedHeight,
[styles.noSpacingBottom]: !!noSpacingBottom,
[styles.noMaxHeight]: !!noMaxHeight,
})

return (
<section className={contentClasses} data-dialog-entity>
{children}
</section>
)
}

DialogContent.Message = Message

export default DialogContent
45 changes: 45 additions & 0 deletions src/components/DialogBeta/Content/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.content {
display: flex;
flex-direction: column;
flex-shrink: 1;
max-height: calc(70vh - 4.25rem); /* 4.25rem is the height of header */
overflow-x: hidden;
overflow-y: auto;
-webkit-overflow-scrolling: touch;

&.fixedHeight {
height: calc(70vh - 4.25rem); /* 4.25rem is the height of header */

@media (--sm-up) {
height: min(30rem, 64vh);
}
}

@media (--sm-up) {
max-height: min(30rem, 64vh);
}
}

.smExtraSpacing {
padding-bottom: var(--spacing-xx-loose);

@media (--sm-up) {
padding-bottom: 0;
}
}

.spacing {
padding: var(--spacing-base);

@media (--sm-up) {
padding: 0 var(--spacing-base-loose);
}
}

.noSpacingBottom {
padding-bottom: 0;
}

.noMaxHeight {
max-height: none;
}
92 changes: 92 additions & 0 deletions src/components/DialogBeta/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import classNames from 'classnames'
import React from 'react'
import { FormattedMessage } from 'react-intl'

import { Media } from '~/components'

import { RoundedButton, TextButton } from '../Buttons'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment. can import from the original one so we can keep track the changes easier.

import styles from './styles.module.css'

type FooterProps = {
btns?: React.ReactNode
smUpBtns?: React.ReactNode
// smUpContentNoSpacingBottom?: boolean
// smUpSpaceBetween?: boolean
closeText?: React.ReactNode
closeDialog?: () => any
}

const Footer: React.FC<FooterProps> = ({
btns,
smUpBtns,
// smUpContentNoSpacingBottom = false,
// smUpSpaceBetween = false,
closeText,
closeDialog,
}) => {
if (!btns && !smUpBtns && !closeDialog) {
return null
}

const text = closeText || <FormattedMessage defaultMessage="Cancel" />

const footerClasses = classNames({
[styles.footer]: true,
})
const hasBtns = btns || closeDialog
const hasSmUpBtns = smUpBtns || closeDialog

const smUpContentClasses = classNames({
[styles.smUpContent]: true,
// [styles.smUpSpaceBetween]: !!smUpSpaceBetween,
// [styles.smUpContentNoSpacingBottom]: !!smUpContentNoSpacingBottom,
})

const SmUpBtns = () => (
<>
{hasSmUpBtns && (
<Media greaterThan="sm">
<section className={smUpContentClasses}>
{closeDialog && (
<TextButton
text={text}
color="greyDarker"
onClick={closeDialog}
/>
)}
{smUpBtns}
</section>
</Media>
)}
</>
)

if (hasBtns) {
return (
<footer className={footerClasses} data-dialog-entity>
<Media at="sm">
<section className={styles.content}>
{btns}
{closeDialog && (
<RoundedButton
text={text}
color="greyDarker"
onClick={closeDialog}
/>
)}
</section>
</Media>

<SmUpBtns />
</footer>
)
}

return (
<footer className={footerClasses}>
<SmUpBtns />
</footer>
)
}

export default Footer
41 changes: 41 additions & 0 deletions src/components/DialogBeta/Footer/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.footer {
position: relative;
}

.content {
@mixin flex-center-space-between;
@mixin safe-area-botttom;

flex-direction: column;
flex-shrink: 0;
padding: var(--spacing-base-loose) var(--spacing-base) 0;

& > * {
flex: 1;
width: 100%;
}

& > * + * {
margin-top: var(--spacing-base);
}
}

.smUpContent {
@mixin flex-center-end;

padding: 0 var(--spacing-base-loose) 0;
margin: var(--spacing-base) 0 var(--spacing-base-loose);
text-align: right;

& > * + * {
margin-left: var(--spacing-x-loose);
}
}

/* .smUpContentNoSpacingBottom {
margin-bottom: 0;
}
.smUpSpaceBetween {
@mixin flex-center-space-between;
} */
25 changes: 25 additions & 0 deletions src/components/DialogBeta/Handle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useIntl } from 'react-intl'

import styles from './styles.module.css'

interface HandleProps {
closeDialog: () => void
}

const Handle: React.FC<HandleProps> = ({ closeDialog, ...props }) => {
const intl = useIntl()

return (
<button
type="button"
className={styles.handle}
aria-label={intl.formatMessage({ defaultMessage: 'Close' })}
onClick={closeDialog}
{...props}
>
<span className={styles.icon} />
</button>
)
}

export default Handle
Loading
Loading