Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-plugin-theme-ui

Package Overview
Dependencies
Maintainers
1
Versions
465
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-plugin-theme-ui - npm Package Compare versions

Comparing version 0.0.16-6 to 0.0.17-alpha.0

LICENSE.md

9

gatsby-browser.js

@@ -1,8 +0,1 @@

"use strict";
exports.__esModule = true;
exports.wrapRootElement = void 0;
var _root = require("./root");
exports.wrapRootElement = _root.wrapRootElement;
exports.wrapRootElement = require('./root')

@@ -0,4 +1,35 @@

const fs = require('fs')
const path = require('path')
const pkg = require('./package.json')
exports.onCreateWebpackConfig = ({ actions, loaders }, opts) => {
const themeModules = []
const hasModule = dirname => {
return fs.existsSync(path.join(dirname, 'src', 'theme.js'))
|| fs.existsSync(path.join(dirname, 'src', 'theme', 'index.js'))
}
exports.onCreateWebpackConfig = ({ actions, loaders, store }, opts) => {
const { program, config, themes } = store.getState()
const siteThemeModule = path.join(program.directory, 'src', 'theme')
if (Array.isArray(themes.themes)) {
themes.themes.forEach(theme => {
let hasThemePlugin = false
if (theme.themeConfig && theme.themeConfig.plugins) {
hasThemePlugin = theme.themeConfig.plugins.includes(pkg.name)
}
if (hasThemePlugin) {
const filepath = path.join(theme.themeDir, 'src', 'theme.js')
if (hasModule(theme.themeDir)) {
themeModules.push(filepath)
}
}
})
}
if (hasModule(program.directory)) {
themeModules.push(siteThemeModule)
}
actions.setWebpackConfig({

@@ -9,11 +40,14 @@ module: {

test: /\.js$/,
include: path.dirname(require.resolve('gatsby-plugin-theme-ui')) },
include: path.dirname(require.resolve('gatsby-plugin-theme-ui'))
},
{
test: /gatsby-plugin-theme-ui\/theme-loader/,
test: /gatsby-plugin-theme-ui\/loader/,
include: path.dirname(require.resolve('gatsby-plugin-theme-ui')),
use: [
loaders.js(),
{
loader: require.resolve('./theme-loader'),
loader: require.resolve('./loader'),
options: {
...opts,
themes: themeModules,
}

@@ -20,0 +54,0 @@ }

@@ -1,8 +0,26 @@

"use strict";
const { jsx } = require('theme-ui')
exports.__esModule = true;
exports.wrapRootElement = void 0;
exports.wrapRootElement = require('./root')
var _root = require("./root");
// prevent color mode flash
const noflash = `
(function() {
try {
var mode = localStorage.getItem('theme-ui-color-mode');
if (!mode) return
document.body.classList.add('theme-ui-' + mode);
} catch (e) {
}
})();
`
exports.wrapRootElement = _root.wrapRootElement;
exports.onRenderBody = ({
setPreBodyComponents,
}) => {
const script = jsx('script', {
dangerouslySetInnerHTML: {
__html: noflash
}
})
setPreBodyComponents([ script ])
}
{
"name": "gatsby-plugin-theme-ui",
"version": "0.0.16-6",
"version": "0.0.17-alpha.0",
"main": "index.js",
"author": "Brent Jackson <jxnblk@gmail.com>",
"license": "MIT",
"scripts": {
"prepare": "babel src -d ."
},
"devDependencies": {
"@babel/cli": "^7.4.4",
"@babel/core": "^7.4.5",
"babel-preset-gatsby-package": "^0.1.4"
},
"dependencies": {
"loader-utils": "^1.2.3",
"theme-ui": "^0.0.15"
}
"lodash.merge": "^4.6.1"
},
"gitHead": "525dde70c2a15c98f5ffe2ecb5ea62d15be487f0"
}
# gatsby-plugin-theme-ui
Adds the Theme UI ThemeProvider context to Gatsby themes and sites, deeply merging them into a single context.
Automatically adds Theme UI context to a Gatsby site or theme
```sh
npm i gatsby-plugin-theme-ui
npm i theme-ui gatsby-plugin-theme-ui
```

@@ -14,15 +14,39 @@

plugins: [
{
resolve: 'gatsby-plugin-theme-ui',
options: {
// required
theme: require.resolve('./src/theme.js'),
// optional
components: require.resolve('./src/components.js'),
// optional, initial color mode
initialColorMode: 'light',
'gatsby-plugin-theme-ui',
]
}
```
Add a `src/theme.js` file to your site to add values to the theme context.
```js
// src/theme.js
export default {
colors: {
text: '#000',
background: '#fff',
primary: 'tomato',
},
}
```
## Color Modes
To enable support for multiple color modes, add an `initialColorMode` field to your `theme.js` object.
```js
// src/theme.js
export default {
initialColorMode: 'light',
colors: {
text: '#000',
background: '#fff',
modes: {
dark: {
text: '#fff',
background: '#000',
}
}
]
},
}
```

@@ -1,50 +0,21 @@

"use strict";
const {
jsx,
ThemeProvider,
ColorMode,
} = require('theme-ui')
const merge = require('lodash.merge')
const { themes } = require('gatsby-plugin-theme-ui/loader')
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
const theme = merge({}, ...themes)
exports.__esModule = true;
exports.wrapRootElement = void 0;
var _react = _interopRequireDefault(require("react"));
var _themeUi = require("theme-ui");
var _lodash = _interopRequireDefault(require("lodash.merge"));
var _themeLoader = require("gatsby-plugin-theme-ui/theme-loader");
var _jsxFileName = "/Users/jxnblk/repos/theme-ui/gatsby-plugin-theme-ui/src/root.js";
var theme = _lodash.default.apply(void 0, [{}].concat(_themeLoader.themes));
var comps = _lodash.default.apply(void 0, [{}].concat(_themeLoader.components));
var wrapRootElement = function wrapRootElement(_ref, opts) {
var element = _ref.element,
props = _ref.props;
var children = _react.default.createElement(_themeUi.ThemeProvider, {
components: comps,
theme: theme,
__source: {
fileName: _jsxFileName,
lineNumber: 11
},
__self: this
}, element);
if (!opts.initialColorMode) {
return children;
}
return _react.default.createElement(_themeUi.ColorModeProvider, {
initialColorMode: opts.initialColorMode,
__source: {
fileName: _jsxFileName,
lineNumber: 23
},
__self: this
}, children);
};
exports.wrapRootElement = wrapRootElement;
module.exports = ({ element }, opts) => {
return jsx(ThemeProvider, {
...opts,
theme,
},
theme.initialColorMode && jsx(ColorMode, {
key: 'theme-ui-color-mode',
}),
element
)
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc