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

Update text style and use it more consistently #217

Merged
merged 3 commits into from
Mar 13, 2024
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
9 changes: 0 additions & 9 deletions src/components/Box.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { styled } from "@storybook/theming";

import { Text } from "./Text";

export const Box = styled.div<{ warning?: boolean }>(
({ theme }) => ({
display: "flex",
Expand All @@ -20,13 +18,6 @@ export const Box = styled.div<{ warning?: boolean }>(
warning && { background: theme.base === "dark" ? "#342e1a" : theme.background.warning }
);

export const BoxContent = styled(Text)(({ theme }) => ({
flex: 1,
textAlign: "left",
whiteSpace: "pre-wrap",
color: theme.base === "light" ? theme.color.darker : theme.color.lighter,
}));

export const BoxTitle = styled.b(() => ({
display: "block",
marginBottom: 2,
Expand Down
8 changes: 2 additions & 6 deletions src/components/BuildProgressBarInline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@ const ProgressTextWrapper = styled(Text)({
marginTop: 15,
});

const StyledBuildProgressLabel = styled(BuildProgressLabel)({
fontSize: 12,
});

export function BuildProgressInline({
localBuildProgress,
}: {
localBuildProgress: LocalBuildProgress;
}) {
return (
<ProgressTextWrapper small as="div">
<ProgressTextWrapper center small>
<ProgressTrack>
{typeof localBuildProgress.buildProgressPercentage === "number" && (
<ProgressBar style={{ width: `${localBuildProgress.buildProgressPercentage}%` }} />
)}
</ProgressTrack>
<StyledBuildProgressLabel localBuildProgress={localBuildProgress} />
<BuildProgressLabel center muted small localBuildProgress={localBuildProgress} />
</ProgressTextWrapper>
);
}
16 changes: 5 additions & 11 deletions src/components/BuildProgressLabel.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
import { styled } from "@storybook/theming";
import React from "react";
import React, { ComponentProps } from "react";

import { BUILD_STEP_CONFIG } from "../buildSteps";
import { LocalBuildProgress } from "../types";
import { Text } from "./Text";

interface BuildProgressLabelProps {
localBuildProgress: LocalBuildProgress;
withEmoji?: boolean;
}

const Label = styled.span({
fontSize: 14,
lineHeight: "20px",
});

export const BuildProgressLabel = ({
localBuildProgress,
withEmoji = false,

...props
}: BuildProgressLabelProps) => {
}: BuildProgressLabelProps & ComponentProps<typeof Text>) => {
const { emoji, renderProgress } = BUILD_STEP_CONFIG[localBuildProgress.currentStep];
const label = renderProgress(localBuildProgress);
return (
<Label {...props}>
<Text {...props}>
{withEmoji && emoji} {label}
</Label>
</Text>
);
};
2 changes: 1 addition & 1 deletion src/components/SnapshotImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export const SnapshotImage = ({
{hasError && !latestImage && (
<StyledStack>
<PhotoIcon color={theme.base === "light" ? "currentColor" : theme.color.medium} />
<Text>
<Text center muted>
A snapshot couldn’t be captured. This often occurs when a story has a code error.
Confirm that this story successfully renders in your local Storybook and run the build
again.
Expand Down
37 changes: 31 additions & 6 deletions src/components/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
import { styled } from "@storybook/theming";

export const Text = styled.div<{ small?: boolean }>(({ small }) => ({
fontSize: small ? 12 : 14,
lineHeight: small ? "18px" : "20px",
textAlign: "center",
textWrap: "balance",
}));
export const Text = styled.div<{ center?: boolean; muted?: boolean; small?: boolean }>(
({ center, small, theme }) => ({
display: "inline-block",
color: theme.color.defaultText,
fontSize: small ? theme.typography.size.s1 : theme.typography.size.s2,
lineHeight: small ? "18px" : "20px",
textAlign: center ? "center" : "left",
textWrap: "balance",
}),
({ muted, theme }) => muted && { color: theme.base === "light" ? theme.color.dark : "#C9CDCF" },
({ theme }) => ({
b: {
color: theme.color.defaultText,
},
code: {
fontSize: theme.typography.size.s1,
border: `1px solid ${theme.appBorderColor}`,
borderRadius: 3,
padding: 2,
},
small: {
fontSize: theme.typography.size.s1,
},
span: {
whiteSpace: "nowrap",
},
svg: {
verticalAlign: "top",
},
})
);
36 changes: 2 additions & 34 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { styled } from "@storybook/theming";

import { Text as BaseText } from "./Text";

export const Base = styled.div<{ hidden?: boolean }>(({ hidden, theme }) => ({
background: theme.background.app,
containerType: "size",
Expand Down Expand Up @@ -52,37 +54,3 @@ export const Col = styled.div<{ push?: boolean }>(
},
({ push }) => push && { marginLeft: "auto" }
);

export const Text = styled.div(({ theme }) => ({
lineHeight: "18px",
color: `${theme.color.defaultText}99`,
b: {
color: theme.color.defaultText,
},
code: {
fontSize: theme.typography.size.s1,
border: `1px solid ${theme.appBorderColor}`,
borderRadius: 3,
padding: "0 3px",
},
small: {
fontSize: theme.typography.size.s1,
},
span: {
whiteSpace: "nowrap",
},
svg: {
verticalAlign: "top",
},
"@container (min-width: 800px)": {
br: {
verticalAlign: "top",
display: "inline-block",
content: "''",
background: theme.appBorderColor,
width: 1,
height: "100%",
margin: "0 6px",
},
},
}));
2 changes: 1 addition & 1 deletion src/screens/Authentication/SetSubdomain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const SetSubdomain = ({ onBack, onSignIn }: SetSubdomainProps) => {
<VisualTestsIcon />
</div>
<Heading>Sign in with SSO</Heading>
<Text>Enter your team&apos;s Chromatic URL.</Text>
<Text muted>Enter your team&apos;s Chromatic URL.</Text>
<Form onSubmit={handleSubmit}>
<SuffixInput
autoFocus
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Authentication/SignIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const SignIn = ({ onBack, onSignIn, onSignInWithSSO }: SignInProps) => {
<LinkIcon />
<VisualTestsIcon />
<Heading>Sign in to begin visual testing</Heading>
<Text>
<Text center muted>
Pinpoint bugs instantly by connecting with cloud browsers that run visual tests in
parallel.
</Text>
Expand Down
11 changes: 6 additions & 5 deletions src/screens/Authentication/Verify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { BackButton } from "../../components/BackButton";
import { Button } from "../../components/Button";
import { Container } from "../../components/Container";
import { Heading } from "../../components/Heading";
import { BackIcon } from "../../components/icons/BackIcon";
import { Screen } from "../../components/Screen";
import { Stack } from "../../components/Stack";
import { Text } from "../../components/Text";
Expand Down Expand Up @@ -148,10 +147,12 @@ export const Verify = ({
<Stack>
<div>
<Heading>Verify your account</Heading>
<Text>
Check this verification code on Chromatic to grant access to your published
Storybooks.
</Text>
<div>
<Text center muted>
Check this verification code on Chromatic to grant access to your published
Storybooks.
</Text>
</div>
<Digits>
{userCode?.split("").map((char: string, index: number) => (
// eslint-disable-next-line react/no-array-index-key
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Authentication/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const Welcome = ({ onNext, onUninstall }: WelcomeProps) => {
<div>
<VisualTestsIcon />
<Heading>Visual tests</Heading>
<Text>
<Text center muted>
Catch bugs in UI appearance automatically. Compare image snapshots to detect visual
changes.
</Text>
Expand Down
39 changes: 24 additions & 15 deletions src/screens/Errors/BuildError.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { styled } from "@storybook/theming";
import React from "react";
import React, { ReactNode } from "react";
import stripAnsi from "strip-ansi";

import { Box, BoxContent, BoxTitle } from "../../components/Box";
import { Box } from "../../components/Box";
import { Container } from "../../components/Container";
import { Link } from "../../components/design-system";
import { Heading } from "../../components/Heading";
Expand All @@ -12,9 +11,17 @@ import { Text } from "../../components/Text";
import { DOCS_URL } from "../../constants";
import { LocalBuildProgress } from "../../types";

const StyledText = styled(Text)(({ theme }) => ({
color: theme.base === "light" ? theme.color.dark : "#C9CDCF",
}));
const NewlinesAsBreaks = ({ content }: { content: string }) => {
const lines = content.split(/\r?\n/);
return (
<>
{lines.reduce<ReactNode[]>(
(acc, line, index) => acc.concat([index && <br />, line].filter(Boolean)),
[]
)}
</>
);
};

export const ErrorBox = ({
localBuildProgress,
Expand All @@ -24,14 +31,16 @@ export const ErrorBox = ({
title?: string;
}) => (
<Box warning>
<BoxContent>
<Text>
<span>
{title && <b>{title}: </b>}
{stripAnsi(
Array.isArray(localBuildProgress.originalError)
? localBuildProgress.originalError[0]?.message
: localBuildProgress.originalError?.message || "Unknown error"
)}
<NewlinesAsBreaks
content={stripAnsi(
Array.isArray(localBuildProgress.originalError)
? localBuildProgress.originalError[0]?.message
: localBuildProgress.originalError?.message || "Unknown error"
)}
/>
</span>{" "}
<Link
target="_blank"
Expand All @@ -40,7 +49,7 @@ export const ErrorBox = ({
>
{localBuildProgress.errorDetailsUrl ? "Details" : "Troubleshoot"}
</Link>
</BoxContent>
</Text>
</Box>
);

Expand All @@ -57,9 +66,9 @@ export const BuildError = ({
<Stack>
<div>
<Heading>Build failed</Heading>
<StyledText>
<Text center muted>
Check the Storybook process on the command line for more details.
</StyledText>
</Text>
</div>
<ErrorBox localBuildProgress={localBuildProgress} />

Expand Down
9 changes: 2 additions & 7 deletions src/screens/Errors/BuildLimited.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { styled } from "@storybook/theming";
import React from "react";

import { Button } from "../../components/Button";
Expand All @@ -9,10 +8,6 @@ import { Stack } from "../../components/Stack";
import { Text } from "../../components/Text";
import { LocalBuildProgress } from "../../types";

const StyledText = styled(Text)(({ theme }) => ({
color: theme.base === "light" ? theme.color.dark : "#C9CDCF",
}));

export const BuildLimited = ({
children,
localBuildProgress,
Expand All @@ -26,10 +21,10 @@ export const BuildLimited = ({
<Stack>
<div>
<Heading>Snapshot limit reached</Heading>
<StyledText>
<Text center muted>
Your account has reached its monthly snapshot limit. Visual testing is disabled.
Upgrade your plan to increase your quota.
</StyledText>
</Text>
</div>

<Button asChild size="medium" variant="solid">
Expand Down
20 changes: 8 additions & 12 deletions src/screens/Errors/GitNotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { styled } from "@storybook/theming";
import { LockIcon } from "@storybook/icons";
import React from "react";

import { Box, BoxContent, BoxTitle } from "../../components/Box";
import { Box, BoxTitle } from "../../components/Box";
import { Code } from "../../components/Code";
import { Container } from "../../components/Container";
import { Icon, Link } from "../../components/design-system";
import { Link } from "../../components/design-system";
import { Heading } from "../../components/Heading";
import { VisualTestsIcon } from "../../components/icons/VisualTestsIcon";
import { Screen } from "../../components/Screen";
import { Stack } from "../../components/Stack";
import { Text } from "../../components/Text";
import { useUninstallAddon } from "../Uninstalled/UninstallContext";

const StyledText = styled(Text)(({ theme }) => ({
color: theme.base === "light" ? theme.color.dark : "#C9CDCF",
}));

export const GitNotFound = () => {
const { uninstallAddon } = useUninstallAddon();
return (
Expand All @@ -25,19 +21,19 @@ export const GitNotFound = () => {
<div>
<VisualTestsIcon />
<Heading>Visual tests</Heading>
<StyledText>
<Text center muted>
Catch bugs in UI appearance automatically. Compare image snapshots to detect visual
changes.
</StyledText>
</Text>
</div>
<Box>
<Icon icon="lock" />
<BoxContent>
<LockIcon style={{ flexShrink: 0 }} />
<Text>
<BoxTitle>Git not detected</BoxTitle>
This addon requires Git to associate test results with commits and branches. Run{" "}
<Code>git init</Code> and make your first commit
<Code>git commit -m</Code> to get started!
</BoxContent>
</Text>
</Box>
<Link
target="_blank"
Expand Down
Loading
Loading