Tailwind not implementing color additions - reactjs

I'm trying to use Tailwind in my project and I can get different styles to work, e.g. bold, round, flex, etc. However, none of the colors are coming through and I'm not sure why. I'm eventually hoping to use custom colors but that's not working either.
postcss.config.js
module.exports = {
plugins: [require('tailwindcss'), require('autoprefixer')]
};
tailwind.config.js
const colors = require('tailwindcss/colors')
module.exports = {
content: [
'./pages/**/*.{html,js}',
'./components/**/*.{html,js}',
'./index.html'
],
theme: {
colors: {
white: '#ffffff',
blue: {
medium: '#005c98'
},
black: {
light: '#005c98',
faded: '#00000059'
},
gray: {
base: '#616161',
background: '#fafafa',
primary: '#dbdbdb'
}
}
}
};
Styles I'm trying to apply to my button:
className={`bg-blue-500 text-black w-full rounded h-8 font-bold
${isInvalid && 'opacity-50'}`}
package.json dev dependencies
"devDependencies": {
"autoprefixer": "^10.4.8",
"eslint": "^6.3.0",
"eslint-loader": "^3.0.0",
"npm-run-all": "^4.1.5",
"postcss-cli": "^10.0.0",
"prop-types": "^15.8.1",
"tailwindcss": "^3.1.7"
}

You are overriding all of the default colors in your tailwind.config.css. If you want to keep the defaults and add a few new colors, you should use the extend property.
module.exports = {
content: [
"./pages/**/*.{html,js}",
"./components/**/*.{html,js}",
"./index.html",
],
theme: {
extend: {
colors: {
white: "#ffffff",
blue: {
medium: "#005c98",
},
black: {
light: "#005c98",
faded: "#00000059",
},
gray: {
base: "#616161",
background: "#fafafa",
primary: "#dbdbdb",
},
},
},
},
};

Related

Export TailwindCSS CSS rules to file instead of rendering CSS rules on DOM

