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

Refactor styling of debug dialog #2802

Merged
merged 1 commit into from
Jul 18, 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
13 changes: 3 additions & 10 deletions apps/store/src/components/CartPage/PageDebugDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useMemo } from 'react'
import { Space, Text } from 'ui'
import { Space } from 'ui'
import { CopyToClipboard } from '@/components/DebugDialog/CopyToClipboard'
import { DebugDialog } from '@/components/DebugDialog/DebugDialog'
import { DebugShopSessionSection } from '@/components/DebugDialog/DebugShopSessionSection'
Expand All @@ -12,7 +12,7 @@ import { PageLink } from '@/utils/PageLink'
export const PageDebugDialog = () => {
return (
<DebugDialog>
<Space y={1}>
<Space y={0.25}>
<LinkToCartSection />
<DebugShopSessionSection />
</Space>
Expand All @@ -33,12 +33,5 @@ const LinkToCartSection = () => {
})
}, [shopSession, routingLocale])

return (
<Space y={0.25}>
<Text as="p" size="sm">
Share link to cart
</Text>
<CopyToClipboard>{cartLink ?? ''}</CopyToClipboard>
</Space>
)
return <CopyToClipboard label="Share link to cart">{cartLink ?? ''}</CopyToClipboard>
}
51 changes: 23 additions & 28 deletions apps/store/src/components/DebugDialog/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import styled from '@emotion/styled'
import { useEffect, useState } from 'react'
import { CheckIcon, Text, theme } from 'ui'
import { SpaceFlex } from '@/components/SpaceFlex/SpaceFlex'
import { Text, theme } from 'ui'
import { useHighlightAnimation } from '@/utils/useHighlightAnimation'

export const CopyToClipboard = (props: { children: string }) => {
export const CopyToClipboard = (props: { label: string; children: string }) => {
const { highlight, animationProps } = useHighlightAnimation<HTMLButtonElement>()
const [copied, setCopied] = useState(false)

const copy = () => {
navigator.clipboard.writeText(props.children)
setCopied(true)
highlight()
}

useEffect(() => {
Expand All @@ -24,38 +26,34 @@ export const CopyToClipboard = (props: { children: string }) => {
}, [copied])

return (
<CopyToClipboardWrapper>
<Elipsis as="p" size="sm">
<CopyToClipboardWrapper type="button" onClick={copy} {...animationProps}>
<SlimText as="p" size="sm" color="textSecondaryOnGray">
{props.label}
</SlimText>

<Elipsis as="p" size="lg">
{props.children}
</Elipsis>
<CopyToClipboardButton onClick={copy}>
{copied ? (
<SpaceFlex align="center" space={0.5}>
<CheckIcon size="1em" />
Copied
</SpaceFlex>
) : (
'Copy'
)}
</CopyToClipboardButton>
</CopyToClipboardWrapper>
)
}

const CopyToClipboardWrapper = styled.div({
const CopyToClipboardWrapper = styled.button({
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
gap: theme.space.lg,
flexDirection: 'column',
justifyContent: 'center',
height: '3.25rem',
width: '100%',

backgroundColor: theme.colors.gray100,
paddingInline: theme.space.xs,
borderRadius: theme.radius.xs,
height: '2.5rem',
borderRadius: theme.radius.sm,
backgroundColor: theme.colors.translucent1,
paddingInline: theme.space.md,

'@media (hover: hover)': {
cursor: 'pointer',

'&:hover': {
backgroundColor: theme.colors.gray200,
backgroundColor: theme.colors.translucent2,
},
},
})
Expand All @@ -66,7 +64,4 @@ const Elipsis = styled(Text)({
whiteSpace: 'nowrap',
})

const CopyToClipboardButton = styled.button({
cursor: 'pointer',
flexShrink: 0,
})
const SlimText = styled(Text)({ lineHeight: 1 })
3 changes: 1 addition & 2 deletions apps/store/src/components/DebugDialog/DebugDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ const DialogContent = styled(Dialog.Content)({
})

const DialogWindow = styled(Dialog.Window)({
padding: theme.space.lg,
paddingTop: theme.space.md,
padding: theme.space.md,
borderBottomRightRadius: theme.radius.sm,
borderBottomLeftRadius: theme.radius.sm,
maxWidth: `calc(100% - ${theme.space.xs} * 2)`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const DebugResumeSessionSection = () => {
<TextField name={INPUT_NAME} label="Resume shop session" variant="small" />
</div>

<Button size="medium" type="submit">
<Button variant="secondary" size="medium" type="submit">
Go
</Button>
</Layout>
Expand All @@ -47,7 +47,7 @@ export const DebugResumeSessionSection = () => {

const Layout = styled.form({
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: now we have grid with single line, right? Maybe flexbox would be more obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmmm but then we need to add "flex" properties to children to determine how they scale horizontally

That's why I like grid -- it let's you determine layout from the parent 🙂

display: 'grid',
gridTemplateColumns: '4fr 1fr',
gridTemplateColumns: '4fr minmax(8rem, 1fr)',
alignItems: 'center',
gap: theme.space.xs,
gap: theme.space.xxs,
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from '@emotion/styled'
import { useRouter } from 'next/router'
import { Button, Space, Text, theme } from 'ui'
import { Button, Space } from 'ui'
import { useShopSession } from '@/services/shopSession/ShopSessionContext'
import { PageLink } from '@/utils/PageLink'
import { CopyToClipboard } from './CopyToClipboard'
Expand All @@ -15,32 +14,14 @@ export const DebugShopSessionSection = () => {
const nextUrl = `/${router.locale}${router.pathname}`

return (
<Space y={1}>
<Layout>
<Space y={0.25} style={{ flex: 1 }}>
<Text as="p" size="sm">
Shop Session
</Text>
<CopyToClipboard>{shopSession.id}</CopyToClipboard>
</Space>
<Space y={0.25}>
<CopyToClipboard label="Shop Session">{shopSession.id}</CopyToClipboard>

<Button
variant="secondary"
size="medium"
href={PageLink.apiSessionReset({ next: nextUrl })}
>
Reset
</Button>
</Layout>
<Button variant="secondary" href={PageLink.apiSessionReset({ next: nextUrl })}>
Reset Shop Session
</Button>

<DebugResumeSessionSection />
</Space>
)
}

const Layout = styled.div({
display: 'grid',
gridTemplateColumns: '4fr 1fr',
alignItems: 'flex-end',
gap: theme.space.xs,
})
13 changes: 3 additions & 10 deletions apps/store/src/components/ProductPage/PageDebugDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client'

import { useMemo } from 'react'
import { Space, Text } from 'ui'
import { Space } from 'ui'
import { CopyToClipboard } from '@/components/DebugDialog/CopyToClipboard'
import { DebugDialog } from '@/components/DebugDialog/DebugDialog'
import { DebugShopSessionSection } from '@/components/DebugDialog/DebugShopSessionSection'
Expand All @@ -13,7 +13,7 @@ import { usePriceIntent } from './PriceIntentContext'
export const PageDebugDialog = () => {
return (
<DebugDialog>
<Space y={1}>
<Space y={0.25}>
<DebugShopSessionSection />
<LinkToOfferSection />
</Space>
Expand All @@ -36,12 +36,5 @@ const LinkToOfferSection = () => {
})
}, [routingLocale, shopSession, priceIntent])

return (
<Space y={0.25}>
<Text as="p" size="sm">
Share link to offer
</Text>
<CopyToClipboard>{link ?? ''}</CopyToClipboard>
</Space>
)
return <CopyToClipboard label="Share link to offer">{link ?? ''}</CopyToClipboard>
}