This project is a Gatsby starter configured with Theme UI to showcase customizable color modes, reusable components, styled UI elements, and syntax highlighting. It includes a modular theme structure with reusable configurations for colors, typography, spacing, and more.
- Multi-Mode Color Themes:
- Supports Light, Dark, Purple, and Forest modes.
- Easily switch themes using a dropdown menu.
- Theme UI Integration:
- Modular theme structure with dedicated files for colors, typography, and component variants.
- Easily extendable for future needs.
- Syntax Highlighting:
- Powered by Theme UI and @theme-ui/prism.
- Customize syntax themes or use provided presets like Night Owl, Dracula, and more.
- Component-Driven Architecture:
- Reusable components like
Layout
andColorModeToggle
for scalability.
- Reusable components like
- Showcase Page:
- Demonstrates how to use typography, colors, buttons, forms, and tables defined in the theme.
- Testing Suite:
- Jest and Testing Library setup to ensure component functionality.
gatsby-theme-ui-template/
├── gatsby-config.js # Updated to source MDX posts from `/src/posts/`
├── gatsby-node.js # Dynamically creates individual post pages
├── src/
│ ├── pages/
│ │ ├── index.jsx # Homepage
│ │ ├── posts.jsx # Post listing page
│ │ ├── about.jsx # About page
│ │ ├── showcase.jsx # Theme showcase page
│ │ ├── page-2.jsx # Additional example page
│ │ ├── using-dsg.jsx # Deferred Static Generation example page
│ │ ├── using-ssr.jsx # Server-Side Rendering example page
│ │ ├── using-typescript.tsx # TypeScript example page
│ └── 404.jsx # Custom 404 page
│
│ ├── posts/ # MDX blog posts
│ │ ├── analyzing-reddit-comments-with-python.mdx
│ │ ├── mdx-with-theme-ui.mdx
│ │ ├── my-first-post.mdx
│
│ ├── templates/ # Templates for dynamically created pages
│ │ └── post.jsx # Individual post template
│
│ ├── components/ # Reusable components
│ │ ├── Layout.jsx # Shared layout for all pages
│ │ ├── Header.jsx # Page header
│ │ ├── Footer.jsx # Page footer
│ │ ├── ColorModeToggle.jsx # Theme UI color mode switcher
│ │ ├── __tests__/ # Jest tests for components
│ │ │ └── Layout.test.js
│
│ ├── gatsby-plugin-theme-ui/
│ │ ├── colors.js # Colors and color modes
│ │ ├── typography.js # Fonts, sizes, weights, line heights
│ │ ├── space.js # Spacing (margins, paddings)
│ │ ├── radii.js # Border radius styles
│ │ ├── buttons.js # Button styles and variants
│ │ ├── forms.js # Form styles (inputs, selects, etc.)
│ │ ├── text.js # Text variants
│ │ ├── variants.js # Component variants (e.g., cards, badges)
│ │ ├── styles.js # Global styles (root, headings, links, etc.)
│ │ └── index.js # Combines all theme files into a single export
│
│ └── styles/
│ ├── global.css # Global CSS resets and overrides
│ └── utils.css # Utility classes for quick styling
│
└── static/ # Static assets (images, icons, etc.)
Ensure you have the following installed:
- Node.js (>= 14.x)
- Gatsby CLI (optional)
-
Clone the Repository:
git clone https://github.com/your-username/gatsby-theme-ui-starter.git cd gatsby-theme-ui-starter
-
Install Dependencies:
npm install
-
Run the Development Server:
gatsby develop
-
Open in Your Browser:
Visit
http://localhost:8000
to see the project in action.
The theme is broken into smaller, reusable files for maintainability and scalability.
colors.js
:- Defines color palettes and modes (e.g., Light, Dark, Purple).
typography.js
:- Configures fonts, font sizes, weights, and line heights.
space.js
:- Defines spacing scales for margins and paddings.
radii.js
:- Sets border radius styles (e.g.,
default
,circle
).
- Sets border radius styles (e.g.,
buttons.js
:- Defines button styles and variants (
primary
,secondary
).
- Defines button styles and variants (
forms.js
:- Configures input, select, and textarea styles.
text.js
:- Includes text variants for headings and displays.
variants.js
:- Contains reusable component variants (e.g.,
cards
,badges
).
- Contains reusable component variants (e.g.,
styles.js
:- Global styles for the root, headings, links, and more.
index.js
:- Combines all theme files and exports the final theme object.
To add a new button variant:
-
Open
src/gatsby-plugin-theme-ui/buttons.js
. -
Add a new variant:
const buttons = { primary: { fontWeight: "bold", color: "background", bg: "primary", "&:hover": { bg: "secondary", }, }, secondary: { fontWeight: "bold", color: "background", bg: "secondary", "&:hover": { bg: "primary", }, }, tertiary: { fontWeight: "medium", color: "text", bg: "muted", "&:hover": { bg: "highlight", }, }, }; export default buttons;
-
Use the variant in your component:
<button sx={{ variant: "buttons.tertiary" }}>Tertiary Button</button>
The Showcase Page demonstrates how to use the modular theme configuration.
Visit http://localhost:8000/showcase
to explore the examples, including:
- Typography
- Buttons
- Forms
- Colors
- Tables
This project uses Jest and Testing Library for testing.
Run tests:
npm test
Example test file: src/components/__tests__/Layout.test.js
--
The main blog listing page.
Renders individual blog posts.
---
title: "MDX with Theme UI"
excerpt: "Learn how to use MDX with Theme UI to create a customizable and powerful blogging experience."
date: "2024-11-21"
slug: "mdx-with-theme-ui"
---
## Customization
### Components
- **`Layout.js`**:
- Wraps all pages to provide a consistent header and styling.
- Includes the `ColorModeToggle` for theme switching.
- **`ColorModeToggle.js`**:
- Dropdown menu for selecting color modes.
- Customizable via `theme.buttons`.
### Styles
- **Global Styles**:
- Located in `src/styles/global.css`.
- Includes resets and custom font imports.
- **Utility Classes**:
- Located in `src/styles/utils.css`.
- Predefined classes for margins, paddings, and text alignment.
---
## Contributing
1. Fork the repository.
2. Create a new branch (`git checkout -b feature/new-feature`).
3. Commit changes (`git commit -m 'Add new feature'`).
4. Push to the branch (`git push origin feature/new-feature`).
5. Open a pull request.
---
## License
This project is licensed under the [MIT License](LICENSE).
Created by Gilberto Alejandro Haro
---
## Acknowledgments
- [Gatsby](https://www.gatsbyjs.com/)
- [Theme UI](https://theme-ui.com/)
- [Testing Library](https://testing-library.com/)
---
---
----