On my project I use: TailwindCSS + Emotion + Tailwind Macro.
I just want to export TailwindCSS CSS rules to the currently generated styles.css file instead of rendering CSS rules on the DOM (html > head > style[]).
That way I would reduce the size of the app.js bundle, and of course, it will increase the size of the generated file: styles.cssbut I'm fine with that.
Any idea on how to do that?
Thanks!
Here are the config files:
tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
const { darken } = require('polished');
const colors = require('tailwindcss/colors');
const theme = require(`./offers/${process.env.OFFER}/theme`);
module.exports = {
/**
* Useful for arbitrary values:
* https://tailwindcss.com/docs/adding-custom-styles#using-arbitrary-values
*/
content: [ './resources/assets/js/components/**/*.js' ],
theme: {
colors: {
transparent: 'transparent',
current: 'currentColor',
black: colors.black,
white: colors.white,
gray: colors.gray,
emerald: colors.emerald,
indigo: colors.indigo,
yellow: colors.yellow,
/**
* Palette Colors from XD Mockup.
*/
light: theme.color.light,
neutral: theme.color.neutral,
highlight: theme.color.highlight,
textMedium: theme.color.textMedium,
textMediumHover: darken(0.10, theme.color.textMedium),
textDark: theme.color.textDark,
focusPrimary: theme.color.focusPrimary,
focusPrimaryHover: darken(0.10, theme.color.focusPrimary),
focusPrimaryLight: theme.color.focusPrimaryLight,
focusSecondary: theme.color.focusSecondary,
focusSecondaryHover: darken(0.10, theme.color.focusSecondary),
focusSecondaryMed: theme.color.focusSecondaryMed,
},
fontFamily: {
nunito: ['Nunito', 'sans-serif'],
opensans: ['Open Sans', 'sans-serif'],
},
fontSize: {
...defaultTheme.fontSize,
'h1d': '40px',
'h1m': '28px',
'h2d': '28px',
'h2m': '24px',
},
screens: {
'sm': '640px', // => #media (min-width: 640px) { ... }
'md': '768px', // => #media (min-width: 768px) { ... }
'lg': '1024px', // => #media (min-width: 1024px) { ... }
'xl': '1280px', // => #media (min-width: 1280px) { ... }
'2xl': '1536px', // => #media (min-width: 1536px) { ... }
},
},
};
webpack.mix.js
const mix = require('laravel-mix');
const path = require('path');
const theme = require(`./offers/${process.env.OFFER}/theme.js`);
const jsConfig = require('./resources/scripts/js-config');
require("mix-tailwindcss");
/**
* Prevent generating files: *.LICENSE.txt
*/
mix.options({
terser: {
extractComments: false,
terserOptions: {
output: {
comments: false,
},
},
},
});
/**
* Reference:
* https://laravel-mix.com/docs/6.0/extending-mix
*/
mix.extend('addWebpackLoaders', (webpackConfig, loaderRules) => {
loaderRules.forEach((loaderRule) => {
webpackConfig.module.rules.push(loaderRule);
});
});
mix.addWebpackLoaders([
{
test: /\.less$/,
use: [
{
loader: 'less-loader',
},
{
loader: 'text-transform-loader',
options: {
prependText:
`#offer: '${process.env.OFFER}';\n` +
`#cdn-url: '${process.env.CDN_URL}';\n`,
},
},
],
},
]);
mix.webpackConfig(webpack => {
return {
output: {
path: path.resolve(__dirname, 'public/cdn'),
publicPath: process.env.CDN_URL + '/',
chunkFilename: 'js/[name].js?v=##BUILD_NUMBER##',
},
plugins: [
new webpack.DefinePlugin({
'process.env.APP_ENV': `'${process.env.APP_ENV}'`,
'process.env.THEME': JSON.stringify(theme),
'process.env.JS_CONFIG': JSON.stringify(jsConfig(process.env.OFFER)),
}),
]
};
});
const package = require('./package.json');
const deps = Object.keys(package.dependencies);
mix.extract(deps);
mix.js('resources/assets/js/app.js', 'js');
mix
.less('resources/assets/less/styles.less', 'css')
.tailwind("./tailwind.config.js");
back when tailwindcss was new this is how CSS was generated, now it has built into webpack so I dont even use this now days.
npx tailwindcss build src/styles/index.css -o src/styles/output.css
note this will generate all css and file size can go up to Mbs.
so I recommend using postcss purgecss plugin along with this.

How to include icons and fonts file in webpack 4 in react?

