Skip to content

feat: add light theme #11266

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

Merged
merged 21 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 7 additions & 1 deletion site/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import turbosnap from "vite-plugin-turbosnap";
module.exports = {
stories: ["../src/**/*.stories.tsx"],
addons: [
{
name: "@storybook/addon-essentials",
options: {
backgrounds: false,
},
},
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-mdx-gfm",
"@storybook/addon-actions",
"@storybook/addon-themes",
],
staticDirs: ["../static"],
framework: {
Expand Down
53 changes: 28 additions & 25 deletions site/.storybook/preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,33 @@ import {
ThemeProvider as MuiThemeProvider,
} from "@mui/material/styles";
import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
import { DecoratorHelpers } from "@storybook/addon-themes";
import { withRouter } from "storybook-addon-react-router-v6";
import { QueryClient, QueryClientProvider } from "react-query";
import { HelmetProvider } from "react-helmet-async";
import theme from "theme";
import colors from "theme/tailwind";
import themes from "theme";
import "theme/globalFonts";
import { QueryClient, QueryClientProvider } from "react-query";

DecoratorHelpers.initializeThemeState(Object.keys(themes), "dark");

export const decorators = [
(Story) => (
<StyledEngineProvider injectFirst>
<MuiThemeProvider theme={theme.dark}>
<EmotionThemeProvider theme={theme.dark}>
<CssBaseline />
<Story />
</EmotionThemeProvider>
</MuiThemeProvider>
</StyledEngineProvider>
),
(Story, context) => {
const selectedTheme = DecoratorHelpers.pluckThemeFromContext(context);
const { themeOverride } = DecoratorHelpers.useThemeParameters();

const selected = themeOverride || selectedTheme || "dark";

return (
<StyledEngineProvider injectFirst>
<MuiThemeProvider theme={themes[selected]}>
<EmotionThemeProvider theme={themes[selected]}>
<CssBaseline />
<Story />
</EmotionThemeProvider>
</MuiThemeProvider>
</StyledEngineProvider>
);
},
withRouter,
(Story) => {
return (
Expand Down Expand Up @@ -50,18 +59,12 @@ export const decorators = [
];

export const parameters = {
backgrounds: {
default: "dark",
values: [
{
name: "dark",
value: colors.gray[950],
},
{
name: "light",
value: colors.gray[50],
},
],
options: {
storySort: {
method: "alphabetical",
order: ["design", "pages", "components"],
locales: "en-US",
},
},
actions: {
argTypesRegex: "^(on|handler)[A-Z].*",
Expand Down
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"@storybook/addon-essentials": "7.5.2",
"@storybook/addon-links": "7.5.2",
"@storybook/addon-mdx-gfm": "7.5.2",
"@storybook/addon-themes": "^7.6.4",
"@storybook/react": "7.5.2",
"@storybook/react-vite": "7.5.2",
"@swc/core": "1.3.38",
Expand Down
9 changes: 9 additions & 0 deletions site/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions site/src/components/ActiveUserChart/ActiveUserChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
},
scales: {
y: {
grid: { color: theme.palette.divider },
suggestedMin: 0,
ticks: {
precision: 0,
},
},

x: {
grid: { color: theme.palette.divider },
ticks: {
stepSize: data.length > 10 ? 2 : undefined,
},
Expand All @@ -122,11 +124,9 @@ export const ActiveUserChart: FC<ActiveUserChartProps> = ({
{
label: `${interval === "day" ? "Daily" : "Weekly"} Active Users`,
data: chartData,
pointBackgroundColor: theme.palette.info.light,
pointBorderColor: theme.palette.info.light,
borderColor: theme.palette.info.light,
backgroundColor: theme.palette.info.dark,
fill: "origin",
pointBackgroundColor: theme.experimental.roles.active.outline,
pointBorderColor: theme.experimental.roles.active.outline,
borderColor: theme.experimental.roles.active.outline,
},
],
}}
Expand Down
23 changes: 23 additions & 0 deletions site/src/components/Badges/Badges.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ import type { Meta, StoryObj } from "@storybook/react";
import {
Badges,
AlphaBadge,
DisabledBadge,
EnabledBadge,
EntitledBadge,
EnterpriseBadge,
HealthyBadge,
NotHealthyBadge,
NotRegisteredBadge,
NotReachableBadge,
} from "./Badges";

const meta: Meta<typeof Badges> = {
Expand All @@ -26,6 +31,24 @@ export const Entitled: Story = {
children: <EntitledBadge />,
},
};
export const ProxyStatus: Story = {
args: {
children: (
<>
<HealthyBadge />
<HealthyBadge derpOnly />
<NotHealthyBadge />
<NotRegisteredBadge />
<NotReachableBadge />
</>
),
},
};
export const Disabled: Story = {
args: {
children: <DisabledBadge />,
},
};
export const Enterprise: Story = {
args: {
children: <EnterpriseBadge />,
Expand Down
28 changes: 16 additions & 12 deletions site/src/components/Badges/Badges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ const styles = {
enabledBadge: (theme) => ({
border: `1px solid ${theme.experimental.roles.success.outline}`,
backgroundColor: theme.experimental.roles.success.background,
color: theme.experimental.roles.success.text,
}),
errorBadge: (theme) => ({
border: `1px solid ${theme.experimental.roles.error.outline}`,
backgroundColor: theme.experimental.roles.error.background,
color: theme.experimental.roles.error.text,
}),
warnBadge: (theme) => ({
border: `1px solid ${theme.experimental.roles.warning.outline}`,
backgroundColor: theme.experimental.roles.warning.background,
color: theme.experimental.roles.warning.text,
}),
} satisfies Record<string, Interpolation<Theme>>;

Expand All @@ -42,10 +45,9 @@ export const EntitledBadge: FC = () => {
};

interface HealthyBadge {
derpOnly: boolean;
derpOnly?: boolean;
}
export const HealthyBadge: FC<HealthyBadge> = (props) => {
const { derpOnly } = props;
export const HealthyBadge: FC<HealthyBadge> = ({ derpOnly }) => {
return (
<span css={[styles.badge, styles.enabledBadge]}>
{derpOnly ? "Healthy (DERP only)" : "Healthy"}
Expand Down Expand Up @@ -79,8 +81,9 @@ export const DisabledBadge: FC = () => {
css={[
styles.badge,
(theme) => ({
border: `1px solid ${theme.palette.divider}`,
backgroundColor: theme.palette.background.paper,
border: `1px solid ${theme.experimental.l1.outline}`,
backgroundColor: theme.experimental.l1.background,
color: theme.experimental.l1.text,
}),
]}
>
Expand All @@ -95,8 +98,9 @@ export const EnterpriseBadge: FC = () => {
css={[
styles.badge,
(theme) => ({
backgroundColor: theme.palette.info.dark,
border: `1px solid ${theme.palette.info.light}`,
backgroundColor: theme.experimental.roles.info.background,
border: `1px solid ${theme.experimental.roles.info.outline}`,
color: theme.experimental.roles.info.text,
}),
]}
>
Expand All @@ -110,11 +114,11 @@ export const AlphaBadge: FC = () => {
<span
css={[
styles.badge,
{
border: `1px solid ${colors.violet[600]}`,
backgroundColor: colors.violet[950],
color: colors.violet[50],
},
(theme) => ({
border: `1px solid ${theme.experimental.roles.preview.outline}`,
backgroundColor: theme.experimental.roles.preview.background,
color: theme.experimental.roles.preview.text,
}),
]}
>
Alpha
Expand Down
12 changes: 6 additions & 6 deletions site/src/components/CodeExample/CodeExample.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import type { Meta, StoryObj } from "@storybook/react";
import { CodeExample } from "./CodeExample";

const sampleCode = `echo "Hello, world"`;

const meta: Meta<typeof CodeExample> = {
title: "components/CodeExample",
component: CodeExample,
argTypes: {
code: { control: "string", defaultValue: sampleCode },
args: {
code: `echo "hello, friend!"`,
},
};

export default meta;
type Story = StoryObj<typeof CodeExample>;

export const Example: Story = {
export const Example: Story = {};

export const Secret: Story = {
args: {
code: sampleCode,
secret: true,
},
};

Expand Down
68 changes: 34 additions & 34 deletions site/src/components/CodeExample/CodeExample.tsx
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
import { type FC } from "react";
import { useTheme } from "@emotion/react";
import { type Interpolation, type Theme } from "@emotion/react";
import { MONOSPACE_FONT_FAMILY } from "theme/constants";
import { CopyButton } from "../CopyButton/CopyButton";

export interface CodeExampleProps {
code: string;
password?: boolean;
secret?: boolean;
className?: string;
}

/**
* Component to show single-line code examples, with a copy button
*/
export const CodeExample: FC<CodeExampleProps> = (props) => {
const { code, password, className } = props;
const theme = useTheme();

export const CodeExample: FC<CodeExampleProps> = ({
code,
secret,
className,
}) => {
return (
<div
css={{
display: "flex",
flexDirection: "row",
alignItems: "center",
background: "rgb(0 0 0 / 30%)",
color: theme.palette.primary.contrastText,
fontFamily: MONOSPACE_FONT_FAMILY,
fontSize: 14,
borderRadius: 8,
padding: 8,
lineHeight: "150%",
border: `1px solid ${theme.palette.divider}`,
}}
className={className}
>
<code
css={{
padding: "0 8px",
width: "100%",
display: "flex",
alignItems: "center",
wordBreak: "break-all",
"-webkit-text-security": password ? "disc" : undefined,
}}
>
{code}
</code>
<div css={styles.container} className={className}>
<code css={[styles.code, secret && styles.secret]}>{code}</code>
<CopyButton text={code} />
</div>
);
};

const styles = {
container: (theme) => ({
display: "flex",
flexDirection: "row",
alignItems: "center",
color: theme.experimental.l1.text,
fontFamily: MONOSPACE_FONT_FAMILY,
fontSize: 14,
borderRadius: 8,
padding: 8,
lineHeight: "150%",
border: `1px solid ${theme.experimental.l1.outline}`,
}),

code: {
padding: "0 8px",
flexGrow: 1,
wordBreak: "break-all",
},

secret: {
"-webkit-text-security": "disc", // also supported by firefox
},
} satisfies Record<string, Interpolation<Theme>>;
Loading