From 0159227befa16188bc9fa86bdb57b054c5c509b6 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 31 Aug 2024 14:31:47 +0900 Subject: [PATCH 1/4] refactor(site/system): simplify the file structure --- site/src/system/{Box => }/Box.tsx | 4 ++-- .../system/{ButtonLink => }/ButtonLink.css.ts | 4 ++-- .../system/{ButtonLink => }/ButtonLink.tsx | 6 ++--- site/src/system/{Columns => }/Columns.tsx | 23 +++++++++---------- .../{ContentBlock => }/ContentBlock.css.ts | 0 .../{ContentBlock => }/ContentBlock.tsx | 15 ++++++------ site/src/system/{Stack => }/Stack.tsx | 15 +++++------- site/src/system/index.ts | 11 +++++---- site/src/system/styles/index.ts | 2 ++ 9 files changed, 40 insertions(+), 40 deletions(-) rename site/src/system/{Box => }/Box.tsx (94%) rename site/src/system/{ButtonLink => }/ButtonLink.css.ts (92%) rename site/src/system/{ButtonLink => }/ButtonLink.tsx (93%) rename site/src/system/{Columns => }/Columns.tsx (95%) rename site/src/system/{ContentBlock => }/ContentBlock.css.ts (100%) rename site/src/system/{ContentBlock => }/ContentBlock.tsx (81%) rename site/src/system/{Stack => }/Stack.tsx (76%) create mode 100644 site/src/system/styles/index.ts diff --git a/site/src/system/Box/Box.tsx b/site/src/system/Box.tsx similarity index 94% rename from site/src/system/Box/Box.tsx rename to site/src/system/Box.tsx index 30f9f1bb8..f3ee0d3bd 100644 --- a/site/src/system/Box/Box.tsx +++ b/site/src/system/Box.tsx @@ -1,7 +1,7 @@ import { createElement, AllHTMLAttributes, ElementType } from 'react'; import classnames from 'classnames'; -import * as resetStyles from '../styles/reset.css'; -import { sprinkles, Sprinkles } from '../styles/sprinkles.css'; +import * as resetStyles from './styles/reset.css'; +import { sprinkles, Sprinkles } from './styles/sprinkles.css'; export interface BoxProps extends Omit< diff --git a/site/src/system/ButtonLink/ButtonLink.css.ts b/site/src/system/ButtonLink.css.ts similarity index 92% rename from site/src/system/ButtonLink/ButtonLink.css.ts rename to site/src/system/ButtonLink.css.ts index 11fb593ac..4d27c4279 100644 --- a/site/src/system/ButtonLink/ButtonLink.css.ts +++ b/site/src/system/ButtonLink.css.ts @@ -1,6 +1,6 @@ import { style } from '@vanilla-extract/css'; -import { vars } from '../../themes.css'; -import { darkMode } from '../styles/sprinkles.css'; +import { vars } from '../themes.css'; +import { darkMode } from './styles'; export const button = style({ textDecoration: 'none', diff --git a/site/src/system/ButtonLink/ButtonLink.tsx b/site/src/system/ButtonLink.tsx similarity index 93% rename from site/src/system/ButtonLink/ButtonLink.tsx rename to site/src/system/ButtonLink.tsx index 2cb752597..b349661a4 100644 --- a/site/src/system/ButtonLink/ButtonLink.tsx +++ b/site/src/system/ButtonLink.tsx @@ -2,11 +2,11 @@ import { ReactNode } from 'react'; import classnames from 'classnames'; import { Link, NavLinkProps } from 'react-router-dom'; import { HashLink } from 'react-router-hash-link'; -import { Box } from '..'; +import { Box } from '.'; import * as styles from './ButtonLink.css'; -import { sprinkles } from '../styles/sprinkles.css'; +import { sprinkles } from './styles'; -interface ButtonLinkProps extends NavLinkProps { +export interface ButtonLinkProps extends NavLinkProps { variant?: 'solid' | 'transparent'; icon?: ReactNode; children: ReactNode; diff --git a/site/src/system/Columns/Columns.tsx b/site/src/system/Columns.tsx similarity index 95% rename from site/src/system/Columns/Columns.tsx rename to site/src/system/Columns.tsx index 8d8c3e58f..99216d195 100644 --- a/site/src/system/Columns/Columns.tsx +++ b/site/src/system/Columns.tsx @@ -1,19 +1,10 @@ import { Children, ReactNode } from 'react'; -import { Box } from '../Box/Box'; +import { Box } from './Box'; import { mapResponsiveValue, ResponsiveValue, Space, -} from '../styles/sprinkles.css'; - -interface Props { - children: ReactNode; - space: Space; - alignY?: ResponsiveValue<'top' | 'center' | 'bottom'>; - reverseX?: boolean; - collapseOnMobile?: boolean; - collapseOnTablet?: boolean; -} +} from './styles/sprinkles.css'; const alignYToFlexAlign = { top: 'flex-start', @@ -24,6 +15,14 @@ const alignYToFlexAlign = { const negate = (space: Space) => space === 'none' ? ('none' as const) : (`-${space}` as const); +export interface ColumnsProps { + children: ReactNode; + space: Space; + alignY?: ResponsiveValue<'top' | 'center' | 'bottom'>; + reverseX?: boolean; + collapseOnMobile?: boolean; + collapseOnTablet?: boolean; +} export const Columns = ({ children, space, @@ -31,7 +30,7 @@ export const Columns = ({ collapseOnTablet = false, reverseX = false, alignY = 'top', -}: Props) => { +}: ColumnsProps) => { const columns = Children.toArray(children); const row = reverseX ? 'row-reverse' : 'row'; diff --git a/site/src/system/ContentBlock/ContentBlock.css.ts b/site/src/system/ContentBlock.css.ts similarity index 100% rename from site/src/system/ContentBlock/ContentBlock.css.ts rename to site/src/system/ContentBlock.css.ts diff --git a/site/src/system/ContentBlock/ContentBlock.tsx b/site/src/system/ContentBlock.tsx similarity index 81% rename from site/src/system/ContentBlock/ContentBlock.tsx rename to site/src/system/ContentBlock.tsx index b06ae391b..c59ee9189 100644 --- a/site/src/system/ContentBlock/ContentBlock.tsx +++ b/site/src/system/ContentBlock.tsx @@ -1,17 +1,18 @@ import { ReactNode } from 'react'; -import { Box } from '../'; +import { Box, type BoxProps } from './Box'; import * as styles from './ContentBlock.css'; -import { BoxProps } from '../Box/Box'; + +export interface ContentBlockProps { + children: ReactNode; + withGutters?: boolean; + size?: BoxProps['maxWidth']; +} export const ContentBlock = ({ children, withGutters = false, size = 'standard', -}: { - children: ReactNode; - withGutters?: boolean; - size?: BoxProps['maxWidth']; -}) => { +}: ContentBlockProps) => { return ( ; -}) => { +} + +export const Stack = ({ children, space, align }: StackProps) => { const stackItems = Children.toArray(children); const alignItems = align ? mapResponsiveValue(align, (value) => alignToFlexAlign[value]) diff --git a/site/src/system/index.ts b/site/src/system/index.ts index 345b996c2..cdeaea051 100644 --- a/site/src/system/index.ts +++ b/site/src/system/index.ts @@ -1,5 +1,6 @@ -export { Box } from './Box/Box'; -export { ButtonLink } from './ButtonLink/ButtonLink'; -export { ContentBlock } from './ContentBlock/ContentBlock'; -export { Columns } from './Columns/Columns'; -export { Stack } from './Stack/Stack'; +export * from './styles'; +export { Box, type BoxProps } from './Box'; +export { ButtonLink, type ButtonLinkProps } from './ButtonLink'; +export { Columns, type ColumnsProps } from './Columns'; +export { ContentBlock, type ContentBlockProps } from './ContentBlock'; +export { Stack, type StackProps } from './Stack'; diff --git a/site/src/system/styles/index.ts b/site/src/system/styles/index.ts new file mode 100644 index 000000000..b0fc1c3c3 --- /dev/null +++ b/site/src/system/styles/index.ts @@ -0,0 +1,2 @@ +export * from './reset.css'; +export * from './sprinkles.css'; From 729cae3e160274bd22712a846deb0670ab25a97e Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 31 Aug 2024 14:51:45 +0900 Subject: [PATCH 2/4] refactor(site/typography): rename Typography to typography, add index.ts like system, unify with export arrow func style --- site/src/{Typography => typography}/Heading.tsx | 2 +- site/src/{Typography => typography}/Link.css.ts | 0 site/src/{Typography => typography}/Link.tsx | 13 ++++++++----- site/src/{Typography => typography}/Text.tsx | 2 +- site/src/typography/index.ts | 8 ++++++++ .../{Typography => typography}/typography.css.ts | 0 6 files changed, 18 insertions(+), 7 deletions(-) rename site/src/{Typography => typography}/Heading.tsx (94%) rename site/src/{Typography => typography}/Link.css.ts (100%) rename site/src/{Typography => typography}/Link.tsx (87%) rename site/src/{Typography => typography}/Text.tsx (98%) create mode 100644 site/src/typography/index.ts rename site/src/{Typography => typography}/typography.css.ts (100%) diff --git a/site/src/Typography/Heading.tsx b/site/src/typography/Heading.tsx similarity index 94% rename from site/src/Typography/Heading.tsx rename to site/src/typography/Heading.tsx index 1171f0c9d..43bbf7a8c 100644 --- a/site/src/Typography/Heading.tsx +++ b/site/src/typography/Heading.tsx @@ -3,7 +3,7 @@ import classnames from 'classnames'; import * as styles from './typography.css'; import { Box } from '../system'; -import { sprinkles, Sprinkles } from '../system/styles/sprinkles.css'; +import { sprinkles, Sprinkles } from '../system/styles'; export type HeadingLevel = keyof typeof styles.heading; diff --git a/site/src/Typography/Link.css.ts b/site/src/typography/Link.css.ts similarity index 100% rename from site/src/Typography/Link.css.ts rename to site/src/typography/Link.css.ts diff --git a/site/src/Typography/Link.tsx b/site/src/typography/Link.tsx similarity index 87% rename from site/src/Typography/Link.tsx rename to site/src/typography/Link.tsx index 94635a54a..ed1dc4311 100644 --- a/site/src/Typography/Link.tsx +++ b/site/src/typography/Link.tsx @@ -1,11 +1,14 @@ -import { Link, LinkProps } from 'react-router-dom'; +import { + Link as RouterLink, + LinkProps as RouterLinkProps, +} from 'react-router-dom'; import { HashLink } from 'react-router-hash-link'; import classnames from 'classnames'; import { TextProps, useTextStyles } from './Text'; import * as styles from './Link.css'; import { sprinkles } from '../system/styles/sprinkles.css'; -interface Props extends LinkProps { +export interface LinkProps extends RouterLinkProps { baseline?: boolean; size?: 'standard' | 'small' | 'xsmall'; underline?: 'always' | 'hover' | 'never'; @@ -16,7 +19,7 @@ interface Props extends LinkProps { inline?: boolean; highlightOnFocus?: boolean; } -export default ({ +export const Link = ({ to, baseline = false, size = 'standard', @@ -28,7 +31,7 @@ export default ({ inline = false, className, ...restProps -}: Props) => { +}: LinkProps) => { const classNames = classnames( inline ? undefined : sprinkles({ display: 'block' }), underline === 'hover' ? styles.underlineOnHover : undefined, @@ -47,7 +50,7 @@ export default ({ } return ( - window.scrollTo(0, 0)} to={to} {...restProps} diff --git a/site/src/Typography/Text.tsx b/site/src/typography/Text.tsx similarity index 98% rename from site/src/Typography/Text.tsx rename to site/src/typography/Text.tsx index a40ec29a3..9ea41c18a 100644 --- a/site/src/Typography/Text.tsx +++ b/site/src/typography/Text.tsx @@ -42,7 +42,7 @@ export const useTextStyles = ({ styles.weight[weight], ); -export default ({ +export const Text = ({ component = 'span', size, color, diff --git a/site/src/typography/index.ts b/site/src/typography/index.ts new file mode 100644 index 000000000..d5c310ca5 --- /dev/null +++ b/site/src/typography/index.ts @@ -0,0 +1,8 @@ +export { + Heading, + useHeadingStyles, + type HeadingProps, + type HeadingLevel, +} from './Heading'; +export { Link, type LinkProps } from './Link'; +export { Text, useTextStyles, type TextProps } from './Text'; diff --git a/site/src/Typography/typography.css.ts b/site/src/typography/typography.css.ts similarity index 100% rename from site/src/Typography/typography.css.ts rename to site/src/typography/typography.css.ts From 4789b2f2ec26f8361f7ebad3d888716db2be502b Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 31 Aug 2024 15:16:20 +0900 Subject: [PATCH 3/4] refactor(site): unify components with export const arrow function, add Props interface for each component --- site/src/Blockquote/Blockquote.css.ts | 2 +- site/src/Blockquote/Blockquote.tsx | 6 ++++- site/src/Code/CompiledCode.css.ts | 2 +- site/src/Code/CompiledCode.tsx | 4 ++-- site/src/Code/ErrorHighlighter.tsx | 7 ++++-- site/src/Code/SyntaxHighlighter.css.ts | 2 +- site/src/Code/SyntaxHighlighter.tsx | 20 +++++++++------- .../ColorModeToggle/ColorModeToggle.css.ts | 2 +- site/src/ColorModeToggle/ColorModeToggle.tsx | 8 +++++-- site/src/Divider/Divider.tsx | 2 +- site/src/DocsPage/DocsPage.tsx | 11 ++++----- site/src/DocsPage/SiblingDoc/SiblingDoc.tsx | 10 +++++--- site/src/Fab/Fab.css.ts | 2 +- site/src/Fab/Fab.tsx | 9 ++++---- site/src/GitHubStars/GitHubStars.tsx | 2 +- site/src/HomePage/HomePage.tsx | 8 +++---- site/src/InlineCode/InlineCode.css.ts | 2 +- site/src/InlineCode/InlineCode.tsx | 2 +- site/src/Logo/Logo.tsx | 6 ++++- site/src/SearchInput/SearchInput.css.ts | 2 +- site/src/Tweet/Tweet.css.ts | 2 +- site/src/Tweet/Tweet.tsx | 3 +-- site/src/mdx-components.tsx | 23 +++++++++++-------- 23 files changed, 79 insertions(+), 58 deletions(-) diff --git a/site/src/Blockquote/Blockquote.css.ts b/site/src/Blockquote/Blockquote.css.ts index 3c233c6f3..ea71e8c41 100644 --- a/site/src/Blockquote/Blockquote.css.ts +++ b/site/src/Blockquote/Blockquote.css.ts @@ -1,5 +1,5 @@ import { globalStyle, style } from '@vanilla-extract/css'; -import { darkMode } from '../system/styles/sprinkles.css'; +import { darkMode } from '../system/styles'; import { vars } from '../themes.css'; export const root = style({ diff --git a/site/src/Blockquote/Blockquote.tsx b/site/src/Blockquote/Blockquote.tsx index 2f45c5a62..745fe8804 100644 --- a/site/src/Blockquote/Blockquote.tsx +++ b/site/src/Blockquote/Blockquote.tsx @@ -2,7 +2,11 @@ import { ReactNode } from 'react'; import { Box } from '../system'; import * as styles from './Blockquote.css'; -export default (props: { children: ReactNode }) => { +export interface BlockquoteProps { + children: ReactNode; +} + +export const Blockquote = (props: BlockquoteProps) => { return ( ; } -export const ErrorHighlighter = ({ tokens, children }: CodeProps) => { +export const ErrorHighlighter = ({ + tokens, + children, +}: ErrorHighlighterProps) => { const rootRef = useRef(null); useEffect(() => { diff --git a/site/src/Code/SyntaxHighlighter.css.ts b/site/src/Code/SyntaxHighlighter.css.ts index 26ea3ea97..06c954fdc 100644 --- a/site/src/Code/SyntaxHighlighter.css.ts +++ b/site/src/Code/SyntaxHighlighter.css.ts @@ -4,7 +4,7 @@ import { createThemeContract, assignVars, } from '@vanilla-extract/css'; -import { darkMode } from '../system/styles/sprinkles.css'; +import { darkMode } from '../system/styles'; import { vars } from '../themes.css'; const themeVars = createThemeContract({ diff --git a/site/src/Code/SyntaxHighlighter.tsx b/site/src/Code/SyntaxHighlighter.tsx index 11b5be5e1..62f3b10eb 100644 --- a/site/src/Code/SyntaxHighlighter.tsx +++ b/site/src/Code/SyntaxHighlighter.tsx @@ -1,23 +1,27 @@ // @ts-ignore -import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter/dist/esm/index'; +import { PrismLight } from 'react-syntax-highlighter/dist/esm/index'; // @ts-ignore import tsx from 'react-syntax-highlighter/dist/esm/languages/prism/tsx'; // @ts-ignore import ts from 'react-syntax-highlighter/dist/esm/languages/prism/typescript'; -SyntaxHighlighter.registerLanguage('tsx', tsx); -SyntaxHighlighter.registerLanguage('ts', ts); +PrismLight.registerLanguage('tsx', tsx); +PrismLight.registerLanguage('ts', ts); import { Box } from '../system'; -import Text from '../Typography/Text'; +import { Text } from '../typography'; import * as styles from './SyntaxHighlighter.css'; -export interface CodeProps { +export interface SyntaxHighlighterProps { language: string; children: string; tokenized?: boolean; } -export default ({ language, children, tokenized }: CodeProps) => { +export const SyntaxHighlighter = ({ + language, + children, + tokenized, +}: SyntaxHighlighterProps) => { return ( @@ -28,12 +32,12 @@ export default ({ language, children, tokenized }: CodeProps) => { dangerouslySetInnerHTML={{ __html: children }} /> ) : ( - {children} - + )} diff --git a/site/src/ColorModeToggle/ColorModeToggle.css.ts b/site/src/ColorModeToggle/ColorModeToggle.css.ts index adc66a687..120c6195d 100644 --- a/site/src/ColorModeToggle/ColorModeToggle.css.ts +++ b/site/src/ColorModeToggle/ColorModeToggle.css.ts @@ -1,5 +1,5 @@ import { assignVars, createThemeContract, style } from '@vanilla-extract/css'; -import { darkMode } from '../system/styles/sprinkles.css'; +import { darkMode } from '../system/styles'; import { vars } from '../themes.css'; const themeVars = createThemeContract({ diff --git a/site/src/ColorModeToggle/ColorModeToggle.tsx b/site/src/ColorModeToggle/ColorModeToggle.tsx index b00ddd361..ad5d43c24 100644 --- a/site/src/ColorModeToggle/ColorModeToggle.tsx +++ b/site/src/ColorModeToggle/ColorModeToggle.tsx @@ -21,7 +21,11 @@ export const ColorModeContext = createContext({ setColorMode: () => {}, }); -export function ColorModeProvider({ children }: { children: ReactNode }) { +export interface ColorModeProviderProps { + children: ReactNode; +} + +export const ColorModeProvider = ({ children }: ColorModeProviderProps) => { const [colorMode, setColorMode] = useState(null); useEffect(() => { @@ -51,7 +55,7 @@ export function ColorModeProvider({ children }: { children: ReactNode }) { {children} ); -} +}; export const ColorModeToggle = () => { const { colorMode, setColorMode } = useContext(ColorModeContext); diff --git a/site/src/Divider/Divider.tsx b/site/src/Divider/Divider.tsx index db5bfb975..9f87e17ce 100644 --- a/site/src/Divider/Divider.tsx +++ b/site/src/Divider/Divider.tsx @@ -1,7 +1,7 @@ import { Box } from '../system'; import * as styles from './Divider.css'; -export default () => { +export const Divider = () => { return ( ( +export const SiblingDoc = ({ + title, + route, + subtitle, + direction, +}: SiblingDocProps) => ( void; -}) => { +} + +export const Fab = ({ open, onClick }: FabProps) => { return ( ( { return ( diff --git a/site/src/InlineCode/InlineCode.css.ts b/site/src/InlineCode/InlineCode.css.ts index 8915da4b8..c6c2b1803 100644 --- a/site/src/InlineCode/InlineCode.css.ts +++ b/site/src/InlineCode/InlineCode.css.ts @@ -1,5 +1,5 @@ import { style } from '@vanilla-extract/css'; -import { darkMode } from '../system/styles/sprinkles.css'; +import { darkMode } from '../system/styles'; import { vars } from '../themes.css'; export const code = style({ diff --git a/site/src/InlineCode/InlineCode.tsx b/site/src/InlineCode/InlineCode.tsx index 8b31b359e..f4f36f711 100644 --- a/site/src/InlineCode/InlineCode.tsx +++ b/site/src/InlineCode/InlineCode.tsx @@ -6,7 +6,7 @@ export interface InlineCodeProps { children: ReactNode; inline?: boolean; } -export default ({ children }: InlineCodeProps) => { +export const InlineCode = ({ children }: InlineCodeProps) => { return ( ( +export interface LogoProps { + height?: string | number; +} + +export const Logo = ({ height = '100%' }: LogoProps) => ( { ); }; -export default { +export const mdxComponents = { hr: () => ( From e84e7a48e4b6867e0d3642f7f6ba454946f14ef4 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Sat, 31 Aug 2024 15:26:40 +0900 Subject: [PATCH 4/4] refactor(site/typography/Link): rename RouterLink to ReactRouterLink --- site/src/system/Columns.tsx | 1 + site/src/typography/Link.tsx | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/site/src/system/Columns.tsx b/site/src/system/Columns.tsx index 99216d195..8988e1f1c 100644 --- a/site/src/system/Columns.tsx +++ b/site/src/system/Columns.tsx @@ -23,6 +23,7 @@ export interface ColumnsProps { collapseOnMobile?: boolean; collapseOnTablet?: boolean; } + export const Columns = ({ children, space, diff --git a/site/src/typography/Link.tsx b/site/src/typography/Link.tsx index ed1dc4311..704a4ae95 100644 --- a/site/src/typography/Link.tsx +++ b/site/src/typography/Link.tsx @@ -1,6 +1,6 @@ import { - Link as RouterLink, - LinkProps as RouterLinkProps, + Link as ReactRouterLink, + LinkProps as ReactRouterLinkProps, } from 'react-router-dom'; import { HashLink } from 'react-router-hash-link'; import classnames from 'classnames'; @@ -8,7 +8,7 @@ import { TextProps, useTextStyles } from './Text'; import * as styles from './Link.css'; import { sprinkles } from '../system/styles/sprinkles.css'; -export interface LinkProps extends RouterLinkProps { +export interface LinkProps extends ReactRouterLinkProps { baseline?: boolean; size?: 'standard' | 'small' | 'xsmall'; underline?: 'always' | 'hover' | 'never'; @@ -50,7 +50,7 @@ export const Link = ({ } return ( - window.scrollTo(0, 0)} to={to} {...restProps}