I am using bootstrap theme for my project which have scss files for fonts and icons. I am implementing the webpack 4 but my build gone fialed every time when i include fonts and icons files. When i comment these files my webpack create the build, but that files are important. When build failed i got the error
ERROR in ./src/components/CommonForBoth/rightbar.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/components/CommonForBoth/rightbar.scss)
Module not found: Error: Can't resolve '../../../../fonts/materialdesignicons-webfont.woff?v=5.0.45' in 'C:\Users\zeesh\Desktop\prop-pro\src\components\CommonForBoth'
# ./src/components/CommonForBoth/rightbar.scss (./node_modules/css-loader/dist/cjs.js!./node_modules/sass-loader/dist/cjs.js!./src/components/CommonForBoth/rightbar.scss) 7:41-111
# ./src/components/CommonForBoth/rightbar.scss
# ./src/components/CommonForBoth/Rightbar.js
# ./src/components/HorizontalLayout/index.js
# ./src/App.js
# ./src/index.js
now the rightbar.scss is using theme.scss file and theme.scss file is using icons.scss file which makes issue while creating the build.
i have wasted alot of days in finding this issue, but cannot find any solution, why my icons and fonts files are not including,
If anybody knows? Kindly help me.
Rightbar.scc file
#import "../../theme.scss";
.radio-toolbar input[type="radio"] {
opacity: 0;
position: fixed;
width: 0;
}
.radio-toolbar label {
display: inline-block;
background-color: $gray-300;
cursor: pointer;
padding: 5px 10px;
font-size: 14px;
border-radius: 4px;
}
.radio-toolbar input[type="radio"]:checked + label {
background-color: $primary;
border: none;
color: $white;
}
#radio-title {
margin-bottom: 5px;
}
Theme.scss File
//Import Icon scss
#import "./assets/scss/icons.scss";
//import Light Theme
#import "./assets/scss/bootstrap.scss";
#import "./assets/scss/app.scss";
_icons.scss file
/*
Template Name: Nazox - Responsive Bootstrap 4 Admin Dashboard
Author: Themesdesign
Contact: themesdesign.in#gmail.com
File: Icons Css File
*/
// Plugins
#import "custom/plugins/icons";
icons file from icons.scss file
//
// icons.scss
//
#import "icons/materialdesignicons";
#import "icons/fontawesome-all";
#import "icons/dripicons";
#import "icons/remixicon";
_materialdesignicons.scss file from icons.scss file
* MaterialDesignIcons.com */
#font-face {
font-family: "Material Design Icons";
src: url("../../../../fonts/materialdesignicons-webfont.eot");
src: url("../../../../fonts/materialdesignicons-webfont.eot")
format("embedded-opentype"),
url("../../../../fonts/materialdesignicons-webfont.woff2") format("woff2"),
url("../../../../fonts/materialdesignicons-webfont.woff") format("woff"),
url("../../../../fonts/materialdesignicons-webfont.ttf") format("truetype");
font-weight: normal;
font-style: normal;
}
.mdi:before,
.mdi-set {
display: inline-block;
font: normal normal normal 24px/1 "Material Design Icons";
font-size: inherit;
text-rendering: auto;
line-height: inherit;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.mdi-ab-testing::before {
content: "\F01C9";
}
.mdi-abjad-arabic::before {
content: "\F1328";
}
.mdi-abjad-hebrew::before {
content: "\F1329";
}
.mdi-abugida-devanagari::before {
content: "\F132A";
}
.mdi-abugida-thai::before {
content: "\F132B";
}
.mdi-access-point::before {
content: "\F0003";
}
.mdi-access-point-network::before {
content: "\F0002";
}
.mdi-access-point-network-off::before {
content: "\F0BE1";
}
devdependencies i am using regarding my project requirements
"devDependencies": {
"#babel/core": "^7.9.0",
"#babel/preset-env": "^7.16.11",
"#babel/preset-react": "^7.16.7",
"babel-loader": "^8.1.0",
"css-loader": "^2.1.0",
"file-loader": "^4.3.0",
"html-webpack-plugin": "^4.0.0-beta.11",
"laravel-echo": "^1.11.2",
"pusher-js": "^7.0.3",
"react-error-overlay": "6.0.9",
"sass": "^1.51.0",
"sass-loader": "^8.0.2",
"style-loader": "^0.23.1",
"url-loader": "^2.3.0",
"webpack": "^4.42.0",
"webpack-cli": "^3.3.12"
}
my webpack file
const path = require("path");
// const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
mode: "production",
entry: "./src/index.js",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist"),
publicPath: "/dist/",
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader"],
},
{
test: /\.(css|scss)$/,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(png|jpe?g|svg|gif)$/i,
use: ["file-loader", "url-loader"],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
use: [
{
loader: "file-loader",
},
],
},
],
},
// ...add resolve to .jsx extension
resolve: {
extensions: ["*", ".js", ".jsx", ".css"],
},
};

Storybook + MUI5 + Nextjs - theme issue?

