Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xiaoxinghu/gatsby-plugin-themes
https://github.com/xiaoxinghu/gatsby-plugin-themes
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/xiaoxinghu/gatsby-plugin-themes
- Owner: xiaoxinghu
- Created: 2019-08-22T10:05:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-31T09:04:58.000Z (about 5 years ago)
- Last Synced: 2024-05-01T15:44:14.434Z (8 months ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gatsby plugin for themes (and switching between them)
This is a style system agnostic plugin. No matter what style system you are
using (styled-components, emotion, theme-ui ...), you can use them with this
plugin.# How to Use
In your `gatsby-config.js` file.
``` javascript
module.exports = {
// ...
{
resolve: `gatsby-plugin-themes`,
options: {
themes: [
`${__dirname}/src/themes/dark.js`,
`${__dirname}/src/themes/light.js`,
],
},
}
// ...
}
```And anywhere in any of your components.
``` javascript
import React, { useContext } from 'react'
import { ThemeContext } from 'gatsby-plugin-themes'
// ...
const { theme, next } = useContext(ThemeContext)
```Here the `theme` is one of your modules decleared in the `gatsby-config.js` file
(in this example, `dark.js` or `light.js`). And I don't care what's in it, nor
how you use it, you are the boss.The `next` is a function to toggle between your themes. And that's about it. Enjoy.