Skip to content

Commit

Permalink
fix(onboarding): Safari text selection
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurKnaus committed Jan 9, 2025
1 parent 01dea19 commit 7835416
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ export function OnboardingLayout({
) : null}
</Header>
<Divider withBottomMargin />
<Steps>
<div>
{steps.map(step => (
<Step key={step.title ?? step.type} {...step} />
<StyledStep key={step.title ?? step.type} {...step} />
))}
</Steps>
</div>
{nextSteps.length > 0 && (
<Fragment>
<Divider />
Expand Down Expand Up @@ -222,10 +222,10 @@ const Divider = styled('hr')<{withBottomMargin?: boolean}>`
${p => p.withBottomMargin && `margin-bottom: ${space(3)}`}
`;

const Steps = styled('div')`
display: flex;
flex-direction: column;
gap: 1.5rem;
const StyledStep = styled(Step)`
:not(:last-child) {
margin-bottom: 1.5rem;
}
`;

const Wrapper = styled('div')`
Expand Down
101 changes: 59 additions & 42 deletions static/app/components/onboarding/gettingStartedDoc/step.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type React from 'react';
import {Fragment, useState} from 'react';
import styled from '@emotion/styled';
import beautify from 'js-beautify';
Expand All @@ -14,7 +15,7 @@ export enum StepType {
VERIFY = 'verify',
}

export const StepTitle = {
export const StepTitles = {
[StepType.INSTALL]: t('Install'),
[StepType.CONFIGURE]: t('Configure SDK'),
[StepType.VERIFY]: t('Verify'),
Expand Down Expand Up @@ -117,7 +118,7 @@ export type Configuration = {
};

// TODO(aknaus): move to types
interface BaseStepProps {
interface BaseStepProps extends React.HTMLAttributes<HTMLDivElement> {
/**
* Additional information to be displayed below the configurations
*/
Expand Down Expand Up @@ -210,57 +211,55 @@ export function Step({
onOptionalToggleClick,
collapsible = false,
codeHeader,
...props
}: StepProps) {
const [showOptionalConfig, setShowOptionalConfig] = useState(false);

const config = (
<Fragment>
<ContentWrapper>
{description && <Description>{description}</Description>}

{!!configurations?.length && (
<Configurations>
{configurations.map((configuration, index) => {
if (configuration.configurations) {
return (
<Fragment key={index}>
{getConfiguration(configuration)}
{configuration.configurations.map(
(nestedConfiguration, nestedConfigurationIndex) => (
<Fragment key={nestedConfigurationIndex}>
{nestedConfigurationIndex ===
(configuration.configurations?.length ?? 1) - 1
? codeHeader
: null}
{getConfiguration(nestedConfiguration)}
</Fragment>
)
)}
</Fragment>
);
}
{!!configurations?.length &&
configurations.map((configuration, index) => {
if (configuration.configurations) {
return (
<Fragment key={index}>
{index === configurations.length - 1 ? codeHeader : null}
{getConfiguration(configuration)}
{configuration.configurations.map(
(nestedConfiguration, nestedConfigurationIndex) => (
<Fragment key={nestedConfigurationIndex}>
{nestedConfigurationIndex ===
(configuration.configurations?.length ?? 1) - 1
? codeHeader
: null}
{getConfiguration(nestedConfiguration)}
</Fragment>
)
)}
</Fragment>
);
})}
</Configurations>
)}
}
return (
<Fragment key={index}>
{index === configurations.length - 1 ? codeHeader : null}
{getConfiguration(configuration)}
</Fragment>
);
})}
{additionalInfo && <GeneralAdditionalInfo>{additionalInfo}</GeneralAdditionalInfo>}
</Fragment>
</ContentWrapper>
);

return collapsible ? (
<div>
<div {...props}>
<OptionalConfigWrapper
expanded={showOptionalConfig}
onClick={() => {
onOptionalToggleClick?.(!showOptionalConfig);
setShowOptionalConfig(!showOptionalConfig);
}}
>
<h4 style={{marginBottom: 0}}>{title ?? StepTitle[type]}</h4>
<StepTitle>{title ?? StepTitles[type]}</StepTitle>
<ToggleButton
priority="link"
borderless
Expand All @@ -272,40 +271,58 @@ export function Step({
{showOptionalConfig ? config : null}
</div>
) : (
<div>
<h4>{title ?? StepTitle[type]}</h4>
<div {...props}>
<StepTitle>{title ?? StepTitles[type]}</StepTitle>
{config}
</div>
);
}

const Configuration = styled('div')`
display: flex;
flex-direction: column;
gap: 1rem;
// NOTE: We intentionally avoid using flex or grid here
// as it leads to weird text selection behavior in Safari
// see https://github.com/getsentry/sentry/issues/79958

const CONTENT_SPACING = space(2);

const ContentWrapper = styled('div')`
margin-top: ${CONTENT_SPACING};
`;

const StepTitle = styled('h4')`
margin-bottom: 0 !important;
`;

const Configurations = styled(Configuration)`
margin-top: ${space(2)};
const Configuration = styled('div')`
:not(:last-child) {
margin-bottom: ${CONTENT_SPACING};
}
`;

const Description = styled('div')`
code {
color: ${p => p.theme.pink400};
}
:not(:last-child) {
margin-bottom: ${CONTENT_SPACING};
}
&& > p,
&& > h4,
&& > h5,
&& > h6 {
margin-bottom: ${space(1)};
&:not(:last-child) {
margin-bottom: ${CONTENT_SPACING};
}
}
`;

const AdditionalInfo = styled(Description)``;
const AdditionalInfo = styled(Description)`
margin-top: ${CONTENT_SPACING};
`;

const GeneralAdditionalInfo = styled(Description)`
margin-top: ${space(2)};
margin-top: ${CONTENT_SPACING};
`;

const OptionalConfigWrapper = styled('div')<{expanded: boolean}>`
Expand Down

0 comments on commit 7835416

Please sign in to comment.