I finally managed to get SB working with mui4, but after upgrading the mui5, i can't get it going.
installed with Npx sb init —builder webpack5
updated sb main.js as per
Complained that "compressible' module couldn't be found so installed that.
Ran npm i core-js#3.8.2 as gives out about es-weak-map + others not found.
Added web pack 5 as a dev dependency npm install webpack#5 --save-dev
npx sb#next upgrade --prerelease.
plus literally every other suggestion i came across online, which you can see in these files (leaving some comments in so you can see what else i tried in some cases)
.storybook>main.js
const path = require('path');
const toPath = filePath => path.join(process.cwd(), filePath);
module.exports = {
stories: ['../src/**/*.stories.mdx', '../src/**/*.stories.#(js|jsx|ts|tsx)'],
addons: [
'#storybook/addon-links',
'#storybook/addon-essentials',
'#storybook/addon-interactions',
// 'storybook-addon-designs',
// 'storybook-anima',
// '#storybook/addon-actions',
{
name: '#storybook/addon-docs',
options: {
configureJSX: true,
babelOptions: {},
sourceLoaderOptions: null,
transcludeMarkdown: true,
},
},
'#storybook/builder-webpack5',
],
framework: '#storybook/react',
core: {
// builder: '#storybook/builder-webpack5',
builder: 'webpack5',
},
typescript: { reactDocgen: false },
features: {
emotionAlias: false,
modernInlineRendering: true,
},
webpackFinal: async (config, { configType }) => {
config.resolve.modules = [path.resolve(__dirname, '..', '.'), 'node_modules'];
config.resolve.alias = {
...config.resolve.alias,
'#emotion/core': toPath('node_modules/#emotion/react'),
'emotion-theming': toPath('node_modules/#emotion/react'),
// 'core-js/modules/es.weak-map.js': toPath('core-js/modules/es6.weak-map.js'),
};
return config;
// return {
// ...config,
// resolve: {
// ...config.resolve,
// alias: {
// ...config.resolve.alias,
// '#emotion/core': toPath('node_modules/#emotion/react'),
// 'emotion-theming': toPath('node_modules/#emotion/react'),
// },
// },
// };
},
};
.package.json
{ "dependencies": {
"#auth0/nextjs-auth0": "^1.7.0",
"#emotion/react": "^11.8.2",
"#emotion/styled": "^11.8.1",
"#material-ui/core": "^4.12.0",
"#material-ui/icons": "^4.11.2",
"#material-ui/lab": "^4.0.0-alpha.60",
"#mui/icons-material": "^5.5.1",
"#mui/lab": "^5.0.0-alpha.75",
"#mui/material": "^5.5.3",
"#mui/styles": "^5.5.3",
"core-js": "^3.8.2",
"cors": "^2.8.5",
"next": "^12.1.4",
"react": "latest",
},
"devDependencies": {
"#storybook/addon-actions": "^6.5.0-alpha.59",
"#storybook/addon-essentials": "^6.5.0-alpha.59",
"#storybook/addon-interactions": "^6.5.0-alpha.59",
"#storybook/addon-links": "^6.5.0-alpha.59",
"#storybook/builder-webpack5": "^6.5.0-alpha.59",
"#storybook/manager-webpack5": "^6.5.0-alpha.59",
"#storybook/node-logger": "^6.5.0-alpha.59",
"#storybook/preset-create-react-app": "^4.1.0",
"#storybook/react": "^6.5.0-alpha.59",
"#storybook/testing-library": "^0.0.9",
"#svgr/webpack": "^6.2.1",
"compressible": "^2.0.18",
"webpack": "^5.72.0"
},
"eslintConfig": {
"overrides": [
{"files": ["**/*.stories.*"],
"rules": {"import/no-anonymous-default-export": "off"}
}]
},
"resolutions": {"#storybook/{app}/webpack": "^5"}
}
my Story
// import { ThemeProvider } from '#mui/styles';
import { ThemeProvider as MUIThemeProvider, createTheme } from '#mui/material/styles';
import { ThemeProvider } from 'emotion-theming';
import React from 'react';
//import theme from 'src/themes/theme.js';
// import DuplicateComponent from 'src/components/helpers/DuplicateComponent';
// import TickerTicket from 'src/components/modules/dashboard/TickerTicket';
import DataLanes from '.';
export default {
title: 'components/common/dataDisplay/DataLanes',
component: DataLanes,
};
export const Bare = () => (
// <MUIThemeProvider theme={theme}>
// <ThemeProvider theme={theme}>
<DataLanes borderBottom>
<div>1</div>
<div>2</div>
<div>3</div>
</DataLanes>
// </ThemeProvider>
// </MUIThemeProvider>
);
My Component
import { Box } from '#mui/material';
import clsx from 'clsx';
import React from 'react';
import PropTypes from 'prop-types';
import useStyles from './styles';
export default function DataLanes(props) {
const classes = useStyles();
const { borderBottom, borderTop, className, children, ...others } = props;
return (
<Box
className={clsx(classes.dataLanes, className, {
borderBottom: borderBottom,
borderTop: borderTop,
})}
{...others}
>
{children}
</Box>
);
}
its styling
import makeStyles from '#mui/styles/makeStyles';
const useStyles = makeStyles(theme => ({
dataLanes: {
width: '100%',
background: theme.palette.background.paper,
display: 'flex',
paddingTop: theme.spacing(1),
paddingBottom: theme.spacing(1),
overflowY: 'auto',
'& > * ': {
flexGrow: 1,
borderRight: `1px solid ${theme.palette.grey[300]}`,
},
'&.borderBottom': {
borderBottom: `1px solid ${theme.palette.grey[300]}`,
},
'&.borderTop': {
borderTop: `1px solid ${theme.palette.grey[300]}`,
},
},
}));
export default useStyles;
Any thoughts? It seems like it's the background: theme.palette.background.paper,
in the style.js.
For similar issues I encountered with MUI and storybook this change at the preview.js in the .storybook folder solved it.
.storybook>preview.js
import React from 'react';
import { addDecorator } from '#storybook/react';
import { ThemeProvider } from '#mui/material/styles';
import { theme } from '../src/Theme'; //. Please replace the path for the theme with yours.
export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};
addDecorator(story => <ThemeProvider theme={theme}>{story()}</ThemeProvider>);

