Skip to content

Commit

Permalink
Add Scoobie code themes, delete styles submodule
Browse files Browse the repository at this point in the history
I realised theming was pretty simple so I just frankensteined the
`github` and `vs` ones with a Braid palette.

https://github.com/FormidableLabs/prism-react-renderer/blob/e1c83a468b05df7f452b3ad7e4ae5ab874574d4e/packages/prism-react-renderer/src/themes/github.ts
  • Loading branch information
72636c committed Feb 14, 2025
1 parent ac19b66 commit 2af52a6
Show file tree
Hide file tree
Showing 18 changed files with 917 additions and 100 deletions.
5 changes: 5 additions & 0 deletions .changeset/tame-bugs-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'scoobie': major
---

styles: Remove submodule export
5 changes: 5 additions & 0 deletions .changeset/ten-cups-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'scoobie': minor
---

CodeBlock, CodeContainer, CodeThemeProvider: Add `scoobieDark` and `scoobieLight` themes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 43 additions & 25 deletions .storybook/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import { BraidProvider, Card, PageBlock } from 'braid-design-system';
import docs from 'braid-design-system/themes/docs';
import seekJobs from 'braid-design-system/themes/seekJobs';
import wireframe from 'braid-design-system/themes/wireframe';
import { themes } from 'prism-react-renderer';
import React from 'react';
import { Helmet, HelmetProvider } from 'react-helmet-async';
import { BrowserRouter } from 'react-router-dom';

import { CodeThemeProvider } from '../src/components/CodeThemeProvider';
import { ScoobieLink } from '../src/components/ScoobieLink';
import { codeThemes } from '../src/private/codeThemes';
import { robotoHref, robotoMonoHref } from '../typography';

const THEMES = { docs, seekJobs, wireframe };
Expand All @@ -20,13 +19,22 @@ export type BraidThemeName = 'docs' | 'seekJobs' | 'wireframe';

export default {
globalTypes: {
colorMode: {
description: 'Color mode to use',
defaultValue: 'lightMode',
toolbar: {
title: 'Color mode',
icon: 'contrast',
items: ['darkMode', 'lightMode'],
},
},
codeTheme: {
description: 'Code theme to use',
defaultValue: 'github',
toolbar: {
title: 'Code theme',
icon: 'contrast',
items: Object.keys(themes),
items: Object.keys(codeThemes),
},
},
theme: {
Expand All @@ -40,27 +48,37 @@ export default {
},
},
decorators: [
(Story, { globals }) => (
<BraidProvider
theme={THEMES[globals.theme as BraidThemeName]}
linkComponent={ScoobieLink}
>
<CodeThemeProvider theme={globals.codeTheme}>
<BrowserRouter>
<HelmetProvider>
<Helmet>
<link href={robotoHref} rel="stylesheet" />
<link href={robotoMonoHref} rel="stylesheet" />
</Helmet>
<PageBlock>
<Card>
<Story />
</Card>
</PageBlock>
</HelmetProvider>
</BrowserRouter>
</CodeThemeProvider>
</BraidProvider>
),
(Story, { globals }) => {
const DARK_MODE_CLASS = 'sprinkles_darkMode__1t46ksg10';

if (globals.colorMode === 'darkMode') {
document.documentElement.classList.add(DARK_MODE_CLASS);
} else {
document.documentElement.classList.remove(DARK_MODE_CLASS);
}

return (
<BraidProvider
theme={THEMES[globals.theme as BraidThemeName]}
linkComponent={ScoobieLink}
>
<CodeThemeProvider theme={globals.codeTheme}>
<BrowserRouter>
<HelmetProvider>
<Helmet>
<link href={robotoHref} rel="stylesheet" />
<link href={robotoMonoHref} rel="stylesheet" />
</Helmet>
<PageBlock>
<Card>
<Story />
</Card>
</PageBlock>
</HelmetProvider>
</BrowserRouter>
</CodeThemeProvider>
</BraidProvider>
);
},
],
} satisfies Preview;
33 changes: 0 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,39 +234,6 @@ export const SomeLinks = () => (
);
```

## Styling reference

Scoobie distributes some vanilla-extract styles via `scoobie/styles` submodules.

### code

Render text with the same monospace styling as our [CodeBlock](#codeblock):

```tsx
import { Box } from 'braid-design-system';
import React from 'react';
import { code } from 'scoobie/styles/code.css';

export const MyBox = () => (
<Box className={code.standard}>
<Box component="pre">Hello</Box>
</Box>
);
```

### img

```tsx
import React from 'react';
import { img } from 'scoobie/styles/img.css';

export const MySvg = () => (
<svg className={img}>
<path />
</svg>
);
```

## Webpack reference

Scoobie distributes its Webpack config via a `scoobie/webpack` submodule:
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
},
"files": [
"src",
"styles",
"webpack",
"types.d.ts",
"typography.ts"
Expand Down
2 changes: 1 addition & 1 deletion sku.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { SkuConfig } from 'sku';

const config: SkuConfig = {
rootResolution: false,
srcPaths: ['./src', './styles'],
srcPaths: ['./src'],

dangerouslySetESLintConfig: (skuConfig) => [
...skuConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/components/CodeContainer.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { calc } from '@vanilla-extract/css-utils';
import { colorModeStyle, responsiveStyle, vars } from 'braid-design-system/css';
import { darken, lighten } from 'polished';

import { codeBackgroundColor } from '../../styles';
import { codeBackgroundColor } from '../private/color';

export const lineNumberContainer = style([
{
Expand Down
11 changes: 6 additions & 5 deletions src/components/CodeContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Box, Stack } from 'braid-design-system';
import { Highlight, type Token } from 'prism-react-renderer';

import { Prism, themes } from '../private/Prism';
import { Prism } from '../private/Prism';
import { codeThemes } from '../private/codeThemes';

import { useCodeTheme } from './CodeThemeProvider';

import * as styles from './CodeContainer.css';
import * as codeStyles from '../../styles/code.css';
import * as fontStyles from '../private/font.css';

export const CodeContainer = ({
code,
Expand All @@ -25,7 +26,7 @@ export const CodeContainer = ({
prism={Prism}
code={code}
language={language}
theme={themes[theme]}
theme={codeThemes[theme]}
>
{({ getTokenProps, tokens }) => (
<Box display="flex">
Expand All @@ -46,7 +47,7 @@ const LineNumbers = ({ count }: { count: number }) => {
<Box aria-hidden className={styles.lineNumberContainer} padding="medium">
<Stack align="right" space="small">
{numbers.map((number) => (
<Box className={codeStyles.code} key={number}>
<Box className={fontStyles.code} key={number}>
<Box component="pre">{number}</Box>
</Box>
))}
Expand All @@ -69,7 +70,7 @@ const Lines = ({
<Box padding="medium">
<Stack space="small">
{lines.map((line, lineIndex) => (
<Box className={codeStyles.code} key={lineIndex}>
<Box className={fontStyles.code} key={lineIndex}>
<Box component="pre">
{line.map((token, tokenIndex) => {
const props = getTokenProps({ token });
Expand Down
Loading

0 comments on commit 2af52a6

Please sign in to comment.