Work Diary:
Iām back to doing some work on this project.
Right now Iām taking what I can observe from the Chakra theme and using that to try and adjust my theme to have defaults that can also be overriden by the frontity.settings.js file.
I added the following to state:
state: {
// State is where the packages store their default settings and other
// relevant state. It is scoped to the "theme" namespace.
theme: {
menu: [],
isBlog: false,
colors: {
primary: {
default: "#2657eb",
heavy: "#1f38c5"
}
}
}
},
The isBlog
is simply a mode that tells whether or not the website should be presented as a blog (which means that it presents author name and date information on posts and eventually will have very different styling for the archive page)
Iām having a bit more trouble getting the color stuff to work.
Chakra passes itās primary colors etc down as props but I think thatās messy looking and Iād prefer to pass stuff from state to a variable that gets set as a CSS variable.
So I currently have this:
const primaryColor= "green";
const globalStyles = css`
:root {
--primary-heavy: #1f38c5;
--primary: ${primaryColor};
--snappy: cubic-bezier(0.075, 0.82, 0.165, 1);
--heavy-snap: cubic-bezier(0.6, -0.28, 0.735, 0.045);
}
}
And that works. But I want to pass the const primaryColor from the state but Iām not sure how to connect the two?
Instead of const primaryColor = "green"
I need to use const primaryColor = state.theme.colors.primary.default
but thatās not working.
I know this is probably a super basic problem but this is a good example of how Iām still learning how the whole declarative aspect of React works.
When I try setting const primaryColor = state.theme.colors.primary.default
I get a āstate doesnāt existā error.
I feel like that must be because the theme javascript object in src/index.js must not be getting passed to it. So do I need to import it or something?
Why does it work though when I use {isBlog && <dateComponent/>}
though? Components get passed the state via the arrow function in the src/components/index.js but Iām not sure how to pull the state into that file without using the arrow function so that it can be accessed via the styled-components stuff?
Any suggestions?
EDIT 1:
Okay so I tried setting it like this:
const primaryColor = frontity.state.theme.colors.primary.default;
Iām using npx frontity dev and it works! I see the color change from the test "const primaryColor = āgreenā; to the proper setting which is blue.
But, if I refresh it breaks. Thatāsā¦ weird.
EDIT 2:
Yeahā¦ IDK whatās up with this. I can get colors to work by making a file called ātheme.jsā and putting an object in it that contains the necessary information
import { colors } from "../theme.js";
const primaryColor = colors.primary.default;
But I canāt get it to work by just directly referencing the stuff in the src/index.js file:
import desertJackalope from "../index";
const primaryColor = desertJackalope.state.theme.colors.primary.default;
Which is just a javascript object just like theme.jsā¦ so whatās the deal? Is this something specific to Frontity Iām missing?