GatsbyJS + Netlify + MDX loader issue

I am making a style guide with a CMS and running into a few issues.
This is my webpack config
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
plugins: [
new WebpackNotifierPlugin({
skipFirstNotification: true,
}),
],
resolve: {
// Enable absolute import paths
modules: [path.resolve(__dirname, 'src'), 'node_modules'],
extensions: ['.js', '.jsx', '.json', '.tsx'],
},
})
}
This is my package.json
"#babel/core": "^7.2.2",
"#material-ui/core": "^4.9.1",
"#material-ui/icons": "^4.9.1",
"#mdx-js/mdx": "^0.16.8",
"#mdx-js/tag": "^0.16.6",
"#reach/router": "^1.2.1",
"#typescript-eslint/parser": "^2.19.0",
"d3-ease": "^1.0.5",
"docz-utils": "^0.13.6",
"gatsby": "^2.0.76",
"gatsby-image": "^2.0.20",
"gatsby-link": "^2.2.29",
"gatsby-mdx": "^0.3.4",
"gatsby-plugin-catch-links": "^2.0.9",
"gatsby-plugin-manifest": "^2.0.9",
"gatsby-plugin-mdx": "^1.0.67",
"gatsby-plugin-netlify-cms": "4.1.40",
"gatsby-plugin-offline": "^2.0.16",
"gatsby-plugin-sharp": "^2.0.14",
"gatsby-react-router-scroll": "^2.1.21",
"gatsby-source-filesystem": "^2.0.16",
"gatsby-transformer-sharp": "^2.1.8",
"hast-util-to-string": "^1.0.1",
"jss": "^10.0.4",
"jsx-to-string": "^1.4.0",
"lodash": "^4.17.11",
"marked": "^0.6.0",
"netlify-cms-app": "2.9.1",
"netlify-cms-widget-mdx": "^0.4.3",
"netlify-identity-widget": "^1.5.6",
"prismjs": "^1.15.0",
"prop-types": "^15.6.2",
"react": "^16.8.0",
"react-dom": "^16.8.0",
"react-head": "^3.0.2",
"react-highlight": "^0.12.0",
"react-powerplug": "^1.0.0",
"styled-system": "^3.2.1",
"unstated": "^2.1.1",
"write": "^1.0.3"
This is my component:
interface IButtons {
children: React.ReactElement;
}
const useStyles = makeStyles({
root: {
},
button: {
display: 'flex',
justifyContent: 'space-between' as 'space-between',
padding: `16px 8px`,
paddingRight: '50px',
background: `#F7F9FE`,
position: 'relative' as 'relative'
},
expand: {
position: 'absolute' as 'absolute',
top: 0,
right: 0,
cursor: 'pointer'
},
code: {
padding: `16px`,
fontSize: `14px`
}
});
const Buttons = (props: IButtons) => {
const classes = useStyles();
const [isCodeOpen, setCode] = useState(false)
const children = React.Children.toArray(props.children)
const stringChildren = useMemo(() => {
let stringed: string[] | string = []
for (let i = 0; i < React.Children.count(children); i++) {
stringed
.push(jsxToString(props.children[i])
.replace('WithStyles(ForwardRef(Button))', 'Button')
.replace('/WithStyles(ForwardRef(Button))', '/Button'))
}
return stringed.join("\n\n")
}, [props.children])
return (
<section className={classes.root}>
<div className={classes.button}>
<CodeIcon className={classes.expand} fontSize='small' onClick={() => setCode(!isCodeOpen)}></CodeIcon>
{props.children}
</div>
{isCodeOpen &&
<Highlight language="javascript" className={classes.code}>
{stringChildren}
</Highlight>}
</section>
)
}
And these are my UI components
export const UIComponents = {
...UI,
DeleteIcon,
Buttons,
// TODO: include additional custom components here, eg:
Janky: props => <UI.TextField {...props} placeholder={'janky'} />
}
And my query
{
resolve: "gatsby-mdx",
options: {
extensions: [".mdx", ".md"],
defaultLayouts: {
default: require.resolve("./src/components/Layout/index.tsx"),
},
globalScope: `
import { UIComponents } from 'Theme'
export default {
...UIComponents
}
`,
// mdPlugins: [],
// gatsbyRemarkPlugins: [{}],
},
},
The first issue I am encountering when starting the app is I get this error message. I am not sure what loaders I need to put.
Module parse failed: The keyword 'interface' is reserved (8:0)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| import jsxToString from 'jsx-to-string';
|
> interface IButtons {
| children: React.ReactElement;
| }
# ./src/Theme.jsx 32:0-43 123:11-18
# ./src/cms/cms.jsx
# multi ./node_modules/gatsby-plugin-netlify-cms/cms.js ./src/cms/cms
The second issue is that in my netlify cms preview I get:
Invalid MDX:
ReferenceError: Buttons is not defined
Even though in the App itself the Buttons component renders, in the preview it does not.
Gatsby does not ship with Typescript support out of the box, but you can add it easily with the gatsby-plugin-typescript plugin.
Install
npm install gatsby-plugin-typescript
How to use
Include the plugin in your gatsby-config.js file.
Write your components in TSX or TypeScript.
You’re good to go.
gatsby-config.js
module.exports = {
// ...,
plugins: [`gatsby-plugin-typescript`],
}

gatsby-source-graphql only absolute urls are supported

I'm integrating graphQL into my gatsby site. I am getting an error that says "only absolute urls are supported" and then points to some code in the node-fetch library. There isn't an obvious path to how I'm getting that code to execute though, so I'm not sure what the source of my issue is. I have done several days worth of searching, and while I have found several threads about this error, it's never been in the context of gatsby-source-graphql. Any help would be appreciated.
package.json
{
.
.
.
"dependencies": {
"ajv": "^6.9.2",
"core-js": "^2.6.5",
"fullcalendar": "^3.9.0",
"fullcalendar-reactwrapper": "^1.0.7",
"gatsby": "^2.12.0",
"gatsby-cli": "^2.7.20",
"gatsby-plugin-manifest": "^2.0.2",
"gatsby-plugin-netlify-cms": "^4.0.1",
"gatsby-plugin-offline": "^2.0.5",
"gatsby-plugin-react-helmet": "^3.0.0",
"gatsby-plugin-sass": "^2.0.1",
"gatsby-source-filesystem": "^2.1.6",
"gatsby-source-graphql": "^2.1.3",
"gatsby-transformer-remark": "^2.6.9",
"graphql": "^14.1.1",
"jquery": "^3.3.1",
"moment": "^2.22.2",
"netlify-cms-app": "^2.9.1",
"node-sass": "^4.9.3",
"react": "^16.5.1",
"react-calendar": "^2.17.5",
"react-dom": "^16.6.3",
"react-helmet": "^5.2.0",
"react-native-calendars": "^1.21.0"
},
.
.
.
"devDependencies": {
"#material-ui/core": "^3.9.2",
"#material-ui/icons": "^3.0.2",
"material-icons-react": "^1.0.4",
"prettier": "^1.14.2",
"react-tooltip": "^3.9.2",
"surge": "^0.20.1"
},
.
.
.
}
UpcomingScheduleChanges.js
import React from 'react';
import { StaticQuery, graphql } from 'gatsby';
import Cancellations from './Cancellations';
class UpcomingScheduleChanges extends React.Component {
render() {
console.log(this.props.cancellations)
return (
<div className="col-6">
<header className="major">
<h2>Upcoming Schedule Changes</h2>
</header>
{this.props.cancellations ? (
<Cancellations cancellations={this.props.cancellations}></Cancellations>
) : (
<p>There are no upcomimng schedule changes!</p>
)}
</div>
)
}
}
export default () => (
<StaticQuery
query={graphql`
query ScheduleChanges {
allMarkdownRemark {
edges {
node {
frontmatter {
cancellation {
date(formatString: "MMMM DD")
day
location
type
}
}
}
}
}
}
`}
render={(data) => <UpcomingScheduleChanges cancellations={data.allMarkdownRemark.edges[0].node.frontmatter.cancellation} />}
/>
);
index.js
import React from "react";
import Helmet from "react-helmet";
import Layout from "../components/layout";
import ReactTooltip from "react-tooltip";
import ContactForm from "../components/ContactForm";
import Schedule from '../components/Schedule';
import Welcome from "../components/Welcome";
import Administrators from "../components/Administrators";
import MailingList from "../components/MailingList";
class Homepage extends React.Component {
handleClick(url) {
window.open(url, "_blank");
}
render() {
const siteTitle = "...";
return (
<Layout>
<Helmet title={siteTitle}>
<script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script>
</Helmet>
<Welcome></Welcome>
<Schedule></Schedule>
<Administrators></Administrators>
<MailingList></MailingList>
<ContactForm></ContactForm>
<ReactTooltip />
<script>
{`if (window.netlifyIdentity) {
window.netlifyIdentity.on("init", user => {
if (!user) {
window.netlifyIdentity.on("login", () => {
document.location.href = "/admin/";
});
}
});
}`}
</script>
</Layout>
);
}
}
export default Homepage;
gatsby-config.js
module.exports = {
siteMetadata: {
title: "...",
author: "...",
description: "..."
},
plugins: [
'gatsby-plugin-react-helmet',
{
resolve: `gatsby-plugin-manifest`,
options: {
name: '...',
short_name: '...',
start_url: '/',
background_color: '#FFFFFF',
theme_color: '#FFFFFF',
display: 'minimal-ui',
icon: 'src/assets/images/banner_small.png', // This path is relative to the root of the site.
},
},
'gatsby-plugin-sass',
'gatsby-transformer-remark',
{
resolve: 'gatsby-source-filesystem',
options: {
path: `${__dirname}/static/content`,
name: 'content'
}
},
{
resolve: "gatsby-source-graphql",
options: {
typeName: "cancellations",
fieldName: "cancellations",
url: `${__dirname}/static/content/cancellations.md`
}
},
'gatsby-plugin-offline',
'gatsby-plugin-netlify-cms'
],
}
config.yml
backend:
name: git-gateway
branch: master #branch to update (optional; defaults to master)
publish_mode: editorial_workflow #allows for a drafting, reviewing, and approving process for changes
media_folder: "src/assets/images/uploads"
public_folder: "/images"
#collections
collections:
- label: "Upcoming Schedule Changes"
name: "upcoming schedule changes"
files:
- label: "Cancellations"
name: "cancellations"
file: "static/content/cancellations.md"
fields:
- label: "Cancellations"
name: "cancellations"
create: true
widget: "list"
fields:
- {label: "Date", name: "date", widget: "date"}
- {label: "Day", name: "day", widget: "select", options: ["Thursday", "Friday", "Sunday"]}
- {label: "Location", name: "location", widget: "select", options: ["Location1", "Location2", "Location3"]}
- {label: "Type", name: "type", widget: "select", options: ["Cancelled", "Delayed", "Relocated"]}

Resources